]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Calls/Call.php
Release 6.5.0
[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-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:  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->custom_fields->getJOIN();
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                         if($custom_join){
253                                 $query .= $custom_join['select'];
254                         }
255
256                         // this line will help generate a GMT-metric to compare to a locale's timezone
257
258                         if ( preg_match("/contacts/",$where)){
259                                 $query .= ", contacts.first_name, contacts.last_name";
260                                 $query .= ", contacts.assigned_user_id contact_name_owner";
261                         }
262                         $query .= " FROM calls ";
263
264                         if ( preg_match("/contacts/",$where)){
265                                 $query .=       "LEFT JOIN calls_contacts
266                             ON calls.id=calls_contacts.call_id
267                             LEFT JOIN contacts
268                             ON calls_contacts.contact_id=contacts.id ";
269                         }
270                         if ( preg_match('/calls_users\.user_id/',$where))
271                         {
272                 $query .= "LEFT JOIN calls_users
273                         ON calls.id=calls_users.call_id and calls_users.deleted=0 ";
274                         }
275                         $query .= "
276                         LEFT JOIN users
277                         ON calls.assigned_user_id=users.id ";
278                         if($custom_join){
279                                 $query .= $custom_join['join'];
280                         }
281                         $where_auto = '1=1';
282                  if($show_deleted == 0){
283                 $where_auto = " $this->table_name.deleted=0  ";
284                         }else if($show_deleted == 1){
285                                 $where_auto = " $this->table_name.deleted=1 ";
286                         }
287
288                         //$where_auto .= " GROUP BY calls.id";
289
290                 if($where != "")
291                         $query .= "where $where AND ".$where_auto;
292                 else
293                         $query .= "where ".$where_auto;
294
295                 if($order_by != "")
296                 $query .=  " ORDER BY ". $this->process_order_by($order_by, null);
297                 else
298                         $query .= " ORDER BY calls.name";
299                 return $query;
300         }
301
302         function create_export_query(&$order_by, &$where, $relate_link_join='')
303         {
304                 $custom_join = $this->custom_fields->getJOIN(true, true,$where);
305                         if($custom_join)
306                                 $custom_join['join'] .= $relate_link_join;
307                         $contact_required = stristr($where, "contacts");
308             if($contact_required)
309             {
310                     $query = "SELECT calls.*, contacts.first_name, contacts.last_name, users.user_name as assigned_user_name ";
311                     if($custom_join){
312                                                 $query .= $custom_join['select'];
313                                         }
314                     $query .= " FROM contacts, calls, calls_contacts ";
315                     $where_auto = "calls_contacts.contact_id = contacts.id AND calls_contacts.call_id = calls.id AND calls.deleted=0 AND contacts.deleted=0";
316             }
317             else
318             {
319                     $query = 'SELECT calls.*, users.user_name as assigned_user_name ';
320                         if($custom_join){
321                                                 $query .= $custom_join['select'];
322                                         }
323                     $query .= ' FROM calls ';
324                     $where_auto = "calls.deleted=0";
325             }
326
327
328                         $query .= "  LEFT JOIN users ON calls.assigned_user_id=users.id ";
329
330                         if($custom_join){
331                                 $query .= $custom_join['join'];
332                         }
333
334                         if($where != "")
335                     $query .= "where $where AND ".$where_auto;
336             else
337                     $query .= "where ".$where_auto;
338
339             if($order_by != "")
340                     $query .=  " ORDER BY ". $this->process_order_by($order_by, null);
341             else
342                     $query .= " ORDER BY calls.name";
343
344             return $query;
345         }
346
347
348
349
350
351         function fill_in_additional_detail_fields()
352         {
353                 global $locale;
354                 parent::fill_in_additional_detail_fields();
355                 if (!empty($this->contact_id)) {
356                         $query  = "SELECT first_name, last_name FROM contacts ";
357                         $query .= "WHERE id='$this->contact_id' AND deleted=0";
358                         $result = $this->db->limitQuery($query,0,1,true," Error filling in additional detail fields: ");
359
360                         // Get the contact name.
361                         $row = $this->db->fetchByAssoc($result);
362                         $GLOBALS['log']->info("additional call fields $query");
363                         if($row != null)
364                         {
365                                 $this->contact_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name'], '', '');
366                                 $GLOBALS['log']->debug("Call($this->id): contact_name = $this->contact_name");
367                                 $GLOBALS['log']->debug("Call($this->id): contact_id = $this->contact_id");
368                         }
369                 }
370                 if (!isset($this->duration_minutes)) {
371                         $this->duration_minutes = $this->minutes_value_default;
372                 }
373
374         global $timedate;
375         //setting default date and time
376                 if (is_null($this->date_start)) {
377                         $this->date_start = $timedate->now();
378                 }
379
380                 if (is_null($this->duration_hours))
381                         $this->duration_hours = "0";
382                 if (is_null($this->duration_minutes))
383                         $this->duration_minutes = "1";
384
385                 $this->fill_in_additional_parent_fields();
386
387                 global $app_list_strings;
388                 $parent_types = $app_list_strings['record_type_display'];
389                 $disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list');
390                 foreach($disabled_parent_types as $disabled_parent_type){
391                         if($disabled_parent_type != $this->parent_type){
392                                 unset($parent_types[$disabled_parent_type]);
393                         }
394                 }
395
396                 $this->parent_type_options = get_select_options_with_id($parent_types, $this->parent_type);
397
398                 if (empty($this->reminder_time)) {
399                         $this->reminder_time = -1;
400                 }
401
402                 if ( empty($this->id) ) {
403                     $reminder_t = $GLOBALS['current_user']->getPreference('reminder_time');
404                     if ( isset($reminder_t) )
405                         $this->reminder_time = $reminder_t;
406                 }
407                 $this->reminder_checked = $this->reminder_time == -1 ? false : true;
408
409                 if (empty($this->email_reminder_time)) {
410                         $this->email_reminder_time = -1;
411                 }
412                 if(empty($this->id)){ 
413                         $reminder_t = $GLOBALS['current_user']->getPreference('email_reminder_time');
414                         if(isset($reminder_t))
415                                 $this->email_reminder_time = $reminder_t;
416                 }
417                 $this->email_reminder_checked = $this->email_reminder_time == -1 ? false : true;
418
419                 if (isset ($_REQUEST['parent_type'])) {
420                         $this->parent_type = $_REQUEST['parent_type'];
421                 } elseif (is_null($this->parent_type)) {
422                         $this->parent_type = $app_list_strings['record_type_default_key'];
423                 }
424         }
425
426
427         function get_list_view_data(){
428                 $call_fields = $this->get_list_view_array();
429                 global $app_list_strings, $focus, $action, $currentModule;
430                 if (isset($focus->id)) $id = $focus->id;
431                 else $id = '';
432                 if (isset($this->parent_type) && $this->parent_type != null)
433                 {
434                         $call_fields['PARENT_MODULE'] = $this->parent_type;
435                 }
436                 if ($this->status == "Planned") {
437                         //cn: added this if() to deal with sequential Closes in Meetings.  this is a hack to a hack (formbase.php->handleRedirect)
438                         if(empty($action))
439                             $action = "index";
440
441             $setCompleteUrl = "<a id='{$this->id}' onclick='SUGAR.util.closeActivityPanel.show(\"{$this->module_dir}\",\"{$this->id}\",\"Held\",\"listview\",\"1\");'>";
442                         if ($this->ACLAccess('edit')) {
443                 $call_fields['SET_COMPLETE'] = $setCompleteUrl . SugarThemeRegistry::current()->getImage("close_inline"," border='0'",null,null,'.gif',translate('LBL_CLOSEINLINE'))."</a>";
444             } else {
445                 $call_fields['SET_COMPLETE'] = '';
446             }
447                 }
448                 global $timedate;
449                 $today = $timedate->nowDb();
450                 $nextday = $timedate->asDbDate($timedate->getNow()->modify("+1 day"));
451                 $mergeTime = $call_fields['DATE_START']; //$timedate->merge_date_time($call_fields['DATE_START'], $call_fields['TIME_START']);
452                 $date_db = $timedate->to_db($mergeTime);
453                 if( $date_db    < $today){
454                         $call_fields['DATE_START']= "<font class='overdueTask'>".$call_fields['DATE_START']."</font>";
455                 }else if($date_db < $nextday){
456                         $call_fields['DATE_START'] = "<font class='todaysTask'>".$call_fields['DATE_START']."</font>";
457                 }else{
458                         $call_fields['DATE_START'] = "<font class='futureTask'>".$call_fields['DATE_START']."</font>";
459                 }
460                 $this->fill_in_additional_detail_fields();
461
462                 //make sure we grab the localized version of the contact name, if a contact is provided
463                 if (!empty($this->contact_id)) {
464                     global $locale;
465            // Bug# 46125 - make first name, last name, salutation and title of Contacts respect field level ACLs
466             $contact_temp = new Contact();
467             $contact_temp->retrieve($this->contact_id);
468             $contact_temp->_create_proper_name_field();
469             $this->contact_name = $contact_temp->full_name;
470                 }
471
472         $call_fields['CONTACT_ID'] = $this->contact_id;
473         $call_fields['CONTACT_NAME'] = $this->contact_name;
474                 $call_fields['PARENT_NAME'] = $this->parent_name;
475         $call_fields['REMINDER_CHECKED'] = $this->reminder_time==-1 ? false : true;
476         $call_fields['EMAIL_REMINDER_CHECKED'] = $this->email_reminder_time==-1 ? false : true;
477
478                 return $call_fields;
479         }
480
481         function set_notification_body($xtpl, $call) {
482                 global $sugar_config;
483                 global $app_list_strings;
484                 global $current_user;
485                 global $app_list_strings;
486                 global $timedate;
487
488         // rrs: bug 42684 - passing a contact breaks this call
489                 $notifyUser =($call->current_notify_user->object_name == 'User') ? $call->current_notify_user : $current_user;
490                         
491
492                 // Assumes $call dates are in user format
493                 $calldate = $timedate->fromDb($call->date_start);
494                 $xOffset = $timedate->asUser($calldate, $notifyUser).' '.$timedate->userTimezoneSuffix($calldate, $notifyUser);
495
496                 if ( strtolower(get_class($call->current_notify_user)) == 'contact' ) {
497                         $xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
498                                   '/index.php?entryPoint=acceptDecline&module=Calls&contact_id='.$call->current_notify_user->id.'&record='.$call->id);
499                 } elseif ( strtolower(get_class($call->current_notify_user)) == 'lead' ) {
500                         $xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
501                                   '/index.php?entryPoint=acceptDecline&module=Calls&lead_id='.$call->current_notify_user->id.'&record='.$call->id);
502                 } else {
503                         $xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
504                                   '/index.php?entryPoint=acceptDecline&module=Calls&user_id='.$call->current_notify_user->id.'&record='.$call->id);
505                 }
506
507                 $xtpl->assign("CALL_TO", $call->current_notify_user->new_assigned_user_name);
508                 $xtpl->assign("CALL_SUBJECT", $call->name);
509                 $xtpl->assign("CALL_STARTDATE", $xOffset);
510                 $xtpl->assign("CALL_HOURS", $call->duration_hours);
511                 $xtpl->assign("CALL_MINUTES", $call->duration_minutes);
512                 $xtpl->assign("CALL_STATUS", ((isset($call->status))?$app_list_strings['call_status_dom'][$call->status] : ""));
513                 $xtpl->assign("CALL_DESCRIPTION", $call->description);
514
515                 return $xtpl;
516         }
517
518
519         function get_call_users() {
520                 $template = new User();
521                 // First, get the list of IDs.
522                 $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";
523                 $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
524                 $result = $this->db->query($query, true);
525                 $list = Array();
526
527                 while($row = $this->db->fetchByAssoc($result)) {
528                         $template = new User(); // PHP 5 will retrieve by reference, always over-writing the "old" one
529                         $record = $template->retrieve($row['user_id']);
530                         $template->required = $row['required'];
531                         $template->accept_status = $row['accept_status'];
532
533                         if($record != null) {
534                             // this copies the object into the array
535                                 $list[] = $template;
536                         }
537                 }
538                 return $list;
539         }
540
541
542   function get_invite_calls(&$user)
543   {
544     $template = $this;
545     // First, get the list of IDs.
546     $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";
547     $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
548
549
550     $result = $this->db->query($query, true);
551
552
553     $list = Array();
554
555
556     while($row = $this->db->fetchByAssoc($result))
557     {
558       $record = $template->retrieve($row['call_id']);
559       $template->required = $row['required'];
560       $template->accept_status = $row['accept_status'];
561
562
563       if($record != null)
564       {
565         // this copies the object into the array
566         $list[] = $template;
567       }
568     }
569     return $list;
570
571   }
572
573
574   function set_accept_status(&$user,$status)
575   {
576     if ( $user->object_name == 'User')
577     {
578       $relate_values = array('user_id'=>$user->id,'call_id'=>$this->id);
579       $data_values = array('accept_status'=>$status);
580       $this->set_relationship($this->rel_users_table, $relate_values, true, true,$data_values);
581       global $current_user;
582
583       if ( $this->update_vcal )
584       {
585         vCal::cache_sugar_vcal($user);
586       }
587     }
588     else if ( $user->object_name == 'Contact')
589     {
590       $relate_values = array('contact_id'=>$user->id,'call_id'=>$this->id);
591       $data_values = array('accept_status'=>$status);
592       $this->set_relationship($this->rel_contacts_table, $relate_values, true, true,$data_values);
593     }
594     else if ( $user->object_name == 'Lead')
595     {
596       $relate_values = array('lead_id'=>$user->id,'call_id'=>$this->id);
597       $data_values = array('accept_status'=>$status);
598       $this->set_relationship($this->rel_leads_table, $relate_values, true, true,$data_values);
599     }
600   }
601
602
603
604         function get_notification_recipients() {
605                 if($this->special_notification) {
606                         return parent::get_notification_recipients();
607                 }
608
609 //              $GLOBALS['log']->debug('Call.php->get_notification_recipients():'.print_r($this,true));
610                 $list = array();
611         if(!is_array($this->contacts_arr)) {
612                         $this->contacts_arr =   array();
613                 }
614
615                 if(!is_array($this->users_arr)) {
616                         $this->users_arr =      array();
617                 }
618
619         if(!is_array($this->leads_arr)) {
620                         $this->leads_arr =      array();
621                 }
622
623                 foreach($this->users_arr as $user_id) {
624                         $notify_user = new User();
625                         $notify_user->retrieve($user_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->contacts_arr as $contact_id) {
632                         $notify_user = new Contact();
633                         $notify_user->retrieve($contact_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
639         foreach($this->leads_arr as $lead_id) {
640                         $notify_user = new Lead();
641                         $notify_user->retrieve($lead_id);
642                         $notify_user->new_assigned_user_name = $notify_user->full_name;
643                         $GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
644                         $list[$notify_user->id] = $notify_user;
645                 }
646 //              $GLOBALS['log']->debug('Call.php->get_notification_recipients():'.print_r($list,true));
647                 return $list;
648         }
649
650     function bean_implements($interface){
651                 switch($interface){
652                         case 'ACL':return true;
653                 }
654                 return false;
655         }
656
657         function listviewACLHelper(){
658                 $array_assign = parent::listviewACLHelper();
659                 $is_owner = false;
660                 if(!empty($this->parent_name)){
661
662                         if(!empty($this->parent_name_owner)){
663                                 global $current_user;
664                                 $is_owner = $current_user->id == $this->parent_name_owner;
665                         }
666                 }
667                         if(!ACLController::moduleSupportsACL($this->parent_type) || ACLController::checkAccess($this->parent_type, 'view', $is_owner)){
668                                 $array_assign['PARENT'] = 'a';
669                         }else{
670                                 $array_assign['PARENT'] = 'span';
671                         }
672                 $is_owner = false;
673                 if(!empty($this->contact_name)){
674
675                         if(!empty($this->contact_name_owner)){
676                                 global $current_user;
677                                 $is_owner = $current_user->id == $this->contact_name_owner;
678                         }
679                 }
680                         if( ACLController::checkAccess('Contacts', 'view', $is_owner)){
681                                 $array_assign['CONTACT'] = 'a';
682                         }else{
683                                 $array_assign['CONTACT'] = 'span';
684                         }
685
686                 return $array_assign;
687         }
688
689         function save_relationship_changes($is_update) {
690                 $exclude = array();
691                 if(empty($this->in_workflow))
692         {
693             if(empty($this->in_import))
694             {
695                 //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
696                 //add assigned_user_id to exclude list and let the logic from MeetingFormBase determine whether assigned user id gets added to the relationship
697                 if(!empty($GLOBALS['soap_server_object']))
698                 {
699                             $exclude = array('lead_id', 'contact_id', 'user_id');
700                     }
701                 else
702                 {
703                         $exclude = array('lead_id', 'contact_id', 'user_id', 'assigned_user_id');
704                     }
705             }
706             else
707             {
708                 $exclude = array('user_id');
709             }
710
711
712         }
713                 parent::save_relationship_changes($is_update, $exclude);
714         }
715
716     public function getDefaultStatus()
717     {
718          $def = $this->field_defs['status'];
719          if (isset($def['default'])) {
720              return $def['default'];
721          } else {
722             $app = return_app_list_strings_language($GLOBALS['current_language']);
723             if (isset($def['options']) && isset($app[$def['options']])) {
724                 $keys = array_keys($app[$def['options']]);
725                 return $keys[0];
726             }
727         }
728         return '';
729     }
730     
731     public function mark_deleted($id)
732     {
733         require_once("modules/Calendar/CalendarUtils.php");
734         CalendarUtils::correctRecurrences($this, $id);
735                 
736         parent::mark_deleted($id);
737     }
738 }