Completed
Push — console-installer ( e2b50d...6ce748 )
by Adam
22:30
created

ViewDropdown::_getModuleTitleParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/*********************************************************************************
3
 * SugarCRM Community Edition is a customer relationship management program developed by
4
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5
6
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
7
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
8
 *
9
 * This program is free software; you can redistribute it and/or modify it under
10
 * the terms of the GNU Affero General Public License version 3 as published by the
11
 * Free Software Foundation with the addition of the following permission added
12
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
13
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
14
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15
 *
16
 * This program is distributed in the hope that it will be useful, but WITHOUT
17
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
19
 * details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License along with
22
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
23
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
 * 02110-1301 USA.
25
 *
26
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
27
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
28
 *
29
 * The interactive user interfaces in modified source and object code versions
30
 * of this program must display Appropriate Legal Notices, as required under
31
 * Section 5 of the GNU Affero General Public License version 3.
32
 *
33
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
34
 * these Appropriate Legal Notices must retain the display of the "Powered by
35
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
36
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
37
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
38
 ********************************************************************************/
39
40
require_once('modules/ModuleBuilder/MB/AjaxCompose.php');
41
42
class ViewDropdown extends SugarView
43
{
44
 	/**
0 ignored issues
show
Coding Style introduced by
There is some trailing whitespace on this line which should be avoided as per coding-style.
Loading history...
45
	 * @see SugarView::_getModuleTitleParams()
46
	 */
47
	protected function _getModuleTitleParams($browserTitle = false)
48
	{
49
	    global $mod_strings;
50
	    
51
    	return array(
52
    	   translate('LBL_MODULE_NAME','Administration'),
53
    	   ModuleBuilderController::getModuleTitle(),
54
    	   );
55
    }
56
57
 	function display()
58
 	{
59
		$ajax = new AjaxCompose();
60
		$smarty = $this->generateSmarty();
61
		
62
		if (isset($_REQUEST['refreshTree']))
63
		{
64
			require_once ('modules/ModuleBuilder/Module/DropDownTree.php');
65
			$mbt = new DropDownTree();
66
			$ajax->addSection('west', $mbt->getName(), $mbt->fetchNodes());
67
			$smarty->assign('refreshTree',true);
68
		}
69
70
        global $mod_strings;
71
72
 		$smarty->assign('deleteImage', SugarThemeRegistry::current()->getImage( 'delete_inline', '',null,null,'.gif',$mod_strings['LBL_MB_DELETE']));
73
		$smarty->assign('editImage', SugarThemeRegistry::current()->getImage( 'edit_inline', ''
74
,null,null,'.gif',$mod_strings['LBL_EDIT']));
75
		$smarty->assign('action', 'savedropdown');
76
		$body = $smarty->fetch('modules/ModuleBuilder/tpls/MBModule/dropdown.tpl');
77
		$ajax->addSection('east2', $mod_strings['LBL_SECTION_DROPDOWNED'], $body );
78
 		echo $ajax->getJavascript();
79
 	}
80
 	
0 ignored issues
show
Coding Style introduced by
There is some trailing whitespace on this line which should be avoided as per coding-style.
Loading history...
81
 	function generateSmarty()
82
 	{
83
		//get the selected language
84
		$selected_lang = (!empty($_REQUEST['dropdown_lang'])?$_REQUEST['dropdown_lang']:$_SESSION['authenticated_user_language']);
85
		$vardef = array();
86
		$package_name = 'studio';
87
		$package_strings = array();
88
		$new =false;
89
		$my_list_strings = return_app_list_strings_language( $selected_lang ) ;
90
//		$my_list_strings = $GLOBALS['app_list_strings'];
91
92
        $smarty = new Sugar_Smarty();
93
		      
94
		//if we are using ModuleBuilder then process the following
95
		if(!empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio'){
96
			require_once('modules/ModuleBuilder/MB/ModuleBuilder.php');
97
			$mb = new ModuleBuilder();
98
			$module = $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
99
			$package = $mb->packages[$_REQUEST['view_package']];
100
			$package_name = $package->name;
101
			$module->getVardefs();
102
			if(empty($_REQUEST['dropdown_name']) && !empty($_REQUEST['field'])){
103
				$new = true;
104
				$_REQUEST['dropdown_name'] = $_REQUEST['field']. '_list';
105
			}
106
			
107
			$vardef = (!empty($module->mbvardefs->fields[$_REQUEST['dropdown_name']]))? $module->mbvardefs->fields[$_REQUEST['dropdown_name']]: array();
108
			$module->mblanguage->generateAppStrings(false) ;
109
            $my_list_strings = array_merge( $my_list_strings, $module->mblanguage->appListStrings[$selected_lang.'.lang.php'] );
110
            $smarty->assign('module_name', $module->name);
111
		}
112
113
        $module_name = !empty($module->name) ?  $module->name : '';
114
        $module_name = (empty($module_name) && !empty($_REQUEST['view_module'])) ?  $_REQUEST['view_module'] : $module_name;
115
116
		foreach($my_list_strings as $key=>$value){
117
			if(!is_array($value)){
118
				unset($my_list_strings[$key]);
119
			}
120
		}
121
		
122
		$dropdowns = array_keys($my_list_strings);
123
		asort($dropdowns);
124
		$keys = array_keys($dropdowns);
125
		$first_string = $my_list_strings[$dropdowns[$keys[0]]];
126
127
		$name = '';
128
		$selected_dropdown = array();
129
130
		$json = getJSONobj();
131
132
		if(!empty($_REQUEST['dropdown_name']) && !$new){
133
			$name = $_REQUEST['dropdown_name'];
134
			
135
			// handle the case where we've saved a dropdown in one language, and now attempt to edit it for another language. The $name exists, but $my_list_strings[$name] doesn't
136
            // for now, we just treat it as if it was new. A better approach might be to use the first language version as a template for future languages
137
            if (!isset($my_list_strings[$name]))
138
                $my_list_strings[$name] = array () ;
139
 
140
			$selected_dropdown = (!empty($vardef['options']) && !empty($my_list_strings[$vardef['options']])) ? $my_list_strings[$vardef['options']] : $my_list_strings[$name];
141
			$smarty->assign('ul_list', 'list = '.$json->encode(array_keys($selected_dropdown)));
142
			$smarty->assign('dropdown_name', (!empty($vardef['options']) ? $vardef['options'] : $_REQUEST['dropdown_name']));
143
			$smarty->assign('name', $_REQUEST['dropdown_name']);
144
			$smarty->assign('options', $selected_dropdown);
145
		}else{
146
			$smarty->assign('ul_list', 'list = {}');
147
			//we should try to find a name for this dropdown based on the field name.
148
			$pre_pop_name = '';
149
			if(!empty($_REQUEST['field']))
150
				$pre_pop_name = $_REQUEST['field'];
151
			//ensure this dropdown name does not already exist
152
			$use_name = $pre_pop_name.'_list';
153
			for($i = 0; $i < 100; $i++){
154
				if(empty($my_list_strings[$use_name]))
155
					break;
156
				else
157
					$use_name = $pre_pop_name.'_'.$i;
158
			}
159
			$smarty->assign('prepopulated_name', $use_name);
160
		}
161
162
		$smarty->assign('module_name', $module_name);
163
		$smarty->assign('APP', $GLOBALS['app_strings']);
164
		$smarty->assign('MOD', $GLOBALS['mod_strings']);
165
		$smarty->assign('selected_lang', $selected_lang);
166
		$smarty->assign('available_languages',get_languages());
167
		$smarty->assign('package_name', $package_name);
168
 		return $smarty;
169
 	}
170
}