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