Test Failed
Push — CI ( 0f01dd...c95a04 )
by Adam
55:13
created

ModuleBuilderController   F

Complexity

Total Complexity 183

Size/Duplication

Total Lines 874
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 21
Metric Value
wmc 183
lcom 2
cbo 21
dl 0
loc 874
rs 1.263

43 Methods

Rating   Name   Duplication   Size   Complexity  
C getModuleTitle() 0 27 7
A fromModuleBuilder() 0 4 2
B process() 0 17 14
D action_editLayout() 0 46 18
A action_ViewTree() 0 20 3
C action_SavePackage() 0 29 7
A action_BuildPackage() 0 10 2
B action_DeployPackage() 0 61 6
A action_ExportPackage() 0 16 2
A action_DeletePackage() 0 7 1
C action_SaveModule() 0 28 7
A action_DeleteModule() 0 7 1
A action_saveLabels() 0 13 4
B action_SaveLabel() 0 17 5
A action_ExportCustom() 0 16 3
C action_SaveField() 0 70 9
A action_saveSugarField() 0 53 3
A action_RefreshField() 0 7 1
A action_saveVisibility() 0 12 3
B action_SaveRelationshipLabel() 0 20 5
B action_SaveRelationship() 0 29 5
B action_DeleteRelationship() 0 25 4
A action_SaveDropDown() 0 7 1
C action_DeleteField() 0 50 9
A DeleteLabel() 0 6 1
A action_CloneField() 0 6 1
A action_SaveAssistantPref() 0 17 3
A action_EditProperty() 0 4 1
A action_saveProperty() 0 14 4
A action_editModule() 0 4 1
A action_wizard() 0 4 1
B action_saveLayout() 0 14 7
B action_saveAndPublishLayout() 0 16 7
A action_manageBackups() 0 4 1
A action_listViewSave() 0 12 4
A action_dashletSave() 0 7 3
A action_popupSave() 0 19 4
B action_searchViewSave() 0 23 4
A action_editLabels() 0 9 2
D action_get_app_list_string() 0 31 9
A action_history() 0 4 1
A resetmodule() 0 4 1
B action_savetablesort() 0 14 6

How to fix   Complexity   

Complex Class

