]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Calls/Call.php
Release 6.5.15
[Github/sugarcrm.git] / modules / Calls / Call.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-2013 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:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46 class Call extends SugarBean {
47         var $field_name_map;
48         // Stored fields
49         var $id;
50         var $json_id;
51         var $date_entered;
52         var $date_modified;
53         var $assigned_user_id;
54         var $modified_user_id;
55         var $description;
56         var $name;
57         var $status;
58         var $date_start;
59         var $time_start;
60         var $duration_hours;
61         var $duration_minutes;
62         var $date_end;
63         var $parent_type;
64         var $parent_type_options;
65         var $parent_id;
66         var $contact_id;
67         var $user_id;
68         var $lead_id;
69         var $direction;
70         var $reminder_time;
71         var $reminder_time_options;
72         var $reminder_checked;
73         var $email_reminder_time;
74         var $email_reminder_checked;
75         var $email_reminder_sent;
76         var $required;
77         var $accept_status;
78         var $created_by;
79         var $created_by_name;
80         var $modified_by_name;
81         var $parent_name;
82         var $contact_name;
83         var $contact_phone;
84         var $contact_email;
85         var $account_id;
86         var $opportunity_id;
87         var $case_id;
88         var $assigned_user_name;
89         var $note_id;
90     var $outlook_id;
91         var $update_vcal = true;
92         var $contacts_arr;
93         var $users_arr;
94         var $leads_arr;
95         var $default_call_name_values = array('Assemble catalogs', 'Make travel arrangements', 'Send a letter', 'Send contract', 'Send fax', 'Send a follow-up letter', 'Send literature', 'Send proposal', 'Send quote');
96         var $minutes_value_default = 15;
97         var $minutes_values = array('0'=>'00','15'=>'15','30'=>'30','45'=>'45');
98         var $table_name = "calls";
99         var $rel_users_table = "calls_users";
100         var $rel_contacts_table = "calls_contacts";
101     var $rel_leads_table = "calls_leads";
102         var $module_dir = 'Calls';
103         var $object_name = "Call";
104         var $new_schema = true;
105         var $importable = true;
106         var $syncing = false;
107         var $recurring_source;
108
109         // This is used to retrieve related fields from form posts.
110         var $additional_column_fields = array('assigned_user_name', 'assigned_user_id', 'contact_id', 'user_id', 'contact_name');
111         var $relationship_fields = array(       'account_id'            => 'accounts',
112                                                                                 'opportunity_id'        => 'opportunities',
113                                                                                 'contact_id'            => 'contacts',
114                                                                                 'case_id'                       => 'cases',
115                                                                                 'user_id'                       => 'users',
116                                                                                 'assigned_user_id'      => 'users',
117                                                                                 'note_id'                       => 'notes',
118                                         'lead_id'                       => 'leads',
119                                                                 );
120
121         function Call() {
122                 parent::SugarBean();
123                 global $app_list_strings;
124
125         $this->setupCustomFields('Calls');
126
127                 foreach ($this->field_defs as $field) {
128                         $this->field_name_map[$field['name']] = $field;
129                 }
130
131
132
133
134          if(!empty($GLOBALS['app_list_strings']['duration_intervals']))
135                 $this->minutes_values = $GLOBALS['app_list_strings']['duration_intervals'];
136         }
137
138         /**
139          * Disable edit if call is recurring and source is not Sugar. It should be edited only from Outlook.
140          * @param $view string
141          * @param $is_owner bool
142          */
143         function ACLAccess($view,$is_owner = 'not_set'){
144                 // don't check if call is being synced from Outlook
145                 if($this->syncing == false){
146                         $view = strtolower($view);
147                         switch($view){
148                                 case 'edit':
149                                 case 'save':
150                                 case 'editview':
151                                 case 'delete':
152                                         if(!empty($this->recurring_source) && $this->recurring_source != "Sugar"){
153                                                 return false;
154                                         }
155                         }
156                 }
157                 return parent::ACLAccess($view,$is_owner);
158         }
159     // save date_end by calculating user input
160     // this is for calendar
161         function save($check_notify = FALSE) {
162                 global $timedate,$current_user;
163
164             if(isset($this->date_start) && isset($this->duration_hours) && isset($this->duration_minutes))
165         {
166             $td = $timedate->fromDb($this->date_start);
167             if($td)
168             {
169                         $this->date_end = $td->modify("+{$this->duration_hours} hours {$this->duration_minutes} mins")->asDb();
170             }
171         }
172
173                 if(!empty($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == '1') {
174                         $check_notify = true;
175         } else {
176                         $check_notify = false;
177                 }
178                 if(empty($_REQUEST['send_invites'])) {
179                         if(!empty($this->id)) {
180                                 $old_record = new Call();
181                                 $old_record->retrieve($this->id);
182                                 $old_assigned_user_id = $old_record->assigned_user_id;
183                         }
184                         if((empty($this->id) && isset($_REQUEST['assigned_user_id']) && !empty($_REQUEST['assigned_user_id']) && $GLOBALS['current_user']->id != $_REQUEST['assigned_user_id']) || (isset($old_assigned_user_id) && !empty($old_assigned_user_id) && isset($_REQUEST['assigned_user_id']) && !empty($_REQUEST['assigned_user_id']) && $old_assigned_user_id != $_REQUEST['assigned_user_id']) ){
185                                 $this->special_notification = true;
186                                 if(!isset($GLOBALS['resavingRelatedBeans']) || $GLOBALS['resavingRelatedBeans'] == false) {
187                                         $check_notify = true;
188                                 }
189                 if(isset($_REQUEST['assigned_user_name'])) {
190                     $this->new_assigned_user_name = $_REQUEST['assigned_user_name'];
191                 }
192                         }
193                 }
194         if (empty($this->status) ) {
195             $this->status = $this->getDefaultStatus();
196         }
197
198                 // prevent a mass mailing for recurring meetings created in Calendar module
199                 if (empty($this->id) && !empty($_REQUEST['module']) && $_REQUEST['module'] == "Calendar" && !empty($_REQUEST['repeat_type']) && !empty($this->repeat_parent_id)) {
200                         $check_notify = false;
201                 }
202                 /*nsingh 7/3/08  commenting out as bug #20814 is invalid
203                 if($current_user->getPreference('reminder_time')!= -1 &&  isset($_POST['reminder_checked']) && isset($_POST['reminder_time']) && $_POST['reminder_checked']==0  && $_POST['reminder_time']==-1){
204                         $this->reminder_checked = '1';
205                         $this->reminder_time = $current_user->getPreference('reminder_time');
206                 }*/
207
208         $return_id = parent::save($check_notify);
209         global $current_user;
210
211
212         if($this->update_vcal) {
213                         vCal::cache_sugar_vcal($current_user);
214         }
215
216         return $return_id;
217         }
218
219         /** Returns a list of the associated contacts
220          * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
221          * All Rights Reserved..
222          * Contributor(s): ______________________________________..
223         */
224         function get_contacts()
225         {
226                 // First, get the list of IDs.
227                 $query = "SELECT contact_id as id from calls_contacts where call_id='$this->id' AND deleted=0";
228
229                 return $this->build_related_list($query, new Contact());
230         }
231
232
233         function get_summary_text()
234         {
235                 return "$this->name";
236         }
237
238         function create_list_query($order_by, $where, $show_deleted=0)
239         {
240         $custom_join = $this->getCustomJoin();
241                 $query = "SELECT ";
242                 $query .= "
243                         calls.*,";
244                         if ( preg_match("/calls_users\.user_id/",$where))
245                         {
246                                 $query .= "calls_users.required,
247                                 calls_users.accept_status,";
248                         }
249
250                         $query .= "
251                         users.user_name as assigned_user_name";
252         $query .= $custom_join['select'];
253
254                         // this line will help generate a GMT-metric to compare to a locale's timezone
255
256                         if ( preg_match("/contacts/",$where)){
257                                 $query .= ", contacts.first_name, contacts.last_name";
258                                 $query .= ", contacts.assigned_user_id contact_name_owner";
259                         }
260                         $query .= " FROM calls ";
261
262                         if ( preg_match("/contacts/",$where)){
263                                 $query .=       "LEFT JOIN calls_contacts
264                             ON calls.id=calls_contacts.call_id
265                             LEFT JOIN contacts
266                             ON calls_contacts.contact_id=contacts.id ";
267                         }
268                         if ( preg_match('/calls_users\.user_id/',$where))
269                         {
270                 $query .= "LEFT JOIN calls_users
271                         ON calls.id=calls_users.call_id and calls_users.deleted=0 ";
272                         }
273                         $query .= "
274                         LEFT JOIN users
275                         ON calls.assigned_user_id=users.id ";
276         $query .= $custom_join['join'];
277                         $where_auto = '1=1';
278                  if($show_deleted == 0){
279                 $where_auto = " $this->table_name.deleted=0  ";
280                         }else if($show_deleted == 1){
281                                 $where_auto = " $this->table_name.deleted=1 ";
282                         }
283
284                         //$where_auto .= " GROUP BY calls.id";
285
286                 if($where != "")
287                         $query .= "where $where AND ".$where_auto;
288                 else
289                         $query .= "where ".$where_auto;
290
291         $order_by = $this->process_order_by($order_by);
292         if (empty($order_by)) {
293             $order_by = 'calls.name';
294         }
295         $query .= ' ORDER BY ' . $order_by;
296
297                 return $query;
298         }
299
300         function create_export_query(&$order_by, &$where, $relate_link_join='')
301         {
302             $custom_join = $this->getCustomJoin(true, true, $where);
303             $custom_join['join'] .= $relate_link_join;
304                         $contact_required = stristr($where, "contacts");
305             if($contact_required)
306             {
307                     $query = "SELECT calls.*, contacts.first_name, contacts.last_name, users.user_name as assigned_user_name ";
308                     $query .= $custom_join['select'];
309                     $query .= " FROM contacts, calls, calls_contacts ";
310                     $where_auto = "calls_contacts.contact_id = contacts.id AND calls_contacts.call_id = calls.id AND calls.deleted=0 AND contacts.deleted=0";
311             }
312             else
313             {
314                     $query = 'SELECT calls.*, users.user_name as assigned_user_name ';
315                     $query .= $custom_join['select'];
316                     $query .= ' FROM calls ';
317                     $where_auto = "calls.deleted=0";
318             }
319
320
321                         $query .= "  LEFT JOIN users ON calls.assigned_user_id=users.id ";
322
323             $query .= $custom_join['join'];
324
325                         if($where != "")
326                     $query .= "where $where AND ".$where_auto;
327             else
328                     $query .= "where ".$where_auto;
329
330         $order_by = $this->process_order_by($order_by);
331         if (empty($order_by)) {
332             $order_by = 'calls.name';
333         }
334         $query .= ' ORDER BY ' . $order_by;
335
336             return $query;
337         }
338
339
340
341
342
343         function fill_in_additional_detail_fields()
344         {
345                 global $locale;
346                 parent::fill_in_additional_detail_fields();
347                 if (!empty($this->contact_id)) {
348                         $query  = "SELECT first_name, last_name FROM contacts ";
349                         $query .= "WHERE id='$this->contact_id' AND deleted=0";
350                         $result = $this->db->limitQuery($query,0,1,true," Error filling in additional detail fields: ");
351
352                         // Get the contact name.
353                         $row = $this->db->fetchByAssoc($result);
354                         $GLOBALS['log']->info("additional call fields $query");
355                         if($row != null)
356                         {
357                                 $this->contact_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name'], '', '');
358                                 $GLOBALS['log']->debug("Call($this->id): contact_name = $this->contact_name");
359                                 $GLOBALS['log']->debug("Call($this->id): contact_id = $this->contact_id");
360                         }
361                 }
362                 if (!isset($this->duration_minutes)) {
363                         $this->duration_minutes = $this->minutes_value_default;
364                 }
365
366         global $timedate;
367         //setting default date and time
368                 if (is_null($this->date_start)) {
369                         $this->date_start = $timedate->now();
370                 }
371
372                 if (is_null($this->duration_hours))
373                         $this->duration_hours = "0";
374                 if (is_null($this->duration_minutes))
375                         $this->duration_minutes = "1";
376
377                 $this->fill_in_additional_parent_fields();
378
379                 global $app_list_strings;
380                 $parent_types = $app_list_strings['record_type_display'];
381                 $disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list');
382                 foreach($disabled_parent_types as $disabled_parent_type){
383                         if($disabled_parent_type != $this->parent_type){
384                                 unset($parent_types[$disabled_parent_type]);
385                         }
386                 }
387
388                 $this->parent_type_options = get_select_options_with_id($parent_types, $this->parent_type);
389
390                 if (empty($this->reminder_time)) {
391                         $this->reminder_time = -1;
392                 }
393
394                 if ( empty($this->id) ) {
395                     $reminder_t = $GLOBALS['current_user']->getPreference('reminder_time');
396                     if ( isset($reminder_t) )
397                         $this->reminder_time = $reminder_t;
398                 }
399                 $this->reminder_checked = $this->reminder_time == -1 ? false : true;
400
401                 if (empty($this->email_reminder_time)) {
402                         $this->email_reminder_time = -1;
403                 }
404                 if(empty($this->id)){
405                         $reminder_t = $GLOBALS['current_user']->getPreference('email_reminder_time');
406                         if(isset($reminder_t))
407                                 $this->email_reminder_time = $reminder_t;
408                 }
409                 $this->email_reminder_checked = $this->email_reminder_time == -1 ? false : true;
410
411                 if (isset ($_REQUEST['parent_type']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'SubpanelEdits')) {
412                         $this->parent_type = $_REQUEST['parent_type'];
413                 } elseif (is_null($this->parent_type)) {
414                         $this->parent_type = $app_list_strings['record_type_default_key'];
415                 }
416         }
417
418
419         function get_list_view_data(){
420                 $call_fields = $this->get_list_view_array();
421                 global $app_list_strings, $focus, $action, $currentModule;
422                 if (isset($focus->id)) $id = $focus->id;
423                 else $id = '';
424                 if (isset($this->parent_type) && $this->parent_type != null)
425                 {
426                         $call_fields['PARENT_MODULE'] = $this->parent_type;
427                 }
428                 if ($this->status == "Planned") {
429                         //cn: added this if() to deal with sequential Closes in Meetings.  this is a hack to a hack (formbase.php->handleRedirect)
430                         if(empty($action))
431                             $action = "index";
432
433             $setCompleteUrl = "<a id='{$this->id}' onclick='SUGAR.util.closeActivityPanel.show(\"{$this->module_dir}\",\"{$this->id}\",\"Held\",\"listview\",\"1\");'>";
434                         if ($this->ACLAccess('edit')) {
435                 $call_fields['SET_COMPLETE'] = $setCompleteUrl . SugarThemeRegistry::current()->getImage("close_inline"," border='0'",null,null,'.gif',translate('LBL_CLOSEINLINE'))."</a>";
436             } else {
437                 $call_fields['SET_COMPLETE'] = '';
438             }
439                 }
440                 global $timedate;
441                 $today = $timedate->nowDb();
442                 $nextday = $timedate->asDbDate($timedate->getNow()->modify("+1 day"));
443                 $mergeTime = $call_fields['DATE_START']; //$timedate->merge_date_time($call_fields['DATE_START'], $call_fields['TIME_START']);
444                 $date_db = $timedate->to_db($mergeTime);
445                 if( $date_db    < $today){
446                         $call_fields['DATE_START']= "<font class='overdueTask'>".$call_fields['DATE_START']."</font>";
447                 }else if($date_db < $nextday){
448                         $call_fields['DATE_START'] = "<font class='todaysTask'>".$call_fields['DATE_START']."</font>";
449                 }else{
450                         $call_fields['DATE_START'] = "<font class='futureTask'>".$call_fields['DATE_START']."</font>";
451                 }
452                 $this->fill_in_additional_detail_fields();
453
454                 //make sure we grab the localized version of the contact name, if a contact is provided
455                 if (!empty($this->contact_id)) {
456            // Bug# 46125 - make first name, last name, salutation and title of Contacts respect field level ACLs
457             $contact_temp = BeanFactory::getBean("Contacts", $this->contact_id);
458             if(!empty($contact_temp)) {
459                 $contact_temp->_create_proper_name_field();
460                 $this->contact_name = $contact_temp->full_name;
461             }
462                 }
463
464         $call_fields['CONTACT_ID'] = $this->contact_id;
465         $call_fields['CONTACT_NAME'] = $this->contact_name;
466                 $call_fields['PARENT_NAME'] = $this->parent_name;
467         $call_fields['REMINDER_CHECKED'] = $this->reminder_time==-1 ? false : true;
468             $call_fields['EMAIL_REMINDER_CHECKED'] = $this->email_reminder_time==-1 ? false : true;
469
470                 return $call_fields;
471         }
472
473         function set_notification_body($xtpl, $call) {
474                 global $sugar_config;
475                 global $app_list_strings;
476                 global $current_user;
477                 global $app_list_strings;
478                 global $timedate;
479
480         // rrs: bug 42684 - passing a contact breaks this call
481                 $notifyUser =($call->current_notify_user->object_name == 'User') ? $call->current_notify_user : $current_user;
482
483
484                 // Assumes $call dates are in user format
485                 $calldate = $timedate->fromDb($call->date_start);
486                 $xOffset = $timedate->asUser($calldate, $notifyUser).' '.$timedate->userTimezoneSuffix($calldate, $notifyUser);
487
488                 if ( strtolower(get_class($call->current_notify_user)) == 'contact' ) {
489                         $xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
490                                   '/index.php?entryPoint=acceptDecline&module=Calls&contact_id='.$call->current_notify_user->id.'&record='.$call->id);
491                 } elseif ( strtolower(get_class($call->current_notify_user)) == 'lead' ) {
492                         $xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
493                                   '/index.php?entryPoint=acceptDecline&module=Calls&lead_id='.$call->current_notify_user->id.'&record='.$call->id);
494                 } else {
495                         $xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
496                                   '/index.php?entryPoint=acceptDecline&module=Calls&user_id='.$call->current_notify_user->id.'&record='.$call->id);
497                 }
498
499                 $xtpl->assign("CALL_TO", $call->current_notify_user->new_assigned_user_name);
500                 $xtpl->assign("CALL_SUBJECT", $call->name);
501                 $xtpl->assign("CALL_STARTDATE", $xOffset);
502                 $xtpl->assign("CALL_HOURS", $call->duration_hours);
503                 $xtpl->assign("CALL_MINUTES", $call->duration_minutes);
504                 $xtpl->assign("CALL_STATUS", ((isset($call->status))?$app_list_strings['call_status_dom'][$call->status] : ""));
505                 $xtpl->assign("CALL_DESCRIPTION", $call->description);
506
507                 return $xtpl;
508         }
509
510
511         function get_call_users() {
512                 $template = new User();
513                 // First, get the list of IDs.
514                 $query = "SELECT calls_users.required, calls_users.accept_status, calls_users.user_id from calls_users where calls_users.call_id='$this->id' AND calls_users.deleted=0";
515                 $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
516                 $result = $this->db->query($query, true);
517                 $list = Array();
518
519                 while($row = $this->db->fetchByAssoc($result)) {
520                         $template = new User(); // PHP 5 will retrieve by reference, always over-writing the "old" one
521                         $record = $template->retrieve($row['user_id']);
522                         $template->required = $row['required'];
523                         $template->accept_status = $row['accept_status'];
524
525                         if($record != null) {
526                             // this copies the object into the array
527                                 $list[] = $template;
528                         }
529                 }
530                 return $list;
531         }
532
533
534   function get_invite_calls(&$user)
535   {
536     $template = $this;
537     // First, get the list of IDs.
538     $query = "SELECT calls_users.required, calls_users.accept_status, calls_users.call_id from calls_users where calls_users.user_id='$user->id' AND ( calls_users.accept_status IS NULL OR  calls_users.accept_status='none') AND calls_users.deleted=0";
539     $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
540
541
542     $result = $this->db->query($query, true);
543
544
545     $list = Array();
546
547
548     while($row = $this->db->fetchByAssoc($result))
549     {
550       $record = $template->retrieve($row['call_id']);
551       $template->required = $row['required'];
552       $template->accept_status = $row['accept_status'];
553
554
555       if($record != null)
556       {
557         // this copies the object into the array
558         $list[] = $template;
559       }
560     }
561     return $list;
562
563   }
564
565
566   function set_accept_status(&$user,$status)
567   {
568     if ( $user->object_name == 'User')
569     {
570       $relate_values = array('user_id'=>$user->id,'call_id'=>$this->id);
571       $data_values = array('accept_status'=>$status);
572       $this->set_relationship($this->rel_users_table, $relate_values, true, true,$data_values);
573       global $current_user;
574
575       if ( $this->update_vcal )
576       {
577         vCal::cache_sugar_vcal($user);
578       }
579     }
580     else if ( $user->object_name == 'Contact')
581     {
582       $relate_values = array('contact_id'=>$user->id,'call_id'=>$this->id);
583       $data_values = array('accept_status'=>$status);
584       $this->set_relationship($this->rel_contacts_table, $relate_values, true, true,$data_values);
585     }
586     else if ( $user->object_name == 'Lead')
587     {
588       $relate_values = array('lead_id'=>$user->id,'call_id'=>$this->id);
589       $data_values = array('accept_status'=>$status);
590       $this->set_relationship($this->rel_leads_table, $relate_values, true, true,$data_values);
591     }
592   }
593
594
595
596         function get_notification_recipients() {
597                 if($this->special_notification) {
598                         return parent::get_notification_recipients();
599                 }
600
601 //              $GLOBALS['log']->debug('Call.php->get_notification_recipients():'.print_r($this,true));
602                 $list = array();
603         if(!is_array($this->contacts_arr)) {
604                         $this->contacts_arr =   array();
605                 }
606
607                 if(!is_array($this->users_arr)) {
608                         $this->users_arr =      array();
609                 }
610
611         if(!is_array($this->leads_arr)) {
612                         $this->leads_arr =      array();
613                 }
614
615                 foreach($this->users_arr as $user_id) {
616                         $notify_user = new User();
617                         $notify_user->retrieve($user_id);
618                         $notify_user->new_assigned_user_name = $notify_user->full_name;
619                         $GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
620                         $list[$notify_user->id] = $notify_user;
621                 }
622
623                 foreach($this->contacts_arr as $contact_id) {
624                         $notify_user = new Contact();
625                         $notify_user->retrieve($contact_id);
626                         $notify_user->new_assigned_user_name = $notify_user->full_name;
627                         $GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
628                         $list[$notify_user->id] = $notify_user;
629                 }
630
631         foreach($this->leads_arr as $lead_id) {
632                         $notify_user = new Lead();
633                         $notify_user->retrieve($lead_id);
634                         $notify_user->new_assigned_user_name = $notify_user->full_name;
635                         $GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
636                         $list[$notify_user->id] = $notify_user;
637                 }
638                 global $sugar_config;
639                 if(isset($sugar_config['disable_notify_current_user']) && $sugar_config['disable_notify_current_user']) {
640                         global $current_user;
641                         if(isset($list[$current_user->id]))
642                                 unset($list[$current_user->id]);
643                 }
644 //              $GLOBALS['log']->debug('Call.php->get_notification_recipients():'.print_r($list,true));
645                 return $list;
646         }
647
648     function bean_implements($interface){
649                 switch($interface){
650                         case 'ACL':return true;
651                 }
652                 return false;
653         }
654
655         function listviewACLHelper(){
656                 $array_assign = parent::listviewACLHelper();
657                 $is_owner = false;
658                 if(!empty($this->parent_name)){
659
660                         if(!empty($this->parent_name_owner)){
661                                 global $current_user;
662                                 $is_owner = $current_user->id == $this->parent_name_owner;
663                         }
664                 }
665                         if(!ACLController::moduleSupportsACL($this->parent_type) || ACLController::checkAccess($this->parent_type, 'view', $is_owner)){
666                                 $array_assign['PARENT'] = 'a';
667                         }else{
668                                 $array_assign['PARENT'] = 'span';
669                         }
670                 $is_owner = false;
671                 if(!empty($this->contact_name)){
672
673                         if(!empty($this->contact_name_owner)){
674                                 global $current_user;
675                                 $is_owner = $current_user->id == $this->contact_name_owner;
676                         }
677                 }
678                         if( ACLController::checkAccess('Contacts', 'view', $is_owner)){
679                                 $array_assign['CONTACT'] = 'a';
680                         }else{
681                                 $array_assign['CONTACT'] = 'span';
682                         }
683
684                 return $array_assign;
685         }
686
687         function save_relationship_changes($is_update) {
688                 $exclude = array();
689                 if(empty($this->in_workflow))
690         {
691             if(empty($this->in_import))
692             {
693                 //if the global soap_server_object variable is not empty (as in from a soap/OPI call), then process the assigned_user_id relationship, otherwise
694                 //add assigned_user_id to exclude list and let the logic from MeetingFormBase determine whether assigned user id gets added to the relationship
695                 if(!empty($GLOBALS['soap_server_object']))
696                 {
697                             $exclude = array('lead_id', 'contact_id', 'user_id');
698                     }
699                 else
700                 {
701                         $exclude = array('lead_id', 'contact_id', 'user_id', 'assigned_user_id');
702                     }
703             }
704             else
705             {
706                 $exclude = array('user_id');
707             }
708
709
710         }
711                 parent::save_relationship_changes($is_update, $exclude);
712         }
713
714     public function getDefaultStatus()
715     {
716          $def = $this->field_defs['status'];
717          if (isset($def['default'])) {
718              return $def['default'];
719          } else {
720             $app = return_app_list_strings_language($GLOBALS['current_language']);
721             if (isset($def['options']) && isset($app[$def['options']])) {
722                 $keys = array_keys($app[$def['options']]);
723                 return $keys[0];
724             }
725         }
726         return '';
727     }
728
729     public function mark_deleted($id)
730     {
731         require_once("modules/Calendar/CalendarUtils.php");
732         CalendarUtils::correctRecurrences($this, $id);
733
734         parent::mark_deleted($id);
735     }
736 }