user_add.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <?php
  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. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  16. ==============================================================================
  17. */
  18. // TODO: Is this file deprecated?
  19. /**
  20. ==============================================================================
  21. * @package dokeos.user
  22. ==============================================================================
  23. */
  24. /*==========================
  25. INIT
  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(INCLUDE_PATH).'lib/mail.lib.inc.php');
  31. $this_section=SECTION_COURSES;
  32. if (! ($is_courseAdmin || $is_platformAdmin)) api_not_allowed(true);
  33. $currentCourseID = $_course['sysCode'];
  34. $currentCourseName = $_course['official_code'];
  35. $tbl_user = "user";
  36. $tbl_courseUser = "course_rel_user";
  37. /*==========================
  38. DATA CHECKING
  39. ==========================*/
  40. if($register)
  41. {
  42. /*
  43. * Fields Checking
  44. */
  45. $lastname_form = trim($lastname_form);
  46. $firstname_form = trim($firstname_form);
  47. $password_form = trim($password_form);
  48. $username_form = trim($username_form);
  49. $email_form = trim($email_form);
  50. $official_code_form = trim($official_code_form);
  51. // empty field checking
  52. if(empty($lastname_form) || empty($firstname_form) || empty($password_form) || empty($username_form) || empty($email_form))
  53. {
  54. $dataChecked = false;
  55. $message = get_lang('Filled');
  56. }
  57. // valid mail address checking
  58. elseif(!eregi('^[0-9a-z_.-]+@([0-9a-z-]+\.)+([0-9a-z]){2,4}$',$email_form))
  59. {
  60. $dataChecked = false;
  61. $message = get_lang('EmailWrong');
  62. }
  63. else
  64. {
  65. $dataChecked = true;
  66. }
  67. // prevent conflict with existing user account
  68. if($dataChecked)
  69. {
  70. $result=Database::query("SELECT user_id,
  71. (username='$username_form') AS loginExists,
  72. (lastname='$lastname_form' AND firstname='$firstname_form' AND email='$email_form') AS userExists
  73. FROM $tbl_user
  74. WHERE username='$username_form' OR (lastname='$lastname_form' AND firstname='$firstname_form' AND email='$email_form')
  75. ORDER BY userExists DESC, loginExists DESC", __FILE__, __LINE__);
  76. if(Database::num_rows($result))
  77. {
  78. while($user=Database::fetch_array($result))
  79. {
  80. // check if the user is already registered to the platform
  81. if($user['userExists'])
  82. {
  83. $userExists = true;
  84. $userId = $user['user_id'];
  85. break;
  86. }
  87. // check if the login name choosen is already taken by another user
  88. if($user['loginExists'])
  89. {
  90. $loginExists = true;
  91. $userId = 0;
  92. $message = get_lang('UserNo')." (".stripslashes($username_form).") ".get_lang('Taken');
  93. break;
  94. }
  95. } // end while $result
  96. } // end if num rows
  97. } // end if datachecked
  98. /*=============================
  99. NEW USER REGISTRATION PROCESS
  100. =============================*/
  101. if($dataChecked && !$userExists && !$loginExists)
  102. {
  103. /*---------------------------
  104. PLATFORM REGISTRATION
  105. ----------------------------*/
  106. if ($_cid) $platformStatus = STUDENT; // course registrartion context...
  107. else $platformStatus = $platformStatus; // admin section of the platform context...
  108. //if ($userPasswordCrypted) $pw = md5($password_form);
  109. //else $pw = $password_form;
  110. $pw = api_get_encrypted_password($password_form);
  111. $result = Database::query("INSERT INTO $tbl_user
  112. SET lastname = '$lastname_form',
  113. firstname = '$firstname_form',
  114. username = '$username_form',
  115. password = '$pw',
  116. email = '$email_form',
  117. status = '$platformStatus',
  118. official_code = '$official_code_form',
  119. creator_id = '".$_user['user_id']."'", __FILE__, __LINE__);
  120. $userId = Database::insert_id();
  121. if ($userId) $platformRegSucceed = true;
  122. }
  123. if($userId && $_cid)
  124. {
  125. /*
  126. Note : As we temporarly use this script in the platform administration
  127. section to also add user to the platform, We have to prevent course
  128. registration. That's why we check if $_cid is initialized, it gives us
  129. an hint about the use context of the script
  130. */
  131. /*---------------------------
  132. COURSE REGISTRATION
  133. ----------------------------*/
  134. /*
  135. * check the return value of the query
  136. * if 0, the user is already registered to the course
  137. */
  138. if (Database::query("INSERT INTO $tbl_courseUser
  139. SET user_id = '$userId',
  140. course_code = '$currentCourseID',
  141. status = '$admin_form',
  142. tutor_id = '$tutor_form'", __FILE__, __LINE__))
  143. {
  144. $courseRegSucceed = true;
  145. }
  146. } // if $platformRegSucceed && $_cid
  147. /*---------------------------
  148. MAIL NOTIFICATION TO NEW USER
  149. ----------------------------*/
  150. if ($platformRegSucceed)
  151. {
  152. $emailto = "$lastname_form $firstname_form <$email_form>";
  153. $emailfromaddr = $administratorEmail;
  154. $emailfromname = api_get_setting('siteName');
  155. $emailsubject = get_lang('YourReg').' '.api_get_setting('siteName');
  156. $emailheaders = "From: ".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS)." <".$administratorEmail.">\n";
  157. $emailheaders .= "Reply-To: ".$administratorEmail."\n";
  158. $emailheaders .= "Return-Path: ".$administratorEmail."\n";
  159. $emailheaders .= "charset: ".api_get_system_encoding()."\n";
  160. $emailheaders .= "X-Mailer: PHP/" . phpversion() . "\n";
  161. $emailheaders .= "X-Sender-IP: $REMOTE_ADDR"; // (small security precaution...)
  162. $recipient_name = api_get_person_name($firstname_form, $lastname_form, null, PERSON_NAME_EMAIL_ADDRESS);
  163. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  164. $email_admin = api_get_setting('emailAdministrator');
  165. $portal_url = $_configuration['root_web'];
  166. if ($_configuration['multiple_access_urls']==true) {
  167. $access_url_id = api_get_current_access_url_id();
  168. if ($access_url_id != -1 ){
  169. $url = api_get_access_url($access_url_id);
  170. $portal_url = $url['url'];
  171. }
  172. }
  173. if ($courseRegSucceed)
  174. {
  175. $emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname_form, $lastname_form)).",\n".get_lang('OneResp')." $currentCourseName ".get_lang('RegYou')." ".api_get_setting('siteName')." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : $username_form\n".get_lang('Pass').": $password_form\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is').": ".$portal_url."\n".get_lang('Problem')."\n".get_lang('Formula').",\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')."\n";
  176. $message = get_lang('TheU')." ".stripslashes(api_get_person_name($firstname_form, $lastname_form))." ".get_lang('AddedToCourse')."<a href=\"user.php\">".get_lang('BackUser')."</a>\n";
  177. }
  178. else
  179. {
  180. $emailbody = get_lang('Dear')." ".api_get_person_name($firstname_form, $lastname_form).",\n ".get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : $username_form\n".get_lang('Pass').": $password_form\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is').": ".$portal_url."\n".get_lang('Problem')."\n".get_lang('Formula').",\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')."\n";
  181. $message = stripslashes(api_get_person_name($firstname_form, $lastname_form))." ".get_lang('AddedU');
  182. }
  183. @api_mail($recipient_name, $email_form, $emailsubject, $emailbody, $sender_name,$email_admin);
  184. /*
  185. * remove <form> variables to prevent any pre-filled fields
  186. */
  187. unset($lastname_form, $firstname_form, $username_form, $password_form, $email_form, $admin_form, $tutor_form);
  188. } // end if ($platformRegSucceed)
  189. //else
  190. //{
  191. // $message = get_lang('UserAlreadyRegistered');
  192. //}
  193. } // end if register request
  194. $interbreadcrumb[] = array ("url"=>"user.php", "name"=> get_lang('Users'));
  195. $nameTools = get_lang('AddAU');
  196. Display::display_header($nameTools, "User");
  197. ?>
  198. <h3><?php echo get_lang('Users'); ?></h3>
  199. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  200. <tr>
  201. <td><h4><?php echo $nameTools; ?></h4></td>
  202. <td></td>
  203. </tr>
  204. </table>
  205. <?php
  206. /*==========================
  207. ADD ONE USER FORM
  208. ==========================*/
  209. ?>
  210. <?php echo get_lang('OneByOne'); ?>. <?php echo get_lang('UserOneByOneExplanation'); ?>
  211. <form method="post" action="<?php echo api_get_self(); ?>?register=yes">
  212. <table cellpadding="3" cellspacing="0" border="0">
  213. <?php
  214. if(!empty($message))
  215. {
  216. ?>
  217. <tr>
  218. <td colspan="2">
  219. <?php
  220. Display::display_normal_message($message); //main API
  221. ?>
  222. </td>
  223. </tr>
  224. <?php
  225. }
  226. if (api_is_western_name_order()) {
  227. ?>
  228. <tr>
  229. <td align="right"><?php echo get_lang('FirstName'); ?> :</td>
  230. <td><input type="text" size="15" name="firstname_form" value="<?php echo api_htmlentities(stripslashes($firstname_form), ENT_QUOTES, $charset); ?>" /></td>
  231. </tr>
  232. <tr>
  233. <td align="right"><?php echo get_lang('LastName'); ?> :</td>
  234. <td><input type="text" size="15" name="lastname_form" value="<?php echo api_htmlentities(stripslashes($lastname_form), ENT_QUOTES, $charset); ?>" /></td>
  235. </tr>
  236. <?php
  237. } else {
  238. ?>
  239. <tr>
  240. <td align="right"><?php echo get_lang('LastName'); ?> :</td>
  241. <td><input type="text" size="15" name="lastname_form" value="<?php echo api_htmlentities(stripslashes($lastname_form), ENT_QUOTES, $charset); ?>" /></td>
  242. </tr>
  243. <tr>
  244. <td align="right"><?php echo get_lang('FirstName'); ?> :</td>
  245. <td><input type="text" size="15" name="firstname_form" value="<?php echo api_htmlentities(stripslashes($firstname_form), ENT_QUOTES, $charset); ?>" /></td>
  246. </tr>
  247. <?php
  248. }
  249. ?>
  250. <tr>
  251. <td align="right"><?php echo get_lang('OfficialCode'); ?> :</td>
  252. <td><input type="text" size="15" name="official_code_form" value="<?php echo api_htmlentities(stripslashes($official_code_form), ENT_QUOTES, $charset); ?>" /></td>
  253. </tr>
  254. <tr>
  255. <td align="right"><?php echo get_lang('UserName') ?> :</td>
  256. <td><input type="text" size="15" name="username_form" value="<?php echo api_htmlentities(stripslashes($username_form), ENT_QUOTES, $charset); ?>" /></td>
  257. </tr>
  258. <tr>
  259. <td align="right"><?php echo get_lang('Pass') ?> :</td>
  260. <td><input type="password" size="15" name="password_form" value="<?php echo api_htmlentities(stripslashes($password_form), ENT_QUOTES, $charset) ?>" /></td>
  261. </tr>
  262. <tr>
  263. <td align="right"><?php echo get_lang('Email'); ?> :</td>
  264. <td><input type="text" size="15" name="email_form" value="<?php echo $email_form; ?>" /></td>
  265. </tr>
  266. <tr>
  267. <?php
  268. if ($_cid) // if we're inside a course, then it's a course registration
  269. {
  270. ?>
  271. <td align="right"><?php echo get_lang('Tutor'); ?> :</td>
  272. <td><input class="checkbox" type="radio" name="tutor_form" value="0" <?php if(!isset($tutor_form) || !$tutor_form) echo 'checked="checked"'; ?> /> <?php echo get_lang('No'); ?>
  273. <input class="checkbox" type="radio" name="tutor_form" value="1" <?php if($tutor_form == 1) echo 'checked="checked"'; ?> /> <?php echo get_lang('Yes') ?></td>
  274. </tr>
  275. <tr>
  276. <td align="right"><?php echo get_lang('Manager') ?> :</td>
  277. <td><input class="checkbox" type="radio" name="admin_form" value="5" <?php if(!isset($admin_form) || $admin_form == 5) echo 'checked="checked"'; ?> /> <?php echo get_lang('No') ?>
  278. <input class="checkbox" type="radio" name="admin_form" value="1" <?php if($admin_form == 1) echo 'checked="checked"'; ?> /> <?php echo get_lang('Yes'); ?></td>
  279. </tr>
  280. <?php
  281. } // end if $_cid - for the case we're not in a course registration
  282. // but a platform registration
  283. else
  284. {
  285. ?>
  286. <tr>
  287. <td align="right"><?php echo get_lang('Status') ?> : </td>
  288. <td>
  289. <select name="platformStatus">
  290. <option value="<?php echo STUDENT ?>"><?php echo get_lang('RegStudent') ?></option>
  291. <option value="<?php echo COURSEMANAGER ?>"><?php echo get_lang('RegAdmin') ?></option>
  292. </select>
  293. </td>
  294. </tr>
  295. <?php
  296. } // end else if $_cid
  297. ?>
  298. <tr>
  299. <td>&nbsp;</td>
  300. <td><input type="submit" name="submit" value="<?php echo get_lang('Ok') ?>" /></td>
  301. </tr>
  302. </table>
  303. </form>
  304. <?php
  305. /*==========================
  306. IMPORT XML/CSV USER LIST
  307. ==========================*/
  308. if($is_platformAdmin)
  309. {
  310. echo "<a href=\"".$rootAdminWeb."importUserList.php\">".get_lang('UserMany')."</a>";
  311. } // if is_platformAdmin
  312. else
  313. {
  314. echo "<p>".get_lang('IfYouWantToAddManyUsers')."</p>";
  315. }
  316. Display::display_footer();
  317. ?>