configure_inscription.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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 __DIR__.'/../inc/global.inc.php';
  9. api_protect_admin_script();
  10. // Load terms & conditions from the current lang
  11. if (api_get_setting('allow_terms_conditions') == 'true') {
  12. $get = array_keys($_GET);
  13. if (isset($get)) {
  14. if ($get[0] == 'legal') {
  15. $language = api_get_interface_language();
  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('platformLanguage');
  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' => 'index.php', '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('platformLanguage');
  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('allow_registration') == 'false') {
  146. // api_not_allowed();
  147. //}
  148. //api_display_tool_title($tool_name);
  149. if (api_get_setting('allow_registration') == 'approval') {
  150. echo Display::return_message(get_lang('YourAccountHasToBeApproved'), 'normal');
  151. }
  152. //if openid was not found
  153. if (!empty($_GET['openid_msg']) && $_GET['openid_msg'] == 'idnotfound') {
  154. echo Display::return_message(get_lang('OpenIDCouldNotBeFoundPleaseRegister'), 'warning');
  155. }
  156. $form = new FormValidator('registration');
  157. if (api_get_setting('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('registration', 'email') == 'true') {
  179. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  180. }
  181. $form->addRule('email', get_lang('EmailWrong'), 'email');
  182. if (api_get_setting('openid_authentication') == 'true') {
  183. $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40, 'disabled' => 'disabled'));
  184. }
  185. // USERNAME
  186. $form->addElement('text', 'username', get_lang('UserName'), array('size' => USERNAME_MAX_LENGTH, 'disabled' => 'disabled'));
  187. $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
  188. $form->addRule('username', get_lang('UsernameWrong'), 'username');
  189. $form->addRule('username', get_lang('UserTaken'), 'username_available');
  190. $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string) USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
  191. // PASSWORD
  192. $form->addElement('password', 'pass1', get_lang('Pass'), array('size' => 40, 'disabled' => 'disabled'));
  193. $form->addElement('password', 'pass2', get_lang('Confirmation'), array('size' => 40, 'disabled' => 'disabled'));
  194. $form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required');
  195. $form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required');
  196. $form->addRule(array('pass1', 'pass2'), get_lang('PassTwo'), 'compare');
  197. $form->addPasswordRule('pass1');
  198. // PHONE
  199. $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 40, 'disabled' => 'disabled'));
  200. if (api_get_setting('registration', 'phone') == 'true') {
  201. $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required');
  202. }
  203. // LANGUAGE
  204. if (api_get_setting('registration', 'language') == 'true') {
  205. $form->addSelectLanguage(
  206. 'language',
  207. get_lang('Language'),
  208. '',
  209. array('disabled' => 'disabled')
  210. );
  211. }
  212. // STUDENT/TEACHER
  213. if (api_get_setting('allow_registration_as_teacher') != 'false') {
  214. $form->addElement('radio', 'status', get_lang('Status'), get_lang('RegStudent'), STUDENT, array('disabled' => 'disabled'));
  215. $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER, array('disabled' => 'disabled'));
  216. }
  217. // EXTENDED FIELDS
  218. if (api_get_setting('extended_profile') == 'true' &&
  219. api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true'
  220. ) {
  221. $form->addHtmlEditor('competences', get_lang('MyCompetences'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  222. }
  223. if (api_get_setting('extended_profile') == 'true' &&
  224. api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true'
  225. ) {
  226. $form->addHtmlEditor('diplomas', get_lang('MyDiplomas'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  227. }
  228. if (api_get_setting('extended_profile') == 'true' &&
  229. api_get_setting('extendedprofile_registration', 'myteach') == 'true'
  230. ) {
  231. $form->addHtmlEditor('teach', get_lang('MyTeach'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  232. }
  233. if (api_get_setting('extended_profile') == 'true' &&
  234. api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true'
  235. ) {
  236. $form->addHtmlEditor('openarea', get_lang('MyPersonalOpenArea'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  237. }
  238. if (api_get_setting('extended_profile') == 'true') {
  239. if (api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') == 'true') {
  240. $form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required');
  241. }
  242. if (api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') == 'true') {
  243. $form->addRule('diplomas', get_lang('ThisFieldIsRequired'), 'required');
  244. }
  245. if (api_get_setting('extendedprofile_registrationrequired', 'myteach') == 'true') {
  246. $form->addRule('teach', get_lang('ThisFieldIsRequired'), 'required');
  247. }
  248. if (api_get_setting('extendedprofile_registrationrequired', 'mypersonalopenarea') == 'true') {
  249. $form->addRule('openarea', get_lang('ThisFieldIsRequired'), 'required');
  250. }
  251. }
  252. $extraField = new ExtraField('user');
  253. $extraField->addElements($form);
  254. }
  255. // Terms and conditions
  256. if (api_get_setting('allow_terms_conditions') == 'true') {
  257. $language = api_get_interface_language();
  258. $language = api_get_language_id($language);
  259. $term_preview = LegalManager::get_last_condition($language);
  260. if (!$term_preview) {
  261. //we load from the platform
  262. $language = api_get_setting('platformLanguage');
  263. $language = api_get_language_id($language);
  264. $term_preview = LegalManager::get_last_condition($language);
  265. //if is false we load from english
  266. if (!$term_preview) {
  267. $language = api_get_language_id('english'); //this must work
  268. $term_preview = LegalManager::get_last_condition($language);
  269. }
  270. }
  271. // Version and language //password
  272. $form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']);
  273. $form->addElement('hidden', 'legal_info', $term_preview['id'].':'.$term_preview['language_id']);
  274. if ($term_preview['type'] == 1) {
  275. $form->addElement(
  276. 'checkbox',
  277. 'legal_accept',
  278. null,
  279. get_lang('IHaveReadAndAgree').'&nbsp;<a href="inscription.php?legal" target="_blank">'.get_lang('TermsAndConditions').'</a>'
  280. );
  281. $form->addRule('legal_accept', get_lang('ThisFieldIsRequired'), 'required');
  282. } else {
  283. if (!empty($term_preview['content'])) {
  284. $preview = LegalManager::show_last_condition($term_preview);
  285. $form->addElement('label', get_lang('TermsAndConditions'), $preview);
  286. }
  287. }
  288. }
  289. $form->addButtonSave(get_lang('RegisterUser'));
  290. $defaults['status'] = STUDENT;
  291. if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {
  292. $defaults['language'] = $_SESSION['user_language_choice'];
  293. } else {
  294. $defaults['language'] = api_get_setting('platformLanguage');
  295. }
  296. if (!empty($_GET['username'])) {
  297. $defaults['username'] = Security::remove_XSS($_GET['username']);
  298. }
  299. if (!empty($_GET['email'])) {
  300. $defaults['email'] = Security::remove_XSS($_GET['email']);
  301. }
  302. if (!empty($_GET['phone'])) {
  303. $defaults['phone'] = Security::remove_XSS($_GET['phone']);
  304. }
  305. if (api_get_setting('openid_authentication') == 'true' && !empty($_GET['openid'])) {
  306. $defaults['openid'] = Security::remove_XSS($_GET['openid']);
  307. }
  308. $form->setDefaults($defaults);
  309. switch ($action) {
  310. case 'edit_top':
  311. if ($action == 'edit_top') {
  312. $name = $topf;
  313. $open = $home_top;
  314. } else {
  315. $name = $newsf;
  316. $open = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
  317. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  318. }
  319. if (!empty($errorMsg)) {
  320. echo Display::return_message($errorMsg, 'normal');
  321. }
  322. $default = array();
  323. $form = new FormValidator('configure_inscription_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  324. $renderer = & $form->defaultRenderer();
  325. $renderer->setHeaderTemplate('');
  326. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  327. $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
  328. $renderer->setRequiredNoteTemplate('');
  329. $form->addElement('hidden', 'formSent', '1');
  330. $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
  331. $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  332. $form->addButtonSave(get_lang('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();