iTx Technologies offre gratuitement
cet espace pour SugarCRM !

title

Body

[fermer]

/soap/ -> SoapPortalHelper.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  $portal_modules = array('Contacts', 'Accounts', 'Cases', 'Bugs', 'Notes');
  38  
  39  
  40  
  41  
  42  /*
  43  BUGS
  44  */
  45  
  46  
  47  
  48  
  49  
  50  
  51  
  52  
  53  
  54  function get_bugs_in_contacts($in, $orderBy = '', $where='')
  55      {
  56          //bail if the in is empty
  57          if($in == '()')return;
  58          // First, get the list of IDs.
  59          
  60  
  61          $query = "SELECT bug_id as id from contacts_bugs where contact_id IN $in AND deleted=0";
  62          if(!empty($orderBy)){
  63              $query .= ' ORDER BY ' . $orderBy;
  64          }
  65  
  66  
  67  
  68  
  69  
  70  
  71  
  72  
  73          $sugar = new Contact();
  74  
  75  
  76  
  77          set_module_in($sugar->build_related_in($query), 'Bugs');
  78      }
  79  
  80  function get_bugs_in_accounts($in, $orderBy = '', $where='')
  81      {
  82          //bail if the in is empty
  83          if($in == '()')return;
  84          // First, get the list of IDs.
  85          
  86  
  87          $query = "SELECT bug_id as id from accounts_bugs where account_id IN $in AND deleted=0";
  88          if(!empty($orderBy)){
  89              $query .= ' ORDER BY ' . $orderBy;
  90          }
  91  
  92  
  93  
  94  
  95  
  96  
  97  
  98  
  99          $sugar = new Account();
 100  
 101  
 102  
 103  
 104          set_module_in($sugar->build_related_in($query), 'Bugs');
 105      }
 106  
 107  /*
 108  Cases
 109  */
 110  
 111  function get_cases_in_contacts($in, $orderBy = '')
 112      {
 113          //bail if the in is empty
 114          if($in == '()')return;
 115          // First, get the list of IDs.
 116  
 117  
 118          $query = "SELECT case_id as id from contacts_cases where contact_id IN $in AND deleted=0";
 119          if(!empty($orderBy)){
 120              $query .= ' ORDER BY ' . $orderBy;
 121          }
 122  
 123  
 124  
 125  
 126  
 127  
 128  
 129  
 130          $sugar = new Contact();
 131  
 132  
 133  
 134          set_module_in($sugar->build_related_in($query), 'Cases');
 135      }
 136  
 137  function get_cases_in_accounts($in, $orderBy = '')
 138      {
 139          if(empty($_SESSION['viewable']['Accounts'])){
 140              return;
 141          }
 142          //bail if the in is empty
 143          if($in == '()')return;
 144          // First, get the list of IDs.
 145  
 146          $query = "SELECT id  from cases where account_id IN $in AND deleted=0";
 147          if(!empty($orderBy)){
 148              $query .= ' ORDER BY ' . $orderBy;
 149          }        
 150  
 151  
 152  
 153  
 154  
 155  
 156  
 157          
 158          $sugar = new Account();
 159  
 160  
 161  
 162          set_module_in($sugar->build_related_in($query), 'Cases');
 163      }
 164  
 165  
 166  
 167  /*
 168  NOTES
 169  */
 170  
 171  
 172  function get_notes_in_contacts($in, $orderBy = '')
 173      {
 174          //bail if the in is empty
 175          if($in == '()')return;
 176          // First, get the list of IDs.
 177          $query = "SELECT id from notes where contact_id IN $in AND deleted=0 AND portal_flag=1";
 178          if(!empty($orderBy)){
 179              $query .= ' ORDER BY ' . $orderBy;
 180          }
 181              
 182          $contact = new Contact();
 183  
 184  
 185  
 186          $note = new Note();
 187  
 188  
 189  
 190          return $contact->build_related_list($query, $note);
 191      }
 192  
 193  function get_notes_in_module($in, $module, $orderBy = '')
 194      {
 195          //bail if the in is empty
 196          if($in == '()')return;
 197          // First, get the list of IDs.
 198          $query = "SELECT id from notes where parent_id IN $in AND parent_type='$module' AND deleted=0 AND portal_flag = 1";
 199          if(!empty($orderBy)){
 200              $query .= ' ORDER BY ' . $orderBy;
 201          }
 202          global $beanList, $beanFiles;
 203  
 204          if(!empty($beanList[$module])){
 205              $class_name = $beanList[$module];
 206              require_once($beanFiles[$class_name]);
 207              $sugar = new $class_name();
 208          }else{
 209              return array();
 210          }
 211  
 212  
 213  
 214  
 215          $note = new Note();
 216  
 217  
 218  
 219          return $sugar->build_related_list($query, $note);
 220      }
 221      
 222      function get_related_in_module($in, $module, $rel_module, $orderBy = '', $row_offset = 0, $limit= -1)
 223      {
 224          global $beanList, $beanFiles;
 225           if(!empty($beanList[$rel_module])){
 226              $class_name = $beanList[$rel_module];
 227              require_once($beanFiles[$class_name]);
 228              $rel = new $class_name();
 229          }else{
 230              return array();
 231          }
 232          
 233          //bail if the in is empty
 234          if($in == '()')return;
 235  
 236          // First, get the list of IDs.
 237          if ($module == 'KBDocuments' || $module == 'DocumentRevisions') {
 238              $query = "SELECT dr.* from document_revisions dr
 239                        inner join kbdocument_revisions kr on kr.document_revision_id = dr.id AND kr.kbdocument_id IN ($in)
 240                        AND dr.file_mime_type is not null";
 241          } else {
 242              $query = "SELECT id from $rel->table_name where parent_id IN $in AND parent_type='$module' AND deleted=0 AND portal_flag = 1";
 243          }
 244  
 245          if(!empty($orderBy)){
 246              $query .= ' ORDER BY ' . $orderBy;
 247          }
 248  
 249          if(!empty($beanList[$module])){
 250              $class_name = $beanList[$module];
 251              require_once($beanFiles[$class_name]);
 252              $sugar = new $class_name();
 253          }else{
 254              return array();
 255          }
 256          
 257  
 258  
 259  
 260  
 261  
 262  
 263          
 264          $count_query = $sugar->create_list_count_query($query);
 265          if(!empty($count_query))
 266          {
 267              // We have a count query.  Run it and get the results.
 268              $result = $sugar->db->query($count_query, true, "Error running count query for $sugar->object_name List: ");
 269              $assoc = $sugar->db->fetchByAssoc($result);
 270              if(!empty($assoc['c']))
 271              {
 272                  $rows_found = $assoc['c'];
 273              }
 274          }
 275          $list = $sugar->build_related_list($query, $rel, $row_offset, $limit);
 276          $list['result_count'] = $rows_found;
 277          return $list;
 278      }
 279  
 280  function get_accounts_from_contact($contact_id, $orderBy = '')
 281      {
 282                  // First, get the list of IDs.
 283          $query = "SELECT account_id as id from accounts_contacts where contact_id='$contact_id' AND deleted=0";
 284          if(!empty($orderBy)){
 285              $query .= ' ORDER BY ' . $orderBy;
 286          }
 287          $sugar = new Contact();
 288  
 289  
 290  
 291          set_module_in($sugar->build_related_in($query), 'Accounts');
 292      }
 293  
 294  function get_contacts_from_account($account_id, $orderBy = '')
 295      {
 296          // First, get the list of IDs.
 297          $query = "SELECT contact_id as id from accounts_contacts where account_id='$account_id' AND deleted=0";
 298          if(!empty($orderBy)){
 299              $query .= ' ORDER BY ' . $orderBy;
 300          }
 301          $sugar = new Account();
 302  
 303  
 304  
 305          set_module_in($sugar->build_related_in($query), 'Contacts');
 306      }
 307  
 308  function get_related_list($in, $template, $where, $order_by, $row_offset = 0, $limit = ""){
 309  
 310          $list = array();
 311          //bail if the in is empty
 312          if($in == '()')return $list;
 313  
 314  
 315  
 316  
 317          return $template->build_related_list_where('',$template, $where, $in, $order_by, $limit, $row_offset);
 318  
 319  
 320  }
 321  
 322  function build_relationship_tree($contact){
 323      global $sugar_config;
 324      $contact->retrieve($contact->id);
 325  
 326  
 327  
 328  
 329      get_accounts_from_contact($contact->id);
 330  
 331      set_module_in(array('list'=>array($contact->id), 'in'=> "('$contact->id')"), 'Contacts');
 332  
 333      $accounts = $_SESSION['viewable']['Accounts'];
 334      foreach($accounts as $id){
 335          if(!isset($sugar_config['portal_view']) || $sugar_config['portal_view'] != 'single_user'){
 336              get_contacts_from_account($id);
 337          }
 338      }
 339  }
 340  
 341  function get_contacts_in(){
 342      return $_SESSION['viewable']['contacts_in'];
 343  }
 344  
 345  function get_accounts_in(){
 346      return $_SESSION['viewable']['accounts_in'];
 347  }
 348  
 349  function get_module_in($module_name){
 350      if(!isset($_SESSION['viewable'][$module_name])){
 351          return '()';
 352      }
 353  
 354      $mod_in = "('" . join("','", array_keys($_SESSION['viewable'][$module_name])) . "')";
 355      $_SESSION['viewable'][strtolower($module_name).'_in'] = $mod_in;
 356      
 357      return $mod_in;
 358  }
 359  
 360  function set_module_in($arrayList, $module_name){
 361  
 362          if(!isset($_SESSION['viewable'][$module_name])){
 363              $_SESSION['viewable'][$module_name] = array();
 364          }
 365          foreach($arrayList['list'] as $id){
 366              $_SESSION['viewable'][$module_name][$id] = $id;
 367          }
 368          if($module_name == 'Accounts' && isset($id)){
 369              $_SESSION['account_id'] = $id;
 370          }
 371  
 372          if(!empty($_SESSION['viewable'][strtolower($module_name).'_in'])){
 373              if($arrayList['in'] != '()') {
 374                  $_SESSION['viewable'][strtolower($module_name).'_in'] = "('" . implode("', '", $_SESSION['viewable'][strtolower($module_name).'_in']);
 375                  $_SESSION['viewable'][strtolower($module_name).'_in'] .= implode("', '", $arrayList['list']) . "')";
 376              }
 377          }else{
 378              $_SESSION['viewable'][strtolower($module_name).'_in'] = $arrayList['in'];
 379          }
 380  }
 381  
 382  /*
 383   * Given the user auth, attempt to log the user in.
 384   * used by SoapPortalUsers.php
 385   */
 386  function login_user($portal_auth){
 387       $error = new SoapError();
 388       $user = new User();
 389       $user = $user->retrieve_by_string_fields(array('user_name'=>$portal_auth['user_name'],'user_hash'=>$portal_auth['password'], 'deleted'=>0, 'status'=>'Active', 'portal_only'=>1) );    
 390          
 391          if($user != null){
 392              global $current_user;
 393              $current_user = $user;
 394  
 395  
 396  
 397  
 398  
 399  
 400  
 401  
 402              return 'success';
 403          }else{
 404              $GLOBALS['log']->fatal('SECURITY: User authentication for '. $portal_auth['user_name']. ' failed');
 405              return 'fail';
 406          }
 407  }
 408  
 409  
 410  
 411  
 412  
 413  
 414  
 415  
 416  
 417  
 418  
 419  
 420  
 421  
 422  
 423  
 424  
 425  
 426  
 427  
 428  
 429  
 430  
 431  
 432  
 433  
 434  
 435  
 436  
 437  
 438  
 439  
 440  
 441  
 442  
 443  
 444  
 445  
 446  
 447  
 448  
 449  
 450  
 451  
 452  
 453  
 454  
 455  
 456  
 457  
 458  
 459  
 460  
 461  
 462  
 463  function portal_get_entry_list_limited($session, $module_name,$where, $order_by, $select_fields, $row_offset, $limit){
 464      global  $beanList, $beanFiles, $portal_modules;
 465      $error = new SoapError();
 466      if(! portal_validate_authenticated($session)){
 467          $error->set_error('invalid_session');
 468          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 469      }
 470      if($_SESSION['type'] == 'lead' ){
 471          $error->set_error('no_access');
 472          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 473      }
 474      if(empty($beanList[$module_name])){
 475          $error->set_error('no_module');
 476          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 477      }
 478      if($module_name == 'Cases'){
 479          if(!isset($_SESSION['viewable'][$module_name])){
 480              get_cases_in_contacts(get_contacts_in());
 481              get_cases_in_accounts(get_accounts_in());
 482          }
 483           
 484          $sugar = new aCase();
 485          $list =  get_related_list(get_module_in($module_name), new aCase(), $where,$order_by, $row_offset, $limit);
 486  
 487      }else if($module_name == 'Contacts'){
 488              $sugar = new Contact();
 489              $list =  get_related_list(get_module_in($module_name), new Contact(), $where,$order_by);
 490      }else if($module_name == 'Accounts'){
 491              $sugar = new Account();
 492              $list =  get_related_list(get_module_in($module_name), new Account(), $where,$order_by);
 493      }else if($module_name == 'Bugs'){
 494              if(!isset($_SESSION['viewable'][$module_name])){
 495                  get_bugs_in_contacts(get_contacts_in());
 496                  get_bugs_in_accounts(get_accounts_in());
 497              }
 498  
 499              $list = get_related_list(get_module_in($module_name), new Bug(), $where, $order_by, $row_offset, $limit);
 500      } else if ($module_name == 'KBDocuments') {
 501  
 502  
 503  
 504  
 505  
 506  
 507  
 508  
 509  
 510  
 511  
 512  
 513  
 514  
 515  
 516  
 517  
 518  
 519  
 520  
 521  
 522  
 523  
 524  
 525  
 526  
 527      } else if ($module_name == 'FAQ') {
 528  
 529  
 530  
 531  
 532  
 533  
 534  
 535      } else{
 536          $error->set_error('no_module_support');
 537          return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
 538  
 539      }
 540  
 541      $output_list = Array();
 542      $field_list = array();
 543      foreach($list as $value)
 544      {
 545  
 546          //$loga->fatal("Adding another account to the list");
 547          $output_list[] = get_return_value($value, $module_name);
 548          $_SESSION['viewable'][$module_name][$value->id] = $value->id;
 549          if(empty($field_list)){
 550              $field_list = get_field_list($value);
 551          }
 552      }
 553      $output_list = filter_return_list($output_list, $select_fields, $module_name);
 554      $field_list = filter_field_list($field_list,$select_fields, $module_name);
 555  
 556      return array('result_count'=>sizeof($output_list), 'next_offset'=>0,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
 557  }
 558  
 559  $invalid_contact_fields = array('portal_name'=>1, 'portal_password'=>1, 'portal_active'=>1);
 560  $valid_modules_for_contact = array('Contacts'=>1, 'Cases'=>1, 'Notes'=>1, 'Bugs'=>1, 'Accounts'=>1, 'Leads'=>1, 'KBDocuments'=>1);
 561  
 562  
 563  
 564  
 565  ?>


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