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