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