settings.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. // Resetting the course id.
  21. $cidReset = true;
  22. // Including some necessary library files.
  23. require_once '../inc/global.inc.php';
  24. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  25. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  26. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  27. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  28. require_once api_get_path(LIBRARY_PATH).'dashboard.lib.php';
  29. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  30. require_once 'settings.lib.php';
  31. // Setting the section (for the tabs).
  32. $this_section = SECTION_PLATFORM_ADMIN;
  33. $_SESSION['this_section'] = $this_section;
  34. // Access restrictions.
  35. api_protect_admin_script();
  36. /* This fragment of code has been moved to gradebook_scoring_system file.
  37. if ($_GET['category'] == 'Gradebook') {
  38. // Used for the gradebook system
  39. $htmlHeadXtra[]= '
  40. <script language="JavaScript">
  41. function plusItem(item)
  42. {
  43. document.getElementById(item).style.display = "inline";
  44. document.getElementById("plus-"+item).style.display = "none";
  45. document.getElementById("min-"+(item-1)).style.display = "none";
  46. document.getElementById("min-"+(item)).style.display = "inline";
  47. document.getElementById("plus-"+(item+1)).style.display = "inline";
  48. document.getElementById("txta-"+(item)).value = "100";
  49. document.getElementById("txta-"+(item-1)).value = "";
  50. }
  51. function minItem(item)
  52. {
  53. if (item != 1)
  54. {
  55. document.getElementById(item).style.display = "none";
  56. document.getElementById("txta-"+item).value = "";
  57. document.getElementById("txtb-"+item).value = "";
  58. document.getElementById("plus-"+item).style.display = "inline";
  59. document.getElementById("min-"+(item-1)).style.display = "inline";
  60. document.getElementById("txta-"+(item-1)).value = "100";
  61. }
  62. if (item = 1)
  63. {
  64. document.getElementById("min-"+(item)).style.display = "none";
  65. }
  66. }
  67. </script>';
  68. }
  69. */
  70. // Submit stylesheets.
  71. if (isset($_POST['submit_stylesheets'])) {
  72. $message = store_stylesheets();
  73. header("Location: ".api_get_self()."?category=stylesheets");
  74. exit;
  75. }
  76. // Database table definitions.
  77. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  78. // Setting breadcrumbs.
  79. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  80. // Setting the name of the tool.
  81. $tool_name = get_lang('DokeosConfigSettings');
  82. if (empty($_GET['category'])) {
  83. $_GET['category'] = 'Platform';
  84. }
  85. $watermark_deleted = false;
  86. if (isset($_GET['delete_watermark'])) {
  87. $watermark_deleted = PDF::delete_watermark();
  88. }
  89. // Build the form.
  90. if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search'))) {
  91. $form = new FormValidator('settings', 'post', 'settings.php?category='.$_GET['category']);
  92. $renderer = & $form->defaultRenderer();
  93. $renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>'."\n");
  94. $renderer->setElementTemplate('<div class="sectioncomment">{label}</div>'."\n".'<div class="sectionvalue">{element}</div>'."\n");
  95. $my_category = Database::escape_string($_GET['category']);
  96. $sqlcountsettings = "SELECT COUNT(*) FROM $table_settings_current WHERE category='".$my_category."' AND type<>'checkbox'";
  97. $resultcountsettings = Database::query($sqlcountsettings);
  98. $countsetting = Database::fetch_array($resultcountsettings);
  99. if ($_configuration['access_url'] == 1) {
  100. $settings = api_get_settings($my_category, 'group', $_configuration['access_url']);
  101. } else {
  102. $url_info = api_get_access_url($_configuration['access_url']);
  103. if ($url_info['active'] == 1) {
  104. // The default settings of Chamilo
  105. $settings = api_get_settings($my_category, 'group', 1, 0);
  106. // The settings that are changeable from a particular site.
  107. $settings_by_access = api_get_settings($my_category, 'group', $_configuration['access_url'], 1);
  108. //echo '<pre>';
  109. //print_r($settings_by_access);
  110. $settings_by_access_list = array();
  111. foreach ($settings_by_access as $row) {
  112. if (empty($row['variable']))
  113. $row['variable'] = 0;
  114. if (empty($row['subkey']))
  115. $row['subkey'] = 0;
  116. if (empty($row['category']))
  117. $row['category'] = 0;
  118. // One more validation if is changeable.
  119. if ($row['access_url_changeable'] == 1)
  120. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = $row;
  121. else
  122. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = array();
  123. }
  124. }
  125. }
  126. //print_r($settings_by_access_list);echo '</pre>';
  127. //$sqlsettings = "SELECT DISTINCT * FROM $table_settings_current WHERE category='$my_category' GROUP BY variable ORDER BY id ASC";
  128. //$resultsettings = Database::query($sqlsettings);
  129. //while ($row = Database::fetch_array($resultsettings))
  130. $default_values = array();
  131. foreach ($settings as $row) {
  132. // Settings to avoid
  133. $rows_to_avoid = array('gradebook_enable');
  134. if (in_array($row['variable'], $rows_to_avoid)) { continue; }
  135. $anchor_name = $row['variable'].(!empty($row['subkey']) ? '_'.$row['subkey'] : '');
  136. $form->addElement('html',"\n<a name=\"$anchor_name\"></a>\n");
  137. ($countsetting['0'] % 10) < 5 ? $b = $countsetting['0'] - 10 : $b = $countsetting['0'];
  138. if ($i % 10 == 0 and $i < $b) {
  139. $form->addElement('html', '<div align="right">');
  140. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  141. $form->addElement('html', '</div>');
  142. }
  143. $i++;
  144. $form->addElement('header', null, get_lang($row['title']));
  145. if ($row['access_url_changeable'] == '1' && $_configuration['multiple_access_urls']) {
  146. $form->addElement('html', '<div style="float: right;">'.Display::return_icon('shared_setting.png', get_lang('SharedSettingIconComment')).'</div>');
  147. }
  148. $hideme = array();
  149. $hide_element = false;
  150. if ($_configuration['access_url'] != 1) {
  151. if ($row['access_url_changeable'] == 0) {
  152. // We hide the element in other cases (checkbox, radiobutton) we 'freeze' the element.
  153. $hide_element = true;
  154. $hideme = array('disabled');
  155. } elseif ($url_info['active'] == 1) {
  156. // We show the elements.
  157. if (empty($row['variable']))
  158. $row['variable'] = 0;
  159. if (empty($row['subkey']))
  160. $row['subkey'] = 0;
  161. if (empty($row['category']))
  162. $row['category'] = 0;
  163. if (is_array($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ])) {
  164. // We are sure that the other site have a selected value.
  165. if ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ]['selected_value'] != '')
  166. $row['selected_value'] =$settings_by_access_list[$row['variable']] [$row['subkey']] [ $row['category'] ]['selected_value'];
  167. }
  168. // There is no else{} statement because we load the default $row['selected_value'] of the main Chamilo site.
  169. }
  170. }
  171. switch ($row['type']) {
  172. case 'textfield':
  173. if ($row['variable'] == 'account_valid_duration') {
  174. $form->addElement('text', $row['variable'], get_lang($row['comment']), array('maxlength' => '5'));
  175. $form->applyFilter($row['variable'], 'html_filter');
  176. $default_values[$row['variable']] = $row['selected_value'];
  177. // For platform character set selection: Conversion of the textfield to a select box with valid values.
  178. } elseif ($row['variable'] == 'platform_charset') {
  179. $current_system_encoding = api_refine_encoding_id(trim($row['selected_value']));
  180. $valid_encodings = array_flip(api_get_valid_encodings());
  181. if (!isset($valid_encodings[$current_system_encoding])) {
  182. $is_alias_encoding = false;
  183. foreach ($valid_encodings as $encoding) {
  184. if (api_equal_encodings($encoding, $current_system_encoding)) {
  185. $is_alias_encoding = true;
  186. $current_system_encoding = $encoding;
  187. break;
  188. }
  189. }
  190. if (!$is_alias_encoding) {
  191. $valid_encodings[$current_system_encoding] = $current_system_encoding;
  192. }
  193. }
  194. foreach ($valid_encodings as $key => &$encoding) {
  195. if (api_is_encoding_supported($key) && Database::is_encoding_supported($key)) {
  196. $encoding = $key;
  197. } else {
  198. //$encoding = $key.' (n.a.)';
  199. unset($valid_encodings[$key]);
  200. }
  201. }
  202. $form->addElement('select', $row['variable'], get_lang($row['comment']), $valid_encodings);
  203. $default_values[$row['variable']] = $current_system_encoding;
  204. } else {
  205. $form->addElement('text', $row['variable'], get_lang($row['comment']), $hideme);
  206. $form->applyFilter($row['variable'],'html_filter');
  207. $default_values[$row['variable']] = $row['selected_value'];
  208. }
  209. break;
  210. case 'textarea':
  211. $form->addElement('textarea', $row['variable'], get_lang($row['comment']), $hideme);
  212. $default_values[$row['variable']] = $row['selected_value'];
  213. break;
  214. case 'radio':
  215. $values = get_settings_options($row['variable']);
  216. $group = array ();
  217. if (is_array($values )) {
  218. foreach ($values as $key => $value) {
  219. $element = & $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']);
  220. if ($hide_element) {
  221. $element->freeze();
  222. }
  223. $group[] = $element;
  224. }
  225. }
  226. $form->addGroup($group, $row['variable'], get_lang($row['comment']), '<br />', false);
  227. $default_values[$row['variable']] = $row['selected_value'];
  228. break;
  229. case 'checkbox';
  230. // 1. We collect all the options of this variable.
  231. $sql = "SELECT * FROM settings_current WHERE variable='".$row['variable']."' AND access_url = 1";
  232. $result = Database::query($sql);
  233. $group = array ();
  234. while ($rowkeys = Database::fetch_array($result)) {
  235. //if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; }
  236. // Profile tab option should be hidden when the social tool is enabled.
  237. if (api_get_setting('allow_social_tool') == 'true') {
  238. if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') { continue; }
  239. }
  240. // Hiding the gradebook option.
  241. if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') { continue; }
  242. $element = & $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext']));
  243. if ($row['access_url_changeable'] == 1) {
  244. // 2. We look into the DB if there is a setting for a specific access_url.
  245. $access_url = $_configuration['access_url'];
  246. if (empty($access_url )) $access_url = 1;
  247. $sql = "SELECT selected_value FROM settings_current WHERE variable='".$rowkeys['variable']."' AND subkey='".$rowkeys['subkey']."' AND subkeytext='".$rowkeys['subkeytext']."' AND access_url = $access_url";
  248. $result_access = Database::query($sql);
  249. $row_access = Database::fetch_array($result_access);
  250. if ($row_access['selected_value'] == 'true' && !$form->isSubmitted()) {
  251. $element->setChecked(true);
  252. }
  253. } else {
  254. if ($rowkeys['selected_value'] == 'true' && !$form->isSubmitted()) {
  255. $element->setChecked(true);
  256. }
  257. }
  258. if ($hide_element) {
  259. $element->freeze();
  260. }
  261. $group[] = $element;
  262. }
  263. $form->addGroup($group, $row['variable'], get_lang($row['comment']), '<br />'."\n");
  264. break;
  265. case 'link':
  266. $form->addElement('static', null, get_lang($row['comment']), get_lang('CurrentValue').' : '.$row['selected_value'], $hideme);
  267. break;
  268. /*
  269. * To populate its list of options, the select type dynamically calls a function that must be called select_ + the name of the variable being displayed.
  270. * The functions being called must be added to the file settings.lib.php.
  271. */
  272. case 'select':
  273. $form->addElement('select', $row['variable'], get_lang($row['comment']), call_user_func('select_'.$row['variable']), $hideme);
  274. $default_values[$row['variable']] = $row['selected_value'];
  275. break;
  276. /*
  277. * Used to display custom values for the gradebook score display
  278. */
  279. /* this configuration is moved now inside gradebook tool
  280. case 'gradebook_score_display_custom':
  281. if(api_get_setting('gradebook_score_display_custom', 'my_display_custom') == 'false') {
  282. $form->addElement('static', null, null, get_lang('GradebookActivateScoreDisplayCustom'));
  283. } else {
  284. // Get score displays.
  285. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/scoredisplay.class.php';
  286. $scoredisplay = ScoreDisplay::instance();
  287. $customdisplays = $scoredisplay->get_custom_score_display_settings();
  288. $nr_items = (count($customdisplays)!='0') ? count($customdisplays) : '1';
  289. $form->addElement('hidden', 'gradebook_score_display_custom_values_maxvalue', '100');
  290. $form->addElement('hidden', 'gradebook_score_display_custom_values_minvalue', '0');
  291. $form->addElement('static', null, null, get_lang('ScoreInfo'));
  292. $scorenull[] = $form->CreateElement('static', null, null, get_lang('Between'));
  293. $form->setDefaults(array (
  294. 'beginscore' => '0'
  295. ));
  296. $scorenull[] = $form->CreateElement('text', 'beginscore', null, array (
  297. 'size' => 5,
  298. 'maxlength' => 5,
  299. 'disabled' => 'disabled'
  300. ));
  301. $scorenull[] = $form->CreateElement('static', null, null, ' %');
  302. $form->addGroup($scorenull, '', '', ' ');
  303. for ($counter= 1; $counter <= 20; $counter++) {
  304. $renderer = $form->defaultRenderer();
  305. $elementTemplateTwoLabel =
  306. '<div id=' . $counter . ' style="display: '.(($counter<=$nr_items)?'inline':'none').';">
  307. <p><!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}
  308. <div class="formw"><!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> <b>'.get_lang('And').'</b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp{element} % =';
  309. $elementTemplateTwoLabel2 =
  310. '<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error -->&nbsp{element}
  311. <a href="javascript:minItem(' . ($counter) . ')"><img style="display: '.(($counter >= $nr_items && $counter != 1) ? 'inline' : 'none').';" id="min-' . $counter . '" src="../img/gradebook_remove.gif" alt="'.get_lang('Delete').'" title="'.get_lang('Delete').'"></img></a>
  312. <a href="javascript:plusItem(' . ($counter+1) . ')"><img style="display: '.(($counter >= $nr_items) ? 'inline' : 'none').';" id="plus-' . ($counter+1) . '" src="../img/gradebook_add.gif" alt="'.get_lang('Add').'" title="'.get_lang('Add').'"></img></a>
  313. </div></p></div>';
  314. $scorebetw= array ();
  315. $form->addElement('text', 'gradebook_score_display_custom_values_endscore[' . $counter . ']', null, array (
  316. 'size' => 5,
  317. 'maxlength' => 5,
  318. 'id' => 'txta-'.$counter
  319. ));
  320. $form->addElement('text', 'gradebook_score_display_custom_values_displaytext[' . $counter . ']', null,array (
  321. 'size' => 40,
  322. 'maxlength' => 40,
  323. 'id' => 'txtb-'.$counter
  324. ));
  325. $renderer->setElementTemplate($elementTemplateTwoLabel,'gradebook_score_display_custom_values_endscore[' . $counter . ']');
  326. $renderer->setElementTemplate($elementTemplateTwoLabel2,'gradebook_score_display_custom_values_displaytext[' . $counter . ']');
  327. $form->addRule('gradebook_score_display_custom_values_endscore[' . $counter . ']', get_lang('OnlyNumbers'), 'numeric');
  328. $form->addRule(array('gradebook_score_display_custom_values_endscore[' . $counter . ']', 'gradebook_score_display_custom_values_maxvalue'), get_lang('Over100'), 'compare', '<=');
  329. $form->addRule(array('gradebook_score_display_custom_values_endscore[' . $counter . ']', 'gradebook_score_display_custom_values_minvalue'), get_lang('UnderMin'), 'compare', '>');
  330. if ($customdisplays[$counter - 1]) {
  331. $default_values['gradebook_score_display_custom_values_endscore['.$counter.']'] = $customdisplays[$counter - 1]['score'];
  332. $default_values['gradebook_score_display_custom_values_displaytext['.$counter.']'] = $customdisplays[$counter - 1]['display'];
  333. }
  334. }
  335. }
  336. break;
  337. */
  338. }
  339. if ($row['variable'] == 'pdf_export_watermark_enable') {
  340. $url = PDF::get_watermark($course_code);
  341. $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark'));
  342. if ($url != false) {
  343. $delete_url = '<a href="?delete_watermark">'.Display::return_icon('delete.png',get_lang('DelImage')).'</a>';
  344. $form->addElement('html', '<a href="'.$url.'">'.$url.' '.$delete_url.'</a>');
  345. }
  346. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  347. $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  348. }
  349. }
  350. $form->addElement('html', '<div style="text-align: right; clear: both;">');
  351. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  352. $form->addElement('html', '</div>');
  353. $form->setDefaults($default_values);
  354. $message = array();
  355. if ($form->validate()) {
  356. $values = $form->exportValues();
  357. $pdf_export_watermark_path = $_FILES['pdf_export_watermark_path'];
  358. if (isset($pdf_export_watermark_path) && !empty($pdf_export_watermark_path['name'])) {
  359. $pdf_export_watermark_path_result = PDF::upload_watermark($pdf_export_watermark_path['name'], $pdf_export_watermark_path['tmp_name']);
  360. if ($pdf_export_watermark_path_result) {
  361. $message['confirmation'][] = get_lang('UplUploadSucceeded');
  362. } else {
  363. $message['warning'][] = get_lang('UplUnableToSaveFile').' '.get_lang('Folder').': '.api_get_path(SYS_CODE_PATH).'default_course_document/images';
  364. }
  365. unset($update_values['pdf_export_watermark_path']);
  366. }
  367. // Set true for allow_message_tool variable if social tool is actived.
  368. if ($values['allow_social_tool'] == 'true') {
  369. $values['allow_message_tool'] = 'true';
  370. }
  371. // quick patch to avoid gradebook_enable's value to be blanked
  372. if ($my_category == 'Gradebook') {
  373. $gb = 'false';
  374. $gb = api_get_setting('gradebook_enable');
  375. }
  376. // The first step is to set all the variables that have type=checkbox of the category
  377. // to false as the checkbox that is unchecked is not in the $_POST data and can
  378. // therefore not be set to false.
  379. // This, however, also means that if the process breaks on the third of five checkboxes, the others
  380. // will be set to false.
  381. $r = api_set_settings_category($my_category, 'false', $_configuration['access_url'], array('checkbox', 'radio'));
  382. // quick patch to avoid gradebook_enable's value to be blanked
  383. if ($my_category == 'Gradebook') {
  384. api_set_setting('gradebook_enable', $gb, null, $my_category, $_configuration['access_url']);
  385. }
  386. //$sql = "UPDATE $table_settings_current SET selected_value='false' WHERE category='$my_category' AND type='checkbox'";
  387. //$result = Database::query($sql);
  388. // Save the settings.
  389. $keys = array();
  390. //$gradebook_score_display_custom_values = array();
  391. foreach ($values as $key => $value) {
  392. // Treat gradebook values in separate function.
  393. //if (strpos($key, 'gradebook_score_display_custom_values') === false) {
  394. if (!is_array($value)) {
  395. //$sql = "UPDATE $table_settings_current SET selected_value='".Database::escape_string($value)."' WHERE variable='$key'";
  396. //$result = Database::query($sql);
  397. $old_value = api_get_setting($key);
  398. switch ($key) {
  399. // URL validation for some settings.
  400. case 'InstitutionUrl':
  401. case 'course_validation_terms_and_conditions_url':
  402. $value = trim(Security::remove_XSS($value));
  403. if ($value != '') {
  404. // Here we accept absolute URLs only.
  405. if (strpos($value, '://') === false) {
  406. $value = 'http://'.$value;
  407. }
  408. if (!api_valid_url($value, true)) {
  409. // If the new (non-empty) URL value is invalid, then the old URL value stays.
  410. $value = $old_value;
  411. }
  412. }
  413. // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted).
  414. break;
  415. // Validation against e-mail address for some settings.
  416. case 'emailAdministrator':
  417. $value = trim(Security::remove_XSS($value));
  418. if ($value != '' && !api_valid_email($value)) {
  419. // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays.
  420. // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted).
  421. $value = $old_value;
  422. }
  423. break;
  424. }
  425. if ($old_value != $value) $keys[] = $key;
  426. $result = api_set_setting($key, $value, null, null, $_configuration['access_url']);
  427. } else {
  428. $sql = "SELECT subkey FROM $table_settings_current WHERE variable = '$key'";
  429. $res = Database::query($sql);
  430. $subkeys = array();
  431. while ($row_subkeys = Database::fetch_array($res)) {
  432. // If subkey is changed:
  433. if ((isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'false') ||
  434. (!isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'true')) {
  435. $keys[] = $key;
  436. break;
  437. }
  438. }
  439. foreach ($value as $subkey => $subvalue) {
  440. //$sql = "UPDATE $table_settings_current SET selected_value='true' WHERE variable='$key' AND subkey = '$subkey'";
  441. //$result = Database::query($sql);
  442. $result = api_set_setting($key, 'true', $subkey, null, $_configuration['access_url']);
  443. }
  444. }
  445. //} else {
  446. // $gradebook_score_display_custom_values[$key] = $value;
  447. //}
  448. }
  449. /*
  450. if (count($gradebook_score_display_custom_values) > 0) {
  451. update_gradebook_score_display_custom_values($gradebook_score_display_custom_values);
  452. }
  453. */
  454. // Add event configuration settings category to the system log.
  455. $time = time();
  456. $user_id = api_get_user_id();
  457. $category = $_GET['category'];
  458. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, $time, $user_id);
  459. // Add event configuration settings variable to the system log.
  460. if (is_array($keys) && count($keys) > 0) {
  461. foreach ($keys as $variable) {
  462. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_VARIABLE, $variable, $time, $user_id);
  463. }
  464. }
  465. //header('Location: settings.php?action=stored&category='.Security::remove_XSS($_GET['category']).'&message='.$message);
  466. //exit;
  467. }
  468. }
  469. // Including the header (banner).
  470. Display :: display_header($tool_name);
  471. // The action images.
  472. $action_images['platform'] = 'platform.png';
  473. $action_images['course'] = 'course.png';
  474. $action_images['tools'] = 'tools.png';
  475. $action_images['user'] = 'user.png';
  476. $action_images['gradebook'] = 'gradebook.png';
  477. $action_images['ldap'] = 'ldap.png';
  478. $action_images['security'] = 'security.png';
  479. $action_images['languages'] = 'languages.png';
  480. $action_images['tuning'] = 'tuning.png';
  481. $action_images['plugins'] = 'plugins.png';
  482. $action_images['stylesheets'] = 'stylesheets.png';
  483. $action_images['templates'] = 'template.png';
  484. $action_images['search'] = 'search.png';
  485. $action_images['editor'] = 'html_editor.png';
  486. $action_images['timezones'] = 'timezone.png';
  487. $action_images['extra'] = 'wizard.png';
  488. // Grabbing the categories.
  489. //$selectcategories = "SELECT DISTINCT category FROM ".$table_settings_current." WHERE category NOT IN ('stylesheets','Plugins')";
  490. //$resultcategories = Database::query($selectcategories);
  491. $resultcategories = api_get_settings_categories(array('stylesheets', 'Plugins', 'Templates', 'Search'));
  492. echo "<div class=\"actions\">";
  493. //while ($row = Database::fetch_array($resultcategories))
  494. foreach ($resultcategories as $row) {
  495. echo "<a href=\"".api_get_self()."?category=".$row['category']."\">".Display::return_icon($action_images[strtolower($row['category'])], api_ucfirst(get_lang($row['category'])),'','32')."</a>";
  496. }
  497. echo "<a href=\"".api_get_self()."?category=Search\">".Display::return_icon($action_images['search'], api_ucfirst(get_lang('Search')),'','32')."</a>";
  498. echo "<a href=\"".api_get_self()."?category=stylesheets\">".Display::return_icon($action_images['stylesheets'], api_ucfirst(get_lang('Stylesheets')),'','32')."</a>";
  499. echo "<a href=\"".api_get_self()."?category=Templates\">".Display::return_icon($action_images['templates'], api_ucfirst(get_lang('Templates')),'','32')."</a>";
  500. echo "<a href=\"".api_get_self()."?category=Plugins\">".Display::return_icon($action_images['plugins'], api_ucfirst(get_lang('Plugins')),'','32')."</a>";
  501. echo "</div>";
  502. if ($watermark_deleted) {
  503. Display :: display_normal_message(get_lang('FileDeleted'));
  504. }
  505. //api_display_tool_title($tool_name);
  506. // Displaying the message that the settings have been stored.
  507. if (isset($form) && $form->validate()) {
  508. Display::display_confirmation_message(get_lang('SettingsStored'));
  509. if (is_array($message)) {
  510. foreach($message as $type => $content) {
  511. foreach($content as $msg) {
  512. echo Display::return_message($msg, $type);
  513. }
  514. }
  515. }
  516. }
  517. if (!empty($_GET['category'])) {
  518. switch ($_GET['category']) {
  519. case 'Plugins':
  520. // Displaying the extensions: Plugins.
  521. // This will be available to all the sites (access_urls).
  522. if (isset($_POST['submit_dashboard_plugins'])) {
  523. $affected_rows = DashboardManager::store_dashboard_plugins($_POST);
  524. if ($affected_rows) {
  525. // add event to system log
  526. $time = time();
  527. $user_id = api_get_user_id();
  528. $category = $_GET['category'];
  529. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, $time, $user_id);
  530. Display :: display_confirmation_message(get_lang('DashboardPluginsHaveBeenUpdatedSucesslly'));
  531. }
  532. }
  533. handle_plugins();
  534. DashboardManager::handle_dashboard_plugins();
  535. break;
  536. case 'stylesheets':
  537. // Displaying the extensions: Stylesheets.
  538. handle_stylesheets();
  539. break;
  540. case 'Search':
  541. handle_search();
  542. break;
  543. case 'Templates':
  544. handle_templates();
  545. break;
  546. default:
  547. $form->display();
  548. }
  549. }
  550. /* FOOTER */
  551. Display :: display_footer();