settings.php 21 KB

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