Issues (4069)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

modules/Meetings/Meeting.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2 1
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-2013 SugarCRM Inc.
6
7
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
8
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
9
 *
10
 * This program is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU Affero General Public License version 3 as published by the
12
 * Free Software Foundation with the addition of the following permission added
13
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
14
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
15
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
16
 *
17
 * This program is distributed in the hope that it will be useful, but WITHOUT
18
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
20
 * details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License along with
23
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
 * 02110-1301 USA.
26
 *
27
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
28
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
29
 *
30
 * The interactive user interfaces in modified source and object code versions
31
 * of this program must display Appropriate Legal Notices, as required under
32
 * Section 5 of the GNU Affero General Public License version 3.
33
 *
34
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
35
 * these Appropriate Legal Notices must retain the display of the "Powered by
36
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
37
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
38
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39
 ********************************************************************************/
40
41
42
class Meeting extends SugarBean {
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 $email_reminder_time;
73
	var $email_reminder_checked;
74
	var $email_reminder_sent;
75
	var $required;
76
	var $accept_status;
77
	var $parent_name;
78
	var $contact_name;
79
	var $contact_phone;
80
	var $contact_email;
81
	var $account_id;
82
	var $opportunity_id;
83
	var $case_id;
84
	var $assigned_user_name;
85
	var $outlook_id;
86
	var $sequence;
87
	var $syncing = false;
88
	var $recurring_source;
89
90
	var $update_vcal = true;
91
	var $contacts_arr;
92
	var $users_arr;
93
	var $meetings_arr;
94
	// when assoc w/ a user/contact:
95
	var $minutes_value_default = 15;
96
	var $minutes_values = array('0'=>'00','15'=>'15','30'=>'30','45'=>'45');
97
	var $table_name = "meetings";
98
	var $rel_users_table = "meetings_users";
99
	var $rel_contacts_table = "meetings_contacts";
100
	var $rel_leads_table = "meetings_leads";
101
	var $module_dir = "Meetings";
102
	var $object_name = "Meeting";
103
104
	var $importable = true;
105
	// This is used to retrieve related fields from form posts.
106
	var $additional_column_fields = array('assigned_user_name', 'assigned_user_id', 'contact_id', 'user_id', 'contact_name', 'accept_status');
107
	var $relationship_fields = array('account_id'=>'accounts','opportunity_id'=>'opportunity','case_id'=>'case',
108
									 'assigned_user_id'=>'users','contact_id'=>'contacts', 'user_id'=>'users', 'meeting_id'=>'meetings');
109
	// so you can run get_users() twice and run query only once
110
	var $cached_get_users = null;
111
	var $new_schema = true;
112
    var $date_changed = false;
113
114
	/**
115
	 * sole constructor
116
	 */
117 52
	public function __construct() {
118 52
		parent::__construct();
119 52
		$this->setupCustomFields('Meetings');
120 52
		foreach($this->field_defs as $field) {
121 52
			$this->field_name_map[$field['name']] = $field;
122
		}
123
//		$this->fill_in_additional_detail_fields();
124 52
        if(!empty($GLOBALS['app_list_strings']['duration_intervals'])) {
125 52
            $this->minutes_values = $GLOBALS['app_list_strings']['duration_intervals'];
126
        }
127 52
	}
128
129
	/**
130
	 * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
131
	 */
132
	public function Meeting(){
133
		$deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
134
		if(isset($GLOBALS['log'])) {
135
			$GLOBALS['log']->deprecated($deprecatedMessage);
136
		}
137
		else {
138
			trigger_error($deprecatedMessage, E_USER_DEPRECATED);
139
		}
140
		self::__construct();
141
	}
142
143
	/**
144
	 * Disable edit if meeting is recurring and source is not Sugar. It should be edited only from Outlook.
145
	 * @param $view string
146
	 * @param $is_owner bool
147
	 */
148 6
	function ACLAccess($view,$is_owner='not_set',$in_group='not_set'){
149
		// don't check if meeting is being synced from Outlook
150 6
		if($this->syncing == false){
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
151 6
			$view = strtolower($view);
152
			switch($view){
153 6
				case 'edit':
154 5
				case 'save':
155 5
				case 'editview':
156 5
				case 'delete':
157 5
					if(!empty($this->recurring_source) && $this->recurring_source != "Sugar"){
158 1
						return false;
159
					}
160
			}
161
		}
162 6
		return parent::ACLAccess($view,$is_owner,$in_group);
163
	}
164
165
	/**
166
	 * Stub for integration
167
	 * @return bool
168
	 */
169 1
	function hasIntegratedMeeting() {
170 1
		return false;
171
	}
172
173
	// save date_end by calculating user input
174
	// this is for calendar
175 1
	function save($check_notify = FALSE) {
176 1
		global $timedate;
177 1
		global $current_user;
178
179 1
		global $disable_date_format;
180
181 1
        if(isset($this->date_start))
182
        {
183 1
            $td = $timedate->fromDb($this->date_start);
184 1
            if(!$td){
185
            		$this->date_start = $timedate->to_db($this->date_start);
186
            		$td = $timedate->fromDb($this->date_start);
187
            }
188 1
            if($td)
189
            {
190 1
                if (isset($this->duration_hours) && $this->duration_hours != '')
191
                {
192 1
                    $td->modify("+{$this->duration_hours} hours");
193
                }
194 1
                if (isset($this->duration_minutes) && $this->duration_minutes != '')
195
                {
196 1
                    $td->modify("+{$this->duration_minutes} mins");
197
                }
198 1
                $this->date_end = $td->asDb();
199
            }
200
        }
201
202 1
		$check_notify =(!empty($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == '1') ? true : false;
203 1
		if(empty($_REQUEST['send_invites'])) {
204 1
			if(!empty($this->id)) {
205
				$old_record = new Meeting();
206
				$old_record->retrieve($this->id);
207
				$old_assigned_user_id = $old_record->assigned_user_id;
208
			}
209 1
			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']) ){
210
				$this->special_notification = true;
211
				$check_notify = true;
212
                if(isset($_REQUEST['assigned_user_name'])) {
213
                    $this->new_assigned_user_name = $_REQUEST['assigned_user_name'];
214
                }
215
			}
216
		}
217
		/*nsingh 7/3/08  commenting out as bug #20814 is invalid
218
		if($current_user->getPreference('reminder_time')!= -1 &&  isset($_POST['reminder_checked']) && isset($_POST['reminder_time']) && $_POST['reminder_checked']==0  && $_POST['reminder_time']==-1){
219
			$this->reminder_checked = '1';
220
			$this->reminder_time = $current_user->getPreference('reminder_time');
221
		}*/
222
223
		// prevent a mass mailing for recurring meetings created in Calendar module
224 1
		if(empty($this->id) && !empty($_REQUEST['module']) && $_REQUEST['module'] == "Calendar" && !empty($_REQUEST['repeat_type']) && !empty($this->repeat_parent_id))
225
			$check_notify = false;
226
227 1
        if (empty($this->status) ) {
228
            $this->status = $this->getDefaultStatus();
229
        }
230
231
        // Do any external API saving
232
        // Clear out the old external API stuff if we have changed types
233 1
        if (isset($this->fetched_row) && $this->fetched_row['type'] != $this->type ) {
234 1
            $this->join_url = '';
235 1
            $this->host_url = '';
236 1
            $this->external_id = '';
237 1
            $this->creator = '';
238
        }
239
240 1
        if (!empty($this->type) && $this->type != 'Sugar' ) {
241
            require_once('include/externalAPI/ExternalAPIFactory.php');
242
            $api = ExternalAPIFactory::loadAPI($this->type);
243
        }
244
245 1
        if (empty($this->type)) {
246
			$this->type = 'Sugar';
247
		}
248
249 1
        if ( isset($api) && is_a($api,'WebMeeting') && empty($this->in_relationship_update) ) {
250
            // Make sure the API initialized and it supports Web Meetings
251
            // Also make suer we have an ID, the external site needs something to reference
252
            if ( !isset($this->id) || empty($this->id) ) {
253
                $this->id = create_guid();
254
                $this->new_with_id = true;
255
            }
256
            $response = $api->scheduleMeeting($this);
0 ignored issues
show
The method scheduleMeeting() does not seem to exist on object<ExternalAPIBase>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
257
            if ( $response['success'] == TRUE ) {
258
                // Need to send out notifications
259
                if ( $api->canInvite ) {
260
                    $notifyList = $this->get_notification_recipients();
261
                    foreach($notifyList as $person) {
262
                        $api->inviteAttendee($this,$person,$check_notify);
0 ignored issues
show
The method inviteAttendee() does not seem to exist on object<ExternalAPIBase>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
263
                    }
264
265
                }
266
            } else {
267
                // Generic Message Provides no value to End User - Log the issue with message detail and continue
268
                // SugarApplication::appendErrorMessage($GLOBALS['app_strings']['ERR_EXTERNAL_API_SAVE_FAIL']);
269
                $GLOBALS['log']->warn('ERR_EXTERNAL_API_SAVE_FAIL' . ": " . $this->type . " - " .  $response['errorMessage']);
270
            }
271
272
            $api->logoff();
0 ignored issues
show
The call to the method ExternalAPIBase::logOff() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
273
        }
274
275 1
		$return_id = parent::save($check_notify);
276
277 1
		if($this->update_vcal) {
278 1
			vCal::cache_sugar_vcal($current_user);
279
		}
280
281 1
		if(isset($_REQUEST['reminders_data'])) {
282
			Reminder::saveRemindersDataJson('Meetings', $return_id, html_entity_decode($_REQUEST['reminders_data']));
283
		}
284
285
286 1
		return $return_id;
287
	}
288
289
	// this is for calendar
290 1
	function mark_deleted($id) {
291
292 1
		require_once("modules/Calendar/CalendarUtils.php");
293 1
		CalendarUtils::correctRecurrences($this, $id);
294
295 1
		global $current_user;
296
297 1
		parent::mark_deleted($id);
298
299 1
		if($this->update_vcal) {
300 1
			vCal::cache_sugar_vcal($current_user);
301
		}
302 1
	}
303
304 2
	function get_summary_text() {
305 2
		return "$this->name";
306
	}
307
308 1
    function create_export_query($order_by, $where, $relate_link_join='')
309
    {
310 1
        $custom_join = $this->getCustomJoin(true, true, $where);
311 1
        $custom_join['join'] .= $relate_link_join;
312 1
		$contact_required = stristr($where, "contacts");
313
314 1
		if($contact_required) {
315
			$query = "SELECT meetings.*, contacts.first_name, contacts.last_name, contacts.assigned_user_id contact_name_owner, users.user_name as assigned_user_name   ";
316
            $query .= $custom_join['select'];
317
			$query .= " FROM contacts, meetings, meetings_contacts ";
318
			$where_auto = " meetings_contacts.contact_id = contacts.id AND meetings_contacts.meeting_id = meetings.id AND meetings.deleted=0 AND contacts.deleted=0";
319
		} else {
320 1
			$query = 'SELECT meetings.*, users.user_name as assigned_user_name  ';
321 1
            $query .= $custom_join['select'];
322 1
			$query .= ' FROM meetings ';
323 1
			$where_auto = "meetings.deleted=0";
324
		}
325 1
		$query .= "  LEFT JOIN users ON meetings.assigned_user_id=users.id ";
326
327 1
        $query .= $custom_join['join'];
328
329 1
		if($where != "")
330 1
			$query .= " where $where AND ".$where_auto;
331
		else
332 1
			$query .= " where ".$where_auto;
333
334 1
        $order_by = $this->process_order_by($order_by);
335 1
        if (!empty($order_by)) {
336
            $query .= ' ORDER BY ' . $order_by;
337
        }
338
339 1
		return $query;
340
	}
341
342
343
344 4
	function fill_in_additional_detail_fields() {
345 4
		global $locale;
346
		// Fill in the assigned_user_name
347 4
		$this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
348
349 4
		if (!empty($this->contact_id)) {
350 2
			$query  = "SELECT first_name, last_name FROM contacts ";
351 2
			$query .= "WHERE id='$this->contact_id' AND deleted=0";
352 2
			$result = $this->db->limitQuery($query,0,1,true," Error filling in additional detail fields: ");
353
354
			// Get the contact name.
355 2
			$row = $this->db->fetchByAssoc($result);
356 2
			$GLOBALS['log']->info("additional call fields $query");
357 2
			if($row != null)
358
			{
359
				$this->contact_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name'], '', '');
360
				$GLOBALS['log']->debug("Call($this->id): contact_name = $this->contact_name");
361
				$GLOBALS['log']->debug("Call($this->id): contact_id = $this->contact_id");
362
			}
363
		}
364
365
366
367 4
		$this->created_by_name = get_assigned_user_name($this->created_by);
368 4
		$this->modified_by_name = get_assigned_user_name($this->modified_user_id);
369 4
		$this->fill_in_additional_parent_fields();
370
371 4
		if (!isset($this->time_hour_start)) {
372 4
			$this->time_start_hour = intval(substr($this->time_start, 0, 2));
373
		} //if-else
374
375 4
		if (isset($this->time_minute_start)) {
376
			$time_start_minutes = $this->time_minute_start;
377
		} else {
378 4
			$time_start_minutes = substr($this->time_start, 3, 5);
379 4
			if ($time_start_minutes > 0 && $time_start_minutes < 15) {
380
				$time_start_minutes = "15";
381 4
			} else if ($time_start_minutes > 15 && $time_start_minutes < 30) {
382
				$time_start_minutes = "30";
383 4
			} else if ($time_start_minutes > 30 && $time_start_minutes < 45) {
384
				$time_start_minutes = "45";
385 4
			} else if ($time_start_minutes > 45) {
386
				$this->time_start_hour += 1;
387
				$time_start_minutes = "00";
388
		    } //if-else
389
		} //if-else
390
391
392 4
		if (isset($this->time_hour_start)) {
393
			$time_start_hour = $this->time_hour_start;
394
		} else {
395 4
			$time_start_hour = intval(substr($this->time_start, 0, 2));
396
		}
397
398 4
		global $timedate;
399 4
        $this->time_meridiem = $timedate->AMPMMenu('', $this->time_start, 'onchange="SugarWidgetScheduler.update_time();"');
400 4
		$hours_arr = array ();
401 4
		$num_of_hours = 13;
402 4
		$start_at = 1;
403
404 4
		if (empty ($time_meridiem)) {
0 ignored issues
show
The variable $time_meridiem seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
405 4
			$num_of_hours = 24;
406 4
			$start_at = 0;
407
		} //if
408
409 4
		for ($i = $start_at; $i < $num_of_hours; $i ++) {
410 4
			$i = $i."";
411 4
			if (strlen($i) == 1) {
412 4
				$i = "0".$i;
413
			}
414 4
			$hours_arr[$i] = $i;
415
		} //for
416
417 4
        if (!isset($this->duration_minutes)) {
418 3
			$this->duration_minutes = $this->minutes_value_default;
419
		}
420
421
        //setting default date and time
422 4
		if (is_null($this->date_start))
423 3
			$this->date_start = $timedate->now();
424 4
		if (is_null($this->time_start))
425 4
			$this->time_start = $timedate->to_display_time(TimeDate::getInstance()->nowDb(), true);
426 4
		if (is_null($this->duration_hours)) {
427 3
			$this->duration_hours = "0";
428
		}
429 4
		if (is_null($this->duration_minutes))
430
			$this->duration_minutes = "1";
431
432 4
		if(empty($this->id) && !empty($_REQUEST['date_start'])){
433
			$this->date_start = $_REQUEST['date_start'];
434
		}
435 4
        if(!empty($this->date_start))
436
        {
437 4
            $td = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(),$this->date_start);
438 4
            if (!empty($td))
439
            {
440 4
    	        if (!empty($this->duration_hours) && $this->duration_hours != '')
441
                {
442 1
		            $td = $td->modify("+{$this->duration_hours} hours");
443
		        }
444 4
                if (!empty($this->duration_minutes) && $this->duration_minutes != '')
445
                {
446 4
                    $td = $td->modify("+{$this->duration_minutes} mins");
447
                }
448 4
                $this->date_end = $td->format($GLOBALS['timedate']->get_date_time_format());
449
            }
450
            else
451
            {
452
                $GLOBALS['log']->fatal("Meeting::save: Bad date {$this->date_start} for format ".$GLOBALS['timedate']->get_date_time_format());
453
            }
454
		}
455
456 4
		global $app_list_strings;
457 4
		$parent_types = $app_list_strings['record_type_display'];
458 4
		$disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list');
459 4
		foreach($disabled_parent_types as $disabled_parent_type){
460
			if($disabled_parent_type != $this->parent_type){
461
				unset($parent_types[$disabled_parent_type]);
462
			}
463
		}
464
465 4
		$this->parent_type_options = get_select_options_with_id($parent_types, $this->parent_type);
466 4
		if (empty($this->reminder_time)) {
467
			$this->reminder_time = -1;
468
		}
469
470 4
		if ( empty($this->id) ) {
471 3
		    $reminder_t = $GLOBALS['current_user']->getPreference('reminder_time');
472 3
		    if ( isset($reminder_t) )
473
		        $this->reminder_time = $reminder_t;
474
		}
475 4
		$this->reminder_checked = $this->reminder_time == -1 ? false : true;
476
477 4
		if (empty($this->email_reminder_time)) {
478
			$this->email_reminder_time = -1;
479
		}
480 4
		if(empty($this->id)){
481 3
			$reminder_t = $GLOBALS['current_user']->getPreference('email_reminder_time');
482 3
			if(isset($reminder_t))
483
		    		$this->email_reminder_time = $reminder_t;
484
		}
485 4
		$this->email_reminder_checked = $this->email_reminder_time == -1 ? false : true;
486
487 4
		if (isset ($_REQUEST['parent_type']) && empty($this->parent_type)) {
488
			$this->parent_type = $_REQUEST['parent_type'];
489 4
		} elseif (is_null($this->parent_type)) {
490 2
			$this->parent_type = $app_list_strings['record_type_default_key'];
491
		}
492
493 4
	}
