]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Meetings/Meeting.php
Release 6.2.2
[Github/sugarcrm.git] / modules / Meetings / Meeting.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-2011 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
47
48
49 // Meeting is used to store customer information.
50 class Meeting extends SugarBean {
51         // Stored fields
52         var $id;
53         var $date_entered;
54         var $date_modified;
55         var $assigned_user_id;
56         var $modified_user_id;
57         var $created_by;
58         var $created_by_name;
59         var $modified_by_name;
60         var $description;
61         var $name;
62         var $location;
63         var $status;
64         var $type;
65         var $date_start;
66         var $time_start;
67         var $date_end;
68         var $duration_hours;
69         var $duration_minutes;
70         var $time_meridiem;
71         var $parent_type;
72         var $parent_type_options;
73         var $parent_id;
74         var $field_name_map;
75         var $contact_id;
76         var $user_id;
77         var $meeting_id;
78         var $reminder_time;
79         var $reminder_checked;
80         var $required;
81         var $accept_status;
82         var $parent_name;
83         var $contact_name;
84         var $contact_phone;
85         var $contact_email;
86         var $account_id;
87         var $opportunity_id;
88         var $case_id;
89         var $assigned_user_name;
90         var $outlook_id;
91
92         var $update_vcal = true;
93         var $contacts_arr;
94         var $users_arr;
95         var $meetings_arr;
96         // when assoc w/ a user/contact:
97         var $minutes_value_default = 15;
98         var $minutes_values = array('0'=>'00','15'=>'15','30'=>'30','45'=>'45');
99         var $table_name = "meetings";
100         var $rel_users_table = "meetings_users";
101         var $rel_contacts_table = "meetings_contacts";
102         var $rel_leads_table = "meetings_leads";
103         var $module_dir = "Meetings";
104         var $object_name = "Meeting";
105
106         var $importable = true;
107         // This is used to retrieve related fields from form posts.
108         var $additional_column_fields = array('assigned_user_name', 'assigned_user_id', 'contact_id', 'user_id', 'contact_name', 'accept_status');
109         var $relationship_fields = array('account_id'=>'accounts','opportunity_id'=>'opportunity','case_id'=>'case',
110                                                                          'assigned_user_id'=>'users','contact_id'=>'contacts', 'user_id'=>'users', 'meeting_id'=>'meetings');
111         // so you can run get_users() twice and run query only once
112         var $cached_get_users = null;
113         var $new_schema = true;
114
115         /**
116          * sole constructor
117          */
118         function Meeting() {
119                 parent::SugarBean();
120                 $this->setupCustomFields('Meetings');
121                 foreach($this->field_defs as $field) {
122                         $this->field_name_map[$field['name']] = $field;
123                 }
124 //              $this->fill_in_additional_detail_fields();
125         if(!empty($GLOBALS['app_list_strings']['duration_intervals'])) {
126             $this->minutes_values = $GLOBALS['app_list_strings']['duration_intervals'];
127         }
128         }
129
130         /**
131          * Stub for integration
132          * @return bool
133          */
134         function hasIntegratedMeeting() {
135                 return false;
136         }
137
138         // save date_end by calculating user input
139         // this is for calendar
140         function save($check_notify = FALSE) {
141                 global $timedate;
142                 global $current_user;
143                 global $disable_date_format;
144                 
145             if(isset($this->date_start) && isset($this->duration_hours) && isset($this->duration_minutes)) 
146         {
147                 if(isset($this->date_start) && isset($this->duration_hours) && isset($this->duration_minutes)) 
148                 {
149                     $td = $timedate->fromDb($this->date_start);
150                     if($td)
151                     {
152                                 $this->date_end = $td->modify("+{$this->duration_hours} hours {$this->duration_minutes} mins")->asDb();
153                     }   
154                 }
155                 }                       
156
157                 $check_notify =(!empty($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == '1') ? true : false;
158                 if(empty($_REQUEST['send_invites'])) {
159                         if(!empty($this->id)) {
160                                 $old_record = new Meeting();
161                                 $old_record->retrieve($this->id);
162                                 $old_assigned_user_id = $old_record->assigned_user_id;
163                         }
164                         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']) ){
165                                 $this->special_notification = true;
166                                 $check_notify = true;
167                 if(isset($_REQUEST['assigned_user_name'])) {
168                     $this->new_assigned_user_name = $_REQUEST['assigned_user_name'];
169                 }
170                         }
171                 }
172                 /*nsingh 7/3/08  commenting out as bug #20814 is invalid
173                 if($current_user->getPreference('reminder_time')!= -1 &&  isset($_POST['reminder_checked']) && isset($_POST['reminder_time']) && $_POST['reminder_checked']==0  && $_POST['reminder_time']==-1){
174                         $this->reminder_checked = '1';
175                         $this->reminder_time = $current_user->getPreference('reminder_time');
176                 }*/
177
178         if (empty($this->status) ) {
179             $this->status = $this->getDefaultStatus();
180         }
181
182         // Do any external API saving
183         // Clear out the old external API stuff if we have changed types
184         if (isset($this->fetched_row) && $this->fetched_row['type'] != $this->type ) {
185             $this->join_url = '';
186             $this->host_url = '';
187             $this->external_id = '';
188             $this->creator = '';
189         }
190
191         if (!empty($this->type) && $this->type != 'Sugar' ) {
192             require_once('include/externalAPI/ExternalAPIFactory.php');
193             $api = ExternalAPIFactory::loadAPI($this->type);
194         }
195
196         if (empty($this->type)) {
197                         $this->type = 'Sugar';
198                 }
199
200         if ( isset($api) && is_a($api,'WebMeeting') ) {
201             // Make sure the API initialized and it supports Web Meetings
202             // Also make suer we have an ID, the external site needs something to reference
203             if ( !isset($this->id) || empty($this->id) ) {
204                 $this->id = create_guid();
205                 $this->new_with_id = true;
206             }
207             $response = $api->scheduleMeeting($this);
208             if ( $response['success'] == TRUE ) {
209                 // Need to send out notifications
210                 if ( $api->canInvite ) {
211                     $notifyList = $this->get_notification_recipients();
212                     foreach($notifyList as $person) {
213                         $api->inviteAttendee($this,$person,$check_notify);
214                     }
215
216                 }
217             } else {
218                 SugarApplication::appendErrorMessage($GLOBALS['app_strings']['ERR_EXTERNAL_API_SAVE_FAIL']);
219                 return $this->id;
220             }
221
222             $api->logoff();
223         }
224
225                 $return_id = parent::save($check_notify);
226
227                 if($this->update_vcal) {
228                         vCal::cache_sugar_vcal($current_user);
229                 }
230
231
232
233                 return $return_id;
234         }
235
236         // this is for calendar
237         function mark_deleted($id) {
238
239                 global $current_user;
240
241                 parent::mark_deleted($id);
242
243                 if($this->update_vcal) {
244                         vCal::cache_sugar_vcal($current_user);
245                 }
246         }
247
248         function get_summary_text() {
249                 return "$this->name";
250         }
251
252     function create_export_query(&$order_by, &$where, $relate_link_join='')
253     {
254         $custom_join = $this->custom_fields->getJOIN(true, true,$where);
255                 if($custom_join)
256                                 $custom_join['join'] .= $relate_link_join;
257                 $contact_required = stristr($where, "contacts");
258
259                 if($contact_required) {
260                         $query = "SELECT meetings.*, contacts.first_name, contacts.last_name, contacts.assigned_user_id contact_name_owner ";
261                         if($custom_join) {
262                                 $query .= $custom_join['select'];
263                         }
264                         $query .= " FROM contacts, meetings, meetings_contacts ";
265                         $where_auto = " meetings_contacts.contact_id = contacts.id AND meetings_contacts.meeting_id = meetings.id AND meetings.deleted=0 AND contacts.deleted=0";
266                 } else {
267                         $query = 'SELECT meetings.*';
268                         if($custom_join) {
269                                 $query .= $custom_join['select'];
270                         }
271                         $query .= ' FROM meetings ';
272                         $where_auto = "meetings.deleted=0";
273                 }
274
275                 if($custom_join) {
276                         $query .= $custom_join['join'];
277                 }
278
279                 if($where != "")
280                         $query .= " where $where AND ".$where_auto;
281                 else
282                         $query .= " where ".$where_auto;
283
284                 if($order_by != "") {
285                         $query .= " ORDER BY $order_by";
286                 } else {
287                         $alternate_order_by =   $this->process_order_by($order_by, null);
288                         if($alternate_order_by != "")
289                                 $query .=       " ORDER BY ". $alternate_order_by;
290                 }
291                 return $query;
292         }
293
294
295
296         function fill_in_additional_detail_fields() {
297                 global $locale;
298                 // Fill in the assigned_user_name
299                 $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
300
301                 if (!empty($this->contact_id)) {
302                         $query  = "SELECT first_name, last_name FROM contacts ";
303                         $query .= "WHERE id='$this->contact_id' AND deleted=0";
304                         $result = $this->db->limitQuery($query,0,1,true," Error filling in additional detail fields: ");
305
306                         // Get the contact name.
307                         $row = $this->db->fetchByAssoc($result);
308                         $GLOBALS['log']->info("additional call fields $query");
309                         if($row != null)
310                         {
311                                 $this->contact_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name'], '', '');
312                                 $GLOBALS['log']->debug("Call($this->id): contact_name = $this->contact_name");
313                                 $GLOBALS['log']->debug("Call($this->id): contact_id = $this->contact_id");
314                         }
315                 }
316
317
318
319                 $this->created_by_name = get_assigned_user_name($this->created_by);
320                 $this->modified_by_name = get_assigned_user_name($this->modified_user_id);
321                 $this->fill_in_additional_parent_fields();
322
323                 if (!isset($this->time_hour_start)) {
324                         $this->time_start_hour = intval(substr($this->time_start, 0, 2));
325                 } //if-else
326
327                 if (isset($this->time_minute_start)) {
328                         $time_start_minutes = $this->time_minute_start;
329                 } else {
330                         $time_start_minutes = substr($this->time_start, 3, 5);
331                         if ($time_start_minutes > 0 && $time_start_minutes < 15) {
332                                 $time_start_minutes = "15";
333                         } else if ($time_start_minutes > 15 && $time_start_minutes < 30) {
334                                 $time_start_minutes = "30";
335                         } else if ($time_start_minutes > 30 && $time_start_minutes < 45) {
336                                 $time_start_minutes = "45";
337                         } else if ($time_start_minutes > 45) {
338                                 $this->time_start_hour += 1;
339                                 $time_start_minutes = "00";
340                     } //if-else
341                 } //if-else
342
343
344                 if (isset($this->time_hour_start)) {
345                         $time_start_hour = $this->time_hour_start;
346                 } else {
347                         $time_start_hour = intval(substr($this->time_start, 0, 2));
348                 }
349
350                 global $timedate;
351         $this->time_meridiem = $timedate->AMPMMenu('', $this->time_start, 'onchange="SugarWidgetScheduler.update_time();"');
352                 $hours_arr = array ();
353                 $num_of_hours = 13;
354                 $start_at = 1;
355
356                 if (empty ($time_meridiem)) {
357                         $num_of_hours = 24;
358                         $start_at = 0;
359                 } //if
360
361                 for ($i = $start_at; $i < $num_of_hours; $i ++) {
362                         $i = $i."";
363                         if (strlen($i) == 1) {
364                                 $i = "0".$i;
365                         }
366                         $hours_arr[$i] = $i;
367                 } //for
368
369         if (!isset($this->duration_minutes)) {
370                         $this->duration_minutes = $this->minutes_value_default;
371                 }
372
373         //setting default date and time
374                 if (is_null($this->date_start))
375                         $this->date_start = $timedate->now();
376                 if (is_null($this->time_start))
377                         $this->time_start = $timedate->to_display_time(TimeDate::getInstance()->nowDb(), true);
378                 if (is_null($this->duration_hours)) {
379                         $this->duration_hours = "0";
380                 }
381                 if (is_null($this->duration_minutes))
382                         $this->duration_minutes = "1";
383
384                 global $app_list_strings;
385                 $parent_types = $app_list_strings['record_type_display'];
386                 $disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list');
387                 foreach($disabled_parent_types as $disabled_parent_type){
388                         if($disabled_parent_type != $this->parent_type){
389                                 unset($parent_types[$disabled_parent_type]);
390                         }
391                 }
392
393                 $this->parent_type_options = get_select_options_with_id($parent_types, $this->parent_type);
394                 if (empty($this->reminder_time)) {
395                         $this->reminder_time = -1;
396                 }
397
398                 if ( empty($this->id) ) {
399                     $reminder_t = $GLOBALS['current_user']->getPreference('reminder_time');
400                     if ( isset($reminder_t) )
401                         $this->reminder_time = $reminder_t;
402                 }
403                 $this->reminder_checked = $this->reminder_time == -1 ? false : true;
404
405                 if (isset ($_REQUEST['parent_type'])) {
406                         $this->parent_type = $_REQUEST['parent_type'];
407                 } elseif (is_null($this->parent_type)) {
408                         $this->parent_type = $app_list_strings['record_type_default_key'];
409                 }
410
411         }
412
413         function get_list_view_data() {
414                 $meeting_fields = $this->get_list_view_array();
415                 global $app_list_strings, $focus, $action, $currentModule;
416                 if(isset($this->parent_type))
417                         $meeting_fields['PARENT_MODULE'] = $this->parent_type;
418                 if($this->status == "Planned") {
419                         //cn: added this if() to deal with sequential Closes in Meetings.       this is a hack to a hack(formbase.php->handleRedirect)
420                         if(empty($action))
421                              $action = "index";
422             $setCompleteUrl = "<a onclick='SUGAR.util.closeActivityPanel.show(\"{$this->module_dir}\",\"{$this->id}\",\"Held\",\"listview\",\"1\");'>";
423                         $meeting_fields['SET_COMPLETE'] = $setCompleteUrl . SugarThemeRegistry::current()->getImage("close_inline","title=".translate('LBL_LIST_CLOSE','Meetings')." border='0'")."</a>";
424                 }
425                 global $timedate;
426                 $today = $timedate->nowDb();
427                 $nextday = $timedate->asDbDate($timedate->getNow()->get("+1 day")); 
428                 $mergeTime = $meeting_fields['DATE_START']; //$timedate->merge_date_time($meeting_fields['DATE_START'], $meeting_fields['TIME_START']);
429                 $date_db = $timedate->to_db($mergeTime);
430                 if($date_db     < $today        ) {
431                         $meeting_fields['DATE_START']= "<font class='overdueTask'>".$meeting_fields['DATE_START']."</font>";
432                 }else if($date_db       < $nextday) {
433                         $meeting_fields['DATE_START'] = "<font class='todaysTask'>".$meeting_fields['DATE_START']."</font>";
434                 } else {
435                         $meeting_fields['DATE_START'] = "<font class='futureTask'>".$meeting_fields['DATE_START']."</font>";
436                 }
437                 $this->fill_in_additional_detail_fields();
438
439                 //make sure we grab the localized version of the contact name, if a contact is provided
440                 if (!empty($this->contact_id)) {
441                         global $locale;
442                         $query  = "SELECT first_name, last_name, salutation, title FROM contacts ";
443                         $query .= "WHERE id='$this->contact_id' AND deleted=0";
444                         $result = $this->db->limitQuery($query,0,1,true," Error filling in contact name fields: ");
445
446                         // Get the contact name.
447                         $row = $this->db->fetchByAssoc($result);
448
449                         if($row != null)
450                         {
451                                 $this->contact_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name'], $row['salutation'], $row['title']);
452                         }
453                 }
454
455         $meeting_fields['CONTACT_ID'] = $this->contact_id;
456         $meeting_fields['CONTACT_NAME'] = $this->contact_name;
457
458                 $meeting_fields['PARENT_NAME'] = $this->parent_name;
459
460         $meeting_fields['REMINDER_CHECKED'] = $this->reminder_time==-1 ? false : true;
461
462                 
463                 return $meeting_fields;
464         }
465
466         function set_notification_body($xtpl, &$meeting) {
467                 global $sugar_config;
468                 global $app_list_strings;
469                 global $current_user;
470                 global $timedate;
471
472
473                 // cn: bug 9494 - passing a contact breaks this call
474                 $notifyUser =($meeting->current_notify_user->object_name == 'User') ? $meeting->current_notify_user : $current_user;
475                 // cn: bug 8078 - fixed call to $timedate
476                 $prefDate = $notifyUser->getUserDateTimePreferences();
477
478                 if(strtolower(get_class($meeting->current_notify_user)) == 'contact') {
479                         $xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
480                                                         '/index.php?entryPoint=acceptDecline&module=Meetings&contact_id='.$meeting->current_notify_user->id.'&record='.$meeting->id);
481                 } elseif(strtolower(get_class($meeting->current_notify_user)) == 'lead') {
482                         $xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
483                                                         '/index.php?entryPoint=acceptDecline&module=Meetings&lead_id='.$meeting->current_notify_user->id.'&record='.$meeting->id);
484                 } else {
485                         $xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
486                                                         '/index.php?entryPoint=acceptDecline&module=Meetings&user_id='.$meeting->current_notify_user->id.'&record='.$meeting->id);
487                 }
488                 $xtpl->assign("MEETING_TO", $meeting->current_notify_user->new_assigned_user_name);
489                 $xtpl->assign("MEETING_SUBJECT", trim($meeting->name));
490                 $xtpl->assign("MEETING_STATUS",(isset($meeting->status)? $app_list_strings['meeting_status_dom'][$meeting->status]:""));
491                 $typekey = strtolower($meeting->type);
492                 if(isset($meeting->type)) {
493                     if(!empty($app_list_strings['eapm_list'][$typekey])) {
494                     $typestring = $app_list_strings['eapm_list'][$typekey];
495                 } else {
496                         $typestring = $app_list_strings['meeting_type_dom'][$meeting->type];
497                     }
498                 }
499                 $xtpl->assign("MEETING_TYPE", isset($meeting->type)? $typestring:"");
500                 $xtpl->assign("MEETING_STARTDATE", $timedate->to_display_date_time($meeting->date_start,true,true,$notifyUser)." ".$prefDate['userGmt']);
501                 $xtpl->assign("MEETING_HOURS", $meeting->duration_hours);
502                 $xtpl->assign("MEETING_MINUTES", $meeting->duration_minutes);
503                 $xtpl->assign("MEETING_DESCRIPTION", $meeting->description);
504         if ( !empty($meeting->join_url) ) {
505             $xtpl->assign('MEETING_URL', $meeting->join_url);
506             $xtpl->parse('Meeting.Meeting_External_API');
507         }
508
509                 return $xtpl;
510         }
511
512         function get_meeting_users() {
513                 $template = new User();
514                 // First, get the list of IDs.
515                 $query = "SELECT meetings_users.required, meetings_users.accept_status, meetings_users.user_id from meetings_users where meetings_users.meeting_id='$this->id' AND meetings_users.deleted=0";
516                 $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
517                 $result = $this->db->query($query, true);
518                 $list = Array();
519
520                 while($row = $this->db->fetchByAssoc($result)) {
521                         $template = new User(); // PHP 5 will retrieve by reference, always over-writing the "old" one
522                         $record = $template->retrieve($row['user_id']);
523                         $template->required = $row['required'];
524                         $template->accept_status = $row['accept_status'];
525
526                         if($record != null) {
527                                 // this copies the object into the array
528                                 $list[] = $template;
529                         }
530                 }
531                 return $list;
532         }
533
534         function get_invite_meetings(&$user) {
535                 $template = $this;
536                 // First, get the list of IDs.
537                 $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
538                 $query = "SELECT meetings_users.required, meetings_users.accept_status, meetings_users.meeting_id from meetings_users where meetings_users.user_id='$user->id' AND( meetings_users.accept_status IS NULL OR     meetings_users.accept_status='none') AND meetings_users.deleted=0";
539                 $result = $this->db->query($query, true);
540                 $list = Array();
541
542                 while($row = $this->db->fetchByAssoc($result)) {
543                         $record = $template->retrieve($row['meeting_id']);
544                         $template->required = $row['required'];
545                         $template->accept_status = $row['accept_status'];
546
547
548                         if($record != null)
549                         {
550                         // this copies the object into the array
551                         $list[] = $template;
552                         }
553                 }
554                 return $list;
555         }
556
557
558         function set_accept_status(&$user,$status)
559         {
560                 if($user->object_name == 'User')
561                 {
562                         $relate_values = array('user_id'=>$user->id,'meeting_id'=>$this->id);
563                         $data_values = array('accept_status'=>$status);
564                         $this->set_relationship($this->rel_users_table, $relate_values, true, true,$data_values);
565                         global $current_user;
566
567                         if($this->update_vcal)
568                         {
569                                 vCal::cache_sugar_vcal($user);
570                         }
571                 }
572                 else if($user->object_name == 'Contact')
573                 {
574                         $relate_values = array('contact_id'=>$user->id,'meeting_id'=>$this->id);
575                         $data_values = array('accept_status'=>$status);
576                         $this->set_relationship($this->rel_contacts_table, $relate_values, true, true,$data_values);
577                 }
578         else if($user->object_name == 'Lead')
579                 {
580                         $relate_values = array('lead_id'=>$user->id,'meeting_id'=>$this->id);
581                         $data_values = array('accept_status'=>$status);
582                         $this->set_relationship($this->rel_leads_table, $relate_values, true, true,$data_values);
583                 }
584         }
585
586
587         function get_notification_recipients() {
588                 if($this->special_notification) {
589                         return parent::get_notification_recipients();
590                 }
591
592                 $list = array();
593                 if(!is_array($this->contacts_arr)) {
594                         $this->contacts_arr =   array();
595                 }
596
597                 if(!is_array($this->users_arr)) {
598                         $this->users_arr =      array();
599                 }
600
601         if(!is_array($this->leads_arr)) {
602                         $this->leads_arr =      array();
603                 }
604
605                 foreach($this->users_arr as $user_id) {
606                         $notify_user = new User();
607                         $notify_user->retrieve($user_id);
608                         $notify_user->new_assigned_user_name = $notify_user->full_name;
609                         $GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
610                         $list[$notify_user->id] = $notify_user;
611                 }
612
613                 foreach($this->contacts_arr as $contact_id) {
614                         $notify_user = new Contact();
615                         $notify_user->retrieve($contact_id);
616                         $notify_user->new_assigned_user_name = $notify_user->full_name;
617                         $GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
618                         $list[$notify_user->id] = $notify_user;
619                 }
620
621         foreach($this->leads_arr as $lead_id) {
622                         $notify_user = new Lead();
623                         $notify_user->retrieve($lead_id);
624                         $notify_user->new_assigned_user_name = $notify_user->full_name;
625                         $GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
626                         $list[$notify_user->id] = $notify_user;
627                 }
628
629                 return $list;
630         }
631
632
633         function bean_implements($interface) {
634                 switch($interface) {
635                         case 'ACL':return true;
636                 }
637                 return false;
638         }
639
640         function listviewACLHelper() {
641                 $array_assign = parent::listviewACLHelper();
642                 $is_owner = false;
643                 if(!empty($this->parent_name)) {
644
645                         if(!empty($this->parent_name_owner)) {
646                                 global $current_user;
647                                 $is_owner = $current_user->id == $this->parent_name_owner;
648                         }
649                 }
650
651                 if(!ACLController::moduleSupportsACL($this->parent_type) || ACLController::checkAccess($this->parent_type, 'view', $is_owner)) {
652                         $array_assign['PARENT'] = 'a';
653                 } else {
654                         $array_assign['PARENT'] = 'span';
655                 }
656
657                 $is_owner = false;
658
659                 if(!empty($this->contact_name)) {
660                         if(!empty($this->contact_name_owner)) {
661                                 global $current_user;
662                                 $is_owner = $current_user->id == $this->contact_name_owner;
663                         }
664                 }
665
666                 if(ACLController::checkAccess('Contacts', 'view', $is_owner)) {
667                         $array_assign['CONTACT'] = 'a';
668                 } else {
669                         $array_assign['CONTACT'] = 'span';
670                 }
671                 return $array_assign;
672         }
673
674
675         function save_relationship_changes($is_update) {
676                 $exclude = array();
677             if(empty($this->in_workflow)) {
678            if(empty($this->in_import)){//if a meeting is being imported then contact_id  should not be excluded
679            //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
680            //add assigned_user_id to exclude list and let the logic from MeetingFormBase determine whether assigned user id gets added to the relationship
681                 if(!empty($GLOBALS['soap_server_object'])){
682                         $exclude = array('contact_id', 'user_id');
683                 }else{
684                         $exclude = array('contact_id', 'user_id','assigned_user_id');
685                 }
686            }
687            else{
688                 $exclude = array('user_id');
689            }
690         }
691        parent::save_relationship_changes($is_update, $exclude);
692         }
693
694
695         /**
696          * @see SugarBean::afterImportSave()
697          */
698         public function afterImportSave()
699         {
700             if ( $this->parent_type == 'Contacts' ) {
701                 $this->load_relationship('contacts');
702                 if ( !$this->contacts->relationship_exists('contacts',array('id'=>$this->parent_id)) )
703                     $this->contacts->add($this->parent_id);
704             }
705             elseif ( $this->parent_type == 'Leads' ) {
706                 $this->load_relationship('leads');
707                 if ( !$this->leads->relationship_exists('leads',array('id'=>$this->parent_id)) )
708                     $this->leads->add($this->parent_id);
709             }
710
711             parent::afterImportSave();
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 } // end class def
729
730 // External API integration, for the dropdown list of what external API's are available
731 function getMeetingsExternalApiDropDown($focus = null, $name = null, $value = null, $view = null) {
732     require_once('include/externalAPI/ExternalAPIFactory.php');
733
734     $apiList = ExternalAPIFactory::getModuleDropDown('Meetings');
735     $apiList = array_merge(array('Sugar'=>$GLOBALS['app_list_strings']['eapm_list']['Sugar']),$apiList);
736     if(!empty($value) && empty($apiList[$value])){
737         $apiList[$value] = $value;
738     }
739     return $apiList;
740
741 }
742
743 ?>