2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 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 $user_arr['fields']['gmt_offset'] = $timedate->getUserUTCOffset();
116 $user_arr['fields']['date_time_format'] = $current_user->getUserDateTimePreferences();
117 $str = "\n".$this->global_registry_var_name.".current_user = ".$json->encode($user_arr).";\n";
121 function getFocusData($module, $record) {
123 if (empty($module)) {
126 else if(empty($record)) {
127 return "\n".$this->global_registry_var_name.'["focus"] = {"module":"'.$module.'",users_arr:[],fields:{"id":"-1"}}'."\n";
130 $module_arr = $this->meeting_retrieve($module, $record);
131 return "\n".$this->global_registry_var_name."['focus'] = ". $json->encode($module_arr).";\n";
134 function meeting_retrieve($module, $record) {
135 global $json, $response;
136 global $beanFiles, $beanList;
137 require_once($beanFiles[$beanList[$module]]);
138 $focus = new $beanList[$module];
140 if(empty($module) || empty($record)) {
144 $focus->retrieve($record);
145 $module_arr = $this->populateBean($focus);
147 if($module == 'Meetings') {
148 $users = $focus->get_meeting_users();
150 else if ( $module == 'Calls') {
151 $users = $focus->get_call_users();
154 $module_arr['users_arr'] = array();
156 foreach($users as $user) {
157 array_push($module_arr['users_arr'], $this->populateBean($user));
160 $module_arr['orig_users_arr_hash'] = array();
162 foreach($users as $user) {
163 $module_arr['orig_users_arr_hash'][$user->id] = '1';
166 $module_arr['contacts_arr'] = array();
168 $focus->load_relationships('contacts');
169 $contacts=$focus->get_linked_beans('contacts','Contact');
170 foreach($contacts as $contact) {
171 array_push($module_arr['users_arr'], $this->populateBean($contact));
173 $module_arr['leads_arr'] = array();
174 $focus->load_relationships('leads');
175 $leads=$focus->get_linked_beans('leads','Lead');
176 foreach($leads as $lead) {
177 array_push($module_arr['users_arr'], $this->populateBean($lead));
183 function getStringsJSON($module) {
184 global $current_language;
185 $currentModule = 'Calendar';
186 $mod_list_strings = return_mod_list_strings_language($current_language,$currentModule);
189 $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";
193 $currentModule = $module;
194 $mod_strings = return_module_language($current_language,$currentModule);
195 return $str . "\n".$this->global_registry_var_name."['meeting_strings'] = ". $json->encode($mod_strings)."\n";
198 // HAS MEETING SPECIFIC CODE:
199 function populateBean(&$focus) {
200 require_once('include/utils/db_utils.php');
201 $all_fields = $focus->column_fields;
203 $all_fields = array_merge($all_fields,array('required','accept_status','name')); // need name field for contacts and users
204 //$all_fields = array_merge($focus->column_fields,$focus->additional_column_fields);
206 $module_arr = array();
208 $module_arr['module'] = $focus->object_name;
210 $module_arr['fields'] = array();
212 foreach($all_fields as $field) {
213 if(isset($focus->$field) && !is_object($focus->$field)) {
214 $focus->$field = from_html($focus->$field);
215 $focus->$field = preg_replace("/\r\n/","<BR>",$focus->$field);
216 $focus->$field = preg_replace("/\n/","<BR>",$focus->$field);
217 $module_arr['fields'][$field] = $focus->$field;
220 $GLOBALS['log']->debug("JSON_SERVER:populate bean:");