Skip to content

Commit

Permalink
Fix for bug 1503:
Browse files Browse the repository at this point in the history
Things are now easier for visitors and guests. We should do some regression
testing though: if you are a visitor or a guest and then you login (either
after browsing the site or immediately by typing a Moodle URL in the location
bar, without having a Moodle session at all), do user events always get shown
correctly? Does anything abnormal happen to the courses filter?
  • Loading branch information
defacer committed Jun 1, 2004
1 parent df9e0f8 commit f52f741
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
36 changes: 29 additions & 7 deletions calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ function calendar_sql_where($tstart, $tend, $users, $groups, $courses, $withdura
if(is_bool($users) && is_bool($groups) && is_bool($courses)) {
return false;
}

if(is_array($users) && !empty($users)) {
// Events from a number of users
if(!empty($whereclause)) $whereclause .= ' OR';
Expand All @@ -467,6 +466,13 @@ function calendar_sql_where($tstart, $tend, $users, $groups, $courses, $withdura
if(!empty($whereclause)) $whereclause .= ' OR';
$whereclause .= ' userid != 0 AND courseid = 0 AND groupid = 0';
}
else if($users === false) {
// No user at all
if(!empty($whereclause)) {
$whereclause .= ' OR';
}
$whereclause .= ' 0';
}
if(is_array($groups) && !empty($groups)) {
// Events from a number of groups
if(!empty($whereclause)) $whereclause .= ' OR';
Expand All @@ -482,10 +488,21 @@ function calendar_sql_where($tstart, $tend, $users, $groups, $courses, $withdura
if(!empty($whereclause)) $whereclause .= ' OR ';
$whereclause .= ' groupid != 0';
}
if(is_array($courses) && !empty($courses)) {
// A number of courses
if(!empty($whereclause)) $whereclause .= ' OR';
$whereclause .= ' groupid = 0 AND courseid IN ('.implode(',', $courses).')';
if(is_array($courses)) {
// A number of courses (maybe none at all!)
if(!empty($courses)) {
if(!empty($whereclause)) {
$whereclause .= ' OR';
}
$whereclause .= ' groupid = 0 AND courseid IN ('.implode(',', $courses).')';
}
else {
// This means NO courses, not that we don't care!
if(!empty($whereclause)) {
$whereclause .= ' OR';
}
$whereclause .= ' 0';
}
}
else if(is_numeric($courses)) {
// One course
Expand Down Expand Up @@ -517,6 +534,7 @@ function calendar_sql_where($tstart, $tend, $users, $groups, $courses, $withdura
// Just basic time filtering
$whereclause = $timeclause;
}

return $whereclause;
}

Expand Down Expand Up @@ -639,7 +657,7 @@ function calendar_filter_controls($type, $vars = NULL, $course = NULL) {
$content .= '<td style="width: 8px;"></td><td><a href="'.CALENDAR_URL.'set.php?var=showcourses'.$getvars.'" title="'.get_string('tt_showcourse', 'calendar').'">'.get_string('courseevents', 'calendar').'</a></td>'."\n";
}

if(!isguest($USER->id)) {
if(!empty($USER) && !isguest($USER->id)) {
$content .= "</tr>\n<tr>";

if($groupevents) {
Expand Down Expand Up @@ -1032,6 +1050,10 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU
function calendar_edit_event_allowed($event) {
global $USER;

if(empty($USER) || isguest($USER->id)) {
return false;
}

if (isadmin($USER->id)) return true; // Admins are allowed anything

if ($event->courseid > 1) {
Expand Down Expand Up @@ -1128,7 +1150,7 @@ function calendar_preferences_button() {
global $CFG, $USER;

// Guests have no preferences
if (empty($USER->id) or isguest()) {
if (empty($USER->id) || isguest()) {
return '';
}

Expand Down
2 changes: 0 additions & 2 deletions calendar/set.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
require_once('../config.php');
require_once('lib.php');

require_login();

require_variable($_GET['from']);
require_variable($_GET['var']);
optional_variable($_GET['value']);
Expand Down
15 changes: 6 additions & 9 deletions calendar/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@

require_once('../config.php');
require_once('../course/lib.php');

require_login();

require_once('lib.php');

optional_variable($_GET['view'], 'upcoming');
Expand Down Expand Up @@ -108,7 +105,7 @@
}
}

if(isguest($USER->id)) {
if(empty($USER) || isguest($USER->id)) {
$defaultcourses = calendar_get_default_courses();
calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
}
Expand Down Expand Up @@ -200,7 +197,7 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users) {
$events = calendar_get_upcoming($courses, $groups, $users, 1, 100, $starttime);

// New event button
if (isguest()) {
if (empty($USER) || isguest()) {
$text = get_string('dayview', 'calendar').': '.calendar_course_filter_selector($getvars);

} else {
Expand Down Expand Up @@ -311,7 +308,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
calendar_events_by_day($events, $display->tstart, $eventsbyday, $durationbyday, $typesbyday);

// New event button
if(isguest()) {
if(empty($USER) || isguest()) {
$text = get_string('detailedmonthview', 'calendar').': '.calendar_course_filter_selector($getvars);
}
else {
Expand Down Expand Up @@ -474,7 +471,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {

echo "</tr>\n";

if(!isguest($USER->id)) {
if(!empty($USER) && !isguest($USER->id)) {
echo '<tr>';
// Group events
if($SESSION->cal_show_groups) {
Expand Down Expand Up @@ -506,7 +503,7 @@ function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $
$events = calendar_get_upcoming($courses, $groups, $users, $futuredays, $maxevents);

// New event button
if(isguest()) {
if(empty($USER) || isguest()) {
$text = get_string('upcomingevents', 'calendar').': '.calendar_course_filter_selector('from=upcoming');

} else {
Expand Down Expand Up @@ -592,7 +589,7 @@ function calendar_print_event($event) {
function calendar_course_filter_selector($getvars = '') {
global $USER, $SESSION;

if (isguest($USER->id)) {
if (empty($USER) || isguest($USER->id)) {
return '';
}

Expand Down

0 comments on commit f52f741

Please sign in to comment.