[ Index ]
 

Code source de SugarCRM 5.0.0beta1

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

title

Body

[fermer]

/ -> json.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  
  36  ///////////////////////////////////////////////////////////////////////////////

  37  ////    HELPER FUNCTIONS

  38  function json_retrieve() {
  39      global $beanFiles,$beanList;
  40      require_once($beanFiles[$beanList[$_REQUEST['module']]]);
  41  
  42      $json = getJSONobj();
  43      
  44      $focus = new $beanList[$_REQUEST['module']];
  45      $focus->retrieve($_REQUEST['record']);
  46  
  47      $all_fields = array_merge($focus->column_fields,$focus->additional_column_fields);
  48  
  49      $obj = array();
  50      $ret = array();
  51  
  52      foreach($all_fields as $field) {
  53          if(isset($focus->$field)) {
  54              $obj[$field] = $focus->$field;
  55          }
  56      }
  57  
  58      // cn: bug 12274 - defend against CSRF

  59      $ret['fields'] = $obj;
  60      print $json->encode($ret, true);
  61  }
  62  
  63  function json_get_full_list() {
  64      global $beanFiles;
  65      global $beanList;
  66  
  67      require_once ('include/utils.php');
  68      require_once($beanFiles[$beanList[$_REQUEST['module']]]);
  69  
  70      $json = getJSONobj();
  71  
  72      $where = str_replace('\\','', rawurldecode($_REQUEST['where']));
  73      $order = str_replace('\\','', rawurldecode($_REQUEST['order']));
  74      $focus = new $beanList[$_REQUEST['module']];
  75      $fullList = $focus->get_full_list($order, $where, '');
  76      $all_fields = array_merge($focus->column_fields,$focus->additional_column_fields);
  77  
  78      $js_fields_arr = array();
  79      
  80      $i=1; // js doesn't like 0 index?

  81      foreach($fullList as $note) {
  82          $js_fields_arr[$i] = array();
  83          
  84          foreach($all_fields as $field) {
  85              if(isset($note->$field)) {
  86                  $note->$field = from_html($note->$field);
  87                  $note->$field = preg_replace('/\r\n/','<BR>',$note->$field);
  88                  $note->$field = preg_replace('/\n/','<BR>',$note->$field);
  89                  $js_fields_arr[$i][$field] = addslashes($note->$field);
  90              }
  91          }
  92          $i++;
  93      }
  94      
  95      $out = $json->encode($js_fields_arr, true);
  96      print($out);
  97  }
  98  ////    END HELPER FUNCTIONS

  99  ///////////////////////////////////////////////////////////////////////////////

 100  
 101  
 102  clean_special_arguments();
 103  
 104  // called from another file

 105  $GLOBALS['log'] = LoggerManager::getLogger('json.php');
 106  
 107  // check for old config format.

 108  if(empty($sugar_config) && isset($dbconfig['db_host_name'])) {
 109     make_sugar_config($sugar_config);
 110  }
 111  
 112  insert_charset_header();
 113  
 114  if(!empty($sugar_config['session_dir'])) {
 115      session_save_path($sugar_config['session_dir']);
 116  }
 117  
 118  session_start();
 119  
 120  $user_unique_key = (isset($_SESSION['unique_key'])) ? $_SESSION['unique_key'] : "";
 121  $server_unique_key = (isset($sugar_config['unique_key'])) ? $sugar_config['unique_key'] : "";
 122  
 123  if($user_unique_key != $server_unique_key) {
 124      session_destroy();
 125      header('Location: index.php?action=Login&module=Users');
 126      exit();
 127  }
 128  
 129  if(!isset($_SESSION['authenticated_user_id'])) {
 130      // TODO change this to a translated string.

 131      session_destroy();
 132      die('An active session is required to export content');
 133  }
 134  
 135  $current_user = new User();
 136  
 137  $result = $current_user->retrieve($_SESSION['authenticated_user_id']);
 138  if($result == null) {
 139      session_destroy();
 140      die('An active session is required to export content');
 141  }
 142  
 143  $supported_functions = array('retrieve','get_full_list');
 144  if(in_array($_REQUEST['action'],$supported_functions)) {
 145      call_user_func('json_'.$_REQUEST['action']);
 146  }
 147  
 148  sugar_cleanup();
 149  ?>


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