configure_inscription.php 17 KB

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