Complex classes like ModuleBuilderController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ModuleBuilderController, and based on these observations, apply Extract Interface, too.

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/ModuleBuilder.php') ;
41
require_once ('modules/ModuleBuilder/parsers/ParserFactory.php') ;
42
require_once ('modules/ModuleBuilder/Module/StudioModuleFactory.php');
43
require_once 'modules/ModuleBuilder/parsers/constants.php' ;
44
45
class ModuleBuilderController extends SugarController
46
{
47
    var $action_remap = array ( ) ;
48
49
    /**
50
     * Used by the _getModuleTitleParams() method calls in ModuleBuilder views to get the correct string
51
     * for the section you are in
52
     *
53
     * @return string
54
     */
55
    public static function getModuleTitle()
56
    {
57
        global $mod_strings;
58
59
        if(!empty($_REQUEST['type'])){
60
            if ( $_REQUEST['type'] == 'studio' ) {
61
                return $mod_strings['LBL_STUDIO'];
62
            }
63
            elseif ( $_REQUEST['type'] == 'sugarportal' ) {
64
                return $mod_strings['LBL_SUGARPORTAL'];
65
            }
66
            elseif ( $_REQUEST['type'] == 'mb' ) {
67
                return $mod_strings['LBL_MODULEBUILDER'];
68
            }
69
            elseif ( $_REQUEST['type'] == 'dropdowns') {
70
                return $mod_strings['LBL_DROPDOWNEDITOR'];
71
            }
72
            elseif ( $_REQUEST['type'] == 'home' ) {
73
                return $mod_strings['LBL_HOME'];
74
            }
75
            else {
76
                return $mod_strings['LBL_DEVELOPER_TOOLS'];
77
            }
78
        }else{
79
            return $mod_strings['LBL_DEVELOPER_TOOLS'];
80
        }
81
    }
82
83
    function fromModuleBuilder ()
84
    {
85
        return (isset ( $_REQUEST [ 'MB' ] ) && ($_REQUEST [ 'MB' ] == '1')) ;
86
    }
87
88
    function process(){
89
    	$GLOBALS [ 'log' ]->info ( get_class($this).":" ) ;
90
        global $current_user;
91
        $access = $current_user->getDeveloperModules();
92
            if($current_user->isAdmin() || ($current_user->isDeveloperForAnyModule() && !isset($_REQUEST['view_module']) && (isset($_REQUEST['action']) && $_REQUEST['action'] != 'package'))||
93
          (isset($_REQUEST['view_module']) && (in_array($_REQUEST['view_module'], $access)|| empty($_REQUEST['view_module']))) ||
94
               (isset($_REQUEST['type']) && (($_REQUEST['type']=='dropdowns' && $current_user->isDeveloperForAnyModule())||
95
          ($_REQUEST['type']=='studio' && displayStudioForCurrentUser() == true))))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
96
        {
97
            $this->hasAccess = true;
98
        }
99
        else
100
        {
101
            $this->hasAccess = false;
102
        }
103
        parent::process();
104
    }
105
106
107
    function action_editLayout ()
108
    {
109
        $view = strtolower ( $_REQUEST [ 'view' ] );
110
        $found = false;
111
        //Check the StudioModule first for mapping overrides
112
        if(empty($_REQUEST [ 'view_package' ] )|| $_REQUEST [ 'view_package' ] == "studio")
113
        {
114
            $sm = StudioModuleFactory::getStudioModule($_REQUEST [ 'view_module' ]);
115
            foreach($sm->sources as $file => $def)
116
            {
117
                if (!empty($def['type']) && !empty($def['view']) && $def['view'] == $view )
118
                {
119
                    $view = $def['type'];
120
                }
121
            }
122
        }
123
        if (!$found)
124
        {
125
            switch ( $view)
126
            {
127
                case MB_EDITVIEW :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
128
                case MB_DETAILVIEW :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
129
                case MB_QUICKCREATE :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
130
                    $this->view = 'layoutView' ;
131
                    break ;
132
                case MB_LISTVIEW :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
133
                    $this->view = 'listView' ;
134
                    break ;
135
                case MB_BASICSEARCH :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
136
                case MB_ADVANCEDSEARCH :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
137
                    $this->view = 'searchView' ;
138
                    break ;
139
                case MB_DASHLET :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
140
                case MB_DASHLETSEARCH :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
141
                    $this->view = 'dashlet' ;
142
                    break ;
143
                case MB_POPUPLIST :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
144
                case MB_POPUPSEARCH :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
145
                    $this->view = 'popupview' ;
146
                    break ;
147
                default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
148
                    $GLOBALS [ 'log' ]->fatal ( 'Action = editLayout with unknown view=' . $_REQUEST [ 'view' ] ) ;
149
            } 
150
        }
151
152
    }
153
154
155
    function action_ViewTree ()
156
    {
157
        require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
158
        switch ( $_REQUEST [ 'tree' ])
159
        {
160
            case 'ModuleBuilder' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
161
                require_once ('modules/ModuleBuilder/MB/MBPackageTree.php') ;
162
                $mbt = new MBPackageTree ( ) ;
163
                break ;
164
            case 'Studio' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
165
                require_once ('modules/ModuleBuilder/Module/StudioTree.php') ;
166
                $mbt = new StudioTree ( ) ;
167
        }
168
        $ajax = new AjaxCompose ( ) ;
169
        $ajax->addSection ( 'west', $mbt->getName (), $mbt->fetchNodes () ) ;
170
        echo $ajax->getJavascript () ;
171
172
        sugar_cleanup ( true ) ;
173
174
    }
175
176
    function action_SavePackage ()
177
    {
178
        $mb = new ModuleBuilder ( ) ;
179
        $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
180
        if (! empty ( $load ))
181
        {
182
            $mb->getPackage ( $load ) ;
183
184
            if (! empty ( $_REQUEST [ 'duplicate' ] ))
185
            {
186
                $result = $mb->packages [ $load ]->copy ( $_REQUEST [ 'name' ] ) ;
187
                $load = $mb->packages [ $load ]->name ;
188
                $mb->getPackage ( $load ) ;
189
            }
190
            $mb->packages [ $load ]->populateFromPost () ;
191
            $mb->packages [ $load ]->loadModules () ;
192
            $mb->save () ;
193
            if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
194
            {
195
                if (! $mb->packages [ $load ]->rename ( $_REQUEST [ 'name' ] ))
196
                {
197
                    $mb->packages [ $load ]->name = $_REQUEST [ 'original_name' ] ;
198
                    $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
199
                }
200
            }
201
            $_REQUEST [ 'package' ] = $_REQUEST [ 'name' ] ;
202
            $this->view = 'package' ;
203
        }
204
    }
205
206
    function action_BuildPackage ()
207
    {
208
        $mb = new ModuleBuilder ( ) ;
209
        $load = $_REQUEST [ 'name' ] ;
210
        if (! empty ( $load ))
211
        {
212
            $mb->getPackage ( $load ) ;
213
            $mb->packages [ $load ]->build () ;
214
        }
215
    }
216
217
    function action_DeployPackage ()
218
    {
219
    	global $current_user;
220
    	
221
    	if(defined('TEMPLATE_URL')){
222
    		sugar_cache_reset();
223
    		SugarTemplateUtilities::disableCache();
224
    	}
225
    	
226
    	//increment etag for menu so the new module shows up when the AJAX UI reloads
227
    	$current_user->incrementETag("mainMenuETag");
228
229
        $mb = new ModuleBuilder ( ) ;
230
        $load = $_REQUEST [ 'package' ] ;
231
        $message = $GLOBALS [ 'mod_strings' ] [ 'LBL_MODULE_DEPLOYED' ] ;
232
        if (! empty ( $load ))
233
        {
234
            $zip = $mb->getPackage ( $load ) ;
235
            require_once ('ModuleInstall/PackageManager/PackageManager.php') ;
236
            $pm = new PackageManager ( ) ;
237
            $info = $mb->packages [ $load ]->build ( false ) ;
238
            $uploadDir = $pm->upload_dir.'/upgrades/module/';
239
            mkdir_recursive ($uploadDir) ;
240
            rename ( $info [ 'zip' ], $uploadDir . $info [ 'name' ] . '.zip' ) ;
241
            copy ( $info [ 'manifest' ], $uploadDir . $info [ 'name' ] . '-manifest.php' ) ;
242
            $_REQUEST [ 'install_file' ] = $uploadDir. $info [ 'name' ] . '.zip' ;
243
            $GLOBALS [ 'mi_remove_tables' ] = false ;
244
            $pm->performUninstall ( $load ) ;
245
            //#23177 , js cache clear
246
            clearAllJsAndJsLangFilesWithoutOutput();
247
            //#30747, clear the cache in memory
248
            $cache_key = 'app_list_strings.'.$GLOBALS['current_language'];
249
            sugar_cache_clear($cache_key );
250
            sugar_cache_reset();
251
            //clear end
252
            $pm->performInstall ( $_REQUEST [ 'install_file' ] , true);
253
254
            //clear the unified_search_module.php file
255
            require_once('modules/Home/UnifiedSearchAdvanced.php');
256
            UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
257
258
            //bug 44269 - start
259
            
260
            //clear workflow admin modules cache
261
            if (isset($_SESSION['get_workflow_admin_modules_for_user'])) unset($_SESSION['get_workflow_admin_modules_for_user']);
262
263
            //clear "is_admin_for_module" cache
264
            $sessionVar = 'MLA_'.$current_user->user_name;
265
            foreach ($mb->packages as $package) {
266
                foreach ($package->modules as $module) {
267
                    $_SESSION[$sessionVar][$package->name . '_' . $module->name] = true;
268
                }
269
            }
270
271
            //recreate acl cache
272
            $actions = ACLAction::getUserActions($current_user->id, true);
273
            //bug 44269 - end
274
        }
275
276
        echo 'complete' ;
277
    }
278
279
    function action_ExportPackage ()
280
    {
281
        $mb = new ModuleBuilder ( ) ;
282
        $load = $_REQUEST [ 'name' ] ;
283
        $author = $_REQUEST [ 'author' ] ;
284
        $description = $_REQUEST [ 'description' ] ;
285
        $readme = $_REQUEST [ 'readme' ] ;
286
        if (! empty ( $load ))
287
        {
288
            $mb->getPackage ( $load ) ;
289
            $mb->packages [ $load ]->author = $author ;
290
            $mb->packages [ $load ]->description = $description ;
291
            $mb->packages [ $load ]->exportProject () ;
292
            $mb->packages [ $load ]->readme = $readme ;
293
        }
294
    }
295
296
    function action_DeletePackage ()
297
    {
298
        $mb = new ModuleBuilder ( ) ;
299
        $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
300
        $mb->packages [ $_REQUEST [ 'package' ] ]->delete () ;
301
        $this->view = 'deletepackage' ;
302
    }
303
304
    function action_SaveModule ()
305
    {
306
        $mb = new ModuleBuilder ( ) ;
307
        $load = (! empty ( $_REQUEST [ 'original_name' ] )) ? $_REQUEST [ 'original_name' ] : $_REQUEST [ 'name' ] ;
308
        if (! empty ( $load ))
309
        {
310
            $mb->getPackage ( $_REQUEST [ 'package' ] ) ;
311
            $mb->packages [ $_REQUEST [ 'package' ] ]->getModule ( $load ) ;
312
            $module = & $mb->packages [ $_REQUEST [ 'package' ] ]->modules [ $load ] ;
313
            $module->populateFromPost () ;
314
            $mb->save () ;
315
            if (! empty ( $_REQUEST [ 'duplicate' ] ))
316
            {
317
                $module->copy ( $_REQUEST [ 'name' ] ) ;
318
            } else if (! empty ( $_REQUEST [ 'original_name' ] ) && $_REQUEST [ 'original_name' ] != $_REQUEST [ 'name' ])
319
            {
320
                if (! $module->rename ( $_REQUEST [ 'name' ] ))
321
                {
322
                    $module->name = $_REQUEST [ 'original_name' ] ;
323
                    $_REQUEST [ 'name' ] = $_REQUEST [ 'original_name' ] ;
324
                }
325
            }
326
327
            $_REQUEST [ 'view_package' ] = $_REQUEST [ 'package' ] ;
328
            $_REQUEST [ 'view_module' ] = $module->name ;
329
            $this->view = 'module' ;
330
        }
331
    }
332
333
    function action_DeleteModule ()
334
    {
335
        $mb = new ModuleBuilder ( ) ;
336
        $module = & $mb->getPackageModule ( $_REQUEST [ 'package' ], $_REQUEST [ 'view_module' ] ) ;
337
        $module->delete () ;
338
        $this->view = 'package' ;
339
    }
340
341
    function action_saveLabels ()
342
    {
343
        require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
344
        $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
345
        $parser->handleSave ( $_REQUEST, $_REQUEST [ 'selected_lang' ] ) ;
346
        if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
347
        {
348
            $this->view = 'modulelabels' ;
349
        } else //STUDIO
350
        {
351
            $this->view = isset ( $_REQUEST [ 'view' ] ) ? 'edit' : 'labels' ; // detect if we are being called by the LayoutEditor rather than the LabelEditor (set in view.layoutlabel.php)
352
        }
353
    }
354
355
    function action_SaveLabel ()
356
    {
357
        if (! empty ( $_REQUEST [ 'view_module' ] ) && !empty($_REQUEST [ 'labelValue' ]))
358
        {
359
            $_REQUEST [ "label_" . $_REQUEST [ 'label' ] ] = $_REQUEST [ 'labelValue' ] ;
360
            require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
361
362
            $req = $_REQUEST;
363
            foreach (ModuleBuilder::getModuleAliases($_REQUEST['view_module']) as $key)
364
            {
365
                $req['view_module'] = $key;
366
                $parser = new ParserLabel($req['view_module'], isset($req['view_package']) ? $req['view_package'] : null);
367
                $parser->handleSave($req, $GLOBALS['current_language']);
368
            }
369
        }
370
        $this->view = 'modulefields' ;
371
    }
372
373
    function action_ExportCustom ()
374
    {
375
        $modules = $_REQUEST [ 'modules' ] ;
376
        $name = $_REQUEST [ 'name' ] ;
377
        $author = $_REQUEST [ 'author' ] ;
378
        $description = $_REQUEST [ 'description' ] ;
379
        ob_clean () ;
380
        if (! empty ( $modules ) && ! empty ( $name ))
381
        {
382
            require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
383
            $mb = new MBPackage ( $name ) ;
384
            $mb->author = $author ;
385
            $mb->description = $description ;
386
            $mb->exportCustom ( $modules, true, true ) ;
387
        }
388
    }
389
390
    function action_SaveField ()
391
    {
392
        require_once ('modules/DynamicFields/FieldCases.php') ;
393
        $field = get_widget ( $_REQUEST [ 'type' ] ) ;
394
        $_REQUEST [ 'name' ] = trim ( $_REQUEST [ 'name' ] ) ;
395
396
        $field->populateFromPost () ;
397
398
        if (!isset ( $_REQUEST [ 'view_package' ] ))
399
        {
400
            require_once ('modules/DynamicFields/DynamicField.php') ;
401
            if (! empty ( $_REQUEST [ 'view_module' ] ))
402
            {
403
                $module = $_REQUEST [ 'view_module' ] ;
404
                if ( $module == 'Employees' ) {
405
                    $module = 'Users';
406
                }
407
408
                $bean = BeanFactory::getBean($module);
409
                if(!empty($bean))
410
                {
411
	                $field_defs = $bean->field_defs;
412
	                if(isset($field_defs[$field->name. '_c']))
413
	                {
414
						$GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS'] . '[' . $field->name . ']');
415
						sugar_die($GLOBALS['mod_strings']['ERROR_ALREADY_EXISTS']);
416
	                }
417
                }
418
419
                $df = new DynamicField ( $module ) ;
420
                $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
421
                require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
422
                $mod = new $class_name ( ) ;
423
                $df->setup ( $mod ) ;
424
425
                $field->save ( $df ) ;
426
                $this->action_SaveLabel () ;
427
                include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
428
        		global $mod_strings;
429
                $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
430
                require_once('ModuleInstall/ModuleInstaller.php');
431
                $mi = new ModuleInstaller();
432
                $mi->silent = true;
433
                $mi->rebuild_extensions();
434
                $repair = new RepairAndClear();
435
436
		        $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
437
                if ( $module == 'Users' ) {
438
                    $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array('Employee'), true, false);
439
                    
440
                }
441
442
                //#28707 ,clear all the js files in cache
443
		        $repair->module_list = array();
444
		        $repair->clearJsFiles();
445
            }
446
        } else
447
        {
448
            $mb = new ModuleBuilder ( ) ;
449
            $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
450
            $field->save ( $module ) ;
451
            $module->mbvardefs->save () ;
452
            // get the module again to refresh the labels we might have saved with the $field->save (e.g., for address fields)
453
            $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
454
            if (isset ( $_REQUEST [ 'label' ] ) && isset ( $_REQUEST [ 'labelValue' ] ))
455
                $module->setLabel ( $GLOBALS [ 'current_language' ], $_REQUEST [ 'label' ], $_REQUEST [ 'labelValue' ] ) ;
456
            $module->save();
457
        }
458
        $this->view = 'modulefields' ;
459
    }
