configure_inscription.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays a form for registering new users.
  5. * @package chamilo.admin
  6. */
  7. $language_file = array('registration', 'admin');
  8. $cidReset = true;
  9. ////require_once '../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 ($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[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  42. $tool_name = get_lang('ConfigureInscription');
  43. if (!empty($action)) {
  44. $interbreadcrumb[] = array('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_PATH).'home/'; //homep for Home Path
  69. $homep_new = api_get_path(SYS_PATH).'home/'.$clean_url; //homep for Home Path added the url
  70. $new_url_dir = api_get_path(SYS_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_DATA_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 = array($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']) && $_POST['formSent']) {
  100. switch ($action) {
  101. case 'edit_top':
  102. // Filter
  103. $home_top = '';
  104. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  105. $home_top = WCAG_Rendering::prepareXHTML();
  106. } else {
  107. $home_top = trim(stripslashes($_POST['register_top']));
  108. }
  109. // Write
  110. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  111. if (is_writable($homep.$topf.'_'.$lang.$ext)) {
  112. $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
  113. fputs($fp, $home_top);
  114. fclose($fp);
  115. } else {
  116. $errorMsg = get_lang('HomePageFilesNotWritable');
  117. }
  118. } else {
  119. //File does not exist
  120. $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
  121. fputs($fp, $home_top);
  122. fclose($fp);
  123. }
  124. break;
  125. }
  126. if (empty($errorMsg)) {
  127. header('Location: '.api_get_self());
  128. exit();
  129. }
  130. } else {
  131. switch ($action) {
  132. case 'edit_top':
  133. // This request is only the preparation for the update of the home_top
  134. $home_top = '';
  135. if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
  136. $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
  137. } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
  138. $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext);
  139. } else {
  140. $errorMsg = get_lang('HomePageFilesNotReadable');
  141. }
  142. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  143. break;
  144. }
  145. }
  146. }
  147. Display :: display_header($tool_name);
  148. echo Display::page_header($tool_name);
  149. // The following security condition has been removed, because it makes no sense here. See Bug #1846.
  150. //// Forbidden to self-register
  151. //if (api_get_setting('allow_registration') == 'false') {
  152. // api_not_allowed();
  153. //}
  154. //api_display_tool_title($tool_name);
  155. if (api_get_setting('allow_registration') == 'approval') {
  156. Display::display_normal_message(get_lang('YourAccountHasToBeApproved'));
  157. }
  158. //if openid was not found
  159. if (!empty($_GET['openid_msg']) && $_GET['openid_msg'] == 'idnotfound') {
  160. Display::display_warning_message(get_lang('OpenIDCouldNotBeFoundPleaseRegister'));
  161. }
  162. $form = new FormValidator('registration');
  163. if (api_get_setting('allow_terms_conditions') == 'true') {
  164. $display_all_form = !isset($_SESSION['update_term_and_condition']['user_id']);
  165. } else {
  166. $display_all_form = true;
  167. }
  168. if ($display_all_form) {
  169. if (api_is_western_name_order()) {
  170. // FIRST NAME and LAST NAME
  171. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40, 'disabled' => 'disabled'));
  172. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40, 'disabled' => 'disabled'));
  173. } else {
  174. // LAST NAME and FIRST NAME
  175. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40, 'disabled' => 'disabled'));
  176. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40, 'disabled' => 'disabled'));
  177. }
  178. $form->applyFilter('firstname', 'trim');
  179. $form->applyFilter('lastname', 'trim');
  180. $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
  181. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  182. // EMAIL
  183. $form->addElement('text', 'email', get_lang('Email'), array('size' => 40, 'disabled' => 'disabled'));
  184. if (api_get_setting('registration', 'email') == 'true') {
  185. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  186. }
  187. $form->addRule('email', get_lang('EmailWrong'), 'email');
  188. if (api_get_setting('openid_authentication') == 'true') {
  189. $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40, 'disabled' => 'disabled'));
  190. }
  191. // USERNAME
  192. $form->addElement('text', 'username', get_lang('UserName'), array('size' => USERNAME_MAX_LENGTH, 'disabled' => 'disabled'));
  193. $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
  194. $form->addRule('username', get_lang('UsernameWrong'), 'username');
  195. $form->addRule('username', get_lang('UserTaken'), 'username_available');
  196. $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
  197. // PASSWORD
  198. $form->addElement('password', 'pass1', get_lang('Pass'), array('size' => 40, 'disabled' => 'disabled'));
  199. $form->addElement('password', 'pass2', get_lang('Confirmation'), array('size' => 40, 'disabled' => 'disabled'));
  200. $form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required');
  201. $form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required');
  202. $form->addRule(array('pass1', 'pass2'), get_lang('PassTwo'), 'compare');
  203. if (CHECK_PASS_EASY_TO_FIND) {
  204. $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password');
  205. }
  206. // PHONE
  207. $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 40, 'disabled' => 'disabled'));
  208. if (api_get_setting('registration', 'phone') == 'true') {
  209. $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required');
  210. }
  211. // LANGUAGE
  212. if (api_get_setting('registration', 'language') == 'true') {
  213. $form->addElement('select_language', 'language', get_lang('Language'), '', array('disabled' => 'disabled'));
  214. }
  215. // STUDENT/TEACHER
  216. if (api_get_setting('allow_registration_as_teacher') != 'false') {
  217. $form->addElement('radio', 'status', get_lang('Status'), get_lang('RegStudent'), STUDENT, array('disabled' => 'disabled'));
  218. $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER, array('disabled' => 'disabled'));
  219. }
  220. // EXTENDED FIELDS
  221. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','mycomptetences') == 'true') {
  222. $form->add_html_editor('competences', get_lang('MyCompetences'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  223. }
  224. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','mydiplomas') == 'true') {
  225. $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  226. }
  227. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','myteach') == 'true') {
  228. $form->add_html_editor('teach', get_lang('MyTeach'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  229. }
  230. if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration','mypersonalopenarea') == 'true') {
  231. $form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  232. }
  233. if (api_get_setting('extended_profile') == 'true') {
  234. if (api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') == 'true') {
  235. $form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required');
  236. }
  237. if (api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') == 'true') {
  238. $form->addRule('diplomas', get_lang('ThisFieldIsRequired'), 'required');
  239. }
  240. if (api_get_setting('extendedprofile_registrationrequired', 'myteach') == 'true') {
  241. $form->addRule('teach', get_lang('ThisFieldIsRequired'), 'required');
  242. }
  243. if (api_get_setting('extendedprofile_registrationrequired', 'mypersonalopenarea') == 'true') {
  244. $form->addRule('openarea', get_lang('ThisFieldIsRequired'), 'required');
  245. }
  246. }
  247. $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true);
  248. $extraField = new ExtraField('user');
  249. $extraField->set_extra_fields_in_form($form, $extra_data, 'registration', false, null);
  250. }
  251. // Terms and conditions
  252. if (api_get_setting('allow_terms_conditions') == 'true') {
  253. $language = api_get_interface_language();
  254. $language = api_get_language_id($language);
  255. $term_preview = LegalManager::get_last_condition($language);
  256. if (!$term_preview) {
  257. //we load from the platform
  258. $language = api_get_setting('platformLanguage');
  259. $language = api_get_language_id($language);
  260. $term_preview = LegalManager::get_last_condition($language);
  261. //if is false we load from english
  262. if (!$term_preview) {
  263. $language = api_get_language_id('english'); //this must work
  264. $term_preview = LegalManager::get_last_condition($language);
  265. }
  266. }
  267. // Version and language //password
  268. $form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']);
  269. $form->addElement('hidden', 'legal_info', $term_preview['legal_id'].':'.$term_preview['language_id']);
  270. if ($term_preview['type'] == 1) {
  271. $form->addElement('checkbox', 'legal_accept', null, get_lang('IHaveReadAndAgree').'&nbsp;<a href="inscription.php?legal" target="_blank">'.get_lang('TermsAndConditions').'</a>');
  272. $form->addRule('extra_legal_accept', get_lang('ThisFieldIsRequired'), 'required');
  273. } else {
  274. if (!empty($term_preview['content'])) {
  275. $preview = LegalManager::show_last_condition($term_preview);
  276. $form->addElement('label', get_lang('TermsAndConditions'), $preview);
  277. }
  278. }
  279. }
  280. $form->addElement('style_submit_button', 'submit', get_lang('RegisterUser'), array('disabled' => 'disabled'));
  281. $defaults['status'] = STUDENT;
  282. if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {
  283. $defaults['language'] = $_SESSION['user_language_choice'];
  284. } else {
  285. $defaults['language'] = api_get_setting('platformLanguage');
  286. }
  287. if (!empty($_GET['username'])) {
  288. $defaults['username'] = Security::remove_XSS($_GET['username']);
  289. }
  290. if (!empty($_GET['email'])) {
  291. $defaults['email'] = Security::remove_XSS($_GET['email']);
  292. }
  293. if (!empty($_GET['phone'])) {
  294. $defaults['phone'] = Security::remove_XSS($_GET['phone']);
  295. }
  296. if (api_get_setting('openid_authentication') == 'true' && !empty($_GET['openid'])) {
  297. $defaults['openid'] = Security::remove_XSS($_GET['openid']);
  298. }
  299. $form->setDefaults($defaults);
  300. switch ($action){
  301. case 'edit_top':
  302. if ($action == 'edit_top') {
  303. $name = $topf;
  304. $open = $home_top;
  305. } else {
  306. $name = $newsf;
  307. $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
  308. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  309. }
  310. if (!empty($errorMsg)) {
  311. Display::display_normal_message($errorMsg);
  312. }
  313. $default = array();
  314. $form = new FormValidator('configure_inscription_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  315. $renderer =& $form->defaultRenderer();
  316. $renderer->setHeaderTemplate('');
  317. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  318. $renderer->setElementTemplate('<tr><td>{element}</td></tr>');
  319. $renderer->setRequiredNoteTemplate('');
  320. $form->addElement('hidden', 'formSent', '1');
  321. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  322. //TODO: review these lines
  323. // Print WCAG-specific HTML editor
  324. $html = '<tr><td>';
  325. $html .= WCAG_Rendering::create_xhtml($open);
  326. $html .= '</td></tr>';
  327. $form->addElement('html', $html);
  328. } else {
  329. $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
  330. $form->add_html_editor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  331. }
  332. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  333. $form->setDefaults($default);
  334. $form->display();
  335. break;
  336. default:
  337. //Form of language
  338. api_display_language_form();
  339. 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>';
  340. $open = '';
  341. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  342. $open = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
  343. } else {
  344. $open = @(string)file_get_contents($homep.$topf.$ext);
  345. }
  346. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  347. if (!empty($open)) {
  348. echo '<div class="well_border">';
  349. echo $open;
  350. echo '</div>';
  351. }
  352. $form->display();
  353. break;
  354. }
  355. Display :: display_footer();