Remove unused file.

1.10.x
Julio Montoya 10 years ago
parent 38c794855b
commit 2458d70cf0
  1. 378
      main/mySpace/user_add.php

@ -1,378 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Deprecated
* @package chamilo.reporting
*/
/**
* Code
*/
$cidReset = true;
exit; //@deprecated file seems to be unused
// including necessary libraries
require_once '../inc/global.inc.php';
$libpath = api_get_path(LIBRARY_PATH);
// user permissions
api_protect_admin_script(true);
api_block_anonymous_users();
// Database table definitions
$table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$htmlHeadXtra[] = '
<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 display_drh_list(){
if(document.getElementById("status_select").value=='.STUDENT.')
{
document.getElementById("drh_list").style.display="block";
}
else
{
document.getElementById("drh_list").style.display="none";
document.getElementById("drh_select").options[0].selected="selected";
}
}
//-->
</script>';
if (!empty($_GET['message'])) {
$message = urldecode($_GET['message']);
}
$id_session='';
if (isset($_GET["id_session"]) && $_GET["id_session"] != "") {
$id_session = Security::remove_XSS($_GET["id_session"]);
}
$interbreadcrumb[] = array ('url' => '../admin/index.php', 'name' => get_lang('PlatformAdmin'));
$tool_name = get_lang('AddUsers');
// Create the form
$form = new FormValidator('user_add');
if (api_is_western_name_order()) {
// Firstname
$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->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
} else {
// Lastname
$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->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');
// Email
$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'));
// 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));
$form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
$form->addRule('username', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
$form->addRule('username', get_lang('UserTaken'), 'username_available', $user_data['username']);
// 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);
$auth_sources = array();
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('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(document.user_add,"password[password_auto]");'));
$form->addGroup($group, 'password', get_lang('Password'), '');
// 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;');
// 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('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);
$now = api_get_utc_datetime();
//Session list
if (api_is_session_admin()) {
$where = 'WHERE session_admin_id='.intval(api_get_user_id());
$where .= ' AND ( (session.date_start <= "'.$now.'" AND session.date_end >= "'.$now.'") OR session.date_start="0000-00-00" ) ';
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$sql="SELECT id,name,nbr_courses,date_start,date_end FROM $tbl_session $where ORDER BY name";
$result = Database::query($sql);
$a_sessions = Database::store_result($result);
$session_list = array();
$session_list[0] = get_lang('SelectSession');
if (is_array($a_sessions)) {
foreach ($a_sessions as $session) {
$session_list[$session['id']]=$session['name'];
}
}
api_natsort($session_list);
$form->addElement('select', 'session_id', get_lang('Session'), $session_list);
}
UserManager::set_extra_fields_in_form($form, null, 'registration');
// Set default values
$defaults['admin']['platform_admin'] = 0;
$defaults['mail']['send_mail'] = 0;
$defaults['password']['password_auto'] = 1;
$defaults['active'] = 1;
$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['radio_expiration_date'] = 0;
$defaults['status'] = STUDENT;
$defaults['session_id'] = api_get_session_id();
$form->setDefaults($defaults);
// Submit button
$select_level = array ();
$html_results_enabled[] = FormValidator :: addButtonCreate(get_lang('Add') . '+', 'submit_plus', true);
$html_results_enabled[] = FormValidator :: addButtonCreate(get_lang('Add'), 'submit', true);
$form->addGroup($html_results_enabled);
// Validate form
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$user = $form->exportValues();
$picture_element = $form->getElement('picture');
$picture = $picture_element->getValue();
$picture_uri = '';
$lastname = $user['lastname'];
$firstname = $user['firstname'];
$official_code = $user['official_code'];
$email = $user['email'];
$phone = $user['phone'];
$username = $user['username'];
$status = intval($user['status']);
$picture = $_FILES['picture'];
$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') {
$auth_source = $user['password']['auth_source'];
$password = 'PLACEHOLDER';
} 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';
}
$active = intval($user['active']);
// default status = student
$status = 5;
//create user
$user_id = UserManager::create_user(
$firstname,
$lastname,
$status,
$email,
$username,
$password,
$official_code,
api_get_setting('platformLanguage'),
$phone,
$picture_uri,
$auth_source,
$expiration_date,
$active,
$hr_dept_id
);
//adding to the session
if (api_is_session_admin()) {
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$id_session = $user['session_id'];
if ($id_session != 0) {
$result = Database::query("SELECT c_id FROM $tbl_session_rel_course WHERE session_id ='$id_session'");
$CourseList=array();
while ($row = Database::fetch_array($result)) {
$CourseList[] = $row['c_id'];
}
foreach ($CourseList as $enreg_course) {
$sql = "INSERT INTO $tbl_session_rel_course_rel_user(id_session,c_id,user_id)
VALUES('$id_session','$enreg_course','$user_id')";
Database::query($sql);
// updating the total
$sql = "SELECT COUNT(user_id) as nbUsers FROM $tbl_session_rel_course_rel_user
WHERE session_id ='$id_session' AND c_id='$enreg_course'";
$rs = Database::query($sql);
list($nbr_users) = Database::fetch_array($rs);
Database::query("UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE session_id='$id_session' AND c_id='$enreg_course'");
}
Database::query("INSERT INTO $tbl_session_rel_user(session_id, user_id) VALUES('$id_session','$user_id')");
$sql = "SELECT COUNT(nbr_users) as nbUsers
FROM $tbl_session WHERE id='$id_session' ";
$rs = Database::query($sql);
list($nbr_users) = Database::fetch_array($rs);
Database::query("UPDATE $tbl_session SET nbr_users= $nbr_users WHERE id='$id_session' ");
}
}
$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);
}
}
if ($platform_admin) {
$sql = "INSERT INTO $table_admin SET user_id = '".$user_id."'";
Database::query($sql);
}
if (!empty ($email) && $send_mail) {
//$emailto = '"'.api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS).'" <'.$email.'>';
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$portal_url = $_configuration['root_web'];
if (api_is_multiple_url_enabled()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$portal_url = $url['url'];
}
}
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ". api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ".$portal_url."\n\n". get_lang('Problem'). "\n\n". get_lang('SignatureFormula').",\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_html(
api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS),
$email,
$emailsubject,
$emailbody
);
}
Security::clear_token();
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 {
$tok = Security::get_token();
header('Location: ../admin/user_list.php?action=show_message&message='.urlencode(get_lang('UserAdded')).'&sec_token='.$tok);
exit ();
}
}
} else {
if (isset($_POST['submit'])) {
Security::clear_token();
}
$token = Security::get_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);
if (!empty($message)) {
Display::display_normal_message(stripslashes($message));
}
$form->display();
/*
==============================================================================
FOOTER
==============================================================================
*/
Display::display_footer();
Loading…
Cancel
Save