460
461
    function action_saveSugarField ()
462
    {
463
    	global $mod_strings;
464
    	require_once ('modules/DynamicFields/FieldCases.php') ;
465
    	    	
466
        $field = get_widget ( $_REQUEST [ 'type' ] ) ;
467
        $_REQUEST [ 'name' ] = trim ( $_POST [ 'name' ] ) ;
468
469
        $field->populateFromPost () ;
470
        require_once ('modules/ModuleBuilder/parsers/StandardField.php') ;
471
        $module = $_REQUEST [ 'view_module' ] ;
472
        
473
        // Need to map Employees -> Users
474
        if ( $module=='Employees') {
475
            $module = 'Users';
476
        }
477
        
478
        $df = new StandardField ( $module ) ;
479
        $mod = BeanFactory::getBean($module);
480
        $class_name = $GLOBALS [ 'beanList' ] [ $module ] ;
481
        $df->setup ( $mod ) ;
482
483
        $field->module = $mod;
484
        $field->save ( $df ) ;
485
        $this->action_SaveLabel () ;
486
487
        $MBmodStrings = $mod_strings;
488
        $GLOBALS [ 'mod_strings' ] = return_module_language ( '', 'Administration' ) ;
489
490
       	include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
491
        $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
492
        $_REQUEST['execute_sql'] = true;
493
494
        require_once('ModuleInstall/ModuleInstaller.php');
495
		$mi = new ModuleInstaller();
496
        $mi->silent = true;
497
		$mi->rebuild_extensions();
498
499
        $repair = new RepairAndClear();
500
        $repair->repairAndClearAll(array('clearVardefs', 'clearTpls'), array($class_name), true, false);
501
        //#28707 ,clear all the js files in cache
502
        $repair->module_list = array();
503
        $repair->clearJsFiles();
504
505
        // now clear the cache so that the results are immediately visible
506
        include_once ('include/TemplateHandler/TemplateHandler.php') ;
507
        TemplateHandler::clearCache ( $module ) ;
508
        if ( $module == 'Users' ) {
509
            TemplateHandler::clearCache('Employees');
510
        }
511
512
        $GLOBALS [ 'mod_strings' ] = $MBmodStrings;
513
    }
