inscription_second.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php // $Id: inscription_second.php 9246 2006-09-25 13:24:53Z bmol $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * This script reacts on the form data normally delivered by inscription.php
  22. * to register users into Dokeos.
  23. * (but malicious users can easily send POST data from their own scripts).
  24. *
  25. * @package dokeos.auth
  26. * @deprecated File not in use
  27. ==============================================================================
  28. */
  29. /*==========================
  30. INIT
  31. ==========================*/
  32. $langFile = "registration";
  33. require("../inc/global.inc.php");
  34. $TABLEUSER = Database::get_main_table(MAIN_USER_TABLE);
  35. define ("CHECK_PASS_EASY_TO_FIND", false);
  36. if (!isset($userPasswordCrypted)) $userPasswordCrypted = false;
  37. $regDataOk = false; // default value...
  38. if(!empty($_POST['submitRegistration']))
  39. {
  40. $regexp = "^[0-9a-z_\.-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2,4})$";
  41. $uname = trim ($_POST["uname" ]);
  42. $email = trim ($_POST["email" ]);
  43. $official_code = trim ($_POST["official_code" ]);
  44. $lastname = trim ($_POST["lastname" ]);
  45. $firstname = trim ($_POST["firstname" ]);
  46. $password = trim ($_POST["password" ]);
  47. $password1 = trim ($_POST["password1" ]);
  48. $language = $_POST['form_user_language'];
  49. $status=($_POST['status'] == COURSEMANAGER)?COURSEMANAGER:STUDENT;
  50. $uname=eregi_replace('[^a-z0-9_.-]','_',strtr(stripslashes($uname),'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ','AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn'));
  51. /*==========================
  52. DATA SUBIMITED CHECKIN
  53. ==========================*/
  54. // CHECK THE LANGUAGE OF THE USER PROFILE
  55. // we use the platform language if the user cannot select his language or if the chosen language is not valid (spoofed form)
  56. if (get_setting('registration', 'language') == "true")
  57. {
  58. // check if the submitted value is a valid language. If not we use the platform language (against form sppofing)
  59. $language_list=api_get_languages();
  60. $language_name=$language_list['name'];
  61. $language_folder=$language_list['folder'];
  62. if (!in_array($language,$language_folder))
  63. {
  64. $language=get_setting('platformLanguage');
  65. }
  66. }
  67. else
  68. {
  69. // we use the platform languange as the language for the profile
  70. $language=get_setting('platformLanguage');
  71. }
  72. // CHECK IF THERE IS NO EMPTY FIELD
  73. if (
  74. empty($lastname)
  75. OR empty($firstname)
  76. OR (empty($official_code)
  77. AND (get_setting('registration','officialcode')=="true"))
  78. OR empty($password1)
  79. OR empty($password)
  80. OR empty($uname)
  81. OR (empty($email) AND api_get_setting('registration','email')=="true")
  82. )
  83. {
  84. $regDataOk = false;
  85. unset($password1, $password);
  86. $error_message .= "<p>".get_lang('langEmptyFields')."</p>\n";
  87. }
  88. // CHECK IF THE TWO PASSWORD TOKEN ARE IDENTICAL
  89. elseif($password1 != $password)
  90. {
  91. $regDataOk = false;
  92. unset($password1, $password);
  93. $error_message .= "<p>".get_lang('langPassTwice')."</p>\n";
  94. }
  95. elseif(CHECK_PASS_EASY_TO_FIND && !api_check_password($password))
  96. {
  97. $error_message .= "<p>".get_lang('langPassTooEasy')." : <code>".api_generate_password()."</code><br></p>";
  98. }
  99. // CHECK EMAIL ADDRESS VALIDITY
  100. elseif( !empty($email) && ! eregi( $regexp, $email ))
  101. {
  102. $regDataOk = false;
  103. unset($password1, $password, $email);
  104. $error_message .= "<p>".get_lang('langEmailWrong').".</p>\n";
  105. }
  106. // CHECK IF THE LOGIN NAME IS ALREADY OWNED BY ANOTHER USER
  107. else
  108. {
  109. $result = api_sql_query("SELECT user_id FROM $TABLEUSER
  110. WHERE username='$uname'");
  111. if (mysql_num_rows($result) > 0)
  112. {
  113. $regDataOk = false;
  114. unset($password1, $password, $uname);
  115. $error_message .= "<p>".get_lang('langUserFree')."</p>";
  116. }
  117. else
  118. {
  119. $regDataOk = true;
  120. }
  121. }
  122. }
  123. $nameTools = get_lang('Registration');
  124. if ( ! $regDataOk)
  125. {
  126. Display::display_header($nameTools);
  127. api_display_tool_title($nameTools);
  128. echo $error_message;
  129. echo "<p>",
  130. "<a href=\"inscription.php?lastname=",urlencode(stripslashes($lastname)),"&firstname=",urlencode(stripslashes($firstname)),"&official_code=",urlencode(stripslashes($official_code)),"&uname=",urlencode(stripslashes($uname)),"&email=",urlencode(stripslashes($email)),"&status=",$status,"\">",
  131. get_lang('langAgain'),
  132. "</a>",
  133. "</p>\n";
  134. Display::display_footer();
  135. exit;
  136. }
  137. /*> > > > > > > > > > > > REGISTRATION ACCEPTED < < < < < < < < < < < <*/
  138. if ($regDataOk)
  139. {
  140. /*-----------------------------------------------------
  141. STORE THE NEW USER DATA INSIDE THE CLAROLINE DATABASE
  142. -----------------------------------------------------*/
  143. api_sql_query("INSERT INTO ".$TABLEUSER."
  144. SET lastname = '".$lastname."',
  145. firstname = '".$firstname."',
  146. username = '".$uname."',
  147. password = '".($userPasswordCrypted?md5($password):$password)."',
  148. email = '".$email."',
  149. status = '".$status."',
  150. official_code = '".$official_code."',
  151. language = '".$language."'
  152. ");
  153. $_uid = mysql_insert_id();
  154. if ($_uid)
  155. {
  156. /*--------------------------------------
  157. SESSION REGISTERING
  158. --------------------------------------*/
  159. $_user['firstName'] = stripslashes($firstname);
  160. $_user['lastName' ] = stripslashes($lastname);
  161. $_user['mail' ] = $email;
  162. $_user['language'] = $language;
  163. $is_allowedCreateCourse = ($status == 1) ? true : false ;
  164. api_session_register('_uid');
  165. api_session_register('_user');
  166. api_session_register('is_allowedCreateCourse');
  167. //stats
  168. include(api_get_path(LIBRARY_PATH)."events.lib.inc.php");
  169. event_login();
  170. // last user login date is now
  171. $user_last_login_datetime = 0; // used as a unix timestamp it will correspond to : 1 1 1970
  172. api_session_register('user_last_login_datetime');
  173. /*--------------------------------------
  174. EMAIL NOTIFICATION
  175. --------------------------------------*/
  176. if(strstr($email,'@'))
  177. {
  178. // Lets predefine some variables. Be sure to change the from address!
  179. $emailto = "\"$firstname $lastname\" <$email>";
  180. $emailfromaddr = api_get_setting('emailAdministrator');
  181. $emailfromname = api_get_setting('siteName');
  182. $emailsubject = "[".get_setting('siteName')."] ".get_lang('YourReg')." ".get_setting('siteName');
  183. // The body can be as long as you wish, and any combination of text and variables
  184. $emailbody=get_lang('langDear')." ".stripslashes("$firstname $lastname").",\n\n".get_lang('langYouAreReg')." ". get_setting('siteName') ." ".get_lang('langSettings')." ". $uname ."\n". get_lang('langPass')." : ".stripslashes($password)."\n\n" .get_lang('langAddress') ." ". api_get_setting('siteName') ." ". get_lang('langIs') ." : ". $rootWeb ."\n\n". get_lang('langProblem'). "\n\n". get_lang('langFormula').",\n\n".get_setting('administratorName')." ".get_setting('administratorSurname')."\n". get_lang('langManager'). " ".get_setting('siteName')."\nT. ".get_setting('administratorTelephone')."\n" .get_lang('langEmail') ." : ".get_setting('emailAdministrator');
  185. // Here we are forming one large header line
  186. // Every header must be followed by a \n except the last
  187. $emailheaders = "From: ".get_setting('administratorSurname')." ".get_setting('administratorName')." <".get_setting('emailAdministrator').">\n";
  188. $emailheaders .= "Reply-To: ".get_setting('emailAdministrator');
  189. // Because I predefined all of my variables, this api_send_mail() function looks nice and clean hmm?
  190. @api_send_mail( $emailto, $emailsubject, $emailbody, $emailheaders);
  191. }
  192. }
  193. Display::display_header($nameTools);
  194. api_display_tool_title($nameTools);
  195. echo "<p>".get_lang('langDear')." ".stripslashes("$firstname $lastname").",<br><br>".get_lang('langPersonalSettings').".</p>\n";
  196. if(!empty($email))
  197. {
  198. echo "<p>".get_lang('langMailHasBeenSent').".</p>";
  199. }
  200. if($is_allowedCreateCourse)
  201. {
  202. echo "<p>",get_lang('langNowGoCreateYourCourse'),".</p>\n";
  203. $actionUrl = "../create_course/add_course.php";
  204. }
  205. else
  206. {
  207. echo "<p>",get_lang('langNowGoChooseYourCourses'),".</p>\n";
  208. $actionUrl = "courses.php?action=subscribe";
  209. }
  210. // ?uidReset=true&uidReq=$_uid
  211. echo "<form action=\"",$actionUrl,"\" method=\"post\">\n",
  212. "<input type=\"submit\" name=\"next\" value=\"",get_lang('langNext'),"\" validationmsg=\" ",get_lang('langNext')," \">\n",
  213. "</form>\n";
  214. } // else Registration accepted
  215. $already_second=1;
  216. Display::display_footer();
  217. ?>