settings.php 21 KB

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