iTx Technologies offre gratuitement
cet espace pour SugarCRM !

title

Body

[fermer]

/soap/ -> SoapPortalUsers.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  
  38  require_once ('soap/SoapHelperFunctions.php');
  39  require_once ('soap/SoapTypes.php');
  40  
  41  
  42  require_once ('soap/SoapPortalHelper.php');
  43  
  44  
  45  
  46  
  47  
  48  
  49  
  50  
  51  /*************************************************************************************
  52  
  53  THIS IS FOR PORTAL USERS
  54  
  55  
  56  *************************************************************************************/
  57  /*
  58  this authenticates a user as a portal user and returns the session id or it returns false otherwise;
  59  */
  60  $server->register(
  61          'portal_login',
  62          array('portal_auth'=>'tns:user_auth','user_name'=>'xsd:string', 'application_name'=>'xsd:string'),
  63          array('return'=>'tns:set_entry_result'),
  64          $NAMESPACE);
  65  
  66  function portal_login($portal_auth, $user_name, $application_name){
  67      $error = new SoapError();
  68      $contact = new Contact();
  69      $result = login_user($portal_auth);
  70  
  71      if($result == 'fail' || $result == 'sessions_exceeded'){
  72          if($result == 'sessions_exceeded') {
  73              $error->set_error('sessions_exceeded');
  74          }
  75          else {
  76              $error->set_error('no_portal');
  77          }
  78          return array('id'=>-1, 'error'=>$error->get_soap_array());
  79      }
  80      global $current_user;
  81  
  82  
  83  
  84  
  85      if($user_name == 'lead'){
  86          session_start();
  87          $_SESSION['is_valid_session']= true;
  88          $_SESSION['ip_address'] = query_client_ip();
  89          $_SESSION['portal_id'] = $current_user->id;
  90          $_SESSION['type'] = 'lead';
  91  
  92  
  93  
  94  
  95  
  96  
  97          login_success();
  98          return array('id'=>session_id(), 'error'=>$error->get_soap_array());
  99      }else if($user_name == 'portal'){
 100          session_start();
 101          $_SESSION['is_valid_session']= true;
 102          $_SESSION['ip_address'] = query_client_ip();
 103          $_SESSION['portal_id'] = $current_user->id;
 104          $_SESSION['type'] = 'portal';
 105  
 106  
 107  
 108  
 109  
 110  
 111          $GLOBALS['log']->debug("Saving new session");
 112          login_success();
 113          return array('id'=>session_id(), 'error'=>$error->get_soap_array());
 114      }else{
 115      $contact = $contact->retrieve_by_string_fields(array('portal_name'=>$user_name, 'portal_active'=>'1', 'deleted'=>0) );
 116      if($contact != null){
 117          session_start();
 118          $_SESSION['is_valid_session']= true;
 119          $_SESSION['ip_address'] = query_client_ip();
 120          $_SESSION['user_id'] = $contact->id;
 121          $_SESSION['portal_id'] = $current_user->id;
 122  
 123          $_SESSION['type'] = 'contact';
 124  
 125  
 126  
 127  
 128          $_SESSION['assigned_user_id'] = $contact->assigned_user_id;
 129  
 130  
 131  
 132  
 133  
 134  
 135          login_success();
 136          build_relationship_tree($contact);
 137          return array('id'=>session_id(), 'error'=>$error->get_soap_array());
 138      }
 139      }
 140      $error->set_error('invalid_login');
 141      return array('id'=>-1, 'error'=>$error->get_soap_array());
 142  }
 143  
 144  
 145  
 146  
 147  
 148  
 149  
 150  
 151  
 152  
 153  
 154  
 155  
 156  
 157  
 158  
 159  
 160  
 161  
 162  
 163  
 164  
 165  
 166  
 167  
 168  
 169  
 170  
 171  
 172  
 173  
 174  
 175  
 176  
 177  
 178  
 179  
 180  
 181  
 182  
 183  
 184  
 185  
 186  
 187  
 188  
 189  
 190  
 191  
 192  
 193  
 194  
 195  
 196  
 197  /*
 198  this validates the session and starts the session;
 199  */
 200  function portal_validate_authenticated($session_id){
 201      $old_error_reporting = error_reporting(0);
 202      session_id($session_id);
 203  
 204      // This little construct checks to see if the session validated
 205      if(session_start()) {
 206          $valid_session = true;
 207  
 208  
 209  
 210          if(!empty($_SESSION['is_valid_session']) && $_SESSION['ip_address'] == query_client_ip() && $valid_session != null && ($_SESSION['type'] == 'contact' || $_SESSION['type'] == 'lead' || $_SESSION['type'] == 'portal')){
 211              global $current_user;
 212  
 213  
 214  
 215  
 216              $current_user = new User();
 217              $current_user->retrieve($_SESSION['portal_id']);
 218              login_success();
 219              error_reporting($old_error_reporting);
 220              return true;
 221          }
 222      }
 223      session_destroy();
 224      $GLOBALS['log']->fatal('SECURITY: The session ID is invalid');
 225      error_reporting($old_error_reporting);
 226      return false;
 227  }
 228  
 229  
 230  $server->register(
 231          'portal_logout',
 232          array('session'=>'xsd:string'),
 233          array('return'=>'tns:error_value'),
 234          $NAMESPACE);
 235  function portal_logout($session){
 236      $error = new SoapError();
 237      if(portal_validate_authenticated($session)){
 238  
 239  
 240  
 241  
 242          session_destroy();
 243          return $error->get_soap_array();
 244      }
 245      $error->set_error('invalid_session');
 246      return $error->get_soap_array();
 247  }
 248  
 249  $server->register(
 250          'portal_get_sugar_id',
 251          array('session'=>'xsd:string'),
 252          array('return'=>'tns:set_entry_result'),
 253          $NAMESPACE);
 254  function portal_get_sugar_id($session){
 255      $error = new SoapError();
 256      if(portal_validate_authenticated($session)){
 257          return array('id'=>$_SESSION['portal_id'], 'error'=>$error->get_soap_array());
 258      }
 259      $error->set_error('invalid_session');
 260      return array('id'=>-1, 'error'=>$error->get_soap_array());
 261  
 262  }
 263  
 264  $server->register(
 265          'portal_get_sugar_contact_id',
 266          array('session'=>'xsd:string'),
 267          array('return'=>'tns:set_entry_result'),
 268          $NAMESPACE);
 269  function portal_get_sugar_contact_id($session){
 270      $error = new SoapError();
 271      if(portal_validate_authenticated($session)){
 272          return array('id'=>$_SESSION['user_id'], 'error'=>$error->get_soap_array());
 273      }
 274      $error->set_error('invalid_session');
 275      return array('id'=>-1, 'error'=>$error->get_soap_array());
 276  
 277  }
 278  
 279  
 280  $server->register(
 281      'portal_get_entry_list',
 282      array('session'=>'xsd:string', 'module_name'=>'xsd:string','where'=>'xsd:string', 'order_by'=>'xsd:string', 'select_fields'=>'tns:select_fields'),
 283      array('return'=>'tns:get_entry_list_result'),
 284      $NAMESPACE);
 285  
 286  function portal_get_entry_list($session, $module_name,$where, $order_by, $select_fields){
 287      return portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, 0, "");
 288  }
 289  
 290  /*
 291   * Acts like a normal get_entry_list except it will build the where clause based on the name_value pairs passed
 292   * Here we assume 'AND'
 293   */
 294  $server->register(
 295      'portal_get_entry_list_filter',
 296      array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'order_by'=>'xsd:string', 'select_fields'=>'tns:select_fields', 'row_offset' => 'xsd:int', 'limit'=>'xsd:int', 'filter' =>'tns:name_value_operator_list'),
 297      array('return'=>'tns:get_entry_list_result'),
 298      $NAMESPACE);
 299  
 300  
 301  function portal_get_entry_list_filter($session, $module_name, $order_by, $select_fields, $row_offset, $limit, $filter){
 302      global  $beanList, $beanFiles, $portal_modules;
 303      $error = new SoapError();
 304      if(! portal_validate_authenticated($session)){
 305          $error->set_error('invalid_session');
 306          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 307      }
 308      if($_SESSION['type'] == 'lead'){
 309          $error->set_error('no_access');
 310          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 311      }
 312      if(empty($beanList[$module_name])){
 313          $error->set_error('no_module');
 314          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 315      }
 316  
 317      //build the where clause
 318  
 319      $sugar = null;
 320      if($module_name == 'Cases'){
 321          $sugar = new aCase();
 322      }else if($module_name == 'Contacts'){
 323          $sugar = new Contact();
 324      }else if($module_name == 'Accounts'){
 325          $sugar = new Account();
 326      }else if($module_name == 'Bugs'){
 327          $sugar = new Bug();
 328      } else if($module_name == 'KBDocuments' || $module_name == 'FAQ') {
 329          $sugar = new KBDocument();
 330      } else {
 331          $error->set_error('no_module_support');
 332          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 333      }
 334  
 335      if($sugar != null){
 336          if(isset($filter) && is_array($filter)){
 337              $where = "";
 338              foreach($filter as $nvOp){
 339                  $name = $nvOp['name'];
 340                  $value = $nvOp['value'];
 341                  $value_array = $nvOp['value_array'];
 342                  $operator = $nvOp['operator'];
 343                  //do nothing if all three values are not set
 344                  if(isset($name) && (isset($value) || isset($value_array)) && isset($operator)){
 345                      if(!empty($where)){
 346                          $where .= ' AND ';
 347                      }
 348                      if(isset($sugar->field_defs[$name])){
 349                          // MFH - Added Support For Custom Fields in Searches
 350                          $cstm = isset($sugar->field_defs[$name]['source']) && $sugar->field_defs[$name]['source'] == 'custom_fields' ? '_cstm' : '';
 351  
 352                          $where .=  "$sugar->table_name$cstm.$name $operator ";
 353                          if($sugar->field_defs['name']['type'] == 'datetime'){
 354                              $where .= db_convert("'$value'", 'datetime');
 355                          }else{
 356                              if(empty($value)) {
 357                                  $tmp = array();
 358                                  foreach($value_array as $v) {
 359                                      $tmp[] = $GLOBALS['db']->quote($v);
 360                                  }
 361                                  $where .= "('" . implode("', '", $tmp) . "')";
 362                              } else {
 363                                  $where .= "'".$GLOBALS['db']->quote($value)."'";
 364                              }
 365                          }
 366                      }
 367                  }
 368              }
 369          }
 370          return portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, $row_offset, $limit);
 371      }else{
 372          $error->set_error('no_module_support');
 373          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 374      }
 375  }
 376  
 377  
 378  $server->register(
 379      'portal_get_entry',
 380      array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'id'=>'xsd:string', 'select_fields'=>'tns:select_fields'),
 381      array('return'=>'tns:get_entry_result'),
 382      $NAMESPACE);
 383  
 384  function portal_get_entry($session, $module_name, $id,$select_fields ){
 385      global  $beanList, $beanFiles;
 386      $error = new SoapError();
 387      if(!portal_validate_authenticated($session)){
 388          $error->set_error('invalid_session');
 389          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 390      }
 391      if($_SESSION['type'] == 'lead'){
 392          $error->set_error('no_access');
 393          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 394      }
 395      if(empty($beanList[$module_name])){
 396          $error->set_error('no_module');
 397          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 398      }
 399  
 400      if(empty($_SESSION['viewable'][$module_name][$id])){
 401          $error->set_error('no_access');
 402          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 403      }
 404  
 405      $class_name = $beanList[$module_name];
 406      require_once($beanFiles[$class_name]);
 407      $seed = new $class_name();
 408  
 409  
 410  
 411      $seed->retrieve($id);
 412      if($module_name == 'KBDocuments') {
 413         $body = $seed->get_kbdoc_body($id);
 414         $seed->description = $body;
 415      }
 416  
 417      $output_list = Array();
 418      $output_list[] = get_return_value($seed, $module_name);
 419  
 420      //$output_list[0]['name_value_list']['description'] = array('name'=>'description', 'value'=>$seed->description);
 421      //$output_list = filter_return_list($output_list, $select_fields, $module_name);
 422      $field_list = array();
 423      if(empty($field_list)){
 424         $field_list = get_field_list($seed, true);
 425      }
 426      $output_list = filter_return_list($output_list, $select_fields, $module_name);
 427      $field_list = filter_field_list($field_list,$select_fields, $module_name);
 428  
 429      return array('field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
 430  }
 431  
 432  
 433  $server->register(
 434      'portal_set_entry',
 435      array('session'=>'xsd:string', 'module_name'=>'xsd:string',  'name_value_list'=>'tns:name_value_list'),
 436      array('return'=>'tns:set_entry_result'),
 437      $NAMESPACE);
 438  
 439  function portal_set_entry($session,$module_name, $name_value_list){
 440      global  $beanList, $beanFiles, $valid_modules_for_contact;
 441  
 442      $error = new SoapError();
 443      if(!portal_validate_authenticated($session)){
 444          $error->set_error('invalid_session');
 445          return array('id'=>-1,  'error'=>$error->get_soap_array());
 446      }
 447      if(empty($beanList[$module_name])){
 448          $error->set_error('no_module');
 449          return array('id'=>-1, 'error'=>$error->get_soap_array());
 450      }
 451      if($_SESSION['type'] == 'lead' && $module_name != 'Leads'){
 452          $error->set_error('no_access');
 453          return array('id'=>-1, 'error'=>$error->get_soap_array());
 454      }
 455  
 456      if($_SESSION['type'] == 'contact' && !key_exists($module_name, $valid_modules_for_contact) ){
 457          $error->set_error('no_access');
 458          return array('id'=>-1, 'error'=>$error->get_soap_array());
 459      }
 460  
 461  
 462      $class_name = $beanList[$module_name];
 463      require_once($beanFiles[$class_name]);
 464      $seed = new $class_name();
 465      $is_update = false;
 466      $values_set = array();
 467  
 468      foreach($name_value_list as $value){
 469          if($value['name'] == 'id' && !empty($value['value'])) {
 470              $seed->disable_row_level_security = true;
 471              $seed->retrieve($value['value']);
 472              $is_update = true;
 473              break;
 474          }
 475          $values_set[$value['name']] = $value['value'];
 476          $seed->$value['name'] = $value['value'];
 477      }
 478  
 479      // If it was an update, we have to set the values again
 480      if($is_update) {
 481          foreach($name_value_list as $value){
 482              $seed->$value['name'] = $value['value'];
 483          }
 484      }
 485  
 486      if(!isset($_SESSION['viewable'][$module_name])){
 487          $_SESSION['viewable'][$module_name] = array();
 488      }
 489  
 490      if(!$is_update){
 491  
 492  
 493  
 494  
 495  
 496  
 497  
 498  
 499  
 500          if(isset($_SESSION['assigned_user_id']) && (!key_exists('assigned_user_id', $values_set) || empty($values_set['assigned_user_id']))){
 501              $seed->assigned_user_id = $_SESSION['assigned_user_id'];
 502          }
 503          if(isset($_SESSION['account_id']) && (!key_exists('account_id', $values_set) || empty($values_set['account_id']))){
 504              $seed->account_id = $_SESSION['account_id'];
 505          }
 506          $seed->portal_flag = 1;
 507          $seed->portal_viewable = true;
 508      }
 509  
 510  
 511  
 512      $id = $seed->save();
 513  
 514  
 515  
 516      set_module_in(array('in'=>"('$id')", 'list'=>array($id)), $module_name);
 517      if($_SESSION['type'] == 'contact' && $module_name != 'Contacts' && !$is_update){
 518          if($module_name == 'Notes'){
 519              $seed->contact_id = $_SESSION['user_id'];
 520              if(isset( $_SESSION['account_id'])){
 521                  $seed->parent_type = 'Accounts';
 522                  $seed->parent_id = $_SESSION['account_id'];
 523  
 524              }
 525              $id = $seed->save();
 526          }else{
 527              $seed->contact_id = $_SESSION['user_id'];
 528  
 529              if(isset( $_SESSION['account_id'])){
 530                  $seed->account_id = $_SESSION['account_id'];
 531  
 532              }
 533              $seed->save_relationship_changes(false);
 534          }
 535      }
 536      return array('id'=>$id, 'error'=>$error->get_soap_array());
 537  
 538  }
 539  
 540  
 541  
 542  /*
 543  
 544  NOTE SPECIFIC CODE
 545  */
 546  $server->register(
 547          'portal_set_note_attachment',
 548          array('session'=>'xsd:string','note'=>'tns:note_attachment'),
 549          array('return'=>'tns:set_entry_result'),
 550          $NAMESPACE);
 551  
 552  function portal_set_note_attachment($session,$note)
 553  {
 554      $error = new SoapError();
 555      if(!portal_validate_authenticated($session)){
 556          $error->set_error('invalid_session');
 557          return array('id'=>'-1', 'error'=>$error->get_soap_array());
 558      }
 559      if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$note['id']])){
 560          $error->set_error('no_access');
 561          return array('id'=>-1, 'error'=>$error->get_soap_array());
 562      }
 563      require_once ('modules/Notes/NoteSoap.php');
 564      $ns = new NoteSoap();
 565      $id = $ns->saveFile($note, true);
 566      return array('id'=>$id, 'error'=>$error->get_soap_array());
 567  
 568  }
 569  
 570  $server->register(
 571      'portal_remove_note_attachment',
 572      array('session'=>'xsd:string', 'id'=>'xsd:string'),
 573      array('return'=>'tns:error_value'),
 574      $NAMESPACE);
 575  
 576  function portal_remove_note_attachment($session, $id)
 577  {
 578      $error = new SoapError();
 579      if(! portal_validate_authenticated($session)){
 580          $error->set_error('invalid_session');
 581          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 582      }
 583      if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$id])){
 584          $error->set_error('no_access');
 585          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 586      }
 587      
 588      $focus = new Note();
 589  
 590  
 591  
 592      $focus->retrieve($id);
 593      $result = $focus->deleteAttachment();
 594  
 595      return $error->get_soap_array();
 596  }
 597  
 598  $server->register(
 599      'portal_get_note_attachment',
 600      array('session'=>'xsd:string', 'id'=>'xsd:string'),
 601      array('return'=>'tns:return_note_attachment'),
 602      $NAMESPACE);
 603  
 604  function portal_get_note_attachment($session,$id)
 605  {
 606  
 607      $error = new SoapError();
 608      if(! portal_validate_authenticated($session)){
 609          $error->set_error('invalid_session');
 610          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 611      }
 612      if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$id])){
 613          $error->set_error('no_access');
 614          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 615      }
 616      $current_user = $seed_user;
 617      
 618      $note = new Note();
 619  
 620  
 621  
 622      $note->retrieve($id);
 623      require_once ('modules/Notes/NoteSoap.php');
 624      $ns = new NoteSoap();
 625      if(!isset($note->filename)){
 626          $note->filename = '';
 627      }
 628      $file= $ns->retrieveFile($id,$note->filename);
 629      if($file == -1){
 630          $error->set_error('no_file');
 631          $file = '';
 632      }
 633  
 634      return array('note_attachment'=>array('id'=>$id, 'filename'=>$note->filename, 'file'=>$file), 'error'=>$error->get_soap_array());
 635  
 636  }
 637  $server->register(
 638      'portal_relate_note_to_module',
 639      array('session'=>'xsd:string', 'note_id'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string'),
 640      array('return'=>'tns:error_value'),
 641      $NAMESPACE);
 642  
 643  function portal_relate_note_to_module($session,$note_id, $module_name, $module_id){
 644      global  $beanList, $beanFiles, $current_user;
 645      $error = new SoapError();
 646      if(! portal_validate_authenticated($session)){
 647          $error->set_error('invalid_session');
 648          return $error->get_soap_array();
 649          }
 650      if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$note_id]) || !isset($_SESSION['viewable'][$module_name][$module_id])){
 651          $error->set_error('no_access');
 652          return $error->get_soap_array();
 653          }
 654      if(empty($beanList[$module_name])){
 655          $error->set_error('no_module');
 656          return $error->get_soap_array();
 657      }
 658  
 659      $class_name = $beanList[$module_name];
 660      require_once($beanFiles[$class_name]);
 661  
 662      $seed = new $class_name();
 663  
 664  
 665  
 666      $seed->retrieve($module_id);
 667      if($module_name == 'Cases' || $module_name == 'Bugs') {
 668          $seed->note_id =  $note_id;
 669          $seed->save(false);
 670      } else {
 671          $error->set_error('no_module_support');
 672          $error->description .= ': '. $module_name;
 673      }
 674      return $error->get_soap_array();
 675  
 676  }
 677  $server->register(
 678      'portal_get_related_notes',
 679      array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string',  'select_fields'=>'tns:select_fields', 'order_by'=>'xsd:string'),
 680      array('return'=>'tns:get_entry_result'),
 681      $NAMESPACE);
 682  
 683  function portal_get_related_notes($session,$module_name, $module_id, $select_fields, $order_by){
 684      global  $beanList, $beanFiles;
 685      $error = new SoapError();
 686      if(! portal_validate_authenticated($session)){
 687          $error->set_error('invalid_session');
 688          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 689      }
 690      if($_SESSION['type'] == 'lead' ){
 691          $error->set_error('no_access');
 692          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 693      }
 694      if(empty($beanList[$module_name])){
 695          $error->set_error('no_module');
 696          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 697      }
 698      if(empty($_SESSION['viewable'][$module_name][$module_id])){
 699          $error->set_error('no_access');
 700          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 701      }
 702  
 703      if($module_name =='Contacts'){
 704          if($_SESSION['user_id'] != $module_id){
 705              $error->set_error('no_access');
 706              return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 707          }
 708          $list = get_notes_in_contacts("('$module_id')", $order_by);
 709      }else{
 710          $list = get_notes_in_module("('$module_id')", $module_name, $order_by);
 711      }
 712  
 713  
 714  
 715      $output_list = Array();
 716      $field_list = Array();
 717      foreach($list as $value)
 718      {
 719          $output_list[] = get_return_value($value, 'Notes');
 720          $_SESSION['viewable']['Notes'][$value->id] = $value->id;
 721      if(empty($field_list)){
 722              $field_list = get_field_list($value, true);
 723          }
 724      }
 725      $output_list = filter_return_list($output_list, $select_fields, $module_name);
 726      $field_list = filter_field_list($field_list,$select_fields, $module_name);
 727  
 728  
 729      return array('result_count'=>sizeof($output_list), 'next_offset'=>0,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
 730  }
 731  
 732  $server->register(
 733      'portal_get_related_list',
 734      array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'rel_module'=>'xsd:string', 'module_id'=>'xsd:string',  'select_fields'=>'tns:select_fields', 'order_by'=>'xsd:string', 'offset' => 'xsd:int', 'limit' => 'xsd:int'),
 735      array('return'=>'tns:get_entry_result'),
 736      $NAMESPACE);
 737  
 738  function portal_get_related_list($session, $module_name, $rel_module, $module_id, $select_fields, $order_by, $offset, $limit){
 739      global  $beanList, $beanFiles;
 740      $error = new SoapError();
 741      if(! portal_validate_authenticated($session)){
 742          $error->set_error('invalid_session');
 743          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 744      }
 745      if($_SESSION['type'] == 'lead' ){
 746          $error->set_error('no_access');
 747          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 748      }
 749      if(empty($beanList[$module_name])){
 750          $error->set_error('no_module');
 751          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 752      }
 753      if(empty($_SESSION['viewable'][$module_name][$module_id])){
 754          $error->set_error('no_access');
 755          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 756      }
 757  
 758      $list = get_related_in_module("('$module_id')", $module_name, $rel_module, $order_by, $offset, $limit);
 759  
 760      $output_list = Array();
 761      $field_list = Array();
 762      foreach($list as $value)
 763      {
 764          $output_list[] = get_return_value($value, $rel_module);
 765          $_SESSION['viewable'][$rel_module][$value->id] = $value->id;
 766      if(empty($field_list)){
 767              $field_list = get_field_list($value, true);
 768          }
 769      }
 770      $output_list = filter_return_list($output_list, $select_fields, $module_name);
 771      $field_list = filter_field_list($field_list,$select_fields, $module_name);
 772  
 773  
 774      return array('result_count'=>$list['result_count'], 'next_offset'=>0,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
 775  }
 776  
 777  $server->register(
 778      'portal_get_module_fields',
 779      array('session'=>'xsd:string', 'module_name'=>'xsd:string'),
 780      array('return'=>'tns:module_fields'),
 781      $NAMESPACE);
 782  
 783  function portal_get_module_fields($session, $module_name){
 784      global  $beanList, $beanFiles, $portal_modules, $valid_modules_for_contact;
 785      $error = new SoapError();
 786      $module_fields = array();
 787      if(! portal_validate_authenticated($session)){
 788          $error->set_error('invalid_session');
 789          $error->description .=$session;
 790          return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
 791      }
 792      if($_SESSION['type'] == 'lead' && $module_name != 'Leads'){
 793          $error->set_error('no_access');
 794          return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
 795      }
 796  
 797      if(empty($beanList[$module_name])){
 798          $error->set_error('no_module');
 799          return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
 800      }
 801  
 802      if(($_SESSION['type'] == 'portal'||$_SESSION['type'] == 'contact') &&  !key_exists($module_name, $valid_modules_for_contact)){
 803          $error->set_error('no_module');
 804          return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
 805      }
 806  
 807      $class_name = $beanList[$module_name];
 808      require_once($beanFiles[$class_name]);
 809      $seed = new $class_name();
 810      $seed->fill_in_additional_detail_fields();
 811      $returnFields = get_return_module_fields($seed, $module_name, $error->get_soap_array(), true);
 812      if(is_subclass_of($seed, 'Person')) {
 813         $returnFields['module_fields']['email1'] = array('name'=>'email1', 'type'=>'email', 'required'=>0, 'label'=>translate('LBL_EMAIL_ADDRESS', $seed->module_dir));
 814         $returnFields['module_fields']['email_opt_out'] = array('name'=>'email_opt_out', 'type'=>'bool', 'required'=>0, 'label'=>translate('LBL_EMAIL_OPT_OUT', $seed->module_dir), 'options'=>array());
 815      } //if
 816  
 817      return $returnFields;
 818  }
 819  
 820  $server->register(
 821      'portal_get_subscription_lists',
 822      array('session'=>'xsd:string'),
 823      array('return'=>'tns:get_subscription_lists_result'),
 824      $NAMESPACE);
 825  
 826  function portal_get_subscription_lists($session){
 827      global  $beanList, $beanFiles;
 828  
 829      $error = new SoapError();
 830      if(! portal_validate_authenticated($session)){
 831          $error->set_error('invalid_session');
 832          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 833      }
 834  
 835      require_once ('modules/Campaigns/utils.php');
 836  
 837      $contact = new Contact();
 838  
 839  
 840  
 841      $contact->retrieve($_SESSION['user_id']);
 842  
 843      if(!empty($contact->id)) {
 844          $result = get_subscription_lists_keyed($contact, true);
 845      }
 846  
 847  
 848      $return_results = array('unsubscribed' => array(), 'subscribed' => array());
 849  
 850      foreach($result['unsubscribed'] as $newsletter_name => $data) {
 851          $return_results['unsubscribed'][] = array('name' => $newsletter_name, 'prospect_list_id' => $data['prospect_list_id'],
 852                                                    'campaign_id' => $data['campaign_id'], 'description' => $data['description'],
 853                                                    'frequency' => $data['frequency']);
 854      }
 855      foreach($result['subscribed'] as $newsletter_name => $data) {
 856          $return_results['subscribed'][] = array('name' => $newsletter_name, 'prospect_list_id' => $data['prospect_list_id'],
 857                                                  'campaign_id' => $data['campaign_id'], 'description' => $data['description'],
 858                                                  'frequency' => $data['frequency']);
 859      }
 860  
 861      return array('unsubscribed'=>$return_results['unsubscribed'], 'subscribed' => $return_results['subscribed'], 'error'=>$error->get_soap_array());
 862  }
 863  
 864  $server->register(
 865      'portal_set_newsletters',
 866      array('session'=>'xsd:string', 'subscribe_ids' => 'tns:select_fields', 'unsubscribe_ids' => 'tns:select_fields'),
 867      array('return'=>'tns:error_value'),
 868      $NAMESPACE);
 869  
 870  function portal_set_newsletters($session, $subscribe_ids, $unsubscribe_ids){
 871      global  $beanList, $beanFiles;
 872  
 873      $error = new SoapError();
 874      if(! portal_validate_authenticated($session)){
 875          $error->set_error('invalid_session');
 876          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 877      }
 878  
 879      require_once ('modules/Campaigns/utils.php');
 880  
 881      $contact = new Contact();
 882  
 883  
 884  
 885      $contact->retrieve($_SESSION['user_id']);
 886  
 887      if(!empty($contact->id)) {
 888          foreach($subscribe_ids as $campaign_id) {
 889              subscribe($campaign_id, null, $contact, true);
 890          }
 891          foreach($unsubscribe_ids as $campaign_id) {
 892              unsubscribe($campaign_id, $contact);
 893          }
 894      }
 895  
 896      return $error->get_soap_array();
 897  }
 898  
 899  
 900  
 901  
 902  
 903  
 904  
 905  
 906  
 907  
 908  
 909  
 910  
 911  
 912  
 913  
 914  
 915  
 916  
 917  
 918  
 919  
 920  
 921  
 922  
 923  
 924  
 925  
 926  
 927  
 928  
 929  
 930  
 931  
 932  
 933  
 934  
 935  
 936  
 937  
 938  
 939  
 940  
 941  
 942  
 943  
 944  
 945  
 946  
 947  
 948  
 949  
 950  
 951  
 952  
 953  ?>


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