settings.php 21 KB

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