494
495 1
	function get_list_view_data() {
496 1
		$meeting_fields = $this->get_list_view_array();
497
498 1
		global $app_list_strings, $focus, $action, $currentModule;
499 1
		if(isset($this->parent_type))
500 1
			$meeting_fields['PARENT_MODULE'] = $this->parent_type;
501 1
		if($this->status == "Planned") {
502
			//cn: added this if() to deal with sequential Closes in Meetings.	this is a hack to a hack(formbase.php->handleRedirect)
503 1
			if(empty($action))
504 1
			     $action = "index";
505 1
            $setCompleteUrl = "<a id='{$this->id}' onclick='SUGAR.util.closeActivityPanel.show(\"{$this->module_dir}\",\"{$this->id}\",\"Held\",\"listview\",\"1\");'>";
506 1
			if ($this->ACLAccess('edit')) {
507 1
                $meeting_fields['SET_COMPLETE'] = $setCompleteUrl . SugarThemeRegistry::current()->getImage("close_inline"," border='0'",null,null,'.gif',translate('LBL_CLOSEINLINE'))."</a>";
508
            } else {
509
                $meeting_fields['SET_COMPLETE'] = '';
510
            }
511
		}
512 1
		global $timedate;
513 1
		$today = $timedate->nowDb();
514 1
		$nextday = $timedate->asDbDate($timedate->getNow()->get("+1 day"));
515 1
		$mergeTime = $meeting_fields['DATE_START']; //$timedate->merge_date_time($meeting_fields['DATE_START'], $meeting_fields['TIME_START']);
516 1
		$date_db = $timedate->to_db($mergeTime);
517 1
		if($date_db	< $today	) {
518 1
			$meeting_fields['DATE_START']= "<font class='overdueTask'>".$meeting_fields['DATE_START']."</font>";
519
		}else if($date_db	< $nextday) {
520
			$meeting_fields['DATE_START'] = "<font class='todaysTask'>".$meeting_fields['DATE_START']."</font>";
521
		} else {
522
			$meeting_fields['DATE_START'] = "<font class='futureTask'>".$meeting_fields['DATE_START']."</font>";
523
		}
524 1
		$this->fill_in_additional_detail_fields();
525
526
        // make sure we grab the localized version of the contact name, if a contact is provided
527 1
        if (!empty($this->contact_id))
528
        {
529 1
            $contact_temp = BeanFactory::getBean("Contacts", $this->contact_id);
530 1
            if (!empty($contact_temp))
531
            {
532
                // Make first name, last name, salutation and title of Contacts respect field level ACLs
533
                $contact_temp->_create_proper_name_field();
534
                $this->contact_name = $contact_temp->full_name;
535
            }
536
        }
537
538 1
        $meeting_fields['CONTACT_ID'] = $this->contact_id;
539 1
        $meeting_fields['CONTACT_NAME'] = $this->contact_name;
540 1
		$meeting_fields['PARENT_NAME'] = $this->parent_name;
541 1
        $meeting_fields['REMINDER_CHECKED'] = $this->reminder_time==-1 ? false : true;
542 1
        $meeting_fields['EMAIL_REMINDER_CHECKED'] = $this->email_reminder_time==-1 ? false : true;
543
544
545 1
		return $meeting_fields;
546
	}
