settings.php 21 KB

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