]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Prospects/ProspectFormBase.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Prospects / ProspectFormBase.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  Base form for prospect
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46 class ProspectFormBase  {
47
48 function checkForDuplicates($prefix){
49         global $local_log;
50         require_once('include/formbase.php');
51         
52         $focus = new Prospect();
53         if(!checkRequired($prefix, array_keys($focus->required_fields))){
54                 return null;
55         }
56         $query = '';
57         $baseQuery = 'select id,first_name, last_name, title, email1, email2  from prospects where deleted!=1 and (';
58         if(!empty($_POST[$prefix.'first_name']) && !empty($_POST[$prefix.'last_name'])){
59                 $query = $baseQuery ."  (first_name like '". $_POST[$prefix.'first_name'] . "%' and last_name = '". $_POST[$prefix.'last_name'] ."')";
60         }else{
61                         $query = $baseQuery ."  last_name = '". $_POST[$prefix.'last_name'] ."'";
62         }
63         if(!empty($_POST[$prefix.'email1'])){
64                 if(empty($query)){
65                 $query = $baseQuery. "  email1='". $_POST[$prefix.'email1'] . "' or email2 = '". $_POST[$prefix.'email1'] ."'";
66                 }else {
67                         $query .= "or email1='". $_POST[$prefix.'email1'] . "' or email2 = '". $_POST[$prefix.'email1'] ."'";
68                 }
69         }
70         if(!empty($_POST[$prefix.'email2'])){
71                 if(empty($query))       {
72                         $query = $baseQuery. "  email1='". $_POST[$prefix.'email2'] . "' or email2 = '". $_POST[$prefix.'email2'] ."'";
73                 }else{
74                         $query .= "or email1='". $_POST[$prefix.'email2'] . "' or email2 = '". $_POST[$prefix.'email2'] ."'";
75                 }
76
77         }
78
79         if(!empty($query)){
80                 $rows = array();
81                 
82                 $db = DBManagerFactory::getInstance();
83                 $result = $db->query($query.');');
84         while($row = $db->fetchByAssoc($result)) {
85             $rows[] = $row;
86                 }
87                 if(count($rows) > 0) return $rows;
88                 }
89         return null;
90 }
91
92
93 function buildTableForm($rows, $mod=''){
94         global $action;
95         if(!empty($mod)){
96         global $current_language;
97         $mod_strings = return_module_language($current_language, $mod);
98         }else global $mod_strings;
99         global $app_strings;
100         $cols = sizeof($rows[0]) * 2 + 1;
101         if ($action != 'ShowDuplicates') 
102         {
103                 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_DUPLICATE']. '</td></tr><tr><td height="20"></td></tr></table>';
104                 $form .= "<form action='index.php' method='post' name='dupProspects'><input type='hidden' name='selectedProspect' value=''>";
105         }
106         else 
107         {
108                 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_SHOW_DUPLICATES']. '</td></tr><tr><td height="20"></td></tr></table>';
109         }
110         $form .= get_form_header($mod_strings['LBL_DUPLICATE'],"", '');
111         $form .= "<table width='100%' cellpadding='0' cellspacing='0'>  <tr >   ";
112         if ($action != 'ShowDuplicates') 
113         {
114                 $form .= "<td > &nbsp;</td>";
115         }
116
117         require_once('include/formbase.php');
118         $form .= getPostToForm();
119
120         if(isset($rows[0])){
121                 foreach ($rows[0] as $key=>$value){
122                         if($key != 'id'){
123                                         $form .= "<td scope='col' >". $mod_strings[$mod_strings['db_'.$key]]. "</td>";
124                         }
125                 }
126                 $form .= "</tr>";
127         }
128         $rowColor = 'oddListRowS1';
129         foreach($rows as $row){
130
131                 $form .= "<tr class='$rowColor'>";
132                 if ($action != 'ShowDuplicates') 
133                         $form .= "<td width='1%' nowrap='nowrap' ><a href='#' onClick=\"document.dupProspects.selectedProspect.value='${row['id']}';document.dupProspects.submit() \">[${app_strings['LBL_SELECT_BUTTON_LABEL']}]</a>&nbsp;&nbsp;</td>\n";
134                 
135                 $wasSet = false;
136
137                 foreach ($row as $key=>$value) {
138             if($key != 'id') {
139                 if(!$wasSet) {
140                     $form .= "<td scope='row' ><a target='_blank' href='index.php?module=Prospects&action=DetailView&record=${row['id']}'>$value</a></td>\n";
141                     $wasSet = true;
142                 }
143                 else {
144                     $form .= "<td><a target='_blank' href='index.php?module=Prospects&action=DetailView&record=${row['id']}'>$value</a></td>\n";
145                 }
146             }
147                 }
148
149                 if($rowColor == 'evenListRowS1'){
150                         $rowColor = 'oddListRowS1';
151                 }else{
152                          $rowColor = 'evenListRowS1';
153                 }
154                 $form .= "</tr>";
155         }
156         $form .= "<tr ><td colspan='$cols' class='blackline'></td></tr>";
157         if ($action == 'ShowDuplicates') 
158         {
159                 $form .= "</table><br><input title='${app_strings['LBL_SAVE_BUTTON_TITLE']}' accessKey='${app_strings['LBL_SAVE_BUTTON_KEY']}' class='button' onclick=\"this.form.action.value='Save';\" type='submit' name='button' value='  ${app_strings['LBL_SAVE_BUTTON_LABEL']}  '> <input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='${app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onclick=\"this.form.action.value='ListView'; this.form.module.value='Prospects';\" type='submit' name='button' value='  ${app_strings['LBL_CANCEL_BUTTON_LABEL']}  '></form>";
160         }
161         else 
162         {
163                 $form .= "</table><br><input type='submit' class='button' name='ContinueProspect' value='${mod_strings['LNK_NEW_PROSPECT']}'></form>";
164         }
165         return $form;
166
167
168
169
170
171 }
172 function getWideFormBody($prefix, $mod='',$formname='',  $prospect = ''){
173         if(!ACLController::checkAccess('Prospects', 'edit', true)){
174                 return '';
175         }
176         
177         if(empty($prospect)){
178                 $prospect = new Prospect();
179         }
180         global $mod_strings;
181 $temp_strings = $mod_strings;
182 if(!empty($mod)){
183         global $current_language;
184         $mod_strings = return_module_language($current_language, $mod);
185 }
186                 global $app_strings;
187                 global $current_user;
188                 global $app_list_strings;
189                 $primary_address_country_options = get_select_options_with_id($app_list_strings['countries_dom'], $prospect->primary_address_country);
190                 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
191                 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
192                 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
193                 $lbl_phone = $mod_strings['LBL_OFFICE_PHONE'];
194                 $lbl_address =  $mod_strings['LBL_PRIMARY_ADDRESS'];
195                 $user_id = $current_user->id;
196                 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
197                 $form = <<<EOQ
198                 <input type="hidden" name="${prefix}record" value="">
199                 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
200                 <table border='0' celpadding="0" cellspacing="0" width='100%'>
201                 <tr>
202                 <td nowrap class='dataLabel'>$lbl_first_name</td>
203                 <td class='dataLabel'>$lbl_last_name&nbsp;<span class="required">$lbl_required_symbol</span></td>
204                 <td nowrap class='dataLabel'>&nbsp;</td>
205                 <td class='dataLabel'>&nbsp;</td>
206                 </tr>
207                 <tr>
208                 <td nowrap  class='dataField'><input name="${prefix}first_name" type="text" value="{$prospect->first_name}"></td>
209                 <td class='dataField'><input name='${prefix}last_name' type="text" value="{$prospect->last_name}"></td>
210                 <td class='dataField' nowrap>&nbsp;</td>
211                 <td class='dataField'>&nbsp;</td>
212                 </tr>
213
214                 <tr>
215                 <td class='dataLabel' nowrap>${mod_strings['LBL_TITLE']}</td>
216                 <td class='dataLabel' nowrap>${mod_strings['LBL_DEPARTMENT']}</td>
217                 <td class='dataLabel' nowrap>&nbsp;</td>
218                 <td class='dataLabel' nowrap>&nbsp;</td>
219                 </tr>
220                 <tr>
221                 <td class='dataField' nowrap><input name='${prefix}title' type="text" value="{$prospect->title}"></td>
222                 <td class='dataField' nowrap><input name='${prefix}department' type="text" value="{$prospect->department}"></td>
223                 <td class='dataField' nowra>&nbsp;</td>
224                 <td class='dataField' nowrap>&nbsp;</td>
225                 </tr>
226
227                 <tr>
228                 <td nowrap colspan='4' class='dataLabel'>$lbl_address</td>
229                 </tr>
230
231                 <tr>
232                 <td nowrap colspan='4' class='dataField'><input type='text' name='${prefix}primary_address_street' size='80' value='{$prospect->primary_address_street}'></td>
233                 </tr>
234
235                 <tr>
236                 <td class='dataLabel'>${mod_strings['LBL_CITY']}</td>
237                 <td class='dataLabel'>${mod_strings['LBL_STATE']}</td>
238                 <td class='dataLabel'>${mod_strings['LBL_POSTAL_CODE']}</td>
239                 <td class='dataLabel'>${mod_strings['LBL_COUNTRY']}</td>
240                 </tr>
241
242                 <tr>
243                 <td class='dataField'><input name='${prefix}primary_address_city'  maxlength='100' value='{$prospect->primary_address_city}'></td>
244                 <td class='dataField'><input name='${prefix}primary_address_state'  maxlength='100' value='{$prospect->primary_address_state}'></td>
245                 <td class='dataField'><input name='${prefix}primary_address_postalcode'  maxlength='100' value='{$prospect->primary_address_postalcode}'></td>
246                 <td class='dataField'><select name='${prefix}primary_address_country' size='1'>{$primary_address_country_options}</select></td>
247                 </tr>
248
249
250                 <tr>
251                 <td nowrap class='dataLabel'>$lbl_phone</td>
252                 <td nowrap class='dataLabel'>${mod_strings['LBL_MOBILE_PHONE']}</td>
253                 <td nowrap class='dataLabel'>${mod_strings['LBL_FAX_PHONE']}</td>
254                 <td nowrap class='dataLabel'>${mod_strings['LBL_HOME_PHONE']}</td>
255                 </tr>
256
257                 <tr>
258                 <td nowrap class='dataField'><input name='${prefix}phone_work' type="text" value="{$prospect->phone_work}"></td>
259                 <td nowrap class='dataField'><input name='${prefix}phone_mobile' type="text" value="{$prospect->phone_mobile}"></td>
260                 <td nowrap class='dataField'><input name='${prefix}phone_fax' type="text" value="{$prospect->phone_fax}"></td>
261                 <td nowrap class='dataField'><input name='${prefix}phone_home' type="text" value="{$prospect->phone_home}"></td>
262                 </tr>
263
264                 <tr>
265                 <td class='dataLabel' nowrap>$lbl_email_address</td>
266                 <td class='dataLabel' nowrap>${mod_strings['LBL_OTHER_EMAIL_ADDRESS']}</td>
267                 <td class='dataLabel' nowrap>&nbsp;</td>
268                 <td class='dataLabel' nowrap>&nbsp;</td>
269                 </tr>
270
271                 <tr>
272                 <td class='dataField' nowrap><input name='${prefix}email1' type="text" value="{$prospect->email1}"></td>
273                 <td class='dataField' nowrap><input name='${prefix}email2' type="text" value="{$prospect->email2}"></td>
274                 <td class='dataField' nowrap>&nbsp;</td>
275                 <td class='dataField' nowrap>&nbsp;</td>
276                 </tr>
277
278
279                 <tr>
280                 <td nowrap colspan='4' class='dataLabel'>${mod_strings['LBL_DESCRIPTION']}</td>
281                 </tr>
282                 <tr>
283                 <td nowrap colspan='4' class='dataField'><textarea cols='80' rows='4' name='${prefix}description' >{$prospect->description}</textarea></td>
284                 </tr>
285                 </table>
286                 <input type='hidden' name='${prefix}alt_address_city' value='{$prospect->alt_address_city}'><input type='hidden' name='${prefix}alt_address_state'   value='{$prospect->alt_address_state}'><input type='hidden' name='${prefix}alt_address_postalcode'   value='{$prospect->alt_address_postalcode}'><input type='hidden' name='${prefix}alt_address_country'  value='{$prospect->alt_address_country}'>
287                 <input type='hidden' name='${prefix}do_not_call'  value='{$prospect->do_not_call}'><input type='hidden' name='${prefix}email_opt_out'  value='{$prospect->email_opt_out}'>
288 EOQ;
289
290
291
292 $javascript = new javascript();
293 $javascript->setFormName($formname);
294 $javascript->setSugarBean(new Prospect());
295 $javascript->addField('email1','false',$prefix);
296 $javascript->addField('email2','false',$prefix);
297 $javascript->addRequiredFields($prefix);
298 $form .=$javascript->getScript();
299 $mod_strings = $temp_strings;
300 return $form;
301 }
302
303 function getFormBody($prefix, $mod='', $formname=''){
304         if(!ACLController::checkAccess('Prospects', 'edit', true)){
305                 return '';
306         }
307 global $mod_strings;
308 $temp_strings = $mod_strings;
309 if(!empty($mod)){
310         global $current_language;
311         $mod_strings = return_module_language($current_language, $mod);
312 }
313                 global $app_strings;
314                 global $current_user;
315                 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
316                 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
317                 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
318                 $lbl_phone = $mod_strings['LBL_PHONE'];
319                 $user_id = $current_user->id;
320                 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
321 if ($formname == 'EmailEditView')
322 {
323                 $form = <<<EOQ
324                 <input type="hidden" name="${prefix}record" value="">
325                 <input type="hidden" name="${prefix}email2" value="">
326                 <input type="hidden" name="${prefix}phone_work" value="">
327                 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
328                 $lbl_first_name<br>
329                 <input name="${prefix}first_name" type="text" value="" size=10><br>
330                 $lbl_last_name&nbsp;<span class="required">$lbl_required_symbol</span><br>
331                 <input name='${prefix}last_name' type="text" value="" size=10><br>
332                 $lbl_email_address&nbsp;<span class="required">$lbl_required_symbol</span><br>
333                 <input name='${prefix}email1' type="text" value=""><br><br>
334
335 EOQ;
336 }
337 else
338 {
339                 $form = <<<EOQ
340                 <input type="hidden" name="${prefix}record" value="">
341                 <input type="hidden" name="${prefix}email2" value="">
342                 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
343                 $lbl_first_name<br>
344                 <input name="${prefix}first_name" type="text" value=""><br>
345                 $lbl_last_name&nbsp;<span class="required">$lbl_required_symbol</span><br>
346                 <input name='${prefix}last_name' type="text" value=""><br>
347                 $lbl_phone<br>
348                 <input name='${prefix}phone_work' type="text" value=""><br>
349                 $lbl_email_address<br>
350                 <input name='${prefix}email1' type="text" value=""><br><br>
351
352 EOQ;
353 }
354
355
356 $javascript = new javascript();
357 $javascript->setFormName($formname);
358 $javascript->setSugarBean(new Prospect());
359 $javascript->addField('email1','false',$prefix);
360 $javascript->addRequiredFields($prefix);
361
362 $form .=$javascript->getScript();
363 $mod_strings = $temp_strings;
364 return $form;
365
366 }
367 function getForm($prefix, $mod=''){
368 if(!ACLController::checkAccess('Prospects', 'edit', true)){
369                 return '';
370         }
371 if(!empty($mod)){
372         global $current_language;
373         $mod_strings = return_module_language($current_language, $mod);
374 }else global $mod_strings;
375 global $app_strings;
376
377 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
378 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
379 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
380
381
382 $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
383 $the_form .= <<<EOQ
384
385                 <form name="${prefix}ProspectSave" onSubmit="return check_form('${prefix}ProspectSave')" method="POST" action="index.php">
386                         <input type="hidden" name="${prefix}module" value="Prospects">
387                         <input type="hidden" name="${prefix}action" value="Save">
388 EOQ;
389 $the_form .= $this->getFormBody($prefix,'Prospects', "${prefix}ProspectSave");
390 $the_form .= <<<EOQ
391                 <input title="$lbl_save_button_title" accessKey="$lbl_save_button_key" class="button" type="submit" name="${prefix}button" value="  $lbl_save_button_label  " >
392                 </form>
393
394 EOQ;
395 $the_form .= get_left_form_footer();
396 $the_form .= get_validate_record_js();
397
398 return $the_form;
399
400
401 }
402
403
404 function handleSave($prefix,$redirect=true, $useRequired=false){
405         global $theme;
406         
407         
408         
409         
410         require_once('include/formbase.php');
411         
412         global $timedate;
413         
414         
415         $focus = new Prospect();
416         if($useRequired &&  !checkRequired($prefix, array_keys($focus->required_fields))){
417                 return null;
418         }
419         $focus = populateFromPost($prefix, $focus);
420         if(!$focus->ACLAccess('Save')){
421                 return null;
422         }
423         if (!isset($GLOBALS['check_notify'])) $GLOBALS['check_notify']=false;
424         
425         if (!isset($_POST[$prefix.'email_opt_out'])) $focus->email_opt_out = 0;
426         if (!isset($_POST[$prefix.'do_not_call'])) $focus->do_not_call = 0;
427         
428         if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
429                 /*
430                 // we don't check dupes on Prospects - this is the dirtiest data in the system
431                 //$duplicateProspects = $this->checkForDuplicates($prefix);
432                 if(isset($duplicateProspects)){
433                         $get='module=Prospects&action=ShowDuplicates';
434                         
435                         //add all of the post fields to redirect get string
436                         foreach ($focus->column_fields as $field) 
437                         {
438                                 if (!empty($focus->$field))
439                                 {
440                                         $get .= "&Prospects$field=".urlencode($focus->$field);
441                                 }       
442                         }
443                         
444                         foreach ($focus->additional_column_fields as $field) 
445                         {
446                                 if (!empty($focus->$field))
447                                 {
448                                         $get .= "&Prospects$field=".urlencode($focus->$field);
449                                 }       
450                         }
451
452                         //create list of suspected duplicate prospect id's in redirect get string
453                         $i=0;
454                         foreach ($duplicateProspects as $prospect)
455                         {
456                                 $get .= "&duplicate[$i]=".$prospect['id'];
457                                 $i++;
458                         }
459
460                         //add return_module, return_action, and return_id to redirect get string
461                         $get .= "&return_module=";
462                         if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
463                         else $get .= "Prospects";
464                         $get .= "&return_action=";
465                         if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
466                         else $get .= "DetailView";
467                         if(!empty($_POST['return_id'])) $get .= "&return_id=".$_POST['return_id'];
468
469                         //now redirect the post to modules/Prospects/ShowDuplicates.php
470                         header("Location: index.php?$get");
471                         return null;
472                 }*/
473         }
474         global $current_user;
475
476         $focus->save($GLOBALS['check_notify']);
477         $return_id = $focus->id;
478     
479         $GLOBALS['log']->debug("Saved record with id of ".$return_id);
480     if(isset($_POST['popup']) && $_POST['popup'] == 'true') {
481         $get = '&module=';
482         if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
483         else $get .= 'Prospects';
484         $get .= '&action=';
485         if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
486         else $get .= 'Popup';
487         if(!empty($_POST['return_id'])) $get .= '&return_id='.$_POST['return_id'];
488         if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
489         if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
490         if(!empty($_POST['to_pdf'])) $get .= '&to_pdf='.$_POST['to_pdf'];
491         $get .= '&first_name=' . $focus->first_name;
492         $get .= '&last_name=' . $focus->last_name;
493         $get .= '&query=true';
494         header("Location: index.php?$get");
495         return;
496     }
497         if($redirect){
498             require_once('include/formbase.php');
499             handleRedirect($return_id, 'Prospects');
500         }else{
501                 return $focus;
502         }
503 }
504
505 }
506
507
508 ?>