547
548 3
	function set_notification_body($xtpl, &$meeting) {
549 3
		global $sugar_config;
550 3
		global $app_list_strings;
551 3
		global $current_user;
552 3
		global $timedate;
553
554
555
		// cn: bug 9494 - passing a contact breaks this call
556 3
		$notifyUser =($meeting->current_notify_user->object_name == 'User') ? $meeting->current_notify_user : $current_user;
557
		// cn: bug 8078 - fixed call to $timedate
558 3
		if(strtolower(get_class($meeting->current_notify_user)) == 'contact') {
559
			$xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
560
							'/index.php?entryPoint=acceptDecline&module=Meetings&contact_id='.$meeting->current_notify_user->id.'&record='.$meeting->id);
561 3
		} elseif(strtolower(get_class($meeting->current_notify_user)) == 'lead') {
562
			$xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
563
							'/index.php?entryPoint=acceptDecline&module=Meetings&lead_id='.$meeting->current_notify_user->id.'&record='.$meeting->id);
564
		} else {
565 3
			$xtpl->assign("ACCEPT_URL", $sugar_config['site_url'].
566 3
							'/index.php?entryPoint=acceptDecline&module=Meetings&user_id='.$meeting->current_notify_user->id.'&record='.$meeting->id);
567
		}
568 3
		$xtpl->assign("MEETING_TO", $meeting->current_notify_user->new_assigned_user_name);
