configure_inscription.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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('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. 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('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. if (CHECK_PASS_EASY_TO_FIND) {
  198. $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password');
  199. }
  200. // PHONE
  201. $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 40, 'disabled' => 'disabled'));
  202. if (api_get_setting('registration', 'phone') == 'true') {
  203. $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required');
  204. }
  205. // LANGUAGE
  206. if (api_get_setting('registration', 'language') == 'true') {
  207. $form->addElement('select_language', 'language', get_lang('Language'), '', array('disabled' => 'disabled'));
  208. }
  209. // STUDENT/TEACHER
  210. if (api_get_setting('allow_registration_as_teacher') != 'false') {
  211. $form->addElement('radio', 'status', get_lang('Status'), get_lang('RegStudent'), STUDENT, array('disabled' => 'disabled'));
  212. $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER, array('disabled' => 'disabled'));
  213. }
  214. // EXTENDED FIELDS
  215. if (api_get_setting('extended_profile') == 'true' &&
  216. api_get_setting('extendedprofile_registration','mycomptetences') == 'true'
  217. ) {
  218. $form->addHtmlEditor('competences', get_lang('MyCompetences'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  219. }
  220. if (api_get_setting('extended_profile') == 'true' &&
  221. api_get_setting('extendedprofile_registration','mydiplomas') == 'true'
  222. ) {
  223. $form->addHtmlEditor('diplomas', get_lang('MyDiplomas'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  224. }
  225. if (api_get_setting('extended_profile') == 'true' &&
  226. api_get_setting('extendedprofile_registration','myteach') == 'true'
  227. ) {
  228. $form->addHtmlEditor('teach', get_lang('MyTeach'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  229. }
  230. if (api_get_setting('extended_profile') == 'true' &&
  231. api_get_setting('extendedprofile_registration','mypersonalopenarea') == 'true'
  232. ) {
  233. $form->addHtmlEditor('openarea', get_lang('MyPersonalOpenArea'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
  234. }
  235. if (api_get_setting('extended_profile') == 'true') {
  236. if (api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') == 'true') {
  237. $form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required');
  238. }
  239. if (api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') == 'true') {
  240. $form->addRule('diplomas', get_lang('ThisFieldIsRequired'), 'required');
  241. }
  242. if (api_get_setting('extendedprofile_registrationrequired', 'myteach') == 'true') {
  243. $form->addRule('teach', get_lang('ThisFieldIsRequired'), 'required');
  244. }
  245. if (api_get_setting('extendedprofile_registrationrequired', 'mypersonalopenarea') == 'true') {
  246. $form->addRule('openarea', get_lang('ThisFieldIsRequired'), 'required');
  247. }
  248. }
  249. $extraField = new ExtraField('user');
  250. $extraField->addElements($form);
  251. }
  252. // Terms and conditions
  253. if (api_get_setting('allow_terms_conditions') == 'true') {
  254. $language = api_get_interface_language();
  255. $language = api_get_language_id($language);
  256. $term_preview = LegalManager::get_last_condition($language);
  257. if (!$term_preview) {
  258. //we load from the platform
  259. $language = api_get_setting('platformLanguage');
  260. $language = api_get_language_id($language);
  261. $term_preview = LegalManager::get_last_condition($language);
  262. //if is false we load from english
  263. if (!$term_preview) {
  264. $language = api_get_language_id('english'); //this must work
  265. $term_preview = LegalManager::get_last_condition($language);
  266. }
  267. }
  268. // Version and language //password
  269. $form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']);
  270. $form->addElement('hidden', 'legal_info', $term_preview['legal_id'].':'.$term_preview['language_id']);
  271. if ($term_preview['type'] == 1) {
  272. $form->addElement('checkbox', 'legal_accept', null, get_lang('IHaveReadAndAgree').'&nbsp;<a href="inscription.php?legal" target="_blank">'.get_lang('TermsAndConditions').'</a>');
  273. $form->addRule('extra_legal_accept', get_lang('ThisFieldIsRequired'), 'required');
  274. } else {
  275. if (!empty($term_preview['content'])) {
  276. $preview = LegalManager::show_last_condition($term_preview);
  277. $form->addElement('label', get_lang('TermsAndConditions'), $preview);
  278. }
  279. }
  280. }
  281. $form->addButtonSave(get_lang('RegisterUser'));
  282. $defaults['status'] = STUDENT;
  283. if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {
  284. $defaults['language'] = $_SESSION['user_language_choice'];
  285. } else {
  286. $defaults['language'] = api_get_setting('platformLanguage');
  287. }
  288. if (!empty($_GET['username'])) {
  289. $defaults['username'] = Security::remove_XSS($_GET['username']);
  290. }
  291. if (!empty($_GET['email'])) {
  292. $defaults['email'] = Security::remove_XSS($_GET['email']);
  293. }
  294. if (!empty($_GET['phone'])) {
  295. $defaults['phone'] = Security::remove_XSS($_GET['phone']);
  296. }
  297. if (api_get_setting('openid_authentication') == 'true' && !empty($_GET['openid'])) {
  298. $defaults['openid'] = Security::remove_XSS($_GET['openid']);
  299. }
  300. $form->setDefaults($defaults);
  301. switch ($action){
  302. case 'edit_top':
  303. if ($action == 'edit_top') {
  304. $name = $topf;
  305. $open = $home_top;
  306. } else {
  307. $name = $newsf;
  308. $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
  309. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  310. }
  311. if (!empty($errorMsg)) {
  312. Display::display_normal_message($errorMsg);
  313. }
  314. $default = array();
  315. $form = new FormValidator('configure_inscription_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  316. $renderer =& $form->defaultRenderer();
  317. $renderer->setHeaderTemplate('');
  318. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  319. $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
  320. $renderer->setRequiredNoteTemplate('');
  321. $form->addElement('hidden', 'formSent', '1');
  322. $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
  323. $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  324. $form->addButtonSave(get_lang('Save'));
  325. $form->setDefaults($default);
  326. $form->display();
  327. break;
  328. default:
  329. //Form of language
  330. api_display_language_form();
  331. 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>';
  332. $open = '';
  333. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  334. $open = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
  335. } else {
  336. $open = @(string)file_get_contents($homep.$topf.$ext);
  337. }
  338. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  339. if (!empty($open)) {
  340. echo '<div class="well_border">';
  341. echo $open;
  342. echo '</div>';
  343. }
  344. $form->display();
  345. break;
  346. }
  347. Display :: display_footer();