iTx Technologies offre gratuitement
cet espace pour SugarCRM !

title

Body

[fermer]

/soap/ -> SoapDeprecated.php (source)

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


Generé en: Thu Mar 4 09:44:50 2010 | Cross-referenced par PHPXref 0.7