inscription.php 44 KB

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