514
515
    function action_RefreshField ()
516
    {
517
        require_once ('modules/DynamicFields/FieldCases.php') ;
518
        $field = get_widget ( $_POST [ 'type' ] ) ;
519
        $field->populateFromPost () ;
520
        $this->view = 'modulefield' ;
521
    }
522
523
    function action_saveVisibility ()
524
    {
525
		$packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
526
        require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
527
        $parser = ParserFactory::getParser ( MB_VISIBILITY, $_REQUEST [ 'view_module' ], $packageName ) ;
528
529
        $json = getJSONobj();
530
        $visibility_grid = $json->decode(html_entity_decode(rawurldecode($_REQUEST [ 'visibility_grid' ]), ENT_QUOTES) );
531
		$parser->saveVisibility ( $_REQUEST [ 'fieldname' ] , $_REQUEST [ 'trigger' ] , $visibility_grid ) ;
0 ignored issues
show
Bug introduced by
The method saveVisibility() does not seem to exist on object<AbstractMetaDataParser>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
532
533
        echo $json->encode(array( "visibility_editor_{$_REQUEST['fieldname']}" => array("action" => "deactivate")));
534
    }
535
536
	function action_SaveRelationshipLabel (){
537
            $selected_lang = (!empty($_REQUEST['relationship_lang'])?$_REQUEST['relationship_lang']:$_SESSION['authenticated_user_language']);
538
		 if (empty($_REQUEST [ 'view_package' ])){
539
            require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
540
            $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
541
            if (! empty ( $_REQUEST [ 'relationship_name' ] ))
542
	        {
543
	            if ($relationship = $relationships->get ( $_REQUEST [ 'relationship_name' ] )){
544
	            	$metadata = $relationship->buildLabels(true);
545
	            	 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
546
			        $parser = new ParserLabel ( $_REQUEST['view_module'] ) ;
547
			        $parser->handleSaveRelationshipLabels ( $metadata, $selected_lang ) ;
548
	            }
549
            }
550
        }
551
        else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
552
            //TODO FOR MB
553
        }
