Permalink
Browse files

Added reset to defaults

  • Loading branch information...
julmis
julmis committed Aug 23, 2004
1 parent 9c52ca1 commit 5d5a26c4c126354cbba3618367e32abd78018369
Showing with 52 additions and 10 deletions.
  1. +4 −1 admin/editor.html
  2. +48 −9 admin/editor.php
View
@@ -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>
View
@@ -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,23 +73,33 @@ 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
$fontlist = substr($fontlist, 0, strlen($fontlist) - 1);
// 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;
+}
?>

0 comments on commit 5d5a26c

Please sign in to comment.