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