settings.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { continue; }
  178. $key = Database::escape_string($key);
  179. $sql = "UPDATE $table_settings_current SET selected_value = 'false' WHERE variable = '".$key."' AND access_url = ".intval($url_id)." AND type IN ('checkbox', 'radio') ";
  180. $res = Database::query($sql);
  181. }
  182. /*foreach($settings_to_avoid as $key => $value) {
  183. api_set_setting($key, $value, null, null, $_configuration['access_url']);
  184. }*/
  185. // Save the settings.
  186. $keys = array();
  187. foreach ($values as $key => $value) {
  188. if (in_array($key, $settings_to_avoid)) { continue; }
  189. // Avoid form elements which have nothing to do with settings
  190. if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { continue; }
  191. //
  192. // Treat gradebook values in separate function.
  193. //if (strpos($key, 'gradebook_score_display_custom_values') === false) {
  194. if (!is_array($value)) {
  195. $old_value = api_get_setting($key);
  196. switch ($key) {
  197. case 'header_extra_content':
  198. file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/header_extra_content.txt', $value);
  199. $value = api_get_home_path().'/header_extra_content.txt';
  200. break;
  201. case 'footer_extra_content':
  202. file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/footer_extra_content.txt', $value);
  203. $value = api_get_home_path().'/footer_extra_content.txt';
  204. break;
  205. // URL validation for some settings.
  206. case 'InstitutionUrl':
  207. case 'course_validation_terms_and_conditions_url':
  208. $value = trim(Security::remove_XSS($value));
  209. if ($value != '') {
  210. // Here we accept absolute URLs only.
  211. if (strpos($value, '://') === false) {
  212. $value = 'http://'.$value;
  213. }
  214. if (!api_valid_url($value, true)) {
  215. // If the new (non-empty) URL value is invalid, then the old URL value stays.
  216. $value = $old_value;
  217. }
  218. }
  219. // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted).
  220. break;
  221. // Validation against e-mail address for some settings.
  222. case 'emailAdministrator':
  223. $value = trim(Security::remove_XSS($value));
  224. if ($value != '' && !api_valid_email($value)) {
  225. // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays.
  226. // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted).
  227. $value = $old_value;
  228. }
  229. break;
  230. }
  231. if ($old_value != $value) $keys[] = $key;
  232. $result = api_set_setting($key, $value, null, null, $url_id);
  233. } else {
  234. $sql = "SELECT subkey FROM $table_settings_current WHERE variable = '$key'";
  235. $res = Database::query($sql);
  236. while ($row_subkeys = Database::fetch_array($res)) {
  237. // If subkey is changed:
  238. if ((isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'false') ||
  239. (!isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'true')) {
  240. $keys[] = $key;
  241. break;
  242. }
  243. }
  244. foreach ($value as $subkey => $subvalue) {
  245. $result = api_set_setting($key, 'true', $subkey, null, $url_id);
  246. }
  247. }
  248. }
  249. // Add event configuration settings category to the system log.
  250. $user_id = api_get_user_id();
  251. $category = $_GET['category'];
  252. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
  253. // Add event configuration settings variable to the system log.
  254. if (is_array($keys) && count($keys) > 0) {
  255. foreach ($keys as $variable) {
  256. if (in_array($key, $settings_to_avoid)) { continue; }
  257. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_VARIABLE, $variable, api_get_utc_datetime(), $user_id);
  258. }
  259. }
  260. }
  261. }
  262. $htmlHeadXtra[] = '<script>
  263. var hide_icon = "'.api_get_path(WEB_IMG_PATH).'shared_setting_na.png";
  264. var show_icon = "'.api_get_path(WEB_IMG_PATH).'shared_setting.png";
  265. var url = "'.api_get_path(WEB_AJAX_PATH).'admin.ajax.php?a=update_changeable_setting";
  266. $(function() {
  267. $(".share_this_setting").on("click", function() {
  268. var my_img = $(this).find("img");
  269. var link = $(this);
  270. $.ajax({
  271. url: url,
  272. data: { changeable: $(this).attr("data_status"), id: $(this).attr("data_to_send") },
  273. success: function(data) {
  274. if (data == 1) {
  275. if (link.attr("data_status") == 1) {
  276. my_img.attr("src", show_icon);
  277. link.attr("data_status", 0);
  278. } else {
  279. my_img.attr("src", hide_icon);
  280. link.attr("data_status", 1);
  281. }
  282. }
  283. }
  284. });
  285. });
  286. });
  287. </script>';
  288. // Including the header (banner).
  289. Display :: display_header($tool_name);
  290. // The action images.
  291. $action_images['platform'] = 'platform.png';
  292. $action_images['course'] = 'course.png';
  293. $action_images['session'] = 'session.png';
  294. $action_images['tools'] = 'tools.png';
  295. $action_images['user'] = 'user.png';
  296. $action_images['gradebook'] = 'gradebook.png';
  297. $action_images['ldap'] = 'ldap.png';
  298. $action_images['cas'] = 'user_access.png';
  299. $action_images['security'] = 'security.png';
  300. $action_images['languages'] = 'languages.png';
  301. $action_images['tuning'] = 'tuning.png';
  302. $action_images['templates'] = 'template.png';
  303. $action_images['search'] = 'search.png';
  304. $action_images['editor'] = 'html_editor.png';
  305. $action_images['timezones'] = 'timezone.png';
  306. $action_images['extra'] = 'wizard.png';
  307. $action_images['tracking'] = 'statistics.png';
  308. $action_images['gradebook'] = 'gradebook.png';
  309. $action_images['search'] = 'search.png';
  310. $action_images['stylesheets'] = 'stylesheets.png';
  311. $action_images['templates'] = 'template.png';
  312. $action_images['plugins'] = 'plugins.png';
  313. $action_images['shibboleth'] = 'shibboleth.png';
  314. $action_images['facebook'] = 'facebook.png';
  315. // Grabbing the categories.
  316. //$resultcategories = api_get_settings_categories(array('stylesheets', 'Plugins', 'Templates', 'Search'));
  317. $action_array = array();
  318. $resultcategories = array();
  319. $resultcategories[] = array('category' => 'Platform');
  320. $resultcategories[] = array('category' => 'Course');
  321. $resultcategories[] = array('category' => 'Session');
  322. $resultcategories[] = array('category' => 'Languages');
  323. $resultcategories[] = array('category' => 'User');
  324. $resultcategories[] = array('category' => 'Tools');
  325. $resultcategories[] = array('category' => 'Editor');
  326. $resultcategories[] = array('category' => 'Security');
  327. $resultcategories[] = array('category' => 'Tuning');
  328. $resultcategories[] = array('category' => 'Gradebook');
  329. $resultcategories[] = array('category' => 'Timezones');
  330. $resultcategories[] = array('category' => 'Tracking');
  331. $resultcategories[] = array('category' => 'Search');
  332. $resultcategories[] = array('category' => 'Stylesheets');
  333. $resultcategories[] = array('category' => 'Templates');
  334. $resultcategories[] = array('category' => 'Plugins');
  335. $resultcategories[] = array('category' => 'LDAP');
  336. $resultcategories[] = array('category' => 'CAS');
  337. $resultcategories[] = array('category' => 'Shibboleth');
  338. $resultcategories[] = array('category' => 'Facebook');
  339. foreach ($resultcategories as $row) {
  340. $url = array();
  341. $url['url'] = api_get_self()."?category=".$row['category'];
  342. $url['content'] = Display::return_icon($action_images[strtolower($row['category'])], api_ucfirst(get_lang($row['category'])),'',ICON_SIZE_MEDIUM);
  343. if (strtolower($row['category']) == strtolower($_GET['category'])) {
  344. $url['active'] = true;
  345. }
  346. $action_array[] = $url;
  347. }
  348. echo Display::actions($action_array);
  349. echo '<br />';
  350. echo $form_search_html;
  351. if ($watermark_deleted) {
  352. Display :: display_normal_message(get_lang('FileDeleted'));
  353. }
  354. // Displaying the message that the settings have been stored.
  355. if (isset($form) && $form->validate()) {
  356. Display::display_confirmation_message(get_lang('SettingsStored'));
  357. if (is_array($message)) {
  358. foreach($message as $type => $content) {
  359. foreach($content as $msg) {
  360. echo Display::return_message($msg, $type);
  361. }
  362. }
  363. }
  364. }
  365. if (!empty($_GET['category'])) {
  366. switch ($_GET['category']) {
  367. case 'Regions':
  368. handle_regions();
  369. break;
  370. case 'Plugins':
  371. // Displaying the extensions: Plugins.
  372. // This will be available to all the sites (access_urls).
  373. if (isset($_POST['submit_dashboard_plugins'])) {
  374. $affected_rows = DashboardManager::store_dashboard_plugins($_POST);
  375. if ($affected_rows) {
  376. // add event to system log
  377. $user_id = api_get_user_id();
  378. $category = $_GET['category'];
  379. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
  380. Display :: display_confirmation_message(get_lang('DashboardPluginsHaveBeenUpdatedSucesslly'));
  381. }
  382. }
  383. echo '<script>
  384. $(function(){
  385. $("#tabs").tabs();
  386. });
  387. </script>';
  388. echo '<div id="tabs">';
  389. echo '<ul>';
  390. echo '<li><a href="#tabs-1">'.get_lang('Plugins').'</a></li>';
  391. echo '<li><a href="#tabs-2">'.get_lang('DashboardPlugins').'</a></li>';
  392. echo '<li><a href="#tabs-3">'.get_lang('ConfigureExtensions').'</a></li>';
  393. echo '</ul>';
  394. echo '<div id="tabs-1">';
  395. handle_plugins();
  396. echo '</div>';
  397. echo '<div id="tabs-2">';
  398. DashboardManager::handle_dashboard_plugins();
  399. echo '</div>';
  400. echo '<div id="tabs-3">';
  401. handle_extensions();
  402. echo '</div>';
  403. echo '</div>';
  404. break;
  405. case 'Stylesheets':
  406. // Displaying the extensions: Stylesheets.
  407. handle_stylesheets();
  408. break;
  409. case 'Search':
  410. handle_search();
  411. break;
  412. case 'Templates':
  413. handle_templates();
  414. break;
  415. case 'search_setting':
  416. search_setting($_REQUEST['search_field']);
  417. if (isset($_REQUEST['search_field'])) {
  418. $form->display();
  419. }
  420. break;
  421. default:
  422. if (isset($form))
  423. $form->display();
  424. }
  425. }
  426. /* FOOTER */
  427. Display :: display_footer();