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-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero 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.
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 Affero General Public License for more
19 * You should have received a copy of the GNU Affero 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
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.
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 Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero 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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: This class is used to include the json server config inline. Previous method
41 * of using <script src=json_server.php></script> causes multiple server hits per page load
42 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
43 * All Rights Reserved.
44 * Contributor(s): ______________________________________..
45 ********************************************************************************/
47 global $app_strings, $json;
51 var $global_registry_var_name = 'GLOBAL_REGISTRY';
53 function get_static_json_server($configOnly = true, $getStrings = false, $module = null, $record = null, $scheduler = false) {
56 $str .= $this->getAppMetaJSON($scheduler);
58 $str .= $this->getFocusData($module, $record);
59 if($getStrings) $str .= $this->getStringsJSON($module);
61 $str .= $this->getUserConfigJSON();
66 function getAppMetaJSON($scheduler = false) {
68 global $json, $sugar_config;
70 $str = "\nvar ". $this->global_registry_var_name." = new Object();\n";
71 $str .= "\n".$this->global_registry_var_name.".config = {\"site_url\":\"".getJavascriptSiteURL()."\"};\n";
73 $str .= $this->global_registry_var_name.".meta = new Object();\n";
74 $str .= $this->global_registry_var_name.".meta.modules = new Object();\n";
77 $modules_arr = array('Meetings','Calls');
78 $meta_modules = array();
80 global $beanFiles,$beanList;
81 //header('Content-type: text/xml');
82 foreach($modules_arr as $module) {
83 require_once($beanFiles[$beanList[$module]]);
84 $focus = new $beanList[$module];
85 $meta_modules[$module] = array();
86 $meta_modules[$module]['field_defs'] = $focus->field_defs;
89 $str .= $this->global_registry_var_name.".meta.modules.Meetings = ". $json->encode($meta_modules['Meetings'])."\n";
90 $str .= $this->global_registry_var_name.".meta.modules.Calls = ". $json->encode($meta_modules['Calls'])."\n";
95 function getUserConfigJSON() {
97 global $current_user, $sugar_config;
99 if(isset($_SESSION['authenticated_user_theme']) && $_SESSION['authenticated_user_theme'] != '') {
100 $theme = $_SESSION['authenticated_user_theme'];
103 $theme = $sugar_config['default_theme'];
106 $user_arr['theme'] = $theme;
107 $user_arr['fields'] = array();
108 $user_arr['module'] = 'User';
109 $user_arr['fields']['id'] = $current_user->id;
110 $user_arr['fields']['user_name'] = $current_user->user_name;
111 $user_arr['fields']['first_name'] = $current_user->first_name;
112 $user_arr['fields']['last_name'] = $current_user->last_name;
113 $user_arr['fields']['full_name'] = $current_user->full_name;
114 $user_arr['fields']['email'] = $current_user->email1;
115 $userTz = $timedate->getUserTimeZone();
116 $dstRange = $timedate->getDSTRange(date('Y'), $userTz);
117 $user_arr['fields']['dst_start'] = $dstRange['start'];
118 $user_arr['fields']['dst_end'] = $dstRange['end'];
119 $user_arr['fields']['gmt_offset'] = $userTz['gmtOffset'];
120 $user_arr['fields']['date_time_format'] = $current_user->getUserDateTimePreferences();
121 $str = "\n".$this->global_registry_var_name.".current_user = ".$json->encode($user_arr).";\n";
125 function getFocusData($module, $record) {
127 if (empty($module)) {
130 else if(empty($record)) {
131 return "\n".$this->global_registry_var_name.'["focus"] = {"module":"'.$module.'",users_arr:[],fields:{"id":"-1"}}'."\n";
134 $module_arr = $this->meeting_retrieve($module, $record);
135 return "\n".$this->global_registry_var_name."['focus'] = ". $json->encode($module_arr).";\n";
138 function meeting_retrieve($module, $record) {
139 global $json, $response;
140 global $beanFiles, $beanList;
141 require_once($beanFiles[$beanList[$module]]);
142 $focus = new $beanList[$module];
144 if(empty($module) || empty($record)) {
148 $focus->retrieve($record);
149 $module_arr = $this->populateBean($focus);
151 if($module == 'Meetings') {
152 $users = $focus->get_meeting_users();
154 else if ( $module == 'Calls') {
155 $users = $focus->get_call_users();
158 $module_arr['users_arr'] = array();
160 foreach($users as $user) {
161 array_push($module_arr['users_arr'], $this->populateBean($user));
164 $module_arr['orig_users_arr_hash'] = array();
166 foreach($users as $user) {
167 $module_arr['orig_users_arr_hash'][$user->id] = '1';
170 $module_arr['contacts_arr'] = array();
172 $focus->load_relationships('contacts');
173 $contacts=$focus->get_linked_beans('contacts','Contact');
174 foreach($contacts as $contact) {
175 array_push($module_arr['users_arr'], $this->populateBean($contact));
177 $module_arr['leads_arr'] = array();
178 $focus->load_relationships('leads');
179 $leads=$focus->get_linked_beans('leads','Lead');
180 foreach($leads as $lead) {
181 array_push($module_arr['users_arr'], $this->populateBean($lead));
187 function getStringsJSON($module) {
188 global $current_language;
189 $currentModule = 'Calendar';
190 $mod_list_strings = return_mod_list_strings_language($current_language,$currentModule);
193 $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";
197 $currentModule = $module;
198 $mod_strings = return_module_language($current_language,$currentModule);
199 return $str . "\n".$this->global_registry_var_name."['meeting_strings'] = ". $json->encode($mod_strings)."\n";
202 // HAS MEETING SPECIFIC CODE:
203 function populateBean(&$focus) {
204 require_once('include/utils/db_utils.php');
205 $all_fields = $focus->list_fields;
207 $all_fields = array_merge($all_fields,array('required','accept_status','name')); // need name field for contacts and users
208 //$all_fields = array_merge($focus->column_fields,$focus->additional_column_fields);
210 $module_arr = array();
212 $module_arr['module'] = $focus->object_name;
214 $module_arr['fields'] = array();
216 foreach($all_fields as $field) {
217 if(isset($focus->$field)) {
218 $focus->$field = from_html($focus->$field);
219 $focus->$field = preg_replace("/\r\n/","<BR>",$focus->$field);
220 $focus->$field = preg_replace("/\n/","<BR>",$focus->$field);
221 $module_arr['fields'][$field] = $focus->$field;
224 $GLOBALS['log']->debug("JSON_SERVER:populate bean:");