569 3
		$xtpl->assign("MEETING_SUBJECT", trim($meeting->name));
570 3
		$xtpl->assign("MEETING_STATUS",(isset($meeting->status)? $app_list_strings['meeting_status_dom'][$meeting->status]:""));
571 3
		$typekey = strtolower($meeting->type);
572 3
		if(isset($meeting->type)) {
573 3
		    if(!empty($app_list_strings['eapm_list'][$typekey])) {
574
    		    $typestring = $app_list_strings['eapm_list'][$typekey];
575
	    	} else {
576 3
		        $typestring = $app_list_strings['meeting_type_dom'][$meeting->type];
577
		    }
578
		}
579 3
		$xtpl->assign("MEETING_TYPE", isset($meeting->type)? $typestring:"");
580 3
		$startdate = $timedate->fromDb($meeting->date_start);
581 3
		$xtpl->assign("MEETING_STARTDATE", $timedate->asUser($startdate, $notifyUser)." ".TimeDate::userTimezoneSuffix($startdate, $notifyUser));
582 3
		$enddate = $timedate->fromDb($meeting->date_end);
583 3
		$xtpl->assign("MEETING_ENDDATE", $timedate->asUser($enddate, $notifyUser)." ".TimeDate::userTimezoneSuffix($enddate, $notifyUser));
