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-2013 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 while($row = $db->fetchByAssoc($result)) {
87 if(count($rows) > 0) return $rows;
93 function buildTableForm($rows, $mod=''){
96 global $current_language;
97 $mod_strings = return_module_language($current_language, $mod);
98 }else global $mod_strings;
100 $cols = sizeof($rows[0]) * 2 + 1;
101 if ($action != 'ShowDuplicates')
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=''>";
108 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_SHOW_DUPLICATES']. '</td></tr><tr><td height="20"></td></tr></table>';
110 $form .= get_form_header($mod_strings['LBL_DUPLICATE'],"", '');
111 $form .= "<table width='100%' cellpadding='0' cellspacing='0'> <tr > ";
112 if ($action != 'ShowDuplicates')
114 $form .= "<td > </td>";
117 require_once('include/formbase.php');
118 $form .= getPostToForm();
121 foreach ($rows[0] as $key=>$value){
123 $form .= "<td scope='col' >". $mod_strings[$mod_strings['db_'.$key]]. "</td>";
128 $rowColor = 'oddListRowS1';
129 foreach($rows as $row){
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> </td>\n";
137 foreach ($row as $key=>$value) {
140 $form .= "<td scope='row' ><a target='_blank' href='index.php?module=Prospects&action=DetailView&record=${row['id']}'>$value</a></td>\n";
144 $form .= "<td><a target='_blank' href='index.php?module=Prospects&action=DetailView&record=${row['id']}'>$value</a></td>\n";
149 if($rowColor == 'evenListRowS1'){
150 $rowColor = 'oddListRowS1';
152 $rowColor = 'evenListRowS1';
156 $form .= "<tr ><td colspan='$cols' class='blackline'></td></tr>";
157 if ($action == 'ShowDuplicates')
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>";
163 $form .= "</table><br><input type='submit' class='button' name='ContinueProspect' value='${mod_strings['LNK_NEW_PROSPECT']}'></form>";
172 function getWideFormBody($prefix, $mod='',$formname='', $prospect = ''){
173 if(!ACLController::checkAccess('Prospects', 'edit', true)){
177 if(empty($prospect)){
178 $prospect = new Prospect();
181 $temp_strings = $mod_strings;
183 global $current_language;
184 $mod_strings = return_module_language($current_language, $mod);
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'];
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%'>
202 <td nowrap class='dataLabel'>$lbl_first_name</td>
203 <td class='dataLabel'>$lbl_last_name <span class="required">$lbl_required_symbol</span></td>
204 <td nowrap class='dataLabel'> </td>
205 <td class='dataLabel'> </td>
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> </td>
211 <td class='dataField'> </td>
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> </td>
218 <td class='dataLabel' nowrap> </td>
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> </td>
224 <td class='dataField' nowrap> </td>
228 <td nowrap colspan='4' class='dataLabel'>$lbl_address</td>
232 <td nowrap colspan='4' class='dataField'><input type='text' name='${prefix}primary_address_street' size='80' value='{$prospect->primary_address_street}'></td>
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>
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>
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>
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>
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> </td>
268 <td class='dataLabel' nowrap> </td>
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> </td>
275 <td class='dataField' nowrap> </td>
280 <td nowrap colspan='4' class='dataLabel'>${mod_strings['LBL_DESCRIPTION']}</td>
283 <td nowrap colspan='4' class='dataField'><textarea cols='80' rows='4' name='${prefix}description' >{$prospect->description}</textarea></td>
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}'>
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;
303 function getFormBody($prefix, $mod='', $formname=''){
304 if(!ACLController::checkAccess('Prospects', 'edit', true)){
308 $temp_strings = $mod_strings;
310 global $current_language;
311 $mod_strings = return_module_language($current_language, $mod);
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')
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}'>
329 <input name="${prefix}first_name" type="text" value="" size=10><br>
330 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
331 <input name='${prefix}last_name' type="text" value="" size=10><br>
332 $lbl_email_address <span class="required">$lbl_required_symbol</span><br>
333 <input name='${prefix}email1' type="text" value=""><br><br>
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}'>
344 <input name="${prefix}first_name" type="text" value=""><br>
345 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
346 <input name='${prefix}last_name' type="text" value=""><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>
356 $javascript = new javascript();
357 $javascript->setFormName($formname);
358 $javascript->setSugarBean(new Prospect());
359 $javascript->addField('email1','false',$prefix);
360 $javascript->addRequiredFields($prefix);
362 $form .=$javascript->getScript();
363 $mod_strings = $temp_strings;
367 function getForm($prefix, $mod=''){
368 if(!ACLController::checkAccess('Prospects', 'edit', true)){
372 global $current_language;
373 $mod_strings = return_module_language($current_language, $mod);
374 }else global $mod_strings;
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'];
382 $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
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">
389 $the_form .= $this->getFormBody($prefix,'Prospects', "${prefix}ProspectSave");
391 <input title="$lbl_save_button_title" accessKey="$lbl_save_button_key" class="button" type="submit" name="${prefix}button" value=" $lbl_save_button_label " >
395 $the_form .= get_left_form_footer();
396 $the_form .= get_validate_record_js();
404 function handleSave($prefix,$redirect=true, $useRequired=false){
410 require_once('include/formbase.php');
415 $focus = new Prospect();
416 if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))){
419 $focus = populateFromPost($prefix, $focus);
420 if(!$focus->ACLAccess('Save')){
423 if (!isset($GLOBALS['check_notify'])) $GLOBALS['check_notify']=false;
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;
428 if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
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';
435 //add all of the post fields to redirect get string
436 foreach ($focus->column_fields as $field)
438 if (!empty($focus->$field))
440 $get .= "&Prospects$field=".urlencode($focus->$field);
444 foreach ($focus->additional_column_fields as $field)
446 if (!empty($focus->$field))
448 $get .= "&Prospects$field=".urlencode($focus->$field);
452 //create list of suspected duplicate prospect id's in redirect get string
454 foreach ($duplicateProspects as $prospect)
456 $get .= "&duplicate[$i]=".$prospect['id'];
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'];
469 //now redirect the post to modules/Prospects/ShowDuplicates.php
470 header("Location: index.php?$get");
474 global $current_user;
476 $focus->save($GLOBALS['check_notify']);
477 $return_id = $focus->id;
479 $GLOBALS['log']->debug("Saved record with id of ".$return_id);
480 if(isset($_POST['popup']) && $_POST['popup'] == 'true') {
482 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
483 else $get .= 'Prospects';
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");
498 require_once('include/formbase.php');
499 handleRedirect($return_id, 'Prospects');