inscription.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. use Chamilo\CoreBundle\Entity\ExtraFieldValues;
  5. /**
  6. * This script displays a form for registering new users.
  7. * @package chamilo.auth
  8. */
  9. //quick hack to adapt the registration form result to the selected registration language
  10. if (!empty($_POST['language'])) {
  11. $_GET['language'] = $_POST['language'];
  12. }
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. $hideHeaders = isset($_GET['hide_headers']);
  15. $allowedFields = [
  16. 'official_code',
  17. 'phone',
  18. 'status',
  19. 'language',
  20. 'extra_fields',
  21. 'address'
  22. ];
  23. $allowedFieldsConfiguration = api_get_configuration_value('allow_fields_inscription');
  24. if ($allowedFieldsConfiguration !== false) {
  25. $allowedFields = $allowedFieldsConfiguration;
  26. }
  27. $gMapsPlugin = GoogleMapsPlugin::create();
  28. $geolocalization = $gMapsPlugin->get('enable_api') === 'true';
  29. if ($geolocalization) {
  30. $gmapsApiKey = $gMapsPlugin->get('api_key');
  31. $htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true&key='. $gmapsApiKey . '" ></script>';
  32. }
  33. $webserviceUrl = api_get_plugin_setting('logintcc', 'webservice_url');
  34. $hash = api_get_plugin_setting('logintcc', 'hash');
  35. $htmlHeadXtra[] = '<script>
  36. $(document).ready(function() {
  37. $("#search_user").click(function() {
  38. var data = new Object();
  39. data.Mail = $("input[name=\'email\']").val();
  40. data.HashKey = "'.$hash.'";
  41. $.ajax({
  42. url: "'.$webserviceUrl.'/IsExistEmail",
  43. data: JSON.stringify(data),
  44. dataType: "json",
  45. type: "POST",
  46. contentType: "application/json; charset=utf-8",
  47. success: function (data, status) {
  48. if (data.d.Exist) {
  49. var monU = data.d.User;
  50. $("input[name=\'extra_tcc_user_id\']").val(monU.UserID);
  51. $("input[name=\'extra_tcc_hash_key\']").val(monU.HashKey);
  52. var $radios = $("input:radio[name=\'extra_terms_genre[extra_terms_genre]\']");
  53. if (monU.Genre == "Masculin") {
  54. $radios.filter(\'[value=homme]\').prop(\'checked\', true);
  55. } else {
  56. $radios.filter(\'[value=femme]\').prop(\'checked\', true);
  57. }
  58. $("input[name=\'lastname\']").val(monU.Nom);
  59. $("input[name=\'firstname\']").val(monU.Prenom);
  60. var date = monU.DateNaissance; // 30/06/1986
  61. if (date != "") {
  62. var parts = date.split(\'/\');
  63. $("#extra_terms_datedenaissance").datepicker("setDate", new Date(parts[2], parts[1], parts[0]));
  64. }
  65. if (monU.Langue == "fr-FR") {
  66. $("#language").selectpicker("val", "french");
  67. $("#language").selectpicker(\'render\');
  68. }
  69. if (monU.Langue == "de-DE") {
  70. $("#language").selectpicker("val", "german");
  71. $("#language").selectpicker(\'render\');
  72. }
  73. $("input[name=\'extra_terms_nationalite\']").val(monU.Nationalite);
  74. $("input[name=\'extra_terms_paysresidence\']").val(monU.PaysResidence);
  75. $("input[name=\'extra_terms_adresse\']").val(monU.Adresse);
  76. $("input[name=\'extra_terms_codepostal\']").val(monU.CP);
  77. $("input[name=\'extra_terms_ville\']").val(monU.Ville);
  78. } else {
  79. alert("'.get_lang("UnknownUser").'");
  80. }
  81. },
  82. error: function (XMLHttpRequest, textStatus, errorThrown) {
  83. alert(textStatus);
  84. }
  85. });
  86. return false;
  87. });
  88. });
  89. </script>';
  90. $htmlHeadXtra[] = api_get_password_checker_js('#username', '#pass1');
  91. // User is not allowed if Terms and Conditions are disabled and
  92. // registration is disabled too.
  93. $isNotAllowedHere = api_get_setting('allow_terms_conditions') === 'false' && api_get_setting('allow_registration') === 'false';
  94. if ($isNotAllowedHere) {
  95. api_not_allowed(true, get_lang('RegistrationDisabled'));
  96. }
  97. if (!empty($_SESSION['user_language_choice'])) {
  98. $user_selected_language = $_SESSION['user_language_choice'];
  99. } elseif (!empty($_SESSION['_user']['language'])) {
  100. $user_selected_language = $_SESSION['_user']['language'];
  101. } else {
  102. $user_selected_language = api_get_setting('platformLanguage');
  103. }
  104. $form = new FormValidator('registration');
  105. $user_already_registered_show_terms = false;
  106. if (api_get_setting('allow_terms_conditions') == 'true') {
  107. $user_already_registered_show_terms = isset($_SESSION['term_and_condition']['user_id']);
  108. }
  109. $sessionPremiumChecker = Session::read('SessionIsPremium');
  110. $sessionId = Session::read('sessionId');
  111. // Direct Link Session Subscription feature #12220
  112. $sessionRedirect = isset($_REQUEST['s']) && !empty($_REQUEST['s']) ? $_REQUEST['s'] : null;
  113. $onlyOneCourseSessionRedirect = isset($_REQUEST['cr']) && !empty($_REQUEST['cr']) ? $_REQUEST['cr'] : null;
  114. if (api_get_configuration_value('allow_redirect_to_session_after_inscription_about')) {
  115. if (!empty($sessionRedirect)) {
  116. Session::write('session_redirect', $sessionRedirect);
  117. Session::write('only_one_course_session_redirect', $onlyOneCourseSessionRedirect);
  118. }
  119. }
  120. // Direct Link Subscription feature #5299
  121. $course_code_redirect = isset($_REQUEST['c']) && !empty($_REQUEST['c']) ? $_REQUEST['c'] : null;
  122. $exercise_redirect = isset($_REQUEST['e']) && !empty($_REQUEST['e']) ? $_REQUEST['e'] : null;
  123. if (!empty($course_code_redirect)) {
  124. Session::write('course_redirect', $course_code_redirect);
  125. Session::write('exercise_redirect', $exercise_redirect);
  126. }
  127. if ($user_already_registered_show_terms === false) {
  128. // EMAIL
  129. $form->addElement('text', 'email', get_lang('Email'), array('size' => 40));
  130. if (api_get_setting('registration', 'email') === 'true') {
  131. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  132. }
  133. $form->addButtonSearch(get_lang('SearchTCC'), 'search', ['id' => 'search_user']);
  134. if (api_is_western_name_order()) {
  135. // FIRST NAME and LAST NAME
  136. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  137. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  138. } else {
  139. // LAST NAME and FIRST NAME
  140. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  141. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  142. }
  143. $form->applyFilter(array('lastname', 'firstname'), 'trim');
  144. $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
  145. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  146. if (api_get_setting('login_is_email') === 'true') {
  147. $form->applyFilter('email', 'trim');
  148. if (api_get_setting('registration', 'email') != 'true') {
  149. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  150. }
  151. $form->addRule('email', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
  152. $form->addRule('email', get_lang('UserTaken'), 'username_available');
  153. }
  154. $form->addRule('email', get_lang('EmailWrong'), 'email');
  155. if (api_get_setting('openid_authentication') === 'true') {
  156. $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40));
  157. }
  158. // OFFICIAL CODE
  159. if (CONFVAL_ASK_FOR_OFFICIAL_CODE) {
  160. if (in_array('official_code', $allowedFields)) {
  161. $form->addElement(
  162. 'text',
  163. 'official_code',
  164. get_lang('OfficialCode'),
  165. array('size' => 40)
  166. );
  167. if (api_get_setting('registration', 'officialcode') == 'true') {
  168. $form->addRule(
  169. 'official_code',
  170. get_lang('ThisFieldIsRequired'),
  171. 'required'
  172. );
  173. }
  174. }
  175. }
  176. // USERNAME
  177. if (api_get_setting('login_is_email') != 'true') {
  178. $form->addText(
  179. 'username',
  180. get_lang('UserName'),
  181. true,
  182. array(
  183. 'id' => 'username',
  184. 'size' => USERNAME_MAX_LENGTH,
  185. 'autocomplete' => 'off'
  186. )
  187. );
  188. $form->applyFilter('username', 'trim');
  189. $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
  190. $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
  191. $form->addRule('username', get_lang('UsernameWrong'), 'username');
  192. $form->addRule('username', get_lang('UserTaken'), 'username_available');
  193. }
  194. $passDiv = '<div id="password_progress"></div><div id="password-verdict"></div><div id="password-errors"></div>';
  195. $checkPass = api_get_setting('allow_strength_pass_checker');
  196. if ($checkPass === 'true') {
  197. $checkPass = '';
  198. }
  199. // PASSWORD
  200. $form->addElement(
  201. 'password',
  202. 'pass1',
  203. [get_lang('Pass'), $passDiv],
  204. array('id' => 'pass1', 'size' => 20, 'autocomplete' => 'off')
  205. );
  206. $checkPass = api_get_setting('allow_strength_pass_checker');
  207. // if ($checkPass === 'true') {
  208. // $form->addLabel(null,
  209. // '<div id="password_progress"></div><div id="password-verdict"></div><div id="password-errors"></div>'
  210. // );
  211. // }
  212. $form->addElement(
  213. 'password',
  214. 'pass2',
  215. get_lang('Confirmation'),
  216. array('id' => 'pass2', 'size' => 20, 'autocomplete' => 'off')
  217. );
  218. $form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required');
  219. $form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required');
  220. $form->addRule(array('pass1', 'pass2'), get_lang('PassTwo'), 'compare');
  221. if (true) {
  222. $form->addRule(
  223. 'pass1',
  224. get_lang('PassTooEasy') . ': ' . api_generate_password(),
  225. 'callback',
  226. 'api_check_password'
  227. );
  228. }
  229. // PHONE
  230. if (in_array('phone', $allowedFields)) {
  231. $form->addElement(
  232. 'text',
  233. 'phone',
  234. get_lang('Phone'),
  235. array('size' => 20)
  236. );
  237. if (api_get_setting('registration', 'phone') == 'true') {
  238. $form->addRule(
  239. 'phone',
  240. get_lang('ThisFieldIsRequired'),
  241. 'required'
  242. );
  243. }
  244. }
  245. if ($userGeolocalization) {
  246. // Geo location
  247. if (in_array('address', $allowedFields)) {
  248. $form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
  249. $form->addHtml('
  250. <div class="form-group">
  251. <label for="geolocalization" class="col-sm-2 control-label"></label>
  252. <div class="col-sm-8">
  253. <button class="null btn btn-default " id="geolocalization" name="geolocalization" type="submit"><em class="fa fa-map-marker"></em> '.get_lang('Geolocalization').'</button>
  254. <button class="null btn btn-default " id="myLocation" name="myLocation" type="submit"><em class="fa fa-crosshairs"></em> '.get_lang('MyLocation').'</button>
  255. </div>
  256. </div>
  257. ');
  258. $form->addHtml('
  259. <div class="form-group">
  260. <label for="map" class="col-sm-2 control-label">
  261. '.get_lang('Map').'
  262. </label>
  263. <div class="col-sm-8">
  264. <div name="map" id="map" style="width:100%; height:300px;">
  265. </div>
  266. </div>
  267. </div>
  268. ');
  269. }
  270. }
  271. // Language
  272. if (in_array('language', $allowedFields)) {
  273. if (api_get_setting('registration', 'language') == 'true') {
  274. $form->addSelectLanguage(
  275. 'language',
  276. get_lang('Language'),
  277. [],
  278. ['id' => 'language']
  279. );
  280. }
  281. }
  282. // STUDENT/TEACHER
  283. if (api_get_setting('allow_registration_as_teacher') != 'false') {
  284. if (in_array('status', $allowedFields)) {
  285. $form->addElement(
  286. 'radio',
  287. 'status',
  288. get_lang('Profile'),
  289. get_lang('RegStudent'),
  290. STUDENT
  291. );
  292. $form->addElement(
  293. 'radio',
  294. 'status',
  295. null,
  296. get_lang('RegAdmin'),
  297. COURSEMANAGER
  298. );
  299. }
  300. }
  301. $captcha = api_get_setting('allow_captcha');
  302. $allowCaptcha = $captcha === 'true';
  303. if ($allowCaptcha) {
  304. $ajax = api_get_path(WEB_AJAX_PATH).'form.ajax.php?a=get_captcha';
  305. $options = array(
  306. 'width' => 220,
  307. 'height' => 90,
  308. 'callback' => $ajax.'&var='.basename(__FILE__, '.php'),
  309. 'sessionVar' => basename(__FILE__, '.php'),
  310. 'imageOptions' => array(
  311. 'font_size' => 20,
  312. 'font_path' => api_get_path(SYS_FONTS_PATH).'opensans/',
  313. 'font_file' => 'OpenSans-Regular.ttf',
  314. //'output' => 'gif'
  315. )
  316. );
  317. $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options);
  318. $form->addElement('static', null, null, get_lang('ClickOnTheImageForANewOne'));
  319. $form->addElement('text', 'captcha', get_lang('EnterTheLettersYouSee'), array('size' => 40));
  320. $form->addRule('captcha', get_lang('EnterTheCharactersYouReadInTheImage'), 'required', null, 'client');
  321. $form->addRule('captcha', get_lang('TheTextYouEnteredDoesNotMatchThePicture'), 'CAPTCHA', $captcha_question);
  322. }
  323. // EXTENDED FIELDS
  324. if (api_get_setting('extended_profile') == 'true' &&
  325. api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true'
  326. ) {
  327. $form->addHtmlEditor(
  328. 'competences',
  329. get_lang('MyCompetences'),
  330. false,
  331. false,
  332. array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130')
  333. );
  334. }
  335. if (api_get_setting('extended_profile') == 'true' &&
  336. api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true'
  337. ) {
  338. $form->addHtmlEditor(
  339. 'diplomas',
  340. get_lang('MyDiplomas'),
  341. false,
  342. false,
  343. array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130')
  344. );
  345. }
  346. if (api_get_setting('extended_profile') == 'true' &&
  347. api_get_setting('extendedprofile_registration', 'myteach') == 'true'
  348. ) {
  349. $form->addHtmlEditor(
  350. 'teach',
  351. get_lang('MyTeach'),
  352. false,
  353. false,
  354. array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130')
  355. );
  356. }
  357. if (api_get_setting('extended_profile') == 'true' &&
  358. api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true'
  359. ) {
  360. $form->addHtmlEditor(
  361. 'openarea',
  362. get_lang('MyPersonalOpenArea'),
  363. false,
  364. false,
  365. array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130')
  366. );
  367. }
  368. if (api_get_setting('extended_profile') === 'true') {
  369. if (api_get_setting('extendedprofile_registration', 'mycomptetences') === 'true' &&
  370. api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') === 'true'
  371. ) {
  372. $form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required');
  373. }
  374. if (api_get_setting('extendedprofile_registration', 'mydiplomas') === 'true' &&
  375. api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') === 'true'
  376. ) {
  377. $form->addRule('diplomas', get_lang('ThisFieldIsRequired'), 'required');
  378. }
  379. if (api_get_setting('extendedprofile_registration', 'myteach') === 'true' &&
  380. api_get_setting('extendedprofile_registrationrequired', 'myteach') === 'true'
  381. ) {
  382. $form->addRule('teach', get_lang('ThisFieldIsRequired'), 'required');
  383. }
  384. if (api_get_setting('extendedprofile_registration', 'mypersonalopenarea') === 'true' &&
  385. api_get_setting('extendedprofile_registrationrequired', 'mypersonalopenarea') === 'true'
  386. ) {
  387. $form->addRule('openarea', get_lang('ThisFieldIsRequired'), 'required');
  388. }
  389. }
  390. $form->addElement(
  391. 'hidden',
  392. 'extra_tcc_user_id'
  393. );
  394. $form->addElement(
  395. 'hidden',
  396. 'extra_tcc_hash_key'
  397. );
  398. // EXTRA FIELDS
  399. if (array_key_exists('extra_fields', $allowedFields) || in_array('extra_fields', $allowedFields)) {
  400. $extraField = new ExtraField('user');
  401. $extraFieldList = isset($allowedFields['extra_fields']) && is_array($allowedFields['extra_fields']) ? $allowedFields['extra_fields'] : [];
  402. $returnParams = $extraField->addElements($form, 0, [], false, false, $extraFieldList);
  403. }
  404. }
  405. if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {
  406. $defaults['language'] = $_SESSION['user_language_choice'];
  407. } else {
  408. $defaults['language'] = api_get_setting('platformLanguage');
  409. }
  410. if (!empty($_GET['username'])) {
  411. $defaults['username'] = Security::remove_XSS($_GET['username']);
  412. }
  413. if (!empty($_GET['email'])) {
  414. $defaults['email'] = Security::remove_XSS($_GET['email']);
  415. }
  416. if (!empty($_GET['phone'])) {
  417. $defaults['phone'] = Security::remove_XSS($_GET['phone']);
  418. }
  419. if (api_get_setting('openid_authentication') === 'true' && !empty($_GET['openid'])) {
  420. $defaults['openid'] = Security::remove_XSS($_GET['openid']);
  421. }
  422. $defaults['status'] = STUDENT;
  423. $defaults['extra_mail_notify_invitation'] = 1;
  424. $defaults['extra_mail_notify_message'] = 1;
  425. $defaults['extra_mail_notify_group_message'] = 1;
  426. $form->setDefaults($defaults);
  427. $content = null;
  428. if (!CustomPages::enabled()) {
  429. // Load terms & conditions from the current lang
  430. if (api_get_setting('allow_terms_conditions') === 'true') {
  431. $get = array_keys($_GET);
  432. if (isset($get)) {
  433. if (isset($get[0]) && $get[0] == 'legal') {
  434. $language = api_get_interface_language();
  435. $language = api_get_language_id($language);
  436. $term_preview = LegalManager::get_last_condition($language);
  437. if (!$term_preview) {
  438. //look for the default language
  439. $language = api_get_setting('platformLanguage');
  440. $language = api_get_language_id($language);
  441. $term_preview = LegalManager::get_last_condition($language);
  442. }
  443. $tool_name = get_lang('TermsAndConditions');
  444. Display::display_header($tool_name);
  445. if (!empty($term_preview['content'])) {
  446. echo $term_preview['content'];
  447. } else {
  448. echo get_lang('ComingSoon');
  449. }
  450. Display::display_footer();
  451. exit;
  452. }
  453. }
  454. }
  455. $tool_name = get_lang('Registration', null, (!empty($_POST['language'])?$_POST['language']: $_user['language']));
  456. if (api_get_setting('allow_terms_conditions') === 'true' && $user_already_registered_show_terms) {
  457. $tool_name = get_lang('TermsAndConditions');
  458. }
  459. $home = api_get_path(SYS_APP_PATH).'home/';
  460. if (api_is_multiple_url_enabled()) {
  461. $access_url_id = api_get_current_access_url_id();
  462. if ($access_url_id != -1) {
  463. $url_info = api_get_access_url($access_url_id);
  464. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  465. $clean_url = api_replace_dangerous_char($url);
  466. $clean_url = str_replace('/', '-', $clean_url);
  467. $clean_url .= '/';
  468. $home_old = api_get_path(SYS_APP_PATH).'home/';
  469. $home = api_get_path(SYS_APP_PATH).'home/'.$clean_url;
  470. }
  471. }
  472. if (file_exists($home.'register_top_'.$user_selected_language.'.html')) {
  473. $home_top_temp = @(string)file_get_contents($home.'register_top_'.$user_selected_language.'.html');
  474. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  475. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  476. if (!empty($open)) {
  477. $content = '<div class="well_border">'.$open.'</div>';
  478. }
  479. }
  480. // Forbidden to self-register
  481. if ($isNotAllowedHere) {
  482. api_not_allowed(true, get_lang('RegistrationDisabled'));
  483. }
  484. if (api_get_setting('allow_registration') === 'approval') {
  485. $content .= Display::return_message(get_lang('YourAccountHasToBeApproved'));
  486. }
  487. //if openid was not found
  488. if (!empty($_GET['openid_msg']) && $_GET['openid_msg'] == 'idnotfound') {
  489. $content .= Display::return_message(get_lang('OpenIDCouldNotBeFoundPleaseRegister'));
  490. }
  491. }
  492. $blockButton = false;
  493. // Terms and conditions
  494. if (api_get_setting('allow_terms_conditions') == 'true') {
  495. if (!api_is_platform_admin()) {
  496. if (api_get_setting('show_terms_if_profile_completed') === 'true') {
  497. $userInfo = api_get_user_info(api_get_user_id(), false, false, true);
  498. if ($userInfo && $userInfo['status'] != ANONYMOUS) {
  499. $extraFieldValue = new ExtraFieldValue('user');
  500. $termActivated = false;
  501. $value = $extraFieldValue->get_values_by_handler_and_field_variable(api_get_user_id(), 'termactivated');
  502. if (isset($value['value'])) {
  503. $termActivated = !empty($value['value']) && $value['value'] == 1;
  504. }
  505. /*$extraFieldValue = new ExtraFieldValue('user');
  506. $value = $extraFieldValue->get_values_by_handler_and_field_variable(api_get_user_id(), 'legal_accept');
  507. $legalAccept = false;
  508. if (isset($value['value'])) {
  509. list($legalId, $legalLanguageId, $legalTime) = explode(
  510. ':',
  511. $value['value']
  512. );
  513. if ($legalId) {
  514. $legalAccept = true;
  515. }
  516. }*/
  517. if ($termActivated === false) {
  518. $blockButton = true;
  519. Display::addFlash(Display::return_message(get_lang('TermActivatedIsNeededDescription'), 'warning'));
  520. }
  521. if ($blockButton === false) {
  522. if ((int)$userInfo['profile_completed'] !== 1) {
  523. $blockButton = true;
  524. Display::addFlash(
  525. Display::return_message(get_lang('TermYourProfileIsNotCompleted'), 'warning')
  526. );
  527. }
  528. }
  529. }
  530. }
  531. }
  532. // Ofaj
  533. if (!api_is_anonymous()) {
  534. $language = api_get_interface_language();
  535. $language = api_get_language_id($language);
  536. $term_preview = LegalManager::get_last_condition($language);
  537. if (!$term_preview) {
  538. //we load from the platform
  539. $language = api_get_setting('platformLanguage');
  540. $language = api_get_language_id($language);
  541. $term_preview = LegalManager::get_last_condition($language);
  542. //if is false we load from english
  543. if (!$term_preview) {
  544. $language = api_get_language_id('english'); //this must work
  545. $term_preview = LegalManager::get_last_condition($language);
  546. }
  547. }
  548. // Version and language
  549. $form->addElement(
  550. 'hidden',
  551. 'legal_accept_type',
  552. $term_preview['version'].':'.$term_preview['language_id']
  553. );
  554. $form->addElement(
  555. 'hidden',
  556. 'legal_info',
  557. $term_preview['id'].':'.$term_preview['language_id']
  558. );
  559. if ($term_preview['type'] == 1) {
  560. $form->addElement(
  561. 'checkbox',
  562. 'legal_accept',
  563. null,
  564. get_lang(
  565. 'IHaveReadAndAgree'
  566. ).'&nbsp;<a href="inscription.php?legal" target="_blank">'.get_lang(
  567. 'TermsAndConditions'
  568. ).'</a>'
  569. );
  570. $form->addRule(
  571. 'legal_accept',
  572. get_lang('ThisFieldIsRequired'),
  573. 'required'
  574. );
  575. } else {
  576. $preview = LegalManager::show_last_condition($term_preview);
  577. $form->addElement('label', null, $preview);
  578. }
  579. }
  580. }
  581. if ($user_already_registered_show_terms === false) {
  582. $form->addCheckBox(
  583. 'extra_platformuseconditions',
  584. null,
  585. get_lang('PlatformUseConditions')
  586. );
  587. $form->addRule(
  588. 'extra_platformuseconditions',
  589. get_lang('ThisFieldIsRequired'),
  590. 'required'
  591. );
  592. }
  593. if ($blockButton) {
  594. $form->addButton('submit', get_lang('RegisterUserOk'), 'check', 'primary', null, null, ['disabled' => 'disabled'], false);
  595. } else {
  596. $form->addButton('submit', get_lang('RegisterUser'));
  597. }
  598. $course_code_redirect = Session::read('course_redirect');
  599. $sessionToRedirect = Session::read('session_redirect');
  600. if ($form->validate()) {
  601. $values = $form->getSubmitValues(1);
  602. // Make *sure* the login isn't too long
  603. if (isset($values['username'])) {
  604. $values['username'] = api_substr($values['username'], 0, USERNAME_MAX_LENGTH);
  605. }
  606. if (api_get_setting('allow_registration_as_teacher') === 'false') {
  607. $values['status'] = STUDENT;
  608. }
  609. if (empty($values['official_code']) && !empty($values['username'])) {
  610. $values['official_code'] = api_strtoupper($values['username']);
  611. }
  612. if (api_get_setting('login_is_email') == 'true') {
  613. $values['username'] = $values['email'];
  614. }
  615. if ($user_already_registered_show_terms &&
  616. api_get_setting('allow_terms_conditions') === 'true'
  617. ) {
  618. $user_id = $_SESSION['term_and_condition']['user_id'];
  619. $is_admin = UserManager::is_admin($user_id);
  620. Session::write('is_platformAdmin', $is_admin);
  621. } else {
  622. // Moved here to include extra fields when creating a user. Formerly placed after user creation
  623. // Register extra fields
  624. $extras = array();
  625. foreach ($values as $key => $value) {
  626. if (substr($key, 0, 6) == 'extra_') {
  627. //an extra field
  628. $extras[substr($key, 6)] = $value;
  629. } elseif (strpos($key, 'remove_extra_') !== false) {
  630. $extra_value = Security::filter_filename(urldecode(key($value)));
  631. // To remove from user_field_value and folder
  632. UserManager::update_extra_field_value(
  633. $user_id,
  634. substr($key, 13),
  635. $extra_value
  636. );
  637. }
  638. }
  639. $userFromDb = UserManager::getManager()->findUserByEmail($values['email']);
  640. if ($userFromDb) {
  641. Display::addFlash(Display::return_message(get_lang('EmailUsedTwice'), 'warning'));
  642. header('Location: '.api_get_self());
  643. exit;
  644. }
  645. $status = isset($values['status']) ? $values['status'] : STUDENT;
  646. $phone = isset($values['phone']) ? $values['phone'] : null;
  647. $values['language'] = isset($values['language']) ? $values['language'] : api_get_interface_language();
  648. $values['address'] = isset($values['address']) ? $values['address'] : '';
  649. // Creates a new user
  650. $user_id = UserManager::create_user(
  651. $values['firstname'],
  652. $values['lastname'],
  653. $status,
  654. $values['email'],
  655. $values['username'],
  656. $values['pass1'],
  657. $values['official_code'],
  658. $values['language'],
  659. $phone,
  660. null,
  661. PLATFORM_AUTH_SOURCE,
  662. null,
  663. 1,
  664. 0,
  665. $extras,
  666. null,
  667. true,
  668. false,
  669. $values['address'],
  670. true,
  671. $form
  672. );
  673. //update the extra fields
  674. $count_extra_field = count($extras);
  675. if ($count_extra_field > 0 && is_integer($user_id)) {
  676. foreach ($extras as $key => $value) {
  677. // For array $value -> if exists key 'tmp_name' then must not be empty
  678. // This avoid delete from user field value table when doesn't upload a file
  679. if (is_array($value)) {
  680. if (array_key_exists('tmp_name', $value) && empty($value['tmp_name'])) {
  681. //Nothing to do
  682. } else {
  683. if (array_key_exists('tmp_name', $value)) {
  684. $value['tmp_name'] = Security::filter_filename($value['tmp_name']);
  685. }
  686. if (array_key_exists('name', $value)) {
  687. $value['name'] = Security::filter_filename($value['name']);
  688. }
  689. UserManager::update_extra_field_value($user_id, $key, $value);
  690. }
  691. } else {
  692. UserManager::update_extra_field_value($user_id, $key, $value);
  693. }
  694. }
  695. }
  696. if ($user_id) {
  697. // Storing the extended profile
  698. $store_extended = false;
  699. $sql = "UPDATE ".Database::get_main_table(TABLE_MAIN_USER)." SET ";
  700. if (api_get_setting('extended_profile') == 'true' &&
  701. api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true'
  702. ) {
  703. $sql_set[] = "competences = '".Database::escape_string($values['competences'])."'";
  704. $store_extended = true;
  705. }
  706. if (api_get_setting('extended_profile') == 'true' &&
  707. api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true'
  708. ) {
  709. $sql_set[] = "diplomas = '".Database::escape_string($values['diplomas'])."'";
  710. $store_extended = true;
  711. }
  712. if (api_get_setting('extended_profile') == 'true' &&
  713. api_get_setting('extendedprofile_registration', 'myteach') == 'true'
  714. ) {
  715. $sql_set[] = "teach = '".Database::escape_string($values['teach'])."'";
  716. $store_extended = true;
  717. }
  718. if (api_get_setting('extended_profile') == 'true' &&
  719. api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true'
  720. ) {
  721. $sql_set[] = "openarea = '".Database::escape_string($values['openarea'])."'";
  722. $store_extended = true;
  723. }
  724. if ($store_extended) {
  725. $sql .= implode(',', $sql_set);
  726. $sql .= " WHERE user_id = ".intval($user_id)."";
  727. Database::query($sql);
  728. }
  729. // Saving user to Session if it was set
  730. if (!empty($sessionToRedirect) && !$sessionPremiumChecker) {
  731. $sessionInfo = api_get_session_info($sessionToRedirect);
  732. if (!empty($sessionInfo)) {
  733. SessionManager::subscribe_users_to_session(
  734. $sessionToRedirect,
  735. [$user_id],
  736. SESSION_VISIBLE_READ_ONLY,
  737. false
  738. );
  739. }
  740. }
  741. // Saving user to course if it was set.
  742. if (!empty($course_code_redirect)) {
  743. $course_info = api_get_course_info($course_code_redirect);
  744. if (!empty($course_info)) {
  745. if (in_array(
  746. $course_info['visibility'],
  747. array(
  748. COURSE_VISIBILITY_OPEN_PLATFORM,
  749. COURSE_VISIBILITY_OPEN_WORLD
  750. )
  751. )
  752. ) {
  753. CourseManager::subscribe_user(
  754. $user_id,
  755. $course_info['code']
  756. );
  757. }
  758. }
  759. }
  760. /* If the account has to be approved then we set the account to inactive,
  761. sent a mail to the platform admin and exit the page.*/
  762. if (api_get_setting('allow_registration') === 'approval') {
  763. $TABLE_USER = Database::get_main_table(TABLE_MAIN_USER);
  764. // 1. set account inactive
  765. $sql = "UPDATE $TABLE_USER SET active='0' WHERE user_id = ".$user_id;
  766. Database::query($sql);
  767. // 2. Send mail to all platform admin
  768. $emailsubject = get_lang('ApprovalForNewAccount', null, $values['language']).': '.$values['username'];
  769. $emailbody = get_lang('ApprovalForNewAccount', null, $values['language'])."\n";
  770. $emailbody .= get_lang('UserName', null, $values['language']).': '.$values['username']."\n";
  771. if (api_is_western_name_order()) {
  772. $emailbody .= get_lang('FirstName', null, $values['language']).': '.$values['firstname']."\n";
  773. $emailbody .= get_lang('LastName', null, $values['language']).': '.$values['lastname']."\n";
  774. } else {
  775. $emailbody .= get_lang('LastName', null, $values['language']).': '.$values['lastname']."\n";
  776. $emailbody .= get_lang('FirstName', null, $values['language']).': '.$values['firstname']."\n";
  777. }
  778. $emailbody .= get_lang('Email', null, $values['language']).': '.$values['email']."\n";
  779. $emailbody .= get_lang('Status', null, $values['language']).': '.$values['status']."\n\n";
  780. $url_edit = Display::url(
  781. api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id,
  782. api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id
  783. );
  784. $emailbody .= get_lang('ManageUser', null, $values['language']).": $url_edit";
  785. $admins = UserManager::get_all_administrators();
  786. foreach ($admins as $admin_info) {
  787. MessageManager::send_message(
  788. $admin_info['user_id'],
  789. $emailsubject,
  790. $emailbody,
  791. [],
  792. [],
  793. null,
  794. null,
  795. null,
  796. null,
  797. $user_id
  798. );
  799. }
  800. // 3. exit the page
  801. unset($user_id);
  802. Display::display_header($tool_name);
  803. echo Display::page_header($tool_name);
  804. echo $content;
  805. Display::display_footer();
  806. exit;
  807. }
  808. }
  809. }
  810. // Terms & Conditions
  811. if (api_get_setting('allow_terms_conditions') === 'true') {
  812. // Update the terms & conditions.
  813. if (isset($values['legal_accept_type'])) {
  814. $cond_array = explode(':', $values['legal_accept_type']);
  815. if (!empty($cond_array[0]) && !empty($cond_array[1])) {
  816. $time = time();
  817. $condition_to_save = intval($cond_array[0]).':'.intval($cond_array[1]).':'.$time;
  818. UserManager::update_extra_field_value($user_id, 'legal_accept', $condition_to_save);
  819. $bossList = UserManager::getStudentBossList($user_id);
  820. if ($bossList) {
  821. $bossList = array_column($bossList, 'boss_id');
  822. $currentUserInfo = api_get_user_info($user_id);
  823. $followUpPath = api_get_path(WEB_CODE_PATH) . 'admin/user_information.php?user_id='.$currentUserInfo['id'];
  824. foreach ($bossList as $bossId) {
  825. $subjectEmail = sprintf(get_lang('UserXSignedTheAgreementCheckAtPageX'), $currentUserInfo['complete_name'], $followUpPath);
  826. $contentEmail = sprintf(
  827. get_lang('UserXSignedTheAgreementTheY'),
  828. $currentUserInfo['complete_name'],
  829. api_get_local_time($time)
  830. );
  831. MessageManager::send_message_simple(
  832. $bossId,
  833. $subjectEmail,
  834. $contentEmail
  835. );
  836. }
  837. }
  838. }
  839. }
  840. $values = api_get_user_info($user_id);
  841. }
  842. /* SESSION REGISTERING */
  843. /* @todo move this in a function */
  844. $_user['firstName'] = stripslashes($values['firstname']);
  845. $_user['lastName'] = stripslashes($values['lastname']);
  846. $_user['mail'] = $values['email'];
  847. $_user['language'] = $values['language'];
  848. $_user['user_id'] = $user_id;
  849. $userInfo = api_get_user_info($user_id);
  850. $_user['status'] = $userInfo['status'];
  851. $is_allowedCreateCourse = isset($values['status']) && $values['status'] == 1;
  852. $usersCanCreateCourse = api_is_allowed_to_create_course();
  853. Session::write('_user', $_user);
  854. Session::write('is_allowedCreateCourse', $is_allowedCreateCourse);
  855. // Stats
  856. Event::event_login($user_id);
  857. // last user login date is now
  858. $user_last_login_datetime = 0; // used as a unix timestamp it will correspond to : 1 1 1970
  859. Session::write('user_last_login_datetime', $user_last_login_datetime);
  860. $text_after_registration =
  861. '<p>'.
  862. get_lang('Dear', null, $_user['language']).' '.
  863. stripslashes(Security::remove_XSS($values['firstname'])).',<br /><br />'.
  864. get_lang('PersonalSettings',null,$_user['language'])."</p>";
  865. $form_data = array(
  866. 'button' => Display::button('next', get_lang('Next', null, $_user['language']), array('class' => 'btn btn-primary btn-large')),
  867. 'message' => null,
  868. 'action' => api_get_path(WEB_PATH).'user_portal.php'
  869. );
  870. if (api_get_setting('allow_terms_conditions') === 'true' && $user_already_registered_show_terms) {
  871. if (api_get_setting('load_term_conditions_section') === 'login') {
  872. $form_data['action'] = api_get_path(WEB_PATH).'user_portal.php';
  873. } else {
  874. $courseInfo = api_get_course_info();
  875. if (!empty($courseInfo)) {
  876. $form_data['action'] = $courseInfo['course_public_url'].'?id_session='.api_get_session_id();
  877. $cidReset = true;
  878. Session::erase('_course');
  879. Session::erase('_cid');
  880. } else {
  881. $form_data['action'] = api_get_path(WEB_PATH).'user_portal.php';
  882. }
  883. }
  884. } else {
  885. if (!empty($values['email'])) {
  886. $text_after_registration.= '<p>'.get_lang('MailHasBeenSent', null, $_user['language']).'</p>';
  887. $diagnosticPath = '<a href="'.api_get_path(WEB_PATH).'search.php">'.api_get_path(WEB_PATH).'search.php</a>';
  888. $text_after_registration.= '<p>'.sprintf(get_lang('WelcomePleaseGoToDiagnosticAtX', null, $_user['language']), $diagnosticPath).'</p>';
  889. }
  890. if ($is_allowedCreateCourse) {
  891. if ($usersCanCreateCourse) {
  892. $form_data['message'] = '<p>'. get_lang('NowGoCreateYourCourse', null, $_user['language']). "</p>";
  893. }
  894. $form_data['action'] = api_get_path(WEB_CODE_PATH).'create_course/add_course.php';
  895. if (api_get_setting('course_validation') === 'true') {
  896. $form_data['button'] = Display::button(
  897. 'next',
  898. get_lang('CreateCourseRequest', null, $_user['language']),
  899. array('class' => 'btn btn-primary btn-large')
  900. );
  901. } else {
  902. $form_data['button'] = Display::button(
  903. 'next',
  904. get_lang('CourseCreate', null, $_user['language']),
  905. array('class' => 'btn btn-primary btn-large')
  906. );
  907. $form_data['go_button'] = '&nbsp;&nbsp;<a href="'.api_get_path(WEB_PATH).'index.php'.'">'.
  908. Display::span(
  909. get_lang('Next', null, $_user['language']),
  910. array('class' => 'btn btn-primary btn-large')
  911. ).'</a>';
  912. }
  913. } else {
  914. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  915. $form_data['action'] = 'courses.php?action=subscribe';
  916. $form_data['message'] = '<p>'. get_lang('NowGoChooseYourCourses', null, $_user['language']). ".</p>";
  917. } else {
  918. $form_data['action'] = api_get_path(WEB_PATH).'user_portal.php';
  919. }
  920. $form_data['button'] = Display::button(
  921. 'next',
  922. get_lang('Next', null, $_user['language']),
  923. array('class' => 'btn btn-primary btn-large')
  924. );
  925. }
  926. }
  927. if ($sessionPremiumChecker && $sessionId) {
  928. header('Location:' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/process.php?i=' . $sessionId . '&t=2');
  929. Session::erase('SessionIsPremium');
  930. Session::erase('sessionId');
  931. exit;
  932. }
  933. SessionManager::redirectToSession();
  934. $form_data = CourseManager::redirectToCourse($form_data);
  935. $form_register = new FormValidator('form_register', 'post', $form_data['action']);
  936. if (!empty($form_data['message'])) {
  937. $form_register->addElement('html', $form_data['message'].'<br /><br />');
  938. }
  939. if ($usersCanCreateCourse) {
  940. $form_register->addElement('html', $form_data['button']);
  941. } else {
  942. $form_register->addElement('html', $form_data['go_button']);
  943. }
  944. $text_after_registration .= $form_register->returnForm();
  945. // Just in case
  946. Session::erase('course_redirect');
  947. Session::erase('exercise_redirect');
  948. Session::erase('session_redirect');
  949. Session::erase('only_one_course_session_redirect');
  950. if (CustomPages::enabled()) {
  951. CustomPages::display(
  952. CustomPages::REGISTRATION_FEEDBACK,
  953. array('info' => $text_after_registration)
  954. );
  955. } else {
  956. $tpl = new Template($tool_name);
  957. $tpl->assign('inscription_content', $content);
  958. $tpl->assign('text_after_registration', $text_after_registration);
  959. $tpl->assign('hide_header', $hideHeaders);
  960. $inscription = $tpl->get_template('auth/inscription.tpl');
  961. $tpl->display($inscription);
  962. }
  963. } else {
  964. // Custom pages
  965. if (CustomPages::enabled()) {
  966. CustomPages::display(
  967. CustomPages::REGISTRATION, array('form' => $form)
  968. );
  969. } else {
  970. if (!api_is_anonymous()) {
  971. // Saving user to course if it was set.
  972. if (!empty($course_code_redirect)) {
  973. $course_info = api_get_course_info($course_code_redirect);
  974. if (!empty($course_info)) {
  975. if (in_array(
  976. $course_info['visibility'],
  977. array(
  978. COURSE_VISIBILITY_OPEN_PLATFORM,
  979. COURSE_VISIBILITY_OPEN_WORLD
  980. )
  981. )
  982. ) {
  983. CourseManager::subscribe_user(
  984. $user_id,
  985. $course_info['code']
  986. );
  987. }
  988. }
  989. }
  990. CourseManager::redirectToCourse([]);
  991. }
  992. $tpl = new Template($tool_name);
  993. $tpl->assign('inscription_header', Display::page_header($tool_name));
  994. $tpl->assign('inscription_content', $content);
  995. $tpl->assign('form', $form->returnForm());
  996. $tpl->assign('hide_header', $hideHeaders);
  997. $inscription = $tpl->get_template('auth/inscription.tpl');
  998. $tpl->display($inscription);
  999. }
  1000. }