From: moodler Date: Sat, 1 May 2004 17:32:37 +0000 (+0000) Subject: Some interface cleanups ... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1e1ff33b2eb087eb60b0392d93169b66ab5cfc2c;p=moodle.git Some interface cleanups ... - 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 :-) --- diff --git a/calendar/lib.php b/calendar/lib.php index 37ae0254e7..22cbe37f5f 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -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 = '
'; - $str .= ''; - $str .= ''; - $str .= ''; - $str .= '
'; - - return $str; + return "
framename\" method=\"get\" ". + " action=\"$CFG->wwwroot/calendar/preferences.php\">". + "
"; } if(!function_exists('array_diff_assoc')) { diff --git a/calendar/preferences.html b/calendar/preferences.html new file mode 100644 index 0000000000..35abd8b5c8 --- /dev/null +++ b/calendar/preferences.html @@ -0,0 +1,78 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

:

+ timeformat, "", "", ""); + ?> + + +

:

+ startwday, '', '', ''); + ?> + + +

:

+ maxevents, "", "", ""); + ?> + + +

:

+ lookahead, "", "", ""); + ?> + + +
+ ">
+ +
diff --git a/calendar/preferences.php b/calendar/preferences.php index 380c4ad1db..194f3f4b63 100644 --- a/calendar/preferences.php +++ b/calendar/preferences.php @@ -1,282 +1,84 @@ -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&', $now['mday'], $now['mon'], $now['year']); - if($knownpreference) { - $nav .= ' -> '.$pagetitle.' -> '.$prefs[$_GET['edit']]; - } - else { - $nav .= ' -> '.$pagetitle; + if ($course->category) { + $navigation = "wwwroot/course/view.php?id=$course->id\">$course->shortname -> + $strcalendar -> $strpreferences"; + } else { + $navigation = "$strcalendar -> $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 = ''.$shortname.' -> '.$nav; - } - print_header(get_string('calendar', 'calendar').': '.$pagetitle, $site->fullname, $nav, + print_header("$site->shortname: $strcalendar: $strpreferences", $strcalendar, $navigation, '', '', true, '', '

'.user_login_string($site).'

'); - echo calendar_overlib_html(); - - // Layout the whole page as three big columns. - echo ''; - - // START: The main column - echo ''; - - echo '
'; - - $text = '
'.get_string('calendarheading', 'calendar', strip_tags($site->shortname)).'
'; - $text.= calendar_get_preferences_menu(); - $text.= '
'; - - 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 '

'; - print_string('explain_'.$_GET['edit'], 'calendar'); - echo '

'; - echo ''; - } - - 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 ''; - break; - case 'startwday': - echo ''; - break; - case 'maxevents': - echo ''; - break; - case 'lookahead': - echo ''; - break; - default: - // Print a form displaying all the preferences and their values - print_side_block_start(get_string('preferences', 'calendar'), '', 'mycalendar'); - echo '
'.get_string('preferences_available', 'calendar').'
'; - echo '

'.$prefs[$_GET['edit']].':'; - $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 '
'; - - // 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 ''; - echo ''; - } - - // Done - echo '
'.$description.':'.($values[$name] === NULL?get_string('default', 'calendar'):$values[$name]) .'

'; - print_side_block_end(); - break; - } - - if($knownpreference) { - echo '
'; - echo '

'; - echo ''; - echo '

'; - echo ''; - print_side_block_end(); - } + print_heading($strpreferences); - echo ''; - // END: Middle column + print_simple_box_start("center", "", "$THEME->cellheading"); - // START: Last column (3-month display) - echo ''; - 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 '

'; - echo calendar_top_controls('display', array('m' => $prevmon, 'y' => $prevyr)); - echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr); - echo '

'; - echo calendar_top_controls('display', array('m' => $mon, 'y' => $yr)); - echo calendar_get_mini($courses, $groups, $users, $mon, $yr); - echo '

'; - echo calendar_top_controls('display', array('m' => $nextmon, 'y' => $nextyr)); - echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr); - echo '

'; - print_side_block_end(); - print_spacer(1, $side); - echo ''; - // END: Last column (3-month display) + include("preferences.html"); + print_simple_box_end(); - echo ''; - print_footer(); + print_footer($course->id); ?> diff --git a/calendar/view.php b/calendar/view.php index cbf58eb06f..915fb91a0d 100644 --- a/calendar/view.php +++ b/calendar/view.php @@ -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']); @@ -106,12 +105,13 @@ $nav = ''.$shortname.' -> '.$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, '', '

'.user_login_string($site).'

'); + print_header("$site->shortname: $strcalendar: $pagetitle", $strcalendar, $nav, + '', '', true, $prefsbutton, '

'.user_login_string($site).'

'); echo calendar_overlib_html(); @@ -123,18 +123,6 @@ echo ''; - if ($prefmenu) { - $text = '
'.get_string('calendarheading', 'calendar', strip_tags($site->shortname)).'
'; - $text.= calendar_get_preferences_menu(); - $text.= '
'; - - } 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();