|
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
|
|
|
require_once('soap/SoapRelationshipHelper.php'); |
|
42
|
|
|
set_time_limit(360); |
|
43
|
|
|
|
|
44
|
|
|
$server->register( |
|
45
|
|
|
'sync_get_modified_relationships', |
|
46
|
|
|
array('session'=>'xsd:string', 'module_name'=>'xsd:string','related_module'=>'xsd:string', 'from_date'=>'xsd:string', 'to_date'=>'xsd:string','offset'=>'xsd:int', 'max_results'=>'xsd:int','deleted'=>'xsd:int', 'module_id'=>'xsd:string', 'select_fields'=>'tns:select_fields', 'ids'=>'tns:select_fields', 'relationship_name'=>'xsd:string', 'deletion_date'=>'xsd:string', 'php_serialize'=>'xsd:int'), |
|
47
|
|
|
array('return'=>'tns:get_entry_list_result_encoded'), |
|
48
|
|
|
$NAMESPACE); |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get a list of the relationship records that have been modified within a |
|
54
|
|
|
* specified date range. This is used to perform a sync with a mobile client. |
|
55
|
|
|
* The results are paged. |
|
56
|
|
|
* |
|
57
|
|
|
* @param xsd:string $session |
|
|
|
|
|
|
58
|
|
|
* @param xsd:string $module_name |
|
|
|
|
|
|
59
|
|
|
* @param xsd:string $related_module |
|
|
|
|
|
|
60
|
|
|
* @param xsd:string $from_date |
|
|
|
|
|
|
61
|
|
|
* @param xsd:string $to_date |
|
|
|
|
|
|
62
|
|
|
* @param xsd:int $offset |
|
|
|
|
|
|
63
|
|
|
* @param xsd:int $max_results |
|
|
|
|
|
|
64
|
|
|
* @param xsd:int $deleted |
|
|
|
|
|
|
65
|
|
|
* @param xsd:int $module_id |
|
|
|
|
|
|
66
|
|
|
* @param tns:select_fields $select_fields |
|
|
|
|
|
|
67
|
|
|
* @param tns:select_fields $ids |
|
|
|
|
|
|
68
|
|
|
* @param xsd:string $relationship_name |
|
|
|
|
|
|
69
|
|
|
* @param xsd:string $deletion_date |
|
|
|
|
|
|
70
|
|
|
* @param xsd:int $php_serialize |
|
|
|
|
|
|
71
|
|
|
* @return |
|
72
|
|
|
*/ |
|
73
|
|
|
function sync_get_modified_relationships($session, $module_name, $related_module,$from_date,$to_date,$offset, $max_results, $deleted, $module_id = '', $select_fields = array(), $ids = array(), $relationship_name = '', $deletion_date = '', $php_serialize = 1){ |
|
74
|
|
|
global $beanList, $beanFiles; |
|
75
|
|
|
$error = new SoapError(); |
|
76
|
|
|
$output_list = array(); |
|
77
|
|
|
if(!validate_authenticated($session)){ |
|
78
|
|
|
$error->set_error('invalid_login'); |
|
79
|
|
|
return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array()); |
|
80
|
|
|
} |
|
81
|
|
|
if(empty($beanList[$module_name]) || empty($beanList[$related_module])){ |
|
82
|
|
|
$error->set_error('no_module'); |
|
83
|
|
|
return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array()); |
|
84
|
|
|
} |
|
85
|
|
|
global $current_user; |
|
86
|
|
|
if(!check_modules_access($current_user, $module_name, 'read') || !check_modules_access($current_user, $related_module, 'read')){ |
|
87
|
|
|
$error->set_error('no_access'); |
|
88
|
|
|
return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array()); |
|
89
|
|
|
} |
|
90
|
|
|
// Cast to integer |
|
91
|
|
|
$deleted = (int)$deleted; |
|
92
|
|
|
if($max_results > 0 || $max_results == '-99'){ |
|
93
|
|
|
global $sugar_config; |
|
94
|
|
|
$sugar_config['list_max_entries_per_page'] = $max_results; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$date_query = "(m1.date_modified > " . db_convert("'".$GLOBALS['db']->quote($from_date)."'", 'datetime'). " AND m1.date_modified <= ". db_convert("'".$GLOBALS['db']->quote($to_date)."'", 'datetime')." AND {0}.deleted = $deleted)"; |
|
|
|
|
|
|
98
|
|
|
if(isset($deletion_date) && !empty($deletion_date)){ |
|
99
|
|
|
$date_query .= " OR ({0}.date_modified > " . db_convert("'".$GLOBALS['db']->quote($deletion_date)."'", 'datetime'). " AND {0}.date_modified <= ". db_convert("'".$GLOBALS['db']->quote($to_date)."'", 'datetime')." AND {0}.deleted = 1)"; |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$in = ''; |
|
103
|
|
|
if(isset($ids) && !empty($ids)){ |
|
104
|
|
|
foreach($ids as $value){ |
|
105
|
|
|
if(empty($in)) |
|
106
|
|
|
{ |
|
107
|
|
|
$in .= "('" . $GLOBALS['db']->quote($value) . "'"; |
|
108
|
|
|
} |
|
109
|
|
|
else |
|
110
|
|
|
{ |
|
111
|
|
|
$in .= ",'" . $GLOBALS['db']->quote($value) . "'"; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
$in .=')'; |
|
115
|
|
|
} |
|
116
|
|
|
$query = ''; |
|
117
|
|
|
if(isset($in) && !empty($in)){ |
|
118
|
|
|
$query .= "( $date_query AND m1.id IN $in) OR (m1.id NOT IN $in AND {0}.deleted = 0)"; |
|
119
|
|
|
} |
|
120
|
|
|
else{ |
|
121
|
|
|
$query .= "( {0}.deleted = 0)"; |
|
122
|
|
|
} |
|
123
|
|
|
if(isset($module_id) && !empty($module_id)){ |
|
124
|
|
|
//if(isset($in) && !empty($in)){ |
|
125
|
|
|
$query .= " AND"; |
|
126
|
|
|
//} |
|
127
|
|
|
$query .= " m2.id = '".$GLOBALS['db']->quote($module_id)."'"; |
|
128
|
|
|
} |
|
129
|
|
|
if($related_module == 'Meetings' || $related_module == 'Calls'){ |
|
130
|
|
|
$query = string_format($query, array('m1')); |
|
131
|
|
|
} |
|
132
|
|
|
$results = retrieve_modified_relationships($module_name, $related_module, $query, $deleted, $offset, $max_results, $select_fields, $relationship_name); |
|
133
|
|
|
|
|
134
|
|
|
$list = $results['result']; |
|
135
|
|
|
|
|
136
|
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?><items>'; |
|
137
|
|
|
foreach($list as $value) |
|
138
|
|
|
{ |
|
139
|
|
|
$val = array_get_return_value($value, $results['table_name']); |
|
140
|
|
|
if($php_serialize == 0){ |
|
141
|
|
|
$xml .= get_name_value_xml($val, $module_name); |
|
142
|
|
|
} |
|
143
|
|
|
$output_list[] = $val; |
|
144
|
|
|
} |
|
145
|
|
|
$xml .= '</items>'; |
|
146
|
|
|
$next_offset = $offset + sizeof($output_list); |
|
147
|
|
|
|
|
148
|
|
|
if($php_serialize == 0){ |
|
149
|
|
|
$myoutput = base64_encode($xml); |
|
150
|
|
|
} |
|
151
|
|
|
else{ |
|
152
|
|
|
$myoutput = get_encoded($output_list); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
return array('result_count'=>sizeof($output_list),'next_offset'=>0, 'total_count'=>sizeof($output_list), 'field_list'=>array(), 'entry_list'=>$myoutput , 'error'=>$error->get_soap_array()); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
$server->register( |
|
160
|
|
|
'get_modified_entries', |
|
161
|
|
|
array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'ids'=>'tns:select_fields', 'select_fields'=>'tns:select_fields'), |
|
162
|
|
|
array('return'=>'tns:get_sync_result_encoded'), |
|
163
|
|
|
$NAMESPACE); |
|
164
|
|
|
|
|
165
|
|
|
function get_modified_entries($session, $module_name, $ids, $select_fields ){ |
|
166
|
|
|
global $beanList, $beanFiles; |
|
167
|
|
|
$error = new SoapError(); |
|
168
|
|
|
$field_list = array(); |
|
169
|
|
|
$output_list = array(); |
|
170
|
|
|
if(!validate_authenticated($session)){ |
|
171
|
|
|
$error->set_error('invalid_login'); |
|
172
|
|
|
return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array()); |
|
173
|
|
|
} |
|
174
|
|
|
if(empty($beanList[$module_name])){ |
|
175
|
|
|
$error->set_error('no_module'); |
|
176
|
|
|
return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array()); |
|
177
|
|
|
} |
|
178
|
|
|
global $current_user; |
|
179
|
|
|
if(!check_modules_access($current_user, $module_name, 'read')){ |
|
180
|
|
|
$error->set_error('no_access'); |
|
181
|
|
|
return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array()); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
$class_name = $beanList[$module_name]; |
|
185
|
|
|
require_once($beanFiles[$class_name]); |
|
186
|
|
|
$seed = new $class_name(); |
|
187
|
|
|
//rsmith |
|
188
|
|
|
$in = ''; |
|
189
|
|
|
$field_select =''; |
|
190
|
|
|
|
|
191
|
|
|
$table_name = $seed->table_name; |
|
192
|
|
|
if(isset($ids)){ |
|
193
|
|
|
foreach($ids as $value){ |
|
194
|
|
|
if(empty($in)) |
|
195
|
|
|
{ |
|
196
|
|
|
$in .= "('" . $GLOBALS['db']->quote($value) . "'"; |
|
197
|
|
|
} |
|
198
|
|
|
else |
|
199
|
|
|
{ |
|
200
|
|
|
$in .= ",'" . $GLOBALS['db']->quote($value) . "'"; |
|
201
|
|
|
} |
|
202
|
|
|
}//end foreach |
|
203
|
|
|
} |
|
204
|
|
|
$index = 0; |
|
205
|
|
|
foreach($select_fields as $field){ |
|
206
|
|
|
if ( !isset($seed->field_defs[$field]) ) { |
|
207
|
|
|
continue; |
|
208
|
|
|
} |
|
209
|
|
|
$field_select .= $table_name.".".$field; |
|
210
|
|
|
|
|
211
|
|
|
if($index < (count($select_fields) - 1)) |
|
212
|
|
|
{ |
|
213
|
|
|
$field_select .= ","; |
|
214
|
|
|
$index++; |
|
215
|
|
|
} |
|
216
|
|
|
}//end foreach |
|
217
|
|
|
|
|
218
|
|
|
$ids = array(); |
|
219
|
|
|
|
|
220
|
|
|
//end rsmith |
|
221
|
|
|
if(!empty($in)){ |
|
222
|
|
|
$in .=')'; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
$ret_array = $seed->create_new_list_query('', "$table_name.id IN $in", $select_fields, array(), -2, '', true, $seed, true); |
|
226
|
|
|
if(!is_array($params)) $params = array(); |
|
|
|
|
|
|
227
|
|
|
if(!isset($params['custom_select'])) $params['custom_select'] = ''; |
|
228
|
|
|
if(!isset($params['custom_from'])) $params['custom_from'] = ''; |
|
229
|
|
|
if(!isset($params['custom_where'])) $params['custom_where'] = ''; |
|
230
|
|
|
if(!isset($params['custom_order_by'])) $params['custom_order_by'] = ''; |
|
231
|
|
|
$main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by']; |
|
232
|
|
|
$result = $seed->db->query($main_query); |
|
233
|
|
|
|
|
234
|
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?><items>'; |
|
235
|
|
|
while($row = $seed->db->fetchByAssoc($result)) |
|
236
|
|
|
{ |
|
237
|
|
|
if (version_compare(phpversion(), '5.0') < 0) { |
|
238
|
|
|
$temp = $seed; |
|
239
|
|
|
} else { |
|
240
|
|
|
$temp = @clone($seed); |
|
241
|
|
|
} |
|
242
|
|
|
$temp->setupCustomFields($temp->module_dir); |
|
243
|
|
|
$temp->loadFromRow($row); |
|
244
|
|
|
$temp->fill_in_additional_detail_fields(); |
|
245
|
|
|
if(isset($temp->emailAddress)){ |
|
246
|
|
|
$temp->emailAddress->handleLegacyRetrieve($temp); |
|
247
|
|
|
} |
|
248
|
|
|
$val = get_return_value($temp, $table_name); |
|
249
|
|
|
$xml .= get_name_value_xml($val, $module_name); |
|
250
|
|
|
} |
|
251
|
|
|
$xml .= "</items>"; |
|
252
|
|
|
|
|
253
|
|
|
$xml = base64_encode($xml); |
|
254
|
|
|
|
|
255
|
|
|
return array('result'=>$xml, 'error'=>$error->get_soap_array()); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
$server->register( |
|
259
|
|
|
'get_attendee_list', |
|
260
|
|
|
array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'id'=>'xsd:string'), |
|
261
|
|
|
array('return'=>'tns:get_sync_result_encoded'), |
|
262
|
|
|
$NAMESPACE); |
|
263
|
|
|
|
|
264
|
|
|
function get_attendee_list($session, $module_name, $id){ |
|
265
|
|
|
global $beanList, $beanFiles; |
|
266
|
|
|
$error = new SoapError(); |
|
267
|
|
|
$field_list = array(); |
|
268
|
|
|
$output_list = array(); |
|
269
|
|
|
if(!validate_authenticated($session)){ |
|
270
|
|
|
$error->set_error('invalid_login'); |
|
271
|
|
|
return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array()); |
|
272
|
|
|
} |
|
273
|
|
|
if(empty($beanList[$module_name])){ |
|
274
|
|
|
$error->set_error('no_module'); |
|
275
|
|
|
return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array()); |
|
276
|
|
|
} |
|
277
|
|
|
global $current_user; |
|
278
|
|
|
if(!check_modules_access($current_user, $module_name, 'read')){ |
|
279
|
|
|
$error->set_error('no_access'); |
|
280
|
|
|
return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array()); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
|
|
284
|
|
|
$class_name = $beanList[$module_name]; |
|
285
|
|
|
require_once($beanFiles[$class_name]); |
|
286
|
|
|
$seed = new $class_name(); |
|
287
|
|
|
|
|
288
|
|
|
|
|
289
|
|
|
//rsmith |
|
290
|
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>'; |
|
291
|
|
|
if($module_name == 'Meetings' || $module_name == 'Calls'){ |
|
292
|
|
|
//if we find a meeting or call we want to send back the attendees |
|
293
|
|
|
$l_module_name = strtolower($module_name); |
|
294
|
|
|
$table_name = $l_module_name."_users"; |
|
295
|
|
|
if($module_name == 'Meetings') |
|
296
|
|
|
$join_field = "meeting"; |
|
297
|
|
|
else |
|
298
|
|
|
$join_field = "call"; |
|
299
|
|
|
$xml .= '<attendees>'; |
|
300
|
|
|
$result = $seed->db->query("SELECT users.id, $table_name.date_modified, first_name, last_name FROM users INNER JOIN $table_name ON $table_name.user_id = users.id WHERE ".$table_name.".".$join_field."_id = '".$GLOBALS['db']->quote($id)."' AND $table_name.deleted = 0"); |
|
301
|
|
|
$user = new User(); |
|
302
|
|
|
while($row = $seed->db->fetchByAssoc($result)) |
|
303
|
|
|
{ |
|
304
|
|
|
$user->id = $row['id']; |
|
305
|
|
|
$email = $user->emailAddress->getPrimaryAddress($user); |
|
306
|
|
|
$xml .= '<attendee>'; |
|
307
|
|
|
$xml .= '<id>'.$user->id.'</id>'; |
|
308
|
|
|
$xml .= '<first_name>'.$row['first_name'].'</first_name>'; |
|
309
|
|
|
$xml .= '<last_name>'.$row['last_name'].'</last_name>'; |
|
310
|
|
|
$xml .= '<email1>'.$email.'</email1>'; |
|
311
|
|
|
$xml .= '</attendee>'; |
|
312
|
|
|
} |
|
313
|
|
|
//now get contacts |
|
314
|
|
|
$table_name = $l_module_name."_contacts"; |
|
315
|
|
|
$result = $seed->db->query("SELECT contacts.id, $table_name.date_modified, first_name, last_name FROM contacts INNER JOIN $table_name ON $table_name.contact_id = contacts.id INNER JOIN $seed->table_name ON ".$seed->table_name.".id = ".$table_name.".".$join_field."_id WHERE ".$table_name.".".$join_field."_id = '".$GLOBALS['db']->quote($id)."' AND ".$table_name.".deleted = 0 AND (contacts.id != ".$seed->table_name.".parent_id OR ".$seed->table_name.".parent_id IS NULL)"); |
|
316
|
|
|
$contact = new Contact(); |
|
317
|
|
|
while($row = $seed->db->fetchByAssoc($result)) |
|
318
|
|
|
{ |
|
319
|
|
|
$contact->id = $row['id']; |
|
320
|
|
|
$email = $contact->emailAddress->getPrimaryAddress($contact); |
|
321
|
|
|
$xml .= '<attendee>'; |
|
322
|
|
|
$xml .= '<id>'.$contact->id.'</id>'; |
|
323
|
|
|
$xml .= '<first_name>'.$row['first_name'].'</first_name>'; |
|
324
|
|
|
$xml .= '<last_name>'.$row['last_name'].'</last_name>'; |
|
325
|
|
|
$xml .= '<email1>'.$email.'</email1>'; |
|
326
|
|
|
$xml .= '</attendee>'; |
|
327
|
|
|
} |
|
328
|
|
|
$xml .= '</attendees>'; |
|
329
|
|
|
} |
|
330
|
|
|
$xml = base64_encode($xml); |
|
331
|
|
|
return array('result'=>$xml, 'error'=>$error->get_soap_array()); |
|
332
|
|
|
} |
|
333
|
|
|
?> |
|
334
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.