]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Accounts/AccountFormBase.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Accounts / AccountFormBase.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-2012 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 account
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46 class AccountFormBase{
47
48
49 function checkForDuplicates($prefix){
50         require_once('include/formbase.php');
51         
52         $focus = new Account();
53         $query = '';
54         $baseQuery = 'select id, name, website, billing_address_city  from accounts where deleted!=1 and ';
55         if(!empty($_POST[$prefix.'name'])){
56                 $query = $baseQuery ."  name like '".$_POST[$prefix.'name']."%'";
57         }
58
59         if(!empty($_POST[$prefix.'billing_address_city']) || !empty($_POST[$prefix.'shipping_address_city'])){
60
61                 $temp_query = '';
62                 if(!empty($_POST[$prefix.'billing_address_city'])){
63                         if(empty($temp_query)){
64                                 $temp_query =  "  billing_address_city like '".$_POST[$prefix.'billing_address_city']."%'";
65                         }else {
66                                 $temp_query .= "or billing_address_city like '".$_POST[$prefix.'billing_address_city']."%'";
67                         }
68                 }
69                 if(!empty($_POST[$prefix.'shipping_address_city'])){
70                         if(empty($temp_query)){
71                                 $temp_query = "  shipping_address_city like '".$_POST[$prefix.'shipping_address_city']."%'";
72                         }else {
73                                 $temp_query .= "or shipping_address_city like '".$_POST[$prefix.'shipping_address_city']."%'";
74                         }
75                 }
76                 if(empty($query)){
77                         $query .= $baseQuery;
78                 }else{
79                         $query .= ' AND ';
80                 }
81                 $query .=   ' ('. $temp_query . ' ) ';
82
83         }
84
85         if(!empty($query)){
86                 $rows = array();
87                 global $db;
88                 $result = $db->query($query);
89                 $i=-1;
90                 while(($row=$db->fetchByAssoc($result)) != null) {
91                         $i++;
92                         $rows[$i] = $row;
93                 }
94                 if ($i==-1) return null;
95
96                 return $rows;
97         }
98         return null;
99 }
100
101
102 function buildTableForm($rows, $mod='Accounts'){
103         if(!ACLController::checkAccess('Accounts', 'edit', true)){
104                 return '';
105         }
106         global $action;
107         if(!empty($mod)){
108         global $current_language;
109         $mod_strings = return_module_language($current_language, $mod);
110         }else global $mod_strings;
111         global $app_strings;
112         $cols = sizeof($rows[0]) * 2 + 1;
113         if ($action != 'ShowDuplicates')
114         {
115                 $form = "<form action='index.php' method='post' id='dupAccounts'  name='dupAccounts'><input type='hidden' name='selectedAccount' value=''>";
116                 $form .= '<table width="100%"><tr><td>'.$mod_strings['MSG_DUPLICATE']. '</td></tr><tr><td height="20"></td></tr></table>';
117                 unset($_POST['selectedAccount']);
118         }
119         else
120         {
121                 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_SHOW_DUPLICATES']. '</td></tr><tr><td height="20"></td></tr></table>';
122         }
123
124     if(isset($_POST['return_action']) && $_POST['return_action'] == 'SubPanelViewer') {
125         $_POST['return_action'] = 'DetailView';
126     }
127
128     if(isset($_POST['return_action']) && $_POST['return_action'] == 'DetailView' && empty($_REQUEST['return_id'])) {
129         unset($_POST['return_action']);
130     }
131
132         $form .= "<table width='100%' cellpadding='0' cellspacing='0' class='list view' border='0'><tr class='pagination'><td colspan='$cols'><table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td>";
133         // handle buttons
134         if ($action == 'ShowDuplicates') {
135                 $return_action = 'ListView'; // cn: bug 6658 - hardcoded return action break popup -> create -> duplicate -> cancel
136                 $return_action = (isset($_REQUEST['return_action']) && !empty($_REQUEST['return_action'])) ? $_REQUEST['return_action'] : $return_action;
137                 $form .= "<input type='hidden' name='selectedAccount' id='selectedAccount' value=''><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']}  '>\n";
138
139         if (!empty($_REQUEST['return_module']) && !empty($_REQUEST['return_action']) && !empty($_REQUEST['return_id']))
140             $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='${app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onclick=\"this.form.module.value='".$_REQUEST['return_module']."';this.form.action.value='".$_REQUEST['return_action']."';this.form.record.value='".$_REQUEST['return_id']."'\" type='submit' name='button' value='  ${app_strings['LBL_CANCEL_BUTTON_LABEL']}  '>";
141         else if (!empty($_POST['return_module']) && !empty($_POST['return_action']))
142             $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='${app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onclick=\"this.form.module.value='".$_POST['return_module']."';this.form.action.value='". $_POST['return_action']."';\" type='submit' name='button' value='  ${app_strings['LBL_CANCEL_BUTTON_LABEL']}  '>";
143         else
144             $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='${app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onclick=\"this.form.action.value='ListView';\" type='submit' type='submit' name='button' value='  ${app_strings['LBL_CANCEL_BUTTON_LABEL']}  '>";
145         } else {
146                 $form .= "<input type='submit' class='button' name='ContinueAccount' value='${mod_strings['LNK_NEW_ACCOUNT']}'>\n";
147         }
148         $form .= "</td></tr></table></td></tr><tr>";
149     if ($action != 'ShowDuplicates')
150         {
151                 $form .= "<th> &nbsp;</th>";
152         }
153         require_once('include/formbase.php');
154
155         $form .= getPostToForm();
156         if(isset($rows[0])){
157                 foreach ($rows[0] as $key=>$value){
158                         if($key != 'id'){
159
160                                         $form .= "<th>". $mod_strings[$mod_strings['db_'.$key]]. "</th>";
161                 }}
162
163                 $form .= "</tr>";
164         }
165
166         $rowColor = 'oddListRowS1';
167         foreach($rows as $row){
168
169                 $form .= "<tr class='$rowColor'>";
170                 if ($action != 'ShowDuplicates')
171                 {
172                 $form .= "<td width='1%' nowrap><a href='javascript:void(0)' onclick='document.dupAccounts.selectedAccount.value=\"${row['id']}\"; document.dupAccounts.submit(); '>[${app_strings['LBL_SELECT_BUTTON_LABEL']}]</a>&nbsp;&nbsp;</td>\n";
173                 }
174                 foreach ($row as $key=>$value){
175                                 if($key != 'id'){
176                     if(isset($_POST['popup']) && $_POST['popup']==true){
177                         $form .= "<td scope='row'><a  href='javascript:void(0)' onclick=\"window.opener.location='index.php?module=Accounts&action=DetailView&record=${row['id']}'\">$value</a></td>\n";
178                     }   
179                     else
180                                             $form .= "<td><a target='_blank' href='index.php?module=Accounts&action=DetailView&record=${row['id']}'>$value</a></td>\n";
181
182                                 }}
183
184                 if($rowColor == 'evenListRowS1'){
185                         $rowColor = 'oddListRowS1';
186                 }else{
187                          $rowColor = 'evenListRowS1';
188                 }
189                 $form .= "</tr>";
190         }
191         $form .= "<tr class='pagination'><td colspan='$cols'><table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td>";
192
193         // handle buttons
194         if ($action == 'ShowDuplicates') {
195                 $return_action = 'ListView'; // cn: bug 6658 - hardcoded return action break popup -> create -> duplicate -> cancel
196                 $return_action = (isset($_REQUEST['return_action']) && !empty($_REQUEST['return_action'])) ? $_REQUEST['return_action'] : $return_action;
197                 $form .= "<input type='hidden' name='selectedAccount' id='selectedAccount' value=''><input title='${app_strings['LBL_SAVE_BUTTON_TITLE']}' class='button' onclick=\"this.form.action.value='Save';\" type='submit' name='button' value='  ${app_strings['LBL_SAVE_BUTTON_LABEL']}  '>\n";
198             
199         if (!empty($_REQUEST['return_module']) && !empty($_REQUEST['return_action']) && !empty($_REQUEST['return_id']))
200             $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' class='button' onclick=\"this.form.module.value='".$_REQUEST['return_module']."';this.form.action.value='".$_REQUEST['return_action']."';this.form.record.value='".$_REQUEST['return_id']."'\" type='submit' name='button' value='  ${app_strings['LBL_CANCEL_BUTTON_LABEL']}  '>";
201         else if (!empty($_POST['return_module']) && !empty($_POST['return_action']))
202             $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' class='button' onclick=\"this.form.module.value='".$_POST['return_module']."';this.form.action.value='". $_POST['return_action']."';\" type='submit' name='button' value='  ${app_strings['LBL_CANCEL_BUTTON_LABEL']}  '>";
203         else
204             $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}'  class='button' onclick=\"this.form.action.value='ListView';\" type='submit' name='button' value='  ${app_strings['LBL_CANCEL_BUTTON_LABEL']}  '>";
205         } else {
206                 $form .= "<input type='submit' class='button' name='ContinueAccount' value='${mod_strings['LNK_NEW_ACCOUNT']}'></form>\n";
207         }
208     $form .= "</td></tr></table></td></tr></table>";
209         return $form;
210
211
212
213 }
214
215 function getForm($prefix, $mod='', $form=''){
216         if(!ACLController::checkAccess('Accounts', 'edit', true)){
217                 return '';
218         }
219 if(!empty($mod)){
220         global $current_language;
221         $mod_strings = return_module_language($current_language, $mod);
222 }else global $mod_strings;
223 global $app_strings;
224 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
225 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
226 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
227
228
229 $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
230 $the_form .= <<<EOQ
231                 <form name="${prefix}AccountSave" onSubmit="return check_form('${prefix}AccountSave');" method="POST" action="index.php">
232                         <input type="hidden" name="${prefix}module" value="Accounts">
233                         <input type="hidden" name="${prefix}action" value="Save">
234 EOQ;
235 $the_form .= $this->getFormBody($prefix, $mod, $prefix."AccountSave");
236 $the_form .= <<<EOQ
237                 <p><input title="$lbl_save_button_title" accessKey="$lbl_save_button_key" class="button" type="submit" name="button" value="  $lbl_save_button_label  " ></p>
238                 </form>
239
240 EOQ;
241 $the_form .= get_left_form_footer();
242 $the_form .= get_validate_record_js();
243
244 return $the_form;
245 }
246
247
248 function getFormBody($prefix,$mod='', $formname=''){
249         if(!ACLController::checkAccess('Accounts', 'edit', true)){
250                 return '';
251         }
252 global $mod_strings;
253 $temp_strings = $mod_strings;
254 if(!empty($mod)){
255         global $current_language;
256         $mod_strings = return_module_language($current_language, $mod);
257 }
258         global $app_strings;
259 global $current_user;
260
261 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
262 $lbl_account_name = $mod_strings['LBL_ACCOUNT_NAME'];
263 $lbl_phone = $mod_strings['LBL_PHONE'];
264 $lbl_website = $mod_strings['LBL_WEBSITE'];
265 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
266 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
267 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
268 $user_id = $current_user->id;
269
270         $form = <<<EOQ
271                         <p><input type="hidden" name="record" value="">
272                         <input type="hidden" name="email1" value="">
273                         <input type="hidden" name="email2" value="">
274                         <input type="hidden" name="assigned_user_id" value='${user_id}'>
275                         <input type="hidden" name="action" value="Save">
276 EOQ;
277         $form .= "$lbl_account_name&nbsp;<span class='required'>$lbl_required_symbol</span><br><input name='name' type='text' value=''><br>";
278         $form .= "$lbl_phone<br><input name='phone_office' type='text' value=''><br>";
279                 $form .= "$lbl_website<br><input name='website' type='text' value='http://'><br>";
280 $form .='</p>';
281
282
283
284 $javascript = new javascript();
285 $javascript->setFormName($formname);
286 $javascript->setSugarBean(new Account());
287 $javascript->addRequiredFields($prefix);
288 $form .=$javascript->getScript();
289 $mod_strings = $temp_strings;
290 return $form;
291 }
292
293
294
295 function getWideFormBody($prefix, $mod='',$formname='',  $contact=''){
296         if(!ACLController::checkAccess('Accounts', 'edit', true)){
297                 return '';
298         }
299         
300         if(empty($contact)){
301                 $contact = new Contact();
302         }
303 global $mod_strings;
304 $temp_strings = $mod_strings;
305 if(!empty($mod)){
306         global $current_language;
307         $mod_strings = return_module_language($current_language, $mod);
308 }
309 global $app_strings;
310 global $current_user;
311 $account = new Account();
312
313 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
314 $lbl_account_name = $mod_strings['LBL_ACCOUNT_NAME'];
315 $lbl_phone = $mod_strings['LBL_PHONE'];
316 $lbl_website = $mod_strings['LBL_WEBSITE'];
317 if (isset($contact->assigned_user_id)) {
318         $user_id=$contact->assigned_user_id;
319 } else {
320         $user_id = $current_user->id;
321 }
322
323         //Retrieve Email address and set email1, email2
324         $sugarEmailAddress = new SugarEmailAddress();
325         $sugarEmailAddress->handleLegacyRetrieve($contact);
326          if(!isset($contact->email1)){
327         $contact->email1 = '';
328     }
329     if(!isset($contact->email2)){
330         $contact->email2 = '';
331     }
332     if(!isset($contact->email_opt_out)){
333         $contact->email_opt_out = '';
334     }
335                 $form="";
336         $default_desc="";
337         if (!empty($contact->description)) {
338             $default_desc=$contact->description;
339         }
340         $form .= <<<EOQ
341                 <input type="hidden" name="${prefix}record" value="">
342                 <input type="hidden" name="${prefix}phone_fax" value="{$contact->phone_fax}">
343                 <input type="hidden" name="${prefix}phone_other" value="{$contact->phone_other}">
344                 <input type="hidden" name="${prefix}email1" value="{$contact->email1}">
345                 <input type="hidden" name="${prefix}email2" value="{$contact->email2}">
346                 <input type='hidden' name='${prefix}billing_address_street' value='{$contact->primary_address_street}'><input type='hidden' name='${prefix}billing_address_city' value='{$contact->primary_address_city}'><input type='hidden' name='${prefix}billing_address_state'   value='{$contact->primary_address_state}'><input type='hidden' name='${prefix}billing_address_postalcode'   value='{$contact->primary_address_postalcode}'><input type='hidden' name='${prefix}billing_address_country'  value='{$contact->primary_address_country}'>
347                 <input type='hidden' name='${prefix}shipping_address_street' value='{$contact->alt_address_street}'><input type='hidden' name='${prefix}shipping_address_city' value='{$contact->alt_address_city}'><input type='hidden' name='${prefix}shipping_address_state'   value='{$contact->alt_address_state}'><input type='hidden' name='${prefix}shipping_address_postalcode'   value='{$contact->alt_address_postalcode}'><input type='hidden' name='${prefix}shipping_address_country'  value='{$contact->alt_address_country}'>
348                 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
349                 <input type='hidden' name='${prefix}do_not_call'  value='{$contact->do_not_call}'>
350                 <input type='hidden' name='${prefix}email_opt_out'  value='{$contact->email_opt_out}'>
351                 <table width='100%' border="0" cellpadding="0" cellspacing="0">
352                 <tr>
353                 <td width="20%" nowrap scope="row">$lbl_account_name&nbsp;<span class="required">$lbl_required_symbol</span></td>
354                 <TD width="80%" nowrap scope="row">{$mod_strings['LBL_DESCRIPTION']}</TD>
355                 </tr>
356                 <tr>
357                 <td nowrap ><input name='{$prefix}name' type="text" value="$contact->account_name"></td>
358                 <TD rowspan="5" ><textarea name='{$prefix}description' rows='6' cols='50' >$default_desc</textarea></TD>
359                 </tr>
360                 <tr>
361                 <td nowrap scope="row">$lbl_phone</td>
362                 </tr>
363                 <tr>
364                 <td nowrap ><input name='{$prefix}phone_office' type="text" value="$contact->phone_work"></td>
365                 </tr>
366                 <tr>
367                 <td nowrap scope="row">$lbl_website</td>
368                 </tr>
369                 <tr>
370                 <td nowrap ><input name='{$prefix}website' type="text" value="http://"></td>
371                 </tr>
372 EOQ;
373         //carry forward custom lead fields common to accounts during Lead Conversion
374         $tempAccount = new Account();
375         if (method_exists($contact, 'convertCustomFieldsForm')) $contact->convertCustomFieldsForm($form, $tempAccount, $prefix);
376         unset($tempAccount);
377 $form .= <<<EOQ
378                 </TABLE>
379 EOQ;
380         
381
382 $javascript = new javascript();
383 $javascript->setFormName($formname);
384 $javascript->setSugarBean(new Account());
385 $javascript->addRequiredFields($prefix);
386 $form .=$javascript->getScript();
387 $mod_strings = $temp_strings;
388         return $form;
389 }
390
391
392 function handleSave($prefix,$redirect=true, $useRequired=false){
393         
394     
395         require_once('include/formbase.php');
396
397         $focus = new Account();
398
399         if($useRequired &&  !checkRequired($prefix, array_keys($focus->required_fields))){
400                 return null;
401         }
402         $focus = populateFromPost($prefix, $focus);
403
404         if (isset($GLOBALS['check_notify'])) {
405                 $check_notify = $GLOBALS['check_notify'];
406         }
407         else {
408                 $check_notify = FALSE;
409         }
410
411         if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
412                 $duplicateAccounts = $this->checkForDuplicates($prefix);
413                 if(isset($duplicateAccounts)){
414                         $location='module=Accounts&action=ShowDuplicates';
415                         $get = '';
416
417                         // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
418                         if(isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
419                                 $get .= '&Accountsrelate_to='.$_POST['relate_to'];
420                         }
421                         if(isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
422                                 $get .= '&Accountsrelate_id='.$_POST['relate_id'];
423                         }
424                         
425                         //add all of the post fields to redirect get string
426                         foreach ($focus->column_fields as $field)
427                         {
428                                 if (!empty($focus->$field) && !is_object($focus->$field))
429                                 {
430                                         $get .= "&Accounts$field=".urlencode($focus->$field);
431                                 }
432                         }
433
434                         foreach ($focus->additional_column_fields as $field)
435                         {
436                                 if (!empty($focus->$field))
437                                 {
438                                         $get .= "&Accounts$field=".urlencode($focus->$field);
439                                 }
440                         }
441             
442                         
443                         if($focus->hasCustomFields()) {
444                                 foreach($focus->field_defs as $name=>$field) {  
445                                         if (!empty($field['source']) && $field['source'] == 'custom_fields')
446                                         {
447                                                 $get .= "&Accounts$name=".urlencode($focus->$name);
448                                         }                           
449                                 }
450                         }
451                         
452                         
453                         
454                         $emailAddress = new SugarEmailAddress();
455                         $get .= $emailAddress->getFormBaseURL($focus);
456
457                         
458                         
459                         //create list of suspected duplicate account id's in redirect get string
460                         $i=0;
461                         foreach ($duplicateAccounts as $account)
462                         {
463                                 $get .= "&duplicate[$i]=".$account['id'];
464                                 $i++;
465                         }
466
467                         //add return_module, return_action, and return_id to redirect get string
468                         $get .= '&return_module=';
469                         if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
470                         else $get .= 'Accounts';
471                         $get .= '&return_action=';
472                         if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
473                         //else $get .= 'DetailView';
474                         if(!empty($_POST['return_id'])) $get .= '&return_id='.$_POST['return_id'];
475                         if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
476                         if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
477                         
478                         $_SESSION['SHOW_DUPLICATES'] = $get;
479                         //now redirect the post to modules/Accounts/ShowDuplicates.php
480             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1')
481             {
482                 ob_clean();
483                 $json = getJSONobj();
484                 echo $json->encode(array('status' => 'dupe', 'get' => $location));
485             }
486             else if(!empty($_REQUEST['ajax_load']))
487             {
488                 echo "<script>SUGAR.ajaxUI.loadContent('index.php?$location');</script>";
489             }
490             else {
491                 if(!empty($_POST['to_pdf']))
492                     $location .= '&to_pdf='.$_POST['to_pdf'];
493                 header("Location: index.php?$location");
494             }
495                         return null;
496                 }
497         }
498         if(!$focus->ACLAccess('Save')){
499                 ACLController::displayNoAccess(true);
500                 sugar_cleanup(true);
501         }
502
503         $focus->save($check_notify);
504     $return_id = $focus->id;
505     
506         $GLOBALS['log']->debug("Saved record with id of ".$return_id);
507
508
509     if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
510         $json = getJSONobj();
511         echo $json->encode(array('status' => 'success',
512                                  'get' => ''));
513                 $trackerManager = TrackerManager::getInstance();
514         $timeStamp = TimeDate::getInstance()->nowDb();
515         if($monitor = $trackerManager->getMonitor('tracker')){ 
516                 $monitor->setValue('action', 'detailview');
517                 $monitor->setValue('user_id', $GLOBALS['current_user']->id);
518                 $monitor->setValue('module_name', 'Accounts');
519                 $monitor->setValue('date_modified', $timeStamp);
520                 $monitor->setValue('visible', 1);
521         
522                 if (!empty($this->bean->id)) {
523                     $monitor->setValue('item_id', $return_id);
524                     $monitor->setValue('item_summary', $focus->get_summary_text());
525                 }
526                         $trackerManager->saveMonitor($monitor, true, true);
527                 }
528         return null;
529     }
530
531         if(isset($_POST['popup']) && $_POST['popup'] == 'true') {
532                 $get = '&module=';
533                 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
534                 else $get .= 'Accounts';
535                 $get .= '&action=';
536                 if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
537                 else $get .= 'Popup';
538                 if(!empty($_POST['return_id'])) $get .= '&return_id='.$_POST['return_id'];
539                 if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
540                 if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
541                 if(!empty($_POST['to_pdf'])) $get .= '&to_pdf='.$_POST['to_pdf'];
542                 $get .= '&name=' . $focus->name;
543                 $get .= '&query=true';
544                 header("Location: index.php?$get");
545                 return;
546         }
547         if($redirect){
548                 handleRedirect($return_id,'Accounts');
549         }else{
550                 return $focus;
551         }
552 }
553
554
555 }
556 ?>