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