554
        $this->view = 'relationships' ;
555
	}
556
557
    function action_SaveRelationship ()
558
    {
559
        if(!empty($GLOBALS['current_user']) && empty($GLOBALS['modListHeader']))
560
        {
561
            $GLOBALS['modListHeader'] = query_module_access_list($GLOBALS['current_user']);
562
        }
563
564
        if (empty($_REQUEST [ 'view_package' ]))
565
        {
566
            require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
567
            $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
568
        } else
569
        {
570
            $mb = new ModuleBuilder ( ) ;
571
            $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
572
            require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
573
            $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
574
        }
575
576
        $relationships->addFromPost () ;
577
        $relationships->save () ;
578
        $GLOBALS['log']->debug("\n\nSTART BUILD");
579
        if (empty($_REQUEST [ 'view_package' ])) {
580
            $relationships->build () ;
0 ignored issues
show
Bug introduced by
The call to build() misses some required arguments starting with $basepath.
Loading history...
581
            LanguageManager::clearLanguageCache($_REQUEST [ 'view_module' ]);
582
        }
583
        $GLOBALS['log']->debug("\n\nEND BUILD");
584
        $this->view = 'relationships' ;
585
    }
586
587
    function action_DeleteRelationship ()
588
    {
589
        if (isset ( $_REQUEST [ 'relationship_name' ] ))
590
        {
591
            if (empty($_REQUEST [ 'view_package' ] ))
592
            {
593
                require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
594
                if (!empty($_REQUEST['remove_tables']))
595
				    $GLOBALS['mi_remove_tables'] = $_REQUEST['remove_tables'];
596
                $relationships = new DeployedRelationships ( $_REQUEST [ 'view_module' ] ) ;
597
            } else
598
            {
599
                $mb = new ModuleBuilder ( ) ;
600
                $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
601
                require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
602
                $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
603
            }
604
            $relationships->delete ( $_REQUEST [ 'relationship_name' ] ) ;
605
606
            $relationships->save () ;
607
            require_once("data/Relationships/RelationshipFactory.php");
608
            SugarRelationshipFactory::deleteCache();
609
        }
610
        $this->view = 'relationships' ;
611
    }
