1
|
|
|
<?php |
2
|
|
|
if(!defined('sugarEntry'))define('sugarEntry', true); |
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
|
|
|
// the types/methods defined in this file are deprecated -- please see SoapSugarUsers.php, SoapPortalUsers.php, SoapStudio.php, etc. |
43
|
|
|
|
44
|
|
|
$server->wsdl->addComplexType( |
45
|
|
|
'contact_detail', |
46
|
|
|
'complexType', |
47
|
|
|
'struct', |
48
|
|
|
'all', |
49
|
|
|
'', |
50
|
|
|
array( |
51
|
|
|
'email_address' => array('name'=>'email_address','type'=>'xsd:string'), |
52
|
|
|
'name1' => array('name'=>'name1','type'=>'xsd:string'), |
53
|
|
|
'name2' => array('name'=>'name2','type'=>'xsd:string'), |
54
|
|
|
'association' => array('name'=>'association','type'=>'xsd:string'), |
55
|
|
|
'id' => array('name'=>'id','type'=>'xsd:string'), |
56
|
|
|
'msi_id' => array('name'=>'id','type'=>'xsd:string'), |
57
|
|
|
'type' => array('name'=>'type','type'=>'xsd:string'), |
58
|
|
|
) |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$server->wsdl->addComplexType( |
62
|
|
|
'contact_detail_array', |
63
|
|
|
'complexType', |
64
|
|
|
'array', |
65
|
|
|
'', |
66
|
|
|
'SOAP-ENC:Array', |
67
|
|
|
array(), |
68
|
|
|
array( |
69
|
|
|
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:contact_detail[]') |
70
|
|
|
), |
71
|
|
|
'tns:contact_detail' |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$server->wsdl->addComplexType( |
75
|
|
|
'user_detail', |
76
|
|
|
'complexType', |
77
|
|
|
'struct', |
78
|
|
|
'all', |
79
|
|
|
'', |
80
|
|
|
array( |
81
|
|
|
'email_address' => array('name'=>'email_address','type'=>'xsd:string'), |
82
|
|
|
'user_name' => array('name'=>'user_name', 'type'=>'xsd:string'), |
83
|
|
|
'first_name' => array('name'=>'first_name','type'=>'xsd:string'), |
84
|
|
|
'last_name' => array('name'=>'last_name','type'=>'xsd:string'), |
85
|
|
|
'department' => array('name'=>'department','type'=>'xsd:string'), |
86
|
|
|
'id' => array('name'=>'id','type'=>'xsd:string'), |
87
|
|
|
'title' => array('name'=>'title','type'=>'xsd:string'), |
88
|
|
|
) |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$server->wsdl->addComplexType( |
92
|
|
|
'user_detail_array', |
93
|
|
|
'complexType', |
94
|
|
|
'array', |
95
|
|
|
'', |
96
|
|
|
'SOAP-ENC:Array', |
97
|
|
|
array(), |
98
|
|
|
array( |
99
|
|
|
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:user_detail[]') |
100
|
|
|
), |
101
|
|
|
'tns:user_detail' |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
$server->register( |
106
|
|
|
'create_session', |
107
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string'), |
108
|
|
|
array('return'=>'xsd:string'), |
109
|
|
|
$NAMESPACE); |
110
|
|
|
|
111
|
|
|
$server->register( |
112
|
|
|
'end_session', |
113
|
|
|
array('user_name'=>'xsd:string'), |
114
|
|
|
array('return'=>'xsd:string'), |
115
|
|
|
$NAMESPACE); |
116
|
|
|
|
117
|
|
|
$server->register( |
118
|
|
|
'contact_by_email', |
119
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string', 'email_address'=>'xsd:string'), |
120
|
|
|
array('return'=>'tns:contact_detail_array'), |
121
|
|
|
$NAMESPACE); |
122
|
|
|
|
123
|
|
|
$server->register( |
124
|
|
|
'get_contact_relationships', |
125
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string', 'id'=>'xsd:string'), |
126
|
|
|
array('return'=>'tns:contact_detail_array'), |
127
|
|
|
$NAMESPACE); |
128
|
|
|
|
129
|
|
|
$server->register( |
130
|
|
|
'user_list', |
131
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string'), |
132
|
|
|
array('return'=>'tns:user_detail_array'), |
133
|
|
|
$NAMESPACE); |
134
|
|
|
|
135
|
|
|
$server->register( |
136
|
|
|
'search', |
137
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string', 'name'=>'xsd:string'), |
138
|
|
|
array('return'=>'tns:contact_detail_array'), |
139
|
|
|
$NAMESPACE); |
140
|
|
|
|
141
|
|
|
$server->register( |
142
|
|
|
'track_email', |
143
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string','parent_id'=>'xsd:string', 'contact_ids'=>'xsd:string', 'date_sent'=>'xsd:date', 'email_subject'=>'xsd:string', 'email_body'=>'xsd:string'), |
144
|
|
|
array('return'=>'xsd:string'), |
145
|
|
|
$NAMESPACE); |
146
|
|
|
|
147
|
|
|
$server->register( |
148
|
|
|
'create_contact', |
149
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string', 'first_name'=>'xsd:string', 'last_name'=>'xsd:string', 'email_address'=>'xsd:string'), |
150
|
|
|
array('return'=>'xsd:string'), |
151
|
|
|
$NAMESPACE); |
152
|
|
|
$server->register( |
153
|
|
|
'create_lead', |
154
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string', 'first_name'=>'xsd:string', 'last_name'=>'xsd:string', 'email_address'=>'xsd:string'), |
155
|
|
|
array('return'=>'xsd:string'), |
156
|
|
|
$NAMESPACE); |
157
|
|
|
$server->register( |
158
|
|
|
'create_account', |
159
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string', 'name'=>'xsd:string', 'phone'=>'xsd:string', 'website'=>'xsd:string'), |
160
|
|
|
array('return'=>'xsd:string'), |
161
|
|
|
$NAMESPACE); |
162
|
|
|
|
163
|
|
|
$server->register( |
164
|
|
|
'create_opportunity', |
165
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string', 'name'=>'xsd:string', 'amount'=>'xsd:string'), |
166
|
|
|
array('return'=>'xsd:string'), |
167
|
|
|
$NAMESPACE); |
168
|
|
|
|
169
|
|
|
$server->register( |
170
|
|
|
'create_case', |
171
|
|
|
array('user_name'=>'xsd:string','password'=>'xsd:string', 'name'=>'xsd:string'), |
172
|
|
|
array('return'=>'xsd:string'), |
173
|
|
|
$NAMESPACE); |
174
|
|
|
/** |
175
|
|
|
* Create a new session. This method is required before calling any other functions. |
176
|
|
|
* |
177
|
|
|
* @param string $user_name -- the user name for the session |
178
|
|
|
* @param string $password -- MD5 of user password |
179
|
|
|
* @return "Success" if the session is created |
|
|
|
|
180
|
|
|
* @return "Failed" if the session creation failed. |
|
|
|
|
181
|
|
|
*/ |
182
|
|
|
function create_session($user_name, $password) |
183
|
|
|
{ |
184
|
|
|
if(validate_user($user_name, $password)) |
185
|
|
|
{ |
186
|
|
|
return "Success"; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
return "Failed"; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* End a session. This method will end the SOAP session. |
194
|
|
|
* |
195
|
|
|
* @param string $user_name -- the user name for the session |
196
|
|
|
* @return "Success" if the session is destroyed |
|
|
|
|
197
|
|
|
* @return "Failed" if the session destruction failed. |
|
|
|
|
198
|
|
|
*/ |
199
|
|
|
function end_session($user_name) |
200
|
|
|
{ |
201
|
|
|
// get around optimizer warning |
202
|
|
|
$user_name = $user_name; |
|
|
|
|
203
|
|
|
return "Success"; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Validate the user session based on user name and password hash. |
208
|
|
|
* |
209
|
|
|
* @param string $user_name -- The user name to create a session for |
210
|
|
|
* @param string $password -- The MD5 sum of the user's password |
211
|
|
|
* @return true -- If the session is created |
212
|
|
|
* @return false -- If the session is not created |
213
|
|
|
*/ |
214
|
|
|
function validate_user($user_name, $password){ |
215
|
|
|
global $server, $current_user, $sugar_config, $system_config; |
216
|
|
|
$user = new User(); |
217
|
|
|
$user->user_name = $user_name; |
218
|
|
|
$system_config = new Administration(); |
219
|
|
|
$system_config->retrieveSettings('system'); |
220
|
|
|
$authController = new AuthenticationController(); |
221
|
|
|
// Check to see if the user name and password are consistent. |
222
|
|
|
if($user->authenticate_user($password)){ |
223
|
|
|
// we also need to set the current_user. |
224
|
|
|
$user->retrieve($user->id); |
225
|
|
|
$current_user = $user; |
226
|
|
|
login_success(); |
227
|
|
|
return true; |
228
|
|
|
}else if(function_exists('mcrypt_cbc')){ |
229
|
|
|
$password = decrypt_string($password); |
230
|
|
|
if($authController->login($user_name, $password) && isset($_SESSION['authenticated_user_id'])){ |
231
|
|
|
$user->retrieve($_SESSION['authenticated_user_id']); |
232
|
|
|
$current_user = $user; |
233
|
|
|
login_success(); |
234
|
|
|
return true; |
235
|
|
|
} |
236
|
|
|
}else{ |
237
|
|
|
$GLOBALS['log']->fatal("SECURITY: failed attempted login for $user_name using SOAP api"); |
238
|
|
|
$server->setError("Invalid username and/or password"); |
239
|
|
|
return false; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Internal: When building a response to the plug-in for Microsoft Outlook, find |
246
|
|
|
* all contacts that match the email address that was provided. |
247
|
|
|
* |
248
|
|
|
* @param array by ref $output_list -- The list of matching beans. New contacts that match |
249
|
|
|
* the email address are appended to the $output_list |
250
|
|
|
* @param string $email_address -- an email address to search for |
251
|
|
|
* @param Contact $seed_contact -- A template SugarBean. This is a blank Contact |
252
|
|
|
* @param ID $msi_id -- Index Count |
253
|
|
|
*/ |
254
|
|
|
function add_contacts_matching_email_address(&$output_list, $email_address, &$seed_contact, &$msi_id) |
255
|
|
|
{ |
256
|
|
|
// escape the email address |
257
|
|
|
$safe_email_address = addslashes($email_address); |
258
|
|
|
global $current_user; |
259
|
|
|
|
260
|
|
|
// Verify that the user has permission to see Contact list views |
261
|
|
|
if(!$seed_contact->ACLAccess('ListView')) |
262
|
|
|
{ |
263
|
|
|
return; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
$contactList = $seed_contact->emailAddress->getBeansByEmailAddress($safe_email_address); |
267
|
|
|
// create a return array of names and email addresses. |
268
|
|
|
foreach($contactList as $contact) |
269
|
|
|
{ |
270
|
|
|
if (!is_a($contact, 'Contact')) continue; |
271
|
|
|
|
272
|
|
|
$output_list[] = Array("name1" => $contact->first_name, |
273
|
|
|
"name2" => $contact->last_name, |
274
|
|
|
"association" => $contact->account_name, |
275
|
|
|
"type" => 'Contact', |
276
|
|
|
"id" => $contact->id, |
277
|
|
|
"msi_id" => $msi_id, |
278
|
|
|
"email_address" => $contact->email1); |
279
|
|
|
|
280
|
|
|
$accounts = $contact->get_linked_beans('accounts','Account'); |
281
|
|
|
foreach($accounts as $account) |
282
|
|
|
{ |
283
|
|
|
$output_list[] = get_account_array($account, $msi_id); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
$opps = $contact->get_linked_beans('opportunities','Opportunity'); |
287
|
|
|
foreach($opps as $opp) |
288
|
|
|
{ |
289
|
|
|
$output_list[] = get_opportunity_array($opp, $msi_id); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
$cases = $contact->get_linked_beans('cases','aCase'); |
293
|
|
|
foreach($cases as $case) |
294
|
|
|
{ |
295
|
|
|
$output_list[] = get_case_array($case, $msi_id); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
$bugs = $contact->get_linked_beans('bugs','Bug'); |
299
|
|
|
foreach($bugs as $bug) |
300
|
|
|
{ |
301
|
|
|
$output_list[] = get_bean_array($bug, $msi_id, 'Bug'); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
$projects = $contact->get_linked_beans('project','Project'); |
305
|
|
|
foreach($projects as $project) |
306
|
|
|
{ |
307
|
|
|
$output_list[] = get_bean_array($project, $msi_id, 'Project'); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
$msi_id = $msi_id + 1; |
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
/** |
314
|
|
|
* Internal: Add Leads that match the specified email address to the result array |
315
|
|
|
* |
316
|
|
|
* @param Array $output_list -- List of matching detail records |
317
|
|
|
* @param String $email_address -- Email address |
318
|
|
|
* @param Bean $seed_lead -- Seed Lead Bean |
319
|
|
|
* @param int $msi_id -- output array offset. |
320
|
|
|
*/ |
321
|
|
|
function add_leads_matching_email_address(&$output_list, $email_address, &$seed_lead, &$msi_id) |
322
|
|
|
{ |
323
|
|
|
$safe_email_address = $GLOBALS['db']->quote($email_address); |
324
|
|
|
if(!$seed_lead->ACLAccess('ListView')){ |
325
|
|
|
return; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
$leadList = $seed_lead->emailAddress->getBeansByEmailAddress($safe_email_address); |
329
|
|
|
|
330
|
|
|
// create a return array of names and email addresses. |
331
|
|
|
foreach($leadList as $lead) |
332
|
|
|
{ |
333
|
|
|
if (!is_a($lead, 'Lead')) continue; |
334
|
|
|
|
335
|
|
|
$output_list[] = Array("name1" => $lead->first_name, |
336
|
|
|
"name2" => $lead->last_name, |
337
|
|
|
"association" => $lead->account_name, |
338
|
|
|
"type" => 'Lead', |
339
|
|
|
"id" => $lead->id, |
340
|
|
|
"msi_id" => $msi_id, |
341
|
|
|
"email_address" => $lead->email1); |
342
|
|
|
|
343
|
|
|
$msi_id = $msi_id + 1; |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
/** |
347
|
|
|
* Return a list of modules related to the specifed contact record |
348
|
|
|
* |
349
|
|
|
* This function does not require a session be created first. |
350
|
|
|
* |
351
|
|
|
* @param string $user_name -- User name to authenticate with |
352
|
|
|
* @param string $password -- MD5 of the user password |
353
|
|
|
* @param string $id -- the id of the record |
354
|
|
|
* @return contact detail array along with associated objects. |
355
|
|
|
*/ |
356
|
|
|
function get_contact_relationships($user_name, $password, $id) |
357
|
|
|
{ |
358
|
|
|
if(!validate_user($user_name, $password)){ |
359
|
|
|
return array(); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
$seed_contact = new Contact(); |
363
|
|
|
// Verify that the user has permission to see Contact list views |
364
|
|
|
if(!$seed_contact->ACLAccess('ListView')) |
365
|
|
|
{ |
366
|
|
|
return; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
$msi_id = 1; |
370
|
|
|
$seed_contact->retrieve($id); |
371
|
|
|
|
372
|
|
|
$output_list[] = Array("name1" => $seed_contact->first_name, |
373
|
|
|
"name2" => $seed_contact->last_name, |
374
|
|
|
"association" => $seed_contact->account_name, |
375
|
|
|
"type" => 'Contact', |
376
|
|
|
"id" => $seed_contact->id, |
377
|
|
|
"msi_id" => $msi_id, |
378
|
|
|
"email_address" => $seed_contact->email1); |
379
|
|
|
|
380
|
|
|
$accounts = $seed_contact->get_linked_beans('accounts','Account'); |
381
|
|
|
foreach($accounts as $account) |
382
|
|
|
{ |
383
|
|
|
$output_list[] = get_account_array($account, $msi_id); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
$opps = $seed_contact->get_linked_beans('opportunities','Opportunity'); |
387
|
|
|
foreach($opps as $opp) |
388
|
|
|
{ |
389
|
|
|
$output_list[] = get_opportunity_array($opp, $msi_id); |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
$cases = $seed_contact->get_linked_beans('cases','aCase'); |
393
|
|
|
foreach($cases as $case) |
394
|
|
|
{ |
395
|
|
|
$output_list[] = get_case_array($case, $msi_id); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
$bugs = $seed_contact->get_linked_beans('bugs','Bug'); |
399
|
|
|
foreach($bugs as $bug) |
400
|
|
|
{ |
401
|
|
|
$output_list[] = get_bean_array($bug, $msi_id, 'Bug'); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
$projects = $seed_contact->get_linked_beans('project','Project'); |
405
|
|
|
foreach($projects as $project) |
406
|
|
|
{ |
407
|
|
|
$output_list[] = get_bean_array($project, $msi_id, 'Project'); |
408
|
|
|
} |
409
|
|
|
return $output_list; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
// Define a global current user |
413
|
|
|
$current_user = null; |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* Return a list of contact and lead detail records based on a single email |
417
|
|
|
* address or a list of email addresses separated by '; '. |
418
|
|
|
* |
419
|
|
|
* This function does not require a session be created first. |
420
|
|
|
* |
421
|
|
|
* @param string $user_name -- User name to authenticate with |
422
|
|
|
* @param string $password -- MD5 of the user password |
423
|
|
|
* @param string $email_address -- Single email address or '; ' separated list of email addresses (e.x "[email protected]; [email protected]" |
424
|
|
|
* @return contact detail array along with associated objects. |
425
|
|
|
*/ |
426
|
|
|
function contact_by_email($user_name, $password, $email_address) |
427
|
|
|
{ |
428
|
|
|
if(!validate_user($user_name, $password)){ |
429
|
|
|
return array(); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
$seed_contact = new Contact(); |
433
|
|
|
$seed_lead = new Lead(); |
434
|
|
|
$output_list = Array(); |
435
|
|
|
$email_address_list = explode("; ", $email_address); |
436
|
|
|
|
437
|
|
|
// remove duplicate email addresses |
438
|
|
|
$non_duplicate_email_address_list = Array(); |
439
|
|
|
foreach( $email_address_list as $single_address) |
440
|
|
|
{ |
441
|
|
|
// Check to see if the current address is a match of an existing address |
442
|
|
|
$found_match = false; |
443
|
|
|
foreach( $non_duplicate_email_address_list as $non_dupe_single) |
444
|
|
|
{ |
445
|
|
|
if(strtolower($single_address) == $non_dupe_single) |
446
|
|
|
{ |
447
|
|
|
$found_match = true; |
448
|
|
|
break; |
449
|
|
|
} |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
if($found_match == false) |
|
|
|
|
453
|
|
|
{ |
454
|
|
|
$non_duplicate_email_address_list[] = strtolower($single_address); |
455
|
|
|
} |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
// now copy over the non-duplicated list as the original list. |
459
|
|
|
$email_address_list =$non_duplicate_email_address_list; |
460
|
|
|
|
461
|
|
|
// Track the msi_id |
462
|
|
|
$msi_id = 1; |
463
|
|
|
|
464
|
|
|
foreach( $email_address_list as $single_address) |
465
|
|
|
{ |
466
|
|
|
// verify that contacts can be listed |
467
|
|
|
if($seed_contact->ACLAccess('ListView')){ |
468
|
|
|
add_contacts_matching_email_address($output_list, $single_address, $seed_contact, $msi_id); |
|
|
|
|
469
|
|
|
} |
470
|
|
|
// verify that leads can be listed |
471
|
|
|
if($seed_lead->ACLAccess('ListView')){ |
472
|
|
|
add_leads_matching_email_address($output_list, $single_address, $seed_lead, $msi_id); |
|
|
|
|
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
return $output_list; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* Internal: convert a bean into an array |
481
|
|
|
* |
482
|
|
|
* @param Bean $bean -- The bean to convert |
|
|
|
|
483
|
|
|
* @param int $msi_id -- Russult array index |
484
|
|
|
* @return An associated array containing the detail fields. |
485
|
|
|
*/ |
486
|
|
|
function get_contact_array($contact, $msi_id = '0'){ |
487
|
|
|
$contact->emailAddress->handleLegacyRetrieve($contact); |
488
|
|
|
return Array("name1" => $contact->first_name, |
489
|
|
|
"name2" => $contact->last_name, |
490
|
|
|
"association" => $contact->account_name, |
491
|
|
|
"type" => 'Contact', |
492
|
|
|
"id" => $contact->id, |
493
|
|
|
"msi_id" => $msi_id, |
494
|
|
|
"email_address" => $contact->email1); |
495
|
|
|
|
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* Internal: Convert a user into an array |
500
|
|
|
* |
501
|
|
|
* @param User $user -- The user to convert |
502
|
|
|
* @return An associated array containing the detail fields. |
503
|
|
|
*/ |
504
|
|
|
function get_user_list_array($user) { |
505
|
|
|
return Array('email_address' => $user->email1, |
506
|
|
|
'user_name' => $user->user_name, |
507
|
|
|
'first_name' => $user->first_name, |
508
|
|
|
'last_name' => $user->last_name, |
509
|
|
|
'department' => $user->department, |
510
|
|
|
'id' => $user->id, |
511
|
|
|
'title' => $user->title); |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
/** |
515
|
|
|
* Get a full user list. |
516
|
|
|
* |
517
|
|
|
* This function does not require a session be created first. |
518
|
|
|
* |
519
|
|
|
* @param string $user -- user name for validation |
520
|
|
|
* @param password $password -- MD5 hash of the user password for validation |
521
|
|
|
* @return User Array -- An array of user detail records |
522
|
|
|
*/ |
523
|
|
|
function user_list($user, $password) { |
524
|
|
|
if(!validate_user($user, $password)){ |
525
|
|
|
return array(); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
$seed_user = new User(); |
529
|
|
|
$output_list = Array(); |
530
|
|
|
if(!$seed_user->ACLAccess('ListView')){ |
531
|
|
|
return $output_list; |
532
|
|
|
} |
533
|
|
|
$userList = $seed_user->get_full_list(); |
534
|
|
|
|
535
|
|
|
|
536
|
|
|
foreach($userList as $user) { |
|
|
|
|
537
|
|
|
$output_list[] = get_user_list_array($user); |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
return $output_list; |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* Internal: Search for contacts based on the specified name and where clause. |
545
|
|
|
* Currently only the name is used. |
546
|
|
|
* |
547
|
|
|
* @param string $name -- Name to search for. |
548
|
|
|
* @param string $where -- Where clause defaults to '' |
549
|
|
|
* @param int $msi_id -- Response array index |
550
|
|
|
* @return array -- Resturns a list of contacts that have the provided name. |
551
|
|
|
*/ |
552
|
|
|
function contact_by_search($name, $where = '', $msi_id = '0') |
553
|
|
|
{ |
554
|
|
|
$seed_contact = new Contact(); |
555
|
|
|
if($where == ''){ |
556
|
|
|
$where = $seed_contact->build_generic_where_clause($name); |
557
|
|
|
} |
558
|
|
|
if(!$seed_contact->ACLAccess('ListView')){ |
559
|
|
|
return array(); |
560
|
|
|
} |
561
|
|
|
$response = $seed_contact->get_list("last_name, first_name", $where, 0); |
562
|
|
|
$contactList = $response['list']; |
563
|
|
|
|
564
|
|
|
$output_list = Array(); |
565
|
|
|
|
566
|
|
|
// create a return array of names and email addresses. |
567
|
|
|
foreach($contactList as $contact) |
568
|
|
|
{ |
569
|
|
|
$output_list[] = get_contact_array($contact, $msi_id); |
570
|
|
|
} |
571
|
|
|
return $output_list; |
572
|
|
|
} |
573
|
|
|
/** |
574
|
|
|
* Internal: convert a bean into an array |
575
|
|
|
* |
576
|
|
|
* @param Bean $bean -- The bean to convert |
|
|
|
|
577
|
|
|
* @param int $msi_id -- Russult array index |
578
|
|
|
* @return An associated array containing the detail fields. |
579
|
|
|
*/ |
580
|
|
|
function get_lead_array($lead, $msi_id = '0'){ |
581
|
|
|
$lead->emailAddress->handleLegacyRetrieve($lead); |
582
|
|
|
return Array("name1" => $lead->first_name, |
583
|
|
|
"name2" => $lead->last_name, |
584
|
|
|
"association" => $lead->account_name, |
585
|
|
|
"type" => 'Lead', |
586
|
|
|
"id" => $lead->id, |
587
|
|
|
"msi_id" => $msi_id, |
588
|
|
|
"email_address" => $lead->email1); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
function lead_by_search($name, $where = '', $msi_id = '0') |
592
|
|
|
{ |
593
|
|
|
$seed_lead = new Lead(); |
594
|
|
|
if($where == ''){ |
595
|
|
|
$where = $seed_lead->build_generic_where_clause($name); |
596
|
|
|
} |
597
|
|
|
if(!$seed_lead->ACLAccess('ListView')){ |
598
|
|
|
return array(); |
599
|
|
|
} |
600
|
|
|
$response = $seed_lead->get_list("last_name, first_name", $where, 0); |
601
|
|
|
$lead_list = $response['list']; |
602
|
|
|
|
603
|
|
|
$output_list = Array(); |
604
|
|
|
|
605
|
|
|
// create a return array of names and email addresses. |
606
|
|
|
foreach($lead_list as $lead) |
607
|
|
|
{ |
608
|
|
|
$output_list[] = get_lead_array($lead, $msi_id); |
609
|
|
|
} |
610
|
|
|
return $output_list; |
611
|
|
|
} |
612
|
|
|
/** |
613
|
|
|
* Internal: convert a bean into an array |
614
|
|
|
* |
615
|
|
|
* @param Bean $bean -- The bean to convert |
|
|
|
|
616
|
|
|
* @param int $msi_id -- Russult array index |
617
|
|
|
* @return An associated array containing the detail fields. |
618
|
|
|
*/ |
619
|
|
|
function get_account_array($account, $msi_id){ |
620
|
|
|
return Array("name1" => '', |
621
|
|
|
"name2" => $account->name, |
622
|
|
|
"association" => $account->billing_address_city, |
623
|
|
|
"type" => 'Account', |
624
|
|
|
"id" => $account->id, |
625
|
|
|
"msi_id" => $msi_id, |
626
|
|
|
"email_address" => $account->email1); |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
function account_by_search($name, $where = '', $msi_id = '0') |
630
|
|
|
{ |
631
|
|
|
$seed_account = new Account(); |
632
|
|
|
if(!$seed_account->ACLAccess('ListView')){ |
633
|
|
|
return array(); |
634
|
|
|
} |
635
|
|
|
if($where == ''){ |
636
|
|
|
$where = $seed_account->build_generic_where_clause($name); |
637
|
|
|
} |
638
|
|
|
$response = $seed_account->get_list("name", $where, 0); |
639
|
|
|
$accountList = $response['list']; |
640
|
|
|
|
641
|
|
|
$output_list = Array(); |
642
|
|
|
|
643
|
|
|
// create a return array of names and email addresses. |
644
|
|
|
foreach($accountList as $account) |
645
|
|
|
{ |
646
|
|
|
$output_list[] = get_account_array($account, $msi_id); |
647
|
|
|
} |
648
|
|
|
return $output_list; |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
/** |
652
|
|
|
* Internal: convert a bean into an array |
653
|
|
|
* |
654
|
|
|
* @param Bean $bean -- The bean to convert |
|
|
|
|
655
|
|
|
* @param int $msi_id -- Russult array index |
656
|
|
|
* @return An associated array containing the detail fields. |
657
|
|
|
*/ |
658
|
|
|
function get_opportunity_array($value, $msi_id = '0'){ |
659
|
|
|
return Array("name1" => '', |
660
|
|
|
"name2" => $value->name, |
661
|
|
|
"association" => $value->account_name, |
662
|
|
|
"type" => 'Opportunity', |
663
|
|
|
"id" => $value->id, |
664
|
|
|
"msi_id" => $msi_id, |
665
|
|
|
"email_address" => ''); |
666
|
|
|
|
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
function opportunity_by_search($name, $where = '', $msi_id = '0') |
670
|
|
|
{ |
671
|
|
|
$seed = new Opportunity(); |
672
|
|
|
if(!$seed->ACLAccess('ListView')){ |
673
|
|
|
return array(); |
674
|
|
|
} |
675
|
|
|
if($where == ''){ |
676
|
|
|
$where = $seed->build_generic_where_clause($name); |
677
|
|
|
} |
678
|
|
|
$response = $seed->get_list("name", $where, 0); |
679
|
|
|
$list = $response['list']; |
680
|
|
|
|
681
|
|
|
$output_list = Array(); |
682
|
|
|
|
683
|
|
|
// create a return array of names and email addresses. |
684
|
|
|
foreach($list as $value) |
685
|
|
|
{ |
686
|
|
|
$output_list[] = get_opportunity_array($value, $msi_id); |
687
|
|
|
} |
688
|
|
|
return $output_list; |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
/** |
692
|
|
|
* Internal: convert a bean into an array |
693
|
|
|
* |
694
|
|
|
* @param Bean $bean -- The bean to convert |
|
|
|
|
695
|
|
|
* @param int $msi_id -- Russult array index |
696
|
|
|
* @return An associated array containing the detail fields. |
697
|
|
|
*/ |
698
|
|
|
function get_bean_array($value, $msi_id, $type){ |
699
|
|
|
return Array("name1" => '', |
700
|
|
|
"name2" => $value->get_summary_text(), |
701
|
|
|
"association" => '', |
702
|
|
|
"type" => $type, |
703
|
|
|
"id" => $value->id, |
704
|
|
|
"msi_id" => $msi_id, |
705
|
|
|
"email_address" => ''); |
706
|
|
|
|
707
|
|
|
} |
708
|
|
|
/** |
709
|
|
|
* Internal: convert a bean into an array |
710
|
|
|
* |
711
|
|
|
* @param Bean $bean -- The bean to convert |
|
|
|
|
712
|
|
|
* @param int $msi_id -- Russult array index |
713
|
|
|
* @return An associated array containing the detail fields. |
714
|
|
|
*/ |
715
|
|
|
function get_case_array($value, $msi_id){ |
716
|
|
|
return Array("name1" => '', |
717
|
|
|
"name2" => $value->get_summary_text(), |
718
|
|
|
"association" => $value->account_name, |
719
|
|
|
"type" => 'Case', |
720
|
|
|
"id" => $value->id, |
721
|
|
|
"msi_id" => $msi_id, |
722
|
|
|
"email_address" => ''); |
723
|
|
|
|
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
function bug_by_search($name, $where = '', $msi_id='0') |
727
|
|
|
{ |
728
|
|
|
$seed = new Bug(); |
729
|
|
|
if(!$seed->ACLAccess('ListView')){ |
730
|
|
|
return array(); |
731
|
|
|
} |
732
|
|
|
if($where == ''){ |
733
|
|
|
$where = $seed->build_generic_where_clause($name); |
734
|
|
|
} |
735
|
|
|
$response = $seed->get_list("name", $where, 0); |
736
|
|
|
$list = $response['list']; |
737
|
|
|
|
738
|
|
|
$output_list = Array(); |
739
|
|
|
|
740
|
|
|
// create a return array of names and email addresses. |
741
|
|
|
foreach($list as $value) |
742
|
|
|
{ |
743
|
|
|
$output_list[] = get_bean_array($value, $msi_id, 'Bug'); |
744
|
|
|
} |
745
|
|
|
return $output_list; |
746
|
|
|
} |
747
|
|
|
|
748
|
|
|
function case_by_search($name, $where = '', $msi_id='0') |
749
|
|
|
{ |
750
|
|
|
$seed = new aCase(); |
751
|
|
|
if(!$seed->ACLAccess('ListView')){ |
752
|
|
|
return array(); |
753
|
|
|
} |
754
|
|
|
if($where == ''){ |
755
|
|
|
$where = $seed->build_generic_where_clause($name); |
756
|
|
|
} |
757
|
|
|
$response = $seed->get_list("name", $where, 0); |
758
|
|
|
$list = $response['list']; |
759
|
|
|
|
760
|
|
|
$output_list = Array(); |
761
|
|
|
|
762
|
|
|
// create a return array of names and email addresses. |
763
|
|
|
foreach($list as $value) |
764
|
|
|
{ |
765
|
|
|
$output_list[] = get_case_array($value, $msi_id); |
766
|
|
|
} |
767
|
|
|
return $output_list; |
768
|
|
|
} |
769
|
|
|
/** |
770
|
|
|
* Record and email message and associated it with the specified parent bean and contact ids. |
771
|
|
|
* |
772
|
|
|
* This function does not require a session be created first. |
773
|
|
|
* |
774
|
|
|
* @param string $user_name -- Name of the user to authenticate |
775
|
|
|
* @param string $password -- MD5 hash of the user password for authentication |
776
|
|
|
* @param id $parent_id -- [optional] The parent record to link the email to. |
777
|
|
|
* @param unknown_type $contact_ids |
778
|
|
|
* @param string $date_sent -- Date/time the email was sent in Visual Basic Date format. (e.g. '7/22/2004 9:36:31 AM') |
779
|
|
|
* @param string $email_subject -- The subject of the email |
780
|
|
|
* @param string $email_body -- The body of the email |
781
|
|
|
* @return "Invalid username and/or password" |
|
|
|
|
782
|
|
|
* @return -1 If the authenticated user does not have ACL access to save Email. |
|
|
|
|
783
|
|
|
*/ |
784
|
|
|
function track_email($user_name, $password,$parent_id, $contact_ids, $date_sent, $email_subject, $email_body) |
785
|
|
|
{ |
786
|
|
|
if(!validate_user($user_name, $password)){ |
787
|
|
|
return "Invalid username and/or password"; |
788
|
|
|
} |
789
|
|
|
global $current_user; |
790
|
|
|
|
791
|
|
|
$GLOBALS['log']->info("In track email: username: $user_name contacts: $contact_ids date_sent: $date_sent"); |
792
|
|
|
|
793
|
|
|
// translate date sent from VB format 7/22/2004 9:36:31 AM |
794
|
|
|
// to yyyy-mm-dd 9:36:31 AM |
795
|
|
|
|
796
|
|
|
$date_sent = preg_replace("@([0-9]*)/([0-9]*)/([0-9]*)( .*$)@", "\\3-\\1-\\2\\4", $date_sent); |
797
|
|
|
|
798
|
|
|
|
799
|
|
|
$seed_user = new User(); |
800
|
|
|
|
801
|
|
|
$user_id = $seed_user->retrieve_user_id($user_name); |
802
|
|
|
$seed_user->retrieve($user_id); |
803
|
|
|
$current_user = $seed_user; |
804
|
|
|
|
805
|
|
|
|
806
|
|
|
$email = new Email(); |
807
|
|
|
if(!$email->ACLAccess('Save')){ |
808
|
|
|
return -1; |
809
|
|
|
} |
810
|
|
|
$email->description = $email_body; |
811
|
|
|
$email->name = $email_subject; |
812
|
|
|
$email->user_id = $user_id; |
813
|
|
|
$email->assigned_user_id = $user_id; |
814
|
|
|
$email->assigned_user_name = $user_name; |
815
|
|
|
$email->date_start = $date_sent; |
816
|
|
|
|
817
|
|
|
// Save one copy of the email message |
818
|
|
|
$parent_id_list = explode(";", $parent_id); |
819
|
|
|
$parent_id = explode(':', $parent_id_list[0]); |
820
|
|
|
|
821
|
|
|
// Having a parent object is optional. If it is set, then associate it. |
822
|
|
|
if(isset($parent_id[0]) && isset($parent_id[1])) |
823
|
|
|
{ |
824
|
|
|
$email->parent_type = $parent_id[0]; |
825
|
|
|
$email->parent_id = $parent_id[1]; |
826
|
|
|
} |
827
|
|
|
|
828
|
|
|
$email->save(); |
829
|
|
|
// for each contact, add a link between the contact and the email message |
830
|
|
|
$id_list = explode(";", $contact_ids); |
831
|
|
|
|
832
|
|
|
foreach( $id_list as $id) |
833
|
|
|
{ |
834
|
|
|
if(!empty($id)) { |
835
|
|
|
$email->set_emails_contact_invitee_relationship($email->id, $GLOBALS['db']->quote($id)); |
|
|
|
|
836
|
|
|
} |
837
|
|
|
} |
838
|
|
|
|
839
|
|
|
return "Succeeded"; |
840
|
|
|
} |
841
|
|
|
|
842
|
|
|
function create_contact($user_name,$password, $first_name, $last_name, $email_address) |
843
|
|
|
{ |
844
|
|
|
if(!validate_user($user_name, $password)){ |
845
|
|
|
return 0; |
846
|
|
|
} |
847
|
|
|
|
848
|
|
|
|
849
|
|
|
$seed_user = new User(); |
850
|
|
|
$user_id = $seed_user->retrieve_user_id($user_name); |
851
|
|
|
$seed_user->retrieve($user_id); |
852
|
|
|
|
853
|
|
|
|
854
|
|
|
$contact = new Contact(); |
855
|
|
|
if(!$contact->ACLAccess('Save')){ |
856
|
|
|
return -1; |
857
|
|
|
} |
858
|
|
|
$contact->first_name = $first_name; |
859
|
|
|
$contact->last_name = $last_name; |
860
|
|
|
$contact->email1 = $email_address; |
861
|
|
|
$contact->assigned_user_id = $user_id; |
862
|
|
|
$contact->assigned_user_name = $user_name; |
863
|
|
|
return $contact->save(); |
864
|
|
|
} |
865
|
|
|
function create_lead($user_name,$password, $first_name, $last_name, $email_address) |
866
|
|
|
{ |
867
|
|
|
if(!validate_user($user_name, $password)){ |
868
|
|
|
return 0; |
869
|
|
|
} |
870
|
|
|
|
871
|
|
|
//todo make the activity body not be html encoded |
872
|
|
|
|
873
|
|
|
|
874
|
|
|
$seed_user = new User(); |
875
|
|
|
$user_id = $seed_user->retrieve_user_id($user_name); |
876
|
|
|
|
877
|
|
|
|
878
|
|
|
$lead = new Lead(); |
879
|
|
|
if(!$lead->ACLAccess('Save')){ |
880
|
|
|
return -1; |
881
|
|
|
} |
882
|
|
|
$lead->first_name = $first_name; |
883
|
|
|
$lead->last_name = $last_name; |
884
|
|
|
$lead->email1 = $email_address; |
885
|
|
|
$lead->assigned_user_id = $user_id; |
886
|
|
|
$lead->assigned_user_name = $user_name; |
887
|
|
|
return $lead->save(); |
888
|
|
|
} |
889
|
|
|
function create_account($user_name,$password, $name, $phone, $website) |
890
|
|
|
{ |
891
|
|
|
if(!validate_user($user_name, $password)){ |
892
|
|
|
return 0; |
893
|
|
|
} |
894
|
|
|
|
895
|
|
|
//todo make the activity body not be html encoded |
896
|
|
|
|
897
|
|
|
|
898
|
|
|
$seed_user = new User(); |
899
|
|
|
$user_id = $seed_user->retrieve_user_id($user_name); |
900
|
|
|
$account = new Account(); |
901
|
|
|
if(!$account->ACLAccess('Save')){ |
902
|
|
|
return -1; |
903
|
|
|
} |
904
|
|
|
$account->name = $name; |
905
|
|
|
$account->phone_office = $phone; |
906
|
|
|
$account->website = $website; |
907
|
|
|
$account->assigned_user_id = $user_id; |
908
|
|
|
$account->assigned_user_name = $user_name; |
909
|
|
|
$account->save(); |
910
|
|
|
return $account->id; |
911
|
|
|
|
912
|
|
|
} |
913
|
|
|
function create_case($user_name,$password, $name) |
914
|
|
|
{ |
915
|
|
|
if(!validate_user($user_name, $password)){ |
916
|
|
|
return 0; |
917
|
|
|
} |
918
|
|
|
|
919
|
|
|
//todo make the activity body not be html encoded |
920
|
|
|
|
921
|
|
|
|
922
|
|
|
$seed_user = new User(); |
923
|
|
|
$user_id = $seed_user->retrieve_user_id($user_name); |
924
|
|
|
$case = new aCase(); |
925
|
|
|
if(!$case->ACLAccess('Save')){ |
926
|
|
|
return -1; |
927
|
|
|
} |
928
|
|
|
$case->assigned_user_id = $user_id; |
929
|
|
|
$case->assigned_user_name = $user_name; |
930
|
|
|
$case->name = $name; |
931
|
|
|
return $case->save(); |
932
|
|
|
} |
933
|
|
|
function create_opportunity($user_name,$password, $name, $amount) |
934
|
|
|
{ |
935
|
|
|
if(!validate_user($user_name, $password)){ |
936
|
|
|
return 0; |
937
|
|
|
} |
938
|
|
|
|
939
|
|
|
|
940
|
|
|
$seed_user = new User(); |
941
|
|
|
$user_id = $seed_user->retrieve_user_id($user_name); |
942
|
|
|
$opp = new Opportunity(); |
943
|
|
|
if(!$opp->ACLAccess('Save')){ |
944
|
|
|
return -1; |
945
|
|
|
} |
946
|
|
|
$opp->name = $name; |
947
|
|
|
$opp->amount = $amount; |
948
|
|
|
$opp->assigned_user_id = $user_id; |
949
|
|
|
$opp->assigned_user_name = $user_name; |
950
|
|
|
return $opp->save(); |
951
|
|
|
} |
952
|
|
|
|
953
|
|
|
function search($user_name, $password,$name){ |
954
|
|
|
if(!validate_user($user_name, $password)){ |
955
|
|
|
return array(); |
956
|
|
|
} |
957
|
|
|
$name_list = explode("; ", $name); |
958
|
|
|
$list = array(); |
959
|
|
|
foreach( $name_list as $single_name) |
960
|
|
|
{ |
961
|
|
|
$list = array_merge($list, contact_by_search($single_name)); |
962
|
|
|
$list = array_merge($list, lead_by_search($single_name)); |
963
|
|
|
$list = array_merge($list, account_by_search($single_name)); |
964
|
|
|
$list = array_merge($list, case_by_search($single_name)); |
965
|
|
|
$list = array_merge($list, opportunity_by_search($single_name)); |
966
|
|
|
$list = array_merge($list, bug_by_search($single_name)); |
967
|
|
|
} |
968
|
|
|
return $list; |
969
|
|
|
} |
970
|
|
|
|
971
|
|
|
?> |
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.