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-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 ********************************************************************************/
39 require_once('modules/ModuleBuilder/parsers/ModuleBuilderParser.php');
41 class ParserDropDown extends ModuleBuilderParser {
44 * Takes in the request params from a save request and processes
47 * @param REQUEST params $params
49 function saveDropDown($params){
50 require_once('modules/Administration/Common.php');
51 $emptyMarker = translate('LBL_BLANK');
52 $selected_lang = (!empty($params['dropdown_lang'])?$params['dropdown_lang']:$_SESSION['authenticated_user_language']);
53 $type = $_REQUEST['view_package'];
55 $dropdown_name = $params['dropdown_name'];
58 $list_value = str_replace('"":""', '"__empty__":""', $params['list_value']);
59 //Bug 21362 ENT_QUOTES- convert single quotes to escaped single quotes.
60 $temp = $json->decode(html_entity_decode(rawurldecode($list_value), ENT_QUOTES) );
61 $dropdown = array () ;
62 // dropdown is received as an array of (name,value) pairs - now extract to name=>value format preserving order
63 // we rely here on PHP to preserve the order of the received name=>value pairs - associative arrays in PHP are ordered
66 foreach ( $temp as $item )
68 $dropdown[ remove_xss(from_html($item [ 0 ])) ] = remove_xss(from_html($item [ 1 ])) ;
72 if(array_key_exists($emptyMarker, $dropdown)){
74 foreach($dropdown as $key => $value){
75 if($emptyMarker===$key)
83 if($type != 'studio'){
84 $mb = new ModuleBuilder();
85 $module =& $mb->getPackageModule($params['view_package'], $params['view_module']);
86 $this->synchMBDropDown($dropdown_name, $dropdown, $selected_lang, $module);
87 //Can't use synch on selected lang as we want to overwrite values, not just keys
88 $module->mblanguage->appListStrings[$selected_lang.'.lang.php'][$dropdown_name] = $dropdown;
89 $module->mblanguage->save($module->key_name); // tyoung - key is required parameter as of
91 $contents = return_custom_app_list_strings_file_contents($selected_lang);
92 $my_list_strings = return_app_list_strings_language($selected_lang);
93 if($selected_lang == $GLOBALS['current_language']){
94 $GLOBALS['app_list_strings'][$dropdown_name] = $dropdown;
97 $contents = str_replace("?>", '', $contents);
98 if(empty($contents))$contents = "<?php";
99 //add new drop down to the bottom
100 if(!empty($params['use_push'])){
101 //this is for handling moduleList and such where nothing should be deleted or anything but they can be renamed
102 foreach($dropdown as $key=>$value){
103 //only if the value has changed or does not exist do we want to add it this way
104 if(!isset($my_list_strings[$dropdown_name][$key]) || strcmp($my_list_strings[$dropdown_name][$key], $value) != 0 ){
105 //clear out the old value
106 $pattern_match = '/\s*\$app_list_strings\s*\[\s*\''.$dropdown_name.'\'\s*\]\[\s*\''.$key.'\'\s*\]\s*=\s*[\'\"]{1}.*?[\'\"]{1};\s*/ism';
107 $contents = preg_replace($pattern_match, "\n", $contents);
109 $contents .= "\n\$GLOBALS['app_list_strings']['$dropdown_name']['$key']=" . var_export_helper($value) . ";";
113 //Now synch up the keys in other langauges to ensure that removed/added Drop down values work properly under all langs.
114 $this->synchDropDown($dropdown_name, $dropdown, $selected_lang, $dir);
115 $contents = $this->getNewCustomContents($dropdown_name, $dropdown, $selected_lang);
117 if(!empty($dir) && !is_dir($dir))
119 $continue = mkdir_recursive($dir);
121 save_custom_app_list_strings_contents($contents, $selected_lang, $dir);
124 clearAllJsAndJsLangFilesWithoutOutput();
128 * function synchDropDown
129 * Ensures that the set of dropdown keys is consistant accross all languages.
131 * @param $dropdown_name The name of the dropdown to be synched
132 * @param $dropdown array The dropdown currently being saved
133 * @param $selected_lang String the language currently selected in Studio/MB
134 * @param $saveLov String the path to the directory to save the new lang file in.
136 function synchDropDown($dropdown_name, $dropdown, $selected_lang, $saveLoc) {
137 $allLanguages = get_languages();
138 foreach ($allLanguages as $lang => $langName) {
139 if ($lang != $selected_lang) {
140 $listStrings = return_app_list_strings_language($lang);
141 $langDropDown = array();
142 if (isset($listStrings[$dropdown_name]) && is_array($listStrings[$dropdown_name]))
144 $langDropDown = $this->synchDDKeys($dropdown, $listStrings[$dropdown_name]);
147 //if the dropdown does not exist in the language, justt use what we have.
148 $langDropDown = $dropdown;
150 $contents = $this->getNewCustomContents($dropdown_name, $langDropDown, $lang);
151 save_custom_app_list_strings_contents($contents, $lang, $saveLoc);
157 * function synchMBDropDown
158 * Ensures that the set of dropdown keys is consistant accross all languages in a ModuleBuilder Module
160 * @param $dropdown_name The name of the dropdown to be synched
161 * @param $dropdown array The dropdown currently being saved
162 * @param $selected_lang String the language currently selected in Studio/MB
163 * @param $module MBModule the module to update the languages in
165 function synchMBDropDown($dropdown_name, $dropdown, $selected_lang, $module) {
166 $selected_lang = $selected_lang . '.lang.php';
167 foreach($module->mblanguage->appListStrings as $lang => $listStrings) {
168 if ($lang != $selected_lang)
170 $langDropDown = array();
171 if (isset($listStrings[$dropdown_name]) && is_array($listStrings[$dropdown_name]))
173 $langDropDown = $this->synchDDKeys($dropdown, $listStrings[$dropdown_name]);
176 $langDropDown = $dropdown;
178 $module->mblanguage->appListStrings[$lang][$dropdown_name] = $langDropDown;
179 $module->mblanguage->save($module->key_name);
184 private function synchDDKeys($dom, $sub) {
185 //check for extra keys
186 foreach($sub as $key=>$value) {
187 if (!isset($dom[$key])) {
191 //check for missing keys
192 foreach($dom as $key=>$value) {
193 if (!isset($sub[$key])) {
200 function getPatternMatch($dropdown_name) {
201 return '/\s*\$GLOBALS\s*\[\s*\'app_list_strings\s*\'\s*\]\[\s*\''
202 . $dropdown_name.'\'\s*\]\s*=\s*array\s*\([^\)]*\)\s*;\s*/ism';
205 function getNewCustomContents($dropdown_name, $dropdown, $lang) {
206 $contents = return_custom_app_list_strings_file_contents($lang);
207 $contents = str_replace("?>", '', $contents);
208 if(empty($contents))$contents = "<?php";
209 $contents = preg_replace($this->getPatternMatch($dropdown_name), "\n", $contents);
210 $contents .= "\n\$GLOBALS['app_list_strings']['$dropdown_name']=" . var_export_helper($dropdown) . ";";