iTx Technologies offre gratuitement
cet espace pour SugarCRM !

title

Body

[fermer]

/ -> json_server.php (source)

   1  <?php if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
   2  /*********************************************************************************
   3   * SugarCRM is a customer relationship management program developed by
   4   * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
   5   * 
   6   * This program is free software; you can redistribute it and/or modify it under
   7   * the terms of the GNU General Public License version 3 as published by the
   8   * Free Software Foundation with the addition of the following permission added
   9   * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10   * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  11   * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12   * 
  13   * This program is distributed in the hope that it will be useful, but WITHOUT
  14   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  16   * details.
  17   * 
  18   * You should have received a copy of the GNU General Public License along with
  19   * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21   * 02110-1301 USA.
  22   * 
  23   * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  24   * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  25   * 
  26   * The interactive user interfaces in modified source and object code versions
  27   * of this program must display Appropriate Legal Notices, as required under
  28   * Section 5 of the GNU General Public License version 3.
  29   * 
  30   * In accordance with Section 7(b) of the GNU General Public License version 3,
  31   * these Appropriate Legal Notices must retain the display of the "Powered by
  32   * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  33   * technical reasons, the Appropriate Legal Notices must display the words
  34   * "Powered by SugarCRM".
  35   ********************************************************************************/
  36  
  37  require_once ('soap/SoapHelperFunctions.php');
  38  $GLOBALS['log']->debug("JSON_SERVER:");
  39  $global_registry_var_name = 'GLOBAL_REGISTRY';
  40  
  41  ///////////////////////////////////////////////////////////////////////////////
  42  ////    SUPPORTED METHODS
  43  /*
  44   * ADD NEW METHODS TO THIS ARRAY:
  45   * then create a function called "function json_$method($request_id, &$params)"
  46   * where $method is the method name
  47   */
  48  $SUPPORTED_METHODS = array(
  49      'retrieve',
  50      'query',
  51      'set_accept_status',
  52      'get_user_array', 
  53      'get_objects_from_module', 
  54      'email', 
  55      'get_full_list'
  56  );
  57  
  58  /**
  59   * Generic retrieve for getting data from a sugarbean
  60   */
  61  function json_retrieve($request_id, &$params) {
  62      global $current_user;
  63      global $beanFiles,$beanList;
  64      $json = getJSONobj();
  65      
  66      $record = $params[0]['record'];
  67  
  68      require_once($beanFiles[$beanList[$params[0]['module']]]);
  69      $focus = new $beanList[$params[0]['module']];
  70      $focus->retrieve($record);
  71  
  72      // to get a simplified version of the sugarbean
  73      $module_arr = populateBean($focus);
  74  
  75      $response = array();
  76      $response['id'] = $request_id;
  77      $response['result'] = array("status"=>"success","record"=>$module_arr);
  78      $json_response = $json->encode($response, true);
  79      print $json_response;
  80  }
  81  
  82  function json_query($request_id, &$params) {
  83      global $response, $sugar_config;
  84      global $beanFiles, $beanList;
  85      $json = getJSONobj();
  86      
  87      if($sugar_config['list_max_entries_per_page'] < 31)    // override query limits
  88          $sugar_config['list_max_entries_per_page'] = 31;
  89  
  90      $args = $params[0];
  91      
  92      //decode condition parameter values..
  93      if(is_array($args['conditions'])) {
  94          foreach($args['conditions'] as $key=>$condition)    {        
  95              if(!empty($condition['value'])) {
  96                  $where = $json->decode(utf8_encode($condition['value']));
  97                  // cn: bug 12693 - API change due to CSRF security changes.
  98                  $where = empty($where) ? $condition['value'] : $where;
  99                  $args['conditions'][$key]['value'] = $where;
 100              }        
 101          }
 102      }
 103  
 104      $list_return = array();
 105      
 106      if(! empty($args['module'])) {
 107          $args['modules'] = array($args['module']);
 108      }
 109      
 110      foreach($args['modules'] as $module) {
 111          require_once($beanFiles[$beanList[$module]]);
 112          $focus = new $beanList[$module];
 113          
 114          $query_orderby = '';
 115          if(!empty($args['order'])) {
 116              $query_orderby = $args['order'];
 117          }
 118          $query_limit = '';
 119          if(!empty($args['limit'])) {
 120              $query_limit = $args['limit'];
 121          }
 122          $query_where = construct_where($args, $focus->table_name,$module);
 123          $list_arr = array();
 124          if($focus->ACLAccess('ListView', true)) {
 125              $focus->ungreedy_count=false;
 126              $curlist = $focus->get_list($query_orderby, $query_where, 0, $query_limit, -1, 0);
 127              $list_return = array_merge($list_return,$curlist['list']);
 128          }
 129      }
 130      
 131      $app_list_strings = null;
 132  
 133      for($i = 0;$i < count($list_return);$i++) {
 134          if(isset($list_return[$i]->emailAddress) && is_object($list_return[$i]->emailAddress)) {
 135              $list_return[$i]->emailAddress->handleLegacyRetrieve($list_return[$i]);
 136          }
 137          
 138          $list_arr[$i]= array();
 139          $list_arr[$i]['fields']= array();
 140          $list_arr[$i]['module']= $list_return[$i]->object_name;
 141          
 142          foreach($args['field_list'] as $field) {
 143              // handle enums
 144              if(    (isset($list_return[$i]->field_name_map[$field]['type']) && $list_return[$i]->field_name_map[$field]['type'] == 'enum') || 
 145                  (isset($list_return[$i]->field_name_map[$field]['custom_type']) && $list_return[$i]->field_name_map[$field]['custom_type'] == 'enum')) {
 146                  
 147                  // get fields to match enum vals
 148                  if(empty($app_list_strings)) {
 149                      if(isset($_SESSION['authenticated_user_language']) && $_SESSION['authenticated_user_language'] != '') $current_language = $_SESSION['authenticated_user_language'];
 150                      else $current_language = $sugar_config['default_language'];
 151                      $app_list_strings = return_app_list_strings_language($current_language);
 152                  }
 153                  
 154                  // match enum vals to text vals in language pack for return
 155                  if(!empty($app_list_strings[$list_return[$i]->field_name_map[$field]['options']])) {
 156                      $list_return[$i]->$field = $app_list_strings[$list_return[$i]->field_name_map[$field]['options']][$list_return[$i]->$field];
 157                  }
 158              }
 159  
 160              $list_arr[$i]['fields'][$field] = $list_return[$i]->$field;
 161          }
 162      }
 163  
 164  
 165      $response['id'] = $request_id;
 166      $response['result'] = array("list"=>$list_arr);
 167      $json_response = $json->encode($response, true);
 168      echo $json_response;
 169  }
 170  
 171  
 172  function json_set_accept_status($request_id, &$params) {
 173      global $current_user;
 174      global $beanFiles,$beanList;
 175      $json = getJSONobj();
 176       require_once($beanFiles[$beanList[$params[0]['module']]]);
 177      
 178      $focus = new $beanList[$params[0]['module']];
 179      $focus->id = $params[0]['record'];
 180      
 181      $test = $focus->set_accept_status($current_user,$params[0]['accept_status']);
 182      
 183      $response = array();
 184      $response['id'] = $request_id;
 185      $response['result'] = array("status"=>"success","record"=>$params[0]['record'],'accept_status'=>$params[0]['accept_status']);
 186      $json_response = $json->encode($response, true);
 187      print $json_response;
 188  }
 189  
 190  
 191  /**
 192   * retrieves Users matching passed criteria
 193   */
 194  function json_get_user_array($request_id, &$params) {
 195      $json = getJSONobj();
 196      $args = $params[0];
 197      
 198      //decode condition parameter values..
 199      if(is_array($args['conditions'])) {
 200          foreach($args['conditions'] as $key=>$condition) {        
 201              if(!empty($condition['value'])) {
 202                  $args['conditions'][$key]['value']=$json->decode($condition['value']);
 203              }
 204          }
 205      }
 206      
 207      $response = array();
 208      $response['id'] = $request_id;
 209      $response['result'] = array();
 210      $response['result']['list'] = array();
 211      
 212      if(showFullName()) {
 213          $user_array = getUserArrayFromFullName($args['conditions'][0]['value']);
 214      } else {
 215           $user_array = get_user_array(false, "Active", $focus->assigned_user_id, false, $args['conditions'][0]['value']);
 216      }
 217      
 218      foreach($user_array as $id=>$name) {
 219          array_push($response['result']['list'], array('fields' => array('id' => $id, 'user_name' => $name), 'module' => 'Users'));
 220      }
 221  
 222      print $json->encode($response, true);
 223  }
 224  
 225  function json_get_objects_from_module($request_id, &$params) {
 226      global $beanList, $beanFiles, $current_user;
 227      $json = getJSONobj();
 228      
 229      $module_name = $params[0]['module'];
 230      $offset = intval($params[0]['offset']);
 231      $where = $params[0]['where'];
 232      $max = $params[0]['max'];
 233      $order_by = $params[0]['order_by'];
 234      $using_cp = false;
 235      
 236      if($module_name == 'CampaignProspects'){
 237          $module_name = 'Prospects';   
 238          $using_cp = true;
 239      }
 240  
 241      $class_name = $beanList[$module_name];
 242      require_once($beanFiles[$class_name]);
 243      $seed = new $class_name();
 244      if($where == ''){
 245          $where = '';
 246      }
 247      if($offset == '' || $offset == -1){
 248          $offset = 0;
 249      }
 250      if($max == ''){
 251          $max = 10;
 252      }
 253  
 254      $deleted = '0';
 255       if($using_cp){
 256           $fields = array('id', 'first_name', 'last_name');
 257         $response = $seed->retrieveTargetList($where, $fields, $offset,-1,$max,$deleted);
 258      }else{
 259        $response = $seed->get_list($order_by, $where, $offset,-1,$max,$deleted);
 260      }
 261       
 262      $list = $response['list'];
 263      $row_count = $response['row_count'];
 264  
 265      $output_list = array();
 266      foreach($list as $value)
 267      {
 268          $output_list[] = get_return_value($value, $module_name);
 269      }
 270      $response = array();
 271      $response['id'] = $request_id;
 272     
 273      $response['result'] = array('result_count'=>$row_count,'entry_list'=>$output_list);
 274      $json_response = $json->encode($response, true);
 275      print $json_response;
 276  }
 277  
 278  
 279  
 280  
 281  function json_email($request_id, &$params) {
 282      global $response, $sugar_config;
 283      global $beanFiles,$beanList;
 284      $json = getJSONobj();
 285      
 286      $args = $params[0];
 287  
 288      if($sugar_config['list_max_entries_per_page'] < 50)    // override query limits
 289          $sugar_config['list_max_entries_per_page'] = 50;
 290  
 291      $list_return = array();
 292  
 293      if(! empty($args['module'])) {
 294          $args['modules'] = array($args['module']);
 295      }
 296  
 297      foreach($args['modules'] as $module) {
 298          require_once($beanFiles[$beanList[$module]]);
 299          $focus = new $beanList[$module];
 300      
 301          $query_orderby = '';
 302          if(!empty($args['order'])) {
 303              $query_orderby = $args['order'];
 304          }
 305          $query_limit = '';
 306          if(!empty($args['limit'])) {
 307              $query_limit = $args['limit'];
 308          }
 309          $query_where = construct_where($args,$focus->table_name);
 310          $list_arr = array();
 311      
 312          $curlist = $focus->get_list($query_orderby, $query_where, 0, $query_limit, -1, 0);
 313          $list_return = array_merge($list_return,$curlist['list']);
 314      }
 315  
 316      for($i = 0;$i < count($list_return);$i++) {
 317          $list_arr[$i]= array();
 318          $list_arr[$i]['fields']= array();
 319          $list_arr[$i]['module']= $list_return[$i]->object_name;
 320      
 321          foreach($args['field_list'] as $field) {
 322              $list_arr[$i]['fields'][$field] = $list_return[$i]->$field;
 323          }
 324      }
 325  
 326      $response['id'] = $request_id;
 327      $response['result'] = array("list"=>$list_arr);
 328      $json_response = $json->encode($response, true);
 329      echo $json_response;
 330  }
 331  
 332  
 333  function json_get_full_list($request_id, &$params) {
 334      global $beanFiles;
 335      global $beanList;
 336      $json = getJSONobj();
 337      require_once($beanFiles[$beanList[$params[0]['module']]]);
 338  
 339      $where = str_replace('\\','', rawurldecode($params[0]['where']));
 340      $order = str_replace('\\','', rawurldecode($params[0]['order']));
 341      $focus = new $beanList[$params[0]['module']];
 342      
 343      $fullList = $focus->get_full_list($order, $where, '');
 344      $all_fields = array_merge($focus->column_fields,$focus->additional_column_fields);
 345  
 346      $js_fields_arr = array();
 347  
 348      if(isset($fullList) && !empty($fullList)) { // json error if this isn't defensive
 349          $i=0; 
 350          foreach($fullList as $note) {
 351              $js_fields_arr[$i] = array();
 352              
 353              foreach($all_fields as $field) {
 354                  if(isset($note->$field)) {
 355                      $note->$field = from_html($note->$field);
 356                      $note->$field = preg_replace('/\r\n/','<BR>',$note->$field);
 357                      $note->$field = preg_replace('/\n/','<BR>',$note->$field);
 358                      $js_fields_arr[$i][$field] = addslashes($note->$field);
 359                  }
 360              }
 361              $i++;
 362          }
 363      }
 364      
 365      $fin['id'] = $request_id;
 366      $fin['result'] = $js_fields_arr;
 367      $out = $json->encode($fin, true);
 368      
 369      print($out);
 370  }
 371  ////    END SUPPORTED METHODS
 372  ///////////////////////////////////////////////////////////////////////////////
 373  
 374  
 375  
 376  
 377  
 378  
 379  
 380  
 381  
 382  
 383  
 384  // ONLY USED FOR MEETINGS
 385  function meeting_retrieve($module,$record) {
 386      global $response;
 387      global $beanFiles,$beanList;
 388      //header('Content-type: text/xml');
 389      require_once($beanFiles[$beanList[$module]]);
 390      $focus = new $beanList[$module];
 391      $json = getJSONobj();
 392      
 393      if(empty($module) || empty($record))
 394      {
 395          $response['error'] = array("error_msg"=>"method: retrieve: missing module or record as parameters");
 396          print $json->encode($response, true);
 397          
 398      }
 399  
 400      $focus->retrieve($record);
 401      
 402      $GLOBALS['log']->debug("JSON_SERVER:retrieved meeting:");
 403      
 404      $module_arr = populateBean($focus);
 405  
 406      if($module == 'Meetings')
 407      {
 408          $users = $focus->get_meeting_users();
 409      } else if($module == 'Calls')
 410      {
 411          $users = $focus->get_call_users();
 412      }
 413  
 414      $module_arr['users_arr'] = array();
 415  
 416      foreach($users as $user)
 417      {
 418          array_push($module_arr['users_arr'],    populateBean($user));
 419      }
 420      $module_arr['orig_users_arr_hash'] = array();
 421      foreach($users as $user)
 422      {
 423      $module_arr['orig_users_arr_hash'][$user->id] = '1';
 424      }
 425  
 426      $module_arr['contacts_arr'] = array();
 427  
 428      $focus->load_relationships('contacts');
 429      $contacts=$focus->get_linked_beans('contacts','Contact');
 430      foreach($contacts as $contact)
 431      {
 432          array_push($module_arr['users_arr'], populateBean($contact));
 433      }
 434  
 435      return $module_arr;
 436  }
 437  
 438  // HAS MEETING SPECIFIC CODE:
 439  function populateBean(&$focus) {
 440      $all_fields = $focus->list_fields;
 441      // MEETING SPECIFIC
 442      $all_fields = array_merge($all_fields,array('required','accept_status','name')); // need name field for contacts and users
 443      //$all_fields = array_merge($focus->column_fields,$focus->additional_column_fields);
 444  
 445      $module_arr = array();
 446  
 447      $module_arr['module'] = $focus->object_name;
 448  
 449      $module_arr['fields'] = array();
 450  
 451      foreach($all_fields as $field)
 452      {
 453          if(isset($focus->$field))
 454          {
 455              $focus->$field =    from_html($focus->$field);
 456              $focus->$field =    preg_replace("/\r\n/","<BR>",$focus->$field);
 457              $focus->$field =    preg_replace("/\n/","<BR>",$focus->$field);
 458              $module_arr['fields'][$field] = $focus->$field;
 459          }
 460      }
 461  $GLOBALS['log']->debug("JSON_SERVER:populate bean:");
 462      return $module_arr;
 463  }
 464  
 465  
 466  
 467  
 468  
 469  
 470  
 471  
 472  
 473  
 474  
 475  
 476  function getUserJSON() {
 477  }
 478  
 479  
 480  function getUserConfigJSON() {
 481   require_once ('include/TimeDate.php');
 482   $td = new TimeDate();
 483   global $current_user,$global_registry_var_name,$json,$_SESSION,$sugar_config;
 484  
 485   if(isset($_SESSION['authenticated_user_theme']) && $_SESSION['authenticated_user_theme'] != '')
 486   {
 487      $theme = $_SESSION['authenticated_user_theme'];
 488   }
 489   else
 490   {
 491      $theme = $sugar_config['default_theme'];
 492   }
 493   $user_arr = array();
 494   $user_arr['theme'] = $theme;
 495   $user_arr['fields'] = array();
 496   $user_arr['module'] = 'User';
 497   $user_arr['fields']['id'] = $current_user->id;
 498   $user_arr['fields']['user_name'] = $current_user->user_name;
 499   $user_arr['fields']['first_name'] = $current_user->first_name;
 500   $user_arr['fields']['last_name'] = $current_user->last_name;
 501   $user_arr['fields']['email'] = $current_user->email1;
 502   $userTz = $td->getUserTimeZone();
 503   $dstRange = $td->getDSTRange(date('Y'), $userTz);
 504   $user_arr['fields']['dst_start'] = $dstRange['start'];
 505   $user_arr['fields']['dst_end'] = $dstRange['end'];
 506   $user_arr['fields']['gmt_offset'] = $userTz['gmtOffset'];
 507   $str = "\n".$global_registry_var_name.".current_user = ".$json->encode($user_arr, true).";\n";
 508  return $str;
 509  
 510  }
 511  
 512  
 513  
 514  
 515  
 516  
 517  ///////////////////////////////////////////////////////////////////////////////
 518  ////    UTILS
 519  function authenticate() {
 520      global $sugar_config;
 521  
 522      $user_unique_key =(isset($_SESSION['unique_key'])) ? $_SESSION['unique_key'] : "";
 523      $server_unique_key =(isset($sugar_config['unique_key'])) ? $sugar_config['unique_key'] : "";
 524  
 525      if($user_unique_key != $server_unique_key) {
 526          $GLOBALS['log']->debug("JSON_SERVER: user_unique_key:".$user_unique_key."!=".$server_unique_key);
 527          session_destroy();
 528          return null;
 529      }
 530  
 531      if(!isset($_SESSION['authenticated_user_id'])) {
 532          $GLOBALS['log']->debug("JSON_SERVER: authenticated_user_id NOT SET. DESTROY");
 533          session_destroy();
 534          return null;
 535      }
 536  
 537      $current_user = new User();
 538  
 539      $result = $current_user->retrieve($_SESSION['authenticated_user_id']);
 540      $GLOBALS['log']->debug("JSON_SERVER: retrieved user from SESSION");
 541  
 542  
 543      if($result == null) {
 544          $GLOBALS['log']->debug("JSON_SERVER: could get a user from SESSION. DESTROY");
 545          session_destroy();
 546          return null;
 547      }
 548  
 549      return $result;
 550  }
 551  
 552  function construct_where(&$query_obj, $table='',$module=null) {
 553      if(! empty($table)) {
 554          $table .= ".";
 555      }
 556      $cond_arr = array();
 557  
 558      if(! is_array($query_obj['conditions'])) {
 559          $query_obj['conditions'] = array();
 560      }
 561  
 562      foreach($query_obj['conditions'] as $condition) {
 563  
 564          if ($condition['name']=='email1' or $condition['name']=='email2') {
 565  
 566              $email1_value=strtoupper($condition['value']);
 567              $email1_condition = " {$table}id in ( SELECT  er.bean_id AS id FROM email_addr_bean_rel er, " .
 568                   "email_addresses ea WHERE ea.id = er.email_address_id " .
 569                   "AND ea.deleted = 0 AND er.deleted = 0 AND er.bean_module = '{$module}' AND email_address_caps IN ('{$email1_value}') )";
 570                   
 571               array_push($cond_arr,$email1_condition);
 572          }
 573          else {
 574              if($condition['op'] == 'contains') {
 575                  $cond_arr[] = $GLOBALS['db']->quote($table.$condition['name'])." like '%".$GLOBALS['db']->quote($condition['value'])."%'";
 576              }
 577              if($condition['op'] == 'like_custom') {
 578                  $like = '';
 579                  if(!empty($condition['begin'])) $like .= $GLOBALS['db']->quote($condition['begin']);
 580                  $like .= $GLOBALS['db']->quote($condition['value']);
 581                  if(!empty($condition['end'])) $like .= $GLOBALS['db']->quote($condition['end']);
 582                  $cond_arr[] = $GLOBALS['db']->quote($table.$condition['name'])." like '$like'";
 583              } else { // starts_with
 584                  $cond_arr[] = $GLOBALS['db']->quote($table.$condition['name'])." like '".$GLOBALS['db']->quote($condition['value'])."%'";
 585              }
 586          }
 587      }
 588      
 589      if($table == 'users.') {
 590          $cond_arr[] = $table."status='Active'";
 591      }
 592      
 593      return implode(" {$query_obj['group']} ",$cond_arr);
 594  }
 595  
 596  function getAppMetaJSON() {
 597      global $global_registry_var_name, $sugar_config;
 598      $json = getJSONobj();
 599      
 600      $str = "\nvar ".$global_registry_var_name." = new Object();\n";
 601      $str .= "\n".$global_registry_var_name.".config = {\"site_url\":\"".getJavascriptSiteURL()."\"};\n";
 602      
 603      $str .= $global_registry_var_name.".meta = new Object();\n";
 604      $str .= $global_registry_var_name.".meta.modules = new Object();\n";
 605      $modules_arr = array('Meetings','Calls');
 606      $meta_modules = array();
 607      
 608      global $beanFiles,$beanList;
 609      //header('Content-type: text/xml');
 610      foreach($modules_arr as $module) {
 611          require_once($beanFiles[$beanList[$module]]);
 612          $focus = new $beanList[$module];
 613          $meta_modules[$module] = array();
 614          $meta_modules[$module]['field_defs'] = $focus->field_defs;
 615      }
 616      
 617      $str .= $global_registry_var_name.".meta.modules.Meetings = ". $json->encode($meta_modules['Meetings'], true)."\n";
 618      $str .= $global_registry_var_name.".meta.modules.Calls = ". $json->encode($meta_modules['Calls'], true)."\n";
 619      return $str;
 620  }
 621  
 622  function getFocusData() {
 623      global $global_registry_var_name;
 624      $json = getJSONobj();
 625      
 626      if(empty($_REQUEST['module']) )
 627          return '';
 628      elseif(empty($_REQUEST['record'] ) )
 629          return "\n".$global_registry_var_name.'["focus"] = {"module":"'.$_REQUEST['module'].'",users_arr:[],fields:{"id":"-1"}}'."\n";
 630  
 631      $module_arr = meeting_retrieve($_REQUEST['module'], $_REQUEST['record']);
 632      return "\n".$global_registry_var_name."['focus'] = ". $json->encode($module_arr, true).";\n";
 633  }
 634  
 635  function getStringsJSON() {
 636      //set module and application string arrays based upon selected language
 637      global $current_language;
 638      global $global_registry_var_name;
 639      $json = getJSONobj();
 640      
 641      $currentModule = 'Calendar';
 642      $mod_list_strings = return_mod_list_strings_language($current_language,$currentModule);
 643      $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";
 644      
 645      if(empty($_REQUEST['module']))
 646          $_REQUEST['module'] = 'Home';
 647      
 648      $currentModule = $_REQUEST['module'];
 649      $mod_strings = return_module_language($current_language,$currentModule);
 650      return $str . "\n".$global_registry_var_name."['meeting_strings'] =    ". $json->encode($mod_strings, true)."\n";
 651  }
 652  ////    END UTILS
 653  ///////////////////////////////////////////////////////////////////////////////
 654  
 655  
 656  
 657  ///////////////////////////////////////////////////////////////////////////////
 658  ////    JSON SERVER HANDLER LOGIC
 659  //ignore notices
 660  error_reporting(E_ALL ^ E_NOTICE);
 661  ob_start();
 662  insert_charset_header();
 663  
 664  if(!empty($sugar_config['session_dir'])) {
 665      session_save_path($sugar_config['session_dir']);
 666      $GLOBALS['log']->debug("JSON_SERVER:session_save_path:".$sugar_config['session_dir']);
 667  }
 668  
 669  session_start();
 670  $GLOBALS['log']->debug("JSON_SERVER:session started");
 671  
 672  $current_language = 'en_us'; // defaulting - will be set by user, then sys prefs
 673  
 674  // create json parser
 675  $json = getJSONobj();
 676  
 677  // if the language is not set yet, then set it to the default language.
 678  if(isset($_SESSION['authenticated_user_language']) && $_SESSION['authenticated_user_language'] != '') {
 679      $current_language = $_SESSION['authenticated_user_language'];
 680  } else {
 681      $current_language = $sugar_config['default_language'];
 682  }
 683  
 684  $locale = new Localization();
 685  
 686  $GLOBALS['log']->debug("JSON_SERVER: current_language:".$current_language);
 687  
 688  // if this is a get, than this is spitting out static javascript as if it was a file
 689  // wp: DO NOT USE THIS. Include the javascript inline using include/json_config.php
 690  // using <script src=json_server.php></script> does not cache properly on some browsers
 691  // resulting in 2 or more server hits per page load. Very bad for SSL. 
 692  if(strtolower($_SERVER['REQUEST_METHOD'])== 'get') {
 693      echo "alert('DEPRECATED API\nPlease report as a bug.');";
 694      /**
 695       * Deprecated for security reasons.
 696       * 
 697       * DO NOT USE.
 698       * 
 699       * 
 700      $current_user = authenticate();
 701      if(empty($current_user)) {
 702          $GLOBALS['log']->debug("JSON_SERVER: current_user isn't set");
 703          print "";
 704      }
 705  
 706      $str = '';
 707      $str .= getAppMetaJSON();
 708      $GLOBALS['log']->debug("JSON_SERVER:getAppMetaJSON");
 709      
 710      if($_GET['module'] != '_configonly') {
 711          $str .= getFocusData();
 712          $GLOBALS['log']->debug("JSON_SERVER: getFocusData");
 713          $str .= getStringsJSON();
 714          $GLOBALS['log']->debug("JSON_SERVER:getStringsJSON");
 715      }
 716      
 717      $str .= getUserConfigJSON();
 718      $GLOBALS['log']->debug("JSON_SERVER:getUserConfigJSON");
 719      print $str;
 720       */
 721  } else {
 722      // else act as a JSON-RPC server for SugarCRM
 723      // create result array
 724      $response = array();
 725      $response['result'] = null;
 726      $response['id'] = "-1";
 727  
 728      // authenticate user
 729      $current_user = authenticate();
 730  
 731      if(empty($current_user)) {
 732          $response['error'] = array("error_msg"=>"not logged in");
 733          print $json->encode($response, true);
 734          print "not logged in";
 735      }
 736  
 737      // extract request
 738      if(isset($GLOBALS['HTTP_RAW_POST_DATA']))
 739          $request = $json->decode($GLOBALS['HTTP_RAW_POST_DATA'], true);
 740      else
 741          $request = $json->decode(file_get_contents("php://input"), true);
 742      
 743      
 744      if(!is_array($request)) {
 745          $response['error'] = array("error_msg"=>"malformed request");
 746          print $json->encode($response, true);
 747      }
 748  
 749      // make sure required RPC fields are set
 750      if(empty($request['method']) || empty($request['id'])) {
 751          $response['error'] = array("error_msg"=>"missing parameters");
 752          print $json->encode($response, true);
 753      }
 754      
 755      $response['id'] = $request['id'];
 756  
 757      if(in_array($request['method'], $SUPPORTED_METHODS)) {
 758          call_user_func('json_'.$request['method'],$request['id'],$request['params']);
 759      } else {
 760          $response['error'] = array("error_msg"=>"method:".$request["method"]." not supported");
 761          print $json->encode($response, true);
 762      }
 763  }
 764  
 765  ob_end_flush();
 766  sugar_cleanup();
 767  exit();
 768  ?>


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