From 5d5a26c4c126354cbba3618367e32abd78018369 Mon Sep 17 00:00:00 2001 From: julmis <julmis> Date: Mon, 23 Aug 2004 21:31:30 +0000 Subject: [PATCH] Added reset to defaults --- admin/editor.html | 5 ++++- admin/editor.php | 57 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/admin/editor.html b/admin/editor.html index 65cfba9719..8be6ac141c 100644 --- a/admin/editor.html +++ b/admin/editor.html @@ -1,5 +1,6 @@ <form method="post" action="<?php print($_SERVER['PHP_SELF']);?>"> <table border="0" cellpadding="4" cellspacing="2"> +<tr><td colspan="3"><input type="checkbox" name="resettodefaults" value="" /> <?php print_string("editorresettodefaults");?>.</td></tr> <tr><td colspan="3"><strong><?php print_string("editorcommonsettings");?></strong></td></tr> <tr> <td align="right" valign="top"><?php print_string("editorbgcolor");?>:</td> @@ -40,13 +41,15 @@ <tr><td colspan="2"><strong><?php print_string("editorfontlist");?></strong></td> <td valign="top"><?php print_string("edhelpfontlist");?></td></tr> <?php - foreach($fontlist as $fontkey => $fontvalue) { + if(is_array($fontlist)) { + foreach($fontlist as $fontkey => $fontvalue) { ?> <tr> <td align="right"><input type="text" name="fontname[]" size="15" value="<?php print($fontkey);?>"></td> <td colspan="2"><input type="text" name="fontnamevalue[]" size="30" value="<?php print($fontvalue);?>"></td> </tr> <?php + } } ?> <tr> diff --git a/admin/editor.php b/admin/editor.php index 9fae276cbe..32305b60f2 100644 --- a/admin/editor.php +++ b/admin/editor.php @@ -10,8 +10,16 @@ if($data = data_submitted()) { - if(!(editor_update_config($data))) { - error("Editor settings could not be updated!"); + // do we want default values? + if(isset($data->resettodefaults)) { + if(!(reset_to_defaults())) { + error("Editor settings could not be restored!"); + } + } else { + + if(!(editor_update_config($data))) { + error("Editor settings could not be updated!"); + } } redirect("$CFG->wwwroot/$CFG->admin/editor.php", get_string("changessaved"), 1); @@ -65,11 +73,21 @@ function editor_update_config ($data) { return false; } + // Make array for unwanted characters. + $nochars = array(chr(33),chr(34),chr(35),chr(36),chr(37), + chr(38),chr(39),chr(40),chr(41),chr(42), + chr(43),chr(46),chr(47),chr(58),chr(59), + chr(60),chr(61),chr(62),chr(63),chr(64), + chr(91),chr(92),chr(93),chr(94),chr(95), + chr(96),chr(123),chr(124),chr(125),chr(126)); + + $fontlist = ''; + // make font string for($i = 0; $i < count($data->fontname); $i++) { if(!empty($data->fontname[$i])) { - $fontlist .= $data->fontname[$i] .":"; - $fontlist .= $data->fontnamevalue[$i] .";"; + $fontlist .= str_replace($nochars, "", $data->fontname[$i]) .":"; + $fontlist .= str_replace($nochars, "", $data->fontnamevalue[$i]) .";"; } } // strip last semicolon @@ -77,11 +95,11 @@ function editor_update_config ($data) { // make array of values to update $updatedata = array(); - $updatedata['editorbackgroundcolor'] = $data->backgroundcolor; - $updatedata['editorfontfamily'] = $data->fontfamily; - $updatedata['editorfontsize'] = $data->fontsize; - $updatedata['editorkillword'] = $data->killword; - $updatedata['editorspelling'] = $data->spelling; + $updatedata['editorbackgroundcolor'] = !empty($data->backgroundcolor) ? $data->backgroundcolor : "#ffffff"; + $updatedata['editorfontfamily'] = !empty($data->fontfamily) ? str_replace($nochars,"",$data->fontfamily) : "Times New Roman, Times"; + $updatedata['editorfontsize'] = !empty($data->fontsize) ? $data->fontsize : ""; + $updatedata['editorkillword'] = !empty($data->killword) ? $data->killword : "true"; + $updatedata['editorspelling'] = !empty($data->spelling) ? $data->spelling : 0; $updatedata['editorfontlist'] = $fontlist; foreach($updatedata as $name => $value) { @@ -92,4 +110,25 @@ function editor_update_config ($data) { return true; } + +function reset_to_defaults () { + global $CFG; + include_once($CFG->dirroot .'/lib/defaults.php'); + + $updatedata = array(); + + $updatedata['editorbackgroundcolor'] = $defaults['editorbackgroundcolor']; + $updatedata['editorfontfamily'] = $defaults['editorfontfamily']; + $updatedata['editorfontsize'] = $defaults['editorfontsize']; + $updatedata['editorkillword'] = $defaults['editorkillword']; + $updatedata['editorspelling'] = $defaults['editorspelling']; + $updatedata['editorfontlist'] = $defaults['editorfontlist']; + + foreach($updatedata as $name => $value) { + if(!(set_config($name, $value))) { + return false; + } + } + return true; +} ?> \ No newline at end of file -- 2.39.5