inscription.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays a form for registering new users.
  5. * @package chamilo.auth
  6. */
  7. use \ChamiloSession as Session;
  8. use Symfony\Component\EventDispatcher\EventDispatcher,
  9. Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken,
  10. Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  11. $language_file = array('registration', 'admin');
  12. if (!empty($_POST['language'])) { //quick hack to adapt the registration form result to the selected registration language
  13. $_GET['language'] = $_POST['language'];
  14. }
  15. if (api_get_setting('allow_registration') === 'false') {
  16. api_not_allowed(true);
  17. }
  18. $htmlHeadXtra[] = api_get_password_checker_js('#username', '#pass1');
  19. if (!empty($_SESSION['user_language_choice'])) {
  20. $user_selected_language = $_SESSION['user_language_choice'];
  21. } elseif (!empty($_SESSION['_user']['language'])) {
  22. $user_selected_language = $_SESSION['_user']['language'];
  23. } else {
  24. $user_selected_language = api_get_setting('platformLanguage');
  25. }
  26. $form = new FormValidator('registration');
  27. if (api_get_setting('allow_terms_conditions') == 'true') {
  28. $user_already_registered_show_terms = isset($_SESSION['term_and_condition']['user_id']);
  29. } else {
  30. $user_already_registered_show_terms = false;
  31. }
  32. //Direct Link Subscription feature #5299
  33. $course_code_redirect = isset($_REQUEST['c']) && !empty($_REQUEST['c']) ? $_REQUEST['c'] : null;
  34. $exercise_redirect = isset($_REQUEST['e']) && !empty($_REQUEST['e']) ? $_REQUEST['e'] : null;
  35. if (!empty($course_code_redirect)) {
  36. Session::write('course_redirect', $course_code_redirect);
  37. Session::write('exercise_redirect', $exercise_redirect);
  38. }
  39. if ($user_already_registered_show_terms == false) {
  40. if (api_is_western_name_order()) {
  41. // FIRST NAME and LAST NAME
  42. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  43. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  44. } else {
  45. // LAST NAME and FIRST NAME
  46. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  47. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  48. }
  49. $form->applyFilter(array('lastname', 'firstname'), 'trim');
  50. $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
  51. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  52. // EMAIL
  53. $form->addElement('text', 'email', get_lang('Email'), array('size' => 40));
  54. if (api_get_setting('registration', 'email') == 'true') {
  55. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  56. }
  57. if (api_get_setting('login_is_email') == 'true') {
  58. $form->applyFilter('email','trim');
  59. if (api_get_setting('registration', 'email') != 'true') {
  60. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  61. }
  62. $form->addRule('email', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
  63. $form->addRule('email', get_lang('UserTaken'), 'username_available');
  64. }
  65. $form->addRule('email', get_lang('EmailWrong'), 'email');
  66. if (api_get_setting('openid_authentication') == 'true') {
  67. $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40));
  68. }
  69. $form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => 40));
  70. if (api_get_setting('registration', 'officialcode') == 'true') {
  71. $form->addRule('official_code', get_lang('ThisFieldIsRequired'), 'required');
  72. }
  73. // USERNAME
  74. if (api_get_setting('login_is_email') != 'true') {
  75. $form->addElement('text', 'username', get_lang('UserName'), array('size' => USERNAME_MAX_LENGTH));
  76. $form->applyFilter('username','trim');
  77. $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
  78. $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
  79. $form->addRule('username', get_lang('UsernameWrong'), 'username');
  80. $form->addRule('username', get_lang('UserTaken'), 'username_available');
  81. }
  82. // PASSWORD
  83. $form->addElement('password', 'pass1', get_lang('Password'), array('id' => 'pass1', 'size' => 20, 'autocomplete' => 'off'));
  84. global $_configuration;
  85. if (isset($_configuration['allow_strength_pass_checker']) && $_configuration['allow_strength_pass_checker']) {
  86. $form->addElement('label', null, '<div id="password_progress"></div>');
  87. }
  88. $form->addElement('password', 'pass2', get_lang('Confirmation'), array('id' => 'pass2', 'size' => 20, 'autocomplete' => 'off'));
  89. $form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required');
  90. $form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required');
  91. $form->addRule(array('pass1', 'pass2'), get_lang('PassTwo'), 'compare');
  92. if (CHECK_PASS_EASY_TO_FIND)
  93. $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password');
  94. // PHONE
  95. $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 20));
  96. if (api_get_setting('registration', 'phone') == 'true') {
  97. $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required');
  98. }
  99. // LANGUAGE
  100. if (api_get_setting('registration', 'language') == 'true') {
  101. $form->addElement('select_language', 'language', get_lang('Language'));
  102. }
  103. // STUDENT/TEACHER
  104. if (api_get_setting('allow_registration_as_teacher') != 'false') {
  105. $form->addElement('radio', 'status', get_lang('Profile'), get_lang('RegStudent'), STUDENT);
  106. $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER);
  107. }
  108. // EXTENDED FIELDS
  109. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true') {
  110. $form->add_html_editor('competences', get_lang('MyCompetences'), false, false, array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130'));
  111. }
  112. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true') {
  113. $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false, false, array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130'));
  114. }
  115. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'myteach') == 'true') {
  116. $form->add_html_editor('teach', get_lang('MyTeach'), false, false, array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130'));
  117. }
  118. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true') {
  119. $form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false, false, array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130'));
  120. }
  121. if (api_get_setting('extended_profile') == 'true') {
  122. if (api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true' && api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') == 'true') {
  123. $form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required');
  124. }
  125. if (api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true' && api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') == 'true') {
  126. $form->addRule('diplomas', get_lang('ThisFieldIsRequired'), 'required');
  127. }
  128. if (api_get_setting('extendedprofile_registration', 'myteach') == 'true' && api_get_setting('extendedprofile_registrationrequired', 'myteach') == 'true') {
  129. $form->addRule('teach', get_lang('ThisFieldIsRequired'), 'required');
  130. }
  131. if (api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true' && api_get_setting('extendedprofile_registrationrequired','mypersonalopenarea') == 'true') {
  132. $form->addRule('openarea', get_lang('ThisFieldIsRequired'), 'required');
  133. }
  134. }
  135. // EXTRA FIELDS
  136. $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true);
  137. $extraField = new ExtraField('user');
  138. $extraField->set_extra_fields_in_form($form, $extra_data, 'registration', false, null);
  139. }
  140. if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {
  141. $defaults['language'] = $_SESSION['user_language_choice'];
  142. } else {
  143. $defaults['language'] = api_get_setting('platformLanguage');
  144. }
  145. if (!empty($_GET['username'])) {
  146. $defaults['username'] = Security::remove_XSS($_GET['username']);
  147. }
  148. if (!empty($_GET['email'])) {
  149. $defaults['email'] = Security::remove_XSS($_GET['email']);
  150. }
  151. if (!empty($_GET['phone'])) {
  152. $defaults['phone'] = Security::remove_XSS($_GET['phone']);
  153. }
  154. if (api_get_setting('openid_authentication') == 'true' && !empty($_GET['openid'])) {
  155. $defaults['openid'] = Security::remove_XSS($_GET['openid']);
  156. }
  157. $defaults['status'] = STUDENT;
  158. if (is_array($extra_data)) {
  159. $defaults = array_merge($defaults, $extra_data);
  160. }
  161. $form->setDefaults($defaults);
  162. $content = null;
  163. if (!CustomPages::enabled()) {
  164. // Load terms & conditions from the current lang
  165. if (api_get_setting('allow_terms_conditions') == 'true') {
  166. $get = array_keys($_GET);
  167. if (isset($get)) {
  168. if ($get[0] == 'legal') {
  169. $language = api_get_interface_language();
  170. $language = api_get_language_id($language);
  171. $term_preview = LegalManager::get_last_condition($language);
  172. if (!$term_preview) {
  173. //look for the default language
  174. $language = api_get_setting('platformLanguage');
  175. $language = api_get_language_id($language);
  176. $term_preview = LegalManager::get_last_condition($language);
  177. }
  178. $tool_name = get_lang('TermsAndConditions');
  179. Display :: display_header($tool_name);
  180. if (!empty($term_preview['content'])) {
  181. echo $term_preview['content'];
  182. } else {
  183. echo get_lang('ComingSoon');
  184. }
  185. Display :: display_footer();
  186. exit;
  187. }
  188. }
  189. }
  190. $tool_name = get_lang('Registration');
  191. if (api_get_setting('allow_terms_conditions') == 'true' && $user_already_registered_show_terms) {
  192. $tool_name = get_lang('TermsAndConditions');
  193. }
  194. $home = api_get_path(SYS_PATH).'home/';
  195. if (api_is_multiple_url_enabled()) {
  196. $access_url_id = api_get_current_access_url_id();
  197. if ($access_url_id != -1) {
  198. $url_info = api_get_access_url($access_url_id);
  199. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  200. $clean_url = api_replace_dangerous_char($url);
  201. $clean_url = str_replace('/', '-', $clean_url);
  202. $clean_url .= '/';
  203. $home_old = api_get_path(SYS_PATH).'home/';
  204. $home = api_get_path(SYS_PATH).'home/'.$clean_url;
  205. }
  206. }
  207. if (file_exists($home.'register_top_'.$user_selected_language.'.html')) {
  208. $home_top_temp = @(string)file_get_contents($home.'register_top_'.$user_selected_language.'.html');
  209. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  210. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  211. if (!empty($open)) {
  212. $content = '<div class="well_border">'.$open.'</div>';
  213. }
  214. }
  215. // Forbidden to self-register
  216. if (api_get_setting('allow_registration') == 'false') {
  217. api_not_allowed(true);
  218. }
  219. if (api_get_setting('allow_registration') == 'approval') {
  220. $content .= Display::return_message(get_lang('YourAccountHasToBeApproved'));
  221. }
  222. //if openid was not found
  223. if (!empty($_GET['openid_msg']) && $_GET['openid_msg'] == 'idnotfound') {
  224. $content .= Display::return_message(get_lang('OpenIDCouldNotBeFoundPleaseRegister'));
  225. }
  226. }
  227. // Terms and conditions
  228. if (api_get_setting('allow_terms_conditions') == 'true') {
  229. $language = api_get_interface_language();
  230. $language = api_get_language_id($language);
  231. $term_preview = LegalManager::get_last_condition($language);
  232. if (!$term_preview) {
  233. //we load from the platform
  234. $language = api_get_setting('platformLanguage');
  235. $language = api_get_language_id($language);
  236. $term_preview = LegalManager::get_last_condition($language);
  237. //if is false we load from english
  238. if (!$term_preview) {
  239. $language = api_get_language_id('english'); //this must work
  240. $term_preview = LegalManager::get_last_condition($language);
  241. }
  242. }
  243. // Version and language
  244. $form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']);
  245. $form->addElement('hidden', 'legal_info', $term_preview['legal_id'].':'.$term_preview['language_id']);
  246. if ($term_preview['type'] == 1) {
  247. $form->addElement('checkbox', 'legal_accept', null, get_lang('IHaveReadAndAgree').'&nbsp;<a href="inscription.php?legal" target="_blank">'.get_lang('TermsAndConditions').'</a>');
  248. $form->addRule('legal_accept', get_lang('ThisFieldIsRequired'), 'required');
  249. } else {
  250. $preview = LegalManager::show_last_condition($term_preview);
  251. $form->addElement('label', null, $preview);
  252. }
  253. }
  254. $form->addElement('button', 'submit', get_lang('RegisterUser'), array('class' => 'btn btn-primary btn-large'));
  255. if ($form->validate()) {
  256. $values = $form->exportValues();
  257. $values['username'] = api_substr($values['username'], 0, USERNAME_MAX_LENGTH); //make *sure* the login isn't too long
  258. if (api_get_setting('allow_registration_as_teacher') == 'false') {
  259. $values['status'] = STUDENT;
  260. }
  261. // Added by Ivan Tcholakov, 06-MAR-2008.
  262. if (empty($values['official_code'])) {
  263. $values['official_code'] = api_strtoupper($values['username']);
  264. }
  265. if (api_get_setting('login_is_email') == 'true') {
  266. $values['username'] = $values['email'];
  267. }
  268. if ($user_already_registered_show_terms && api_get_setting('allow_terms_conditions') == 'true') {
  269. $user_id = $_SESSION['term_and_condition']['user_id'];
  270. $is_admin = UserManager::is_admin($user_id);
  271. Session::write('is_platformAdmin', $is_admin);
  272. } else {
  273. // Creates a new user
  274. $user_id = UserManager::create_user(
  275. $values['firstname'],
  276. $values['lastname'],
  277. $values['status'],
  278. $values['email'],
  279. $values['username'],
  280. $values['pass1'],
  281. $values['official_code'],
  282. $values['language'],
  283. $values['phone'],
  284. null,
  285. PLATFORM_AUTH_SOURCE,
  286. null,
  287. 1,
  288. 0,
  289. null,
  290. null,
  291. true
  292. );
  293. // Register extra fields
  294. $extras = array();
  295. foreach ($values as $key => $value) {
  296. if (substr($key, 0, 6) == 'extra_') { //an extra field
  297. $extras[substr($key, 6)] = $value;
  298. }
  299. }
  300. //update the extra fields
  301. $count_extra_field = count($extras);
  302. if ($count_extra_field > 0) {
  303. foreach ($extras as $key => $value) {
  304. UserManager::update_extra_field_value($user_id, $key, $value);
  305. }
  306. }
  307. if ($user_id) {
  308. // storing the extended profile
  309. $store_extended = false;
  310. $sql = "UPDATE ".Database::get_main_table(TABLE_MAIN_USER)." SET ";
  311. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true') {
  312. $sql_set[] = "competences = '".Database::escape_string($values['competences'])."'";
  313. $store_extended = true;
  314. }
  315. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true') {
  316. $sql_set[] = "diplomas = '".Database::escape_string($values['diplomas'])."'";
  317. $store_extended = true;
  318. }
  319. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'myteach') == 'true') {
  320. $sql_set[] = "teach = '".Database::escape_string($values['teach'])."'";
  321. $store_extended = true;
  322. }
  323. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true') {
  324. $sql_set[] = "openarea = '".Database::escape_string($values['openarea'])."'";
  325. $store_extended = true;
  326. }
  327. if ($store_extended) {
  328. $sql .= implode(',', $sql_set);
  329. $sql .= " WHERE user_id = '".Database::escape_string($user_id)."'";
  330. Database::query($sql);
  331. }
  332. // if there is a default duration of a valid account then we have to change the expiration_date accordingly
  333. if (api_get_setting('account_valid_duration') != '') {
  334. $sql = "UPDATE ".Database::get_main_table(TABLE_MAIN_USER)." SET expiration_date='registration_date+1' WHERE user_id='".$user_id."'";
  335. Database::query($sql);
  336. }
  337. // if the account has to be approved then we set the account to inactive, sent a mail to the platform admin and exit the page.
  338. if (api_get_setting('allow_registration') == 'approval') {
  339. $TABLE_USER = Database::get_main_table(TABLE_MAIN_USER);
  340. // 1. set account inactive
  341. $sql = "UPDATE ".$TABLE_USER." SET active='0' WHERE user_id='".$user_id."'";
  342. Database::query($sql);
  343. // 2. Send mail to all platform admin
  344. $emailsubject = get_lang('ApprovalForNewAccount',null,$values['language']).': '.$values['username'];
  345. $emailbody = get_lang('ApprovalForNewAccount',null,$values['language'])."\n";
  346. $emailbody .= get_lang('UserName',null, $values['language']).': '.$values['username']."\n";
  347. if (api_is_western_name_order()) {
  348. $emailbody .= get_lang('FirstName',null, $values['language']).': '.$values['firstname']."\n";
  349. $emailbody .= get_lang('LastName',null, $values['language']).': '.$values['lastname']."\n";
  350. } else {
  351. $emailbody .= get_lang('LastName',null, $values['language']).': '.$values['lastname']."\n";
  352. $emailbody .= get_lang('FirstName',null, $values['language']).': '.$values['firstname']."\n";
  353. }
  354. $emailbody .= get_lang('Email',null, $values['language']).': '.$values['email']."\n";
  355. $emailbody .= get_lang('Status',null, $values['language']).': '.$values['status']."\n\n";
  356. $url_edit = Display::url(api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id, api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id);
  357. $emailbody .= get_lang('ManageUser',null, $values['language']).": $url_edit";
  358. $admins = UserManager::get_all_administrators();
  359. foreach ($admins as $admin_info) {
  360. MessageManager::send_message($admin_info['user_id'], $emailsubject, $emailbody, null, null, null, null, null, null, $user_id);
  361. }
  362. // 3. exit the page
  363. unset($user_id);
  364. Display :: display_header($tool_name);
  365. echo Display::page_header($tool_name);
  366. echo $content;
  367. Display::display_footer();
  368. exit;
  369. }
  370. }
  371. }
  372. // Terms & Conditions
  373. if (api_get_setting('allow_terms_conditions') == 'true') {
  374. // update the terms & conditions
  375. if (isset($values['legal_accept_type'])) {
  376. $cond_array = explode(':', $values['legal_accept_type']);
  377. if (!empty($cond_array[0]) && !empty($cond_array[1])) {
  378. $time = time();
  379. $condition_to_save = intval($cond_array[0]).':'.intval($cond_array[1]).':'.$time;
  380. UserManager::update_extra_field_value($user_id, 'legal_accept', $condition_to_save);
  381. }
  382. }
  383. $values = api_get_user_info($user_id);
  384. }
  385. // Symfony way to login as a user
  386. $user = $app['orm.em']->getRepository('Entity\User')->find($user_id);
  387. // Here, "secured" is the name of the firewall in your security.yml
  388. $token = new UsernamePasswordToken($user, $user->getPassword(), 'secured', $user->getRoles());
  389. $app['security']->setToken($token);
  390. $request = $app['request'];
  391. // Fire the login event
  392. // Logging the user in above the way we do it doesn't do this automatically
  393. $event = new InteractiveLoginEvent($request, $token);
  394. $app['dispatcher']->dispatch("security.interactive_login", $event);
  395. $recipient_name = api_get_person_name($values['firstname'], $values['lastname']);
  396. $text_after_registration = '<p>'.get_lang('Dear', null, $_user['language']).' '.stripslashes(Security::remove_XSS($recipient_name)).',<br /><br />'.get_lang('PersonalSettings',null,$_user['language']).".</p>";
  397. $form_data = array( 'button' => Display::button('next', get_lang('Next', null, $_user['language']), array('class' => 'btn btn-primary btn-large')),
  398. 'message' => null,
  399. 'action' => api_get_path(WEB_PATH).'user_portal.php');
  400. if (api_get_setting('allow_terms_conditions') == 'true' && $user_already_registered_show_terms) {
  401. $form_data['action'] = api_get_path(WEB_PATH).'user_portal.php';
  402. } else {
  403. if (!empty ($values['email'])) {
  404. $text_after_registration.= '<p>'.get_lang('MailHasBeenSent',null,$_user['language']).'.</p>';
  405. }
  406. if (api_is_allowed_to_create_course()) {
  407. $form_data['message'] = '<p>'. get_lang('NowGoCreateYourCourse',null,$_user['language']). "</p>";
  408. $form_data['action'] = '../create_course/add_course.php';
  409. if (api_get_setting('course_validation') == 'true') {
  410. $form_data['button'] = Display::button('next', get_lang('CreateCourseRequest', null, $_user['language']), array('class' => 'btn btn-primary btn-large'));
  411. } else {
  412. $form_data['button'] = Display::button('next', get_lang('CourseCreate', null, $_user['language']), array('class' => 'btn btn-primary btn-large'));
  413. }
  414. } else {
  415. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  416. $form_data['action'] = 'courses.php?action=subscribe';
  417. $form_data['message'] = '<p>'. get_lang('NowGoChooseYourCourses',null,$_user['language']). ".</p>";
  418. } else {
  419. $form_data['action'] = api_get_path(WEB_PATH).'user_portal.php';
  420. }
  421. $form_data['button'] = Display::button('next', get_lang('Next', null, $_user['language']), array('class' => 'btn btn-primary btn-large'));
  422. }
  423. }
  424. /*
  425. * Direct course link see #5299
  426. *
  427. * You can send to your students an URL like this
  428. * http://chamilodev.beeznest.com/main/auth/inscription.php?c=ABC&e=3
  429. * Where "c" is the course code and "e" is the exercise Id, after a succesfull registration the user will be sent to the course or exercise
  430. *
  431. */
  432. $course_code_redirect = Session::read('course_redirect');
  433. if (!empty($course_code_redirect)) {
  434. $course_info = api_get_course_info($course_code_redirect);
  435. if (!empty($course_info)) {
  436. if (in_array($course_info['visibility'], array(COURSE_VISIBILITY_OPEN_PLATFORM, COURSE_VISIBILITY_OPEN_WORLD))) {
  437. $user_id = api_get_user_id();
  438. if (CourseManager::subscribe_user($user_id, $course_info['code'])) {
  439. $form_data['action'] = $course_info['course_public_url'];
  440. $form_data['message'] = sprintf(get_lang('YouHaveBeenRegisteredToCourseX'), $course_info['title']);
  441. $form_data['button'] = Display::button('next', get_lang('GoToCourse', null, $_user['language']), array('class' => 'btn btn-primary btn-large'));
  442. $exercise_redirect = intval(Session::read('exercise_redirect'));
  443. if (!empty($exercise_redirect)) {
  444. $form_data['action'] = api_get_path(WEB_CODE_PATH).'exercice/overview.php?exerciseId='.intval($exercise_redirect).'&cidReq='.$course_info['code'];
  445. $form_data['message'] .= '<br />'.get_lang('YouCanAccessTheExercise');
  446. $form_data['button'] = Display::button('next', get_lang('Go', null, $_user['language']), array('class' => 'btn btn-primary btn-large'));
  447. }
  448. if (!empty($form_data['action'])) {
  449. header('Location: '.$form_data['action']);
  450. exit;
  451. }
  452. }
  453. }
  454. }
  455. }
  456. $form_register = new FormValidator('form_register', 'post', $form_data['action']);
  457. if (!empty($form_data['message'])) {
  458. $form_register->addElement('html', $form_data['message'].'<br /><br />');
  459. }
  460. $form_register->addElement('html', $form_data['button']);
  461. $text_after_registration .= $form_register->return_form();
  462. //Just in case
  463. Session::erase('course_redirect');
  464. Session::erase('exercise_redirect');
  465. Display :: display_header($tool_name);
  466. echo Display::page_header($tool_name);
  467. echo $content;
  468. echo $text_after_registration;
  469. if (CustomPages::enabled()) {
  470. CustomPages::display(CustomPages::REGISTRATION_FEEDBACK, array('info' => $text_after_registration));
  471. }
  472. } else {
  473. Display :: display_header($tool_name);
  474. echo Display::page_header($tool_name);
  475. echo $content;
  476. // Custom pages
  477. if (CustomPages::enabled()) {
  478. CustomPages::display(CustomPages::REGISTRATION, array('form' => $form));
  479. } else {
  480. $form->display();
  481. }
  482. }
  483. Display :: display_footer();