584 3
		$xtpl->assign("MEETING_HOURS", $meeting->duration_hours);
585 3
		$xtpl->assign("MEETING_MINUTES", $meeting->duration_minutes);
586 3
		$xtpl->assign("MEETING_DESCRIPTION", $meeting->description);
587 3
        if ( !empty($meeting->join_url) ) {
588
            $xtpl->assign('MEETING_URL', $meeting->join_url);
589
            $xtpl->parse('Meeting.Meeting_External_API');
590
        }
591
592 3
		return $xtpl;
593
	}
594
595
	/**
596
	 * Redefine method to attach ics file to notification email
597
	 */
598 2
	public function create_notification_email($notify_user){
599
        // reset acceptance status for non organizer if date is changed
600 2
        if (($notify_user->id != $GLOBALS['current_user']->id) && $this->date_changed) {
601
            $this->set_accept_status($notify_user, 'none');
602
        }
603
604 2
		$notify_mail = parent::create_notification_email($notify_user);
605
606 2
		$path = SugarConfig::getInstance()->get('upload_dir','upload/') . $this->id;
607
608 2
		require_once("modules/vCals/vCal.php");
609 2
		$content = vCal::get_ical_event($this, $GLOBALS['current_user']);
610
611 2
		if(file_put_contents($path,$content)){
612
			$notify_mail->AddAttachment($path, 'meeting.ics', 'base64', 'text/calendar');
613
		}
614 2
		return $notify_mail;
615
	}
