settings.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 api_get_path(LIBRARY_PATH).'dashboard.lib.php';
  28. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  29. require_once api_get_path(LIBRARY_PATH).'plugin.lib.php';
  30. require_once 'settings.lib.php';
  31. // Setting the section (for the tabs).
  32. $this_section = SECTION_PLATFORM_ADMIN;
  33. $_SESSION['this_section'] = $this_section;
  34. // Access restrictions.
  35. api_protect_admin_script();
  36. // Settings to avoid
  37. $settings_to_avoid = array(
  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('dropbox_max_filesize', 'message_max_upload_filesize', 'default_document_quotum', 'default_group_quotum');
  42. // Submit stylesheets.
  43. if (isset($_POST['submit_stylesheets'])) {
  44. $message = store_stylesheets();
  45. header("Location: ".api_get_self()."?category=stylesheets");
  46. exit;
  47. }
  48. if (isset($_POST['style'])) {
  49. Display::$preview_style = $_POST['style'];
  50. }
  51. // Database table definitions.
  52. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  53. // Setting breadcrumbs.
  54. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  55. // Setting the name of the tool.
  56. $tool_name = get_lang('PlatformConfigSettings');
  57. if (empty($_GET['category'])) {
  58. $_GET['category'] = 'Platform';
  59. }
  60. $watermark_deleted = false;
  61. if (isset($_GET['delete_watermark'])) {
  62. $watermark_deleted = PDF::delete_watermark();
  63. }
  64. if (isset($_GET['action']) && $_GET['action'] == 'delete_grading') {
  65. $id = intval($_GET['id']);
  66. api_delete_setting_option($id);
  67. }
  68. $settings = null;
  69. // Build the form.
  70. if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search'))) {
  71. $my_category = Database::escape_string($_GET['category']);
  72. if ($_configuration['access_url'] == 1) {
  73. $settings = api_get_settings($my_category, 'group', $_configuration['access_url']);
  74. } else {
  75. $url_info = api_get_access_url($_configuration['access_url']);
  76. if ($url_info['active'] == 1) {
  77. // The default settings of Chamilo
  78. $settings = api_get_settings($my_category, 'group', 1, 0);
  79. // The settings that are changeable from a particular site.
  80. $settings_by_access = api_get_settings($my_category, 'group', $_configuration['access_url'], 1);
  81. $settings_by_access_list = array();
  82. foreach ($settings_by_access as $row) {
  83. if (empty($row['variable']))
  84. $row['variable'] = 0;
  85. if (empty($row['subkey']))
  86. $row['subkey'] = 0;
  87. if (empty($row['category']))
  88. $row['category'] = 0;
  89. // One more validation if is changeable.
  90. if ($row['access_url_changeable'] == 1)
  91. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = $row;
  92. else
  93. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = array();
  94. }
  95. }
  96. }
  97. if (isset($_GET['category']) && $_GET['category'] == 'search_setting') {
  98. if (!empty($_REQUEST['search_field'])) {
  99. $settings = search_setting($_REQUEST['search_field']);
  100. }
  101. }
  102. $form = generate_settings_form($settings, $settings_by_access_list);
  103. $message = array();
  104. if ($form->validate()) {
  105. $values = $form->exportValues();
  106. $pdf_export_watermark_path = $_FILES['pdf_export_watermark_path'];
  107. if (isset($pdf_export_watermark_path) && !empty($pdf_export_watermark_path['name'])) {
  108. $pdf_export_watermark_path_result = PDF::upload_watermark($pdf_export_watermark_path['name'], $pdf_export_watermark_path['tmp_name']);
  109. if ($pdf_export_watermark_path_result) {
  110. $message['confirmation'][] = get_lang('UplUploadSucceeded');
  111. } else {
  112. $message['warning'][] = get_lang('UplUnableToSaveFile').' '.get_lang('Folder').': '.api_get_path(SYS_CODE_PATH).'default_course_document/images';
  113. }
  114. unset($update_values['pdf_export_watermark_path']);
  115. }
  116. // Set true for allow_message_tool variable if social tool is actived
  117. foreach ($convert_byte_to_mega_list as $item) {
  118. if (isset($values[$item])) {
  119. $values[$item] = round($values[$item]*1024*1024);
  120. }
  121. }
  122. if ($values['allow_social_tool'] == 'true') {
  123. $values['allow_message_tool'] = 'true';
  124. }
  125. // The first step is to set all the variables that have type=checkbox of the category
  126. // to false as the checkbox that is unchecked is not in the $_POST data and can
  127. // therefore not be set to false.
  128. // This, however, also means that if the process breaks on the third of five checkboxes, the others
  129. // will be set to false.
  130. //$r = api_set_settings_category($my_category, 'false', $_configuration['access_url'], array('checkbox', 'radio'));
  131. //This is amore accurate way of updating to false the checboxes and radios the settings
  132. foreach ($values as $key => $value) {
  133. if (in_array($key, $settings_to_avoid)) { continue; }
  134. $key = Database::escape_string($key);
  135. $sql = "UPDATE $table_settings_current SET selected_value = 'false' WHERE variable = '".$key."' AND access_url = ".intval($_configuration['access_url'])." AND type IN ('checkbox', 'radio') ";
  136. $res = Database::query($sql);
  137. }
  138. /*foreach($settings_to_avoid as $key => $value) {
  139. api_set_setting($key, $value, null, null, $_configuration['access_url']);
  140. }*/
  141. // Save the settings.
  142. $keys = array();
  143. foreach ($values as $key => $value) {
  144. if (in_array($key, $settings_to_avoid)) { continue; }
  145. //
  146. // Treat gradebook values in separate function.
  147. //if (strpos($key, 'gradebook_score_display_custom_values') === false) {
  148. if (!is_array($value)) {
  149. $old_value = api_get_setting($key);
  150. switch ($key) {
  151. case 'header_extra_content':
  152. file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/header_extra_content.txt', $value);
  153. $value = api_get_home_path().'/header_extra_content.txt';
  154. break;
  155. case 'footer_extra_content':
  156. file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/footer_extra_content.txt', $value);
  157. $value = api_get_home_path().'/footer_extra_content.txt';
  158. break;
  159. // URL validation for some settings.
  160. case 'InstitutionUrl':
  161. case 'course_validation_terms_and_conditions_url':
  162. $value = trim(Security::remove_XSS($value));
  163. if ($value != '') {
  164. // Here we accept absolute URLs only.
  165. if (strpos($value, '://') === false) {
  166. $value = 'http://'.$value;
  167. }
  168. if (!api_valid_url($value, true)) {
  169. // If the new (non-empty) URL value is invalid, then the old URL value stays.
  170. $value = $old_value;
  171. }
  172. }
  173. // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted).
  174. break;
  175. // Validation against e-mail address for some settings.
  176. case 'emailAdministrator':
  177. $value = trim(Security::remove_XSS($value));
  178. if ($value != '' && !api_valid_email($value)) {
  179. // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays.
  180. // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted).
  181. $value = $old_value;
  182. }
  183. break;
  184. }
  185. if ($old_value != $value) $keys[] = $key;
  186. $result = api_set_setting($key, $value, null, null, $_configuration['access_url']);
  187. } else {
  188. $sql = "SELECT subkey FROM $table_settings_current WHERE variable = '$key'";
  189. $res = Database::query($sql);
  190. while ($row_subkeys = Database::fetch_array($res)) {
  191. // If subkey is changed:
  192. if ((isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'false') ||
  193. (!isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'true')) {
  194. $keys[] = $key;
  195. break;
  196. }
  197. }
  198. foreach ($value as $subkey => $subvalue) {
  199. $result = api_set_setting($key, 'true', $subkey, null, $_configuration['access_url']);
  200. }
  201. }
  202. }
  203. // Add event configuration settings category to the system log.
  204. $user_id = api_get_user_id();
  205. $category = $_GET['category'];
  206. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
  207. // Add event configuration settings variable to the system log.
  208. if (is_array($keys) && count($keys) > 0) {
  209. foreach ($keys as $variable) {
  210. if (in_array($key, $settings_to_avoid)) { continue; }
  211. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_VARIABLE, $variable, api_get_utc_datetime(), $user_id);
  212. }
  213. }
  214. }
  215. }
  216. $htmlHeadXtra[] = '<script>
  217. var hide_icon = "'.api_get_path(WEB_IMG_PATH).'shared_setting_na.png";
  218. var show_icon = "'.api_get_path(WEB_IMG_PATH).'shared_setting.png";
  219. var url = "'.api_get_path(WEB_AJAX_PATH).'admin.ajax.php?a=update_changeable_setting";
  220. $(function(){
  221. $(".share_this_setting").on("click", function() {
  222. var my_img = $(this).find("img");
  223. var link = $(this);
  224. $.ajax({
  225. url: url,
  226. data: {changeable: $(this).attr("data_status"), id: $(this).attr("data_to_send") },
  227. success: function(data) {
  228. if (data == 1) {
  229. if (link.attr("data_status") == 1) {
  230. my_img.attr("src", show_icon);
  231. link.attr("data_status", 0);
  232. } else {
  233. my_img.attr("src", hide_icon);
  234. link.attr("data_status", 1);
  235. }
  236. }
  237. }
  238. });
  239. });
  240. });
  241. </script>';
  242. // Including the header (banner).
  243. Display :: display_header($tool_name);
  244. // The action images.
  245. $action_images['platform'] = 'platform.png';
  246. $action_images['course'] = 'course.png';
  247. $action_images['tools'] = 'tools.png';
  248. $action_images['user'] = 'user.png';
  249. $action_images['gradebook'] = 'gradebook.png';
  250. $action_images['ldap'] = 'ldap.png';
  251. $action_images['cas'] = 'user_access.png';
  252. $action_images['security'] = 'security.png';
  253. $action_images['languages'] = 'languages.png';
  254. $action_images['tuning'] = 'tuning.png';
  255. $action_images['plugins'] = 'plugins.png';
  256. $action_images['stylesheets'] = 'stylesheets.png';
  257. $action_images['templates'] = 'template.png';
  258. $action_images['search'] = 'search.png';
  259. $action_images['editor'] = 'html_editor.png';
  260. $action_images['timezones'] = 'timezone.png';
  261. $action_images['extra'] = 'wizard.png';
  262. $action_images['tracking'] = 'statistics.png';
  263. $action_images['gradebook'] = 'gradebook.png';
  264. $action_images['search'] = 'search.png';
  265. $action_images['stylesheets'] = 'stylesheets.png';
  266. $action_images['templates'] = 'template.png';
  267. $action_images['plugins'] = 'plugins.png';
  268. $action_images['shibboleth'] = 'shibboleth.png';
  269. $action_images['facebook'] = 'facebook.png';
  270. // Grabbing the categories.
  271. $resultcategories = api_get_settings_categories(array('stylesheets', 'Plugins', 'Templates', 'Search'));
  272. $action_array = array();
  273. $resultcategories[] = array('category' => 'Search');
  274. $resultcategories[] = array('category' => 'Stylesheets');
  275. $resultcategories[] = array('category' => 'Templates');
  276. $resultcategories[] = array('category' => 'Plugins');
  277. foreach ($resultcategories as $row) {
  278. $url = array();
  279. $url['url'] = api_get_self()."?category=".$row['category'];
  280. $url['content'] = Display::return_icon($action_images[strtolower($row['category'])], api_ucfirst(get_lang($row['category'])),'',ICON_SIZE_MEDIUM);
  281. if (strtolower($row['category']) == strtolower($_GET['category'])) {
  282. $url['active'] = true;
  283. }
  284. $action_array[] = $url;
  285. }
  286. echo Display::actions($action_array);
  287. $form_search = new FormValidator('search_settings', 'get', api_get_self() , null, array('class'=>'vertical'));
  288. $form_search->addElement('text', 'search_field');
  289. $form_search->addElement('hidden', 'category', 'search_setting');
  290. $form_search->addElement('style_submit_button', 'submit_button', get_lang('Search'), 'value="submit_button", class="search"');
  291. $form_search->setDefaults(array('search_field' => $_REQUEST['search_field']));
  292. $form_search->display();
  293. if ($watermark_deleted) {
  294. Display :: display_normal_message(get_lang('FileDeleted'));
  295. }
  296. // Displaying the message that the settings have been stored.
  297. if (isset($form) && $form->validate()) {
  298. Display::display_confirmation_message(get_lang('SettingsStored'));
  299. if (is_array($message)) {
  300. foreach($message as $type => $content) {
  301. foreach($content as $msg) {
  302. echo Display::return_message($msg, $type);
  303. }
  304. }
  305. }
  306. }
  307. if (!empty($_GET['category'])) {
  308. switch ($_GET['category']) {
  309. case 'Regions':
  310. handle_regions();
  311. break;
  312. case 'Plugins':
  313. // Displaying the extensions: Plugins.
  314. // This will be available to all the sites (access_urls).
  315. if (isset($_POST['submit_dashboard_plugins'])) {
  316. $affected_rows = DashboardManager::store_dashboard_plugins($_POST);
  317. if ($affected_rows) {
  318. // add event to system log
  319. $user_id = api_get_user_id();
  320. $category = $_GET['category'];
  321. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
  322. Display :: display_confirmation_message(get_lang('DashboardPluginsHaveBeenUpdatedSucesslly'));
  323. }
  324. }
  325. handle_plugins();
  326. DashboardManager::handle_dashboard_plugins();
  327. handle_extensions();
  328. break;
  329. case 'stylesheets':
  330. // Displaying the extensions: Stylesheets.
  331. handle_stylesheets();
  332. break;
  333. case 'Search':
  334. handle_search();
  335. break;
  336. case 'Templates':
  337. handle_templates();
  338. break;
  339. case 'search_setting':
  340. search_setting($_REQUEST['search_field']);
  341. if (isset($_REQUEST['search_field'])) {
  342. $form->display();
  343. }
  344. break;
  345. default:
  346. $form->display();
  347. }
  348. }
  349. /* FOOTER */
  350. Display :: display_footer();