]> git.mjollnir.org Git - moodle.git/commitdiff
Merging from MOODLE_17_STABLE:
authordefacer <defacer>
Tue, 27 Feb 2007 12:42:08 +0000 (12:42 +0000)
committerdefacer <defacer>
Tue, 27 Feb 2007 12:42:08 +0000 (12:42 +0000)
Fix for MDL-8402:
$CFG->calendar_weekdays wasn't saved correctly and misbehaved.

I took the opportunity to rewrite a little HTML too.

lib/adminlib.php
theme/standard/styles_layout.css

index 65a04be50544cefc7f290b066f14b752639a4c4a..c7b48ec44c64214853dd598cfbfbcaede93b7003 100644 (file)
@@ -2328,64 +2328,43 @@ class admin_setting_special_calendar_weekend extends admin_setting {
         $name = 'calendar_weekend';
         $visiblename = get_string('calendar_weekend', 'admin');
         $description = get_string('helpweekenddays', 'admin');
-        $default = array('u' => 1, 'm' => 0, 't' => 0, 'w' => 0, 'r' => 0, 'f' => 0, 's' => 1);
+        $default = 65; // Saturdays and Sundays
         parent::admin_setting($name, $visiblename, $description, $default);
     }
 
     function get_setting() {
         global $CFG;
-        if (isset($CFG->{$this->name})) {
-            $currentsetting = decbin($CFG->{$this->name});
-            $currentsetting = str_pad($currentsetting, 7, '0', STR_PAD_LEFT);
-            return array('u' => substr($currentsetting, 0, 1),
-                         'm' => substr($currentsetting, 1, 1),
-                         't' => substr($currentsetting, 2, 1),
-                         'w' => substr($currentsetting, 3, 1),
-                         'r' => substr($currentsetting, 4, 1),
-                         'f' => substr($currentsetting, 5, 1),
-                         's' => substr($currentsetting, 6, 1));
-        } else {
-            return NULL;
-        }
+        return isset($CFG->{$this->name}) ? $CFG->{$this->name} : 0;
     }
 
     function write_setting($data) {
-        $week = 'umtwrfs';
-        $result = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0);
+        $result = 0;
         if (!empty($data)) {
-            foreach($data as $key => $value) {
-                if ($value == '1') {
-                    $result[strpos($week, $key)] = 1;
-                }
+            foreach($data as $index) {
+                $result |= 1 << $index;
             }
         }
-        return (set_config($this->name, bindec(implode('',$result))) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '<br />');
+        return (set_config($this->name, $result) ? '' : get_string('errorsetting', 'admin') . $this->visiblename . '<br />');
     }
 
     function output_html() {
-
         if ($this->get_setting() === NULL) {
             $currentsetting = $this->defaultsetting;
         } else {
             $currentsetting = $this->get_setting();
         }
 
-        // rewrite for simplicity
-        $currentsetting = $currentsetting['u'] . $currentsetting['m'] . $currentsetting['t'] . $currentsetting['w'] .
-                          $currentsetting['r'] . $currentsetting['f'] . $currentsetting['s'];
-
-        $return = '<table><tr><td><div style="text-align:center">&nbsp;&nbsp;' . get_string('sunday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div style="text-align:center">&nbsp;&nbsp;' .
-        get_string('monday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div style="text-align:center">&nbsp;&nbsp;' . get_string('tuesday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div style="text-align:center">&nbsp;&nbsp;' .
-        get_string('wednesday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div style="text-align:center">&nbsp;&nbsp;' . get_string('thursday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div style="text-align:center">&nbsp;&nbsp;' .
-        get_string('friday', 'calendar') . '&nbsp;&nbsp;</div></td><td><div style="text-align:center">&nbsp;&nbsp;' . get_string('saturday', 'calendar') . '&nbsp;&nbsp;</div></td></tr><tr>' .
-        '<td><div style="text-align:center"><input type="checkbox" class="form-checkbox" id="id_s_'.$this->name.'u" name="s_'. $this->name .'[u]" value="1" ' . (substr($currentsetting,0,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
-        '<td><div style="text-align:center"><input type="checkbox" class="form-checkbox" id="id_s_'.$this->name.'m" name="s_'. $this->name .'[m]" value="1" ' . (substr($currentsetting,1,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
-        '<td><div style="text-align:center"><input type="checkbox" class="form-checkbox" id="id_s_'.$this->name.'t" name="s_'. $this->name .'[t]" value="1" ' . (substr($currentsetting,2,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
-        '<td><div style="text-align:center"><input type="checkbox" class="form-checkbox" id="id_s_'.$this->name.'w" name="s_'. $this->name .'[w]" value="1" ' . (substr($currentsetting,3,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
-        '<td><div style="text-align:center"><input type="checkbox" class="form-checkbox" id="id_s_'.$this->name.'r" name="s_'. $this->name .'[r]" value="1" ' . (substr($currentsetting,4,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
-        '<td><div style="text-align:center"><input type="checkbox" class="form-checkbox" id="id_s_'.$this->name.'f" name="s_'. $this->name .'[f]" value="1" ' . (substr($currentsetting,5,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
-        '<td><div style="text-align:center"><input type="checkbox" class="form-checkbox" id="id_s_'.$this->name.'s" name="s_'. $this->name .'[s]" value="1" ' . (substr($currentsetting,6,1) == '1' ? 'checked="checked"' : '') . ' /></div></td>' .
-        '</tr></table>';
+        // The order matters very much because of the implied numeric keys
+        $days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
+        $return = '<table><thead><tr>';
+        foreach($days as $index => $day) {
+            $return .= '<td><label for="id_s_'.$this->name.$index.'">'.get_string($day, 'calendar').'</label></td>';
+        }
+        $return .= '</tr></thead><tbody><tr>';
+        foreach($days as $index => $day) {
+            $return .= '<td><input type="checkbox" class="form-checkbox" id="id_s_'.$this->name.$index.'" name="s_'.$this->name.'[]" value="'.$index.'" '.($currentsetting & (1 << $index) ? 'checked="checked"' : '') . ' /></td>';
+        }
+        $return .= '</tr></tbody></table>';
 
         return format_admin_setting($this->name, $this->visiblename, $return, $this->description, false);
 
index 6fb43f5a258bedc52202d8fb3081fe1a38995163..08d11cb149f5a071a83e5f0770491d1aaf408e1c 100644 (file)
@@ -919,6 +919,20 @@ body#admin-modules table.generaltable td.c0
   border-style: solid;
 }
 
+#adminsettings #admin-calendar_weekend table {
+  width: 100%;
+}
+
+#adminsettings #admin-calendar_weekend table td {
+  text-align: center;
+}
+
+#adminsettings #admin-calendar_weekend table td label {
+  width: 100%;
+  text-align: center;
+  float: none;
+}
+
 
 /***
  *** Blocks