settings.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * With this tool you can easily adjust non critical configuration settings.
  5. * Non critical means that changing them will not result in a broken campus.
  6. *
  7. * @author Patrick Cool
  8. * @author Julio Montoya - Multiple URL site
  9. * @package chamilo.admin
  10. */
  11. /* INIT SECTION */
  12. // Language files that need to be included.
  13. if (isset($_GET['category']) && $_GET['category'] == 'Templates') {
  14. $language_file = array('admin', 'document');
  15. } else {
  16. if (isset($_GET['category']) && $_GET['category'] == 'Gradebook') {
  17. $language_file = array('admin', 'gradebook');
  18. } else {
  19. $language_file = array('admin', 'document');
  20. }
  21. }
  22. $language_file[] = 'tracking';
  23. // Resetting the course id.
  24. $cidReset = true;
  25. // Including some necessary library files.
  26. require_once '../inc/global.inc.php';
  27. require_once 'settings.lib.php';
  28. // Setting the section (for the tabs).
  29. $this_section = SECTION_PLATFORM_ADMIN;
  30. $_SESSION['this_section'] = $this_section;
  31. // Access restrictions.
  32. api_protect_admin_script();
  33. // Settings to avoid
  34. $settings_to_avoid = array(
  35. 'stylesheets' => '', // handled by the handle_stylesheet() function
  36. 'server_type' => '',
  37. 'use_session_mode' => 'true',
  38. 'gradebook_enable' => 'false',
  39. 'example_material_course_creation' => 'true' // ON by default - now we have this option when we create a course
  40. );
  41. $convert_byte_to_mega_list = array(
  42. 'dropbox_max_filesize',
  43. 'message_max_upload_filesize',
  44. 'default_document_quotum',
  45. 'default_group_quotum'
  46. );
  47. // Database table definitions.
  48. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  49. // Setting breadcrumbs.
  50. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  51. // Setting the name of the tool.
  52. $tool_name = get_lang('PlatformConfigSettings');
  53. if (empty($_GET['category'])) {
  54. $_GET['category'] = 'Platform';
  55. }
  56. $watermark_deleted = false;
  57. if (isset($_GET['delete_watermark'])) {
  58. $watermark_deleted = PDF::delete_watermark();
  59. }
  60. if (isset($_GET['action']) && $_GET['action'] == 'delete_grading') {
  61. $id = intval($_GET['id']);
  62. api_delete_setting_option($id);
  63. }
  64. $form_search = new FormValidator('search_settings', 'get', api_get_self(), null, array('class' => 'well form-inline'));
  65. $form_search->addElement('text', 'search_field');
  66. $form_search->addElement('hidden', 'category', 'search_setting');
  67. $form_search->addElement(
  68. 'style_submit_button',
  69. 'submit_button',
  70. get_lang('Search'),
  71. 'value="submit_button", class="search"'
  72. );
  73. $form_search->setDefaults(
  74. array('search_field' => (isset($_REQUEST['search_field']) ? $_REQUEST['search_field'] : null))
  75. );
  76. $form_search_html = $form_search->return_form();
  77. $url_id = api_get_current_access_url_id();
  78. $settings = null;
  79. /**
  80. * @param string $category
  81. * @return array
  82. */
  83. function get_settings($category = null)
  84. {
  85. $url_id = api_get_current_access_url_id();
  86. $settings_by_access_list = array();
  87. if ($url_id == 1) {
  88. $settings = api_get_settings($category, 'group', $url_id);
  89. } else {
  90. $url_info = api_get_access_url($url_id);
  91. if ($url_info['active'] == 1) {
  92. // The default settings of Chamilo
  93. $settings = api_get_settings($category, 'group', 1, 0);
  94. // The settings that are changeable from a particular site.
  95. $settings_by_access = api_get_settings($category, 'group', $url_id, 1);
  96. foreach ($settings_by_access as $row) {
  97. if (empty($row['variable'])) {
  98. $row['variable'] = 0;
  99. }
  100. if (empty($row['subkey'])) {
  101. $row['subkey'] = 0;
  102. }
  103. if (empty($row['category'])) {
  104. $row['category'] = 0;
  105. }
  106. // One more validation if is changeable.
  107. if ($row['access_url_changeable'] == 1) {
  108. $settings_by_access_list[$row['variable']] [$row['subkey']] [$row['category']] = $row;
  109. } else {
  110. $settings_by_access_list[$row['variable']] [$row['subkey']] [$row['category']] = array();
  111. }
  112. }
  113. }
  114. }
  115. if (isset($category) && $category == 'search_setting') {
  116. if (!empty($_REQUEST['search_field'])) {
  117. $settings = search_setting($_REQUEST['search_field']);
  118. }
  119. }
  120. return array(
  121. 'settings' => $settings,
  122. 'settings_by_access_list' => $settings_by_access_list
  123. );
  124. }
  125. // Build the form.
  126. if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search'))) {
  127. $my_category = isset($_GET['category']) ? $_GET['category'] : null;
  128. $settings_array = get_settings($my_category);
  129. $settings = $settings_array['settings'];
  130. $settings_by_access_list = $settings_array['settings_by_access_list'];
  131. $form = generate_settings_form($settings, $settings_by_access_list, $settings_to_avoid, $convert_byte_to_mega_list);
  132. $message = array();
  133. if ($form->validate()) {
  134. $values = $form->exportValues();
  135. $mark_all = false;
  136. $un_mark_all = false;
  137. if (!empty($_configuration['multiple_access_urls'])) {
  138. if (isset($values['buttons_in_action_right']) && isset($values['buttons_in_action_right']['mark_all'])) {
  139. $mark_all = true;
  140. }
  141. if (isset($values['buttons_in_action_right']) && isset($values['buttons_in_action_right']['unmark_all'])) {
  142. $un_mark_all = true;
  143. }
  144. }
  145. if ($mark_all || $un_mark_all) {
  146. if (api_is_global_platform_admin()) {
  147. $locked_settings = api_get_locked_settings();
  148. foreach ($values as $key => $value) {
  149. if (!in_array($key, $locked_settings)) {
  150. $changeable = 0;
  151. if ($mark_all) {
  152. $changeable = 1;
  153. }
  154. $params = array('variable = ?' => array($key));
  155. $data = api_get_settings_params($params);
  156. if (!empty($data)) {
  157. foreach ($data as $item) {
  158. $params = array('id' => $item['id'], 'access_url_changeable' => $changeable);
  159. api_set_setting_simple($params);
  160. }
  161. }
  162. }
  163. }
  164. //Reload settings
  165. $settings_array = get_settings($my_category);
  166. $settings = $settings_array['settings'];
  167. $settings_by_access_list = $settings_array['settings_by_access_list'];
  168. $form = generate_settings_form($settings, $settings_by_access_list, $settings_to_avoid, $convert_byte_to_mega_list);
  169. }
  170. }
  171. $pdf_export_watermark_path = $_FILES['pdf_export_watermark_path'];
  172. if (isset($pdf_export_watermark_path) && !empty($pdf_export_watermark_path['name'])) {
  173. $pdf_export_watermark_path_result = PDF::upload_watermark(
  174. $pdf_export_watermark_path['name'],
  175. $pdf_export_watermark_path['tmp_name']
  176. );
  177. if ($pdf_export_watermark_path_result) {
  178. $message['confirmation'][] = get_lang('UplUploadSucceeded');
  179. } else {
  180. $message['warning'][] = get_lang('UplUnableToSaveFile').' '.get_lang('Folder').': '.api_get_path(
  181. SYS_CODE_PATH
  182. ).'default_course_document/images';
  183. }
  184. unset($update_values['pdf_export_watermark_path']);
  185. }
  186. // Set true for allow_message_tool variable if social tool is actived
  187. foreach ($convert_byte_to_mega_list as $item) {
  188. if (isset($values[$item])) {
  189. $values[$item] = round($values[$item] * 1024 * 1024);
  190. }
  191. }
  192. if (isset($values['allow_social_tool']) && $values['allow_social_tool'] == 'true') {
  193. $values['allow_message_tool'] = 'true';
  194. }
  195. // The first step is to set all the variables that have type=checkbox of the category
  196. // to false as the checkbox that is unchecked is not in the $_POST data and can
  197. // therefore not be set to false.
  198. // This, however, also means that if the process breaks on the third of five checkboxes, the others
  199. // will be set to false.
  200. //$r = api_set_settings_category($my_category, 'false', $_configuration['access_url'], array('checkbox', 'radio'));
  201. //This is a more accurate way of updating to false the checkboxes and radios the settings
  202. /*
  203. foreach ($values as $key => $value) {
  204. if (in_array($key, $settings_to_avoid)) { continue; }
  205. if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { continue; }
  206. $key = Database::escape_string($key);
  207. $sql = "UPDATE $table_settings_current SET selected_value = 'false' WHERE variable = '".$key."' AND access_url = ".intval($url_id)." AND type IN ('checkbox', 'radio') ";
  208. $res = Database::query($sql);
  209. }*/
  210. foreach ($settings as $item) {
  211. $key = $item['variable'];
  212. if (in_array($key, $settings_to_avoid)) {
  213. continue;
  214. }
  215. if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') {
  216. continue;
  217. }
  218. $key = Database::escape_string($key);
  219. $sql = "UPDATE $table_settings_current SET selected_value = 'false'
  220. WHERE variable = '".$key."' AND access_url = ".intval($url_id)." AND type IN ('checkbox', 'radio') ";
  221. $res = Database::query($sql);
  222. }
  223. // Save the settings.
  224. $keys = array();
  225. foreach ($values as $key => $value) {
  226. if (in_array($key, $settings_to_avoid)) {
  227. continue;
  228. }
  229. // Avoid form elements which have nothing to do with settings
  230. if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') {
  231. continue;
  232. }
  233. // Treat gradebook values in separate function.
  234. //if (strpos($key, 'gradebook_score_display_custom_values') === false) {
  235. if (!is_array($value)) {
  236. $old_value = api_get_setting($key);
  237. switch ($key) {
  238. case 'header_extra_content':
  239. file_put_contents(
  240. api_get_path(SYS_PATH).api_get_home_path().'/header_extra_content.txt',
  241. $value
  242. );
  243. $value = api_get_home_path().'/header_extra_content.txt';
  244. break;
  245. case 'footer_extra_content':
  246. file_put_contents(
  247. api_get_path(SYS_PATH).api_get_home_path().'/footer_extra_content.txt',
  248. $value
  249. );
  250. $value = api_get_home_path().'/footer_extra_content.txt';
  251. break;
  252. // URL validation for some settings.
  253. case 'InstitutionUrl':
  254. case 'course_validation_terms_and_conditions_url':
  255. $value = trim(Security::remove_XSS($value));
  256. if ($value != '') {
  257. // Here we accept absolute URLs only.
  258. if (strpos($value, '://') === false) {
  259. $value = 'http://'.$value;
  260. }
  261. if (!api_valid_url($value, true)) {
  262. // If the new (non-empty) URL value is invalid, then the old URL value stays.
  263. $value = $old_value;
  264. }
  265. }
  266. // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted).
  267. break;
  268. // Validation against e-mail address for some settings.
  269. case 'emailAdministrator':
  270. $value = trim(Security::remove_XSS($value));
  271. if ($value != '' && !api_valid_email($value)) {
  272. // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays.
  273. // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted).
  274. $value = $old_value;
  275. }
  276. break;
  277. }
  278. if ($old_value != $value) {
  279. $keys[] = $key;
  280. }
  281. $result = api_set_setting($key, $value, null, null, $url_id);
  282. } else {
  283. $sql = "SELECT subkey FROM $table_settings_current WHERE variable = '$key'";
  284. $res = Database::query($sql);
  285. while ($row_subkeys = Database::fetch_array($res)) {
  286. // If subkey is changed:
  287. if ((isset($value[$row_subkeys['subkey']]) && api_get_setting(
  288. $key,
  289. $row_subkeys['subkey']
  290. ) == 'false') ||
  291. (!isset($value[$row_subkeys['subkey']]) && api_get_setting(
  292. $key,
  293. $row_subkeys['subkey']
  294. ) == 'true')
  295. ) {
  296. $keys[] = $key;
  297. break;
  298. }
  299. }
  300. foreach ($value as $subkey => $subvalue) {
  301. $result = api_set_setting($key, 'true', $subkey, null, $url_id);
  302. }
  303. }
  304. }
  305. // Add event configuration settings category to the system log.
  306. $user_id = api_get_user_id();
  307. $category = $_GET['category'];
  308. event_system(
  309. LOG_CONFIGURATION_SETTINGS_CHANGE,
  310. LOG_CONFIGURATION_SETTINGS_CATEGORY,
  311. $category,
  312. api_get_utc_datetime(),
  313. $user_id
  314. );
  315. api_set_setting_last_update();
  316. // Add event configuration settings variable to the system log.
  317. if (is_array($keys) && count($keys) > 0) {
  318. foreach ($keys as $variable) {
  319. if (in_array($key, $settings_to_avoid)) {
  320. continue;
  321. }
  322. event_system(
  323. LOG_CONFIGURATION_SETTINGS_CHANGE,
  324. LOG_CONFIGURATION_SETTINGS_VARIABLE,
  325. $variable,
  326. api_get_utc_datetime(),
  327. $user_id
  328. );
  329. }
  330. }
  331. }
  332. }
  333. $htmlHeadXtra[] = '<script>
  334. var hide_icon = "'.api_get_path(WEB_IMG_PATH).'shared_setting_na.png";
  335. var show_icon = "'.api_get_path(WEB_IMG_PATH).'shared_setting.png";
  336. var url = "'.api_get_path(WEB_AJAX_PATH).'admin.ajax.php?a=update_changeable_setting";
  337. $(function() {
  338. $(".share_this_setting").on("click", function() {
  339. var my_img = $(this).find("img");
  340. var link = $(this);
  341. $.ajax({
  342. url: url,
  343. data: { changeable: $(this).attr("data_status"), id: $(this).attr("data_to_send") },
  344. success: function(data) {
  345. if (data == 1) {
  346. if (link.attr("data_status") == 1) {
  347. my_img.attr("src", show_icon);
  348. link.attr("data_status", 0);
  349. } else {
  350. my_img.attr("src", hide_icon);
  351. link.attr("data_status", 1);
  352. }
  353. }
  354. }
  355. });
  356. });
  357. });
  358. </script>';
  359. // Including the header (banner).
  360. Display :: display_header($tool_name);
  361. // The action images.
  362. $action_images['platform'] = 'platform.png';
  363. $action_images['course'] = 'course.png';
  364. $action_images['session'] = 'session.png';
  365. $action_images['tools'] = 'tools.png';
  366. $action_images['user'] = 'user.png';
  367. $action_images['gradebook'] = 'gradebook.png';
  368. $action_images['ldap'] = 'ldap.png';
  369. $action_images['cas'] = 'user_access.png';
  370. $action_images['security'] = 'security.png';
  371. $action_images['languages'] = 'languages.png';
  372. $action_images['tuning'] = 'tuning.png';
  373. $action_images['templates'] = 'template.png';
  374. $action_images['search'] = 'search.png';
  375. $action_images['editor'] = 'html_editor.png';
  376. $action_images['timezones'] = 'timezone.png';
  377. $action_images['extra'] = 'wizard.png';
  378. $action_images['tracking'] = 'statistics.png';
  379. $action_images['gradebook'] = 'gradebook.png';
  380. $action_images['search'] = 'search.png';
  381. $action_images['stylesheets'] = 'stylesheets.png';
  382. $action_images['templates'] = 'template.png';
  383. $action_images['plugins'] = 'plugins.png';
  384. $action_images['shibboleth'] = 'shibboleth.png';
  385. $action_images['facebook'] = 'facebook.png';
  386. $action_array = array();
  387. $resultcategories = array();
  388. $resultcategories[] = array('category' => 'Platform');
  389. $resultcategories[] = array('category' => 'Course');
  390. $resultcategories[] = array('category' => 'Session');
  391. $resultcategories[] = array('category' => 'Languages');
  392. $resultcategories[] = array('category' => 'User');
  393. $resultcategories[] = array('category' => 'Tools');
  394. $resultcategories[] = array('category' => 'Editor');
  395. $resultcategories[] = array('category' => 'Security');
  396. $resultcategories[] = array('category' => 'Tuning');
  397. $resultcategories[] = array('category' => 'Gradebook');
  398. $resultcategories[] = array('category' => 'Timezones');
  399. $resultcategories[] = array('category' => 'Tracking');
  400. $resultcategories[] = array('category' => 'Search');
  401. $resultcategories[] = array('category' => 'Stylesheets');
  402. $resultcategories[] = array('category' => 'Templates');
  403. $resultcategories[] = array('category' => 'Plugins');
  404. $resultcategories[] = array('category' => 'LDAP');
  405. $resultcategories[] = array('category' => 'CAS');
  406. $resultcategories[] = array('category' => 'Shibboleth');
  407. $resultcategories[] = array('category' => 'Facebook');
  408. foreach ($resultcategories as $row) {
  409. $url = array();
  410. $url['url'] = api_get_self()."?category=".$row['category'];
  411. $url['content'] = Display::return_icon(
  412. $action_images[strtolower($row['category'])],
  413. api_ucfirst(get_lang($row['category'])),
  414. '',
  415. ICON_SIZE_MEDIUM
  416. );
  417. if (strtolower($row['category']) == strtolower($_GET['category'])) {
  418. $url['active'] = true;
  419. }
  420. $action_array[] = $url;
  421. }
  422. echo Display::actions($action_array);
  423. echo '<br />';
  424. echo $form_search_html;
  425. if ($watermark_deleted) {
  426. Display :: display_normal_message(get_lang('FileDeleted'));
  427. }
  428. // Displaying the message that the settings have been stored.
  429. if (isset($form) && $form->validate()) {
  430. Display::display_confirmation_message(get_lang('SettingsStored'));
  431. if (is_array($message)) {
  432. foreach ($message as $type => $content) {
  433. foreach ($content as $msg) {
  434. echo Display::return_message($msg, $type);
  435. }
  436. }
  437. }
  438. }
  439. if (!empty($_GET['category'])) {
  440. switch ($_GET['category']) {
  441. case 'Regions':
  442. handle_regions();
  443. break;
  444. case 'Plugins':
  445. // Displaying the extensions: Plugins.
  446. // This will be available to all the sites (access_urls).
  447. if (isset($_POST['submit_dashboard_plugins'])) {
  448. $affected_rows = DashboardManager::store_dashboard_plugins($_POST);
  449. if ($affected_rows) {
  450. // add event to system log
  451. $user_id = api_get_user_id();
  452. $category = $_GET['category'];
  453. event_system(
  454. LOG_CONFIGURATION_SETTINGS_CHANGE,
  455. LOG_CONFIGURATION_SETTINGS_CATEGORY,
  456. $category,
  457. api_get_utc_datetime(),
  458. $user_id
  459. );
  460. Display :: display_confirmation_message(get_lang('DashboardPluginsHaveBeenUpdatedSucesslly'));
  461. }
  462. }
  463. echo '<script>
  464. $(function(){
  465. $("#tabs").tabs();
  466. });
  467. </script>';
  468. echo '<div id="tabs">';
  469. echo '<ul>';
  470. echo '<li><a href="#tabs-1">'.get_lang('Plugins').'</a></li>';
  471. echo '<li><a href="#tabs-2">'.get_lang('DashboardPlugins').'</a></li>';
  472. echo '<li><a href="#tabs-3">'.get_lang('ConfigureExtensions').'</a></li>';
  473. echo '</ul>';
  474. echo '<div id="tabs-1">';
  475. handle_plugins();
  476. echo '</div>';
  477. echo '<div id="tabs-2">';
  478. DashboardManager::handle_dashboard_plugins();
  479. echo '</div>';
  480. echo '<div id="tabs-3">';
  481. handle_extensions();
  482. echo '</div>';
  483. echo '</div>';
  484. break;
  485. case 'Stylesheets':
  486. // Displaying the extensions: Stylesheets.
  487. handle_stylesheets();
  488. if (isset($_POST)) {
  489. api_set_setting_last_update();
  490. }
  491. $form->display();
  492. break;
  493. case 'Search':
  494. handle_search();
  495. break;
  496. case 'Templates':
  497. handle_templates();
  498. break;
  499. case 'search_setting':
  500. search_setting($_REQUEST['search_field']);
  501. if (isset($_REQUEST['search_field'])) {
  502. $form->display();
  503. }
  504. break;
  505. default:
  506. if (isset($form)) {
  507. $form->display();
  508. }
  509. }
  510. }
  511. /* FOOTER */
  512. Display :: display_footer();