configure_inscription.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * This script displays a form for registering new users.
  6. *
  7. * @package chamilo.admin
  8. */
  9. $cidReset = true;
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. api_protect_admin_script();
  12. // Load terms & conditions from the current lang
  13. if (api_get_setting('allow_terms_conditions') === 'true') {
  14. $get = array_keys($_GET);
  15. if (isset($get)) {
  16. if (isset($get[0]) && $get[0] == 'legal') {
  17. $language = api_get_interface_language();
  18. $language = api_get_language_id($language);
  19. $term_preview = LegalManager::get_last_condition($language);
  20. if (!$term_preview) {
  21. //look for the default language
  22. $language = api_get_setting('platformLanguage');
  23. $language = api_get_language_id($language);
  24. $term_preview = LegalManager::get_last_condition($language);
  25. }
  26. $tool_name = get_lang('Terms and Conditions');
  27. Display :: display_header('');
  28. echo '<div class="actions-title">';
  29. echo $tool_name;
  30. echo '</div>';
  31. if (!empty($term_preview['content'])) {
  32. echo $term_preview['content'];
  33. } else {
  34. echo get_lang('Coming soon...');
  35. }
  36. Display :: display_footer();
  37. exit;
  38. }
  39. }
  40. }
  41. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
  42. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
  43. $tool_name = get_lang('Setting the registration page');
  44. if (!empty($action)) {
  45. $interbreadcrumb[] = ['url' => 'configure_inscription.php', 'name' => get_lang('Setting the registration page')];
  46. switch ($action) {
  47. case 'edit_top':
  48. $tool_name = get_lang('Edit Note');
  49. break;
  50. }
  51. }
  52. $lang = ''; //el for "Edit Language"
  53. if (!empty($_SESSION['user_language_choice'])) {
  54. $lang = $_SESSION['user_language_choice'];
  55. } elseif (!empty($_SESSION['_user']['language'])) {
  56. $lang = $_SESSION['_user']['language'];
  57. } else {
  58. $lang = api_get_setting('platformLanguage');
  59. }
  60. // ----- Ensuring availability of main files in the corresponding language -----
  61. /*if (api_is_multiple_url_enabled()) {
  62. $access_url_id = api_get_current_access_url_id();
  63. if ($access_url_id != -1) {
  64. $url_info = api_get_access_url($access_url_id);
  65. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  66. $clean_url = api_replace_dangerous_char($url);
  67. $clean_url = str_replace('/', '-', $clean_url);
  68. $clean_url .= '/';
  69. $homep = api_get_path(SYS_APP_PATH).'home/'; //homep for Home Path
  70. $homep_new = api_get_path(SYS_APP_PATH).'home/'.$clean_url; //homep for Home Path added the url
  71. $new_url_dir = api_get_path(SYS_APP_PATH).'home/'.$clean_url;
  72. //we create the new dir for the new sites
  73. if (!is_dir($new_url_dir)) {
  74. mkdir($new_url_dir, api_get_permissions_for_new_directories());
  75. }
  76. }
  77. } else {
  78. $homep_new = '';
  79. $homep = api_get_path(SYS_APP_PATH).'home/'; //homep for Home Path
  80. }
  81. $topf = 'register_top'; //topf for Top File
  82. $ext = '.html'; //ext for HTML Extension - when used frequently, variables are
  83. $homef = [$topf];
  84. // If language-specific file does not exist, create it by copying default file
  85. foreach ($homef as $my_file) {
  86. if (api_is_multiple_url_enabled()) {
  87. if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) {
  88. copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext);
  89. }
  90. } else {
  91. if (!file_exists($homep.$my_file.'_'.$lang.$ext)) {
  92. copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext);
  93. }
  94. }
  95. }
  96. if (!empty($homep_new)) {
  97. $homep = $homep_new;
  98. }
  99. if (!empty($action)) {
  100. if (isset($_POST['formSent'])) {
  101. switch ($action) {
  102. case 'edit_top':
  103. // Filter
  104. $home_top = trim(stripslashes($_POST['register_top']));
  105. // Write
  106. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  107. if (is_writable($homep.$topf.'_'.$lang.$ext)) {
  108. $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
  109. fputs($fp, $home_top);
  110. fclose($fp);
  111. } else {
  112. $errorMsg = get_lang('Homepage-files are not writable!');
  113. }
  114. } else {
  115. //File does not exist
  116. $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
  117. fputs($fp, $home_top);
  118. fclose($fp);
  119. }
  120. break;
  121. }
  122. if (empty($errorMsg)) {
  123. header('Location: '.api_get_self());
  124. exit();
  125. }
  126. } else {
  127. switch ($action) {
  128. case 'edit_top':
  129. // This request is only the preparation for the update of the home_top
  130. $home_top = '';
  131. if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
  132. $home_top = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
  133. } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
  134. $home_top = @(string) file_get_contents($homep.$topf.$lang.$ext);
  135. } else {
  136. $errorMsg = get_lang('Homepage files are not readable');
  137. }
  138. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  139. break;
  140. }
  141. }
  142. }*/
  143. $form = new FormValidator('registration');
  144. if (api_get_setting('allow_terms_conditions') === 'true') {
  145. $display_all_form = !isset($_SESSION['update_term_and_condition']['user_id']);
  146. } else {
  147. $display_all_form = true;
  148. }
  149. if ($display_all_form) {
  150. if (api_is_western_name_order()) {
  151. // FIRST NAME and LAST NAME
  152. $form->addElement('text', 'firstname', get_lang('First name'), ['size' => 40, 'disabled' => 'disabled']);
  153. $form->addElement('text', 'lastname', get_lang('Last name'), ['size' => 40, 'disabled' => 'disabled']);
  154. } else {
  155. // LAST NAME and FIRST NAME
  156. $form->addElement('text', 'lastname', get_lang('Last name'), ['size' => 40, 'disabled' => 'disabled']);
  157. $form->addElement('text', 'firstname', get_lang('First name'), ['size' => 40, 'disabled' => 'disabled']);
  158. }
  159. $form->applyFilter('firstname', 'trim');
  160. $form->applyFilter('lastname', 'trim');
  161. $form->addRule('lastname', get_lang('Required field'), 'required');
  162. $form->addRule('firstname', get_lang('Required field'), 'required');
  163. // EMAIL
  164. $form->addElement('text', 'email', get_lang('e-mail'), ['size' => 40, 'disabled' => 'disabled']);
  165. if (api_get_setting('registration', 'email') == 'true') {
  166. $form->addRule('email', get_lang('Required field'), 'required');
  167. }
  168. $form->addRule('email', get_lang('e-mailWrong'), 'email');
  169. // USERNAME
  170. $form->addElement('text', 'username', get_lang('Username'), ['size' => USERNAME_MAX_LENGTH, 'disabled' => 'disabled']);
  171. $form->addRule('username', get_lang('Required field'), 'required');
  172. $form->addRule('username', get_lang('Your login can only contain letters, numbers and _.-'), 'username');
  173. $form->addRule('username', get_lang('This login is already in use'), 'username_available');
  174. $form->addRule('username', sprintf(get_lang('The login needs to be maximum %s characters long'), (string) USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
  175. // PASSWORD
  176. $form->addElement('password', 'pass1', get_lang('Pass'), ['size' => 40, 'disabled' => 'disabled']);
  177. $form->addElement('password', 'pass2', get_lang('Confirm password'), ['size' => 40, 'disabled' => 'disabled']);
  178. $form->addRule('pass1', get_lang('Required field'), 'required');
  179. $form->addRule('pass2', get_lang('Required field'), 'required');
  180. $form->addRule(['pass1', 'pass2'], get_lang('You have typed two different passwords'), 'compare');
  181. $form->addPasswordRule('pass1');
  182. // PHONE
  183. $form->addElement('text', 'phone', get_lang('Phone'), ['size' => 40, 'disabled' => 'disabled']);
  184. if (api_get_setting('registration', 'phone') == 'true') {
  185. $form->addRule('phone', get_lang('Required field'), 'required');
  186. }
  187. // LANGUAGE
  188. if (api_get_setting('registration', 'language') == 'true') {
  189. $form->addSelectLanguage(
  190. 'language',
  191. get_lang('Language'),
  192. '',
  193. ['disabled' => 'disabled']
  194. );
  195. }
  196. // STUDENT/TEACHER
  197. if (api_get_setting('allow_registration_as_teacher') != 'false') {
  198. $form->addElement('radio', 'status', get_lang('Status'), get_lang('Student (follows courses)'), STUDENT, ['disabled' => 'disabled']);
  199. $form->addElement('radio', 'status', null, get_lang('Teacher (creates courses)'), COURSEMANAGER, ['disabled' => 'disabled']);
  200. }
  201. // EXTENDED FIELDS
  202. if (api_get_setting('extended_profile') == 'true' &&
  203. api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true'
  204. ) {
  205. $form->addHtmlEditor('competences', get_lang('My competences'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']);
  206. }
  207. if (api_get_setting('extended_profile') == 'true' &&
  208. api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true'
  209. ) {
  210. $form->addHtmlEditor('diplomas', get_lang('My diplomas'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']);
  211. }
  212. if (api_get_setting('extended_profile') == 'true' &&
  213. api_get_setting('extendedprofile_registration', 'myteach') == 'true'
  214. ) {
  215. $form->addHtmlEditor('teach', get_lang('What I am able to teach'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']);
  216. }
  217. if (api_get_setting('extended_profile') == 'true' &&
  218. api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true'
  219. ) {
  220. $form->addHtmlEditor('openarea', get_lang('My personal open area'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']);
  221. }
  222. if (api_get_setting('extended_profile') == 'true') {
  223. if (api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') == 'true') {
  224. $form->addRule('competences', get_lang('Required field'), 'required');
  225. }
  226. if (api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') == 'true') {
  227. $form->addRule('diplomas', get_lang('Required field'), 'required');
  228. }
  229. if (api_get_setting('extendedprofile_registrationrequired', 'myteach') == 'true') {
  230. $form->addRule('teach', get_lang('Required field'), 'required');
  231. }
  232. if (api_get_setting('extendedprofile_registrationrequired', 'mypersonalopenarea') == 'true') {
  233. $form->addRule('openarea', get_lang('Required field'), 'required');
  234. }
  235. }
  236. $extraField = new ExtraField('user');
  237. $extraField->addElements($form);
  238. }
  239. // Terms and conditions
  240. if (api_get_setting('allow_terms_conditions') == 'true') {
  241. $language = api_get_interface_language();
  242. $language = api_get_language_id($language);
  243. $term_preview = LegalManager::get_last_condition($language);
  244. if (!$term_preview) {
  245. //we load from the platform
  246. $language = api_get_setting('platformLanguage');
  247. $language = api_get_language_id($language);
  248. $term_preview = LegalManager::get_last_condition($language);
  249. //if is false we load from english
  250. if (!$term_preview) {
  251. $language = api_get_language_id('english'); //this must work
  252. $term_preview = LegalManager::get_last_condition($language);
  253. }
  254. }
  255. // Version and language //password
  256. $form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']);
  257. $form->addElement('hidden', 'legal_info', $term_preview['id'].':'.$term_preview['language_id']);
  258. if ($term_preview['type'] == 1) {
  259. $form->addElement(
  260. 'checkbox',
  261. 'legal_accept',
  262. null,
  263. get_lang('I have read and agree to the').'&nbsp;<a href="inscription.php?legal" target="_blank">'.get_lang('Terms and Conditions').'</a>'
  264. );
  265. $form->addRule('legal_accept', get_lang('Required field'), 'required');
  266. } else {
  267. if (!empty($term_preview['content'])) {
  268. $preview = LegalManager::show_last_condition($term_preview);
  269. $form->addElement('label', get_lang('Terms and Conditions'), $preview);
  270. }
  271. }
  272. }
  273. $form->addButtonSave(get_lang('Register'));
  274. $defaults['status'] = STUDENT;
  275. if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {
  276. $defaults['language'] = $_SESSION['user_language_choice'];
  277. } else {
  278. $defaults['language'] = api_get_setting('platformLanguage');
  279. }
  280. if (!empty($_GET['username'])) {
  281. $defaults['username'] = Security::remove_XSS($_GET['username']);
  282. }
  283. if (!empty($_GET['email'])) {
  284. $defaults['email'] = Security::remove_XSS($_GET['email']);
  285. }
  286. if (!empty($_GET['phone'])) {
  287. $defaults['phone'] = Security::remove_XSS($_GET['phone']);
  288. }
  289. $form->setDefaults($defaults);
  290. $tpl = new Template();
  291. $content = Display::page_header($tool_name);
  292. // The following security condition has been removed, because it makes no sense here. See Bug #1846.
  293. //// Forbidden to self-register
  294. //if (api_get_setting('allow_registration') == 'false') {
  295. // api_not_allowed();
  296. //}
  297. //api_display_tool_title($tool_name);
  298. if (api_get_setting('allow_registration') == 'approval') {
  299. $content .= Display::return_message(get_lang('Your account has to be approved'), 'normal');
  300. }
  301. $url = api_get_path(WEB_PUBLIC_PATH).'internal_page/edit/inscription';
  302. //Form of language
  303. //$content .= api_display_language_form();
  304. $content .= '&nbsp;&nbsp;<a href="'.api_get_self().'?action=edit_top">'.
  305. Display::return_icon('edit.gif', get_lang('Edit')).'</a>
  306. <a href="'.$url.'">'.get_lang('Edit notice').'</a>';
  307. $content .= $form->returnForm();
  308. $page = Container::getPage('inscription');
  309. $tpl->assign('page', $page);
  310. $tpl->assign('form', $content);
  311. $templateName = $tpl->get_template('auth/inscription_edit.html.twig');
  312. $tpl->display($templateName);