configure_inscription.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays a form for registering new users.
  5. *
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_protect_admin_script();
  11. // Load terms & conditions from the current lang
  12. if (api_get_setting('allow_terms_conditions') === 'true') {
  13. $get = array_keys($_GET);
  14. if (isset($get)) {
  15. if (isset($get[0]) && $get[0] == 'legal') {
  16. $language = api_get_interface_language();
  17. $language = api_get_language_id($language);
  18. $term_preview = LegalManager::get_last_condition($language);
  19. if (!$term_preview) {
  20. //look for the default language
  21. $language = api_get_setting('platformLanguage');
  22. $language = api_get_language_id($language);
  23. $term_preview = LegalManager::get_last_condition($language);
  24. }
  25. $tool_name = get_lang('TermsAndConditions');
  26. Display :: display_header('');
  27. echo '<div class="actions-title">';
  28. echo $tool_name;
  29. echo '</div>';
  30. if (!empty($term_preview['content'])) {
  31. echo $term_preview['content'];
  32. } else {
  33. echo get_lang('ComingSoon');
  34. }
  35. Display :: display_footer();
  36. exit;
  37. }
  38. }
  39. }
  40. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
  41. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  42. $tool_name = get_lang('ConfigureInscription');
  43. if (!empty($action)) {
  44. $interbreadcrumb[] = ['url' => 'configure_inscription.php', 'name' => get_lang('ConfigureInscription')];
  45. switch ($action) {
  46. case 'edit_top':
  47. $tool_name = get_lang('EditTopRegister');
  48. break;
  49. }
  50. }
  51. $lang = ''; //el for "Edit Language"
  52. if (!empty($_SESSION['user_language_choice'])) {
  53. $lang = $_SESSION['user_language_choice'];
  54. } elseif (!empty($_SESSION['_user']['language'])) {
  55. $lang = $_SESSION['_user']['language'];
  56. } else {
  57. $lang = api_get_setting('platformLanguage');
  58. }
  59. // ----- Ensuring availability of main files in the corresponding language -----
  60. if (api_is_multiple_url_enabled()) {
  61. $access_url_id = api_get_current_access_url_id();
  62. if ($access_url_id != -1) {
  63. $url_info = api_get_access_url($access_url_id);
  64. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  65. $clean_url = api_replace_dangerous_char($url);
  66. $clean_url = str_replace('/', '-', $clean_url);
  67. $clean_url .= '/';
  68. $homep = api_get_path(SYS_APP_PATH).'home/'; //homep for Home Path
  69. $homep_new = api_get_path(SYS_APP_PATH).'home/'.$clean_url; //homep for Home Path added the url
  70. $new_url_dir = api_get_path(SYS_APP_PATH).'home/'.$clean_url;
  71. //we create the new dir for the new sites
  72. if (!is_dir($new_url_dir)) {
  73. mkdir($new_url_dir, api_get_permissions_for_new_directories());
  74. }
  75. }
  76. } else {
  77. $homep_new = '';
  78. $homep = api_get_path(SYS_APP_PATH).'home/'; //homep for Home Path
  79. }
  80. $topf = 'register_top'; //topf for Top File
  81. $ext = '.html'; //ext for HTML Extension - when used frequently, variables are
  82. $homef = [$topf];
  83. // If language-specific file does not exist, create it by copying default file
  84. foreach ($homef as $my_file) {
  85. if (api_is_multiple_url_enabled()) {
  86. if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) {
  87. copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext);
  88. }
  89. } else {
  90. if (!file_exists($homep.$my_file.'_'.$lang.$ext)) {
  91. copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext);
  92. }
  93. }
  94. }
  95. if (!empty($homep_new)) {
  96. $homep = $homep_new;
  97. }
  98. if (!empty($action)) {
  99. if (isset($_POST['formSent'])) {
  100. switch ($action) {
  101. case 'edit_top':
  102. // Filter
  103. $home_top = trim(stripslashes($_POST['register_top']));
  104. // Write
  105. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  106. if (is_writable($homep.$topf.'_'.$lang.$ext)) {
  107. $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
  108. fputs($fp, $home_top);
  109. fclose($fp);
  110. } else {
  111. $errorMsg = get_lang('HomePageFilesNotWritable');
  112. }
  113. } else {
  114. //File does not exist
  115. $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
  116. fputs($fp, $home_top);
  117. fclose($fp);
  118. }
  119. break;
  120. }
  121. if (empty($errorMsg)) {
  122. header('Location: '.api_get_self());
  123. exit();
  124. }
  125. } else {
  126. switch ($action) {
  127. case 'edit_top':
  128. // This request is only the preparation for the update of the home_top
  129. $home_top = '';
  130. if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
  131. $home_top = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
  132. } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
  133. $home_top = @(string) file_get_contents($homep.$topf.$lang.$ext);
  134. } else {
  135. $errorMsg = get_lang('HomePageFilesNotReadable');
  136. }
  137. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  138. break;
  139. }
  140. }
  141. }
  142. Display :: display_header($tool_name);
  143. echo Display::page_header($tool_name);
  144. // The following security condition has been removed, because it makes no sense here. See Bug #1846.
  145. //// Forbidden to self-register
  146. //if (api_get_setting('allow_registration') == 'false') {
  147. // api_not_allowed();
  148. //}
  149. //api_display_tool_title($tool_name);
  150. if (api_get_setting('allow_registration') == 'approval') {
  151. echo Display::return_message(get_lang('YourAccountHasToBeApproved'), 'normal');
  152. }
  153. //if openid was not found
  154. if (!empty($_GET['openid_msg']) && $_GET['openid_msg'] == 'idnotfound') {
  155. echo Display::return_message(get_lang('OpenIDCouldNotBeFoundPleaseRegister'), 'warning');
  156. }
  157. $form = new FormValidator('registration');
  158. if (api_get_setting('allow_terms_conditions') === 'true') {
  159. $display_all_form = !isset($_SESSION['update_term_and_condition']['user_id']);
  160. } else {
  161. $display_all_form = true;
  162. }
  163. if ($display_all_form) {
  164. if (api_is_western_name_order()) {
  165. // FIRST NAME and LAST NAME
  166. $form->addElement('text', 'firstname', get_lang('FirstName'), ['size' => 40, 'disabled' => 'disabled']);
  167. $form->addElement('text', 'lastname', get_lang('LastName'), ['size' => 40, 'disabled' => 'disabled']);
  168. } else {
  169. // LAST NAME and FIRST NAME
  170. $form->addElement('text', 'lastname', get_lang('LastName'), ['size' => 40, 'disabled' => 'disabled']);
  171. $form->addElement('text', 'firstname', get_lang('FirstName'), ['size' => 40, 'disabled' => 'disabled']);
  172. }
  173. $form->applyFilter('firstname', 'trim');
  174. $form->applyFilter('lastname', 'trim');
  175. $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
  176. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  177. // EMAIL
  178. $form->addElement('text', 'email', get_lang('Email'), ['size' => 40, 'disabled' => 'disabled']);
  179. if (api_get_setting('registration', 'email') == 'true') {
  180. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  181. }
  182. $form->addRule('email', get_lang('EmailWrong'), 'email');
  183. if (api_get_setting('openid_authentication') == 'true') {
  184. $form->addElement('text', 'openid', get_lang('OpenIDURL'), ['size' => 40, 'disabled' => 'disabled']);
  185. }
  186. // USERNAME
  187. $form->addElement('text', 'username', get_lang('UserName'), ['size' => USERNAME_MAX_LENGTH, 'disabled' => 'disabled']);
  188. $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
  189. $form->addRule('username', get_lang('UsernameWrong'), 'username');
  190. $form->addRule('username', get_lang('UserTaken'), 'username_available');
  191. $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string) USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
  192. // PASSWORD
  193. $form->addElement('password', 'pass1', get_lang('Pass'), ['size' => 40, 'disabled' => 'disabled']);
  194. $form->addElement('password', 'pass2', get_lang('Confirmation'), ['size' => 40, 'disabled' => 'disabled']);
  195. $form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required');
  196. $form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required');
  197. $form->addRule(['pass1', 'pass2'], get_lang('PassTwo'), 'compare');
  198. $form->addPasswordRule('pass1');
  199. // PHONE
  200. $form->addElement('text', 'phone', get_lang('Phone'), ['size' => 40, 'disabled' => 'disabled']);
  201. if (api_get_setting('registration', 'phone') == 'true') {
  202. $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required');
  203. }
  204. // LANGUAGE
  205. if (api_get_setting('registration', 'language') == 'true') {
  206. $form->addSelectLanguage(
  207. 'language',
  208. get_lang('Language'),
  209. '',
  210. ['disabled' => 'disabled']
  211. );
  212. }
  213. // STUDENT/TEACHER
  214. if (api_get_setting('allow_registration_as_teacher') != 'false') {
  215. $form->addElement('radio', 'status', get_lang('Status'), get_lang('RegStudent'), STUDENT, ['disabled' => 'disabled']);
  216. $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER, ['disabled' => 'disabled']);
  217. }
  218. // EXTENDED FIELDS
  219. if (api_get_setting('extended_profile') == 'true' &&
  220. api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true'
  221. ) {
  222. $form->addHtmlEditor('competences', get_lang('MyCompetences'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']);
  223. }
  224. if (api_get_setting('extended_profile') == 'true' &&
  225. api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true'
  226. ) {
  227. $form->addHtmlEditor('diplomas', get_lang('MyDiplomas'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']);
  228. }
  229. if (api_get_setting('extended_profile') == 'true' &&
  230. api_get_setting('extendedprofile_registration', 'myteach') == 'true'
  231. ) {
  232. $form->addHtmlEditor('teach', get_lang('MyTeach'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']);
  233. }
  234. if (api_get_setting('extended_profile') == 'true' &&
  235. api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true'
  236. ) {
  237. $form->addHtmlEditor('openarea', get_lang('MyPersonalOpenArea'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']);
  238. }
  239. if (api_get_setting('extended_profile') == 'true') {
  240. if (api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') == 'true') {
  241. $form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required');
  242. }
  243. if (api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') == 'true') {
  244. $form->addRule('diplomas', get_lang('ThisFieldIsRequired'), 'required');
  245. }
  246. if (api_get_setting('extendedprofile_registrationrequired', 'myteach') == 'true') {
  247. $form->addRule('teach', get_lang('ThisFieldIsRequired'), 'required');
  248. }
  249. if (api_get_setting('extendedprofile_registrationrequired', 'mypersonalopenarea') == 'true') {
  250. $form->addRule('openarea', get_lang('ThisFieldIsRequired'), 'required');
  251. }
  252. }
  253. $extraField = new ExtraField('user');
  254. $extraField->addElements($form);
  255. }
  256. // Terms and conditions
  257. if (api_get_setting('allow_terms_conditions') == 'true') {
  258. $language = api_get_interface_language();
  259. $language = api_get_language_id($language);
  260. $term_preview = LegalManager::get_last_condition($language);
  261. if (!$term_preview) {
  262. //we load from the platform
  263. $language = api_get_setting('platformLanguage');
  264. $language = api_get_language_id($language);
  265. $term_preview = LegalManager::get_last_condition($language);
  266. //if is false we load from english
  267. if (!$term_preview) {
  268. $language = api_get_language_id('english'); //this must work
  269. $term_preview = LegalManager::get_last_condition($language);
  270. }
  271. }
  272. // Version and language //password
  273. $form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']);
  274. $form->addElement('hidden', 'legal_info', $term_preview['id'].':'.$term_preview['language_id']);
  275. if ($term_preview['type'] == 1) {
  276. $form->addElement(
  277. 'checkbox',
  278. 'legal_accept',
  279. null,
  280. get_lang('IHaveReadAndAgree').'&nbsp;<a href="inscription.php?legal" target="_blank">'.get_lang('TermsAndConditions').'</a>'
  281. );
  282. $form->addRule('legal_accept', get_lang('ThisFieldIsRequired'), 'required');
  283. } else {
  284. if (!empty($term_preview['content'])) {
  285. $preview = LegalManager::show_last_condition($term_preview);
  286. $form->addElement('label', get_lang('TermsAndConditions'), $preview);
  287. }
  288. }
  289. }
  290. $form->addButtonSave(get_lang('RegisterUser'));
  291. $defaults['status'] = STUDENT;
  292. if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {
  293. $defaults['language'] = $_SESSION['user_language_choice'];
  294. } else {
  295. $defaults['language'] = api_get_setting('platformLanguage');
  296. }
  297. if (!empty($_GET['username'])) {
  298. $defaults['username'] = Security::remove_XSS($_GET['username']);
  299. }
  300. if (!empty($_GET['email'])) {
  301. $defaults['email'] = Security::remove_XSS($_GET['email']);
  302. }
  303. if (!empty($_GET['phone'])) {
  304. $defaults['phone'] = Security::remove_XSS($_GET['phone']);
  305. }
  306. if (api_get_setting('openid_authentication') == 'true' && !empty($_GET['openid'])) {
  307. $defaults['openid'] = Security::remove_XSS($_GET['openid']);
  308. }
  309. $form->setDefaults($defaults);
  310. switch ($action) {
  311. case 'edit_top':
  312. if ($action == 'edit_top') {
  313. $name = $topf;
  314. $open = $home_top;
  315. } else {
  316. $name = $newsf;
  317. $open = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
  318. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  319. }
  320. if (!empty($errorMsg)) {
  321. echo Display::return_message($errorMsg, 'normal');
  322. }
  323. $default = [];
  324. $form = new FormValidator(
  325. 'configure_inscription_'.$action,
  326. 'post',
  327. api_get_self().'?action='.$action,
  328. '',
  329. ['style' => 'margin: 0px;']
  330. );
  331. $renderer = &$form->defaultRenderer();
  332. $renderer->setHeaderTemplate('');
  333. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  334. $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
  335. $renderer->setRequiredNoteTemplate('');
  336. $form->addElement('hidden', 'formSent', '1');
  337. $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
  338. $form->addHtmlEditor(
  339. $name,
  340. '',
  341. true,
  342. false,
  343. [
  344. 'ToolbarSet' => 'PortalHomePage',
  345. 'Width' => '100%',
  346. 'Height' => '400',
  347. ]
  348. );
  349. $form->addButtonSave(get_lang('Save'));
  350. $form->setDefaults($default);
  351. $form->display();
  352. break;
  353. default:
  354. //Form of language
  355. api_display_language_form();
  356. echo '&nbsp;&nbsp;<a href="'.api_get_self().'?action=edit_top">'.Display::display_icon('edit.gif', get_lang('Edit')).'</a> <a href="'.api_get_self().'?action=edit_top">'.get_lang('EditNotice').'</a>';
  357. $open = '';
  358. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  359. $open = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
  360. } else {
  361. $open = @(string) file_get_contents($homep.$topf.$ext);
  362. }
  363. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  364. if (!empty($open)) {
  365. echo '<div class="well_border">';
  366. echo $open;
  367. echo '</div>';
  368. }
  369. $form->display();
  370. break;
  371. }
  372. Display :: display_footer();