616
617
	/**
618
	 * Redefine method to remove ics after email is sent
619
	 */
620 1
	public function send_assignment_notifications($notify_user, $admin){
621 1
		parent::send_assignment_notifications($notify_user, $admin);
622
623 1
		$path = SugarConfig::getInstance()->get('upload_dir','upload/') . $this->id;
624 1
		unlink($path);
625 1
	}
626
627 1
	function get_meeting_users() {
628 1
		$template = new User();
629
		// First, get the list of IDs.
630 1
		$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";
631 1
		$GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
632 1
		$result = $this->db->query($query, true);
633 1
		$list = Array();
634
635 1
		while($row = $this->db->fetchByAssoc($result)) {
636
			$template = new User(); // PHP 5 will retrieve by reference, always over-writing the "old" one
637
			$record = $template->retrieve($row['user_id']);
638
			$template->required = $row['required'];
639
			$template->accept_status = $row['accept_status'];
640
641
			if($record != null) {
642
				// this copies the object into the array
643
				$list[] = $template;
644
			}
645
		}
646 1
		return $list;
647
	}
648
649 1
	function get_invite_meetings(&$user) {
650 1
		$template = $this;
651
		// First, get the list of IDs.
652 1
		$GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
0 ignored issues
show
The variable $query seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
653 1
		$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";
654 1
		$result = $this->db->query($query, true);
655 1
		$list = Array();
656
657 1
		while($row = $this->db->fetchByAssoc($result)) {
658
			$record = $template->retrieve($row['meeting_id']);
659
			$template->required = $row['required'];
660
			$template->accept_status = $row['accept_status'];
661
662
663
			if($record != null)
664
			{
665
			// this copies the object into the array
666
			$list[] = $template;
667
			}
668
		}
669 1
		return $list;
670
	}
671
672
673 1
	function set_accept_status(&$user,$status)
674
	{
675 1
		if($user->object_name == 'User')
676
		{
677 1
			$relate_values = array('user_id'=>$user->id,'meeting_id'=>$this->id);
678 1
			$data_values = array('accept_status'=>$status);
679 1
			$this->set_relationship($this->rel_users_table, $relate_values, true, true,$data_values);
680 1
			global $current_user;
681
682 1
			if($this->update_vcal)
683
			{
684 1
				vCal::cache_sugar_vcal($user);
685
			}
686
		}
687 1
		else if($user->object_name == 'Contact')
688
		{
689 1
			$relate_values = array('contact_id'=>$user->id,'meeting_id'=>$this->id);
690 1
			$data_values = array('accept_status'=>$status);
691 1
			$this->set_relationship($this->rel_contacts_table, $relate_values, true, true,$data_values);
692
		}
693 1
        else if($user->object_name == 'Lead')
694
		{
695 1
			$relate_values = array('lead_id'=>$user->id,'meeting_id'=>$this->id);
696 1
			$data_values = array('accept_status'=>$status);
697 1
			$this->set_relationship($this->rel_leads_table, $relate_values, true, true,$data_values);
698
		}
699 1
	}
