inscription.php 44 KB

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