Passed
Push — scrutinizer-code-quality ( 09f5a1...c4c5fb )
by Adam
56:05 queued 14:08
created

UsersViewEdit::display()   F

Complexity

Conditions 27
Paths > 20000

Size

Total Lines 154
Code Lines 94

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 756
Metric Value
cc 27
eloc 94
nc 429496.7295
nop 0
dl 0
loc 154
ccs 0
cts 115
cp 0
crap 756
rs 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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-2013 SugarCRM Inc.
6
7
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
8
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
9
 *
10
 * This program is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU Affero General Public License version 3 as published by the
12
 * Free Software Foundation with the addition of the following permission added
13
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
14
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
15
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
16
 *
17
 * This program is distributed in the hope that it will be useful, but WITHOUT
18
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
20
 * details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License along with
23
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
 * 02110-1301 USA.
26
 *
27
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
28
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
29
 *
30
 * The interactive user interfaces in modified source and object code versions
31
 * of this program must display Appropriate Legal Notices, as required under
32
 * Section 5 of the GNU Affero General Public License version 3.
33
 *
34
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
35
 * these Appropriate Legal Notices must retain the display of the "Powered by
36
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
37
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
38
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39
 ********************************************************************************/
40
41
42
require_once('modules/Users/UserViewHelper.php');
43
44
45
class UsersViewEdit extends ViewEdit {
46
var $useForSubpanel = true;
47
 	function __construct(){
48
 		parent::__construct();
49
 	}
50
51
    /**
52
     * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
53
     */
54
    function UsersViewEdit(){
55
        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
56
        if(isset($GLOBALS['log'])) {
57
            $GLOBALS['log']->deprecated($deprecatedMessage);
58
        }
59
        else {
60
            trigger_error($deprecatedMessage, E_USER_DEPRECATED);
61
        }
62
        self::__construct();
63
    }
64
65
66
    function preDisplay() {
67
        $this->fieldHelper = new UserViewHelper($this->ss, $this->bean, 'EditView');
68
        $this->fieldHelper->setupAdditionalFields();
69
70
        parent::preDisplay();
71
    }
72
73
    public function getMetaDataFile() {
74
        $userType = 'Regular';
75
        if($this->fieldHelper->usertype == 'GROUP'){
76
            $userType = 'Group';
77
        }
78
79
        if ( $userType != 'Regular' ) {
80
            $oldType = $this->type;
81
            $this->type = $oldType.'group';
82
        }
83
        $metadataFile = parent::getMetaDataFile();
84
        if ( $userType != 'Regular' ) {
85
            $this->type = $oldType;
86
        }
87
88
        return $metadataFile;
89
    }
90
91
    function display() {
92
        global $current_user, $app_list_strings;
93
94
95
        //lets set the return values
96
        if(isset($_REQUEST['return_module'])){
97
            $this->ss->assign('RETURN_MODULE',$_REQUEST['return_module']);
98
        }
99
100
        $this->ss->assign('IS_ADMIN', $current_user->is_admin ? true : false);
101
102
        //make sure we can populate user type dropdown.  This usually gets populated in predisplay unless this is a quickeditform
103
        if(!isset($this->fieldHelper)){
104
            $this->fieldHelper = new UserViewHelper($this->ss, $this->bean, 'EditView');
105
            $this->fieldHelper->setupAdditionalFields();
106
        }
107
108
        if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
109
            $this->ss->assign('RETURN_MODULE', $_REQUEST['return_module']);
110
            $this->ss->assign('RETURN_ACTION', $_REQUEST['return_action']);
111
            $this->ss->assign('RETURN_ID', $_REQUEST['record']);
112
            $this->bean->id = "";
113
            $this->bean->user_name = "";
114
            $this->ss->assign('ID','');
115
        } else {
116
            if(isset($_REQUEST['return_module']))
117
            {
118
                $this->ss->assign('RETURN_MODULE', $_REQUEST['return_module']);
119
            } else {
120
                $this->ss->assign('RETURN_MODULE', $this->bean->module_dir);
121
            }
122
123
            $return_id = isset($_REQUEST['return_id'])?$_REQUEST['return_id']:$this->bean->id;
124
            if (isset($return_id)) {
125
                $return_action = isset($_REQUEST['return_action'])?$_REQUEST['return_action']:'DetailView';
126
                $this->ss->assign('RETURN_ID', $return_id);
127
                $this->ss->assign('RETURN_ACTION', $return_action);
128
            }
129
        }
130
131
132
        ///////////////////////////////////////////////////////////////////////////////
133
        ////	REDIRECTS FROM COMPOSE EMAIL SCREEN
134
        if(isset($_REQUEST['type']) && (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Emails')) {
135
            $this->ss->assign('REDIRECT_EMAILS_TYPE', $_REQUEST['type']);
136
        }
137
        ////	END REDIRECTS FROM COMPOSE EMAIL SCREEN
138
        ///////////////////////////////////////////////////////////////////////////////
139
140
        ///////////////////////////////////////////////////////////////////////////////
141
        ////	NEW USER CREATION ONLY
142
        if(empty($this->bean->id)) {
143
            $this->ss->assign('SHOW_ADMIN_CHECKBOX','height="30"');
144
            $this->ss->assign('NEW_USER','1');
145
        }else{
146
            $this->ss->assign('NEW_USER','0');
147
            $this->ss->assign('NEW_USER_TYPE','DISABLED');
148
        }
149
150
        ////	END NEW USER CREATION ONLY
151
        ///////////////////////////////////////////////////////////////////////////////
152
153
154
        // FIXME: Translate error prefix
155
        if(isset($_REQUEST['error_string'])) $this->ss->assign('ERROR_STRING', '<span class="error">Error: '.$_REQUEST['error_string'].'</span>');
156
        if(isset($_REQUEST['error_password'])) $this->ss->assign('ERROR_PASSWORD', '<span id="error_pwd" class="error">Error: '.$_REQUEST['error_password'].'</span>');
157
158
159
160
161
        // Build viewable versions of a few fields for non-admins
162
        if(!empty($this->bean->id)) {
163
            if( !empty($this->bean->status) ) {
164
                $this->ss->assign('STATUS_READONLY',$app_list_strings['user_status_dom'][$this->bean->status]); }
165
            if( !empty($this->bean->employee_status) ) {
166
                $this->ss->assign('EMPLOYEE_STATUS_READONLY', $app_list_strings['employee_status_dom'][$this->bean->employee_status]);
167
            }
168
            if( !empty($this->bean->reports_to_id) ) {
169
                $reportsToUser = get_assigned_user_name($this->bean->reports_to_id);
170
                $reportsToUserField = "<input type='text' name='reports_to_name' id='reports_to_name' value='{$reportsToUser}' disabled>\n";
171
                $reportsToUserField .= "<input type='hidden' name='reports_to_id' id='reports_to_id' value='{$this->bean->reports_to_id}'>";
172
                $this->ss->assign('REPORTS_TO_READONLY', $reportsToUserField);
173
            }
174
            if( !empty($this->bean->title) ) {
175
                $this->ss->assign('TITLE_READONLY', $this->bean->title);
176
            }
177
            if( !empty($this->bean->department) ) {
178
                $this->ss->assign('DEPT_READONLY', $this->bean->department);
179
            }
180
        }
181
182
        $processSpecial = false;
183
        $processFormName = '';
184
        if ( isset($this->fieldHelper->usertype) && ($this->fieldHelper->usertype == 'GROUP'
185
            )) {
186
            $this->ev->formName = 'EditViewGroup';
187
188
            $processSpecial = true;
189
            $processFormName = 'EditViewGroup';
190
        }
191
192
        //Bug#51609 Replace {php} code block in EditViewHeader.tpl
193
        $action_button = array();
194
        $APP = $this->ss->get_template_vars('APP');
195
        $PWDSETTINGS = $this->ss->get_template_vars('PWDSETTINGS');
196
        $REGEX = $this->ss->get_template_vars('REGEX');
197
        $CHOOSER_SCRIPT = $this->ss->get_template_vars('CHOOSER_SCRIPT');
198
        $REASSIGN_JS = $this->ss->get_template_vars('REASSIGN_JS');
199
        $RETURN_ACTION = $this->ss->get_template_vars('RETURN_ACTION');
200
        $RETURN_MODULE = $this->ss->get_template_vars('RETURN_MODULE');
201
        $RETURN_ID = $this->ss->get_template_vars('RETURN_ID');
202
203
        $minpwdlength = !empty($PWDSETTINGS['minpwdlength']) ? $PWDSETTINGS['minpwdlength'] : '';
204
        $maxpwdlength =  !empty($PWDSETTINGS['maxpwdlength']) ? $PWDSETTINGS['maxpwdlength'] : '';
205
        $action_button_header[] = <<<EOD
206
                    <input type="button" id="SAVE_HEADER" title="{$APP['LBL_SAVE_BUTTON_TITLE']}" accessKey="{$APP['LBL_SAVE_BUTTON_KEY']}"
207
                          class="button primary" onclick="var _form = $('#EditView')[0]; if (!set_password(_form,newrules('{$minpwdlength}','{$maxpwdlength}','{$REGEX}'))) return false; if (!Admin_check()) return false; _form.action.value='Save'; {$CHOOSER_SCRIPT} {$REASSIGN_JS} if(verify_data(EditView)) _form.submit();"
208
                          name="button" value="{$APP['LBL_SAVE_BUTTON_LABEL']}">
209
EOD
210
        ;
211
        $action_button_header[] = <<<EOD
212
                    <input	title="{$APP['LBL_CANCEL_BUTTON_TITLE']}" id="CANCEL_HEADER" accessKey="{$APP['LBL_CANCEL_BUTTON_KEY']}"
213
                              class="button" onclick="var _form = $('#EditView')[0]; _form.action.value='{$RETURN_ACTION}'; _form.module.value='{$RETURN_MODULE}'; _form.record.value='{$RETURN_ID}'; _form.submit()"
214
                              type="button" name="button" value="{$APP['LBL_CANCEL_BUTTON_LABEL']}">
215
EOD
216
        ;
217
        $action_button_header = array_merge($action_button_header, $this->ss->get_template_vars('BUTTONS_HEADER'));
218
        $this->ss->assign('ACTION_BUTTON_HEADER', $action_button_header);
219
220
        $action_button_footer[] = <<<EOD
221
                    <input type="button" id="SAVE_FOOTER" title="{$APP['LBL_SAVE_BUTTON_TITLE']}" accessKey="{$APP['LBL_SAVE_BUTTON_KEY']}"
222
                          class="button primary" onclick="var _form = $('#EditView')[0]; if (!set_password(_form,newrules('{$minpwdlength}','{$maxpwdlength}','{$REGEX}'))) return false; if (!Admin_check()) return false; _form.action.value='Save'; {$CHOOSER_SCRIPT} {$REASSIGN_JS} if(verify_data(EditView)) _form.submit();"
223
                          name="button" value="{$APP['LBL_SAVE_BUTTON_LABEL']}">
224
EOD
225
        ;
226
        $action_button_footer[] = <<<EOD
227
                    <input	title="{$APP['LBL_CANCEL_BUTTON_TITLE']}" id="CANCEL_FOOTER" accessKey="{$APP['LBL_CANCEL_BUTTON_KEY']}"
228
                              class="button" onclick="var _form = $('#EditView')[0]; _form.action.value='{$RETURN_ACTION}'; _form.module.value='{$RETURN_MODULE}'; _form.record.value='{$RETURN_ID}'; _form.submit()"
229
                              type="button" name="button" value="{$APP['LBL_CANCEL_BUTTON_LABEL']}">
230
EOD
231
        ;
232
        $action_button_footer = array_merge($action_button_footer, $this->ss->get_template_vars('BUTTONS_FOOTER'));
233
        $this->ss->assign('ACTION_BUTTON_FOOTER', $action_button_footer);
234
235
        //if the request object has 'scrolltocal' set, then we are coming here from the tour window box and need to set flag to true
236
        // so that footer.tpl fires off script to scroll to calendar section
237
        if(!empty($_REQUEST['scrollToCal'])){
238
            $this->ss->assign('scroll_to_cal', true);
239
        }
240
        $this->ev->process($processSpecial,$processFormName);
0 ignored issues
show
Unused Code introduced by
The call to EditView::process() has too many arguments starting with $processSpecial.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
241
242
		echo $this->ev->display($this->showTitle);
0 ignored issues
show
Unused Code introduced by
The call to EditView::display() has too many arguments starting with $this->showTitle.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
243
244
    }
245
246
247
    /**
248
     * getHelpText
249
     *
250
     * This is a protected function that returns the help text portion.  It is called from getModuleTitle.
251
     * We override the function from SugarView.php to make sure the create link only appears if the current user
252
     * meets the valid criteria.
253
     *
254
     * @param $module String the formatted module name
255
     * @return $theTitle String the HTML for the help text
0 ignored issues
show
Documentation introduced by
The doc-type $theTitle could not be parsed: Unknown type name "$theTitle" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
256
     */
257
    protected function getHelpText($module)
258
    {
259
        $theTitle = '';
260
261
        if($GLOBALS['current_user']->isAdminForModule('Users')
262
        ) {
263
        $createImageURL = SugarThemeRegistry::current()->getImageURL('create-record.gif');
264
        $url = ajaxLink("index.php?module=$module&action=EditView&return_module=$module&return_action=DetailView");
265
        $theTitle = <<<EOHTML
266
&nbsp;
267
<img src='{$createImageURL}' alt='{$GLOBALS['app_strings']['LNK_CREATE']}'>
268
<a href="{$url}" class="utilsLink">
269
{$GLOBALS['app_strings']['LNK_CREATE']}
270
</a>
271
EOHTML;
272
        }
273
        return $theTitle;
274
    }
275
}