612
613
    function action_SaveDropDown ()
614
    {
615
        require_once 'modules/ModuleBuilder/parsers/parser.dropdown.php' ;
616
        $parser = new ParserDropDown ( ) ;
617
        $parser->saveDropDown ( $_REQUEST ) ;
618
        $this->view = 'dropdowns' ;
619
    }
620
621
    function action_DeleteField ()
622
    {
623
        require_once ('modules/DynamicFields/FieldCases.php') ;
624
        $field = get_widget ( $_REQUEST [ 'type' ] ) ;
625
        $field->name = $_REQUEST [ 'name' ] ;
626
        if (!isset ( $_REQUEST [ 'view_package' ] ))
627
        {
628
            if (! empty ( $_REQUEST [ 'name' ] ) && ! empty ( $_REQUEST [ 'view_module' ] ))
629
            {
630
                require_once ('modules/DynamicFields/DynamicField.php') ;
631
                $moduleName = $_REQUEST [ 'view_module' ] ;
632
633
                // bug 51325 make sure we make this switch or delete will not work
634
                if( $moduleName == 'Employees' )
635
                    $moduleName = 'Users';
636
                
637
                $class_name = $GLOBALS [ 'beanList' ] [ $moduleName ] ;
638
                require_once ($GLOBALS [ 'beanFiles' ] [ $class_name ]) ;
639
                $seed = new $class_name ( ) ;
640
                $df = new DynamicField ( $moduleName ) ;
641
                $df->setup ( $seed ) ;
642
                //Need to load the entire field_meta_data for some field types
643
                $field = $df->getFieldWidget($moduleName, $field->name);
644
                $field->delete ( $df ) ;
645
646
                $GLOBALS [ 'mod_strings' ]['LBL_ALL_MODULES'] = 'all_modules';
647
                $_REQUEST['execute_sql'] = true;
648
                include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
649
                $repair = new RepairAndClear();
650
                $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
651
                require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php' ;
652
                $module = StudioModuleFactory::getStudioModule( $moduleName ) ;
653
            }
654
        }
655
        else
656
        {
657
            $mb = new ModuleBuilder ( ) ;
658
            $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
659
            $field = $module->getField($field->name);
660
            $field->delete ( $module ) ;
661
            $mb->save () ;
662
        }
663
        $module->removeFieldFromLayouts( $field->name );
664
        $this->view = 'modulefields' ;
665
666
        if (isset($GLOBALS['current_language']) && isset($_REQUEST['label']) &&
667
                isset($_REQUEST['labelValue']) && isset($_REQUEST['view_module'])) {
668
            $this->DeleteLabel($GLOBALS['current_language'], $_REQUEST['label'], $_REQUEST['labelValue'], $_REQUEST['view_module']);
669
        }
670
    }
