inscription.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  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(Display::return_message(get_lang('TermActivatedIsNeededDescription'), 'warning'));
  505. }
  506. if ($blockButton === false) {
  507. if ((int)$userInfo['profile_completed'] !== 1) {
  508. $blockButton = true;
  509. Display::addFlash(
  510. Display::return_message(get_lang('TermYourProfileIsNotCompleted'), 'warning')
  511. );
  512. }
  513. }
  514. }
  515. }
  516. }
  517. // Ofaj
  518. if (!api_is_anonymous()) {
  519. $language = api_get_interface_language();
  520. $language = api_get_language_id($language);
  521. $term_preview = LegalManager::get_last_condition($language);
  522. if (!$term_preview) {
  523. //we load from the platform
  524. $language = api_get_setting('platformLanguage');
  525. $language = api_get_language_id($language);
  526. $term_preview = LegalManager::get_last_condition($language);
  527. //if is false we load from english
  528. if (!$term_preview) {
  529. $language = api_get_language_id('english'); //this must work
  530. $term_preview = LegalManager::get_last_condition($language);
  531. }
  532. }
  533. // ofaj
  534. if ($termActivated !== false) {
  535. // Version and language
  536. $form->addElement(
  537. 'hidden',
  538. 'legal_accept_type',
  539. $term_preview['version'].':'.$term_preview['language_id']
  540. );
  541. $form->addElement(
  542. 'hidden',
  543. 'legal_info',
  544. $term_preview['id'].':'.$term_preview['language_id']
  545. );
  546. if ($term_preview['type'] == 1) {
  547. $form->addElement(
  548. 'checkbox',
  549. 'legal_accept',
  550. null,
  551. get_lang('IHaveReadAndAgree').'&nbsp;<a href="inscription.php?legal" target="_blank">'.
  552. get_lang('TermsAndConditions').'</a>'
  553. );
  554. $form->addRule(
  555. 'legal_accept',
  556. get_lang('ThisFieldIsRequired'),
  557. 'required'
  558. );
  559. } else {
  560. $preview = LegalManager::show_last_condition($term_preview);
  561. $form->addElement('label', null, $preview);
  562. }
  563. }
  564. }
  565. }
  566. if ($user_already_registered_show_terms === false) {
  567. $form->addCheckBox(
  568. 'extra_platformuseconditions',
  569. null,
  570. get_lang('PlatformUseConditions')
  571. );
  572. $form->addRule(
  573. 'extra_platformuseconditions',
  574. get_lang('ThisFieldIsRequired'),
  575. 'required'
  576. );
  577. }
  578. if ($blockButton) {
  579. if ($termActivated !== false) {
  580. $form->addButton(
  581. 'submit',
  582. get_lang('RegisterUserOk'),
  583. 'check',
  584. 'primary',
  585. null,
  586. null,
  587. ['disabled' => 'disabled'],
  588. false
  589. );
  590. }
  591. } else {
  592. $form->addButton('submit', get_lang('RegisterUser'));
  593. }
  594. $course_code_redirect = Session::read('course_redirect');
  595. $sessionToRedirect = Session::read('session_redirect');
  596. if ($form->validate()) {
  597. $values = $form->getSubmitValues(1);
  598. // Make *sure* the login isn't too long
  599. if (isset($values['username'])) {
  600. $values['username'] = api_substr($values['username'], 0, USERNAME_MAX_LENGTH);
  601. }
  602. if (api_get_setting('allow_registration_as_teacher') === 'false') {
  603. $values['status'] = STUDENT;
  604. }
  605. if (empty($values['official_code']) && !empty($values['username'])) {
  606. $values['official_code'] = api_strtoupper($values['username']);
  607. }
  608. if (api_get_setting('login_is_email') == 'true') {
  609. $values['username'] = $values['email'];
  610. }
  611. if ($user_already_registered_show_terms &&
  612. api_get_setting('allow_terms_conditions') === 'true'
  613. ) {
  614. $user_id = $_SESSION['term_and_condition']['user_id'];
  615. $is_admin = UserManager::is_admin($user_id);
  616. Session::write('is_platformAdmin', $is_admin);
  617. } else {
  618. // Moved here to include extra fields when creating a user. Formerly placed after user creation
  619. // Register extra fields
  620. $extras = array();
  621. foreach ($values as $key => $value) {
  622. if (substr($key, 0, 6) == 'extra_') {
  623. //an extra field
  624. $extras[substr($key, 6)] = $value;
  625. } elseif (strpos($key, 'remove_extra_') !== false) {
  626. $extra_value = Security::filter_filename(urldecode(key($value)));
  627. // To remove from user_field_value and folder
  628. UserManager::update_extra_field_value(
  629. $user_id,
  630. substr($key, 13),
  631. $extra_value
  632. );
  633. }
  634. }
  635. $userFromDb = UserManager::getManager()->findUserByEmail($values['email']);
  636. if ($userFromDb) {
  637. Display::addFlash(Display::return_message(get_lang('EmailUsedTwice'), 'warning'));
  638. header('Location: '.api_get_self());
  639. exit;
  640. }
  641. $status = isset($values['status']) ? $values['status'] : STUDENT;
  642. $phone = isset($values['phone']) ? $values['phone'] : null;
  643. $values['language'] = isset($values['language']) ? $values['language'] : api_get_interface_language();
  644. $values['address'] = isset($values['address']) ? $values['address'] : '';
  645. // Creates a new user
  646. $user_id = UserManager::create_user(
  647. $values['firstname'],
  648. $values['lastname'],
  649. $status,
  650. $values['email'],
  651. $values['username'],
  652. $values['pass1'],
  653. $values['official_code'],
  654. $values['language'],
  655. $phone,
  656. null,
  657. PLATFORM_AUTH_SOURCE,
  658. null,
  659. 1,
  660. 0,
  661. $extras,
  662. null,
  663. true,
  664. false,
  665. $values['address'],
  666. true,
  667. $form
  668. );
  669. //update the extra fields
  670. $count_extra_field = count($extras);
  671. if ($count_extra_field > 0 && is_integer($user_id)) {
  672. foreach ($extras as $key => $value) {
  673. // For array $value -> if exists key 'tmp_name' then must not be empty
  674. // This avoid delete from user field value table when doesn't upload a file
  675. if (is_array($value)) {
  676. if (array_key_exists('tmp_name', $value) && empty($value['tmp_name'])) {
  677. //Nothing to do
  678. } else {
  679. if (array_key_exists('tmp_name', $value)) {
  680. $value['tmp_name'] = Security::filter_filename($value['tmp_name']);
  681. }
  682. if (array_key_exists('name', $value)) {
  683. $value['name'] = Security::filter_filename($value['name']);
  684. }
  685. UserManager::update_extra_field_value($user_id, $key, $value);
  686. }
  687. } else {
  688. UserManager::update_extra_field_value($user_id, $key, $value);
  689. }
  690. }
  691. }
  692. if ($user_id) {
  693. // Storing the extended profile
  694. $store_extended = false;
  695. $sql = "UPDATE ".Database::get_main_table(TABLE_MAIN_USER)." SET ";
  696. if (api_get_setting('extended_profile') == 'true' &&
  697. api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true'
  698. ) {
  699. $sql_set[] = "competences = '".Database::escape_string($values['competences'])."'";
  700. $store_extended = true;
  701. }
  702. if (api_get_setting('extended_profile') == 'true' &&
  703. api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true'
  704. ) {
  705. $sql_set[] = "diplomas = '".Database::escape_string($values['diplomas'])."'";
  706. $store_extended = true;
  707. }
  708. if (api_get_setting('extended_profile') == 'true' &&
  709. api_get_setting('extendedprofile_registration', 'myteach') == 'true'
  710. ) {
  711. $sql_set[] = "teach = '".Database::escape_string($values['teach'])."'";
  712. $store_extended = true;
  713. }
  714. if (api_get_setting('extended_profile') == 'true' &&
  715. api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true'
  716. ) {
  717. $sql_set[] = "openarea = '".Database::escape_string($values['openarea'])."'";
  718. $store_extended = true;
  719. }
  720. if ($store_extended) {
  721. $sql .= implode(',', $sql_set);
  722. $sql .= " WHERE user_id = ".intval($user_id)."";
  723. Database::query($sql);
  724. }
  725. // Saving user to Session if it was set
  726. if (!empty($sessionToRedirect) && !$sessionPremiumChecker) {
  727. $sessionInfo = api_get_session_info($sessionToRedirect);
  728. if (!empty($sessionInfo)) {
  729. SessionManager::subscribe_users_to_session(
  730. $sessionToRedirect,
  731. [$user_id],
  732. SESSION_VISIBLE_READ_ONLY,
  733. false
  734. );
  735. }
  736. }
  737. // Saving user to course if it was set.
  738. if (!empty($course_code_redirect)) {
  739. $course_info = api_get_course_info($course_code_redirect);
  740. if (!empty($course_info)) {
  741. if (in_array(
  742. $course_info['visibility'],
  743. array(
  744. COURSE_VISIBILITY_OPEN_PLATFORM,
  745. COURSE_VISIBILITY_OPEN_WORLD
  746. )
  747. )
  748. ) {
  749. CourseManager::subscribe_user(
  750. $user_id,
  751. $course_info['code']
  752. );
  753. }
  754. }
  755. }
  756. /* If the account has to be approved then we set the account to inactive,
  757. sent a mail to the platform admin and exit the page.*/
  758. if (api_get_setting('allow_registration') === 'approval') {
  759. $TABLE_USER = Database::get_main_table(TABLE_MAIN_USER);
  760. // 1. set account inactive
  761. $sql = "UPDATE $TABLE_USER SET active='0' WHERE user_id = ".$user_id;
  762. Database::query($sql);
  763. // 2. Send mail to all platform admin
  764. $emailsubject = get_lang('ApprovalForNewAccount', null, $values['language']).': '.$values['username'];
  765. $emailbody = get_lang('ApprovalForNewAccount', null, $values['language'])."\n";
  766. $emailbody .= get_lang('UserName', null, $values['language']).': '.$values['username']."\n";
  767. if (api_is_western_name_order()) {
  768. $emailbody .= get_lang('FirstName', null, $values['language']).': '.$values['firstname']."\n";
  769. $emailbody .= get_lang('LastName', null, $values['language']).': '.$values['lastname']."\n";
  770. } else {
  771. $emailbody .= get_lang('LastName', null, $values['language']).': '.$values['lastname']."\n";
  772. $emailbody .= get_lang('FirstName', null, $values['language']).': '.$values['firstname']."\n";
  773. }
  774. $emailbody .= get_lang('Email', null, $values['language']).': '.$values['email']."\n";
  775. $emailbody .= get_lang('Status', null, $values['language']).': '.$values['status']."\n\n";
  776. $url_edit = Display::url(
  777. api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id,
  778. api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id
  779. );
  780. $emailbody .= get_lang('ManageUser', null, $values['language']).": $url_edit";
  781. $admins = UserManager::get_all_administrators();
  782. foreach ($admins as $admin_info) {
  783. MessageManager::send_message(
  784. $admin_info['user_id'],
  785. $emailsubject,
  786. $emailbody,
  787. [],
  788. [],
  789. null,
  790. null,
  791. null,
  792. null,
  793. $user_id
  794. );
  795. }
  796. // 3. exit the page
  797. unset($user_id);
  798. Display::display_header($tool_name);
  799. echo Display::page_header($tool_name);
  800. echo $content;
  801. Display::display_footer();
  802. exit;
  803. }
  804. }
  805. }
  806. // Terms & Conditions
  807. if (api_get_setting('allow_terms_conditions') === 'true') {
  808. // Update the terms & conditions.
  809. if (isset($values['legal_accept_type'])) {
  810. $cond_array = explode(':', $values['legal_accept_type']);
  811. if (!empty($cond_array[0]) && !empty($cond_array[1])) {
  812. $time = time();
  813. $condition_to_save = intval($cond_array[0]).':'.intval($cond_array[1]).':'.$time;
  814. UserManager::update_extra_field_value(
  815. $user_id,
  816. 'legal_accept',
  817. $condition_to_save
  818. );
  819. $bossList = UserManager::getStudentBossList($user_id);
  820. if ($bossList) {
  821. $bossList = array_column($bossList, 'boss_id');
  822. $currentUserInfo = api_get_user_info($user_id);
  823. $followUpPath = api_get_path(WEB_CODE_PATH) . 'admin/user_information.php?user_id='.$currentUserInfo['id'];
  824. foreach ($bossList as $bossId) {
  825. $subjectEmail = sprintf(get_lang('UserXSignedTheAgreementCheckAtPageX'), $currentUserInfo['complete_name'], $followUpPath);
  826. $contentEmail = sprintf(
  827. get_lang('UserXSignedTheAgreementTheY'),
  828. $currentUserInfo['complete_name'],
  829. api_get_local_time($time)
  830. );
  831. MessageManager::send_message_simple(
  832. $bossId,
  833. $subjectEmail,
  834. $contentEmail
  835. );
  836. }
  837. }
  838. }
  839. }
  840. $values = api_get_user_info($user_id);
  841. }
  842. /* SESSION REGISTERING */
  843. /* @todo move this in a function */
  844. $_user['firstName'] = stripslashes($values['firstname']);
  845. $_user['lastName'] = stripslashes($values['lastname']);
  846. $_user['mail'] = $values['email'];
  847. $_user['language'] = $values['language'];
  848. $_user['user_id'] = $user_id;
  849. $userInfo = api_get_user_info($user_id);
  850. $_user['status'] = $userInfo['status'];
  851. $is_allowedCreateCourse = isset($values['status']) && $values['status'] == 1;
  852. $usersCanCreateCourse = api_is_allowed_to_create_course();
  853. Session::write('_user', $_user);
  854. Session::write('is_allowedCreateCourse', $is_allowedCreateCourse);
  855. // Stats
  856. Event::event_login($user_id);
  857. // last user login date is now
  858. $user_last_login_datetime = 0; // used as a unix timestamp it will correspond to : 1 1 1970
  859. Session::write('user_last_login_datetime', $user_last_login_datetime);
  860. $text_after_registration =
  861. '<p>'.
  862. get_lang('Dear', null, $_user['language']).' '.
  863. stripslashes(Security::remove_XSS($values['firstname'])).',<br /><br />'.
  864. get_lang('PersonalSettings',null,$_user['language'])."</p>";
  865. $form_data = array(
  866. 'button' => Display::button('next', get_lang('Next', null, $_user['language']), array('class' => 'btn btn-primary btn-large')),
  867. 'message' => null,
  868. 'action' => api_get_path(WEB_PATH).'user_portal.php'
  869. );
  870. if (api_get_setting('allow_terms_conditions') === 'true' && $user_already_registered_show_terms) {
  871. if (api_get_setting('load_term_conditions_section') === 'login') {
  872. $form_data['action'] = api_get_path(WEB_PATH).'user_portal.php';
  873. } else {
  874. $courseInfo = api_get_course_info();
  875. if (!empty($courseInfo)) {
  876. $form_data['action'] = $courseInfo['course_public_url'].'?id_session='.api_get_session_id();
  877. $cidReset = true;
  878. Session::erase('_course');
  879. Session::erase('_cid');
  880. } else {
  881. $form_data['action'] = api_get_path(WEB_PATH).'user_portal.php';
  882. }
  883. }
  884. } else {
  885. if (!empty($values['email'])) {
  886. $text_after_registration.= '<p>'.get_lang('MailHasBeenSent', null, $_user['language']).'</p>';
  887. $diagnosticPath = '<a href="'.api_get_path(WEB_PATH).'search.php">'.api_get_path(WEB_PATH).'search.php</a>';
  888. $text_after_registration.= '<p>'.sprintf(get_lang('WelcomePleaseGoToDiagnosticAtX', null, $_user['language']), $diagnosticPath).'</p>';
  889. }
  890. if ($is_allowedCreateCourse) {
  891. if ($usersCanCreateCourse) {
  892. $form_data['message'] = '<p>'. get_lang('NowGoCreateYourCourse', null, $_user['language']). "</p>";
  893. }
  894. $form_data['action'] = api_get_path(WEB_CODE_PATH).'create_course/add_course.php';
  895. if (api_get_setting('course_validation') === 'true') {
  896. $form_data['button'] = Display::button(
  897. 'next',
  898. get_lang('CreateCourseRequest', null, $_user['language']),
  899. array('class' => 'btn btn-primary btn-large')
  900. );
  901. } else {
  902. $form_data['button'] = Display::button(
  903. 'next',
  904. get_lang('CourseCreate', null, $_user['language']),
  905. array('class' => 'btn btn-primary btn-large')
  906. );
  907. $form_data['go_button'] = '&nbsp;&nbsp;<a href="'.api_get_path(WEB_PATH).'index.php'.'">'.
  908. Display::span(
  909. get_lang('Next', null, $_user['language']),
  910. array('class' => 'btn btn-primary btn-large')
  911. ).'</a>';
  912. }
  913. } else {
  914. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  915. $form_data['action'] = 'courses.php?action=subscribe';
  916. $form_data['message'] = '<p>'. get_lang('NowGoChooseYourCourses', null, $_user['language']). ".</p>";
  917. } else {
  918. $form_data['action'] = api_get_path(WEB_PATH).'user_portal.php';
  919. }
  920. $form_data['button'] = Display::button(
  921. 'next',
  922. get_lang('Next', null, $_user['language']),
  923. array('class' => 'btn btn-primary btn-large')
  924. );
  925. }
  926. }
  927. if ($sessionPremiumChecker && $sessionId) {
  928. header('Location:'.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/process.php?i='.$sessionId.'&t=2');
  929. Session::erase('SessionIsPremium');
  930. Session::erase('sessionId');
  931. exit;
  932. }
  933. SessionManager::redirectToSession();
  934. $redirectBuyCourse = Session::read('buy_course_redirect');
  935. if (!empty($redirectBuyCourse)) {
  936. $form_data['action'] = api_get_path(WEB_PATH).$redirectBuyCourse;
  937. Session::erase('buy_course_redirect');
  938. }
  939. $form_data = CourseManager::redirectToCourse($form_data);
  940. $form_register = new FormValidator('form_register', 'post', $form_data['action']);
  941. if (!empty($form_data['message'])) {
  942. $form_register->addElement('html', $form_data['message'].'<br /><br />');
  943. }
  944. if ($usersCanCreateCourse) {
  945. $form_register->addElement('html', $form_data['button']);
  946. } else {
  947. $form_register->addElement('html', $form_data['go_button']);
  948. }
  949. $text_after_registration .= $form_register->returnForm();
  950. // Just in case
  951. Session::erase('course_redirect');
  952. Session::erase('exercise_redirect');
  953. Session::erase('session_redirect');
  954. Session::erase('only_one_course_session_redirect');
  955. if (CustomPages::enabled()) {
  956. CustomPages::display(
  957. CustomPages::REGISTRATION_FEEDBACK,
  958. array('info' => $text_after_registration)
  959. );
  960. } else {
  961. $tpl = new Template($tool_name);
  962. $tpl->assign('inscription_content', $content);
  963. $tpl->assign('text_after_registration', $text_after_registration);
  964. $tpl->assign('hide_header', $hideHeaders);
  965. $inscription = $tpl->get_template('auth/inscription.tpl');
  966. $tpl->display($inscription);
  967. }
  968. } else {
  969. // Custom pages
  970. if (CustomPages::enabled()) {
  971. CustomPages::display(
  972. CustomPages::REGISTRATION, array('form' => $form)
  973. );
  974. } else {
  975. if (!api_is_anonymous()) {
  976. // Saving user to course if it was set.
  977. if (!empty($course_code_redirect)) {
  978. $course_info = api_get_course_info($course_code_redirect);
  979. if (!empty($course_info)) {
  980. if (in_array(
  981. $course_info['visibility'],
  982. array(
  983. COURSE_VISIBILITY_OPEN_PLATFORM,
  984. COURSE_VISIBILITY_OPEN_WORLD
  985. )
  986. )
  987. ) {
  988. CourseManager::subscribe_user(
  989. $user_id,
  990. $course_info['code']
  991. );
  992. }
  993. }
  994. }
  995. CourseManager::redirectToCourse([]);
  996. }
  997. $tpl = new Template($tool_name);
  998. if ($termActivated !== false) {
  999. $tpl->assign(
  1000. 'inscription_header',
  1001. Display::page_header($tool_name)
  1002. );
  1003. }
  1004. $tpl->assign('inscription_content', $content);
  1005. $tpl->assign('form', $form->returnForm());
  1006. $tpl->assign('hide_header', $hideHeaders);
  1007. $inscription = $tpl->get_template('auth/inscription.tpl');
  1008. $tpl->display($inscription);
  1009. }
  1010. }