]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Prospects/ProspectFormBase.php
Release 6.2.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                 if($db->getRowCount($result) == 0){
85                         return null;
86                 }
87                 for($i = 0; $i < $db->getRowCount($result); $i++){
88                         $rows[$i] = $db->fetchByAssoc($result, $i);
89                 }
90                 return $rows;
91         }
92         return null;
93 }
94
95
96 function buildTableForm($rows, $mod=''){
97         global $action;
98         if(!empty($mod)){
99         global $current_language;
100         $mod_strings = return_module_language($current_language, $mod);
101         }else global $mod_strings;
102         global $app_strings;
103         $cols = sizeof($rows[0]) * 2 + 1;
104         if ($action != 'ShowDuplicates') 
105         {
106                 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_DUPLICATE']. '</td></tr><tr><td height="20"></td></tr></table>';
107                 $form .= "<form action='index.php' method='post' name='dupProspects'><input type='hidden' name='selectedProspect' value=''>";
108         }
109         else 
110         {
111                 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_SHOW_DUPLICATES']. '</td></tr><tr><td height="20"></td></tr></table>';
112         }
113         $form .= get_form_header($mod_strings['LBL_DUPLICATE'],"", '');
114         $form .= "<table width='100%' cellpadding='0' cellspacing='0'>  <tr >   ";
115         if ($action != 'ShowDuplicates') 
116         {
117                 $form .= "<td > &nbsp;</td>";
118         }
119
120         require_once('include/formbase.php');
121         $form .= getPostToForm();
122
123         if(isset($rows[0])){
124                 foreach ($rows[0] as $key=>$value){
125                         if($key != 'id'){
126                                         $form .= "<td scope='col' >". $mod_strings[$mod_strings['db_'.$key]]. "</td>";
127                         }
128                 }
129                 $form .= "</tr>";
130         }
131         $rowColor = 'oddListRowS1';
132         foreach($rows as $row){
133
134                 $form .= "<tr class='$rowColor'>";
135                 if ($action != 'ShowDuplicates') 
136                         $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";
137                 
138                 $wasSet = false;
139
140                 foreach ($row as $key=>$value) {
141             if($key != 'id') {
142                 if(!$wasSet) {
143                     $form .= "<td scope='row' ><a target='_blank' href='index.php?module=Prospects&action=DetailView&record=${row['id']}'>$value</a></td>\n";
144                     $wasSet = true;
145                 }
146                 else {
147                     $form .= "<td><a target='_blank' href='index.php?module=Prospects&action=DetailView&record=${row['id']}'>$value</a></td>\n";
148                 }
149             }
150                 }
151
152                 if($rowColor == 'evenListRowS1'){
153                         $rowColor = 'oddListRowS1';
154                 }else{
155                          $rowColor = 'evenListRowS1';
156                 }
157                 $form .= "</tr>";
158         }
159         $form .= "<tr ><td colspan='$cols' class='blackline'></td></tr>";
160         if ($action == 'ShowDuplicates') 
161         {
162                 $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>";
163         }
164         else 
165         {
166                 $form .= "</table><br><input type='submit' class='button' name='ContinueProspect' value='${mod_strings['LNK_NEW_PROSPECT']}'></form>";
167         }
168         return $form;
169
170
171
172
173
174 }
175 function getWideFormBody($prefix, $mod='',$formname='',  $prospect = ''){
176         if(!ACLController::checkAccess('Prospects', 'edit', true)){
177                 return '';
178         }
179         
180         if(empty($prospect)){
181                 $prospect = new Prospect();
182         }
183         global $mod_strings;
184 $temp_strings = $mod_strings;
185 if(!empty($mod)){
186         global $current_language;
187         $mod_strings = return_module_language($current_language, $mod);
188 }
189                 global $app_strings;
190                 global $current_user;
191                 global $app_list_strings;
192                 $primary_address_country_options = get_select_options_with_id($app_list_strings['countries_dom'], $prospect->primary_address_country);
193                 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
194                 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
195                 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
196                 $lbl_phone = $mod_strings['LBL_OFFICE_PHONE'];
197                 $lbl_address =  $mod_strings['LBL_PRIMARY_ADDRESS'];
198                 $user_id = $current_user->id;
199                 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
200                 $form = <<<EOQ
201                 <input type="hidden" name="${prefix}record" value="">
202                 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
203                 <table border='0' celpadding="0" cellspacing="0" width='100%'>
204                 <tr>
205                 <td nowrap class='dataLabel'>$lbl_first_name</td>
206                 <td class='dataLabel'>$lbl_last_name&nbsp;<span class="required">$lbl_required_symbol</span></td>
207                 <td nowrap class='dataLabel'>&nbsp;</td>
208                 <td class='dataLabel'>&nbsp;</td>
209                 </tr>
210                 <tr>
211                 <td nowrap  class='dataField'><input name="${prefix}first_name" type="text" value="{$prospect->first_name}"></td>
212                 <td class='dataField'><input name='${prefix}last_name' type="text" value="{$prospect->last_name}"></td>
213                 <td class='dataField' nowrap>&nbsp;</td>
214                 <td class='dataField'>&nbsp;</td>
215                 </tr>
216
217                 <tr>
218                 <td class='dataLabel' nowrap>${mod_strings['LBL_TITLE']}</td>
219                 <td class='dataLabel' nowrap>${mod_strings['LBL_DEPARTMENT']}</td>
220                 <td class='dataLabel' nowrap>&nbsp;</td>
221                 <td class='dataLabel' nowrap>&nbsp;</td>
222                 </tr>
223                 <tr>
224                 <td class='dataField' nowrap><input name='${prefix}title' type="text" value="{$prospect->title}"></td>
225                 <td class='dataField' nowrap><input name='${prefix}department' type="text" value="{$prospect->department}"></td>
226                 <td class='dataField' nowra>&nbsp;</td>
227                 <td class='dataField' nowrap>&nbsp;</td>
228                 </tr>
229
230                 <tr>
231                 <td nowrap colspan='4' class='dataLabel'>$lbl_address</td>
232                 </tr>
233
234                 <tr>
235                 <td nowrap colspan='4' class='dataField'><input type='text' name='${prefix}primary_address_street' size='80' value='{$prospect->primary_address_street}'></td>
236                 </tr>
237
238                 <tr>
239                 <td class='dataLabel'>${mod_strings['LBL_CITY']}</td>
240                 <td class='dataLabel'>${mod_strings['LBL_STATE']}</td>
241                 <td class='dataLabel'>${mod_strings['LBL_POSTAL_CODE']}</td>
242                 <td class='dataLabel'>${mod_strings['LBL_COUNTRY']}</td>
243                 </tr>
244
245                 <tr>
246                 <td class='dataField'><input name='${prefix}primary_address_city'  maxlength='100' value='{$prospect->primary_address_city}'></td>
247                 <td class='dataField'><input name='${prefix}primary_address_state'  maxlength='100' value='{$prospect->primary_address_state}'></td>
248                 <td class='dataField'><input name='${prefix}primary_address_postalcode'  maxlength='100' value='{$prospect->primary_address_postalcode}'></td>
249                 <td class='dataField'><select name='${prefix}primary_address_country' size='1'>{$primary_address_country_options}</select></td>
250                 </tr>
251
252
253                 <tr>
254                 <td nowrap class='dataLabel'>$lbl_phone</td>
255                 <td nowrap class='dataLabel'>${mod_strings['LBL_MOBILE_PHONE']}</td>
256                 <td nowrap class='dataLabel'>${mod_strings['LBL_FAX_PHONE']}</td>
257                 <td nowrap class='dataLabel'>${mod_strings['LBL_HOME_PHONE']}</td>
258                 </tr>
259
260                 <tr>
261                 <td nowrap class='dataField'><input name='${prefix}phone_work' type="text" value="{$prospect->phone_work}"></td>
262                 <td nowrap class='dataField'><input name='${prefix}phone_mobile' type="text" value="{$prospect->phone_mobile}"></td>
263                 <td nowrap class='dataField'><input name='${prefix}phone_fax' type="text" value="{$prospect->phone_fax}"></td>
264                 <td nowrap class='dataField'><input name='${prefix}phone_home' type="text" value="{$prospect->phone_home}"></td>
265                 </tr>
266
267                 <tr>
268                 <td class='dataLabel' nowrap>$lbl_email_address</td>
269                 <td class='dataLabel' nowrap>${mod_strings['LBL_OTHER_EMAIL_ADDRESS']}</td>
270                 <td class='dataLabel' nowrap>&nbsp;</td>
271                 <td class='dataLabel' nowrap>&nbsp;</td>
272                 </tr>
273
274                 <tr>
275                 <td class='dataField' nowrap><input name='${prefix}email1' type="text" value="{$prospect->email1}"></td>
276                 <td class='dataField' nowrap><input name='${prefix}email2' type="text" value="{$prospect->email2}"></td>
277                 <td class='dataField' nowrap>&nbsp;</td>
278                 <td class='dataField' nowrap>&nbsp;</td>
279                 </tr>
280
281
282                 <tr>
283                 <td nowrap colspan='4' class='dataLabel'>${mod_strings['LBL_DESCRIPTION']}</td>
284                 </tr>
285                 <tr>
286                 <td nowrap colspan='4' class='dataField'><textarea cols='80' rows='4' name='${prefix}description' >{$prospect->description}</textarea></td>
287                 </tr>
288                 </table>
289                 <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}'>
290                 <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}'>
291 EOQ;
292
293
294
295 $javascript = new javascript();
296 $javascript->setFormName($formname);
297 $javascript->setSugarBean(new Prospect());
298 $javascript->addField('email1','false',$prefix);
299 $javascript->addField('email2','false',$prefix);
300 $javascript->addRequiredFields($prefix);
301 $form .=$javascript->getScript();
302 $mod_strings = $temp_strings;
303 return $form;
304 }
305
306 function getFormBody($prefix, $mod='', $formname=''){
307         if(!ACLController::checkAccess('Prospects', 'edit', true)){
308                 return '';
309         }
310 global $mod_strings;
311 $temp_strings = $mod_strings;
312 if(!empty($mod)){
313         global $current_language;
314         $mod_strings = return_module_language($current_language, $mod);
315 }
316                 global $app_strings;
317                 global $current_user;
318                 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
319                 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
320                 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
321                 $lbl_phone = $mod_strings['LBL_PHONE'];
322                 $user_id = $current_user->id;
323                 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
324 if ($formname == 'EmailEditView')
325 {
326                 $form = <<<EOQ
327                 <input type="hidden" name="${prefix}record" value="">
328                 <input type="hidden" name="${prefix}email2" value="">
329                 <input type="hidden" name="${prefix}phone_work" value="">
330                 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
331                 $lbl_first_name<br>
332                 <input name="${prefix}first_name" type="text" value="" size=10><br>
333                 $lbl_last_name&nbsp;<span class="required">$lbl_required_symbol</span><br>
334                 <input name='${prefix}last_name' type="text" value="" size=10><br>
335                 $lbl_email_address&nbsp;<span class="required">$lbl_required_symbol</span><br>
336                 <input name='${prefix}email1' type="text" value=""><br><br>
337
338 EOQ;
339 }
340 else
341 {
342                 $form = <<<EOQ
343                 <input type="hidden" name="${prefix}record" value="">
344                 <input type="hidden" name="${prefix}email2" value="">
345                 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
346                 $lbl_first_name<br>
347                 <input name="${prefix}first_name" type="text" value=""><br>
348                 $lbl_last_name&nbsp;<span class="required">$lbl_required_symbol</span><br>
349                 <input name='${prefix}last_name' type="text" value=""><br>
350                 $lbl_phone<br>
351                 <input name='${prefix}phone_work' type="text" value=""><br>
352                 $lbl_email_address<br>
353                 <input name='${prefix}email1' type="text" value=""><br><br>
354
355 EOQ;
356 }
357
358
359 $javascript = new javascript();
360 $javascript->setFormName($formname);
361 $javascript->setSugarBean(new Prospect());
362 $javascript->addField('email1','false',$prefix);
363 $javascript->addRequiredFields($prefix);
364
365 $form .=$javascript->getScript();
366 $mod_strings = $temp_strings;
367 return $form;
368
369 }
370 function getForm($prefix, $mod=''){
371 if(!ACLController::checkAccess('Prospects', 'edit', true)){
372                 return '';
373         }
374 if(!empty($mod)){
375         global $current_language;
376         $mod_strings = return_module_language($current_language, $mod);
377 }else global $mod_strings;
378 global $app_strings;
379
380 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
381 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
382 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
383
384
385 $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
386 $the_form .= <<<EOQ
387
388                 <form name="${prefix}ProspectSave" onSubmit="return check_form('${prefix}ProspectSave')" method="POST" action="index.php">
389                         <input type="hidden" name="${prefix}module" value="Prospects">
390                         <input type="hidden" name="${prefix}action" value="Save">
391 EOQ;
392 $the_form .= $this->getFormBody($prefix,'Prospects', "${prefix}ProspectSave");
393 $the_form .= <<<EOQ
394                 <input title="$lbl_save_button_title" accessKey="$lbl_save_button_key" class="button" type="submit" name="${prefix}button" value="  $lbl_save_button_label  " >
395                 </form>
396
397 EOQ;
398 $the_form .= get_left_form_footer();
399 $the_form .= get_validate_record_js();
400
401 return $the_form;
402
403
404 }
405
406
407 function handleSave($prefix,$redirect=true, $useRequired=false){
408         global $theme;
409         
410         
411         
412         
413         require_once('include/formbase.php');
414         
415         global $timedate;
416         
417         
418         $focus = new Prospect();
419         if($useRequired &&  !checkRequired($prefix, array_keys($focus->required_fields))){
420                 return null;
421         }
422         $focus = populateFromPost($prefix, $focus);
423         if(!$focus->ACLAccess('Save')){
424                 return null;
425         }
426         if (!isset($GLOBALS['check_notify'])) $GLOBALS['check_notify']=false;
427         
428         if (!isset($_POST[$prefix.'email_opt_out'])) $focus->email_opt_out = 0;
429         if (!isset($_POST[$prefix.'do_not_call'])) $focus->do_not_call = 0;
430         
431         if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
432                 /*
433                 // we don't check dupes on Prospects - this is the dirtiest data in the system
434                 //$duplicateProspects = $this->checkForDuplicates($prefix);
435                 if(isset($duplicateProspects)){
436                         $get='module=Prospects&action=ShowDuplicates';
437                         
438                         //add all of the post fields to redirect get string
439                         foreach ($focus->column_fields as $field) 
440                         {
441                                 if (!empty($focus->$field))
442                                 {
443                                         $get .= "&Prospects$field=".urlencode($focus->$field);
444                                 }       
445                         }
446                         
447                         foreach ($focus->additional_column_fields as $field) 
448                         {
449                                 if (!empty($focus->$field))
450                                 {
451                                         $get .= "&Prospects$field=".urlencode($focus->$field);
452                                 }       
453                         }
454
455                         //create list of suspected duplicate prospect id's in redirect get string
456                         $i=0;
457                         foreach ($duplicateProspects as $prospect)
458                         {
459                                 $get .= "&duplicate[$i]=".$prospect['id'];
460                                 $i++;
461                         }
462
463                         //add return_module, return_action, and return_id to redirect get string
464                         $get .= "&return_module=";
465                         if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
466                         else $get .= "Prospects";
467                         $get .= "&return_action=";
468                         if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
469                         else $get .= "DetailView";
470                         if(!empty($_POST['return_id'])) $get .= "&return_id=".$_POST['return_id'];
471
472                         //now redirect the post to modules/Prospects/ShowDuplicates.php
473                         header("Location: index.php?$get");
474                         return null;
475                 }*/
476         }
477         global $current_user;
478
479         $focus->save($GLOBALS['check_notify']);
480         $return_id = $focus->id;
481     
482         $GLOBALS['log']->debug("Saved record with id of ".$return_id);
483     if(isset($_POST['popup']) && $_POST['popup'] == 'true') {
484         $get = '&module=';
485         if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
486         else $get .= 'Prospects';
487         $get .= '&action=';
488         if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
489         else $get .= 'Popup';
490         if(!empty($_POST['return_id'])) $get .= '&return_id='.$_POST['return_id'];
491         if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
492         if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
493         if(!empty($_POST['to_pdf'])) $get .= '&to_pdf='.$_POST['to_pdf'];
494         $get .= '&first_name=' . $focus->first_name;
495         $get .= '&last_name=' . $focus->last_name;
496         $get .= '&query=true';
497         header("Location: index.php?$get");
498         return;
499     }
500         if($redirect){
501             require_once('include/formbase.php');
502             handleRedirect($return_id, 'Prospects');
503         }else{
504                 return $focus;
505         }
506 }
507
508 }
509
510
511 ?>