671
672
    function DeleteLabel($language, $label, $labelvalue, $modulename, $basepath = null, $forRelationshipLabel = false)
673
    {
674
        // remove the label
675
        require_once 'modules/ModuleBuilder/parsers/parser.label.php';
676
        ParserLabel::removeLabel($language, $label, $labelvalue, $modulename, $basepath, $forRelationshipLabel);
677
    }
678
679
    function action_CloneField ()
680
    {
681
        $this->view_object_map [ 'field_name' ] = $_REQUEST [ 'name' ] ;
682
        $this->view_object_map [ 'is_clone' ] = true ;
683
        $this->view = 'modulefield' ;
684
    }
685
686
    function action_SaveAssistantPref ()
687
    {
688
        global $current_user ;
689
        if (isset ( $_REQUEST [ 'pref_value' ] ))
690
        {
691
            if ($_REQUEST [ 'pref_value' ] == 'ignore')
692
            {
693
                $current_user->setPreference ( 'mb_assist', 'DISABLED', 0, 'Assistant' ) ;
694
            } else
695
            {
696
                $current_user->setPreference ( 'mb_assist', 'ENABLED', 0, 'Assistant' ) ;
697
            }
698
            $current_pref = $current_user->getPreference ( 'mb_assist', 'Assistant' ) ;
699
            echo "Assistant.processUserPref('$current_pref')" ;
700
            sugar_cleanup ( true ) ; //push preferences to DB.
701
        }
702
    }
703
704
    // Studio2 Actions
705
706
707
    function action_EditProperty ()
708
    {
709
        $this->view = 'property' ;
710
    }
711
712
    function action_saveProperty ()
713
    {
714
        require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
715
        $modules = $_REQUEST['view_module'];
716
        if(!empty($_REQUEST['subpanel'])){
717
        	$modules = $_REQUEST['subpanel'];
718
        }
719
        $parser = new ParserLabel ( $modules , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
720
        // if no language provided, then use the user's current language which is most likely what they intended
721
        $language = (isset($_REQUEST [ 'selected_lang' ])) ? $_REQUEST [ 'selected_lang' ] : $GLOBALS['current_language'] ;
722
        $parser->handleSave ( $_REQUEST, $language ) ;
723
        $json = getJSONobj();
724
        echo $json->encode(array("east" => array("action" => "deactivate")));
725
    }
726
727
    function action_editModule ()
728
    {
729
        $this->view = 'module' ;
730
    }
731
732
    function action_wizard ()
733
    {
734
        $this->view = 'wizard' ;
735
    }
736
737
    /**
738
     * Receive a layout through $_REQUEST and save it out to the working files directory
739
     * Expects a series of $_REQUEST parameters all in the format $_REQUEST['slot-panel#-slot#-property']=value
740
     */
741
742
    function action_saveLayout ()
743
    {
744
            $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
745
            $this->view = 'layoutview' ;
746
        $parser->writeWorkingFile () ;
747
748
    	if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
749
	        if(strtolower ($parser->_view) == MB_EDITVIEW){
750
	        	$parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
751
	        	$parser2->setUseTabs($parser->getUseTabs());
752
                $parser2->writeWorkingFile () ;
753
	        }
754
        }
755
    }
756
757
    function action_saveAndPublishLayout ()
758
    {
759
        $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
760
        $parser->handleSave () ;
761
762
        if(!empty($_REQUEST [ 'sync_detail_and_edit' ]) && $_REQUEST['sync_detail_and_edit'] != false && $_REQUEST['sync_detail_and_edit'] != "false"){
763
	        if(strtolower ($parser->_view) == MB_EDITVIEW){
764
	        	$parser2 = ParserFactory::getParser ( MB_DETAILVIEW, $_REQUEST [ 'view_module' ], isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
765
	        	$parser2->setUseTabs($parser->getUseTabs());
766
                $parser2->handleSave () ;
767
	        }
768
        }
769
770
        $this->view_object_map['new_parser'] = $parser;
771
        $this->view = 'layoutview';
772
    }
773
774
    function action_manageBackups ()
775
    {
776
777
    }
778
779
    function action_listViewSave ()
780
    {
781
    	$GLOBALS [ 'log' ]->info ( "action_listViewSave" ) ;
782
783
        $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
784
        $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
785
        require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
786
        $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName, $subpanelName ) ;
787
        $this->view = 'listView' ;
788
        $parser->handleSave () ;
789
790
    }
791
792
    function action_dashletSave () {
793
        $this->view = 'dashlet' ;
794
        $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
795
        require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
796
        $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
797
        $parser->handleSave () ;
798
    }
