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