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.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: Base form for prospect
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
46 class ProspectFormBase {
48 function checkForDuplicates($prefix){
50 require_once('include/formbase.php');
52 $focus = new Prospect();
53 if(!checkRequired($prefix, array_keys($focus->required_fields))){
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'] ."')";
61 $query = $baseQuery ." last_name = '". $_POST[$prefix.'last_name'] ."'";
63 if(!empty($_POST[$prefix.'email1'])){
65 $query = $baseQuery. " email1='". $_POST[$prefix.'email1'] . "' or email2 = '". $_POST[$prefix.'email1'] ."'";
67 $query .= "or email1='". $_POST[$prefix.'email1'] . "' or email2 = '". $_POST[$prefix.'email1'] ."'";
70 if(!empty($_POST[$prefix.'email2'])){
72 $query = $baseQuery. " email1='". $_POST[$prefix.'email2'] . "' or email2 = '". $_POST[$prefix.'email2'] ."'";
74 $query .= "or email1='". $_POST[$prefix.'email2'] . "' or email2 = '". $_POST[$prefix.'email2'] ."'";
82 $db = DBManagerFactory::getInstance();
83 $result = $db->query($query.');');
84 if($db->getRowCount($result) == 0){
87 for($i = 0; $i < $db->getRowCount($result); $i++){
88 $rows[$i] = $db->fetchByAssoc($result, $i);
96 function buildTableForm($rows, $mod=''){
99 global $current_language;
100 $mod_strings = return_module_language($current_language, $mod);
101 }else global $mod_strings;
103 $cols = sizeof($rows[0]) * 2 + 1;
104 if ($action != 'ShowDuplicates')
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=''>";
111 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_SHOW_DUPLICATES']. '</td></tr><tr><td height="20"></td></tr></table>';
113 $form .= get_form_header($mod_strings['LBL_DUPLICATE'],"", '');
114 $form .= "<table width='100%' cellpadding='0' cellspacing='0'> <tr > ";
115 if ($action != 'ShowDuplicates')
117 $form .= "<td > </td>";
120 require_once('include/formbase.php');
121 $form .= getPostToForm();
124 foreach ($rows[0] as $key=>$value){
126 $form .= "<td scope='col' >". $mod_strings[$mod_strings['db_'.$key]]. "</td>";
131 $rowColor = 'oddListRowS1';
132 foreach($rows as $row){
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> </td>\n";
140 foreach ($row as $key=>$value) {
143 $form .= "<td scope='row' ><a target='_blank' href='index.php?module=Prospects&action=DetailView&record=${row['id']}'>$value</a></td>\n";
147 $form .= "<td><a target='_blank' href='index.php?module=Prospects&action=DetailView&record=${row['id']}'>$value</a></td>\n";
152 if($rowColor == 'evenListRowS1'){
153 $rowColor = 'oddListRowS1';
155 $rowColor = 'evenListRowS1';
159 $form .= "<tr ><td colspan='$cols' class='blackline'></td></tr>";
160 if ($action == 'ShowDuplicates')
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>";
166 $form .= "</table><br><input type='submit' class='button' name='ContinueProspect' value='${mod_strings['LNK_NEW_PROSPECT']}'></form>";
175 function getWideFormBody($prefix, $mod='',$formname='', $prospect = ''){
176 if(!ACLController::checkAccess('Prospects', 'edit', true)){
180 if(empty($prospect)){
181 $prospect = new Prospect();
184 $temp_strings = $mod_strings;
186 global $current_language;
187 $mod_strings = return_module_language($current_language, $mod);
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'];
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%'>
205 <td nowrap class='dataLabel'>$lbl_first_name</td>
206 <td class='dataLabel'>$lbl_last_name <span class="required">$lbl_required_symbol</span></td>
207 <td nowrap class='dataLabel'> </td>
208 <td class='dataLabel'> </td>
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> </td>
214 <td class='dataField'> </td>
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> </td>
221 <td class='dataLabel' nowrap> </td>
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> </td>
227 <td class='dataField' nowrap> </td>
231 <td nowrap colspan='4' class='dataLabel'>$lbl_address</td>
235 <td nowrap colspan='4' class='dataField'><input type='text' name='${prefix}primary_address_street' size='80' value='{$prospect->primary_address_street}'></td>
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>
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>
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>
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>
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> </td>
271 <td class='dataLabel' nowrap> </td>
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> </td>
278 <td class='dataField' nowrap> </td>
283 <td nowrap colspan='4' class='dataLabel'>${mod_strings['LBL_DESCRIPTION']}</td>
286 <td nowrap colspan='4' class='dataField'><textarea cols='80' rows='4' name='${prefix}description' >{$prospect->description}</textarea></td>
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}'>
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;
306 function getFormBody($prefix, $mod='', $formname=''){
307 if(!ACLController::checkAccess('Prospects', 'edit', true)){
311 $temp_strings = $mod_strings;
313 global $current_language;
314 $mod_strings = return_module_language($current_language, $mod);
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')
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}'>
332 <input name="${prefix}first_name" type="text" value="" size=10><br>
333 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
334 <input name='${prefix}last_name' type="text" value="" size=10><br>
335 $lbl_email_address <span class="required">$lbl_required_symbol</span><br>
336 <input name='${prefix}email1' type="text" value=""><br><br>
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}'>
347 <input name="${prefix}first_name" type="text" value=""><br>
348 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
349 <input name='${prefix}last_name' type="text" value=""><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>
359 $javascript = new javascript();
360 $javascript->setFormName($formname);
361 $javascript->setSugarBean(new Prospect());
362 $javascript->addField('email1','false',$prefix);
363 $javascript->addRequiredFields($prefix);
365 $form .=$javascript->getScript();
366 $mod_strings = $temp_strings;
370 function getForm($prefix, $mod=''){
371 if(!ACLController::checkAccess('Prospects', 'edit', true)){
375 global $current_language;
376 $mod_strings = return_module_language($current_language, $mod);
377 }else global $mod_strings;
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'];
385 $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
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">
392 $the_form .= $this->getFormBody($prefix,'Prospects', "${prefix}ProspectSave");
394 <input title="$lbl_save_button_title" accessKey="$lbl_save_button_key" class="button" type="submit" name="${prefix}button" value=" $lbl_save_button_label " >
398 $the_form .= get_left_form_footer();
399 $the_form .= get_validate_record_js();
407 function handleSave($prefix,$redirect=true, $useRequired=false){
413 require_once('include/formbase.php');
418 $focus = new Prospect();
419 if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))){
422 $focus = populateFromPost($prefix, $focus);
423 if(!$focus->ACLAccess('Save')){
426 if (!isset($GLOBALS['check_notify'])) $GLOBALS['check_notify']=false;
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;
431 if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
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';
438 //add all of the post fields to redirect get string
439 foreach ($focus->column_fields as $field)
441 if (!empty($focus->$field))
443 $get .= "&Prospects$field=".urlencode($focus->$field);
447 foreach ($focus->additional_column_fields as $field)
449 if (!empty($focus->$field))
451 $get .= "&Prospects$field=".urlencode($focus->$field);
455 //create list of suspected duplicate prospect id's in redirect get string
457 foreach ($duplicateProspects as $prospect)
459 $get .= "&duplicate[$i]=".$prospect['id'];
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'];
472 //now redirect the post to modules/Prospects/ShowDuplicates.php
473 header("Location: index.php?$get");
477 global $current_user;
479 $focus->save($GLOBALS['check_notify']);
480 $return_id = $focus->id;
482 $GLOBALS['log']->debug("Saved record with id of ".$return_id);
483 if(isset($_POST['popup']) && $_POST['popup'] == 'true') {
485 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
486 else $get .= 'Prospects';
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");
501 require_once('include/formbase.php');
502 handleRedirect($return_id, 'Prospects');