Source for file inscription.php
Documentation is available at inscription.php
// $Id: inscription.php 14212 2008-01-31 02:09:57Z yannoo $
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) various contributors
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, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
==============================================================================
* This script displays a form for registering new users.
==============================================================================
// name of the language file that needs to be included
$language_file = "registration";
include ("../inc/global.inc.php");
require_once (api_get_path(LIBRARY_PATH). 'formvalidator/FormValidator.class.php');
require_once (api_get_path(LIBRARY_PATH). 'usermanager.lib.php');
require_once (api_get_path(CONFIGURATION_PATH). 'profile.conf.php');
// Forbidden to self-register
//api_display_tool_title($tool_name);
//if openid was not found
if (!empty($_GET['openid_msg']) && $_GET['openid_msg'] == 'idnotfound')
$fck_attribute['Height'] = "150";
$fck_attribute['Width'] = "450";
$fck_attribute['ToolbarSet'] = "Profil";
// LAST NAME and FIRST NAME
$form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
$form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('text', 'email', get_lang('Email'), array('size' => 40));
$form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('email', get_lang('EmailWrong'), 'email');
$form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40));
if (CONFVAL_ASK_FOR_OFFICIAL_CODE)
$form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => 40));
$form->addRule('official_code', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('text', 'username', get_lang('UserName'), array('size' => 20));
$form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('username', get_lang('UsernameWrong'), 'username');
$form->addRule('username', get_lang('UserTaken'), 'username_available');
$form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'),'20'), 'maxlength',20);
$form->addElement('password', 'pass1', get_lang('Pass'), array('size' => 40));
$form->addElement('password', 'pass2', get_lang('Confirmation'), array('size' => 40));
$form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule(array('pass1', 'pass2'), get_lang('PassTwo'), 'compare');
if (CHECK_PASS_EASY_TO_FIND)
$form->addElement('select_language', 'language', get_lang('Language'));
if (get_setting('allow_registration_as_teacher') <> 'false')
$form->add_html_editor('competences', get_lang('MyCompetences'), false);
$form->add_html_editor('diplomas', get_lang('MyDiplomas'), false);
$form->add_html_editor('teach', get_lang('MyTeach'), false);
$form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false);
if (api_get_setting('extendedprofile_registrationrequired','mycomptetences') == 'true')
$form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required');
if (api_get_setting('extendedprofile_registrationrequired','mydiplomas') == 'true')
$form->addRule('diplomas', get_lang('ThisFieldIsRequired'), 'required');
if (api_get_setting('extendedprofile_registrationrequired','myteach') == 'true')
$form->addRule('teach', get_lang('ThisFieldIsRequired'), 'required');
if (api_get_setting('extendedprofile_registrationrequired','mypersonalopenarea') == 'true')
$form->addRule('openarea', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('submit', 'submit', get_lang('Ok'));
if(isset ($_SESSION["user_language_choice"]) && $_SESSION["user_language_choice"]!= ""){
$defaults['language'] = $_SESSION["user_language_choice"];
if(!empty($_GET['username']))
if(!empty($_GET['email']))
if (api_get_setting('openid_authentication')== 'true' && !empty($_GET['openid']))
$form->setDefaults($defaults);
/*-----------------------------------------------------
STORE THE NEW USER DATA INSIDE THE MAIN DOKEOS DATABASE
-----------------------------------------------------*/
$values = $form->exportValues();
$values['username'] = substr($values['username'],0,20); //make *sure* the login isn't too long
if (get_setting('allow_registration_as_teacher') == 'false')
$user_id = UserManager::create_user($values['firstname'],$values['lastname'],$values['status'],$values['email'],$values['username'],$values['pass1'],$values['official_code'], $values['language']);
// storing the extended profile
// if there is a default duration of a valid account then we have to change the expiration_date accordingly
SET expiration_date='registration_date+1' WHERE user_id='". $user_id. "'";
// if the account has to be approved then we set the account to inactive, sent a mail to the platform admin and exit the page.
// 1. set account inactive
SET active='0' WHERE user_id='". $user_id. "'";
// 2. send mail to the platform admin
$emailsubject = get_lang('ApprovalForNewAccount'). ': '. $values['username'];
$emailbody = get_lang('ApprovalForNewAccount'). "\n";
$emailbody .= get_lang('UserName'). ': '. $values['username']. "\n";
$emailbody .= get_lang('LastName'). ': '. $values['lastname']. "\n";
$emailbody .= get_lang('FirstName'). ': '. $values['firstname']. "\n";
$emailbody .= get_lang('Email'). ': '. $values['email']. "\n";
$emailbody .= get_lang('Status'). ': '. $values['status']. "\n\n";
$emailheaders .= "Reply-To: ". get_setting('emailAdministrator');
@ api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders);
/*--------------------------------------
--------------------------------------*/
$_user['mail'] = $values['email'];
$_user['language'] = $values['language'];
$_user['user_id'] = $user_id;
$is_allowedCreateCourse = ($values['status'] == 1) ? true : false;
include (api_get_path(LIBRARY_PATH). "events.lib.inc.php");
// last user login date is now
$user_last_login_datetime = 0; // used as a unix timestamp it will correspond to : 1 1 1970
/*--------------------------------------
--------------------------------------*/
if (strstr($values['email'], '@'))
// Lets predefine some variables. Be sure to change the from address!
$firstname = $values['firstname'];
$lastname = $values['lastname'];
$emailto = "\"$firstname $lastname\" <". $values['email']. ">";
// The body can be as long as you wish, and any combination of text and variables
// Here we are forming one large header line
// Every header must be followed by a \n except the last
$emailheaders .= "Reply-To: ". get_setting('emailAdministrator');
// Because I predefined all of my variables, this api_send_mail() function looks nice and clean hmm?
@ api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders);
if (!empty ($values['email']))
echo "<p>". get_lang('MailHasBeenSent'). ".</p>";
if ($is_allowedCreateCourse)
echo "<p>", get_lang('NowGoCreateYourCourse'), ".</p>\n";
$actionUrl = "../create_course/add_course.php";
echo "<p>", get_lang('NowGoChooseYourCourses'), ".</p>\n";
$actionUrl = "courses.php?action=subscribe";
// ?uidReset=true&uidReq=$_user['user_id']
echo "<form action=\"", $actionUrl, "\" method=\"post\">\n", "<input type=\"submit\" name=\"next\" value=\"", get_lang('Next'), "\" validationmsg=\" ", get_lang('Next'), " \">\n", "</form><br>\n";
==============================================================================
==============================================================================
|