inscription.php 49 KB

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