settings.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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).'fileManage.lib.php';
  25. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  26. require_once api_get_path(LIBRARY_PATH).'dashboard.lib.php';
  27. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  28. require_once 'settings.lib.php';
  29. // Setting the section (for the tabs).
  30. $this_section = SECTION_PLATFORM_ADMIN;
  31. $_SESSION['this_section'] = $this_section;
  32. // Access restrictions.
  33. api_protect_admin_script();
  34. // Settings to avoid
  35. $settings_to_avoid = array(
  36. 'gradebook_enable' => 'false',
  37. 'use_document_title' => 'true',
  38. 'example_material_course_creation' => 'true' // ON by default - now we have this option when we create a course
  39. );
  40. $convert_byte_to_mega_list = array('dropbox_max_filesize', 'message_max_upload_filesize', 'default_document_quotum', 'default_group_quotum');
  41. // Submit stylesheets.
  42. if (isset($_POST['submit_stylesheets'])) {
  43. $message = store_stylesheets();
  44. header("Location: ".api_get_self()."?category=stylesheets");
  45. exit;
  46. }
  47. if (isset($_POST['style'])) {
  48. Display::$preview_style = $_POST['style'];
  49. }
  50. // Database table definitions.
  51. $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  52. // Setting breadcrumbs.
  53. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  54. // Setting the name of the tool.
  55. $tool_name = get_lang('PlatformConfigSettings');
  56. if (empty($_GET['category'])) {
  57. $_GET['category'] = 'Platform';
  58. }
  59. $watermark_deleted = false;
  60. if (isset($_GET['delete_watermark'])) {
  61. $watermark_deleted = PDF::delete_watermark();
  62. }
  63. if (isset($_POST['new_model']) && isset($_POST['number_evaluations']) && !empty($_POST['new_model'])) {
  64. $count = intval($_POST['number_evaluations']);
  65. $string_to_save = '';
  66. for ($i = 1; $i<=$count;$i++) {
  67. $sum = "+";
  68. if ($i == $count) {
  69. $sum = "";
  70. }
  71. //Note: We use rand here because there is a unique index in the settings_options table. The 'variable' and 'value' fields must be unique
  72. $string_to_save .= rand(1, 3).'*X'.$sum;
  73. }
  74. $string_to_save .= "/".$count;
  75. $array_to_save = array();
  76. $array_to_save['variable'] = 'grading_model';
  77. $array_to_save['display_text'] = $_POST['new_model'];
  78. $array_to_save['value'] = $string_to_save;
  79. $result = api_set_setting_option($array_to_save);
  80. }
  81. if (isset($_GET['action']) && $_GET['action'] == 'delete_grading') {
  82. $id = intval($_GET['id']);
  83. api_delete_setting_option($id);
  84. }
  85. // Build the form.
  86. if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search'))) {
  87. $form = new FormValidator('settings', 'post', 'settings.php?category='.$_GET['category']);
  88. /*$renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>');
  89. $renderer->setElementTemplate('<div class="sectionvalue">{element}</div><div class="sectioncomment">{label}</div>'."\n");*/
  90. //$renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>');
  91. $my_category = Database::escape_string($_GET['category']);
  92. $sqlcountsettings = "SELECT COUNT(*) FROM $table_settings_current WHERE category='".$my_category."' AND type<>'checkbox'";
  93. $resultcountsettings = Database::query($sqlcountsettings);
  94. $countsetting = Database::fetch_array($resultcountsettings);
  95. if ($_configuration['access_url'] == 1) {
  96. $settings = api_get_settings($my_category, 'group', $_configuration['access_url']);
  97. } else {
  98. $url_info = api_get_access_url($_configuration['access_url']);
  99. if ($url_info['active'] == 1) {
  100. // The default settings of Chamilo
  101. $settings = api_get_settings($my_category, 'group', 1, 0);
  102. // The settings that are changeable from a particular site.
  103. $settings_by_access = api_get_settings($my_category, 'group', $_configuration['access_url'], 1);
  104. //echo '<pre>';
  105. //print_r($settings_by_access);
  106. $settings_by_access_list = array();
  107. foreach ($settings_by_access as $row) {
  108. if (empty($row['variable']))
  109. $row['variable'] = 0;
  110. if (empty($row['subkey']))
  111. $row['subkey'] = 0;
  112. if (empty($row['category']))
  113. $row['category'] = 0;
  114. // One more validation if is changeable.
  115. if ($row['access_url_changeable'] == 1)
  116. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = $row;
  117. else
  118. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = array();
  119. }
  120. }
  121. }
  122. $default_values = array();
  123. foreach ($settings as $row) {
  124. if (in_array($row['variable'], $settings_to_avoid)) { continue; }
  125. $anchor_name = $row['variable'].(!empty($row['subkey']) ? '_'.$row['subkey'] : '');
  126. $form->addElement('html',"\n<a name=\"$anchor_name\"></a>\n");
  127. ($countsetting['0'] % 10) < 5 ? $b = $countsetting['0'] - 10 : $b = $countsetting['0'];
  128. if ($i % 10 == 0 and $i < $b AND $i != 0) {
  129. $form->addElement('html', '<div align="right">');
  130. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  131. $form->addElement('html', '</div>');
  132. }
  133. $i++;
  134. //$form->addElement('header', null, get_lang($row['title']));
  135. if ($row['access_url_changeable'] == '1' && $_configuration['multiple_access_urls']) {
  136. $form->addElement('html', '<div style="float: right;">'.Display::return_icon('shared_setting.png', get_lang('SharedSettingIconComment')).'</div>');
  137. }
  138. $hideme = array();
  139. $hide_element = false;
  140. if ($_configuration['access_url'] != 1) {
  141. if ($row['access_url_changeable'] == 0) {
  142. // We hide the element in other cases (checkbox, radiobutton) we 'freeze' the element.
  143. $hide_element = true;
  144. $hideme = array('disabled');
  145. } elseif ($url_info['active'] == 1) {
  146. // We show the elements.
  147. if (empty($row['variable']))
  148. $row['variable'] = 0;
  149. if (empty($row['subkey']))
  150. $row['subkey'] = 0;
  151. if (empty($row['category']))
  152. $row['category'] = 0;
  153. if (is_array($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ])) {
  154. // We are sure that the other site have a selected value.
  155. if ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ]['selected_value'] != '')
  156. $row['selected_value'] =$settings_by_access_list[$row['variable']] [$row['subkey']] [ $row['category'] ]['selected_value'];
  157. }
  158. // There is no else{} statement because we load the default $row['selected_value'] of the main Chamilo site.
  159. }
  160. }
  161. switch ($row['type']) {
  162. case 'textfield':
  163. if (in_array($row['variable'], $convert_byte_to_mega_list)) {
  164. $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment']), get_lang('MB')), array('maxlength' => '8'));
  165. $form->applyFilter($row['variable'], 'html_filter');
  166. $default_values[$row['variable']] = round($row['selected_value']/1024/1024, 1);
  167. } elseif ($row['variable'] == 'account_valid_duration') {
  168. $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('maxlength' => '5'));
  169. $form->applyFilter($row['variable'], 'html_filter');
  170. $default_values[$row['variable']] = $row['selected_value'];
  171. // For platform character set selection: Conversion of the textfield to a select box with valid values.
  172. } elseif ($row['variable'] == 'platform_charset') {
  173. $current_system_encoding = api_refine_encoding_id(trim($row['selected_value']));
  174. $valid_encodings = array_flip(api_get_valid_encodings());
  175. if (!isset($valid_encodings[$current_system_encoding])) {
  176. $is_alias_encoding = false;
  177. foreach ($valid_encodings as $encoding) {
  178. if (api_equal_encodings($encoding, $current_system_encoding)) {
  179. $is_alias_encoding = true;
  180. $current_system_encoding = $encoding;
  181. break;
  182. }
  183. }
  184. if (!$is_alias_encoding) {
  185. $valid_encodings[$current_system_encoding] = $current_system_encoding;
  186. }
  187. }
  188. foreach ($valid_encodings as $key => &$encoding) {
  189. if (api_is_encoding_supported($key) && Database::is_encoding_supported($key)) {
  190. $encoding = $key;
  191. } else {
  192. //$encoding = $key.' (n.a.)';
  193. unset($valid_encodings[$key]);
  194. }
  195. }
  196. $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $valid_encodings);
  197. $default_values[$row['variable']] = $current_system_encoding;
  198. } else {
  199. $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $hideme);
  200. $form->applyFilter($row['variable'],'html_filter');
  201. $default_values[$row['variable']] = $row['selected_value'];
  202. }
  203. break;
  204. case 'textarea':
  205. if ($row['variable'] == 'header_extra_content') {
  206. $file = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt';
  207. $value = '';
  208. if (file_exists($file)) {
  209. $value = file_get_contents($file);
  210. }
  211. $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10','cols'=>'50'), $hideme);
  212. $default_values[$row['variable']] = $value;
  213. } elseif ($row['variable'] == 'footer_extra_content') {
  214. $file = api_get_path(SYS_PATH).api_get_home_path().'footer_extra_content.txt';
  215. $value = '';
  216. if (file_exists($file)) {
  217. $value = file_get_contents($file);
  218. }
  219. $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10','cols'=>'50'), $hideme);
  220. $default_values[$row['variable']] = $value;
  221. } else {
  222. $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10','cols'=>'50'), $hideme);
  223. $default_values[$row['variable']] = $row['selected_value'];
  224. }
  225. break;
  226. case 'radio':
  227. $values = api_get_settings_options($row['variable']);
  228. $group = array ();
  229. if (is_array($values )) {
  230. foreach ($values as $key => $value) {
  231. $element = & $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']);
  232. if ($hide_element) {
  233. $element->freeze();
  234. }
  235. $group[] = $element;
  236. }
  237. }
  238. $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), '', false); //julio
  239. $default_values[$row['variable']] = $row['selected_value'];
  240. break;
  241. case 'checkbox';
  242. // 1. We collect all the options of this variable.
  243. $sql = "SELECT * FROM settings_current WHERE variable='".$row['variable']."' AND access_url = 1";
  244. $result = Database::query($sql);
  245. $group = array ();
  246. while ($rowkeys = Database::fetch_array($result)) {
  247. //if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; }
  248. // Profile tab option should be hidden when the social tool is enabled.
  249. if (api_get_setting('allow_social_tool') == 'true') {
  250. if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') { continue; }
  251. }
  252. // Hiding the gradebook option.
  253. if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') { continue; }
  254. $element = & $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext']));
  255. if ($row['access_url_changeable'] == 1) {
  256. // 2. We look into the DB if there is a setting for a specific access_url.
  257. $access_url = $_configuration['access_url'];
  258. if (empty($access_url )) $access_url = 1;
  259. $sql = "SELECT selected_value FROM settings_current WHERE variable='".$rowkeys['variable']."' AND subkey='".$rowkeys['subkey']."' AND subkeytext='".$rowkeys['subkeytext']."' AND access_url = $access_url";
  260. $result_access = Database::query($sql);
  261. $row_access = Database::fetch_array($result_access);
  262. if ($row_access['selected_value'] == 'true' && !$form->isSubmitted()) {
  263. $element->setChecked(true);
  264. }
  265. } else {
  266. if ($rowkeys['selected_value'] == 'true' && !$form->isSubmitted()) {
  267. $element->setChecked(true);
  268. }
  269. }
  270. if ($hide_element) {
  271. $element->freeze();
  272. }
  273. $group[] = $element;
  274. }
  275. $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])),'');
  276. break;
  277. case 'link':
  278. $form->addElement('static', null, array(get_lang($row['title']), get_lang($row['comment'])), get_lang('CurrentValue').' : '.$row['selected_value'], $hideme);
  279. break;
  280. /*
  281. * 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.
  282. * The functions being called must be added to the file settings.lib.php.
  283. */
  284. case 'select':
  285. $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), call_user_func('select_'.$row['variable']), $hideme);
  286. $default_values[$row['variable']] = $row['selected_value'];
  287. break;
  288. case 'custom_gradebook':
  289. case 'custom':
  290. $values = api_get_settings_options($row['variable']);
  291. //$renderer = & $form->defaultRenderer();
  292. //$renderer->setElementTemplate('{label} - {element}<!-- BEGIN label_2 --><span class="help-block">{label_2}</span><!-- END label_2 -->');
  293. $numbers = array();
  294. for($j=1;$j<=20;$j++) {
  295. $numbers[$j] = $j;
  296. }
  297. if (!empty($values)) {
  298. foreach($values as $option) {
  299. $group = array();
  300. $id = $option['id'];
  301. $option_id = $row['variable']."[$id]";
  302. $group[] = $form->createElement('text', $option_id.'[display_text]', array(get_lang($row['title']), get_lang($row['comment'])),'class="begin_model"');
  303. $default_values[$option_id.'[display_text]'] = $option['display_text'];
  304. $parts = api_grading_model_functions($option['value'], 'to_array');
  305. $denominator = $parts['denominator'];
  306. $j = 1;
  307. foreach($parts['items'] as $item) {
  308. $letter = $item['letter'];
  309. $value = $item['value'];
  310. $group[] =$form->createElement('static','<div>');
  311. $class = 'number';
  312. if ($j == 1) {
  313. $class = 'first_number';
  314. }
  315. $group[] = $form->createElement('select', $option_id.'[items]['.$j.']', array('dd'), $numbers, array('class'=>$class));
  316. $sum = ' ';
  317. if ($j != count($parts['items'])) {
  318. $sum = ' + ';
  319. }
  320. //$group[] =$form->createElement('static',' * '.$letter.$sum);
  321. $default_values[$option_id.'[items]['.$j.']'] = $value;
  322. $j++;
  323. }
  324. $group[] = $form->createElement('select', $option_id.'[denominator]', array('/'), $numbers,'class="denominator"');
  325. $group[] = $form->createElement('button', "delete", get_lang('Delete'), array('type'=>'button', 'id'=>$id, 'onclick'=>"delete_grading_model('$id');"));
  326. $default_values[$option_id.'[denominator]'] = $denominator;
  327. $form->addGroup($group, '', get_lang($row['title']), ' ');
  328. }
  329. }
  330. //New Grading Model form
  331. $group = array();
  332. $group[] = $form->createElement('text', 'new_model', array(get_lang('AddNewModel')));
  333. $group[] = $form->createElement('select', 'number_evaluations', array(''), $numbers,'');
  334. $form->addGroup($group, '', get_lang('AddNewModel'), "&nbsp;&nbsp;".get_lang('NumberOfSubEvaluations')."&nbsp;");
  335. $form->addElement('style_submit_button', null, get_lang('Add'), 'class="add"');
  336. break;
  337. /*
  338. * Used to display custom values for the gradebook score display
  339. */
  340. /* this configuration is moved now inside gradebook tool
  341. case 'gradebook_score_display_custom':
  342. if(api_get_setting('gradebook_score_display_custom', 'my_display_custom') == 'false') {
  343. $form->addElement('static', null, null, get_lang('GradebookActivateScoreDisplayCustom'));
  344. } else {
  345. // Get score displays.
  346. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/scoredisplay.class.php';
  347. $scoredisplay = ScoreDisplay::instance();
  348. $customdisplays = $scoredisplay->get_custom_score_display_settings();
  349. $nr_items = (count($customdisplays)!='0') ? count($customdisplays) : '1';
  350. $form->addElement('hidden', 'gradebook_score_display_custom_values_maxvalue', '100');
  351. $form->addElement('hidden', 'gradebook_score_display_custom_values_minvalue', '0');
  352. $form->addElement('static', null, null, get_lang('ScoreInfo'));
  353. $scorenull[] = $form->CreateElement('static', null, null, get_lang('Between'));
  354. $form->setDefaults(array (
  355. 'beginscore' => '0'
  356. ));
  357. $scorenull[] = $form->CreateElement('text', 'beginscore', null, array (
  358. 'size' => 5,
  359. 'maxlength' => 5,
  360. 'disabled' => 'disabled'
  361. ));
  362. $scorenull[] = $form->CreateElement('static', null, null, ' %');
  363. $form->addGroup($scorenull, '', '', ' ');
  364. for ($counter= 1; $counter <= 20; $counter++) {
  365. $renderer = $form->defaultRenderer();
  366. $elementTemplateTwoLabel =
  367. '<div id=' . $counter . ' style="display: '.(($counter<=$nr_items)?'inline':'none').';">
  368. <p><!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}
  369. <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} % =';
  370. $elementTemplateTwoLabel2 =
  371. '<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error -->&nbsp{element}
  372. <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>
  373. <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>
  374. </div></p></div>';
  375. $scorebetw= array ();
  376. $form->addElement('text', 'gradebook_score_display_custom_values_endscore[' . $counter . ']', null, array (
  377. 'size' => 5,
  378. 'maxlength' => 5,
  379. 'id' => 'txta-'.$counter
  380. ));
  381. $form->addElement('text', 'gradebook_score_display_custom_values_displaytext[' . $counter . ']', null,array (
  382. 'size' => 40,
  383. 'maxlength' => 40,
  384. 'id' => 'txtb-'.$counter
  385. ));
  386. $renderer->setElementTemplate($elementTemplateTwoLabel,'gradebook_score_display_custom_values_endscore[' . $counter . ']');
  387. $renderer->setElementTemplate($elementTemplateTwoLabel2,'gradebook_score_display_custom_values_displaytext[' . $counter . ']');
  388. $form->addRule('gradebook_score_display_custom_values_endscore[' . $counter . ']', get_lang('OnlyNumbers'), 'numeric');
  389. $form->addRule(array('gradebook_score_display_custom_values_endscore[' . $counter . ']', 'gradebook_score_display_custom_values_maxvalue'), get_lang('Over100'), 'compare', '<=');
  390. $form->addRule(array('gradebook_score_display_custom_values_endscore[' . $counter . ']', 'gradebook_score_display_custom_values_minvalue'), get_lang('UnderMin'), 'compare', '>');
  391. if ($customdisplays[$counter - 1]) {
  392. $default_values['gradebook_score_display_custom_values_endscore['.$counter.']'] = $customdisplays[$counter - 1]['score'];
  393. $default_values['gradebook_score_display_custom_values_displaytext['.$counter.']'] = $customdisplays[$counter - 1]['display'];
  394. }
  395. }
  396. }
  397. break;
  398. */
  399. }
  400. if ($row['variable'] == 'pdf_export_watermark_enable') {
  401. $url = PDF::get_watermark($course_code);
  402. $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark'));
  403. if ($url != false) {
  404. $delete_url = '<a href="?delete_watermark">'.Display::return_icon('delete.png',get_lang('DelImage')).'</a>';
  405. $form->addElement('html', '<a href="'.$url.'">'.$url.' '.$delete_url.'</a>');
  406. }
  407. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  408. $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  409. }
  410. if ($row['variable'] == 'timezone_value') {
  411. $timezone = $row['selected_value'];
  412. if (empty($timezone)) {
  413. $timezone = _api_get_timezone();
  414. }
  415. $form->addElement('html', sprintf(get_lang('LocalTimeUsingPortalTimezoneXIsY'), $timezone, api_get_local_time()));
  416. }
  417. }
  418. $form->addElement('html', '<div style="text-align: right; clear: both;">');
  419. $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
  420. $form->addElement('html', '</div>');
  421. $form->setDefaults($default_values);
  422. $message = array();
  423. if ($form->validate()) {
  424. $values = $form->exportValues();
  425. $pdf_export_watermark_path = $_FILES['pdf_export_watermark_path'];
  426. if (isset($pdf_export_watermark_path) && !empty($pdf_export_watermark_path['name'])) {
  427. $pdf_export_watermark_path_result = PDF::upload_watermark($pdf_export_watermark_path['name'], $pdf_export_watermark_path['tmp_name']);
  428. if ($pdf_export_watermark_path_result) {
  429. $message['confirmation'][] = get_lang('UplUploadSucceeded');
  430. } else {
  431. $message['warning'][] = get_lang('UplUnableToSaveFile').' '.get_lang('Folder').': '.api_get_path(SYS_CODE_PATH).'default_course_document/images';
  432. }
  433. unset($update_values['pdf_export_watermark_path']);
  434. }
  435. // Set true for allow_message_tool variable if social tool is actived
  436. foreach ($convert_byte_to_mega_list as $item) {
  437. if (isset($values[$item])) {
  438. $values[$item] = round($values[$item]*1024*1024);
  439. }
  440. }
  441. /*$values['dropbox_max_filesize'] = $values['dropbox_max_filesize']*1024*1024;
  442. $values['message_max_upload_filesize'] = $values['message_max_upload_filesize']*1024*1024;*/
  443. if ($values['allow_social_tool'] == 'true') {
  444. $values['allow_message_tool'] = 'true';
  445. }
  446. // quick patch to avoid gradebook_enable's value to be blanked
  447. /*
  448. if ($my_category == 'Gradebook') {
  449. $gb = 'false';
  450. $gb = api_get_setting('gradebook_enable');
  451. }*/
  452. // The first step is to set all the variables that have type=checkbox of the category
  453. // to false as the checkbox that is unchecked is not in the $_POST data and can
  454. // therefore not be set to false.
  455. // This, however, also means that if the process breaks on the third of five checkboxes, the others
  456. // will be set to false.
  457. $r = api_set_settings_category($my_category, 'false', $_configuration['access_url'], array('checkbox', 'radio'));
  458. // quick patch to avoid gradebook_enable's value to be blanked
  459. if ($my_category == 'Gradebook') {
  460. //api_set_setting('gradebook_enable', $gb, null, $my_category, $_configuration['access_url']);
  461. }
  462. foreach($settings_to_avoid as $key => $value) {
  463. api_set_setting($key, $value, null, null, $_configuration['access_url']);
  464. }
  465. // Save the settings.
  466. $keys = array();
  467. foreach ($values as $key => $value) {
  468. if (in_array($key, $settings_to_avoid)) { continue; }
  469. // Treat gradebook values in separate function.
  470. //if (strpos($key, 'gradebook_score_display_custom_values') === false) {
  471. if (!is_array($value)) {
  472. $old_value = api_get_setting($key);
  473. switch ($key) {
  474. case 'header_extra_content':
  475. file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/header_extra_content.txt', $value);
  476. $value = api_get_home_path().'/header_extra_content.txt';
  477. break;
  478. case 'footer_extra_content':
  479. file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/footer_extra_content.txt', $value);
  480. $value = api_get_home_path().'/footer_extra_content.txt';
  481. break;
  482. // URL validation for some settings.
  483. case 'InstitutionUrl':
  484. case 'course_validation_terms_and_conditions_url':
  485. $value = trim(Security::remove_XSS($value));
  486. if ($value != '') {
  487. // Here we accept absolute URLs only.
  488. if (strpos($value, '://') === false) {
  489. $value = 'http://'.$value;
  490. }
  491. if (!api_valid_url($value, true)) {
  492. // If the new (non-empty) URL value is invalid, then the old URL value stays.
  493. $value = $old_value;
  494. }
  495. }
  496. // If the new URL value is empty, then it will be stored (i.e. the setting will be deleted).
  497. break;
  498. // Validation against e-mail address for some settings.
  499. case 'emailAdministrator':
  500. $value = trim(Security::remove_XSS($value));
  501. if ($value != '' && !api_valid_email($value)) {
  502. // If the new (non-empty) e-mail address is invalid, then the old e-mail address stays.
  503. // If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted).
  504. $value = $old_value;
  505. }
  506. break;
  507. }
  508. if ($old_value != $value) $keys[] = $key;
  509. $result = api_set_setting($key, $value, null, null, $_configuration['access_url']);
  510. } else {
  511. if ($key == 'grading_model') {
  512. foreach ($value as $my_key => $option) {
  513. $array_to_save = array();
  514. //build this: 1*X+2*X+3*X/4
  515. $string_to_save = '';
  516. foreach ($option['items'] as $item) {
  517. $string_to_save .= $item.'*X+';
  518. }
  519. $string_to_save = substr($string_to_save, 0, strlen($string_to_save)- 1) . '/'.$option['denominator'];
  520. $array_to_save['display_text'] = $option['display_text'];
  521. $array_to_save['value'] = $string_to_save;
  522. $array_to_save['id'] = $my_key;
  523. $result = api_set_setting_option($array_to_save);
  524. }
  525. } else {
  526. $sql = "SELECT subkey FROM $table_settings_current WHERE variable = '$key'";
  527. $res = Database::query($sql);
  528. $subkeys = array();
  529. while ($row_subkeys = Database::fetch_array($res)) {
  530. // If subkey is changed:
  531. if ((isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'false') ||
  532. (!isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'true')) {
  533. $keys[] = $key;
  534. break;
  535. }
  536. }
  537. foreach ($value as $subkey => $subvalue) {
  538. $result = api_set_setting($key, 'true', $subkey, null, $_configuration['access_url']);
  539. }
  540. }
  541. }
  542. }
  543. // Add event configuration settings category to the system log.
  544. $user_id = api_get_user_id();
  545. $category = $_GET['category'];
  546. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
  547. // Add event configuration settings variable to the system log.
  548. if (is_array($keys) && count($keys) > 0) {
  549. foreach ($keys as $variable) {
  550. if (in_array($key, $settings_to_avoid)) { continue; }
  551. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_VARIABLE, $variable, api_get_utc_datetime(), $user_id);
  552. }
  553. }
  554. }
  555. }
  556. $htmlHeadXtra[] = '<script language="javascript">
  557. function delete_grading_model(id) {
  558. window.location = "settings.php?category=Gradebook&action=delete_grading&id=" + id;
  559. }
  560. $(document).ready(function() {
  561. var elements = ["B","C","D","E","F","G","H","I", "J", "K", "L","M","N","O","P","Q","R"];
  562. var i = 0;
  563. $(".formw").each(function(index) {
  564. $(this).find("*").each(function(index2) {
  565. if ($(this).hasClass("first_number")) {
  566. $(this).before("<b>( A * </b>");
  567. }
  568. if ($(this).hasClass("denominator")) {
  569. $(this).before("<b> \) / </b>");
  570. }
  571. if ($(this).hasClass("number")) {
  572. $(this).before("<b> + " + elements[i] + " * </b>");
  573. i++;
  574. }
  575. });
  576. i = 0;
  577. });
  578. });
  579. </script>';
  580. // Including the header (banner).
  581. Display :: display_header($tool_name);
  582. // The action images.
  583. $action_images['platform'] = 'platform.png';
  584. $action_images['course'] = 'course.png';
  585. $action_images['tools'] = 'tools.png';
  586. $action_images['user'] = 'user.png';
  587. $action_images['gradebook'] = 'gradebook.png';
  588. $action_images['ldap'] = 'ldap.png';
  589. $action_images['cas'] = 'user_access.png';
  590. $action_images['security'] = 'security.png';
  591. $action_images['languages'] = 'languages.png';
  592. $action_images['tuning'] = 'tuning.png';
  593. $action_images['plugins'] = 'plugins.png';
  594. $action_images['stylesheets'] = 'stylesheets.png';
  595. $action_images['templates'] = 'template.png';
  596. $action_images['search'] = 'search.png';
  597. $action_images['editor'] = 'html_editor.png';
  598. $action_images['timezones'] = 'timezone.png';
  599. $action_images['extra'] = 'wizard.png';
  600. $action_images['tracking'] = 'statistics.png';
  601. $action_images['gradebook2'] = 'gradebook.png';
  602. // Grabbing the categories.
  603. $resultcategories = api_get_settings_categories(array('stylesheets', 'Plugins', 'Templates', 'Search'));
  604. echo "<div class=\"actions\">";
  605. foreach ($resultcategories as $row) {
  606. echo "<a href=\"".api_get_self()."?category=".$row['category']."\">".Display::return_icon($action_images[strtolower($row['category'])], api_ucfirst(get_lang($row['category'])),'',ICON_SIZE_MEDIUM)."</a>";
  607. }
  608. echo "<a href=\"".api_get_self()."?category=Search\">".Display::return_icon($action_images['search'], api_ucfirst(get_lang('Search')),'',ICON_SIZE_MEDIUM)."</a>";
  609. echo "<a href=\"".api_get_self()."?category=stylesheets\">".Display::return_icon($action_images['stylesheets'], api_ucfirst(get_lang('Stylesheets')),'',ICON_SIZE_MEDIUM)."</a>";
  610. echo "<a href=\"".api_get_self()."?category=Templates\">".Display::return_icon($action_images['templates'], api_ucfirst(get_lang('Templates')),'',ICON_SIZE_MEDIUM)."</a>";
  611. echo "<a href=\"".api_get_self()."?category=Plugins\">".Display::return_icon($action_images['plugins'], api_ucfirst(get_lang('Plugins')),'',ICON_SIZE_MEDIUM)."</a>";
  612. echo "</div>";
  613. if ($watermark_deleted) {
  614. Display :: display_normal_message(get_lang('FileDeleted'));
  615. }
  616. // Displaying the message that the settings have been stored.
  617. if (isset($form) && $form->validate()) {
  618. Display::display_confirmation_message(get_lang('SettingsStored'));
  619. if (is_array($message)) {
  620. foreach($message as $type => $content) {
  621. foreach($content as $msg) {
  622. echo Display::return_message($msg, $type);
  623. }
  624. }
  625. }
  626. }
  627. if (!empty($_GET['category'])) {
  628. switch ($_GET['category']) {
  629. case 'Plugins':
  630. // Displaying the extensions: Plugins.
  631. // This will be available to all the sites (access_urls).
  632. if (isset($_POST['submit_dashboard_plugins'])) {
  633. $affected_rows = DashboardManager::store_dashboard_plugins($_POST);
  634. if ($affected_rows) {
  635. // add event to system log
  636. $user_id = api_get_user_id();
  637. $category = $_GET['category'];
  638. event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
  639. Display :: display_confirmation_message(get_lang('DashboardPluginsHaveBeenUpdatedSucesslly'));
  640. }
  641. }
  642. handle_plugins();
  643. DashboardManager::handle_dashboard_plugins();
  644. break;
  645. case 'stylesheets':
  646. // Displaying the extensions: Stylesheets.
  647. handle_stylesheets();
  648. break;
  649. case 'Search':
  650. handle_search();
  651. break;
  652. case 'Templates':
  653. handle_templates();
  654. break;
  655. default:
  656. $form->display();
  657. }
  658. }
  659. /* FOOTER */
  660. Display :: display_footer();