settings.php 20 KB

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