|
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-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
|
|
|
|
|
43
|
|
|
* Description: TODO: To be written. |
|
44
|
|
|
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
|
45
|
|
|
* All Rights Reserved. |
|
46
|
|
|
* Contributor(s): ______________________________________.. |
|
47
|
|
|
********************************************************************************/ |
|
48
|
|
|
|
|
49
|
|
|
class Call extends SugarBean { |
|
50
|
|
|
var $field_name_map; |
|
51
|
|
|
// Stored fields |
|
52
|
|
|
var $id; |
|
53
|
|
|
var $json_id; |
|
54
|
|
|
var $date_entered; |
|
55
|
|
|
var $date_modified; |
|
56
|
|
|
var $assigned_user_id; |
|
57
|
|
|
var $modified_user_id; |
|
58
|
|
|
var $description; |
|
59
|
|
|
var $name; |
|
60
|
|
|
var $status; |
|
61
|
|
|
var $date_start; |
|
62
|
|
|
var $time_start; |
|
63
|
|
|
var $duration_hours; |
|
64
|
|
|
var $duration_minutes; |
|
65
|
|
|
var $date_end; |
|
66
|
|
|
var $parent_type; |
|
67
|
|
|
var $parent_type_options; |
|
68
|
|
|
var $parent_id; |
|
69
|
|
|
var $contact_id; |
|
70
|
|
|
var $user_id; |
|
71
|
|
|
var $lead_id; |
|
72
|
|
|
var $direction; |
|
73
|
|
|
var $reminder_time; |
|
74
|
|
|
var $reminder_time_options; |
|
75
|
|
|
var $reminder_checked; |
|
76
|
|
|
var $email_reminder_time; |
|
77
|
|
|
var $email_reminder_checked; |
|
78
|
|
|
var $email_reminder_sent; |
|
79
|
|
|
var $required; |
|
80
|
|
|
var $accept_status; |
|
81
|
|
|
var $created_by; |
|
82
|
|
|
var $created_by_name; |
|
83
|
|
|
var $modified_by_name; |
|
84
|
|
|
var $parent_name; |
|
85
|
|
|
var $contact_name; |
|
86
|
|
|
var $contact_phone; |
|
87
|
|
|
var $contact_email; |
|
88
|
|
|
var $account_id; |
|
89
|
|
|
var $opportunity_id; |
|
90
|
|
|
var $case_id; |
|
91
|
|
|
var $assigned_user_name; |
|
92
|
|
|
var $note_id; |
|
93
|
|
|
var $outlook_id; |
|
94
|
|
|
var $update_vcal = true; |
|
95
|
|
|
var $contacts_arr; |
|
96
|
|
|
var $users_arr; |
|
97
|
|
|
var $leads_arr; |
|
98
|
|
|
var $default_call_name_values = array('Assemble catalogs', 'Make travel arrangements', 'Send a letter', 'Send contract', 'Send fax', 'Send a follow-up letter', 'Send literature', 'Send proposal', 'Send quote'); |
|
99
|
|
|
var $minutes_value_default = 15; |
|
100
|
|
|
var $minutes_values = array('0'=>'00','15'=>'15','30'=>'30','45'=>'45'); |
|
101
|
|
|
var $table_name = "calls"; |
|
102
|
|
|
var $rel_users_table = "calls_users"; |
|
103
|
|
|
var $rel_contacts_table = "calls_contacts"; |
|
104
|
|
|
var $rel_leads_table = "calls_leads"; |
|
105
|
|
|
var $module_dir = 'Calls'; |
|
106
|
|
|
var $object_name = "Call"; |
|
107
|
|
|
var $new_schema = true; |
|
108
|
|
|
var $importable = true; |
|
109
|
|
|
var $syncing = false; |
|
110
|
|
|
var $recurring_source; |
|
111
|
|
|
|
|
112
|
|
|
// This is used to retrieve related fields from form posts. |
|
113
|
|
|
var $additional_column_fields = array('assigned_user_name', 'assigned_user_id', 'contact_id', 'user_id', 'contact_name'); |
|
114
|
|
|
var $relationship_fields = array( 'account_id' => 'accounts', |
|
115
|
|
|
'opportunity_id' => 'opportunities', |
|
116
|
|
|
'contact_id' => 'contacts', |
|
117
|
|
|
'case_id' => 'cases', |
|
118
|
|
|
'user_id' => 'users', |
|
119
|
|
|
'assigned_user_id' => 'users', |
|
120
|
|
|
'note_id' => 'notes', |
|
121
|
|
|
'lead_id' => 'leads', |
|
122
|
|
|
); |
|
123
|
|
|
|
|
124
|
|
|
public function __construct() { |
|
125
|
|
|
parent::__construct(); |
|
126
|
|
|
global $app_list_strings; |
|
127
|
|
|
|
|
128
|
|
|
$this->setupCustomFields('Calls'); |
|
129
|
|
|
|
|
130
|
|
|
foreach ($this->field_defs as $field) { |
|
131
|
|
|
$this->field_name_map[$field['name']] = $field; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
if(!empty($GLOBALS['app_list_strings']['duration_intervals'])) |
|
138
|
|
|
$this->minutes_values = $GLOBALS['app_list_strings']['duration_intervals']; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @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 |
|
143
|
|
|
*/ |
|
144
|
|
|
public function Call(){ |
|
145
|
|
|
$deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code'; |
|
146
|
|
|
if(isset($GLOBALS['log'])) { |
|
147
|
|
|
$GLOBALS['log']->deprecated($deprecatedMessage); |
|
148
|
|
|
} |
|
149
|
|
|
else { |
|
150
|
|
|
trigger_error($deprecatedMessage, E_USER_DEPRECATED); |
|
151
|
|
|
} |
|
152
|
|
|
self::__construct(); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Disable edit if call is recurring and source is not Sugar. It should be edited only from Outlook. |
|
157
|
|
|
* @param $view string |
|
158
|
|
|
* @param $is_owner bool |
|
159
|
|
|
*/ |
|
160
|
|
|
function ACLAccess($view,$is_owner='not_set',$in_group='not_set'){ |
|
161
|
|
|
// don't check if call is being synced from Outlook |
|
162
|
|
|
if($this->syncing == false){ |
|
|
|
|
|
|
163
|
|
|
$view = strtolower($view); |
|
164
|
|
|
switch($view){ |
|
165
|
|
|
case 'edit': |
|
166
|
|
|
case 'save': |
|
167
|
|
|
case 'editview': |
|
168
|
|
|
case 'delete': |
|
169
|
|
|
if(!empty($this->recurring_source) && $this->recurring_source != "Sugar"){ |
|
170
|
|
|
return false; |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
return parent::ACLAccess($view,$is_owner,$in_group); |
|
175
|
|
|
} |
|
176
|
|
|
// save date_end by calculating user input |
|
177
|
|
|
// this is for calendar |
|
178
|
|
|
function save($check_notify = FALSE) { |
|
179
|
|
|
global $timedate,$current_user; |
|
180
|
|
|
|
|
181
|
|
|
if(isset($this->date_start) && isset($this->duration_hours) && isset($this->duration_minutes)) |
|
182
|
|
|
{ |
|
183
|
|
|
$td = $timedate->fromDb($this->date_start); |
|
184
|
|
|
if($td) |
|
185
|
|
|
{ |
|
186
|
|
|
$this->date_end = $td->modify("+{$this->duration_hours} hours {$this->duration_minutes} mins")->asDb(); |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
if(!empty($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == '1') { |
|
191
|
|
|
$check_notify = true; |
|
192
|
|
|
} else { |
|
193
|
|
|
$check_notify = false; |
|
194
|
|
|
} |
|
195
|
|
|
if(empty($_REQUEST['send_invites'])) { |
|
196
|
|
|
if(!empty($this->id)) { |
|
197
|
|
|
$old_record = new Call(); |
|
198
|
|
|
$old_record->retrieve($this->id); |
|
199
|
|
|
$old_assigned_user_id = $old_record->assigned_user_id; |
|
200
|
|
|
} |
|
201
|
|
|
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']) ){ |
|
202
|
|
|
$this->special_notification = true; |
|
203
|
|
|
if(!isset($GLOBALS['resavingRelatedBeans']) || $GLOBALS['resavingRelatedBeans'] == false) { |
|
204
|
|
|
$check_notify = true; |
|
205
|
|
|
} |
|
206
|
|
|
if(isset($_REQUEST['assigned_user_name'])) { |
|
207
|
|
|
$this->new_assigned_user_name = $_REQUEST['assigned_user_name']; |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
if (empty($this->status) ) { |
|
212
|
|
|
$this->status = $this->getDefaultStatus(); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
// prevent a mass mailing for recurring meetings created in Calendar module |
|
216
|
|
|
if (empty($this->id) && !empty($_REQUEST['module']) && $_REQUEST['module'] == "Calendar" && !empty($_REQUEST['repeat_type']) && !empty($this->repeat_parent_id)) { |
|
217
|
|
|
$check_notify = false; |
|
218
|
|
|
} |
|
219
|
|
|
/*nsingh 7/3/08 commenting out as bug #20814 is invalid |
|
220
|
|
|
if($current_user->getPreference('reminder_time')!= -1 && isset($_POST['reminder_checked']) && isset($_POST['reminder_time']) && $_POST['reminder_checked']==0 && $_POST['reminder_time']==-1){ |
|
221
|
|
|
$this->reminder_checked = '1'; |
|
222
|
|
|
$this->reminder_time = $current_user->getPreference('reminder_time'); |
|
223
|
|
|
}*/ |
|
224
|
|
|
|
|
225
|
|
|
$return_id = parent::save($check_notify); |
|
226
|
|
|
global $current_user; |
|
227
|
|
|
|
|
228
|
|
|
|
|
229
|
|
|
if($this->update_vcal) { |
|
230
|
|
|
vCal::cache_sugar_vcal($current_user); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
if(isset($_REQUEST['reminders_data'])) { |
|
234
|
|
|
Reminder::saveRemindersDataJson('Calls', $return_id, html_entity_decode($_REQUEST['reminders_data'])); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
return $return_id; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** Returns a list of the associated contacts |
|
241
|
|
|
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. |
|
242
|
|
|
* All Rights Reserved.. |
|
243
|
|
|
* Contributor(s): ______________________________________.. |
|
244
|
|
|
*/ |
|
245
|
|
|
function get_contacts() |
|
246
|
|
|
{ |
|
247
|
|
|
// First, get the list of IDs. |
|
248
|
|
|
$query = "SELECT contact_id as id from calls_contacts where call_id='$this->id' AND deleted=0"; |
|
249
|
|
|
|
|
250
|
|
|
return $this->build_related_list($query, new Contact()); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
|
|
254
|
|
|
function get_summary_text() |
|
255
|
|
|
{ |
|
256
|
|
|
return "$this->name"; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
function create_list_query($order_by, $where, $show_deleted=0) |
|
260
|
|
|
{ |
|
261
|
|
|
$custom_join = $this->getCustomJoin(); |
|
262
|
|
|
$query = "SELECT "; |
|
263
|
|
|
$query .= " |
|
264
|
|
|
calls.*,"; |
|
265
|
|
|
if ( preg_match("/calls_users\.user_id/",$where)) |
|
266
|
|
|
{ |
|
267
|
|
|
$query .= "calls_users.required, |
|
268
|
|
|
calls_users.accept_status,"; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
$query .= " |
|
272
|
|
|
users.user_name as assigned_user_name"; |
|
273
|
|
|
$query .= $custom_join['select']; |
|
274
|
|
|
|
|
275
|
|
|
// this line will help generate a GMT-metric to compare to a locale's timezone |
|
276
|
|
|
|
|
277
|
|
|
if ( preg_match("/contacts/",$where)){ |
|
278
|
|
|
$query .= ", contacts.first_name, contacts.last_name"; |
|
279
|
|
|
$query .= ", contacts.assigned_user_id contact_name_owner"; |
|
280
|
|
|
} |
|
281
|
|
|
$query .= " FROM calls "; |
|
282
|
|
|
|
|
283
|
|
|
if ( preg_match("/contacts/",$where)){ |
|
284
|
|
|
$query .= "LEFT JOIN calls_contacts |
|
285
|
|
|
ON calls.id=calls_contacts.call_id |
|
286
|
|
|
LEFT JOIN contacts |
|
287
|
|
|
ON calls_contacts.contact_id=contacts.id "; |
|
288
|
|
|
} |
|
289
|
|
|
if ( preg_match('/calls_users\.user_id/',$where)) |
|
290
|
|
|
{ |
|
291
|
|
|
$query .= "LEFT JOIN calls_users |
|
292
|
|
|
ON calls.id=calls_users.call_id and calls_users.deleted=0 "; |
|
293
|
|
|
} |
|
294
|
|
|
$query .= " |
|
295
|
|
|
LEFT JOIN users |
|
296
|
|
|
ON calls.assigned_user_id=users.id "; |
|
297
|
|
|
$query .= $custom_join['join']; |
|
298
|
|
|
$where_auto = '1=1'; |
|
299
|
|
|
if($show_deleted == 0){ |
|
300
|
|
|
$where_auto = " $this->table_name.deleted=0 "; |
|
301
|
|
|
}else if($show_deleted == 1){ |
|
302
|
|
|
$where_auto = " $this->table_name.deleted=1 "; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
//$where_auto .= " GROUP BY calls.id"; |
|
306
|
|
|
|
|
307
|
|
|
if($where != "") |
|
308
|
|
|
$query .= "where $where AND ".$where_auto; |
|
309
|
|
|
else |
|
310
|
|
|
$query .= "where ".$where_auto; |
|
311
|
|
|
|
|
312
|
|
|
$order_by = $this->process_order_by($order_by); |
|
313
|
|
|
if (empty($order_by)) { |
|
314
|
|
|
$order_by = 'calls.name'; |
|
315
|
|
|
} |
|
316
|
|
|
$query .= ' ORDER BY ' . $order_by; |
|
317
|
|
|
|
|
318
|
|
|
return $query; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
function create_export_query($order_by, $where, $relate_link_join='') |
|
322
|
|
|
{ |
|
323
|
|
|
$custom_join = $this->getCustomJoin(true, true, $where); |
|
324
|
|
|
$custom_join['join'] .= $relate_link_join; |
|
325
|
|
|
$contact_required = stristr($where, "contacts"); |
|
326
|
|
|
if($contact_required) |
|
327
|
|
|
{ |
|
328
|
|
|
$query = "SELECT calls.*, contacts.first_name, contacts.last_name, users.user_name as assigned_user_name "; |
|
329
|
|
|
$query .= $custom_join['select']; |
|
330
|
|
|
$query .= " FROM contacts, calls, calls_contacts "; |
|
331
|
|
|
$where_auto = "calls_contacts.contact_id = contacts.id AND calls_contacts.call_id = calls.id AND calls.deleted=0 AND contacts.deleted=0"; |
|
332
|
|
|
} |
|
333
|
|
|
else |
|
334
|
|
|
{ |
|
335
|
|
|
$query = 'SELECT calls.*, users.user_name as assigned_user_name '; |
|
336
|
|
|
$query .= $custom_join['select']; |
|
337
|
|
|
$query .= ' FROM calls '; |
|
338
|
|
|
$where_auto = "calls.deleted=0"; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
|
|
342
|
|
|
$query .= " LEFT JOIN users ON calls.assigned_user_id=users.id "; |
|
343
|
|
|
|
|
344
|
|
|
$query .= $custom_join['join']; |
|
345
|
|
|
|
|
346
|
|
|
if($where != "") |
|
347
|
|
|
$query .= "where $where AND ".$where_auto; |
|
348
|
|
|
else |
|
349
|
|
|
$query .= "where ".$where_auto; |
|
350
|
|
|
|
|
351
|
|
|
$order_by = $this->process_order_by($order_by); |
|
352
|
|
|
if (empty($order_by)) { |
|
353
|
|
|
$order_by = 'calls.name'; |
|
354
|
|
|
} |
|
355
|
|
|
$query .= ' ORDER BY ' . $order_by; |
|
356
|
|
|
|
|
357
|
|
|
return $query; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
|
|
361
|
|
|
|
|
362
|
|
|
|
|
363
|
|
|
|
|
364
|
|
|
function fill_in_additional_detail_fields() |
|
365
|
|
|
{ |
|
366
|
|
|
global $locale; |
|
367
|
|
|
parent::fill_in_additional_detail_fields(); |
|
368
|
|
|
if (!empty($this->contact_id)) { |
|
369
|
|
|
$query = "SELECT first_name, last_name FROM contacts "; |
|
370
|
|
|
$query .= "WHERE id='$this->contact_id' AND deleted=0"; |
|
371
|
|
|
$result = $this->db->limitQuery($query,0,1,true," Error filling in additional detail fields: "); |
|
372
|
|
|
|
|
373
|
|
|
// Get the contact name. |
|
374
|
|
|
$row = $this->db->fetchByAssoc($result); |
|
375
|
|
|
$GLOBALS['log']->info("additional call fields $query"); |
|
376
|
|
|
if($row != null) |
|
377
|
|
|
{ |
|
378
|
|
|
$this->contact_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name'], '', ''); |
|
379
|
|
|
$GLOBALS['log']->debug("Call($this->id): contact_name = $this->contact_name"); |
|
380
|
|
|
$GLOBALS['log']->debug("Call($this->id): contact_id = $this->contact_id"); |
|
381
|
|
|
} |
|
382
|
|
|
} |
|
383
|
|
|
if (!isset($this->duration_minutes)) { |
|
384
|
|
|
$this->duration_minutes = $this->minutes_value_default; |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
global $timedate; |
|
388
|
|
|
//setting default date and time |
|
389
|
|
|
if (is_null($this->date_start)) { |
|
390
|
|
|
$this->date_start = $timedate->now(); |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
if (is_null($this->duration_hours)) |
|
394
|
|
|
$this->duration_hours = "0"; |
|
395
|
|
|
if (is_null($this->duration_minutes)) |
|
396
|
|
|
$this->duration_minutes = "1"; |
|
397
|
|
|
|
|
398
|
|
|
$this->fill_in_additional_parent_fields(); |
|
399
|
|
|
|
|
400
|
|
|
global $app_list_strings; |
|
401
|
|
|
$parent_types = $app_list_strings['record_type_display']; |
|
402
|
|
|
$disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list'); |
|
403
|
|
|
foreach($disabled_parent_types as $disabled_parent_type){ |
|
404
|
|
|
if($disabled_parent_type != $this->parent_type){ |
|
405
|
|
|
unset($parent_types[$disabled_parent_type]); |
|
406
|
|
|
} |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
$this->parent_type_options = get_select_options_with_id($parent_types, $this->parent_type); |
|
410
|
|
|
|
|
411
|
|
|
if (empty($this->reminder_time)) { |
|
412
|
|
|
$this->reminder_time = -1; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
if ( empty($this->id) ) { |
|
416
|
|
|
$reminder_t = $GLOBALS['current_user']->getPreference('reminder_time'); |
|
417
|
|
|
if ( isset($reminder_t) ) |
|
418
|
|
|
$this->reminder_time = $reminder_t; |
|
419
|
|
|
} |
|
420
|
|
|
$this->reminder_checked = $this->reminder_time == -1 ? false : true; |
|
421
|
|
|
|
|
422
|
|
|
if (empty($this->email_reminder_time)) { |
|
423
|
|
|
$this->email_reminder_time = -1; |
|
424
|
|
|
} |
|
425
|
|
|
if(empty($this->id)){ |
|
426
|
|
|
$reminder_t = $GLOBALS['current_user']->getPreference('email_reminder_time'); |
|
427
|
|
|
if(isset($reminder_t)) |
|
428
|
|
|
$this->email_reminder_time = $reminder_t; |
|
429
|
|
|
} |
|
430
|
|
|
$this->email_reminder_checked = $this->email_reminder_time == -1 ? false : true; |
|
431
|
|
|
|
|
432
|
|
|
if (isset ($_REQUEST['parent_type']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'SubpanelEdits')) { |
|
433
|
|
|
$this->parent_type = $_REQUEST['parent_type']; |
|
434
|
|
|
} elseif (is_null($this->parent_type)) { |
|
435
|
|
|
$this->parent_type = $app_list_strings['record_type_default_key']; |
|
436
|
|
|
} |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
|
|
440
|
|
|
function get_list_view_data(){ |
|
441
|
|
|
$call_fields = $this->get_list_view_array(); |
|
442
|
|
|
global $app_list_strings, $focus, $action, $currentModule; |
|
443
|
|
|
if (isset($focus->id)) $id = $focus->id; |
|
444
|
|
|
else $id = ''; |
|
445
|
|
|
if (isset($this->parent_type) && $this->parent_type != null) |
|
446
|
|
|
{ |
|
447
|
|
|
$call_fields['PARENT_MODULE'] = $this->parent_type; |
|
448
|
|
|
} |
|
449
|
|
|
if ($this->status == "Planned") { |
|
450
|
|
|
//cn: added this if() to deal with sequential Closes in Meetings. this is a hack to a hack (formbase.php->handleRedirect) |
|
451
|
|
|
if(empty($action)) |
|
452
|
|
|
$action = "index"; |
|
453
|
|
|
|
|
454
|
|
|
$setCompleteUrl = "<a id='{$this->id}' onclick='SUGAR.util.closeActivityPanel.show(\"{$this->module_dir}\",\"{$this->id}\",\"Held\",\"listview\",\"1\");'>"; |
|
455
|
|
|
if ($this->ACLAccess('edit')) { |
|
456
|
|
|
$call_fields['SET_COMPLETE'] = $setCompleteUrl . SugarThemeRegistry::current()->getImage("close_inline"," border='0'",null,null,'.gif',translate('LBL_CLOSEINLINE'))."</a>"; |
|
457
|
|
|
} else { |
|
458
|
|
|
$call_fields['SET_COMPLETE'] = ''; |
|
459
|
|
|
} |
|
460
|
|
|
} |
|
461
|
|
|
global $timedate; |
|
462
|
|
|
$today = $timedate->nowDb(); |
|
463
|
|
|
$nextday = $timedate->asDbDate($timedate->getNow()->modify("+1 day")); |
|
464
|
|
|
$mergeTime = $call_fields['DATE_START']; //$timedate->merge_date_time($call_fields['DATE_START'], $call_fields['TIME_START']); |
|
465
|
|
|
$date_db = $timedate->to_db($mergeTime); |
|
466
|
|
|
if( $date_db < $today){ |
|
467
|
|
|
$call_fields['DATE_START']= "<font class='overdueTask'>".$call_fields['DATE_START']."</font>"; |
|
468
|
|
|
}else if($date_db < $nextday){ |
|
469
|
|
|
$call_fields['DATE_START'] = "<font class='todaysTask'>".$call_fields['DATE_START']."</font>"; |
|
470
|
|
|
}else{ |
|
471
|
|
|
$call_fields['DATE_START'] = "<font class='futureTask'>".$call_fields['DATE_START']."</font>"; |
|
472
|
|
|
} |
|
473
|
|
|
$this->fill_in_additional_detail_fields(); |
|
474
|
|
|
|
|
475
|
|
|
//make sure we grab the localized version of the contact name, if a contact is provided |
|
476
|
|
|
if (!empty($this->contact_id)) { |
|
477
|
|
|
// Bug# 46125 - make first name, last name, salutation and title of Contacts respect field level ACLs |
|
478
|
|
|
$contact_temp = BeanFactory::getBean("Contacts", $this->contact_id); |
|
479
|
|
|
if(!empty($contact_temp)) { |
|
480
|
|
|
$contact_temp->_create_proper_name_field(); |
|
481
|
|
|
$this->contact_name = $contact_temp->full_name; |
|
482
|
|
|
} |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
$call_fields['CONTACT_ID'] = $this->contact_id; |
|
486
|
|
|
$call_fields['CONTACT_NAME'] = $this->contact_name; |
|
487
|
|
|
$call_fields['PARENT_NAME'] = $this->parent_name; |
|
488
|
|
|
$call_fields['REMINDER_CHECKED'] = $this->reminder_time==-1 ? false : true; |
|
489
|
|
|
$call_fields['EMAIL_REMINDER_CHECKED'] = $this->email_reminder_time==-1 ? false : true; |
|
490
|
|
|
|
|
491
|
|
|
return $call_fields; |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
function set_notification_body($xtpl, $call) { |
|
495
|
|
|
global $sugar_config; |
|
496
|
|
|
global $app_list_strings; |
|
497
|
|
|
global $current_user; |
|
498
|
|
|
global $app_list_strings; |
|
499
|
|
|
global $timedate; |
|
500
|
|
|
|
|
501
|
|
|
// rrs: bug 42684 - passing a contact breaks this call |
|
502
|
|
|
$notifyUser =($call->current_notify_user->object_name == 'User') ? $call->current_notify_user : $current_user; |
|
503
|
|
|
|
|
504
|
|
|
|
|
505
|
|
|
// Assumes $call dates are in user format |
|
506
|
|
|
$calldate = $timedate->fromDb($call->date_start); |
|
507
|
|
|
$xOffset = $timedate->asUser($calldate, $notifyUser).' '.$timedate->userTimezoneSuffix($calldate, $notifyUser); |
|
508
|
|
|
|
|
509
|
|
|
if ( strtolower(get_class($call->current_notify_user)) == 'contact' ) { |
|
510
|
|
|
$xtpl->assign("ACCEPT_URL", $sugar_config['site_url']. |
|
511
|
|
|
'/index.php?entryPoint=acceptDecline&module=Calls&contact_id='.$call->current_notify_user->id.'&record='.$call->id); |
|
512
|
|
|
} elseif ( strtolower(get_class($call->current_notify_user)) == 'lead' ) { |
|
513
|
|
|
$xtpl->assign("ACCEPT_URL", $sugar_config['site_url']. |
|
514
|
|
|
'/index.php?entryPoint=acceptDecline&module=Calls&lead_id='.$call->current_notify_user->id.'&record='.$call->id); |
|
515
|
|
|
} else { |
|
516
|
|
|
$xtpl->assign("ACCEPT_URL", $sugar_config['site_url']. |
|
517
|
|
|
'/index.php?entryPoint=acceptDecline&module=Calls&user_id='.$call->current_notify_user->id.'&record='.$call->id); |
|
518
|
|
|
} |
|
519
|
|
|
|
|
520
|
|
|
$xtpl->assign("CALL_TO", $call->current_notify_user->new_assigned_user_name); |
|
521
|
|
|
$xtpl->assign("CALL_SUBJECT", $call->name); |
|
522
|
|
|
$xtpl->assign("CALL_STARTDATE", $xOffset); |
|
523
|
|
|
$xtpl->assign("CALL_HOURS", $call->duration_hours); |
|
524
|
|
|
$xtpl->assign("CALL_MINUTES", $call->duration_minutes); |
|
525
|
|
|
$xtpl->assign("CALL_STATUS", ((isset($call->status))?$app_list_strings['call_status_dom'][$call->status] : "")); |
|
526
|
|
|
$xtpl->assign("CALL_DESCRIPTION", $call->description); |
|
527
|
|
|
|
|
528
|
|
|
return $xtpl; |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
|
|
532
|
|
|
function get_call_users() { |
|
533
|
|
|
$template = new User(); |
|
534
|
|
|
// First, get the list of IDs. |
|
535
|
|
|
$query = "SELECT calls_users.required, calls_users.accept_status, calls_users.user_id from calls_users where calls_users.call_id='$this->id' AND calls_users.deleted=0"; |
|
536
|
|
|
$GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query); |
|
537
|
|
|
$result = $this->db->query($query, true); |
|
538
|
|
|
$list = Array(); |
|
539
|
|
|
|
|
540
|
|
|
while($row = $this->db->fetchByAssoc($result)) { |
|
541
|
|
|
$template = new User(); // PHP 5 will retrieve by reference, always over-writing the "old" one |
|
542
|
|
|
$record = $template->retrieve($row['user_id']); |
|
543
|
|
|
$template->required = $row['required']; |
|
544
|
|
|
$template->accept_status = $row['accept_status']; |
|
545
|
|
|
|
|
546
|
|
|
if($record != null) { |
|
547
|
|
|
// this copies the object into the array |
|
548
|
|
|
$list[] = $template; |
|
549
|
|
|
} |
|
550
|
|
|
} |
|
551
|
|
|
return $list; |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
|
|
555
|
|
|
function get_invite_calls(&$user) |
|
556
|
|
|
{ |
|
557
|
|
|
$template = $this; |
|
558
|
|
|
// First, get the list of IDs. |
|
559
|
|
|
$query = "SELECT calls_users.required, calls_users.accept_status, calls_users.call_id from calls_users where calls_users.user_id='$user->id' AND ( calls_users.accept_status IS NULL OR calls_users.accept_status='none') AND calls_users.deleted=0"; |
|
560
|
|
|
$GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query); |
|
561
|
|
|
|
|
562
|
|
|
|
|
563
|
|
|
$result = $this->db->query($query, true); |
|
564
|
|
|
|
|
565
|
|
|
|
|
566
|
|
|
$list = Array(); |
|
567
|
|
|
|
|
568
|
|
|
|
|
569
|
|
|
while($row = $this->db->fetchByAssoc($result)) |
|
570
|
|
|
{ |
|
571
|
|
|
$record = $template->retrieve($row['call_id']); |
|
572
|
|
|
$template->required = $row['required']; |
|
573
|
|
|
$template->accept_status = $row['accept_status']; |
|
574
|
|
|
|
|
575
|
|
|
|
|
576
|
|
|
if($record != null) |
|
577
|
|
|
{ |
|
578
|
|
|
// this copies the object into the array |
|
579
|
|
|
$list[] = $template; |
|
580
|
|
|
} |
|
581
|
|
|
} |
|
582
|
|
|
return $list; |
|
583
|
|
|
|
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
|
|
|
|
587
|
|
|
function set_accept_status(&$user,$status) |
|
588
|
|
|
{ |
|
589
|
|
|
if ( $user->object_name == 'User') |
|
590
|
|
|
{ |
|
591
|
|
|
$relate_values = array('user_id'=>$user->id,'call_id'=>$this->id); |
|
592
|
|
|
$data_values = array('accept_status'=>$status); |
|
593
|
|
|
$this->set_relationship($this->rel_users_table, $relate_values, true, true,$data_values); |
|
594
|
|
|
global $current_user; |
|
595
|
|
|
|
|
596
|
|
|
if ( $this->update_vcal ) |
|
597
|
|
|
{ |
|
598
|
|
|
vCal::cache_sugar_vcal($user); |
|
599
|
|
|
} |
|
600
|
|
|
} |
|
601
|
|
|
else if ( $user->object_name == 'Contact') |
|
602
|
|
|
{ |
|
603
|
|
|
$relate_values = array('contact_id'=>$user->id,'call_id'=>$this->id); |
|
604
|
|
|
$data_values = array('accept_status'=>$status); |
|
605
|
|
|
$this->set_relationship($this->rel_contacts_table, $relate_values, true, true,$data_values); |
|
606
|
|
|
} |
|
607
|
|
|
else if ( $user->object_name == 'Lead') |
|
608
|
|
|
{ |
|
609
|
|
|
$relate_values = array('lead_id'=>$user->id,'call_id'=>$this->id); |
|
610
|
|
|
$data_values = array('accept_status'=>$status); |
|
611
|
|
|
$this->set_relationship($this->rel_leads_table, $relate_values, true, true,$data_values); |
|
612
|
|
|
} |
|
613
|
|
|
} |
|
614
|
|
|
|
|
615
|
|
|
|
|
616
|
|
|
|
|
617
|
|
|
function get_notification_recipients() { |
|
618
|
|
|
if($this->special_notification) { |
|
619
|
|
|
return parent::get_notification_recipients(); |
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
// $GLOBALS['log']->debug('Call.php->get_notification_recipients():'.print_r($this,true)); |
|
623
|
|
|
$list = array(); |
|
624
|
|
|
if(!is_array($this->contacts_arr)) { |
|
625
|
|
|
$this->contacts_arr = array(); |
|
626
|
|
|
} |
|
627
|
|
|
|
|
628
|
|
|
if(!is_array($this->users_arr)) { |
|
629
|
|
|
$this->users_arr = array(); |
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
if(!is_array($this->leads_arr)) { |
|
633
|
|
|
$this->leads_arr = array(); |
|
634
|
|
|
} |
|
635
|
|
|
|
|
636
|
|
|
foreach($this->users_arr as $user_id) { |
|
637
|
|
|
$notify_user = new User(); |
|
638
|
|
|
$notify_user->retrieve($user_id); |
|
639
|
|
|
$notify_user->new_assigned_user_name = $notify_user->full_name; |
|
640
|
|
|
$GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name"); |
|
641
|
|
|
$list[$notify_user->id] = $notify_user; |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
foreach($this->contacts_arr as $contact_id) { |
|
645
|
|
|
$notify_user = new Contact(); |
|
646
|
|
|
$notify_user->retrieve($contact_id); |
|
647
|
|
|
$notify_user->new_assigned_user_name = $notify_user->full_name; |
|
648
|
|
|
$GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name"); |
|
649
|
|
|
$list[$notify_user->id] = $notify_user; |
|
650
|
|
|
} |
|
651
|
|
|
|
|
652
|
|
|
foreach($this->leads_arr as $lead_id) { |
|
653
|
|
|
$notify_user = new Lead(); |
|
654
|
|
|
$notify_user->retrieve($lead_id); |
|
655
|
|
|
$notify_user->new_assigned_user_name = $notify_user->full_name; |
|
656
|
|
|
$GLOBALS['log']->info("Notifications: recipient is $notify_user->new_assigned_user_name"); |
|
657
|
|
|
$list[$notify_user->id] = $notify_user; |
|
658
|
|
|
} |
|
659
|
|
|
global $sugar_config; |
|
660
|
|
|
if(isset($sugar_config['disable_notify_current_user']) && $sugar_config['disable_notify_current_user']) { |
|
661
|
|
|
global $current_user; |
|
662
|
|
|
if(isset($list[$current_user->id])) |
|
663
|
|
|
unset($list[$current_user->id]); |
|
664
|
|
|
} |
|
665
|
|
|
// $GLOBALS['log']->debug('Call.php->get_notification_recipients():'.print_r($list,true)); |
|
666
|
|
|
return $list; |
|
667
|
|
|
} |
|
668
|
|
|
|
|
669
|
|
|
function bean_implements($interface){ |
|
670
|
|
|
switch($interface){ |
|
671
|
|
|
case 'ACL':return true; |
|
|
|
|
|
|
672
|
|
|
} |
|
673
|
|
|
return false; |
|
674
|
|
|
} |
|
675
|
|
|
|
|
676
|
|
|
function listviewACLHelper(){ |
|
677
|
|
|
$array_assign = parent::listviewACLHelper(); |
|
678
|
|
|
$is_owner = false; |
|
679
|
|
|
$in_group = false; //SECURITY GROUPS |
|
680
|
|
|
if(!empty($this->parent_name)){ |
|
681
|
|
|
|
|
682
|
|
|
if(!empty($this->parent_name_owner)){ |
|
683
|
|
|
global $current_user; |
|
684
|
|
|
$is_owner = $current_user->id == $this->parent_name_owner; |
|
685
|
|
|
} |
|
686
|
|
|
/* BEGIN - SECURITY GROUPS */ |
|
687
|
|
|
//parent_name_owner not being set for whatever reason so we need to figure this out |
|
688
|
|
|
else if(!empty($this->parent_type) && !empty($this->parent_id)) { |
|
689
|
|
|
global $current_user; |
|
690
|
|
|
$parent_bean = BeanFactory::getBean($this->parent_type,$this->parent_id); |
|
691
|
|
|
if($parent_bean !== false) { |
|
692
|
|
|
$is_owner = $current_user->id == $parent_bean->assigned_user_id; |
|
693
|
|
|
} |
|
694
|
|
|
} |
|
695
|
|
|
require_once("modules/SecurityGroups/SecurityGroup.php"); |
|
696
|
|
|
$in_group = SecurityGroup::groupHasAccess($this->parent_type, $this->parent_id, 'view'); |
|
697
|
|
|
/* END - SECURITY GROUPS */ |
|
698
|
|
|
} |
|
699
|
|
|
|
|
700
|
|
|
/* BEGIN - SECURITY GROUPS */ |
|
701
|
|
|
/** |
|
702
|
|
|
if(!ACLController::moduleSupportsACL($this->parent_type) || ACLController::checkAccess($this->parent_type, 'view', $is_owner)){ |
|
703
|
|
|
*/ |
|
704
|
|
|
if(!ACLController::moduleSupportsACL($this->parent_type) || ACLController::checkAccess($this->parent_type, 'view', $is_owner, 'module', $in_group)){ |
|
705
|
|
|
/* END - SECURITY GROUPS */ |
|
706
|
|
|
$array_assign['PARENT'] = 'a'; |
|
707
|
|
|
}else{ |
|
708
|
|
|
$array_assign['PARENT'] = 'span'; |
|
709
|
|
|
} |
|
710
|
|
|
$is_owner = false; |
|
711
|
|
|
$in_group = false; //SECURITY GROUPS |
|
712
|
|
|
if(!empty($this->contact_name)){ |
|
713
|
|
|
|
|
714
|
|
|
if(!empty($this->contact_name_owner)){ |
|
715
|
|
|
global $current_user; |
|
716
|
|
|
$is_owner = $current_user->id == $this->contact_name_owner; |
|
717
|
|
|
} |
|
718
|
|
|
/* BEGIN - SECURITY GROUPS */ |
|
719
|
|
|
//contact_name_owner not being set for whatever reason so we need to figure this out |
|
720
|
|
|
else { |
|
721
|
|
|
global $current_user; |
|
722
|
|
|
$parent_bean = BeanFactory::getBean('Contacts',$this->contact_id); |
|
723
|
|
|
if($parent_bean !== false) { |
|
724
|
|
|
$is_owner = $current_user->id == $parent_bean->assigned_user_id; |
|
725
|
|
|
} |
|
726
|
|
|
} |
|
727
|
|
|
require_once("modules/SecurityGroups/SecurityGroup.php"); |
|
728
|
|
|
$in_group = SecurityGroup::groupHasAccess('Contacts', $this->contact_id, 'view'); |
|
729
|
|
|
/* END - SECURITY GROUPS */ |
|
730
|
|
|
} |
|
731
|
|
|
/* BEGIN - SECURITY GROUPS */ |
|
732
|
|
|
/** |
|
733
|
|
|
if( ACLController::checkAccess('Contacts', 'view', $is_owner)){ |
|
734
|
|
|
*/ |
|
735
|
|
|
if( ACLController::checkAccess('Contacts', 'view', $is_owner, 'module', $in_group)){ |
|
736
|
|
|
/* END - SECURITY GROUPS */ |
|
737
|
|
|
$array_assign['CONTACT'] = 'a'; |
|
738
|
|
|
}else{ |
|
739
|
|
|
$array_assign['CONTACT'] = 'span'; |
|
740
|
|
|
} |
|
741
|
|
|
|
|
742
|
|
|
return $array_assign; |
|
743
|
|
|
} |
|
744
|
|
|
|
|
745
|
|
|
function save_relationship_changes($is_update, $exclude = array()) { |
|
746
|
|
|
if(empty($this->in_workflow)) |
|
747
|
|
|
{ |
|
748
|
|
|
if(empty($this->in_import)) |
|
749
|
|
|
{ |
|
750
|
|
|
//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 |
|
751
|
|
|
//add assigned_user_id to exclude list and let the logic from MeetingFormBase determine whether assigned user id gets added to the relationship |
|
752
|
|
|
if(!empty($GLOBALS['soap_server_object'])) |
|
753
|
|
|
{ |
|
754
|
|
|
$exclude = array('lead_id', 'contact_id', 'user_id'); |
|
755
|
|
|
} |
|
756
|
|
|
else |
|
757
|
|
|
{ |
|
758
|
|
|
$exclude = array('lead_id', 'contact_id', 'user_id', 'assigned_user_id'); |
|
759
|
|
|
} |
|
760
|
|
|
} |
|
761
|
|
|
else |
|
762
|
|
|
{ |
|
763
|
|
|
$exclude = array('user_id'); |
|
764
|
|
|
} |
|
765
|
|
|
|
|
766
|
|
|
|
|
767
|
|
|
} |
|
768
|
|
|
parent::save_relationship_changes($is_update, $exclude); |
|
769
|
|
|
} |
|
770
|
|
|
|
|
771
|
|
|
public function getDefaultStatus() |
|
772
|
|
|
{ |
|
773
|
|
|
$def = $this->field_defs['status']; |
|
774
|
|
|
if (isset($def['default'])) { |
|
775
|
|
|
return $def['default']; |
|
776
|
|
|
} else { |
|
777
|
|
|
$app = return_app_list_strings_language($GLOBALS['current_language']); |
|
778
|
|
|
if (isset($def['options']) && isset($app[$def['options']])) { |
|
779
|
|
|
$keys = array_keys($app[$def['options']]); |
|
780
|
|
|
return $keys[0]; |
|
781
|
|
|
} |
|
782
|
|
|
} |
|
783
|
|
|
return ''; |
|
784
|
|
|
} |
|
785
|
|
|
|
|
786
|
|
|
public function mark_deleted($id) |
|
787
|
|
|
{ |
|
788
|
|
|
require_once("modules/Calendar/CalendarUtils.php"); |
|
789
|
|
|
CalendarUtils::correctRecurrences($this, $id); |
|
790
|
|
|
|
|
791
|
|
|
parent::mark_deleted($id); |
|
792
|
|
|
} |
|
793
|
|
|
} |
|
794
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.