700
701
702 1
	function get_notification_recipients() {
703 1
		if($this->special_notification) {
704 1
			return parent::get_notification_recipients();
705
		}
706
707 1
		$list = array();
708 1
		if(!is_array($this->contacts_arr)) {
709 1
			$this->contacts_arr =	array();
710
		}
711
712 1
		if(!is_array($this->users_arr)) {
713 1
			$this->users_arr =	array();
714
		}
715
716 1
        if(!is_array($this->leads_arr)) {
717 1
			$this->leads_arr =	array();
718
		}
719
720 1
		foreach($this->users_arr as $user_id) {
721
			$notify_user = new User();
722
			$notify_user->retrieve($user_id);
723
			$notify_user->new_assigned_user_name = $notify_user->full_name;
724
			$GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
725
			$list[$notify_user->id] = $notify_user;
726
		}
727
728 1
		foreach($this->contacts_arr as $contact_id) {
729
			$notify_user = new Contact();
730
			$notify_user->retrieve($contact_id);
731
			$notify_user->new_assigned_user_name = $notify_user->full_name;
732
			$GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
733
			$list[$notify_user->id] = $notify_user;
734
		}
735
736 1
        foreach($this->leads_arr as $lead_id) {
737
			$notify_user = new Lead();
738
			$notify_user->retrieve($lead_id);
739
			$notify_user->new_assigned_user_name = $notify_user->full_name;
740
			$GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name");
741
			$list[$notify_user->id] = $notify_user;
742
		}
743
744 1
		global $sugar_config;
745 1
		if(isset($sugar_config['disable_notify_current_user']) && $sugar_config['disable_notify_current_user']) {
746
			global $current_user;
747
			if(isset($list[$current_user->id]))
748
				unset($list[$current_user->id]);
749
		}
750 1
		return $list;
751
	}
752
753
754 52
	function bean_implements($interface) {
755
		switch($interface) {
756 52
			case 'ACL':return true;
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
757
		}
758 2
		return false;
759
	}
760
761 1
	function listviewACLHelper() {
762 1
		$array_assign = parent::listviewACLHelper();
763 1
		$is_owner = false;
764 1
		$in_group = false; //SECURITY GROUPS
765 1
		if(!empty($this->parent_name)) {
766
767
			if(!empty($this->parent_name_owner)) {
768
				global $current_user;
769
				$is_owner = $current_user->id == $this->parent_name_owner;
770
			}
771
			/* BEGIN - SECURITY GROUPS */
772
			//parent_name_owner not being set for whatever reason so we need to figure this out
773
			else if(!empty($this->parent_type) && !empty($this->parent_id)) {
774
				global $current_user;
775
                $parent_bean = BeanFactory::getBean($this->parent_type,$this->parent_id);
776
                if($parent_bean !== false) {
777
                	$is_owner = $current_user->id == $parent_bean->assigned_user_id;
778
                }
779
			}
780
			require_once("modules/SecurityGroups/SecurityGroup.php");
781
			$in_group = SecurityGroup::groupHasAccess($this->parent_type, $this->parent_id, 'view');
782
        	/* END - SECURITY GROUPS */
783
		}
784
785
		/* BEGIN - SECURITY GROUPS */
786
		/**
787
		if(!ACLController::moduleSupportsACL($this->parent_type) || ACLController::checkAccess($this->parent_type, 'view', $is_owner)) {
788
		*/
789 1
		if(!ACLController::moduleSupportsACL($this->parent_type) || ACLController::checkAccess($this->parent_type, 'view', $is_owner, 'module', $in_group)){
790
        /* END - SECURITY GROUPS */
791 1
			$array_assign['PARENT'] = 'a';
792
		} else {
793
			$array_assign['PARENT'] = 'span';
794
		}
795
796 1
		$is_owner = false;
797 1
		$in_group = false; //SECURITY GROUPS
798
799 1
		if(!empty($this->contact_name)) {
800
			if(!empty($this->contact_name_owner)) {
801
				global $current_user;
802
				$is_owner = $current_user->id == $this->contact_name_owner;
803
			}
804
			/* BEGIN - SECURITY GROUPS */
805
			//contact_name_owner not being set for whatever reason so we need to figure this out
806
			else {
807
				global $current_user;
808
                $parent_bean = BeanFactory::getBean('Contacts',$this->contact_id);
809
                if($parent_bean !== false) {
810
                	$is_owner = $current_user->id == $parent_bean->assigned_user_id;
811
                }
812
			}
813
			require_once("modules/SecurityGroups/SecurityGroup.php");
814
			$in_group = SecurityGroup::groupHasAccess('Contacts', $this->contact_id, 'view');
815
        	/* END - SECURITY GROUPS */
816
		}
817
818
		/* BEGIN - SECURITY GROUPS */
819
		/**
820
		if(ACLController::checkAccess('Contacts', 'view', $is_owner)) {
821
		*/
822 1
		if(ACLController::checkAccess('Contacts', 'view', $is_owner, 'module', $in_group)) {
823
        /* END - SECURITY GROUPS */
824 1
			$array_assign['CONTACT'] = 'a';
825
		} else {
826
			$array_assign['CONTACT'] = 'span';
827
		}
828 1
		return $array_assign;
829
	}
