settings.php 21 KB

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