]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Studio/DropDowns/DropDownHelper.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Studio / DropDowns / DropDownHelper.php
1 <?php
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.
6  * 
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.
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 Affero General Public License for more
17  * details.
18  * 
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
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 Affero General Public License version 3.
30  * 
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  ********************************************************************************/
37
38
39
40 require_once('modules/Administration/Common.php');
41 require_once('modules/Administration/QuickRepairAndRebuild.php');
42 class DropDownHelper{
43     var $modules = array();
44     function getDropDownModules(){
45         $dir = dir('modules');
46         while($entry = $dir->read()){
47             if(file_exists('modules/'. $entry . '/EditView.php')){
48                 $this->scanForDropDowns('modules/'. $entry . '/EditView.php', $entry);
49             }
50         }
51
52     }
53
54     function scanForDropDowns($filepath, $module){
55         $contents = file_get_contents($filepath);
56         $matches = array();
57         preg_match_all('/app_list_strings\s*\[\s*[\'\"]([^\]]*)[\'\"]\s*]/', $contents, $matches);
58         if(!empty($matches[1])){
59
60             foreach($matches[1] as $match){
61                 $this->modules[$module][$match] = $match;
62             }
63
64         }
65
66     }
67
68     /**
69      * Allow for certain dropdowns to be filtered when edited by pre 5.0 studio (eg. Rename Tabs)
70      *
71      * @param string name
72      * @param array dropdown
73      * @return array Filtered dropdown list
74      */
75     function filterDropDown($name,$dropdown)
76     {
77         $results = array();
78         switch ($name)
79         {
80             //When renaming tabs ensure that the modList dropdown is filtered properly.
81             case 'moduleList':
82                 $hiddenModList = array_flip($GLOBALS['modInvisList']);
83                 $moduleList = array_flip($GLOBALS['moduleList']);
84
85                 foreach ($dropdown as $k => $v)
86                 {
87                     if( isset($moduleList[$k]) ) // && !$hiddenModList[$k])
88                         $results[$k] = $v;
89                 }
90                 break;
91             default: //By default perform no filtering
92                 $results = $dropdown;
93
94         }
95
96         return $results;
97     }
98
99
100     /**
101      * Takes in the request params from a save request and processes
102      * them for the save.
103      *
104      * @param REQUEST params  $params
105      */
106     function saveDropDown($params){
107        $count = 0;
108        $dropdown = array();
109        $dropdown_name = $params['dropdown_name'];
110        $selected_lang = (!empty($params['dropdown_lang'])?$params['dropdown_lang']:$_SESSION['authenticated_user_language']);
111        $my_list_strings = return_app_list_strings_language($selected_lang);
112        while(isset($params['slot_' . $count])){
113
114            $index = $params['slot_' . $count];
115            $key = (isset($params['key_' . $index]))?SugarCleaner::stripTags($params['key_' . $index]): 'BLANK';
116            $value = (isset($params['value_' . $index]))?SugarCleaner::stripTags($params['value_' . $index]): '';
117            if($key == 'BLANK'){
118                $key = '';
119
120            }
121                 $key = trim($key);
122                 $value = trim($value);
123            if(empty($params['delete_' . $index])){
124             $dropdown[$key] = $value;
125            }
126            $count++;
127        }
128
129        if($selected_lang == $GLOBALS['current_language']){
130
131            $GLOBALS['app_list_strings'][$dropdown_name] = $dropdown;
132        }
133         $contents = return_custom_app_list_strings_file_contents($selected_lang);
134
135
136
137        //get rid of closing tags they are not needed and are just trouble
138         $contents = str_replace("?>", '', $contents);
139                 if(empty($contents))$contents = "<?php";
140         //add new drop down to the bottom
141         if(!empty($params['use_push'])){
142                 //this is for handling moduleList and such where nothing should be deleted or anything but they can be renamed
143                 foreach($dropdown as $key=>$value){
144                         //only if the value has changed or does not exist do we want to add it this way
145                         if(!isset($my_list_strings[$dropdown_name][$key]) || strcmp($my_list_strings[$dropdown_name][$key], $value) != 0 ){
146                                 //clear out the old value
147                                 $pattern_match = '/\s*\$app_list_strings\s*\[\s*\''.$dropdown_name.'\'\s*\]\[\s*\''.$key.'\'\s*\]\s*=\s*[\'\"]{1}.*?[\'\"]{1};\s*/ism';
148                                 $contents = preg_replace($pattern_match, "\n", $contents);
149                                 //add the new ones
150                                 $contents .= "\n\$app_list_strings['$dropdown_name']['$key']=" . var_export_helper($value) . ";";
151                         }
152                 }
153         }else{
154                 //clear out the old value
155                 $pattern_match = '/\s*\$app_list_strings\s*\[\s*\''.$dropdown_name.'\'\s*\]\s*=\s*array\s*\([^\)]*\)\s*;\s*/ism';
156                 $contents = preg_replace($pattern_match, "\n", $contents);
157                 //add the new ones
158                 $contents .= "\n\$app_list_strings['$dropdown_name']=" . var_export_helper($dropdown) . ";";
159         }
160
161         // Bug 40234 - If we have no contents, we don't write the file. Checking for "<?php" because above it's set to that if empty
162         if($contents != "<?php"){
163             save_custom_app_list_strings_contents($contents, $selected_lang);
164             sugar_cache_reset();
165         }
166         // Bug38011
167         $repairAndClear = new RepairAndClear();
168         $repairAndClear->module_list = array(translate('LBL_ALL_MODULES'));
169         $repairAndClear->show_output = false;
170         $repairAndClear->clearJsLangFiles();
171         // ~~~~~~~~
172     }
173
174
175
176 }
177
178
179 ?>