]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Users/views/view.edit.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Users / views / view.edit.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 require_once('modules/Users/UserViewHelper.php');
40
41
42 class UsersViewEdit extends ViewEdit {
43 var $useForSubpanel = true;
44         function UsersViewEdit(){
45                 parent::ViewEdit();
46         }
47
48     function preDisplay() {
49         $this->fieldHelper = new UserViewHelper($this->ss, $this->bean, 'EditView');
50         $this->fieldHelper->setupAdditionalFields();
51
52         parent::preDisplay();
53     }
54
55     public function getMetaDataFile() {
56         $userType = 'Regular';
57         if($this->fieldHelper->usertype == 'GROUP'){
58             $userType = 'Group';
59         }
60
61         if ( $userType != 'Regular' ) {
62             $oldType = $this->type;
63             $this->type = $oldType.'group';
64         }
65         $metadataFile = parent::getMetaDataFile();
66         if ( $userType != 'Regular' ) {
67             $this->type = $oldType;
68         }
69
70         return $metadataFile;
71     }
72
73     function display() {
74         global $current_user, $app_list_strings;
75
76
77         //lets set the return values
78         if(isset($_REQUEST['return_module'])){
79             $this->ss->assign('RETURN_MODULE',$_REQUEST['return_module']);
80         }
81
82         $this->ss->assign('IS_ADMIN', $current_user->is_admin ? true : false);
83
84         //make sure we can populate user type dropdown.  This usually gets populated in predisplay unless this is a quickeditform
85         if(!isset($this->fieldHelper)){
86             $this->fieldHelper = new UserViewHelper($this->ss, $this->bean, 'EditView');
87             $this->fieldHelper->setupAdditionalFields();
88         }
89
90         if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
91             $this->ss->assign('RETURN_MODULE', $_REQUEST['return_module']);
92             $this->ss->assign('RETURN_ACTION', $_REQUEST['return_action']);
93             $this->ss->assign('RETURN_ID', $_REQUEST['record']);
94             $this->bean->id = "";
95             $this->bean->user_name = "";
96             $this->ss->assign('ID','');
97         } else {
98             if(isset($_REQUEST['return_module']))
99             {
100                 $this->ss->assign('RETURN_MODULE', $_REQUEST['return_module']);
101             } else {
102                 $this->ss->assign('RETURN_MODULE', $this->bean->module_dir);
103             }
104
105             $return_id = isset($_REQUEST['return_id'])?$_REQUEST['return_id']:$this->bean->id;
106             if (isset($return_id)) {
107                 $return_action = isset($_REQUEST['return_action'])?$_REQUEST['return_action']:'DetailView';
108                 $this->ss->assign('RETURN_ID', $return_id);
109                 $this->ss->assign('RETURN_ACTION', $return_action);
110             }
111         }
112
113
114         ///////////////////////////////////////////////////////////////////////////////
115         ////    REDIRECTS FROM COMPOSE EMAIL SCREEN
116         if(isset($_REQUEST['type']) && (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Emails')) {
117             $this->ss->assign('REDIRECT_EMAILS_TYPE', $_REQUEST['type']);
118         }
119         ////    END REDIRECTS FROM COMPOSE EMAIL SCREEN
120         ///////////////////////////////////////////////////////////////////////////////
121
122         ///////////////////////////////////////////////////////////////////////////////
123         ////    NEW USER CREATION ONLY
124         if(empty($this->bean->id)) {
125             $this->ss->assign('SHOW_ADMIN_CHECKBOX','height="30"');
126             $this->ss->assign('NEW_USER','1');
127         }else{
128             $this->ss->assign('NEW_USER','0');
129             $this->ss->assign('NEW_USER_TYPE','DISABLED');
130         }
131
132         ////    END NEW USER CREATION ONLY
133         ///////////////////////////////////////////////////////////////////////////////
134
135
136         // FIXME: Translate error prefix
137         if(isset($_REQUEST['error_string'])) $this->ss->assign('ERROR_STRING', '<span class="error">Error: '.$_REQUEST['error_string'].'</span>');
138         if(isset($_REQUEST['error_password'])) $this->ss->assign('ERROR_PASSWORD', '<span id="error_pwd" class="error">Error: '.$_REQUEST['error_password'].'</span>');
139
140
141
142
143         // Build viewable versions of a few fields for non-admins
144         if(!empty($this->bean->id)) {
145             if( !empty($this->bean->status) ) {
146                 $this->ss->assign('STATUS_READONLY',$app_list_strings['user_status_dom'][$this->bean->status]); }
147             if( !empty($this->bean->employee_status) ) {
148                 $this->ss->assign('EMPLOYEE_STATUS_READONLY', $app_list_strings['employee_status_dom'][$this->bean->employee_status]);
149             }
150             if( !empty($this->bean->reports_to_id) ) {
151                 $reportsToUser = get_assigned_user_name($this->bean->reports_to_id);
152                 $reportsToUserField = "<input type='text' name='reports_to_name' id='reports_to_name' value='{$reportsToUser}' disabled>\n";
153                 $reportsToUserField .= "<input type='hidden' name='reports_to_id' id='reports_to_id' value='{$this->bean->reports_to_id}'>";
154                 $this->ss->assign('REPORTS_TO_READONLY', $reportsToUserField);
155             }
156             if( !empty($this->bean->title) ) {
157                 $this->ss->assign('TITLE_READONLY', $this->bean->title);
158             }
159             if( !empty($this->bean->department) ) {
160                 $this->ss->assign('DEPT_READONLY', $this->bean->department);
161             }
162         }
163
164         $processSpecial = false;
165         $processFormName = '';
166         if ( isset($this->fieldHelper->usertype) && ($this->fieldHelper->usertype == 'GROUP'
167             )) {
168             $this->ev->formName = 'EditViewGroup';
169
170             $processSpecial = true;
171             $processFormName = 'EditViewGroup';
172         }
173
174         //Bug#51609 Replace {php} code block in EditViewHeader.tpl
175         $action_button = array();
176         $APP = $this->ss->get_template_vars('APP');
177         $PWDSETTINGS = $this->ss->get_template_vars('PWDSETTINGS');
178         $REGEX = $this->ss->get_template_vars('REGEX');
179         $CHOOSER_SCRIPT = $this->ss->get_template_vars('CHOOSER_SCRIPT');
180         $REASSIGN_JS = $this->ss->get_template_vars('REASSIGN_JS');
181         $RETURN_ACTION = $this->ss->get_template_vars('RETURN_ACTION');
182         $RETURN_MODULE = $this->ss->get_template_vars('RETURN_MODULE');
183         $RETURN_ID = $this->ss->get_template_vars('RETURN_ID');
184
185         $minpwdlength = !empty($PWDSETTINGS['minpwdlength']) ? $PWDSETTINGS['minpwdlength'] : '';
186         $maxpwdlength =  !empty($PWDSETTINGS['maxpwdlength']) ? $PWDSETTINGS['maxpwdlength'] : '';
187         $action_button_header[] = <<<EOD
188                     <input type="button" id="SAVE_HEADER" title="{$APP['LBL_SAVE_BUTTON_TITLE']}" accessKey="{$APP['LBL_SAVE_BUTTON_KEY']}"
189                           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();"
190                           name="button" value="{$APP['LBL_SAVE_BUTTON_LABEL']}">
191 EOD
192         ;
193         $action_button_header[] = <<<EOD
194                     <input      title="{$APP['LBL_CANCEL_BUTTON_TITLE']}" id="CANCEL_HEADER" accessKey="{$APP['LBL_CANCEL_BUTTON_KEY']}"
195                               class="button" onclick="var _form = $('#EditView')[0]; _form.action.value='{$RETURN_ACTION}'; _form.module.value='{$RETURN_MODULE}'; _form.record.value='{$RETURN_ID}'; _form.submit()"
196                               type="button" name="button" value="{$APP['LBL_CANCEL_BUTTON_LABEL']}">
197 EOD
198         ;
199         $action_button_header = array_merge($action_button_header, $this->ss->get_template_vars('BUTTONS_HEADER'));
200         $this->ss->assign('ACTION_BUTTON_HEADER', $action_button_header);
201
202         $action_button_footer[] = <<<EOD
203                     <input type="button" id="SAVE_FOOTER" title="{$APP['LBL_SAVE_BUTTON_TITLE']}" accessKey="{$APP['LBL_SAVE_BUTTON_KEY']}"
204                           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();"
205                           name="button" value="{$APP['LBL_SAVE_BUTTON_LABEL']}">
206 EOD
207         ;
208         $action_button_footer[] = <<<EOD
209                     <input      title="{$APP['LBL_CANCEL_BUTTON_TITLE']}" id="CANCEL_FOOTER" accessKey="{$APP['LBL_CANCEL_BUTTON_KEY']}"
210                               class="button" onclick="var _form = $('#EditView')[0]; _form.action.value='{$RETURN_ACTION}'; _form.module.value='{$RETURN_MODULE}'; _form.record.value='{$RETURN_ID}'; _form.submit()"
211                               type="button" name="button" value="{$APP['LBL_CANCEL_BUTTON_LABEL']}">
212 EOD
213         ;
214         $action_button_footer = array_merge($action_button_footer, $this->ss->get_template_vars('BUTTONS_FOOTER'));
215         $this->ss->assign('ACTION_BUTTON_FOOTER', $action_button_footer);
216
217         $this->ev->process($processSpecial,$processFormName);
218
219                 echo $this->ev->display($this->showTitle);
220
221     }
222
223
224     /**
225      * getHelpText
226      *
227      * This is a protected function that returns the help text portion.  It is called from getModuleTitle.
228      * We override the function from SugarView.php to make sure the create link only appears if the current user
229      * meets the valid criteria.
230      *
231      * @param $module String the formatted module name
232      * @return $theTitle String the HTML for the help text
233      */
234     protected function getHelpText($module)
235     {
236         $theTitle = '';
237
238         if($GLOBALS['current_user']->isAdminForModule('Users')
239         ) {
240         $createImageURL = SugarThemeRegistry::current()->getImageURL('create-record.gif');
241         $url = ajaxLink("index.php?module=$module&action=EditView&return_module=$module&return_action=DetailView");
242         $theTitle = <<<EOHTML
243 &nbsp;
244 <img src='{$createImageURL}' alt='{$GLOBALS['app_strings']['LNK_CREATE']}'>
245 <a href="{$url}" class="utilsLink">
246 {$GLOBALS['app_strings']['LNK_CREATE']}
247 </a>
248 EOHTML;
249         }
250         return $theTitle;
251     }
252 }