]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - soap/SoapDeprecated.php
Release 6.1.4
[Github/sugarcrm.git] / soap / SoapDeprecated.php
1 <?php
2  if(!defined('sugarEntry'))define('sugarEntry', true);
3 /*********************************************************************************
4  * SugarCRM 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
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                         return true;
231                 }
232         }else{
233                 $GLOBALS['log']->fatal("SECURITY: failed attempted login for $user_name using SOAP api");
234                 $server->setError("Invalid username and/or password");
235                 return false;
236         }
237
238 }
239
240 /**
241  * Internal: When building a response to the plug-in for Microsoft Outlook, find
242  * all contacts that match the email address that was provided.
243  *
244  * @param array by ref $output_list -- The list of matching beans.  New contacts that match
245  *   the email address are appended to the $output_list
246  * @param string $email_address -- an email address to search for
247  * @param Contact $seed_contact -- A template SugarBean.  This is a blank Contact
248  * @param ID $msi_id -- Index Count
249  */
250 function add_contacts_matching_email_address(&$output_list, $email_address, &$seed_contact, &$msi_id)
251 {
252     // escape the email address
253         $safe_email_address = addslashes($email_address);
254         global $current_user;
255
256         // Verify that the user has permission to see Contact list views
257         if(!$seed_contact->ACLAccess('ListView'))
258         {
259                 return;
260         }
261
262         $contactList = $seed_contact->emailAddress->getBeansByEmailAddress($safe_email_address);
263         // create a return array of names and email addresses.
264         foreach($contactList as $contact)
265         {
266                 $output_list[] = Array("name1"  => $contact->first_name,
267                         "name2" => $contact->last_name,
268                         "association" => $contact->account_name,
269                         "type" => 'Contact',
270                         "id" => $contact->id,
271                         "msi_id" => $msi_id,
272                         "email_address" => $contact->email1);
273
274         $accounts = $contact->get_linked_beans('accounts','Account');
275                 foreach($accounts as $account)
276                 {
277                         $output_list[] = get_account_array($account, $msi_id);
278                 }
279
280         $opps = $contact->get_linked_beans('opportunities','Opportunity');
281                 foreach($opps as $opp)
282                 {
283                         $output_list[] = get_opportunity_array($opp, $msi_id);
284                 }
285
286         $cases = $contact->get_linked_beans('cases','aCase');
287                 foreach($cases as $case)
288                 {
289                         $output_list[] = get_case_array($case, $msi_id);
290                 }
291
292                 $bugs = $contact->get_linked_beans('bugs','Bug');
293                 foreach($bugs as $bug)
294                 {
295                         $output_list[] = get_bean_array($bug, $msi_id, 'Bug');
296                 }
297
298                 $projects = $contact->get_linked_beans('project','Project');
299                 foreach($projects as $project)
300                 {
301                         $output_list[] = get_bean_array($project, $msi_id, 'Project');
302                 }
303
304                 $msi_id = $msi_id + 1;
305         }
306 }
307 /**
308  * Internal: Add Leads that match the specified email address to the result array
309  *
310  * @param Array $output_list -- List of matching detail records
311  * @param String $email_address -- Email address
312  * @param Bean $seed_lead -- Seed Lead Bean
313  * @param int $msi_id -- output array offset.
314  */
315 function add_leads_matching_email_address(&$output_list, $email_address, &$seed_lead, &$msi_id)
316 {
317         $safe_email_address = addslashes($email_address);
318         if(!$seed_lead->ACLAccess('ListView')){
319                 return;
320         }
321
322         $leadList = $seed_lead->emailAddress->getBeansByEmailAddress($safe_email_address);
323
324         // create a return array of names and email addresses.
325         foreach($leadList as $lead)
326         {
327                 $output_list[] = Array("name1"  => $lead->first_name,
328                         "name2" => $lead->last_name,
329                         "association" => $lead->account_name,
330                         "type" => 'Lead',
331                         "id" => $lead->id,
332                         "msi_id" => $msi_id,
333                         "email_address" => $lead->email1);
334
335                 $msi_id = $msi_id + 1;
336         }
337 }
338 /**
339  * Return a list of modules related to the specifed contact record
340  *
341  * This function does not require a session be created first.
342  *
343  * @param string $user_name -- User name to authenticate with
344  * @param string $password -- MD5 of the user password
345  * @param string $id -- the id of the record
346  * @return contact detail array along with associated objects.
347  */
348 function get_contact_relationships($user_name, $password, $id)
349 {
350         if(!validate_user($user_name, $password)){
351                 return array();
352         }
353
354         $seed_contact = new Contact();
355         // Verify that the user has permission to see Contact list views
356         if(!$seed_contact->ACLAccess('ListView'))
357         {
358                 return;
359         }
360
361         $msi_id = 1;
362         $seed_contact->retrieve($id);
363
364         $output_list[] = Array("name1"  => $seed_contact->first_name,
365                         "name2" => $seed_contact->last_name,
366                         "association" => $seed_contact->account_name,
367                         "type" => 'Contact',
368                         "id" => $seed_contact->id,
369                         "msi_id" => $msi_id,
370                         "email_address" => $seed_contact->email1);
371
372         $accounts = $seed_contact->get_linked_beans('accounts','Account');
373                 foreach($accounts as $account)
374                 {
375                         $output_list[] = get_account_array($account, $msi_id);
376                 }
377
378         $opps = $seed_contact->get_linked_beans('opportunities','Opportunity');
379                 foreach($opps as $opp)
380                 {
381                         $output_list[] = get_opportunity_array($opp, $msi_id);
382                 }
383
384         $cases = $seed_contact->get_linked_beans('cases','aCase');
385                 foreach($cases as $case)
386                 {
387                         $output_list[] = get_case_array($case, $msi_id);
388                 }
389
390                 $bugs = $seed_contact->get_linked_beans('bugs','Bug');
391                 foreach($bugs as $bug)
392                 {
393                         $output_list[] = get_bean_array($bug, $msi_id, 'Bug');
394                 }
395
396                 $projects = $seed_contact->get_linked_beans('project','Project');
397                 foreach($projects as $project)
398                 {
399                         $output_list[] = get_bean_array($project, $msi_id, 'Project');
400                 }
401                 return $output_list;
402 }
403
404 // Define a global current user
405 $current_user = null;
406
407 /**
408  * Return a list of contact and lead detail records based on a single email
409  * address or a  list of email addresses separated by '; '.
410  *
411  * This function does not require a session be created first.
412  *
413  * @param string $user_name -- User name to authenticate with
414  * @param string $password -- MD5 of the user password
415  * @param string $email_address -- Single email address or '; ' separated list of email addresses (e.x "test@example.com; test2@example.com"
416  * @return contact detail array along with associated objects.
417  */
418 function contact_by_email($user_name, $password, $email_address)
419 {
420         if(!validate_user($user_name, $password)){
421                 return array();
422         }
423
424         $seed_contact = new Contact();
425         $seed_lead = new Lead();
426         $output_list = Array();
427         $email_address_list = explode("; ", $email_address);
428
429         // remove duplicate email addresses
430         $non_duplicate_email_address_list = Array();
431         foreach( $email_address_list as $single_address)
432         {
433                 // Check to see if the current address is a match of an existing address
434                 $found_match = false;
435                 foreach( $non_duplicate_email_address_list as $non_dupe_single)
436                 {
437                         if(strtolower($single_address) == $non_dupe_single)
438                         {
439                                 $found_match = true;
440                                 break;
441                         }
442                 }
443
444                 if($found_match == false)
445                 {
446                         $non_duplicate_email_address_list[] = strtolower($single_address);
447                 }
448         }
449
450         // now copy over the non-duplicated list as the original list.
451         $email_address_list =$non_duplicate_email_address_list;
452
453         // Track the msi_id
454         $msi_id = 1;
455
456         foreach( $email_address_list as $single_address)
457         {
458             // verify that contacts can be listed
459                 if($seed_contact->ACLAccess('ListView')){
460                         add_contacts_matching_email_address($output_list, $single_address, $seed_contact, $msi_id);
461                 }
462             // verify that leads can be listed
463                 if($seed_lead->ACLAccess('ListView')){
464                         add_leads_matching_email_address($output_list, $single_address, $seed_lead, $msi_id);
465                 }
466         }
467
468         return $output_list;
469 }
470
471 /**
472  * Internal: convert a bean into an array
473  *
474  * @param Bean $bean -- The bean to convert
475  * @param int $msi_id -- Russult array index
476  * @return An associated array containing the detail fields.
477  */
478 function get_contact_array($contact, $msi_id = '0'){
479          $contact->emailAddress->handleLegacyRetrieve($contact);
480          return Array("name1"   => $contact->first_name,
481                         "name2" => $contact->last_name,
482                         "association" => $contact->account_name,
483                         "type" => 'Contact',
484                         "id" => $contact->id,
485                         "msi_id" => $msi_id,
486                         "email_address" => $contact->email1);
487
488 }
489
490 /**
491  * Internal: Convert a user into an array
492  *
493  * @param User $user -- The user to convert
494  * @return An associated array containing the detail fields.
495  */
496 function get_user_list_array($user) {
497     return Array('email_address' => $user->email1,
498         'user_name' => $user->user_name,
499         'first_name' => $user->first_name,
500         'last_name' => $user->last_name,
501         'department' => $user->department,
502         'id' => $user->id,
503         'title' => $user->title);
504 }
505
506 /**
507  * Get a full user list.
508  *
509  * This function does not require a session be created first.
510  *
511  * @param string $user -- user name for validation
512  * @param password $password -- MD5 hash of the user password for validation
513  * @return User Array -- An array of user detail records
514  */
515 function user_list($user, $password) {
516         if(!validate_user($user, $password)){
517                 return array();
518         }
519
520     $seed_user = new User();
521     $output_list = Array();
522         if(!$seed_user->ACLAccess('ListView')){
523                 return $output_list;
524         }
525     $userList = $seed_user->get_full_list();
526
527
528     foreach($userList as $user) {
529         $output_list[] = get_user_list_array($user);
530     }
531
532     return $output_list;
533 }
534
535 /**
536  * Internal: Search for contacts based on the specified name and where clause.
537  * Currently only the name is used.
538  *
539  * @param string $name -- Name to search for.
540  * @param string $where -- Where clause defaults to ''
541  * @param int $msi_id -- Response array index
542  * @return array -- Resturns a list of contacts that have the provided name.
543  */
544 function contact_by_search($name, $where = '', $msi_id = '0')
545 {
546         $seed_contact = new Contact();
547         if($where == ''){
548                 $where = $seed_contact->build_generic_where_clause($name);
549         }
550         if(!$seed_contact->ACLAccess('ListView')){
551                 return array();
552         }
553         $response = $seed_contact->get_list("last_name, first_name", $where, 0);
554         $contactList = $response['list'];
555
556         $output_list = Array();
557
558         // create a return array of names and email addresses.
559         foreach($contactList as $contact)
560         {
561                 $output_list[] = get_contact_array($contact, $msi_id);
562         }
563         return $output_list;
564 }
565 /**
566  * Internal: convert a bean into an array
567  *
568  * @param Bean $bean -- The bean to convert
569  * @param int $msi_id -- Russult array index
570  * @return An associated array containing the detail fields.
571  */
572 function get_lead_array($lead, $msi_id = '0'){
573          $lead->emailAddress->handleLegacyRetrieve($lead);
574          return Array("name1"   => $lead->first_name,
575                         "name2" => $lead->last_name,
576                         "association" => $lead->account_name,
577                         "type" => 'Lead',
578                         "id" => $lead->id,
579                         "msi_id" => $msi_id,
580                         "email_address" => $lead->email1);
581 }
582
583 function lead_by_search($name, $where = '', $msi_id = '0')
584 {
585         $seed_lead = new Lead();
586         if($where == ''){
587                 $where = $seed_lead->build_generic_where_clause($name);
588         }
589         if(!$seed_lead->ACLAccess('ListView')){
590                 return array();
591         }
592         $response = $seed_lead->get_list("last_name, first_name", $where, 0);
593         $lead_list = $response['list'];
594
595         $output_list = Array();
596
597         // create a return array of names and email addresses.
598         foreach($lead_list as $lead)
599         {
600                 $output_list[] = get_lead_array($lead, $msi_id);
601         }
602         return $output_list;
603 }
604 /**
605  * Internal: convert a bean into an array
606  *
607  * @param Bean $bean -- The bean to convert
608  * @param int $msi_id -- Russult array index
609  * @return An associated array containing the detail fields.
610  */
611 function get_account_array($account, $msi_id){
612         return Array("name1"    => '',
613                         "name2" => $account->name,
614                         "association" => $account->billing_address_city,
615                         "type" => 'Account',
616                         "id" => $account->id,
617                         "msi_id" => $msi_id,
618                         "email_address" => $account->email1);
619 }
620
621 function account_by_search($name, $where = '', $msi_id = '0')
622 {
623         $seed_account = new Account();
624         if(!$seed_account->ACLAccess('ListView')){
625                 return array();
626         }
627         if($where == ''){
628                 $where = $seed_account->build_generic_where_clause($name);
629         }
630         $response = $seed_account->get_list("name", $where, 0);
631         $accountList = $response['list'];
632
633         $output_list = Array();
634
635         // create a return array of names and email addresses.
636         foreach($accountList as $account)
637         {
638                 $output_list[] = get_account_array($account, $msi_id);
639         }
640         return $output_list;
641 }
642
643 /**
644  * Internal: convert a bean into an array
645  *
646  * @param Bean $bean -- The bean to convert
647  * @param int $msi_id -- Russult array index
648  * @return An associated array containing the detail fields.
649  */
650 function get_opportunity_array($value, $msi_id = '0'){
651                 return  Array("name1"   => '',
652                         "name2" => $value->name,
653                         "association" => $value->account_name,
654                         "type" => 'Opportunity',
655                         "id" => $value->id,
656                         "msi_id" => $msi_id,
657                         "email_address" => '');
658
659 }
660
661 function opportunity_by_search($name, $where = '', $msi_id = '0')
662 {
663         $seed = new Opportunity();
664         if(!$seed->ACLAccess('ListView')){
665                 return array();
666         }
667         if($where == ''){
668                 $where = $seed->build_generic_where_clause($name);
669         }
670         $response = $seed->get_list("name", $where, 0);
671         $list = $response['list'];
672
673         $output_list = Array();
674
675         // create a return array of names and email addresses.
676         foreach($list as $value)
677         {
678                 $output_list[] = get_opportunity_array($value, $msi_id);
679         }
680         return $output_list;
681 }
682
683 /**
684  * Internal: convert a bean into an array
685  *
686  * @param Bean $bean -- The bean to convert
687  * @param int $msi_id -- Russult array index
688  * @return An associated array containing the detail fields.
689  */
690 function get_bean_array($value, $msi_id, $type){
691         return Array("name1" => '',
692                         "name2" => $value->get_summary_text(),
693                         "association" => '',
694                         "type" => $type,
695                         "id" => $value->id,
696                         "msi_id" => $msi_id,
697                         "email_address" => '');
698
699 }
700 /**
701  * Internal: convert a bean into an array
702  *
703  * @param Bean $bean -- The bean to convert
704  * @param int $msi_id -- Russult array index
705  * @return An associated array containing the detail fields.
706  */
707 function get_case_array($value, $msi_id){
708         return Array("name1" => '',
709                         "name2" => $value->get_summary_text(),
710                         "association" => $value->account_name,
711                         "type" => 'Case',
712                         "id" => $value->id,
713                         "msi_id" => $msi_id,
714                         "email_address" => '');
715
716 }
717
718 function bug_by_search($name, $where = '', $msi_id='0')
719 {
720         $seed = new Bug();
721         if(!$seed->ACLAccess('ListView')){
722                 return array();
723         }
724         if($where == ''){
725                 $where = $seed->build_generic_where_clause($name);
726         }
727         $response = $seed->get_list("name", $where, 0);
728         $list = $response['list'];
729
730         $output_list = Array();
731
732         // create a return array of names and email addresses.
733         foreach($list as $value)
734         {
735                 $output_list[] = get_bean_array($value, $msi_id, 'Bug');
736         }
737         return $output_list;
738 }
739
740 function case_by_search($name, $where = '', $msi_id='0')
741 {
742         $seed = new aCase();
743         if(!$seed->ACLAccess('ListView')){
744                 return array();
745         }
746         if($where == ''){
747                 $where = $seed->build_generic_where_clause($name);
748         }
749         $response = $seed->get_list("name", $where, 0);
750         $list = $response['list'];
751
752         $output_list = Array();
753
754         // create a return array of names and email addresses.
755         foreach($list as $value)
756         {
757                 $output_list[] = get_case_array($value, $msi_id);
758         }
759         return $output_list;
760 }
761 /**
762  * Record and email message and associated it with the specified parent bean and contact ids.
763  *
764  * This function does not require a session be created first.
765  *
766  * @param string $user_name -- Name of the user to authenticate
767  * @param string $password -- MD5 hash of the user password for authentication
768  * @param id $parent_id -- [optional] The parent record to link the email to.
769  * @param unknown_type $contact_ids
770  * @param string $date_sent -- Date/time the email was sent in Visual Basic Date format. (e.g. '7/22/2004 9:36:31 AM')
771  * @param string $email_subject -- The subject of the email
772  * @param string $email_body -- The body of the email
773  * @return "Invalid username and/or password"
774  * @return -1 If the authenticated user does not have ACL access to save Email.
775  */
776 function track_email($user_name, $password,$parent_id, $contact_ids, $date_sent, $email_subject, $email_body)
777 {
778         if(!validate_user($user_name, $password)){
779                 return "Invalid username and/or password";
780         }
781         global $current_user;
782
783         $GLOBALS['log']->info("In track email: username: $user_name contacts: $contact_ids date_sent: $date_sent");
784
785         // translate date sent from VB format 7/22/2004 9:36:31 AM
786         // to yyyy-mm-dd 9:36:31 AM
787
788         $date_sent = preg_replace("@([0-9]*)/([0-9]*)/([0-9]*)( .*$)@", "\\3-\\1-\\2\\4", $date_sent);
789
790         
791         $seed_user = new User();
792
793         $user_id = $seed_user->retrieve_user_id($user_name);
794         $seed_user->retrieve($user_id);
795         $current_user = $seed_user;
796         
797
798         $email = new Email();
799         if(!$email->ACLAccess('Save')){
800                 return -1;
801         }
802         $email->description = $email_body;
803         $email->name = $email_subject;
804         $email->user_id = $user_id;
805         $email->assigned_user_id = $user_id;
806         $email->assigned_user_name = $user_name;
807         $email->date_start = $date_sent;
808
809         // Save one copy of the email message
810         $parent_id_list = explode(";", $parent_id);
811         $parent_id = explode(':', $parent_id_list[0]);
812
813         // Having a parent object is optional.  If it is set, then associate it.
814         if(isset($parent_id[0]) && isset($parent_id[1]))
815         {
816                 $email->parent_type = $parent_id[0];
817                 $email->parent_id = $parent_id[1];
818         }
819
820         $email->save();
821         // for each contact, add a link between the contact and the email message
822         $id_list = explode(";", $contact_ids);
823
824         foreach( $id_list as $id)
825         {
826                 if(!empty($id))
827                 $email->set_emails_contact_invitee_relationship($email->id, $id);
828         }
829
830         return "Succeeded";
831 }
832
833 function create_contact($user_name,$password, $first_name, $last_name, $email_address)
834 {
835         if(!validate_user($user_name, $password)){
836                 return 0;
837         }
838
839         
840         $seed_user = new User();
841         $user_id = $seed_user->retrieve_user_id($user_name);
842         $seed_user->retrieve($user_id);
843
844         
845         $contact = new Contact();
846         if(!$contact->ACLAccess('Save')){
847                 return -1;
848         }
849         $contact->first_name = $first_name;
850         $contact->last_name = $last_name;
851         $contact->email1 = $email_address;
852         $contact->assigned_user_id = $user_id;
853         $contact->assigned_user_name = $user_name;
854         return $contact->save();
855 }
856 function create_lead($user_name,$password, $first_name, $last_name, $email_address)
857 {
858         if(!validate_user($user_name, $password)){
859                 return 0;
860         }
861
862         //todo make the activity body not be html encoded
863
864         
865         $seed_user = new User();
866         $user_id = $seed_user->retrieve_user_id($user_name);
867
868         
869         $lead = new Lead();
870         if(!$lead->ACLAccess('Save')){
871                 return -1;
872         }
873         $lead->first_name = $first_name;
874         $lead->last_name = $last_name;
875         $lead->email1 = $email_address;
876         $lead->assigned_user_id = $user_id;
877         $lead->assigned_user_name = $user_name;
878         return $lead->save();
879 }
880 function create_account($user_name,$password, $name, $phone, $website)
881 {
882         if(!validate_user($user_name, $password)){
883                 return 0;
884         }
885
886         //todo make the activity body not be html encoded
887
888         
889         $seed_user = new User();
890         $user_id = $seed_user->retrieve_user_id($user_name);
891         $account = new Account();
892         if(!$account->ACLAccess('Save')){
893                 return -1;
894         }
895         $account->name = $name;
896         $account->phone_office = $phone;
897         $account->website = $website;
898         $account->assigned_user_id = $user_id;
899         $account->assigned_user_name = $user_name;
900         $account->save();
901         return $account->id;
902
903 }
904 function create_case($user_name,$password, $name)
905 {
906         if(!validate_user($user_name, $password)){
907                 return 0;
908         }
909
910         //todo make the activity body not be html encoded
911
912         
913         $seed_user = new User();
914         $user_id = $seed_user->retrieve_user_id($user_name);
915         $case = new aCase();
916         if(!$case->ACLAccess('Save')){
917                 return -1;
918         }
919         $case->assigned_user_id = $user_id;
920         $case->assigned_user_name = $user_name;
921         $case->name = $name;
922         return $case->save();
923 }
924 function create_opportunity($user_name,$password, $name, $amount)
925 {
926         if(!validate_user($user_name, $password)){
927                 return 0;
928         }
929
930         
931         $seed_user = new User();
932         $user_id = $seed_user->retrieve_user_id($user_name);
933         $opp = new Opportunity();
934         if(!$opp->ACLAccess('Save')){
935                 return -1;
936         }
937         $opp->name = $name;
938         $opp->amount = $amount;
939         $opp->assigned_user_id = $user_id;
940         $opp->assigned_user_name = $user_name;
941         return $opp->save();
942 }
943
944 function search($user_name, $password,$name){
945         if(!validate_user($user_name, $password)){
946                 return array();
947         }
948     $name_list = explode("; ", $name);
949     $list = array();
950         foreach( $name_list as $single_name)
951         {
952             $list = array_merge($list, contact_by_search($single_name));
953             $list = array_merge($list, lead_by_search($single_name));
954             $list = array_merge($list, account_by_search($single_name));
955             $list = array_merge($list, case_by_search($single_name));
956             $list = array_merge($list, opportunity_by_search($single_name));
957             $list = array_merge($list, bug_by_search($single_name));
958     }
959         return $list;
960 }
961
962 ?>