iTx Technologies offre gratuitement
cet espace pour SugarCRM !

title

Body

[fermer]

/include/ -> json_config.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  
  39   * Description:  This class is used to include the json server config inline. Previous method
  40   * of using <script src=json_server.php></script> causes multiple server hits per page load
  41   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  42   * All Rights Reserved.
  43   * Contributor(s): ______________________________________..
  44   ********************************************************************************/
  45  
  46  global $app_strings, $json;
  47  $json = getJSONobj();
  48  
  49  class json_config {
  50      var $global_registry_var_name = 'GLOBAL_REGISTRY';
  51      
  52  	function get_static_json_server($configOnly = true, $getStrings = false, $module = null, $record = null, $scheduler = false) {
  53          global $current_user;
  54          $str = '';
  55          $str .= $this->getAppMetaJSON($scheduler);
  56          if(!$configOnly) {
  57              $str .= $this->getFocusData($module, $record);
  58              if($getStrings)    $str .= $this->getStringsJSON($module);
  59          }
  60          $str .= $this->getUserConfigJSON();
  61  
  62          return $str; 
  63      }
  64      
  65  	function getAppMetaJSON($scheduler = false) {
  66          
  67          global $json, $sugar_config;
  68          
  69          $str = "\nvar ". $this->global_registry_var_name." = new Object();\n";
  70          $str .= "\n".$this->global_registry_var_name.".config = {\"site_url\":\"".getJavascriptSiteURL()."\"};\n";
  71          
  72          $str .= $this->global_registry_var_name.".meta = new Object();\n";
  73          $str .= $this->global_registry_var_name.".meta.modules = new Object();\n";
  74          
  75          /*
  76          $modules_arr = array('Meetings','Calls');
  77          $meta_modules = array();
  78              
  79          global $beanFiles,$beanList;
  80          //header('Content-type: text/xml');
  81          foreach($modules_arr as $module) {
  82              require_once($beanFiles[$beanList[$module]]);
  83              $focus = new $beanList[$module];
  84              $meta_modules[$module] = array();
  85              $meta_modules[$module]['field_defs'] = $focus->field_defs;
  86          }
  87          
  88          $str .= $this->global_registry_var_name.".meta.modules.Meetings = ". $json->encode($meta_modules['Meetings'])."\n";
  89          $str .= $this->global_registry_var_name.".meta.modules.Calls = ". $json->encode($meta_modules['Calls'])."\n";
  90          */
  91          return $str;
  92      }
  93      
  94  	function getUserConfigJSON() {
  95          global $timedate;
  96          global $current_user, $sugar_config;
  97          $json = getJSONobj();
  98          if(isset($_SESSION['authenticated_user_theme']) && $_SESSION['authenticated_user_theme'] != '')    {
  99              $theme = $_SESSION['authenticated_user_theme'];
 100          }
 101          else {
 102              $theme = $sugar_config['default_theme'];
 103          }
 104          $user_arr = array();
 105          $user_arr['theme'] = $theme;
 106          $user_arr['fields'] = array();
 107          $user_arr['module'] = 'User';
 108          $user_arr['fields']['id'] = $current_user->id;
 109          $user_arr['fields']['user_name'] = $current_user->user_name;
 110          $user_arr['fields']['first_name'] = $current_user->first_name;
 111          $user_arr['fields']['last_name'] = $current_user->last_name;
 112          $user_arr['fields']['full_name'] = $current_user->full_name;
 113          $user_arr['fields']['email'] = $current_user->email1;
 114          $userTz = $timedate->getUserTimeZone();
 115          $dstRange = $timedate->getDSTRange(date('Y'), $userTz);
 116          $user_arr['fields']['dst_start'] = $dstRange['start'];
 117          $user_arr['fields']['dst_end'] = $dstRange['end'];
 118          $user_arr['fields']['gmt_offset'] = $userTz['gmtOffset'];
 119          $user_arr['fields']['date_time_format'] = $current_user->getUserDateTimePreferences();
 120          $str = "\n".$this->global_registry_var_name.".current_user = ".$json->encode($user_arr).";\n";
 121          return $str;
 122      }
 123      
 124  	function getFocusData($module, $record) {
 125          global $json;
 126          if (empty($module)) {
 127              return '';
 128          }
 129          else if(empty($record)) {
 130              return "\n".$this->global_registry_var_name.'["focus"] = {"module":"'.$module.'",users_arr:[],fields:{"id":"-1"}}'."\n";
 131          }
 132      
 133          $module_arr = $this->meeting_retrieve($module, $record);
 134          return "\n".$this->global_registry_var_name."['focus'] = ". $json->encode($module_arr).";\n";
 135      }
 136      
 137  	function meeting_retrieve($module, $record) {
 138          global $json, $response;
 139          global $beanFiles, $beanList;
 140          require_once($beanFiles[$beanList[$module]]);
 141          $focus = new $beanList[$module];
 142          
 143          if(empty($module) || empty($record)) {
 144              return '';
 145          }
 146          
 147          $focus->retrieve($record);
 148          $module_arr = $this->populateBean($focus);
 149          
 150          if($module == 'Meetings') {
 151              $users = $focus->get_meeting_users();
 152          } 
 153          else if ( $module == 'Calls') {
 154              $users = $focus->get_call_users();
 155          }
 156  
 157          $module_arr['users_arr'] = array();
 158          
 159          foreach($users as $user) {
 160              array_push($module_arr['users_arr'],  $this->populateBean($user));
 161          }
 162          
 163          $module_arr['orig_users_arr_hash'] = array();
 164          
 165          foreach($users as $user) {
 166              $module_arr['orig_users_arr_hash'][$user->id] = '1';
 167          }
 168          
 169          $module_arr['contacts_arr'] = array();
 170          
 171          $focus->load_relationships('contacts');
 172          $contacts=$focus->get_linked_beans('contacts','Contact');
 173          foreach($contacts as $contact) {
 174              array_push($module_arr['users_arr'], $this->populateBean($contact));
 175            }
 176          
 177          $module_arr['leads_arr'] = array();
 178          
 179          $focus->load_relationships('leads');
 180          $leads=$focus->get_linked_beans('leads','Lead');
 181          foreach($leads as $lead) {
 182              array_push($module_arr['users_arr'], $this->populateBean($lead));
 183            }
 184      
 185          return $module_arr;
 186      }
 187      
 188  	function getStringsJSON($module) {
 189        global $current_language;
 190        $currentModule = 'Calendar';
 191        $mod_list_strings = return_mod_list_strings_language($current_language,$currentModule);
 192      
 193        global $json;
 194        $str = "\n".$this->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";
 195        if(empty($module)) {
 196          $module = 'Home';
 197        }
 198        $currentModule = $module;
 199        $mod_strings = return_module_language($current_language,$currentModule);
 200        return  $str . "\n".$this->global_registry_var_name."['meeting_strings'] =  ". $json->encode($mod_strings)."\n";
 201      }
 202      
 203      // HAS MEETING SPECIFIC CODE:
 204  	function populateBean(&$focus) {
 205          require_once ('include/utils/db_utils.php');
 206          $all_fields = $focus->list_fields;
 207          // MEETING SPECIFIC
 208          $all_fields = array_merge($all_fields,array('required','accept_status','name')); // need name field for contacts and users
 209          //$all_fields = array_merge($focus->column_fields,$focus->additional_column_fields);
 210          
 211          $module_arr = array();
 212          
 213          $module_arr['module'] = $focus->object_name;
 214          
 215          $module_arr['fields'] = array();
 216          
 217          foreach($all_fields as $field) {
 218              if(isset($focus->$field)) {
 219                  $focus->$field =  from_html($focus->$field);
 220                  $focus->$field =  preg_replace("/\r\n/","<BR>",$focus->$field);
 221                  $focus->$field =  preg_replace("/\n/","<BR>",$focus->$field);
 222                  $module_arr['fields'][$field] = $focus->$field;
 223              }
 224          }
 225              $GLOBALS['log']->debug("JSON_SERVER:populate bean:");
 226              return $module_arr;
 227          }
 228      }
 229  ?>


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