830
831
832 2
	function save_relationship_changes($is_update, $exclude = array()) {
833 2
	    if(empty($this->in_workflow)) {
834 2
           if(empty($this->in_import)){//if a meeting is being imported then contact_id  should not be excluded
835
           //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
836
           //add assigned_user_id to exclude list and let the logic from MeetingFormBase determine whether assigned user id gets added to the relationship
837 2
           	if(!empty($GLOBALS['soap_server_object'])){
838
           		$exclude = array('contact_id', 'user_id');
839
           	}else{
840 2
	    		$exclude = array('contact_id', 'user_id','assigned_user_id');
841
           	}
842
           }
843
           else{
844
           	$exclude = array('user_id');
845
           }
846
        }
847 2
       parent::save_relationship_changes($is_update, $exclude);
848 2
	}
849
850
851
	/**
852
	 * @see SugarBean::afterImportSave()
853
	 */
854 1
	public function afterImportSave()
855
	{
856 1
	    if ( $this->parent_type == 'Contacts' ) {
857 1
	        $this->load_relationship('contacts');
858 1
	        if ( !$this->contacts->relationship_exists('contacts',array('id'=>$this->parent_id)) )
859 1
	            $this->contacts->add($this->parent_id);
860
	    }
861 1
	    elseif ( $this->parent_type == 'Leads' ) {
862 1
	        $this->load_relationship('leads');
863 1
	        if ( !$this->leads->relationship_exists('leads',array('id'=>$this->parent_id)) )
864 1
	            $this->leads->add($this->parent_id);
865
	    }
866
867 1
	    parent::afterImportSave();
868 1
	}
869
870 1
    public function getDefaultStatus()
871
    {
872 1
         $def = $this->field_defs['status'];
873 1
         if (isset($def['default'])) {
874 1
             return $def['default'];
875
         } else {
876
            $app = return_app_list_strings_language($GLOBALS['current_language']);
877
            if (isset($def['options']) && isset($app[$def['options']])) {
878
                $keys = array_keys($app[$def['options']]);
879
                return $keys[0];
880
            }
881
        }
882
        return '';
883
    }
884
885
} // end class def
886
887
// External API integration, for the dropdown list of what external API's are available
888
//TODO: do we really need focus, name and view params for this function
889 1
function getMeetingsExternalApiDropDown($focus = null, $name = null, $value = null, $view = null)
890
{
891 1
	global $dictionary, $app_list_strings;
892
893 1
	$cacheKeyName = 'meetings_type_drop_down';
894
895 1
    $apiList = sugar_cache_retrieve($cacheKeyName);
896 1
    if ($apiList === null)
897
    {
898 1
        require_once('include/externalAPI/ExternalAPIFactory.php');
899
900 1
        $apiList = ExternalAPIFactory::getModuleDropDown('Meetings');
901 1
        $apiList = array_merge(array('Sugar'=>$GLOBALS['app_list_strings']['eapm_list']['Sugar']), $apiList);
902 1
        sugar_cache_put($cacheKeyName, $apiList);
903
    }
904
905 1
	if(!empty($value) && empty($apiList[$value]))
906
	{
907
		$apiList[$value] = $value;
908
    }
909
	//bug 46294: adding list of options to dropdown list (if it is not the default list)
910 1
    if ($dictionary['Meeting']['fields']['type']['options'] != "eapm_list")
911
    {
912 1
        $apiList = array_merge(getMeetingTypeOptions($dictionary, $app_list_strings), $apiList);
913
    }
914
915 1
	return $apiList;
916
}
917
918
/**
919
 * Meeting Type Options Array for dropdown list
920
 * @param array $dictionary - getting type name
921
 * @param array $app_list_strings - getting type options
922
 * @return array Meeting Type Options Array for dropdown list
923
 */
924 1
function getMeetingTypeOptions($dictionary, $app_list_strings)
925
{
926 2
	$result = array();
927
928
    // getting name of meeting type to fill dropdown list by its values
929 2
    if (isset($dictionary['Meeting']['fields']['type']['options']))
930
	{
931
    	$typeName = $dictionary['Meeting']['fields']['type']['options'];
932
933
        if (!empty($app_list_strings[$typeName]))
934
		{
935
        	$typeList = $app_list_strings[$typeName];
936
937
            foreach ($typeList as $key => $value)
938
			{
939
				$result[$value] = $value;
940
            }
941
        }
942
    }
943
944 2
    return $result;
945
}
946