inscription.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. // $Id: inscription.php 11139 2007-02-17 15:43:14Z yannoo $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) various contributors
  10. Copyright (c) Bart Mollet, Hogeschool Gent
  11. For a full list of contributors, see "credits.txt".
  12. The full license can be read in "license.txt".
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. See the GNU General Public License for more details.
  18. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * This script displays a form for registering new users.
  24. * @package dokeos.auth
  25. ==============================================================================
  26. */
  27. // name of the language file that needs to be included
  28. $language_file = "registration";
  29. include ("../inc/global.inc.php");
  30. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  31. require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  32. require_once (api_get_path(CONFIGURATION_PATH).'profile.conf.php');
  33. $tool_name = get_lang('Registration');
  34. Display :: display_header($tool_name);
  35. // Forbidden to self-register
  36. if (get_setting('allow_registration') == 'false')
  37. {
  38. api_not_allowed();
  39. }
  40. //api_display_tool_title($tool_name);
  41. if (get_setting('allow_registration')=='approval')
  42. {
  43. Display::display_normal_message(get_lang('YourAccountHasToBeApproved'));
  44. }
  45. $form = new FormValidator('registration');
  46. // LAST NAME and FIRST NAME
  47. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  48. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  49. $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
  50. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  51. // EMAIL
  52. $form->addElement('text', 'email', get_lang('Email'), array('size' => 40));
  53. if (api_get_setting('registration', 'email') == 'true')
  54. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  55. $form->addRule('email', get_lang('EmailWrong'), 'email');
  56. // OFFICIAL CODE
  57. if (CONFVAL_ASK_FOR_OFFICIAL_CODE)
  58. {
  59. $form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => 40));
  60. if (api_get_setting('registration', 'officialcode') == 'true')
  61. $form->addRule('official_code', get_lang('ThisFieldIsRequired'), 'required');
  62. }
  63. // USERNAME
  64. $form->addElement('text', 'username', get_lang('UserName'), array('size' => 40));
  65. $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
  66. $form->addRule('username', get_lang('UsernameWrong'), 'username');
  67. $form->addRule('username', get_lang('UserTaken'), 'username_available');
  68. // PASSWORD
  69. $form->addElement('password', 'pass1', get_lang('Pass'), array('size' => 40));
  70. $form->addElement('password', 'pass2', get_lang('Confirmation'), array('size' => 40));
  71. $form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required');
  72. $form->addRule(array('pass1', 'pass2'), get_lang('PassTwo'), 'compare');
  73. if (CHECK_PASS_EASY_TO_FIND)
  74. $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password');
  75. // LANGUAGE
  76. if (get_setting('registration', 'language') == 'true')
  77. {
  78. $form->addElement('select_language', 'language', get_lang('Language'));
  79. }
  80. // STUDENT/TEACHER
  81. if (get_setting('allow_registration_as_teacher') <> 'false')
  82. {
  83. $form->addElement('radio', 'status', get_lang('Status'), get_lang('RegStudent'), STUDENT);
  84. $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER);
  85. }
  86. $form->addElement('submit', 'submit', get_lang('Ok'));
  87. if(isset($_SESSION["user_language_choice"]) && $_SESSION["user_language_choice"]!=""){
  88. $defaults['language'] = $_SESSION["user_language_choice"];
  89. }
  90. else{
  91. $defaults['language'] = api_get_setting('platformLanguage');
  92. }
  93. $defaults['status'] = STUDENT;
  94. $form->setDefaults($defaults);
  95. if ($form->validate())
  96. {
  97. /*-----------------------------------------------------
  98. STORE THE NEW USER DATA INSIDE THE MAIN DOKEOS DATABASE
  99. -----------------------------------------------------*/
  100. $values = $form->exportValues();
  101. if (get_setting('allow_registration_as_teacher') == 'false')
  102. {
  103. $values['status'] = STUDENT;
  104. }
  105. // creating a new user
  106. $user_id = UserManager::create_user($values['firstname'],$values['lastname'],$values['status'],$values['email'],$values['username'],$values['pass1'],$values['official_code'], $values['language']);
  107. if ($user_id)
  108. {
  109. // TODO: add language to parameter list of UserManager::create_user(...)
  110. $sql = "UPDATE ".Database::get_main_table(TABLE_MAIN_USER)."
  111. SET language = '".mysql_real_escape_string($values['language'])."'
  112. WHERE user_id = '".$user_id."' ";
  113. //api_sql_query($sql,__FILE__,__LINE__);
  114. // if there is a default duration of a valid account then we have to change the expiration_date accordingly
  115. if (get_setting('account_valid_duration')<>'')
  116. {
  117. $sql = "UPDATE ".Database::get_main_table(TABLE_MAIN_USER)."
  118. SET expiration_date='registration_date+1' WHERE user_id='".$user_id."'";
  119. api_sql_query($sql,__FILE__,__LINE__);
  120. }
  121. // 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.
  122. if (get_setting('allow_registration')=='approval')
  123. {
  124. // 1. set account inactive
  125. $sql = "UPDATE ".Database::get_main_table(TABLE_MAIN_USER)."
  126. SET active='0' WHERE user_id='".$user_id."'";
  127. api_sql_query($sql,__FILE__,__LINE__);
  128. // 2. send mail to the platform admin
  129. $emailfromaddr = api_get_setting('emailAdministrator');
  130. $emailfromname = api_get_setting('siteName');
  131. $emailto = api_get_setting('emailAdministrator');
  132. $emailsubject = get_lang('ApprovalForNewAccount').': '.$values['username'];
  133. $emailbody = get_lang('ApprovalForNewAccount')."\n";
  134. $emailbody .=get_lang('UserName').': '.$values['username']."\n";
  135. $emailbody .=get_lang('LastName').': '.$values['lastname']."\n";
  136. $emailbody .=get_lang('FirstName').': '.$values['firstname']."\n";
  137. $emailbody .=get_lang('Email').': '.$values['email']."\n";
  138. $emailbody .=get_lang('Status').': '.$values['status']."\n\n";
  139. $emailbody .=get_lang('ManageUser').': '.api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id;
  140. $emailheaders = "From: ".get_setting('administratorSurname')." ".get_setting('administratorName')." <".get_setting('emailAdministrator').">\n";
  141. $emailheaders .= "Reply-To: ".get_setting('emailAdministrator');
  142. @ api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders);
  143. // 3. exit the page
  144. unset($user_id);
  145. Display :: display_footer();
  146. exit;
  147. }
  148. /*--------------------------------------
  149. SESSION REGISTERING
  150. --------------------------------------*/
  151. $_user['firstName'] = stripslashes($values['firstname']);
  152. $_user['lastName'] = stripslashes($values['lastname']);
  153. $_user['mail'] = $values['email'];
  154. $_user['language'] = $values['language'];
  155. $_user['user_id'] = $user_id;
  156. $is_allowedCreateCourse = ($values['status'] == 1) ? true : false;
  157. api_session_register('_user');
  158. api_session_register('is_allowedCreateCourse');
  159. //stats
  160. include (api_get_path(LIBRARY_PATH)."events.lib.inc.php");
  161. event_login();
  162. // last user login date is now
  163. $user_last_login_datetime = 0; // used as a unix timestamp it will correspond to : 1 1 1970
  164. api_session_register('user_last_login_datetime');
  165. /*--------------------------------------
  166. EMAIL NOTIFICATION
  167. --------------------------------------*/
  168. if (strstr($values['email'], '@'))
  169. {
  170. // Lets predefine some variables. Be sure to change the from address!
  171. $firstname = $values['firstname'];
  172. $lastname = $values['lastname'];
  173. $emailto = "\"$firstname $lastname\" <".$values['email'].">";
  174. $emailfromaddr = api_get_setting('emailAdministrator');
  175. $emailfromname = api_get_setting('siteName');
  176. $emailsubject = "[".get_setting('siteName')."] ".get_lang('YourReg')." ".get_setting('siteName');
  177. // The body can be as long as you wish, and any combination of text and variables
  178. $emailbody = get_lang('Dear')." ".stripslashes("$firstname $lastname").",\n\n".get_lang('YouAreReg')." ".get_setting('siteName')." ".get_lang('Settings')." ".$values['username']."\n".get_lang('Pass')." : ".stripslashes($values['pass1'])."\n\n".get_lang('Address')." ".get_setting('siteName')." ".get_lang('Is')." : ".$_configuration['root_web']."\n\n".get_lang('Problem')."\n\n".get_lang('Formula').",\n\n".get_setting('administratorName')." ".get_setting('administratorSurname')."\n".get_lang('Manager')." ".get_setting('siteName')."\nT. ".get_setting('administratorTelephone')."\n".get_lang('Email')." : ".get_setting('emailAdministrator');
  179. // Here we are forming one large header line
  180. // Every header must be followed by a \n except the last
  181. $emailheaders = "From: ".get_setting('administratorSurname')." ".get_setting('administratorName')." <".get_setting('emailAdministrator').">\n";
  182. $emailheaders .= "Reply-To: ".get_setting('emailAdministrator');
  183. // Because I predefined all of my variables, this api_send_mail() function looks nice and clean hmm?
  184. @ api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders);
  185. }
  186. }
  187. echo "<p>".get_lang('Dear')." ".stripslashes("$firstname $lastname").",<br><br>".get_lang('PersonalSettings').".</p>\n";
  188. if (!empty ($values['email']))
  189. {
  190. echo "<p>".get_lang('MailHasBeenSent').".</p>";
  191. }
  192. if ($is_allowedCreateCourse)
  193. {
  194. echo "<p>", get_lang('NowGoCreateYourCourse'), ".</p>\n";
  195. $actionUrl = "../create_course/add_course.php";
  196. }
  197. else
  198. {
  199. echo "<p>", get_lang('NowGoChooseYourCourses'), ".</p>\n";
  200. $actionUrl = "courses.php?action=subscribe";
  201. }
  202. // ?uidReset=true&uidReq=$_user['user_id']
  203. echo "<form action=\"", $actionUrl, "\" method=\"post\">\n", "<input type=\"submit\" name=\"next\" value=\"", get_lang('Next'), "\" validationmsg=\" ", get_lang('Next'), " \">\n", "</form><br>\n";
  204. }
  205. else
  206. {
  207. $form->display();
  208. }
  209. ?>
  210. <a href="<?php echo api_get_path(WEB_PATH); ?>">&lt;&lt; <?php echo get_lang('Back'); ?></a>
  211. <?php
  212. /*
  213. ==============================================================================
  214. FOOTER
  215. ==============================================================================
  216. */
  217. Display :: display_footer();
  218. ?>