[ Index ]
 

Code source de SugarCRM 5.0.0beta1

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ -> json_server.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 - 2007 SugarCRM Inc.

   6   * 

   7   * This program is free software; you can redistribute it and/or modify it under

   8   * the terms of the GNU General Public License version 3 as published by the

   9   * Free Software Foundation.

  10   * 

  11   * This program is distributed in the hope that it will be useful, but WITHOUT

  12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS

  13   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more

  14   * details.

  15   * 

  16   * You should have received a copy of the GNU General Public License along with

  17   * this program; if not, see http://www.gnu.org/licenses or write to the Free

  18   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA

  19   * 02110-1301 USA.

  20   * 

  21   * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,

  22   * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.

  23   * 

  24   * The interactive user interfaces in modified source and object code versions

  25   * of this program must display Appropriate Legal Notices, as required under

  26   * Section 5 of the GNU General Public License version 3.

  27   * 

  28   * In accordance with Section 7(b) of the GNU General Public License version 3,

  29   * these Appropriate Legal Notices must retain the display of the "Powered by

  30   * SugarCRM" logo. If the display of the logo is not reasonably feasible for

  31   * technical reasons, the Appropriate Legal Notices must display the words

  32   * "Powered by SugarCRM".

  33   ********************************************************************************/
  34  require_once ('include/entryPoint.php');
  35  require_once ('soap/SoapHelperFunctions.php');
  36  $GLOBALS['log']->debug("JSON_SERVER:");
  37  $global_registry_var_name = 'GLOBAL_REGISTRY';
  38  
  39  
  40  ///////////////////////////////////////////////////////////////////////////////

  41  ////    SUPPORTED METHODS

  42  /*

  43   * ADD NEW METHODS TO THIS ARRAY:

  44   * then create a function called "function json_$method($request_id, &$params)"

  45   * where $method is the method name

  46   */
  47  $SUPPORTED_METHODS = array(
  48      'retrieve',
  49      'query',
  50      'set_accept_status',
  51      'get_user_array', 
  52      'get_objects_from_module', 
  53      'email', 
  54      'get_full_list'
  55  );
  56  
  57  /**

  58   * Generic retrieve for getting data from a sugarbean

  59   */
  60  function json_retrieve($request_id, &$params) {
  61      global $json,$current_user;
  62      global $beanFiles,$beanList;
  63  
  64      $record = $params[0]['record'];
  65  
  66      require_once($beanFiles[$beanList[$params[0]['module']]]);
  67      $focus = new $beanList[$params[0]['module']];
  68      $focus->retrieve($record);
  69  
  70      // to get a simplified version of the sugarbean

  71      $module_arr = populateBean($focus);
  72  
  73      $response = array();
  74      $response['id'] = $request_id;
  75      $response['result'] = array("status"=>"success","record"=>$module_arr);
  76      $json_response = $json->encode($response, true);
  77      print $json_response;
  78  }
  79  
  80  function json_query($request_id, &$params) {
  81      global $json, $response, $sugar_config;
  82      global $beanFiles, $beanList;
  83      
  84      if($sugar_config['list_max_entries_per_page'] < 31)    // override query limits
  85          $sugar_config['list_max_entries_per_page'] = 31;
  86  
  87      $args = $params[0];
  88      
  89      //decode condition parameter values..

  90      if(is_array($args['conditions'])) {
  91          foreach($args['conditions'] as $key=>$condition)    {        
  92              if(!empty($condition['value'])) {
  93                  $where = $json->decode(utf8_encode($condition['value']));
  94                  // cn: bug 12693 - API change due to CSRF security changes.

  95                  $where = empty($where) ? $condition['value'] : $where;
  96                  $args['conditions'][$key]['value'] = $where;
  97              }        
  98          }
  99      }
 100  
 101      $list_return = array();
 102      
 103      if(! empty($args['module'])) {
 104          $args['modules'] = array($args['module']);
 105      }
 106      
 107      foreach($args['modules'] as $module) {
 108          require_once($beanFiles[$beanList[$module]]);
 109          $focus = new $beanList[$module];
 110          
 111          $query_orderby = '';
 112          if(!empty($args['order'])) {
 113              $query_orderby = $args['order'];
 114          }
 115          $query_limit = '';
 116          if(!empty($args['limit'])) {
 117              $query_limit = $args['limit'];
 118          }
 119          $query_where = construct_where($args, $focus->table_name);
 120          $list_arr = array();
 121          if($focus->ACLAccess('ListView', true)) {
 122              $curlist = $focus->get_list($query_orderby, $query_where, 0, $query_limit, -1, 0);
 123              $list_return = array_merge($list_return,$curlist['list']);
 124          }
 125      }
 126      
 127      $app_list_strings = null;
 128  
 129      for($i = 0;$i < count($list_return);$i++) {
 130          if(isset($list_return[$i]->emailAddress) && is_object($list_return[$i]->emailAddress)) {
 131              $list_return[$i]->emailAddress->handleLegacyRetrieve($list_return[$i]);
 132          }
 133          
 134          $list_arr[$i]= array();
 135          $list_arr[$i]['fields']= array();
 136          $list_arr[$i]['module']= $list_return[$i]->object_name;
 137          
 138          foreach($args['field_list'] as $field) {
 139              // handle enums

 140              if(    (isset($list_return[$i]->field_name_map[$field]['type']) && $list_return[$i]->field_name_map[$field]['type'] == 'enum') || 
 141                  (isset($list_return[$i]->field_name_map[$field]['custom_type']) && $list_return[$i]->field_name_map[$field]['custom_type'] == 'enum')) {
 142                  
 143                  // get fields to match enum vals

 144                  if(empty($app_list_strings)) {
 145                      if(isset($_SESSION['authenticated_user_language']) && $_SESSION['authenticated_user_language'] != '') $current_language = $_SESSION['authenticated_user_language'];
 146                      else $current_language = $sugar_config['default_language'];
 147                      $app_list_strings = return_app_list_strings_language($current_language);
 148                  }
 149                  
 150                  // match enum vals to text vals in language pack for return

 151                  if(!empty($app_list_strings[$list_return[$i]->field_name_map[$field]['options']])) {
 152                      $list_return[$i]->$field = $app_list_strings[$list_return[$i]->field_name_map[$field]['options']][$list_return[$i]->$field];
 153                  }
 154              }
 155  
 156              $list_arr[$i]['fields'][$field] = $list_return[$i]->$field;
 157          }
 158      }
 159  
 160  
 161      $response['id'] = $request_id;
 162      $response['result'] = array("list"=>$list_arr);
 163      $json_response = $json->encode($response, true);
 164      echo $json_response;
 165  }
 166  
 167  
 168  function json_set_accept_status($request_id, &$params) {
 169      global $json,$current_user;
 170      global $beanFiles,$beanList;
 171       require_once($beanFiles[$beanList[$params[0]['module']]]);
 172      
 173      $focus = new $beanList[$params[0]['module']];
 174      $focus->id = $params[0]['record'];
 175      
 176      $test = $focus->set_accept_status($current_user,$params[0]['accept_status']);
 177      
 178      $response = array();
 179      $response['id'] = $request_id;
 180      $response['result'] = array("status"=>"success","record"=>$params[0]['record'],'accept_status'=>$params[0]['accept_status']);
 181      $json_response = $json->encode($response, true);
 182      print $json_response;
 183  }
 184  
 185  
 186  /**

 187   * retrieves Users matching passed criteria

 188   */
 189  function json_get_user_array($request_id, &$params) {
 190      global $json;
 191      $args = $params[0];
 192      
 193      //decode condition parameter values..

 194      if(is_array($args['conditions'])) {
 195          foreach($args['conditions'] as $key=>$condition) {        
 196              if(!empty($condition['value'])) {
 197                  $args['conditions'][$key]['value']=$json->decode($condition['value']);
 198              }
 199          }
 200      }
 201      
 202      $response = array();
 203      $response['id'] = $request_id;
 204      $response['result'] = array();
 205      $response['result']['list'] = array();
 206      
 207      if(showFullName()) {
 208          $user_array = getUserArrayFromFullName($args['conditions'][0]['value']);
 209      } else {
 210           $user_array = get_user_array(false, "Active", $focus->assigned_user_id, false, $args['conditions'][0]['value']);
 211      }
 212      
 213      foreach($user_array as $id=>$name) {
 214          array_push($response['result']['list'], array('fields' => array('id' => $id, 'user_name' => $name), 'module' => 'Users'));
 215      }
 216  
 217      print $json->encode($response, true);
 218  }
 219  
 220  function json_get_objects_from_module($request_id, &$params) {
 221      global $beanList, $beanFiles, $json, $current_user;
 222  
 223      $module_name = $params[0]['module'];
 224      $offset = intval($params[0]['offset']);
 225      $where = $params[0]['where'];
 226      $max = $params[0]['max'];
 227      $order_by = $params[0]['order_by'];
 228      $using_cp = false;
 229      
 230      if($module_name == 'CampaignProspects'){
 231          $module_name = 'Prospects';   
 232          $using_cp = true;
 233      }
 234  
 235      $class_name = $beanList[$module_name];
 236      require_once($beanFiles[$class_name]);
 237      $seed = new $class_name();
 238      if($where == ''){
 239          $where = '';
 240      }
 241      if($offset == '' || $offset == -1){
 242          $offset = 0;
 243      }
 244      if($max == ''){
 245          $max = 10;
 246      }
 247  
 248      $deleted = '0';
 249       if($using_cp){
 250           $fields = array('id', 'first_name', 'last_name');
 251         $response = $seed->retrieveTargetList($where, $fields, $offset,-1,$max,$deleted);
 252      }else{
 253        $response = $seed->get_list($order_by, $where, $offset,-1,$max,$deleted);
 254      }
 255       
 256      $list = $response['list'];
 257      $row_count = $response['row_count'];
 258  
 259      $output_list = array();
 260      foreach($list as $value)
 261      {
 262          $output_list[] = get_return_value($value, $module_name);
 263      }
 264      $response = array();
 265      $response['id'] = $request_id;
 266     
 267      $response['result'] = array('result_count'=>$row_count,'entry_list'=>$output_list);
 268      $json_response = $json->encode($response, true);
 269      print $json_response;
 270  }
 271  
 272  
 273  
 274  
 275  function json_email($request_id, &$params) {
 276      global $json,$response, $sugar_config;
 277      global $beanFiles,$beanList;
 278  
 279      $args = $params[0];
 280  
 281      if($sugar_config['list_max_entries_per_page'] < 50)    // override query limits
 282          $sugar_config['list_max_entries_per_page'] = 50;
 283  
 284      $list_return = array();
 285  
 286      if(! empty($args['module'])) {
 287          $args['modules'] = array($args['module']);
 288      }
 289  
 290      foreach($args['modules'] as $module) {
 291          require_once($beanFiles[$beanList[$module]]);
 292          $focus = new $beanList[$module];
 293      
 294          $query_orderby = '';
 295          if(!empty($args['order'])) {
 296              $query_orderby = $args['order'];
 297          }
 298          $query_limit = '';
 299          if(!empty($args['limit'])) {
 300              $query_limit = $args['limit'];
 301          }
 302          $query_where = construct_where($args,$focus->table_name);
 303          $list_arr = array();
 304      
 305          $curlist = $focus->get_list($query_orderby, $query_where, 0, $query_limit, -1, 0);
 306          $list_return = array_merge($list_return,$curlist['list']);
 307      }
 308  
 309      for($i = 0;$i < count($list_return);$i++) {
 310          $list_arr[$i]= array();
 311          $list_arr[$i]['fields']= array();
 312          $list_arr[$i]['module']= $list_return[$i]->object_name;
 313      
 314          foreach($args['field_list'] as $field) {
 315              $list_arr[$i]['fields'][$field] = $list_return[$i]->$field;
 316          }
 317      }
 318  
 319      $response['id'] = $request_id;
 320      $response['result'] = array("list"=>$list_arr);
 321      $json_response = $json->encode($response, true);
 322      echo $json_response;
 323  }
 324  
 325  
 326  function json_get_full_list($request_id, &$params) {
 327      global $json; // pre-instantiated above

 328      global $beanFiles;
 329      global $beanList;
 330      require_once($beanFiles[$beanList[$params[0]['module']]]);
 331  
 332      $where = str_replace('\\','', rawurldecode($params[0]['where']));
 333      $order = str_replace('\\','', rawurldecode($params[0]['order']));
 334      $focus = new $beanList[$params[0]['module']];
 335      
 336      $fullList = $focus->get_full_list($order, $where, '');
 337      $all_fields = array_merge($focus->column_fields,$focus->additional_column_fields);
 338  
 339      $js_fields_arr = array();
 340  
 341      if(isset($fullList) && !empty($fullList)) { // json error if this isn't defensive
 342          $i=0; 
 343          foreach($fullList as $note) {
 344              $js_fields_arr[$i] = array();
 345              
 346              foreach($all_fields as $field) {
 347                  if(isset($note->$field)) {
 348                      $note->$field = from_html($note->$field);
 349                      $note->$field = preg_replace('/\r\n/','<BR>',$note->$field);
 350                      $note->$field = preg_replace('/\n/','<BR>',$note->$field);
 351                      $js_fields_arr[$i][$field] = addslashes($note->$field);
 352                  }
 353              }
 354              $i++;
 355          }
 356      }
 357      
 358      $fin['id'] = $request_id;
 359      $fin['result'] = $js_fields_arr;
 360      $out = $json->encode($fin, true);
 361      
 362      print($out);
 363  }
 364  ////    END SUPPORTED METHODS

 365  ///////////////////////////////////////////////////////////////////////////////

 366  
 367  
 368  
 369  
 370  
 371  
 372  
 373  
 374  
 375  
 376  
 377  // ONLY USED FOR MEETINGS

 378  function meeting_retrieve($module,$record) {
 379      global $json,$response;
 380      global $beanFiles,$beanList;
 381      //header('Content-type: text/xml');

 382      require_once($beanFiles[$beanList[$module]]);
 383      $focus = new $beanList[$module];
 384  
 385      if(empty($module) || empty($record))
 386      {
 387          $response['error'] = array("error_msg"=>"method: retrieve: missing module or record as parameters");
 388          print $json->encode($response, true);
 389          
 390      }
 391  
 392      $focus->retrieve($record);
 393      
 394      $GLOBALS['log']->debug("JSON_SERVER:retrieved meeting:");
 395      
 396      $module_arr = populateBean($focus);
 397  
 398      if($module == 'Meetings')
 399      {
 400          $users = $focus->get_meeting_users();
 401      } else if($module == 'Calls')
 402      {
 403          $users = $focus->get_call_users();
 404      }
 405  
 406      $module_arr['users_arr'] = array();
 407  
 408      foreach($users as $user)
 409      {
 410          array_push($module_arr['users_arr'],    populateBean($user));
 411      }
 412      $module_arr['orig_users_arr_hash'] = array();
 413      foreach($users as $user)
 414      {
 415      $module_arr['orig_users_arr_hash'][$user->id] = '1';
 416      }
 417  
 418      $module_arr['contacts_arr'] = array();
 419  
 420      $focus->load_relationships('contacts');
 421      $contacts=$focus->get_linked_beans('contacts','Contact');
 422      foreach($contacts as $contact)
 423      {
 424          array_push($module_arr['users_arr'], populateBean($contact));
 425      }
 426  
 427      return $module_arr;
 428  }
 429  
 430  // HAS MEETING SPECIFIC CODE:

 431  function populateBean(&$focus) {
 432      $all_fields = $focus->list_fields;
 433      // MEETING SPECIFIC

 434      $all_fields = array_merge($all_fields,array('required','accept_status','name')); // need name field for contacts and users

 435      //$all_fields = array_merge($focus->column_fields,$focus->additional_column_fields);

 436  
 437      $module_arr = array();
 438  
 439      $module_arr['module'] = $focus->object_name;
 440  
 441      $module_arr['fields'] = array();
 442  
 443      foreach($all_fields as $field)
 444      {
 445          if(isset($focus->$field))
 446          {
 447              $focus->$field =    from_html($focus->$field);
 448              $focus->$field =    preg_replace("/\r\n/","<BR>",$focus->$field);
 449              $focus->$field =    preg_replace("/\n/","<BR>",$focus->$field);
 450              $module_arr['fields'][$field] = $focus->$field;
 451          }
 452      }
 453  $GLOBALS['log']->debug("JSON_SERVER:populate bean:");
 454      return $module_arr;
 455  }
 456  
 457  
 458  
 459  
 460  
 461  
 462  
 463  
 464  
 465  
 466  
 467  
 468  function getUserJSON() {
 469  }
 470  
 471  
 472  function getUserConfigJSON() {
 473   require_once ('include/TimeDate.php');
 474   $td = new TimeDate();
 475   global $current_user,$global_registry_var_name,$json,$_SESSION,$sugar_config;
 476  
 477   if(isset($_SESSION['authenticated_user_theme']) && $_SESSION['authenticated_user_theme'] != '')
 478   {
 479      $theme = $_SESSION['authenticated_user_theme'];
 480   }
 481   else
 482   {
 483      $theme = $sugar_config['default_theme'];
 484   }
 485   $user_arr = array();
 486   $user_arr['theme'] = $theme;
 487   $user_arr['fields'] = array();
 488   $user_arr['module'] = 'User';
 489   $user_arr['fields']['id'] = $current_user->id;
 490   $user_arr['fields']['user_name'] = $current_user->user_name;
 491   $user_arr['fields']['first_name'] = $current_user->first_name;
 492   $user_arr['fields']['last_name'] = $current_user->last_name;
 493   $user_arr['fields']['email'] = $current_user->email1;
 494   $userTz = $td->getUserTimeZone();
 495   $dstRange = $td->getDSTRange(date('Y'), $userTz);
 496   $user_arr['fields']['dst_start'] = $dstRange['start'];
 497   $user_arr['fields']['dst_end'] = $dstRange['end'];
 498   $user_arr['fields']['gmt_offset'] = $userTz['gmtOffset'];
 499   $str = "\n".$global_registry_var_name.".current_user = ".$json->encode($user_arr, true).";\n";
 500  return $str;
 501  
 502  }
 503  
 504  
 505  
 506  
 507  
 508  
 509  ///////////////////////////////////////////////////////////////////////////////

 510  ////    UTILS

 511  function authenticate() {
 512      global $sugar_config;
 513  
 514      $user_unique_key =(isset($_SESSION['unique_key'])) ? $_SESSION['unique_key'] : "";
 515      $server_unique_key =(isset($sugar_config['unique_key'])) ? $sugar_config['unique_key'] : "";
 516  
 517      if($user_unique_key != $server_unique_key) {
 518          $GLOBALS['log']->debug("JSON_SERVER: user_unique_key:".$user_unique_key."!=".$server_unique_key);
 519          session_destroy();
 520          return null;
 521      }
 522  
 523      if(!isset($_SESSION['authenticated_user_id'])) {
 524          $GLOBALS['log']->debug("JSON_SERVER: authenticated_user_id NOT SET. DESTROY");
 525          session_destroy();
 526          return null;
 527      }
 528  
 529      $current_user = new User();
 530  
 531      $result = $current_user->retrieve($_SESSION['authenticated_user_id']);
 532      $GLOBALS['log']->debug("JSON_SERVER: retrieved user from SESSION");
 533  
 534  
 535      if($result == null) {
 536          $GLOBALS['log']->debug("JSON_SERVER: could get a user from SESSION. DESTROY");
 537          session_destroy();
 538          return null;
 539      }
 540  
 541      return $result;
 542  }
 543  
 544  function construct_where(&$query_obj, $table='') {
 545      if(! empty($table)) {
 546          $table .= ".";
 547      }
 548      $cond_arr = array();
 549  
 550      if(! is_array($query_obj['conditions'])) {
 551          $query_obj['conditions'] = array();
 552      }
 553  
 554      foreach($query_obj['conditions'] as $condition) {
 555          if($condition['op'] == 'contains') {
 556              array_push($cond_arr,PearDatabase::quote($table.$condition['name'])." like '%".PearDatabase::quote($condition['value'])."%'");
 557          }
 558          if($condition['op'] == 'like_custom') {
 559              $like = '';
 560              if(!empty($condition['begin'])) $like .= PearDatabase::quote($condition['begin']);
 561              $like .= PearDatabase::quote($condition['value']);
 562              if(!empty($condition['end'])) $like .= PearDatabase::quote($condition['end']);
 563              array_push($cond_arr,PearDatabase::quote($table.$condition['name'])." like '$like'");
 564          } else { // starts_with
 565              array_push($cond_arr,PearDatabase::quote($table.$condition['name'])." like '".PearDatabase::quote($condition['value'])."%'");
 566          }
 567      }
 568      
 569      if($table == 'users.') {
 570          array_push($cond_arr,$table."status='Active'");
 571      }
 572      
 573      return implode(" {$query_obj['group']} ",$cond_arr);
 574  }
 575  
 576  function getAppMetaJSON() {
 577      global $json, $global_registry_var_name, $sugar_config;
 578  
 579      $str = "\nvar ".$global_registry_var_name." = new Object();\n";
 580      $str .= "\n".$global_registry_var_name.".config = {\"site_url\":\"".getJavascriptSiteURL()."\"};\n";
 581      
 582      $str .= $global_registry_var_name.".meta = new Object();\n";
 583      $str .= $global_registry_var_name.".meta.modules = new Object();\n";
 584      $modules_arr = array('Meetings','Calls');
 585      $meta_modules = array();
 586      
 587      global $beanFiles,$beanList;
 588      //header('Content-type: text/xml');

 589      foreach($modules_arr as $module) {
 590          require_once($beanFiles[$beanList[$module]]);
 591          $focus = new $beanList[$module];
 592          $meta_modules[$module] = array();
 593          $meta_modules[$module]['field_defs'] = $focus->field_defs;
 594      }
 595      
 596      $str .= $global_registry_var_name.".meta.modules.Meetings = ". $json->encode($meta_modules['Meetings'], true)."\n";
 597      $str .= $global_registry_var_name.".meta.modules.Calls = ". $json->encode($meta_modules['Calls'], true)."\n";
 598      return $str;
 599  }
 600  
 601  function getFocusData() {
 602      global $json,$global_registry_var_name;
 603  
 604      if(empty($_REQUEST['module']) )
 605          return '';
 606      elseif(empty($_REQUEST['record'] ) )
 607          return "\n".$global_registry_var_name.'["focus"] = {"module":"'.$_REQUEST['module'].'",users_arr:[],fields:{"id":"-1"}}'."\n";
 608  
 609      $module_arr = meeting_retrieve($_REQUEST['module'], $_REQUEST['record']);
 610      return "\n".$global_registry_var_name."['focus'] = ". $json->encode($module_arr, true).";\n";
 611  }
 612  
 613  function getStringsJSON() {
 614      //set module and application string arrays based upon selected language

 615      global $current_language;
 616      global $json,$global_registry_var_name;
 617      
 618      $currentModule = 'Calendar';
 619      $mod_list_strings = return_mod_list_strings_language($current_language,$currentModule);
 620      $str = "\n".$global_registry_var_name."['calendar_strings'] =    {\"dom_cal_month_long\":". $json->encode($mod_list_strings['dom_cal_month_long']).",\"dom_cal_weekdays_long\":". $json->encode($mod_list_strings['dom_cal_weekdays_long'])."}\n";
 621      
 622      if(empty($_REQUEST['module']))
 623          $_REQUEST['module'] = 'Home';
 624      
 625      $currentModule = $_REQUEST['module'];
 626      $mod_strings = return_module_language($current_language,$currentModule);
 627      return $str . "\n".$global_registry_var_name."['meeting_strings'] =    ". $json->encode($mod_strings, true)."\n";
 628  }
 629  ////    END UTILS

 630  ///////////////////////////////////////////////////////////////////////////////

 631  
 632  
 633  
 634  ///////////////////////////////////////////////////////////////////////////////

 635  ////    JSON SERVER HANDLER LOGIC

 636  //ignore notices

 637  error_reporting(E_ALL ^ E_NOTICE);
 638  ob_start();
 639  insert_charset_header();
 640  
 641  if(!empty($sugar_config['session_dir'])) {
 642      session_save_path($sugar_config['session_dir']);
 643      $GLOBALS['log']->debug("JSON_SERVER:session_save_path:".$sugar_config['session_dir']);
 644  }
 645  
 646  session_start();
 647  $GLOBALS['log']->debug("JSON_SERVER:session started");
 648  
 649  $current_language = 'en_us'; // defaulting - will be set by user, then sys prefs

 650  
 651  // create json parser

 652  $json = getJSONobj();
 653  
 654  // if the language is not set yet, then set it to the default language.

 655  if(isset($_SESSION['authenticated_user_language']) && $_SESSION['authenticated_user_language'] != '') {
 656      $current_language = $_SESSION['authenticated_user_language'];
 657  } else {
 658      $current_language = $sugar_config['default_language'];
 659  }
 660  
 661  $locale = new Localization();
 662  
 663  $GLOBALS['log']->debug("JSON_SERVER: current_language:".$current_language);
 664  
 665  // if this is a get, than this is spitting out static javascript as if it was a file

 666  // wp: DO NOT USE THIS. Include the javascript inline using include/json_config.php

 667  // using <script src=json_server.php></script> does not cache properly on some browsers

 668  // resulting in 2 or more server hits per page load. Very bad for SSL. 

 669  if(strtolower($_SERVER['REQUEST_METHOD'])== 'get') {
 670      echo "alert('DEPRECATED API\nPlease report as a bug.');";
 671      /**

 672       * Deprecated for security reasons.

 673       * 

 674       * DO NOT USE.

 675       * 

 676       * 

 677      $current_user = authenticate();

 678      if(empty($current_user)) {

 679          $GLOBALS['log']->debug("JSON_SERVER: current_user isn't set");

 680          print "";

 681      }

 682  

 683      $str = '';

 684      $str .= getAppMetaJSON();

 685      $GLOBALS['log']->debug("JSON_SERVER:getAppMetaJSON");

 686      

 687      if($_GET['module'] != '_configonly') {

 688          $str .= getFocusData();

 689          $GLOBALS['log']->debug("JSON_SERVER: getFocusData");

 690          $str .= getStringsJSON();

 691          $GLOBALS['log']->debug("JSON_SERVER:getStringsJSON");

 692      }

 693      

 694      $str .= getUserConfigJSON();

 695      $GLOBALS['log']->debug("JSON_SERVER:getUserConfigJSON");

 696      print $str;

 697       */
 698  } else {
 699      // else act as a JSON-RPC server for SugarCRM

 700      // create result array

 701      $response = array();
 702      $response['result'] = null;
 703      $response['id'] = "-1";
 704  
 705      // authenticate user

 706      $current_user = authenticate();
 707  
 708      if(empty($current_user)) {
 709          $response['error'] = array("error_msg"=>"not logged in");
 710          print $json->encode($response, true);
 711          print "not logged in";
 712      }
 713  
 714      // extract request

 715      if(isset($GLOBALS['HTTP_RAW_POST_DATA']))
 716          $request = $json->decode($GLOBALS['HTTP_RAW_POST_DATA'], true);
 717      else
 718          $request = $json->decode(file_get_contents("php://input"), true);
 719      
 720      
 721      if(!is_array($request)) {
 722          $response['error'] = array("error_msg"=>"malformed request");
 723          print $json->encode($response, true);
 724      }
 725  
 726      // make sure required RPC fields are set

 727      if(empty($request['method']) || empty($request['id'])) {
 728          $response['error'] = array("error_msg"=>"missing parameters");
 729          print $json->encode($response, true);
 730      }
 731      
 732      $response['id'] = $request['id'];
 733  
 734      if(in_array($request['method'], $SUPPORTED_METHODS)) {
 735          call_user_func('json_'.$request['method'],$request['id'],$request['params']);
 736      } else {
 737          $response['error'] = array("error_msg"=>"method:".$request["method"]." not supported");
 738          print $json->encode($response, true);
 739      }
 740  }
 741  
 742  ob_end_flush();
 743  sugar_cleanup();
 744  exit();
 745  ?>


Généré le : Tue Sep 11 10:48:47 2007 par Balluche grâce à PHPXref 0.7