]> git.mjollnir.org Git - moodle.git/commitdiff
Some interface cleanups ...
authormoodler <moodler>
Sat, 1 May 2004 17:32:37 +0000 (17:32 +0000)
committermoodler <moodler>
Sat, 1 May 2004 17:32:37 +0000 (17:32 +0000)
 - simplified the screens some more (headers etc)

 - preferences are all on one page, and the code was rewritten
   for simplicity and consistency

Changes are not well tested yet but I'm off to bed  :-)

calendar/lib.php
calendar/preferences.html [new file with mode: 0644]
calendar/preferences.php
calendar/view.php

index 37ae0254e7d9fa2adaab6f32edfb1409e33d5667..22cbe37f5f18c21b2b3f9c2437d27e4956814d45 100644 (file)
@@ -1187,27 +1187,17 @@ function calendar_preferences_array() {
     );
 }
 
-function calendar_get_preferences_menu() {
+function calendar_preferences_button() {
+    global $CFG, $USER;
 
     // Guests have no preferences
-    if(isguest()) {
+    if (empty($USER->id) or isguest()) {
         return '';
     }
 
-    $str = '<form style="display: inline;" name="cal_pref_form" method="get" action="preferences.php">';
-    $str .= '<select id="cal_pref" name="edit" onchange="self.location=\'preferences.php?edit=\'+document.cal_pref_form.cal_pref.options[document.cal_pref_form.cal_pref.options.selectedIndex].value; ">';
-    $str .= '<option value="" selected="selected">'.get_string('preferences', 'calendar').'...</option>';
-    $prefs = calendar_preferences_array();
-
-    foreach($prefs as $name => $description) {
-        $str .= '<option value="'.$name.'">'.$description.'</option>';
-    }
-    $str .= '</select>';
-    $str .= '<noscript id="cal_noscript" style="display: inline;"> <input type="submit" value=" &gt; " /></noscript>';
-    $str .= '<script type="text/javascript">document.getElementById("cal_noscript").style.display = "none";</script>';
-    $str .= '</form>';
-
-    return $str;
+    return "<form target=\"$CFG->framename\" method=\"get\" ".
+           " action=\"$CFG->wwwroot/calendar/preferences.php\">".
+           "<input type=\"submit\" value=\"".get_string("preferences", "calendar")." ...\" /></form>";
 }
 
 if(!function_exists('array_diff_assoc')) {
diff --git a/calendar/preferences.html b/calendar/preferences.html
new file mode 100644 (file)
index 0000000..35abd8b
--- /dev/null
@@ -0,0 +1,78 @@
+<form method="post" action="preferences.php" name="form">
+
+<table cellpadding="9" cellspacing="0">
+<tr valign="top">
+       <td nowrap="nowrap" align="right"><p><?php print_string('pref_timeformat', 'calendar')?>:</td>
+       <td>
+    <?php 
+        $options = NULL;
+        $options['0']  = get_string('default', 'calendar');
+        $options[CALENDAR_TF_12] = get_string('timeformat_12', 'calendar');
+        $options[CALENDAR_TF_24] = get_string('timeformat_24', 'calendar');
+        choose_from_menu ($options, "timeformat", $prefs->timeformat, "", "", ""); 
+    ?>
+    </td>
+    <td>
+    <?php print_string('explain_timeformat', 'calendar'); ?>
+    </td>
+</tr>
+
+<tr valign="top">
+       <td nowrap="nowrap" align="right"><p><?php print_string('pref_startwday', 'calendar')?>:</td>
+       <td>
+    <?php 
+        $options = NULL;
+        $options[0] = get_string('sunday', 'calendar');
+        $options[1] = get_string('monday', 'calendar');
+        $options[2] = get_string('tuesday', 'calendar');
+        $options[3] = get_string('wednesday', 'calendar');
+        $options[4] = get_string('thursday', 'calendar');
+        $options[5] = get_string('friday', 'calendar');
+        $options[6] = get_string('saturday', 'calendar');
+        choose_from_menu($options, 'startwday', $prefs->startwday, '', '', '');
+    ?>
+    </td>
+    <td>
+    <?php print_string('explain_startwday', 'calendar'); ?>
+    </td>
+</tr>
+
+<tr valign="top">
+       <td nowrap="nowrap" align="right"><p><?php print_string('pref_maxevents', 'calendar')?>:</td>
+       <td>
+    <?php 
+        $options = NULL;
+        for ($i=1; $i<=20; $i++) {
+            $options[$i] = $i;
+        }
+        choose_from_menu ($options, "maxevents", $prefs->maxevents, "", "", ""); 
+    ?>
+    </td>
+    <td>
+    <?php print_string('explain_maxevents', 'calendar'); ?>
+    </td>
+</tr>
+
+<tr valign="top">
+       <td nowrap="nowrap" align="right"><p><?php print_string('pref_lookahead', 'calendar')?>:</td>
+       <td>
+    <?php 
+        $options = NULL;
+        for ($i=1; $i<=200; $i++) {
+            $options[$i] = $i;
+        }
+        choose_from_menu ($options, "lookahead", $prefs->lookahead, "", "", ""); 
+    ?>
+    </td>
+    <td>
+    <?php print_string('explain_lookahead', 'calendar'); ?>
+    </td>
+</tr>
+
+<tr>
+    <td colspan="3" align="center">
+       <input type="submit" value="<?php print_string("savechanges") ?>"></td>
+</tr>
+</table>
+
+</form>
index 380c4ad1dbd612eab8b292cdc6c472c7436e2da9..194f3f4b63296b8fe7c28bf28e88645436d6bf2c 100644 (file)
-<?php // $Id$
+<?PHP  // $Id$
+       // preferences.php - user prefs for calendar
 
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// NOTICE OF COPYRIGHT                                                     //
-//                                                                         //
-// Moodle - Calendar extension                                             //
-//                                                                         //
-// Copyright (C) 2003-2004  Greek School Network            www.sch.gr     //
-//                                                                         //
-// Designed by:                                                            //
-//     Avgoustos Tsinakos (tsinakos@uom.gr)                                //
-//     Jon Papaioannou (pj@uom.gr)                                         //
-//                                                                         //
-// Programming and development:                                            //
-//     Jon Papaioannou (pj@uom.gr)                                         //
-//                                                                         //
-// For bugs, suggestions, etc contact:                                     //
-//     Jon Papaioannou (pj@uom.gr)                                         //
-//                                                                         //
-// The current module was developed at the University of Macedonia         //
-// (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) //
-// The aim of this project is to provide additional and improved           //
-// functionality to the Asynchronous Distance Education service that the   //
-// Greek School Network deploys.                                           //
-//                                                                         //
-// This program is free software; you can redistribute it and/or modify    //
-// it under the terms of the GNU General Public License as published by    //
-// the Free Software Foundation; either version 2 of the License, or       //
-// (at your option) any later version.                                     //
-//                                                                         //
-// This program is distributed in the hope that it will be useful,         //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
-// GNU General Public License for more details:                            //
-//                                                                         //
-//          http://www.gnu.org/copyleft/gpl.html                           //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-
-    //  Edit calendar preferences
-
-    require_once('../config.php');
+    require("../config.php");
     require_once('lib.php');
-    require_once('../course/lib.php');
-    require_once('../mod/forum/lib.php');
 
-    require_login();
 
-    if(!$site = get_site()) {
-        redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
-    }
-    if(isguest()) {
-        redirect($CFG->wwwroot.'/index.php');
+    if (isset($SESSION->cal_course_referer)) {
+        if (! $course = get_record("course", "id", $SESSION->cal_course_referer)) {
+            $course = get_site();
+        }
     }
 
-    optional_variable($_GET['edit'], '');
-    optional_variable($_GET['commit'], 0);
-    $knownpreference = false; // Defensive coding: let's be suspicious from the beginning
-    $prefs = calendar_preferences_array(); // Get this now, we 'll be using it all the time
-
-    if(in_array($_GET['edit'], array_keys($prefs))) {
-        // If we know this preference, you 'll get to see the setting page
-        $knownpreference = true;
+    if ($course->category) {
+        require_login($course->id);
     }
 
-    if($_GET['commit']) {
-        switch($_GET['edit']) {
-            case 'timeformat':
-                if($_GET['timeformat'] == '12') {
-                    $timeformat = CALENDAR_TF_12;
-                }
-                else if($_GET['timeformat'] == '24') {
-                    $timeformat = CALENDAR_TF_24;
-                }
-                else {
-                    $timeformat = '';
-                }
-                set_user_preference('calendar_'.$_GET['edit'], $timeformat);
-            break;
-            case 'startwday':
-                $day = intval($_GET[$_GET['edit']]);
-                if($day < 0 || $day > 6) {
-                    $day = abs($day % 7);
-                }
-                set_user_preference('calendar_'.$_GET['edit'], $day);
-            break;
-            case 'maxevents':
-                $events = intval($_GET[$_GET['edit']]);
-                if($events >= 1) {
-                    set_user_preference('calendar_'.$_GET['edit'], $events);
-                }
-            break;
-            case 'lookahead':
-                $days = intval($_GET[$_GET['edit']]);
-                if($days >= 1) {
-                    set_user_preference('calendar_'.$_GET['edit'], $days);
-                }
-            break;
+/// If data submitted, then process and store.
+
+       if ($form = data_submitted()) {  
+        print_header();
+        foreach ($form as $preference => $value) {
+            switch ($preference) {
+                case 'timeformat':
+                    if ($value != CALENDAR_TF_12 and $value != CALENDAR_TF_24) {
+                        $value = '';
+                    }
+                    set_user_preference('calendar_timeformat', $value);
+                break;
+                case 'startwday':
+                    $value = intval($value);
+                    if ($value < 0 or $value > 6) {
+                        $value = abs($value % 7);
+                    }
+                    set_user_preference('calendar_startwday', $value);
+                break;
+                case 'maxevents':
+                    if ((int)$value >= 1) {
+                        set_user_preference('calendar_maxevents', $value);
+                    }
+                break;
+                case 'lookahead':
+                    if ((int)$value >= 1) {
+                        set_user_preference('calendar_lookahead', $value);
+                    }
+                break;
+            }
         }
-        // Use this trick to get back to the preferences list after editing one
-        $knownpreference = false;
-        $_GET['edit'] = '';
+        redirect("view.php", get_string("changessaved"), 1);
+        exit;
     }
 
-    $firstcolumn = false;  // for now
-    $side = 175;
+    $site = get_site();
 
-    calendar_session_vars();
+    $strcalendar = get_string('calendar', 'calendar');
+    $strpreferences = get_string('preferences', 'calendar');
 
-    $now = usergetdate(time());
-    $pagetitle = get_string('preferences', 'calendar');
-    $nav = calendar_get_link_tag(get_string('calendar', 'calendar'), $CFG->wwwroot.'/calendar/view.php?view=upcoming&amp;', $now['mday'], $now['mon'], $now['year']);
-    if($knownpreference) {
-        $nav .= ' -> <a href="'.$CFG->wwwroot.'/calendar/preferences.php">'.$pagetitle.'</a> -> '.$prefs[$_GET['edit']];
-    }
-    else {
-        $nav .= ' -> '.$pagetitle;
+    if ($course->category) {
+        $navigation = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
+                       <a href=\"view.php\">$strcalendar</a> -> $strpreferences";
+    } else {
+        $navigation = "<a href=\"view.php\">$strcalendar</a> -> $strpreferences";
     }
 
-    // Let's see if we are supposed to provide a referring course link
-    // but NOT for the front page
-    if($SESSION->cal_course_referer > 1 &&
-      ($shortname = get_field('course', 'shortname', 'id', $SESSION->cal_course_referer)) !== false) {
-        // If we know about the referring course, show a return link
-        $nav = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$SESSION->cal_course_referer.'">'.$shortname.'</a> -> '.$nav;
-    }
 
-    print_header(get_string('calendar', 'calendar').': '.$pagetitle, $site->fullname, $nav,
+    print_header("$site->shortname: $strcalendar: $strpreferences", $strcalendar, $navigation,
                  '', '', true, '', '<p class="logininfo">'.user_login_string($site).'</p>');
 
-    echo calendar_overlib_html();
-
-    // Layout the whole page as three big columns.
-    echo '<table border="0" cellpadding="3" cellspacing="0" width="100%">';
-
-    // START: The main column
-    echo '<tr valign="top">';
-
-    echo '<td width="100%" valign="top\">';
-
-    $text = '<div style="float: left;">'.get_string('calendarheading', 'calendar', strip_tags($site->shortname)).'</div><div style="float: right;">';
-    $text.= calendar_get_preferences_menu();
-    $text.= '</div>';
-
-    print_heading_block($text);
-    print_spacer(8,1);
-
-    $defaultcourses = calendar_get_default_courses();
-
-    $courses = array();
-
-    calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
 
-    $day = $now['mday'];
-    $mon = $now['mon'];
-    $yr = $now['year'];
-
-    if($knownpreference) {
-        print_side_block_start($prefs[$_GET['edit']], '', 'mycalendar');
-        echo '<form name="preference" method="get" action="preferences.php"><p style="text-align: justify;">';
-        print_string('explain_'.$_GET['edit'], 'calendar');
-        echo '</p><div style="text-align: center;"><table style="margin: auto;"><tr>';
-        echo '<td><strong>'.$prefs[$_GET['edit']].':</strong></td>';
-    }
-
-    switch($_GET['edit']) {
-        case 'timeformat':
-            $sel = array('default' => ' selected="selected"', '12' => '', '24' => '');
-            switch(get_user_preferences('calendar_timeformat', '')) {
-                case CALENDAR_TF_12:
-                    $sel['12'] = $sel['default'];
-                    $sel['default'] = '';
-                break;
-                case CALENDAR_TF_24:
-                    $sel['24'] = $sel['default'];
-                    $sel['default'] = '';
-                break;
-            }
-            echo '<td><select name="timeformat">';
-            echo '<option value="default"'.$sel['default'].'>'.get_string('default', 'calendar').'</option>';
-            echo '<option value="12"'.$sel['12'].'>'.get_string('timeformat_12', 'calendar').'</option>';
-            echo '<option value="24"'.$sel['24'].'>'.get_string('timeformat_24', 'calendar').'</option>';
-            echo '</select></td>';
-        break;
-        case 'startwday':
-            echo '<td>';
-            $days = array(
-                get_string('sunday', 'calendar'), get_string('monday', 'calendar'),
-                get_string('tuesday', 'calendar'), get_string('wednesday', 'calendar'),
-                get_string('thursday', 'calendar'), get_string('friday', 'calendar'),
-                get_string('saturday', 'calendar'));
-            choose_from_menu($days, 'startwday', get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY), '');
-            echo '</td>';
-        break;
-        case 'maxevents':
-            echo '<td><input type="text" name="maxevents" size="5" value="'.get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS).'" /></td>';
-        break;
-        case 'lookahead':
-            echo '<td><input type="text" name="lookahead" size="5" value="'.get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS).'" /></td>';
-        break;
-        default:
-            // Print a form displaying all the preferences and their values
-            print_side_block_start(get_string('preferences', 'calendar'), '', 'mycalendar');
-            echo '<div style="text-align: center; font-weight: bold;">'.get_string('preferences_available', 'calendar').'</div>';
-            echo '<p style="text-align: center;"><table style="width: 100%">';
-
-            // Get the actual values of all preferences
-            $values = array();
-            foreach($prefs as $name => $description) {
-                $values[$name] = get_user_preferences('calendar_'.$name);
-            }
-
-            // Fix 'display-friendly' values now
-            $days = array(
-                get_string('sunday', 'calendar'), get_string('monday', 'calendar'),
-                get_string('tuesday', 'calendar'), get_string('wednesday', 'calendar'),
-                get_string('thursday', 'calendar'), get_string('friday', 'calendar'),
-                get_string('saturday', 'calendar'));
-            $values['startwday'] = $days[$values['startwday']];
-            switch($values['timeformat']) {
-                case '':
-                    $values['timeformat'] = get_string('default', 'calendar');
-                break;
-                case CALENDAR_TF_12:
-                    $values['timeformat'] = get_string('timeformat_12', 'calendar');
-                break;
-                case CALENDAR_TF_24:
-                    $values['timeformat'] = get_string('timeformat_24', 'calendar');
-                break;
-            }
-
-            // OK, display them
-            foreach($prefs as $name => $description) {
-                echo '<tr><td style="text-align: right; width: 50%;"><a href="preferences.php?edit='.$name.'">'.$description.'</a>:</td>';
-                echo '<td>'.($values[$name] === NULL?get_string('default', 'calendar'):$values[$name]) .'</td></tr>';
-            }
-
-            // Done
-            echo '</table></p>';
-            print_side_block_end();
-        break;
-    }
-
-    if($knownpreference) {
-        echo '</tr></table>';
-        echo '<p><input type="submit" value=" '.get_string('ok').' "/></p>';
-        echo '</div>';
-        echo '<p><input type="hidden" name="commit" value="1" /><input type="hidden" name="edit" value="'.$_GET['edit'].'" />';
-        echo '</form>';
-        print_side_block_end();
-    }
+    print_heading($strpreferences);
 
-    echo '</td>';
-    // END: Middle column
+    print_simple_box_start("center", "", "$THEME->cellheading");
 
-    // START: Last column (3-month display)
-    echo '<td valign="top" width="'.$side.'">';
-    print_side_block_start(get_string('monthlyview', 'calendar'), '', 'sideblockmain');
-    list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
-    list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
+    $prefs->timeformat = get_user_preferences('calendar_timeformat', '');
+    $prefs->startwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
+    $prefs->maxevents = get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS);
+    $prefs->lookahead = get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS);
 
-    echo calendar_filter_controls('prefs');
-    echo '<p>';
-    echo calendar_top_controls('display', array('m' => $prevmon, 'y' => $prevyr));
-    echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
-    echo '</p><p>';
-    echo calendar_top_controls('display', array('m' => $mon, 'y' => $yr));
-    echo calendar_get_mini($courses, $groups, $users, $mon, $yr);
-    echo '</p><p>';
-    echo calendar_top_controls('display', array('m' => $nextmon, 'y' => $nextyr));
-    echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
-    echo '</p>';
-    print_side_block_end();
-    print_spacer(1, $side);
-    echo '</td>';
-    // END: Last column (3-month display)
+       include("preferences.html");
+    print_simple_box_end();
 
-    echo '</tr></table>';
-    print_footer();
+    print_footer($course->id);
 
 ?>
index cbf58eb06f80afbb2ad293c27cf7b68231675df5..915fb91a0d400ad4cf8318f81c4593edd675bc61 100644 (file)
@@ -43,9 +43,8 @@
     require_once('../config.php');
     require_once('lib.php');
     require_once('../course/lib.php');
-    require_once('../mod/forum/lib.php');
 
-    require_variable($_GET['view']);
+    optional_variable($_GET['view'], "upcoming");
     optional_variable($_GET['cal_d']);
     optional_variable($_GET['cal_m']);
     optional_variable($_GET['cal_y']);
         $nav = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$SESSION->cal_course_referer.'">'.$shortname.'</a> -> '.$nav;
     }
 
+    $strcalendar = get_string('calendar', 'calendar');
+
+    $prefsbutton = calendar_preferences_button();
+
     // Print title and header
-    if(!empty($pagetitle)) {
-        $pagetitle = ': '.$pagetitle;
-    }
-    print_header(get_string('calendar', 'calendar').$pagetitle, $site->fullname, $nav,
-                 '', '', true, '', '<p class="logininfo">'.user_login_string($site).'</p>');
+    print_header("$site->shortname: $strcalendar: $pagetitle", $strcalendar, $nav,
+                 '', '', true, $prefsbutton, '<p class="logininfo">'.user_login_string($site).'</p>');
 
     echo calendar_overlib_html();
 
 
     echo '<td width="100%" valign="top">';
 
-    if ($prefmenu) {
-        $text = '<div style="float: left;">'.get_string('calendarheading', 'calendar', strip_tags($site->shortname)).'</div><div style="float: right;">';
-        $text.= calendar_get_preferences_menu();
-        $text.= '</div>';
-
-    } else {
-        $text = get_string('calendarheading', 'calendar', strip_tags($site->shortname));
-    }
-
-    print_heading_block($text);
-    print_spacer(8, 1);
-
     $defaultcourses = calendar_get_default_courses();
     $courses = array();