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.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once('modules/Users/UserViewHelper.php');
42 class UsersViewEdit extends ViewEdit {
43 var $useForSubpanel = true;
44 function UsersViewEdit(){
48 function preDisplay() {
49 $this->fieldHelper = new UserViewHelper($this->ss, $this->bean, 'EditView');
50 $this->fieldHelper->setupAdditionalFields();
55 public function getMetaDataFile() {
56 $userType = 'Regular';
57 if($this->fieldHelper->usertype == 'GROUP'){
61 if ( $userType != 'Regular' ) {
62 $oldType = $this->type;
63 $this->type = $oldType.'group';
65 $metadataFile = parent::getMetaDataFile();
66 if ( $userType != 'Regular' ) {
67 $this->type = $oldType;
74 global $current_user, $app_list_strings;
77 //lets set the return values
78 if(isset($_REQUEST['return_module'])){
79 $this->ss->assign('RETURN_MODULE',$_REQUEST['return_module']);
82 $this->ss->assign('IS_ADMIN', $current_user->is_admin ? true : false);
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();
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']);
95 $this->bean->user_name = "";
96 $this->ss->assign('ID','');
98 if(isset($_REQUEST['return_module']))
100 $this->ss->assign('RETURN_MODULE', $_REQUEST['return_module']);
102 $this->ss->assign('RETURN_MODULE', $this->bean->module_dir);
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);
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']);
119 //// END REDIRECTS FROM COMPOSE EMAIL SCREEN
120 ///////////////////////////////////////////////////////////////////////////////
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');
128 $this->ss->assign('NEW_USER','0');
129 $this->ss->assign('NEW_USER_TYPE','DISABLED');
132 //// END NEW USER CREATION ONLY
133 ///////////////////////////////////////////////////////////////////////////////
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>');
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]);
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);
156 if( !empty($this->bean->title) ) {
157 $this->ss->assign('TITLE_READONLY', $this->bean->title);
159 if( !empty($this->bean->department) ) {
160 $this->ss->assign('DEPT_READONLY', $this->bean->department);
164 $processSpecial = false;
165 $processFormName = '';
166 if ( isset($this->fieldHelper->usertype) && ($this->fieldHelper->usertype == 'GROUP'
168 $this->ev->formName = 'EditViewGroup';
170 $processSpecial = true;
171 $processFormName = 'EditViewGroup';
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');
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']}">
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']}">
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);
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']}">
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']}">
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);
217 //if the request object has 'scrolltocal' set, then we are coming here from the tour window box and need to set flag to true
218 // so that footer.tpl fires off script to scroll to calendar section
219 if(!empty($_REQUEST['scrollToCal'])){
220 $this->ss->assign('scroll_to_cal', true);
222 $this->ev->process($processSpecial,$processFormName);
224 echo $this->ev->display($this->showTitle);
232 * This is a protected function that returns the help text portion. It is called from getModuleTitle.
233 * We override the function from SugarView.php to make sure the create link only appears if the current user
234 * meets the valid criteria.
236 * @param $module String the formatted module name
237 * @return $theTitle String the HTML for the help text
239 protected function getHelpText($module)
243 if($GLOBALS['current_user']->isAdminForModule('Users')
245 $createImageURL = SugarThemeRegistry::current()->getImageURL('create-record.gif');
246 $url = ajaxLink("index.php?module=$module&action=EditView&return_module=$module&return_action=DetailView");
247 $theTitle = <<<EOHTML
249 <img src='{$createImageURL}' alt='{$GLOBALS['app_strings']['LNK_CREATE']}'>
250 <a href="{$url}" class="utilsLink">
251 {$GLOBALS['app_strings']['LNK_CREATE']}