799
800
	function action_popupSave(){
801
        $packageName = (isset ( $_REQUEST [ 'view_package' ] ) && (strtolower($_REQUEST['view_package']) != 'studio')) ? $_REQUEST [ 'view_package' ] : null ;
802
        require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
803
        $parser = ParserFactory::getParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
804
        $parser->handleSave () ;
805
        if(empty($packageName)){
806
        	include_once ('modules/Administration/QuickRepairAndRebuild.php') ;
807
			global $mod_strings;
808
	        $mod_strings['LBL_ALL_MODULES'] = 'all_modules';
809
	        $repair = new RepairAndClear();
810
			$repair->show_output = false;
811
			$class_name = $GLOBALS [ 'beanList' ] [ $_REQUEST [ 'view_module' ] ] ;
812
			$repair->module_list = array($class_name);
813
			$repair->clearTpls();
814
        }
815
816
        $this->view_object_map['new_parser'] = $parser;
817
        $this->view = 'popupview';
818
	}
819
820
    function action_searchViewSave ()
821
    {
822
        $packageName = (isset ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
823
        require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php' ;
824
        $parser = new SearchViewMetaDataParser ( $_REQUEST [ 'view' ], $_REQUEST [ 'view_module' ], $packageName ) ;
825
        $parser->handleSave () ;
826
827
828
        //Repair or create a custom SearchFields.php file as needed
829
        $module_name = $_REQUEST [ 'view_module' ] ;
830
        global $beanList;
831
        if (isset($beanList[$module_name]) && $beanList[$module_name]!="") {
832
            $objectName = BeanFactory::getObjectName($module_name);
833
834
            //Load the vardefs for the module to pass to TemplateRange
835
            VardefManager::loadVardef($module_name, $objectName, true);
836
            global $dictionary;
837
            $vardefs = $dictionary[$objectName]['fields'];
838
            require_once('modules/DynamicFields/templates/Fields/TemplateRange.php');
839
            TemplateRange::repairCustomSearchFields($vardefs, $module_name, $packageName);
840
        }
841
        $this->view = 'searchView' ;
842
    }
843
844
    function action_editLabels ()
845
    {
846
        if (isset ( $_REQUEST [ 'view_package' ] )) //MODULE BUILDER
847
        {
848
            $this->view = 'modulelabels';
849
        }else{ //STUDIO
850
            $this->view = 'labels';
851
        }
852
    }
853
854
    function action_get_app_list_string ()
855
    {
856
        require_once ('include/JSON.php') ;
857
        $json = new JSON ( ) ;
858
        if (isset ( $_REQUEST [ 'key' ] ) && ! empty ( $_REQUEST [ 'key' ] ))
859
        {
860
            $key = $_REQUEST [ 'key' ] ;
861
            $value = array ( ) ;
862
            if (! empty ( $GLOBALS [ 'app_list_strings' ] [ $key ] ))
863
            {
864
                $value = $GLOBALS [ 'app_list_strings' ] [ $key ] ;
865
            } else
866
            {
867
                $package_strings = array ( ) ;
868
                if (! empty ( $_REQUEST [ 'view_package' ] ) && $_REQUEST [ 'view_package' ] != 'studio' && ! empty ( $_REQUEST [ 'view_module' ] ))
869
                {
870
                    require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
871
                    $mb = new ModuleBuilder ( ) ;
872
                    $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
873
                    $lang = $GLOBALS [ 'current_language' ] ;
874
                    $module->mblanguage->generateAppStrings ( false ) ;
875
                    $package_strings = $module->mblanguage->appListStrings [ $lang . '.lang.php' ] ;
876
                    if (isset ( $package_strings [ $key ] ) && is_array ( $package_strings [ $key ] ))
877
                    {
878
                        $value = $package_strings [ $key ] ;
879
                    }
880
                }
881
            }
882
            echo $json->encode ( $value ) ;
883
        }
884
    }
885
886
    function action_history ()
887
    {
888
        $this->view = 'history' ;
889
    }
890
891
    function resetmodule()
892
    {
893
    	$this->view = 'resetmodule';
894
    }
895
896
897
    /**
898
     * savetablesort
899
     * This method handles saving the current user's tabling sorting preferences.  It is called when
900
     * the user clicks on a column to sort from the fields layout table.
901
     *
902
     */
903
    function action_savetablesort ()
904
    {
905
        $this->view = 'ajax';
906
        global $current_user;
907
908
        if(!empty($current_user) && isset($_REQUEST['column']) && isset($_REQUEST['direction']))
909
        {
910
            $direction = ($_REQUEST['direction'] == 'yui-dt-asc') ? 'ASC' : 'DESC';
911
            $valid_columns = array('name', 'label', 'type', 'required', 'unified_search', 'custom');
912
            $key = in_array($_REQUEST['column'], $valid_columns) ? $_REQUEST['column'] : 'name';
913
            $val = array('key'=>$key, 'direction'=>$direction);
914
            $current_user->setPreference('fieldsTableColumn', getJSONobj()->encode($val), 0, 'ModuleBuilder');
915
        }
916
    }
917
918
}
919
?>
920