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