settings.php 19 KB

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