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 ********************************************************************************/
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 ])) ;
71 if(array_key_exists($emptyMarker, $dropdown)){
73 foreach($dropdown as $key => $value){
74 if($emptyMarker===$key)
82 if($type != 'studio'){
83 $mb = new ModuleBuilder();
84 $module =& $mb->getPackageModule($params['view_package'], $params['view_module']);
85 $this->synchMBDropDown($dropdown_name, $dropdown, $selected_lang, $module);
86 //Can't use synch on selected lang as we want to overwrite values, not just keys
87 $module->mblanguage->appListStrings[$selected_lang.'.lang.php'][$dropdown_name] = $dropdown;
88 $module->mblanguage->save($module->key_name); // tyoung - key is required parameter as of
90 $contents = return_custom_app_list_strings_file_contents($selected_lang);
91 $my_list_strings = return_app_list_strings_language($selected_lang);
92 if($selected_lang == $GLOBALS['current_language']){
93 $GLOBALS['app_list_strings'][$dropdown_name] = $dropdown;
96 $contents = str_replace("?>", '', $contents);
97 if(empty($contents))$contents = "<?php";
98 //add new drop down to the bottom
99 if(!empty($params['use_push'])){
100 //this is for handling moduleList and such where nothing should be deleted or anything but they can be renamed
101 foreach($dropdown as $key=>$value){
102 //only if the value has changed or does not exist do we want to add it this way
103 if(!isset($my_list_strings[$dropdown_name][$key]) || strcmp($my_list_strings[$dropdown_name][$key], $value) != 0 ){
104 //clear out the old value
105 $pattern_match = '/\s*\$app_list_strings\s*\[\s*\''.$dropdown_name.'\'\s*\]\[\s*\''.$key.'\'\s*\]\s*=\s*[\'\"]{1}.*?[\'\"]{1};\s*/ism';
106 $contents = preg_replace($pattern_match, "\n", $contents);
108 $contents .= "\n\$GLOBALS['app_list_strings']['$dropdown_name']['$key']=" . var_export_helper($value) . ";";
112 //Now synch up the keys in other langauges to ensure that removed/added Drop down values work properly under all langs.
113 $this->synchDropDown($dropdown_name, $dropdown, $selected_lang, $dir);
114 $contents = $this->getNewCustomContents($dropdown_name, $dropdown, $selected_lang);
116 if(!empty($dir) && !is_dir($dir))
118 $continue = mkdir_recursive($dir);
120 save_custom_app_list_strings_contents($contents, $selected_lang, $dir);
123 clearAllJsAndJsLangFilesWithoutOutput();
127 * function synchDropDown
128 * Ensures that the set of dropdown keys is consistant accross all languages.
130 * @param $dropdown_name The name of the dropdown to be synched
131 * @param $dropdown array The dropdown currently being saved
132 * @param $selected_lang String the language currently selected in Studio/MB
133 * @param $saveLov String the path to the directory to save the new lang file in.
135 function synchDropDown($dropdown_name, $dropdown, $selected_lang, $saveLoc) {
136 $allLanguages = get_languages();
137 foreach ($allLanguages as $lang => $langName) {
138 if ($lang != $selected_lang) {
139 $listStrings = return_app_list_strings_language($lang);
140 $langDropDown = array();
141 if (isset($listStrings[$dropdown_name]) && is_array($listStrings[$dropdown_name]))
143 $langDropDown = $this->synchDDKeys($dropdown, $listStrings[$dropdown_name]);
146 //if the dropdown does not exist in the language, justt use what we have.
147 $langDropDown = $dropdown;
149 $contents = $this->getNewCustomContents($dropdown_name, $langDropDown, $lang);
150 save_custom_app_list_strings_contents($contents, $lang, $saveLoc);
156 * function synchMBDropDown
157 * Ensures that the set of dropdown keys is consistant accross all languages in a ModuleBuilder Module
159 * @param $dropdown_name The name of the dropdown to be synched
160 * @param $dropdown array The dropdown currently being saved
161 * @param $selected_lang String the language currently selected in Studio/MB
162 * @param $module MBModule the module to update the languages in
164 function synchMBDropDown($dropdown_name, $dropdown, $selected_lang, $module) {
165 $selected_lang = $selected_lang . '.lang.php';
166 foreach($module->mblanguage->appListStrings as $lang => $listStrings) {
167 if ($lang != $selected_lang)
169 $langDropDown = array();
170 if (isset($listStrings[$dropdown_name]) && is_array($listStrings[$dropdown_name]))
172 $langDropDown = $this->synchDDKeys($dropdown, $listStrings[$dropdown_name]);
175 $langDropDown = $dropdown;
177 $module->mblanguage->appListStrings[$lang][$dropdown_name] = $langDropDown;
178 $module->mblanguage->save($module->key_name);
183 private function synchDDKeys($dom, $sub) {
184 //check for extra keys
185 foreach($sub as $key=>$value) {
186 if (!isset($dom[$key])) {
190 //check for missing keys
191 foreach($dom as $key=>$value) {
192 if (!isset($sub[$key])) {
199 function getPatternMatch($dropdown_name) {
200 return '/\s*\$GLOBALS\s*\[\s*\'app_list_strings\s*\'\s*\]\[\s*\''
201 . $dropdown_name.'\'\s*\]\s*=\s*array\s*\([^\)]*\)\s*;\s*/ism';
204 function getNewCustomContents($dropdown_name, $dropdown, $lang) {
205 $contents = return_custom_app_list_strings_file_contents($lang);
206 $contents = str_replace("?>", '', $contents);
207 if(empty($contents))$contents = "<?php";
208 $contents = preg_replace($this->getPatternMatch($dropdown_name), "\n", $contents);
209 $contents .= "\n\$GLOBALS['app_list_strings']['$dropdown_name']=" . var_export_helper($dropdown) . ";";