Feature #306 - Platform admin tool: Cleaning code + minor fixes in add/edit user forms.

skala
Ivan Tcholakov 16 years ago
parent a1dafa630c
commit c2f9d649d7
  1. 314
      main/admin/user_add.php
  2. 402
      main/admin/user_edit.php

@ -5,24 +5,26 @@
* @package dokeos.admin
==============================================================================
*/
// name of the language file that needs to be included
$language_file = array('admin','registration');
// Language files that should be included
$language_file = array('admin', 'registration');
$cidReset = true;
// including necessary libraries
// Including necessary libraries.
require '../inc/global.inc.php';
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'fileManage.lib.php';
require_once $libpath.'fileUpload.lib.php';
require_once $libpath.'usermanager.lib.php';
require_once $libpath.'formvalidator/FormValidator.class.php';
require_once api_get_path(LIBRARY_PATH).'image.lib.php';
require_once api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php';
require_once $libpath.'image.lib.php';
require_once $libpath.'mail.lib.inc.php';
// section for the tabs
$this_section=SECTION_PLATFORM_ADMIN;
// Section for the tabs
$this_section = SECTION_PLATFORM_ADMIN;
// user permissions
// User permissions
api_protect_admin_script();
// Database table definitions
@ -31,18 +33,18 @@ $table_user = Database :: get_main_table(TABLE_MAIN_USER);
$database = Database::get_main_database();
$htmlHeadXtra[] = '
<script language="JavaScript" type="text/JavaScript">
<script type="text/javascript">
<!--
function enable_expiration_date() { //v2.0
document.user_add.radio_expiration_date[0].checked=false;
document.user_add.radio_expiration_date[1].checked=true;
}
function password_switch_radio_button(form, input){
var NodeList = document.getElementsByTagName("input");
for(var i=0; i< NodeList.length; i++){
if(NodeList.item(i).name=="password[password_auto]" && NodeList.item(i).value=="0"){
NodeList.item(i).checked=true;
function password_switch_radio_button() {
var input_elements = document.getElementsByTagName("input");
for (var i = 0; i < input_elements.length; i++) {
if (input_elements.item(i).name == "password[password_auto]" && input_elements.item(i).value == "0") {
input_elements.item(i).checked = true;
}
}
}
@ -64,54 +66,53 @@ function display_drh_list(){
//-->
</script>';
if(!empty($_GET['message'])){
if (!empty($_GET['message'])) {
$message = urldecode($_GET['message']);
}
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$tool_name = get_lang('AddUsers');
// Create the form
$form = new FormValidator('user_add');
$form->addElement('header', '', $tool_name);
if (api_is_western_name_order())
{
if (api_is_western_name_order()) {
// Firstname
$form->addElement('text','firstname',get_lang('FirstName'));
$form->applyFilter('firstname','html_filter');
$form->applyFilter('firstname','trim');
$form->addElement('text', 'firstname', get_lang('FirstName'));
$form->applyFilter('firstname', 'html_filter');
$form->applyFilter('firstname', 'trim');
$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
// Lastname
$form->addElement('text','lastname',get_lang('LastName'));
$form->applyFilter('lastname','html_filter');
$form->applyFilter('lastname','trim');
$form->addElement('text', 'lastname', get_lang('LastName'));
$form->applyFilter('lastname', 'html_filter');
$form->applyFilter('lastname', 'trim');
$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
}
else
{
} else {
// Lastname
$form->addElement('text','lastname',get_lang('LastName'));
$form->applyFilter('lastname','html_filter');
$form->applyFilter('lastname','trim');
$form->addElement('text', 'lastname', get_lang('LastName'));
$form->applyFilter('lastname', 'html_filter');
$form->applyFilter('lastname', 'trim');
$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
// Firstname
$form->addElement('text','firstname',get_lang('FirstName'));
$form->applyFilter('firstname','html_filter');
$form->applyFilter('firstname','trim');
$form->addElement('text', 'firstname', get_lang('FirstName'));
$form->applyFilter('firstname', 'html_filter');
$form->applyFilter('firstname', 'trim');
$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
}
// Official code
$form->addElement('text', 'official_code', get_lang('OfficialCode'),array('size' => '40'));
$form->applyFilter('official_code','html_filter');
$form->applyFilter('official_code','trim');
$form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => '40'));
$form->applyFilter('official_code', 'html_filter');
$form->applyFilter('official_code', 'trim');
// Email
$form->addElement('text', 'email', get_lang('Email'),array('size' => '40'));
$form->addElement('text', 'email', get_lang('Email'), array('size' => '40'));
$form->addRule('email', get_lang('EmailWrong'), 'email');
$form->addRule('email', get_lang('EmailWrong'), 'required');
// Phone
$form->addElement('text','phone',get_lang('PhoneNumber'));
$form->addElement('text', 'phone', get_lang('PhoneNumber'));
// Picture
$form->addElement('file', 'picture', get_lang('AddPicture'));
$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
$form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
// Username
$form->addElement('text', 'username', get_lang('LoginName'), array('maxlength' => USERNAME_MAX_LENGTH));
@ -122,46 +123,42 @@ $form->addRule('username', get_lang('UserTaken'), 'username_available', $user_da
// Password
$group = array();
$auth_sources = 0; //make available wider as we need it in case of form reset (see below)
if(count($extAuthSource) > 0)
{
$group[] =& HTML_QuickForm::createElement('radio','password_auto',null,get_lang('ExternalAuthentication').' ',2);
if (count($extAuthSource) > 0) {
$group[] =& HTML_QuickForm::createElement('radio', 'password_auto', null, get_lang('ExternalAuthentication').' ', 2);
$auth_sources = array();
foreach($extAuthSource as $key => $info)
{
foreach($extAuthSource as $key => $info) {
$auth_sources[$key] = $key;
}
$group[] =& HTML_QuickForm::createElement('select','auth_source',null,$auth_sources);
$group[] =& HTML_QuickForm::createElement('static','','','<br />');
$group[] =& HTML_QuickForm::createElement('select', 'auth_source', null, $auth_sources);
$group[] =& HTML_QuickForm::createElement('static', '', '', '<br />');
}
$group[] =& HTML_QuickForm::createElement('radio','password_auto',get_lang('Password'),get_lang('AutoGeneratePassword').'<br />',1);
$group[] =& HTML_QuickForm::createElement('radio', 'password_auto','id="radio_user_password"',null,0);
$group[] =& HTML_QuickForm::createElement('password', 'password',null,'onkeydown=password_switch_radio_button(document.user_add,"password[password_auto]")');
$group[] =& HTML_QuickForm::createElement('radio', 'password_auto', get_lang('Password'), get_lang('AutoGeneratePassword').'<br />', 1);
$group[] =& HTML_QuickForm::createElement('radio', 'password_auto', 'id="radio_user_password"', null, 0);
$group[] =& HTML_QuickForm::createElement('password', 'password', null, array('onkeydown' => 'javascript: password_switch_radio_button();'));
$form->addGroup($group, 'password', get_lang('Password'), '');
// Status
$status = array();
$status[COURSEMANAGER] = get_lang('Teacher');
$status[COURSEMANAGER] = get_lang('Teacher');
$status[STUDENT] = get_lang('Learner');
$status[DRH] = get_lang('Drh');
$status[SESSIONADMIN] = get_lang('SessionsAdmin');
$form->addElement('select','status',get_lang('Status'),$status,'id="status_select" onchange="display_drh_list()"');
$form->addElement('select', 'status', get_lang('Status'), $status, array('id' => 'status_select', 'onchange' => 'javascript: display_drh_list();'));
$form->addElement('select_language', 'language', get_lang('Language'));
//drh list (display only if student)
$display = ($_POST['status'] == STUDENT || !isset($_POST['status'])) ? 'block' : 'none';
$form->addElement('html','<div id="drh_list" style="display:'.$display.';">');
$drh_select = $form->addElement('select','hr_dept_id',get_lang('Drh'),array(),'id="drh_select"');
$drh_list = UserManager :: get_user_list(array('status'=>DRH),array('lastname','firstname'));
$form->addElement('html', '<div id="drh_list" style="display:'.$display.';">');
$drh_select = $form->addElement('select', 'hr_dept_id', get_lang('Drh'), array(), 'id="drh_select"');
$drh_list = UserManager :: get_user_list(array('status' => DRH), api_sort_by_first_name() ? array('firstname', 'lastname') : array('lastname', 'firstname'));
if (count($drh_list) == 0) {
$drh_select->addOption('- '.get_lang('ThereIsNotStillAResponsible').' -',0);
$drh_select->addOption('- '.get_lang('ThereIsNotStillAResponsible', '').' -', 0);
} else {
$drh_select->addOption('- '.get_lang('SelectAResponsible').' -',0);
$drh_select->addOption('- '.get_lang('SelectAResponsible').' -', 0);
}
if(is_array($drh_list))
{
foreach($drh_list as $drh)
{
if (is_array($drh_list)) {
foreach ($drh_list as $drh) {
$drh_select->addOption(api_get_person_name($drh['firstname'], $drh['lastname']), $drh['user_id']);
}
}
@ -169,36 +166,34 @@ $form->addElement('html', '</div>');
// Platform admin
$group = array();
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin','id="id_platform_admin"',get_lang('Yes'),1);
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin','id="id_platform_admin"',get_lang('No'),0);
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin', 'id="id_platform_admin"', get_lang('Yes'), 1);
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin', 'id="id_platform_admin"', get_lang('No'), 0);
$display = ($_POST['status'] == STUDENT || !isset($_POST['status'])) ? 'none' : 'block';
$form->addElement('html','<div id="id_platform_admin" style="display:'.$display.';">');
$form->addElement('html', '<div id="id_platform_admin" style="display:'.$display.';">');
$form->addGroup($group, 'admin', get_lang('PlatformAdmin'), '&nbsp;');
$form->addElement('html', '</div>');
// Send email
$group = array();
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail',null,get_lang('Yes'),1);
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail',null,get_lang('No'),0);
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail', null, get_lang('Yes'), 1);
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail', null, get_lang('No'), 0);
$form->addGroup($group, 'mail', get_lang('SendMailToNewUser'), '&nbsp;');
// Expiration Date
$form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
$group = array ();
$group[] = & $form->createElement('radio', 'radio_expiration_date', null, get_lang('On'), 1);
$group[] = & $form->createElement('datepicker','expiration_date', null, array ('form_name' => $form->getAttribute('name'), 'onChange'=>'enable_expiration_date()'));
$group[] = & $form->createElement('datepicker', 'expiration_date', null, array('form_name' => $form->getAttribute('name'), 'onchange' => 'javascript: enable_expiration_date();'));
$form->addGroup($group, 'max_member_group', null, '', false);
// Active account or inactive account
$form->addElement('radio','active',get_lang('ActiveAccount'),get_lang('Active'),1);
$form->addElement('radio','active','',get_lang('Inactive'),0);
$form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
$form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
// EXTRA FIELDS
$extra = UserManager::get_extra_fields(0,50,5,'ASC');
$extra_data = UserManager::get_extra_user_data(0,true);
foreach($extra as $id => $field_details)
{
if ($field_details[6]==1) { // only show extra fields that are visible
switch($field_details[2])
{
$extra = UserManager::get_extra_fields(0, 50, 5, 'ASC');
$extra_data = UserManager::get_extra_user_data(0, true);
foreach($extra as $id => $field_details) {
if ($field_details[6] == 1) { // only show extra fields that are visible
switch ($field_details[2]) {
case USER_FIELD_TYPE_TEXT:
$form->addElement('text', 'extra_'.$field_details[1], $field_details[3], array('size' => 40));
$form->applyFilter('extra_'.$field_details[1], 'stripslashes');
@ -212,109 +207,97 @@ foreach($extra as $id => $field_details)
break;
case USER_FIELD_TYPE_RADIO:
$group = array();
foreach($field_details[9] as $option_id => $option_details)
{
foreach ($field_details[9] as $option_id => $option_details) {
$options[$option_details[1]] = $option_details[2];
$group[] =& HTML_QuickForm::createElement('radio', 'extra_'.$field_details[1], $option_details[1],$option_details[2].'<br />',$option_details[1]);
$group[] =& HTML_QuickForm::createElement('radio', 'extra_'.$field_details[1], $option_details[1], $option_details[2].'<br />', $option_details[1]);
}
$form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], '');
break;
case USER_FIELD_TYPE_SELECT:
$options = array();
foreach($field_details[9] as $option_id => $option_details)
{
foreach($field_details[9] as $option_id => $option_details) {
$options[$option_details[1]] = $option_details[2];
}
$form->addElement('select','extra_'.$field_details[1],$field_details[3],$options,'');
break;
case USER_FIELD_TYPE_SELECT_MULTIPLE:
$options = array();
foreach($field_details[9] as $option_id => $option_details)
{
foreach($field_details[9] as $option_id => $option_details) {
$options[$option_details[1]] = $option_details[2];
}
$form->addElement('select','extra_'.$field_details[1],$field_details[3],$options,array('multiple' => 'multiple'));
$form->addElement('select', 'extra_'.$field_details[1], $field_details[3], $options, array('multiple' => 'multiple'));
break;
case USER_FIELD_TYPE_DATE:
$form->addElement('datepickerdate', 'extra_'.$field_details[1], $field_details[3],array('form_name'=>'user_add'));
$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900);
$form->addElement('datepickerdate', 'extra_'.$field_details[1], $field_details[3], array('form_name' => 'user_add'));
$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
$defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
$form -> setDefaults($defaults);
$form->applyFilter('theme', 'trim');
break;
case USER_FIELD_TYPE_DATETIME:
$form->addElement('datepicker', 'extra_'.$field_details[1], $field_details[3],array('form_name'=>'user_add'));
$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900);
$form->addElement('datepicker', 'extra_'.$field_details[1], $field_details[3], array('form_name' => 'user_add'));
$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
$defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
$form -> setDefaults($defaults);
$form->applyFilter('theme', 'trim');
break;
case USER_FIELD_TYPE_DOUBLE_SELECT:
foreach ($field_details[9] as $key=>$element)
{
if ($element[2][0] == '*')
{
foreach ($field_details[9] as $key => $element) {
if ($element[2][0] == '*') {
$values['*'][$element[0]] = str_replace('*','',$element[2]);
}
else
{
} else {
$values[0][$element[0]] = $element[2];
}
}
$group='';
$group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1],'',$values[0],'');
$group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1].'*','',$values['*'],'');
$group = '';
$group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1], '', $values[0], '');
$group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1].'*', '', $values['*'], '');
$form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], '&nbsp;');
if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
// recoding the selected values for double : if the user has selected certain values, we have to assign them to the correct select form
if (key_exists('extra_'.$field_details[1], $extra_data))
{
if (key_exists('extra_'.$field_details[1], $extra_data)) {
// exploding all the selected values (of both select forms)
$selected_values = explode(';',$extra_data['extra_'.$field_details[1]]);
$extra_data['extra_'.$field_details[1]] =array();
$selected_values = explode(';', $extra_data['extra_'.$field_details[1]]);
$extra_data['extra_'.$field_details[1]] = array();
// looping through the selected values and assigning the selected values to either the first or second select form
foreach ($selected_values as $key=>$selected_value)
{
if (key_exists($selected_value,$values[0]))
{
foreach ($selected_values as $key => $selected_value) {
if (key_exists($selected_value, $values[0])) {
$extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1]] = $selected_value;
}
else
{
} else {
$extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1].'*'] = $selected_value;
}
}
}
break;
case USER_FIELD_TYPE_DIVIDER:
$form->addElement('static',$field_details[1], '<br /><strong>'.$field_details[3].'</strong>');
$form->addElement('static', $field_details[1], '<br /><strong>'.$field_details[3].'</strong>');
break;
}
}
}
// Set default values
$defaults['admin']['platform_admin'] = 0;
$defaults['mail']['send_mail'] = 1;
$defaults['password']['password_auto'] = 1;
$defaults['active'] = 1;
$defaults['expiration_date']=array();
$defaults['expiration_date'] = array();
$days = api_get_setting('account_valid_duration');
$time = strtotime('+'.$days.' day');
$defaults['expiration_date']['d']=date('d',$time);
$defaults['expiration_date']['F']=date('m',$time);
$defaults['expiration_date']['Y']=date('Y',$time);
$defaults['expiration_date']['d'] = date('d', $time);
$defaults['expiration_date']['F'] = date('m', $time);
$defaults['expiration_date']['Y'] = date('Y', $time);
$defaults['radio_expiration_date'] = 0;
$defaults['status'] = STUDENT;
$defaults = array_merge($defaults,$extra_data);
$defaults = array_merge($defaults, $extra_data);
$form->setDefaults($defaults);
// Submit button
/*
$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"') ;
$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
$form->addElement('style_submit_button', 'submit_plus', get_lang('Add').'+', 'class="add"');
*/
$select_level = array ();
@ -323,11 +306,9 @@ $html_results_enabled[] = FormValidator :: createElement ('style_submit_button',
$form->addGroup($html_results_enabled);
// Validate form
if( $form->validate())
{
if( $form->validate()) {
$check = Security::check_token('post');
if($check)
{
if ($check) {
$user = $form->exportValues();
$picture_element = & $form->getElement('picture');
@ -347,27 +328,21 @@ if( $form->validate())
$platform_admin = intval($user['admin']['platform_admin']);
$send_mail = intval($user['mail']['send_mail']);
$hr_dept_id = intval($user['hr_dept_id']);
if(count($extAuthSource) > 0 && $user['password']['password_auto'] == '2')
{
if (count($extAuthSource) > 0 && $user['password']['password_auto'] == '2') {
$auth_source = $user['password']['auth_source'];
$password = 'PLACEHOLDER';
}
else
{
} else {
$auth_source = PLATFORM_AUTH_SOURCE;
$password = $user['password']['password_auto'] == '1' ? api_generate_password() : $user['password']['password'];
}
if ($user['radio_expiration_date']=='1' )
{
$expiration_date=$user['expiration_date'];
}
else
{
$expiration_date='0000-00-00 00:00:00';
if ($user['radio_expiration_date'] == '1') {
$expiration_date = $user['expiration_date'];
} else {
$expiration_date = '0000-00-00 00:00:00';
}
$active = intval($user['active']);
$user_id = UserManager::create_user($firstname,$lastname,$status,$email,$username,$password,$official_code,$language,$phone,$picture_uri,$auth_source,$expiration_date,$active, $hr_dept_id);
$user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, $language, $phone, $picture_uri, $auth_source, $expiration_date, $active, $hr_dept_id);
if (!empty($picture['name'])) {
@ -375,21 +350,21 @@ if( $form->validate())
if (api_get_setting('split_users_upload_directory') === 'true') {
$picture_path = api_get_path(SYS_CODE_PATH).'upload/users/'.substr((string)$user_id, 0, 1).'/'.$user_id.'/';
} else {
$picture_path = api_get_path(SYS_CODE_PATH).'upload/users/'.$user_id.'/';
$picture_path = api_get_path(SYS_CODE_PATH).'upload/users/'.$user_id.'/';
}
$picture_uri = $user_id.'_'.uniqid('').'_'.replace_dangerous_char($picture['name']);
UserManager::update_user($user_id,$firstname,$lastname,$username,$password,$auth_source,$email,$status,$official_code,$phone,$picture_uri,$expiration_date, $active, null, $hr_dept_id,null,$language);
UserManager::update_user($user_id, $firstname, $lastname, $username, $password, $auth_source, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, null, $hr_dept_id, null, $language);
$perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm)?$perm:'0770');
$perm = octdec(!empty($perm) ? $perm : '0770');
if (!file_exists($picture_path)) {
@mkdir($picture_path, $perm, true);
}
$picture_infos=@getimagesize($_FILES['picture']['tmp_name']);
$type=$picture_infos[2];
$picture_info = @getimagesize($_FILES['picture']['tmp_name']);
$type=$picture_info[2];
$small_picture = UserManager::resize_picture($_FILES['picture']['tmp_name'], 22);
$medium_picture = UserManager::resize_picture($_FILES['picture']['tmp_name'], 85);
$normal_picture = UserManager::resize_picture($_FILES['picture']['tmp_name'], 200);
@ -397,75 +372,64 @@ if( $form->validate())
$picture_types = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG');
if (in_array($type, array_keys($picture_types))) {
$small_picture->send_image($picture_types[$type], $picture_path.'small_'.$picture_uri);
$small_picture->send_image($picture_types[$type], $picture_path.'small_'.$picture_uri);
$medium_picture->send_image($picture_types[$type], $picture_path.'medium_'.$picture_uri);
$normal_picture->send_image($picture_types[$type], $picture_path.$picture_uri);
$big_picture->send_image($picture_types[$type], $picture_path.'big_'.$picture_uri);
}
$normal_picture->send_image($picture_types[$type], $picture_path.$picture_uri);
$big_picture->send_image($picture_types[$type], $picture_path.'big_'.$picture_uri);
}
}
$extras = array();
foreach($user as $key => $value)
{
if(substr($key,0,6)=='extra_') //an extra field
{
$myres = UserManager::update_extra_field_value($user_id,substr($key,6),$value);
foreach($user as $key => $value) {
if (substr($key, 0, 6) == 'extra_') { //an extra field
$myres = UserManager::update_extra_field_value($user_id, substr($key, 6), $value);
}
}
if ($platform_admin)
{
if ($platform_admin) {
$sql = "INSERT INTO $table_admin SET user_id = '".$user_id."'";
api_sql_query($sql,__FILE__,__LINE__);
Database::query($sql,__FILE__,__LINE__);
}
if (!empty ($email) && $send_mail)
{
if (!empty($email) && $send_mail) {
$recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS);
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
$email_admin = api_get_setting('emailAdministrator');
if ($_configuration['multiple_access_urls']==true) {
if ($_configuration['multiple_access_urls'] == true) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1 ){
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$emailbody=get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('Settings')." ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('Settings')." ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
}
else {
$emailbody=get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('Settings')." ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('Settings')." ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
@api_mail($recipient_name, $email, $emailsubject, $emailbody, $sender_name,$email_admin);
@api_mail($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}
Security::clear_token();
if(isset($user['submit_plus']))
{
if (isset($user['submit_plus'])) {
//we want to add more. Prepare report message and redirect to the same page (to clean the form)
$tok = Security::get_token();
header('Location: user_add.php?message='.urlencode(get_lang('UserAdded')).'&sec_token='.$tok);
exit ();
}
else
{
} else {
$tok = Security::get_token();
header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('UserAdded')).'&sec_token='.$tok);
exit ();
}
}
}
else
{
if(isset($_POST['submit']))
{
} else {
if (isset($_POST['submit'])) {
Security::clear_token();
}
$token = Security::get_token();
$form->addElement('hidden','sec_token');
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
}
// Display form
Display::display_header($tool_name);
//api_display_tool_title($tool_name);
@ -473,10 +437,6 @@ if(!empty($message)){
Display::display_normal_message(stripslashes($message));
}
$form->display();
/*
==============================================================================
FOOTER
==============================================================================
*/
// Footer
Display::display_footer();
?>

@ -1,48 +1,39 @@
<?php // $Id: user_edit.php 22233 2009-07-20 09:54:05Z ivantcholakov $
/*
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004-2008 Dokeos SPRL
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
Copyright (c) Bart Mollet, Hogeschool Gent
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
==============================================================================
*/
/* For licensing terms, see /dokeos_license.txt */
/**
==============================================================================
* @package dokeos.admin
==============================================================================
*/
// name of the language file that needs to be included
$language_file=array('admin','registration');
$cidReset=true;
include('../inc/global.inc.php');
$this_section=SECTION_PLATFORM_ADMIN;
// Language files that should be included
$language_file = array('admin', 'registration');
$cidReset = true;
include '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
$htmlHeadXtra[] = '
<script language="JavaScript" type="text/JavaScript">
<script type="text/javascript">
<!--
function enable_expiration_date() { //v2.0
document.user_edit.radio_expiration_date[0].checked=false;
document.user_edit.radio_expiration_date[1].checked=true;
}
function password_switch_radio_button(){
var input_elements = document.getElementsByTagName("input");
for (var i = 0; i < input_elements.length; i++) {
if(input_elements.item(i).name == "reset_password" && input_elements.item(i).value == "2") {
input_elements.item(i).checked = true;
}
}
}
function display_drh_list(){
if(document.getElementById("status_select").value=='.STUDENT.')
{
@ -63,94 +54,90 @@ function show_image(image,width,height) {
//-->
</script>';
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'fileManage.lib.php';
require_once $libpath.'fileUpload.lib.php';
require_once $libpath.'usermanager.lib.php';
require_once $libpath.'formvalidator/FormValidator.class.php';
require_once $libpath.'image.lib.php';
require_once $libpath.'mail.lib.inc.php';
require_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');
require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
require_once (api_get_path(LIBRARY_PATH).'image.lib.php');
require_once(api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php');
$user_id=isset($_GET['user_id']) ? intval($_GET['user_id']) : intval($_POST['user_id']);
$noPHP_SELF=true;
$tool_name=get_lang('ModifyUserInfo');
$user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : intval($_POST['user_id']);
$noPHP_SELF = true;
$tool_name = get_lang('ModifyUserInfo');
$interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
$interbreadcrumb[]=array('url' => "user_list.php","name" => get_lang('UserList'));
$interbreadcrumb[] = array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => "user_list.php","name" => get_lang('UserList'));
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$table_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
$sql = "SELECT u.*, a.user_id AS is_admin FROM $table_user u LEFT JOIN $table_admin a ON a.user_id = u.user_id WHERE u.user_id = '".$user_id."'";
$res = api_sql_query($sql,__FILE__,__LINE__);
if(mysql_num_rows($res) != 1)
{
$res = Database::query($sql, __FILE__, __LINE__);
if (Database::num_rows($res) != 1) {
header('Location: user_list.php');
exit;
}
$user_data = mysql_fetch_array($res,MYSQL_ASSOC);
$user_data = Database::fetch_array($res, 'ASSOC');
$user_data['platform_admin'] = is_null($user_data['is_admin']) ? 0 : 1;
$user_data['send_mail'] = 0;
$user_data['old_password'] = $user_data['password'];
unset($user_data['password']);
$user_data = array_merge($user_data, Usermanager :: get_extra_user_data($user_id,true));
$user_data = array_merge($user_data, Usermanager :: get_extra_user_data($user_id, true));
// Create the form
$form = new FormValidator('user_edit','post','','',array('style' => 'width: 60%; float: '.($text_dir=='rtl'?'right;':'left;')));
$form = new FormValidator('user_edit', 'post', '', '', array('style' => 'width: 60%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;')));
$form->addElement('header', '', $tool_name);
$form->addElement('hidden','user_id',$user_id);
$form->addElement('hidden', 'user_id', $user_id);
if (api_is_western_name_order())
{
if (api_is_western_name_order()) {
// Firstname
$form->addElement('text','firstname',get_lang('FirstName'));
$form->applyFilter('firstname','html_filter');
$form->applyFilter('firstname','trim');
$form->addElement('text', 'firstname', get_lang('FirstName'));
$form->applyFilter('firstname', 'html_filter');
$form->applyFilter('firstname', 'trim');
$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
// Lastname
$form->addElement('text','lastname',get_lang('LastName'));
$form->applyFilter('lastname','html_filter');
$form->applyFilter('lastname','trim');
$form->addElement('text', 'lastname', get_lang('LastName'));
$form->applyFilter('lastname', 'html_filter');
$form->applyFilter('lastname', 'trim');
$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
}
else
{
} else {
// Lastname
$form->addElement('text','lastname',get_lang('LastName'));
$form->applyFilter('lastname','html_filter');
$form->applyFilter('lastname','trim');
$form->addElement('text', 'lastname', get_lang('LastName'));
$form->applyFilter('lastname', 'html_filter');
$form->applyFilter('lastname', 'trim');
$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
// Firstname
$form->addElement('text','firstname',get_lang('FirstName'));
$form->applyFilter('firstname','html_filter');
$form->applyFilter('firstname','trim');
$form->addElement('text', 'firstname', get_lang('FirstName'));
$form->applyFilter('firstname', 'html_filter');
$form->applyFilter('firstname', 'trim');
$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
}
// Official code
$form->addElement('text', 'official_code', get_lang('OfficialCode'),array('size' => '40'));
$form->applyFilter('official_code','html_filter');
$form->applyFilter('official_code','trim');
$form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => '40'));
$form->applyFilter('official_code', 'html_filter');
$form->applyFilter('official_code', 'trim');
// Email
$form->addElement('text', 'email', get_lang('Email'),array('size' => '40'));
$form->addElement('text', 'email', get_lang('Email'), array('size' => '40'));
$form->addRule('email', get_lang('EmailWrong'), 'email');
$form->addRule('email', get_lang('EmailWrong'), 'required');
// OpenID
if(api_get_setting('openid_authentication')=='true')
{
$form->addElement('text', 'openid', get_lang('OpenIDURL'),array('size' => '40'));
if (api_get_setting('openid_authentication') == 'true') {
$form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => '40'));
}
// Phone
$form->addElement('text','phone',get_lang('PhoneNumber'));
$form->addElement('text', 'phone', get_lang('PhoneNumber'));
// Picture
$form->addElement('file', 'picture', get_lang('AddPicture'));
$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
$form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
if (strlen($user_data['picture_uri']) > 0 )
{
if (strlen($user_data['picture_uri']) > 0) {
$form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
}
@ -162,96 +149,88 @@ $form->addRule('username', get_lang('OnlyLettersAndNumbersAllowed'), 'username')
$form->addRule('username', get_lang('UserTaken'), 'username_available', $user_data['username']);
// Password
$form->addElement('radio','reset_password',get_lang('Password'),get_lang('DontResetPassword'),0);
if(count($extAuthSource) > 0)
$form->addElement('radio', 'reset_password', get_lang('Password'), get_lang('DontResetPassword'), 0);
if (count($extAuthSource) > 0)
{
$group[] =& HTML_QuickForm::createElement('radio','reset_password',null,get_lang('ExternalAuthentication').' ',3);
$group[] =& HTML_QuickForm::createElement('radio', 'reset_password', null, get_lang('ExternalAuthentication').' ', 3);
$auth_sources = array();
foreach($extAuthSource as $key => $info)
{
foreach($extAuthSource as $key => $info) {
$auth_sources[$key] = $key;
}
$group[] =& HTML_QuickForm::createElement('select','auth_source',null,$auth_sources);
$group[] =& HTML_QuickForm::createElement('static','','','<br />');
$form->addGroup($group, 'password', null, '',false);
$group[] =& HTML_QuickForm::createElement('select', 'auth_source', null, $auth_sources);
$group[] =& HTML_QuickForm::createElement('static', '', '', '<br />');
$form->addGroup($group, 'password', null, '', false);
}
$form->addElement('radio','reset_password',null,get_lang('AutoGeneratePassword'),1);
$form->addElement('radio', 'reset_password', null, get_lang('AutoGeneratePassword'), 1);
$group = array();
$group[] =& HTML_QuickForm::createElement('radio', 'reset_password',null,null,2);
$group[] =& HTML_QuickForm::createElement('password', 'password',null,null);
$form->addGroup($group, 'password', null, '',false);
$group[] =& HTML_QuickForm::createElement('radio', 'reset_password', null, null, 2);
$group[] =& HTML_QuickForm::createElement('password', 'password', null, array('onkeydown' => 'javascript: password_switch_radio_button();'));
$form->addGroup($group, 'password', null, '', false);
// Status
$status = api_get_status_langvars();
$form->addElement('select','status',get_lang('Status'),$status,'id="status_select" onchange="display_drh_list()"');
$form->addElement('select', 'status', get_lang('Status'), $status, array('id' => 'status_select', 'onchange' => 'javascript: display_drh_list();'));
//Language
$form->addElement('select_language', 'language', get_lang('Language'));
$display = $user_data['status'] == STUDENT || $_POST['status'] == STUDENT ? 'block' : 'none';
$form->addElement('html','<div id="drh_list" style="display:'.$display.';">');
$drh_select = $form->addElement('select','hr_dept_id',get_lang('Drh'),array(),'id="drh_select"');
$drh_list = UserManager :: get_user_list(array('status'=>DRH),array('lastname','firstname'));
$form->addElement('html', '<div id="drh_list" style="display:'.$display.';">');
$drh_select = $form->addElement('select', 'hr_dept_id', get_lang('Drh'), array(), 'id="drh_select"');
$drh_list = UserManager :: get_user_list(array('status' => DRH), api_sort_by_first_name() ? array('firstname', 'lastname') : array('lastname', 'firstname'));
if (count($drh_list) == 0) {
$drh_select->addOption('- '.get_lang('ThereIsNotStillAResponsible').' -',0);
$drh_select->addOption('- '.get_lang('ThereIsNotStillAResponsible', '').' -', 0);
} else {
$drh_select->addOption('- '.get_lang('SelectAResponsible').' -',0);
$drh_select->addOption('- '.get_lang('SelectAResponsible').' -', 0);
}
foreach($drh_list as $drh)
{
foreach($drh_list as $drh) {
$drh_select->addOption(api_get_person_name($drh['firstname'], $drh['lastname']), $drh['user_id']);
}
$form->addElement('html', '</div>');
// Platform admin
// Only when changing another user!
if($user_id != $_SESSION['_uid'])
{
if ($user_id != $_SESSION['_uid']) {
$group = array();
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin',null,get_lang('Yes'),1);
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin',null,get_lang('No'),0);
if ($user_data['status']<>5) {
$form->addGroup($group, 'admin', get_lang('PlatformAdmin'), '&nbsp;',false);
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin', null, get_lang('Yes'), 1);
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin', null, get_lang('No'), 0);
if ($user_data['status'] <> 5) {
$form->addGroup($group, 'admin', get_lang('PlatformAdmin'), '&nbsp;', false);
}
}
// Send email
$group = array();
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail',null,get_lang('Yes'),1);
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail',null,get_lang('No'),0);
$form->addGroup($group, 'mail', get_lang('SendMailToNewUser'), '&nbsp;',false);
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail', null, get_lang('Yes'), 1);
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail', null, get_lang('No'), 0);
$form->addGroup($group, 'mail', get_lang('SendMailToNewUser'), '&nbsp;', false);
// Registration Date
$form->addElement('static','registration_date', get_lang('RegistrationDate'), $user_data['registration_date']);
$form->addElement('static', 'registration_date', get_lang('RegistrationDate'), $user_data['registration_date']);
if(! $user_data['platform_admin'] )
{
if (!$user_data['platform_admin']) {
// Expiration Date
$form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
$group = array ();
$group[] = & $form->createElement('radio', 'radio_expiration_date', null, get_lang('On'), 1);
$group[] = & $form->createElement('datepicker', 'expiration_date',null, array ('form_name' => $form->getAttribute('name'), 'onChange'=>'enable_expiration_date()'));
$group[] = & $form->createElement('datepicker', 'expiration_date', null, array('form_name' => $form->getAttribute('name'), 'onchange' => 'javascript: enable_expiration_date();'));
$form->addGroup($group, 'max_member_group', null, '', false);
// Active account or inactive account
$form->addElement('radio','active',get_lang('ActiveAccount'),get_lang('Active'),1);
$form->addElement('radio','active','',get_lang('Inactive'),0);
$form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
$form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
}
// EXTRA FIELDS
$extra = UserManager::get_extra_fields(0,50,5,'ASC');
foreach($extra as $id => $field_details)
{
if($field_details[6] == 0)
{
continue;
}
switch($field_details[2])
{
$extra = UserManager::get_extra_fields(0, 50, 5, 'ASC');
foreach ($extra as $id => $field_details) {
if ($field_details[6] == 0) {
continue;
}
switch ($field_details[2]) {
case USER_FIELD_TYPE_TEXT:
$form->addElement('text', 'extra_'.$field_details[1], $field_details[3], array('size' => 40));
$form->applyFilter('extra_'.$field_details[1], 'stripslashes');
@ -265,39 +244,36 @@ foreach($extra as $id => $field_details)
break;
case USER_FIELD_TYPE_RADIO:
$group = array();
foreach($field_details[9] as $option_id => $option_details)
{
foreach ($field_details[9] as $option_id => $option_details) {
$options[$option_details[1]] = $option_details[2];
$group[] =& HTML_QuickForm::createElement('radio', 'extra_'.$field_details[1], $option_details[1],$option_details[2].'<br />',$option_details[1]);
$group[] =& HTML_QuickForm::createElement('radio', 'extra_'.$field_details[1], $option_details[1], $option_details[2].'<br />', $option_details[1]);
}
$form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], '');
break;
case USER_FIELD_TYPE_SELECT:
$options = array();
foreach($field_details[9] as $option_id => $option_details)
{
foreach ($field_details[9] as $option_id => $option_details) {
$options[$option_details[1]] = $option_details[2];
}
$form->addElement('select','extra_'.$field_details[1],$field_details[3],$options,'');
$form->addElement('select', 'extra_'.$field_details[1], $field_details[3], $options, '');
break;
case USER_FIELD_TYPE_SELECT_MULTIPLE:
$options = array();
foreach($field_details[9] as $option_id => $option_details)
{
foreach ($field_details[9] as $option_id => $option_details) {
$options[$option_details[1]] = $option_details[2];
}
$form->addElement('select','extra_'.$field_details[1],$field_details[3],$options,array('multiple' => 'multiple'));
$form->addElement('select', 'extra_'.$field_details[1], $field_details[3], $options, array('multiple' => 'multiple'));
break;
case USER_FIELD_TYPE_DATE:
$form->addElement('datepickerdate', 'extra_'.$field_details[1], $field_details[3],array('form_name'=>'user_edit'));
$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900);
$form->addElement('datepickerdate', 'extra_'.$field_details[1], $field_details[3], array('form_name' => 'user_edit'));
$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
$defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
$form -> setDefaults($defaults);
$form->applyFilter('theme', 'trim');
break;
case USER_FIELD_TYPE_DATETIME:
$form->addElement('datepicker', 'extra_'.$field_details[1], $field_details[3],array('form_name'=>'user_edit'));
$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900);
$form->addElement('datepicker', 'extra_'.$field_details[1], $field_details[3], array('form_name' => 'user_edit'));
$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
$defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
$form -> setDefaults($defaults);
$form->applyFilter('theme', 'trim');
@ -305,35 +281,29 @@ foreach($extra as $id => $field_details)
}
}
// Submit button
$form->addElement('style_submit_button', 'submit',get_lang('ModifyInformation'),'class="save"');
$form->addElement('style_submit_button', 'submit', get_lang('ModifyInformation'), 'class="save"');
// Set default values
$expiration_date=$user_data['expiration_date'];
if ($expiration_date=='0000-00-00 00:00:00')
{
$user_data['radio_expiration_date']=0;
$user_data['expiration_date']=array();
$user_data['expiration_date']['d']=date('d');
$user_data['expiration_date']['F']=date('m');
$user_data['expiration_date']['Y']=date('Y');
}
else
{
$user_data['radio_expiration_date']=1;
$user_data['expiration_date']=array();
$user_data['expiration_date']['d']=substr($expiration_date,8,2);
$user_data['expiration_date']['F']=substr($expiration_date,5,2);
$user_data['expiration_date']['Y']=substr($expiration_date,0,4);
$user_data['reset_password'] = 0;
$expiration_date = $user_data['expiration_date'];
if ($expiration_date == '0000-00-00 00:00:00') {
$user_data['radio_expiration_date'] = 0;
$user_data['expiration_date'] = array();
$user_data['expiration_date']['d'] = date('d');
$user_data['expiration_date']['F'] = date('m');
$user_data['expiration_date']['Y'] = date('Y');
} else {
$user_data['radio_expiration_date'] = 1;
$user_data['expiration_date'] = array();
$user_data['expiration_date']['d'] = substr($expiration_date, 8, 2);
$user_data['expiration_date']['F'] = substr($expiration_date, 5, 2);
$user_data['expiration_date']['Y'] = substr($expiration_date, 0, 4);
}
$form->setDefaults($user_data);
// Validate form
if( $form->validate())
{
if ( $form->validate()) {
$user = $form->exportValues();
$picture_element = & $form->getElement('picture');
@ -341,12 +311,11 @@ if( $form->validate())
$picture_uri = $user_data['picture_uri'];
//get the picture directory
$picture_path_info = UserManager::get_user_picture_path_by_id($user_id, 'system', true);
$picture_path = $picture_path_info['dir'];
//get the picture directory
$picture_path_info = UserManager::get_user_picture_path_by_id($user_id, 'system', true);
$picture_path = $picture_path_info['dir'];
if ($user['delete_picture'] || !empty($picture['name']))
{
if ($user['delete_picture'] || !empty($picture['name'])) {
@unlink($picture_path.'small_'.$picture_uri);
@unlink($picture_path.'medium_'.$picture_uri);
@unlink($picture_path.'big_'.$picture_uri);
@ -354,15 +323,13 @@ if( $form->validate())
$picture_uri = '';
}
if (!empty($picture['name']))
{
if (!empty($picture['name'])) {
$picture_uri = $user_id.'_'.uniqid('').'_'.replace_dangerous_char($picture['name']);
$perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm)?$perm:'0770');
if(!file_exists($picture_path))
{
@mkdir($picture_path, $perm, true);
}
$perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm) ? $perm : '0770');
if (!file_exists($picture_path)) {
@mkdir($picture_path, $perm, true);
}
$picture_info = @getimagesize($_FILES['picture']['tmp_name']);
$type = $picture_info[2];
$small_picture = UserManager::resize_picture($_FILES['picture']['tmp_name'], 22);
@ -372,10 +339,10 @@ if( $form->validate())
$picture_types = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG');
if (in_array($type, array_keys($picture_types))) {
$small_picture->send_image($picture_types[$type], $picture_path.'small_'.$picture_uri);
$small_picture->send_image($picture_types[$type], $picture_path.'small_'.$picture_uri);
$medium_picture->send_image($picture_types[$type], $picture_path.'medium_'.$picture_uri);
$normal_picture->send_image($picture_types[$type], $picture_path.$picture_uri);
$big_picture->send_image($picture_types[$type], $picture_path.'big_'.$picture_uri);
$normal_picture->send_image($picture_types[$type], $picture_path.$picture_uri);
$big_picture->send_image($picture_types[$type], $picture_path.'big_'.$picture_uri);
}
}
@ -390,92 +357,74 @@ if( $form->validate())
$send_mail = intval($user['send_mail']);
$reset_password = intval($user['reset_password']);
$hr_dept_id = intval($user['hr_dept_id']);
$language=$user['language'];
if ($user['radio_expiration_date']=='1' && ! $user_data['platform_admin'] )
{
$language = $user['language'];
if ($user['radio_expiration_date'] == '1' && !$user_data['platform_admin']) {
$expiration_date=$user['expiration_date'];
}
else
{
} else {
$expiration_date='0000-00-00 00:00:00';
}
$active = $user_data['platform_admin'] ? 1 : intval($user['active']);
if( $reset_password == 0)
{
if ($reset_password == 0) {
$password = null;
$auth_source = $user_data['auth_source'];
}
elseif($reset_password == 1)
{
elseif($reset_password == 1) {
$password = api_generate_password();
$auth_source = PLATFORM_AUTH_SOURCE;
}
elseif($reset_password == 2)
{
elseif($reset_password == 2) {
$password = $user['password'];
$auth_source = PLATFORM_AUTH_SOURCE;
}
elseif($reset_password == 3)
{
elseif($reset_password == 3) {
$password = $user['password'];
$auth_source = $user['auth_source'];
}
UserManager::update_user($user_id,$firstname,$lastname,$username,$password,$auth_source,$email,$status,$official_code,$phone,$picture_uri,$expiration_date, $active, null, $hr_dept_id,null,$language);
if(api_get_setting('openid_authentication')=='true' && !empty($user['openid']))
{
UserManager::update_user($user_id, $firstname, $lastname, $username, $password, $auth_source, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, null, $hr_dept_id, null, $language);
if (api_get_setting('openid_authentication') == 'true' && !empty($user['openid'])) {
$up = UserManager::update_openid($user_id,$user['openid']);
}
if($user_id != $_SESSION['_uid'])
{
if($platform_admin == 1)
{
if ($user_id != $_SESSION['_uid']) {
if ($platform_admin == 1) {
$sql = "INSERT IGNORE INTO $table_admin SET user_id = '".$user_id."'";
api_sql_query($sql,__FILE__,__LINE__);
}
else
{
Database::query($sql, __FILE__, __LINE__);
} else {
$sql = "DELETE FROM $table_admin WHERE user_id = '".$user_id."'";
api_sql_query($sql,__FILE__,__LINE__);
Database::query($sql, __FILE__, __LINE__);
}
}
$extras = array();
foreach($user as $key => $value)
{
if(substr($key,0,6)=='extra_') //an extra field
{
$myres = UserManager::update_extra_field_value($user_id,substr($key,6),$value);
foreach($user as $key => $value) {
if(substr($key, 0, 6) == 'extra_') { //an extra field
$myres = UserManager::update_extra_field_value($user_id, substr($key, 6), $value);
}
}
if (!empty ($email) && $send_mail)
{
if (!empty ($email) && $send_mail) {
$recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS);
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
$email_admin = api_get_setting('emailAdministrator');
if ($_configuration['multiple_access_urls']==true) {
if ($_configuration['multiple_access_urls'] == true) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1 ){
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$emailbody=get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ". api_get_setting('siteName') ." ".get_lang('Settings')." ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ". api_get_setting('siteName') ." ".get_lang('Settings')." ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
}
else {
$emailbody=get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ". api_get_setting('siteName') ." ".get_lang('Settings')." ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
$emailbody = get_lang('Dear')." ".stripslashes("$firstname $lastname").",\n\n".get_lang('YouAreReg')." ". api_get_setting('siteName') ." ".get_lang('Settings')." ". $username;
// Send password by e-mail if it has been modified, even if encrypted in DB (it doesn't make sense to send an e-mail with login info without the password, even if the password is encrypted)
if($reset_password > 0)
{
if ($reset_password > 0) {
$emailbody .= "\n".get_lang('Pass')." : ".stripslashes($password);
}
@api_mail($recipient_name, $email, $emailsubject, $emailbody, $sender_name,$email_admin);
@api_mail($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}
$tok = Security::get_token();
header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('UserUpdated')).'&sec_token='.$tok);
@ -484,7 +433,7 @@ if( $form->validate())
Display::display_header($tool_name);
// USER PICTURE
// USER PICTURE
$image_path = UserManager::get_user_picture_path_by_id($user_id,'web');
$image_dir = $image_path['dir'];
$image = $image_path['file'];
@ -492,31 +441,28 @@ $image_file = ($image != '' ? $image_dir.$image : api_get_path(WEB_CODE_PATH).'i
$image_size = @getimagesize(api_url_to_local_path($image_file));
$img_attributes = 'src="'.$image_file.'?rand='.time().'" '
.'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" '
.'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" ';
.'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" '
.'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" ';
if ($image_size[0] > 300) //limit display width to 300px
$img_attributes .= 'width="300" ';
if ($image_size[0] > 300) { //limit display width to 300px
$img_attributes .= 'width="300" ';
}
// get the path,width and height from original picture
$big_image = $image_dir.'big_'.$image;
$big_image_size = @getimagesize(api_url_to_local_path($big_image));
$big_image_width= $big_image_size[0];
$big_image_height= $big_image_size[1];
$big_image_width = $big_image_size[0];
$big_image_height = $big_image_size[1];
$url_big_image = $big_image.'?rnd='.time();
if ($image=='') {
if ($image == '') {
echo '<img '.$img_attributes.' />';
} else {
echo '<input type="image" '.$img_attributes.' onclick="return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/>';
echo '<input type="image" '.$img_attributes.' onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/>';
}
// Display form
$form->display();
/*
==============================================================================
FOOTER
==============================================================================
*/
// Footer
Display::display_footer();
?>

Loading…
Cancel
Save