iTx Technologies offre gratuitement
cet espace pour SugarCRM !

title

Body

[fermer]

/soap/ -> SoapData.php (source)

   1  <?php
   2  if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
   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  require_once ('soap/SoapRelationshipHelper.php');
  38  set_time_limit(360);
  39   
  40  $server->register(
  41      'sync_get_modified_relationships',
  42      array('session'=>'xsd:string', 'module_name'=>'xsd:string','related_module'=>'xsd:string', 'from_date'=>'xsd:string', 'to_date'=>'xsd:string','offset'=>'xsd:int', 'max_results'=>'xsd:int','deleted'=>'xsd:int', 'module_id'=>'xsd:string', 'select_fields'=>'tns:select_fields', 'ids'=>'tns:select_fields', 'relationship_name'=>'xsd:string', 'deletion_date'=>'xsd:string', 'php_serialize'=>'xsd:int'),
  43      array('return'=>'tns:get_entry_list_result_encoded'),
  44      $NAMESPACE);
  45  
  46  
  47  
  48  /**
  49   * Get a list of the relationship records that have been modified within a 
  50   * specified date range.  This is used to perform a sync with a mobile client.
  51   * The results are paged.
  52   *
  53   * @param xsd:string $session
  54   * @param xsd:string $module_name
  55   * @param xsd:string $related_module
  56   * @param xsd:string $from_date
  57   * @param xsd:string $to_date
  58   * @param xsd:int $offset
  59   * @param xsd:int $max_results
  60   * @param xsd:int $deleted
  61   * @param xsd:int $module_id
  62   * @param tns:select_fields $select_fields
  63   * @param tns:select_fields $ids
  64   * @param xsd:string $relationship_name
  65   * @param xsd:string $deletion_date
  66   * @param xsd:int $php_serialize
  67   * @return 
  68   */
  69  function sync_get_modified_relationships($session, $module_name, $related_module,$from_date,$to_date,$offset, $max_results, $deleted, $module_id = '', $select_fields = array(), $ids = array(), $relationship_name = '', $deletion_date = '', $php_serialize = 1){
  70      global  $beanList, $beanFiles;
  71      $error = new SoapError();
  72      $output_list = array();
  73      if(!validate_authenticated($session)){
  74          $error->set_error('invalid_login');    
  75          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
  76      }
  77      if(empty($beanList[$module_name]) || empty($beanList[$related_module])){
  78          $error->set_error('no_module');    
  79          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
  80      }
  81      global $current_user;
  82      if(!check_modules_access($current_user, $module_name, 'read') || !check_modules_access($current_user, $related_module, 'read')){
  83          $error->set_error('no_access');    
  84          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
  85      }
  86      if($max_results > 0 || $max_results == '-99'){
  87          global $sugar_config;
  88          $sugar_config['list_max_entries_per_page'] = $max_results;    
  89      }
  90  
  91      $date_query = "(m1.date_modified > " . db_convert("'$from_date'", 'datetime'). " AND m1.date_modified <= ". db_convert("'$to_date'", 'datetime')." AND {0}.deleted = $deleted)";
  92      if(isset($deletion_date) && !empty($deletion_date)){
  93          $date_query .= " OR ({0}.date_modified > " . db_convert("'$deletion_date'", 'datetime'). " AND {0}.date_modified <= ". db_convert("'$to_date'", 'datetime')." AND {0}.deleted = 1)";
  94      }
  95  
  96      $in = '';
  97      if(isset($ids) && !empty($ids)){
  98          foreach($ids as $value){
  99              if(empty($in))
 100              {
 101                  $in .= "('" . $value . "'";    
 102              }
 103              else
 104              {
 105                  $in .= ",'" . $value . "'";    
 106              }
 107          }
 108          $in .=')';
 109      }
 110      $query = '';
 111      if(isset($in) && !empty($in)){
 112          $query .= "( $date_query AND m1.id IN $in) OR (m1.id NOT IN $in AND {0}.deleted = 0)";
 113      }
 114      else{
 115          $query .= "( {0}.deleted = 0)";
 116      }
 117      if(isset($module_id) && !empty($module_id)){
 118          //if(isset($in) && !empty($in)){
 119              $query .= " AND";
 120          //}
 121          $query .= " m2.id = '$module_id'";
 122      }
 123      if($related_module == 'Meetings' || $related_module == 'Calls'){
 124          $query = string_format($query, array('m1'));    
 125      }    
 126      $results = retrieve_modified_relationships($module_name,  $related_module, $query, $deleted, $offset, $max_results, $select_fields, $relationship_name);
 127  
 128      $list = $results['result'];
 129      
 130      $xml = '<?xml version="1.0" encoding="utf-8"?><items>';
 131      foreach($list as $value)
 132      {
 133          $val = array_get_return_value($value, $results['table_name']);
 134          if($php_serialize == 0){
 135              $xml .= get_name_value_xml($val, $module_name);
 136          }
 137          $output_list[] = $val;
 138      }
 139      $xml .= '</items>';
 140      $next_offset = $offset + sizeof($output_list);
 141      
 142      if($php_serialize == 0){
 143          $myoutput = base64_encode($xml);    
 144      }
 145      else{
 146          $myoutput = get_encoded($output_list);
 147      }
 148      
 149      return array('result_count'=>sizeof($output_list),'next_offset'=>0, 'total_count'=>sizeof($output_list), 'field_list'=>array(), 'entry_list'=>$myoutput , 'error'=>$error->get_soap_array());
 150  }
 151  
 152  
 153  $server->register(
 154      'get_modified_entries',
 155      array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'ids'=>'tns:select_fields', 'select_fields'=>'tns:select_fields'),
 156      array('return'=>'tns:get_sync_result_encoded'),
 157      $NAMESPACE);
 158  
 159  function get_modified_entries($session, $module_name, $ids, $select_fields ){
 160      global  $beanList, $beanFiles;
 161      $error = new SoapError();
 162      $field_list = array();
 163      $output_list = array();
 164      if(!validate_authenticated($session)){
 165          $error->set_error('invalid_login');    
 166          return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 167      }
 168      if(empty($beanList[$module_name])){
 169          $error->set_error('no_module');    
 170          return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 171      }
 172      global $current_user;
 173      if(!check_modules_access($current_user, $module_name, 'read')){
 174          $error->set_error('no_access');    
 175          return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 176      }
 177      
 178      $class_name = $beanList[$module_name];
 179      require_once($beanFiles[$class_name]);
 180      $seed = new $class_name();
 181      //rsmith
 182      $in = '';
 183      $field_select ='';
 184      
 185      $table_name = $seed->table_name;
 186      if(isset($ids)){
 187          foreach($ids as $value){
 188              if(empty($in))
 189              {
 190                  $in .= "('" . $value . "'";    
 191              }
 192              else
 193              {
 194                  $in .= ",'" . $value . "'";    
 195              }
 196          }//end foreach
 197      }
 198      $index = 0;
 199      foreach($select_fields as $field){
 200              $field_select .= $table_name.".".$field;
 201          
 202              if($index < (count($select_fields) - 1))
 203              {
 204                  $field_select .= ",";
 205                  $index++;
 206              }
 207          }//end foreach
 208      
 209          $ids = array();
 210      
 211      //end rsmith
 212      if(!empty($in)){
 213              $in .=')';    
 214      }
 215  
 216      $ret_array = $seed->create_new_list_query('', "$table_name.id IN $in", $select_fields, array(), -2, '', true, $seed, true);
 217      if(!is_array($params)) $params = array();
 218      if(!isset($params['custom_select'])) $params['custom_select'] = '';
 219      if(!isset($params['custom_from'])) $params['custom_from'] = '';
 220      if(!isset($params['custom_where'])) $params['custom_where'] = '';
 221      if(!isset($params['custom_order_by'])) $params['custom_order_by'] = '';
 222      $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
 223      $result = $seed->db->query($main_query);
 224  
 225      $xml = '<?xml version="1.0" encoding="utf-8"?><items>';
 226      while($row = $seed->db->fetchByAssoc($result))
 227      {
 228          if (version_compare(phpversion(), '5.0') < 0) {
 229              $temp = $seed;
 230          } else {
 231              $temp = @clone($seed);
 232          }
 233          $temp->setupCustomFields($temp->module_dir);
 234          $temp->loadFromRow($row);
 235          $temp->fill_in_additional_detail_fields();
 236          if(isset($temp->emailAddress)){
 237              $temp->emailAddress->handleLegacyRetrieve($temp);
 238          }
 239          $val = get_return_value($temp, $table_name);
 240          $xml .= get_name_value_xml($val, $module_name);    
 241      }
 242      $xml .= "</items>";
 243  
 244      $xml = base64_encode($xml);
 245      
 246      return array('result'=>$xml, 'error'=>$error->get_soap_array());
 247  }
 248  
 249  $server->register(
 250      'get_attendee_list',
 251      array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'id'=>'xsd:string'),
 252      array('return'=>'tns:get_sync_result_encoded'),
 253      $NAMESPACE);
 254  
 255  function get_attendee_list($session, $module_name, $id){
 256      global  $beanList, $beanFiles;
 257      $error = new SoapError();
 258      $field_list = array();
 259      $output_list = array();
 260      if(!validate_authenticated($session)){
 261          $error->set_error('invalid_login');    
 262          return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 263      }
 264      if(empty($beanList[$module_name])){
 265          $error->set_error('no_module');    
 266          return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 267      }
 268      global $current_user;
 269      if(!check_modules_access($current_user, $module_name, 'read')){
 270          $error->set_error('no_access');    
 271          return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 272      }
 273      
 274  
 275      $class_name = $beanList[$module_name];
 276      require_once($beanFiles[$class_name]);
 277      $seed = new $class_name();
 278      
 279      
 280              //rsmith
 281              $xml = '<?xml version="1.0" encoding="utf-8"?>';
 282              if($module_name == 'Meetings' || $module_name == 'Calls'){
 283                  //if we find a meeting or call we want to send back the attendees
 284                  $l_module_name = strtolower($module_name);
 285                  $table_name = $l_module_name."_users";
 286                  if($module_name == 'Meetings')
 287                      $join_field = "meeting";
 288                  else
 289                      $join_field = "call";
 290                  $xml .= '<attendees>';
 291                  $result = $seed->db->query("SELECT users.id, $table_name.date_modified, first_name, last_name FROM users INNER JOIN $table_name ON $table_name.user_id = users.id WHERE ".$table_name.".".$join_field."_id = '".$id."' AND $table_name.deleted = 0"); 
 292                  $user = new User();
 293                  while($row = $seed->db->fetchByAssoc($result))
 294                  {
 295                      $user->id = $row['id'];
 296                      $email = $user->emailAddress->getPrimaryAddress($user);
 297                      $xml .= '<attendee>';
 298                      $xml .= '<id>'.$user->id.'</id>';
 299                      $xml .= '<first_name>'.$row['first_name'].'</first_name>';
 300                      $xml .= '<last_name>'.$row['last_name'].'</last_name>';
 301                      $xml .= '<email1>'.$email.'</email1>';
 302                      $xml .= '</attendee>';
 303                  }    
 304                  //now get contacts
 305                  $table_name = $l_module_name."_contacts";
 306                  $result = $seed->db->query("SELECT contacts.id, $table_name.date_modified, first_name, last_name FROM contacts INNER JOIN $table_name ON $table_name.contact_id = contacts.id INNER JOIN $seed->table_name ON ".$seed->table_name.".id = ".$table_name.".".$join_field."_id WHERE ".$table_name.".".$join_field."_id = '".$id."' AND ".$table_name.".deleted = 0 AND (contacts.id != ".$seed->table_name.".parent_id OR ".$seed->table_name.".parent_id IS NULL)"); 
 307                  $contact = new Contact();
 308                  while($row = $seed->db->fetchByAssoc($result))
 309                  {
 310                      $contact->id = $row['id'];
 311                      $email = $contact->emailAddress->getPrimaryAddress($contact);
 312                      $xml .= '<attendee>';
 313                      $xml .= '<id>'.$contact->id.'</id>';
 314                      $xml .= '<first_name>'.$row['first_name'].'</first_name>';
 315                      $xml .= '<last_name>'.$row['last_name'].'</last_name>';
 316                      $xml .= '<email1>'.$email.'</email1>';
 317                      $xml .= '</attendee>';
 318                  }                    
 319                  $xml .= '</attendees>';
 320              }
 321      $xml = base64_encode($xml);
 322      return array('result'=>$xml, 'error'=>$error->get_soap_array());
 323  }
 324  ?>


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