settings.php 21 KB

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