mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
calendar MDL-22887 Output is now through a renderer, all pages have navigation, and now uses true pretend blocks.
This commit is contained in:
parent
de832702ad
commit
36dc3b7104
18 changed files with 1058 additions and 939 deletions
|
@ -85,5 +85,28 @@ M.core_calendar = {
|
|||
if (M.core_calendar.showdelayevent !== null) {
|
||||
M.core_calendar.events[M.core_calendar.showdelayevent].show();
|
||||
}
|
||||
},
|
||||
init_basic_export : function(Y, allowthisweek, allownextweek, allownextmonth, username, authtoken) {
|
||||
Y.one('#generateurl').on('click', function(){
|
||||
var presetwhat = 'all';
|
||||
if (Y.one('#pw_course').get('checked')) {
|
||||
presetwhat = 'courses';
|
||||
}
|
||||
|
||||
var presettime = 'recentupcoming';
|
||||
if (allowthisweek && Y.one('#pt_wknow').get('checked')) {
|
||||
presettime = 'weeknow';
|
||||
} else if (allownextweek && Y.one('#pt_wknext').get('checked')) {
|
||||
presettime = 'weeknext';
|
||||
} else if (allownextmonth && Y.one('#pt_monnext').get('checked')) {
|
||||
presettime = 'monthnext';
|
||||
} else if (Y.one('#pt_monnow').get('checked')) {
|
||||
presettime = 'monthnow';
|
||||
}
|
||||
|
||||
var urlstr = M.cfg.wwwroot+'/calendar/export_execute.php?preset_what='+presetwhat+'&preset_time='+presettime+'&username='+username+'&authtoken='+authtoken;
|
||||
Y.one('#url').setContent(urlstr);
|
||||
Y.one('#urlbox').setStyle('display', 'block');
|
||||
}, this);
|
||||
}
|
||||
}
|
|
@ -95,7 +95,6 @@ $PAGE->navbar->add($strcalendar, $viewcalendarurl);
|
|||
$PAGE->navbar->add($title);
|
||||
$PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title);
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->box_start('eventlist');
|
||||
|
||||
|
|
|
@ -71,6 +71,8 @@ if ($cal_y !== 0) $url->param('cal_y', $cal_y);
|
|||
if ($cal_m !== 0) $url->param('cal_m', $cal_m);
|
||||
if ($cal_d !== 0) $url->param('cal_d', $cal_d);
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
$PAGE->set_pagelayout('standard');
|
||||
|
||||
if ($action === 'delete' && $eventid>0) {
|
||||
$deleteurl = new moodle_url('/calendar/delete.php', array('id'=>$eventid));
|
||||
|
@ -121,6 +123,9 @@ if (!empty($SESSION->cal_course_referer)) {
|
|||
|
||||
require_login($course, false);
|
||||
|
||||
$calendar = new calendar_information($cal_d, $cal_m, $cal_y);
|
||||
$calendar->courseid = $courseid;
|
||||
|
||||
$strcalendar = get_string('calendar', 'calendar');
|
||||
$link = clone($viewcalendarurl);
|
||||
$link->param('view', 'upcoming');
|
||||
|
@ -132,7 +137,7 @@ if ($eventid !== 0) {
|
|||
$event = calendar_event::load($eventid);
|
||||
if (!calendar_edit_event_allowed($event)) {
|
||||
print_error('nopermissions');
|
||||
}
|
||||
}
|
||||
$event->action = $action;
|
||||
$event->course = $courseid;
|
||||
$event->timedurationuntil = $event->timestart + $event->timeduration;
|
||||
|
@ -140,8 +145,8 @@ if ($eventid !== 0) {
|
|||
|
||||
if (!calendar_add_event_allowed($event)) {
|
||||
print_error('nopermissions');
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
$title = get_string('newevent', 'calendar');
|
||||
calendar_get_allowed_types($formoptions->eventtypes, $USER->id);
|
||||
$event = new calendar_event();
|
||||
|
@ -156,22 +161,20 @@ if ($eventid !== 0) {
|
|||
unset($formoptions->eventtypes->courses);
|
||||
unset($formoptions->eventtypes->groups);
|
||||
}
|
||||
}
|
||||
|
||||
if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) {
|
||||
}
|
||||
if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) {
|
||||
$event->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0);
|
||||
} else if($cal_y && $cal_m && checkdate($cal_m, 1, $cal_y)) {
|
||||
if($cal_y == $now['year'] && $cal_m == $now['mon']) {
|
||||
if($cal_y == $now['year'] && $cal_m == $now['mon']) {
|
||||
$event->timestart = make_timestamp($cal_y, $cal_m, $now['mday'], 0, 0, 0);
|
||||
} else {
|
||||
$event->timestart = make_timestamp($cal_y, $cal_m, 1, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (!calendar_add_event_allowed($event)) {
|
||||
print_error('nopermissions');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$properties = $event->properties(true);
|
||||
$formoptions->event = $event;
|
||||
|
@ -205,46 +208,13 @@ $PAGE->navbar->add($title);
|
|||
$PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title);
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
|
||||
calendar_set_filters($calendar->courses, $calendar->groups, $calendar->users);
|
||||
$renderer = $PAGE->get_renderer('core_calendar');
|
||||
$calendar->add_sidecalendar_blocks($renderer);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
|
||||
echo '<table class="calendarlayout">';
|
||||
echo '<tr><td class="maincalendar">';
|
||||
echo $renderer->start_layout();
|
||||
echo $OUTPUT->heading($title);
|
||||
$mform->display();
|
||||
echo '</td>';
|
||||
|
||||
// when adding an event you can not be a guest, so it's reasonalbe to ignore defaultcourses MDL-10353
|
||||
calendar_set_filters($courses, $groups, $users);
|
||||
list($prevmon, $prevyr) = calendar_sub_month((int)$now['mon'], (int)$now['year']);
|
||||
list($nextmon, $nextyr) = calendar_add_month((int)$now['mon'], (int)$now['year']);
|
||||
|
||||
echo '<td class="sidecalendar">';
|
||||
|
||||
$block = $OUTPUT->box_start('block');
|
||||
$block .= $OUTPUT->box($OUTPUT->heading(get_string('eventskey', 'calendar')), 'header');
|
||||
$block .= $OUTPUT->box(calendar_filter_controls('event', 'action='.$action.'&id='.$event->id), 'filters content');
|
||||
$block .= $OUTPUT->box_end();
|
||||
$block .= $OUTPUT->box_start('block');
|
||||
$block .= $OUTPUT->box($OUTPUT->heading(get_string('monthlyview', 'calendar')), 'header');
|
||||
$block .= $OUTPUT->box_start('content');
|
||||
$block .= $OUTPUT->box_start('minicalendarblock minicalendartop');
|
||||
$block .= calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
|
||||
$block .= calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
|
||||
$block .= $OUTPUT->box_end();
|
||||
$block .= $OUTPUT->box_start('minicalendarblock');
|
||||
$block .= calendar_top_controls('display', array('id' => $courseid, 'm' => (int)$now['mon'], 'y' => (int)$now['year']));
|
||||
$block .= calendar_get_mini($courses, $groups, $users, (int)$now['mon'], (int)$now['year']);
|
||||
$block .= $OUTPUT->box_end();
|
||||
$block .= $OUTPUT->box_start('minicalendarblock');
|
||||
$block .= calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
|
||||
$block .= calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
|
||||
$block .= $OUTPUT->box_end();
|
||||
$block .= $OUTPUT->box_end();
|
||||
$block .= $OUTPUT->box_end();
|
||||
echo $block;
|
||||
|
||||
echo '</td></tr>';
|
||||
echo '</table>';
|
||||
|
||||
echo $renderer->complete_layout();
|
||||
echo $OUTPUT->footer();
|
||||
|
|
|
@ -115,7 +115,7 @@ class event_form extends moodleform {
|
|||
$mform->addElement('radio', 'duration', get_string('eventduration', 'calendar'), get_string('durationnone', 'calendar'), 0);
|
||||
|
||||
$mform->addElement('radio', 'duration', null, get_string('durationuntil', 'calendar'), 1);
|
||||
$mform->addElement('date_time_selector', 'timedurationuntil', null);
|
||||
$mform->addElement('date_time_selector', 'timedurationuntil', ' ');
|
||||
$mform->disabledIf('timedurationuntil','duration','noteq', 1);
|
||||
|
||||
$mform->addElement('radio', 'duration', null, get_string('durationminutes', 'calendar'), 2);
|
||||
|
|
|
@ -74,8 +74,8 @@ if ($mon !== 0) {
|
|||
if ($yr !== 0) {
|
||||
$url->param('cal_y', $yr);
|
||||
}
|
||||
if ($course !== 0) {
|
||||
$url->param('course', $course);
|
||||
if ($course !== NULL) {
|
||||
$url->param('course', $course->id);
|
||||
}
|
||||
$PAGE->set_url($url);
|
||||
|
||||
|
@ -98,6 +98,10 @@ if (!empty($courseid) && $course->id != SITEID) {
|
|||
$PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
|
||||
}
|
||||
|
||||
$calendar = new calendar_information($day, $mon, $yr);
|
||||
$calendar->courseid = $courseid;
|
||||
|
||||
|
||||
if(!checkdate($mon, $day, $yr)) {
|
||||
$day = intval($now['mday']);
|
||||
$mon = intval($now['mon']);
|
||||
|
@ -107,16 +111,16 @@ $time = make_timestamp($yr, $mon, $day);
|
|||
|
||||
if (!isloggedin() or isguestuser()) {
|
||||
$defaultcourses = calendar_get_default_courses();
|
||||
calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
|
||||
calendar_set_filters($calendar->courses, $calendar->groups, $calendar->users, $defaultcourses, $defaultcourses);
|
||||
} else {
|
||||
calendar_set_filters($courses, $groups, $users);
|
||||
calendar_set_filters($calendar->courses, $calendar->groups, $calendar->users);
|
||||
}
|
||||
|
||||
$strcalendar = get_string('calendar', 'calendar');
|
||||
$prefsbutton = calendar_preferences_button();
|
||||
|
||||
// Print title and header
|
||||
$link = calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&course='.$courseid.'&',
|
||||
$link = calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&course='.$calendar->courseid.'&',
|
||||
$now['mday'], $now['mon'], $now['year']);
|
||||
$PAGE->navbar->add(get_string('calendar', 'calendar'), new moodle_url($link));
|
||||
$PAGE->navbar->add($pagetitle);
|
||||
|
@ -125,26 +129,20 @@ $PAGE->set_title($site->shortname.': '.$strcalendar.': '.$pagetitle);
|
|||
$PAGE->set_heading($COURSE->fullname);
|
||||
$PAGE->set_button($prefsbutton);
|
||||
$PAGE->set_focuscontrol('pw_all');
|
||||
$PAGE->set_pagelayout('standard');
|
||||
|
||||
$renderer = $PAGE->get_renderer('core_calendar');
|
||||
$calendar->add_sidecalendar_blocks($renderer);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// Layout the whole page as three big columns.
|
||||
echo '<table class="calendarlayout">';
|
||||
echo '<tr>';
|
||||
|
||||
// START: Main column
|
||||
|
||||
echo '<td class="maincalendar">';
|
||||
|
||||
$username = $USER->username;
|
||||
$usernameencoded = urlencode($USER->username);
|
||||
$authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
|
||||
|
||||
echo $renderer->start_layout();
|
||||
switch($action) {
|
||||
case 'advanced':
|
||||
break;
|
||||
case '':
|
||||
default:
|
||||
$username = $USER->username;
|
||||
$authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
|
||||
// Let's populate some vars to let "common tasks" be somewhat smart...
|
||||
// If today it's weekend, give the "next week" option
|
||||
$allownextweek = CALENDAR_WEEKEND & (1 << $now['wday']);
|
||||
|
@ -152,37 +150,7 @@ switch($action) {
|
|||
$allownextmonth = calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < 7;
|
||||
// If today it's weekend but tomorrow it isn't, do NOT give the "this week" option
|
||||
$allowthisweek = !((CALENDAR_WEEKEND & (1 << $now['wday'])) && !(CALENDAR_WEEKEND & (1 << (($now['wday'] + 1) % 7))));
|
||||
echo '<div class="header">' . get_string('export', 'calendar') . '</div>';
|
||||
include('export_basic.html');
|
||||
echo $renderer->basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
echo '</td>';
|
||||
|
||||
// END: Main column
|
||||
|
||||
// START: Last column (3-month display)
|
||||
echo '<td class="sidecalendar">';
|
||||
echo '<div class="header">'.get_string('monthlyview', 'calendar').'</div>';
|
||||
|
||||
list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
|
||||
list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
|
||||
$getvars = 'cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering
|
||||
|
||||
echo '<div class="minicalendarblock">';
|
||||
echo calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
|
||||
echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
|
||||
echo '</div><div class="minicalendarblock">';
|
||||
echo calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr));
|
||||
echo calendar_get_mini($courses, $groups, $users, $mon, $yr);
|
||||
echo '</div><div class="minicalendarblock">';
|
||||
echo calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
|
||||
echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
|
||||
echo '</div>';
|
||||
|
||||
echo '</td>';
|
||||
|
||||
echo '</tr></table>';
|
||||
|
||||
echo $renderer->complete_layout();
|
||||
echo $OUTPUT->footer();
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
<fieldset>
|
||||
<legend><?php print_string('commontasks', 'calendar'); ?></legend>
|
||||
<form method="get" action="export_execute.php">
|
||||
<div><?php print_string('iwanttoexport', 'calendar'); ?>:</div>
|
||||
<div class="indent">
|
||||
<input type="radio" name="preset_what" id="pw_all" value="all" checked="checked"/><label for="pw_all"><?php print_string('eventsall', 'calendar'); ?></label><br />
|
||||
<input type="radio" name="preset_what" id="pw_course" value="courses" /><label for="pw_course"><?php print_string('eventsrelatedtocourses', 'calendar'); ?></label><br />
|
||||
</div>
|
||||
<div><?php print_string('for', 'calendar'); ?>:</div>
|
||||
<div class="indent">
|
||||
<?php if($allowthisweek) { ?>
|
||||
<input type="radio" name="preset_time" id="pt_wknow" value="weeknow" checked="checked"/><label for="pt_wknow"><?php print_string('weekthis', 'calendar'); ?></label><br />
|
||||
<?php } ?>
|
||||
<?php if($allownextweek) { ?>
|
||||
<input type="radio" name="preset_time" id="pt_wknext" value="weeknext" /><label for="pt_wknext"><?php print_string('weeknext', 'calendar'); ?></label><br />
|
||||
<?php } ?>
|
||||
<input type="radio" name="preset_time" id="pt_monnow" value="monthnow" /><label for="pt_monnow"><?php print_string('monththis', 'calendar'); ?></label><br />
|
||||
<?php if($allownextmonth) { ?>
|
||||
<input type="radio" name="preset_time" id="pt_monnext" value="monthnext" /><label for="pt_monnext"><?php print_string('monthnext', 'calendar'); ?></label><br />
|
||||
<?php } ?>
|
||||
<input type="radio" name="preset_time" id="pt_recupc" value="recentupcoming" /><label for="pt_recupc"><?php print_string('recentupcoming', 'calendar'); ?></label><br />
|
||||
</div>
|
||||
<div style="text-align: right;">
|
||||
<input type="hidden" name="cal_d" value="" />
|
||||
<input type="hidden" name="cal_m" value="" />
|
||||
<input type="hidden" name="cal_y" value="" />
|
||||
<input type="hidden" name="username" value="<?php echo $username; ?>" />
|
||||
<input type="hidden" name="authtoken" value="<?php echo $authtoken; ?>" />
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
function generate_url() {
|
||||
if (document.getElementById("pw_course").checked) {
|
||||
preset_what = "courses";
|
||||
} else {
|
||||
preset_what = "all";
|
||||
}
|
||||
|
||||
if (<?php echo (int) $allowthisweek; ?> && document.getElementById("pt_wknow").checked) {
|
||||
preset_time = "weeknow";
|
||||
} else if (<?php echo (int) $allownextweek; ?> && document.getElementById("pt_wknext").checked) {
|
||||
preset_time = "weeknext";
|
||||
} else if (<?php echo (int) $allownextmonth; ?> && document.getElementById("pt_monnext").checked) {
|
||||
preset_time = "monthnext";
|
||||
} else if (document.getElementById("pt_monnow").checked) {
|
||||
preset_time = "monthnow";
|
||||
} else {
|
||||
preset_time = "recentupcoming";
|
||||
}
|
||||
|
||||
urlstr = "<?php echo $CFG->wwwroot; ?>/calendar/export_execute.php?preset_what=" + preset_what + "&preset_time=" + preset_time + "&username=<?php echo $usernameencoded; ?>&authtoken=<?php echo $authtoken; ?>";
|
||||
document.getElementById("url").innerText = urlstr;
|
||||
document.getElementById("url").innerHTML = urlstr; //Need this as well, for Firefox
|
||||
|
||||
document.getElementById("urlbox").style.display = "block";
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
<input type="button" value="<?php print_string('generateurlbutton', 'calendar'); ?>" onclick="javascript:generate_url()" />
|
||||
<input type="submit" value="<?php print_string('exportbutton', 'calendar'); ?>" />
|
||||
</div>
|
||||
</form>
|
||||
</fieldset>
|
||||
<div id="urlbox" style="display: none; ">
|
||||
<p><?php print_string('urlforical', 'calendar'); ?>:</p>
|
||||
<div id="url" style="overflow: scroll; width: 650px; "></div>
|
||||
</div>
|
232
calendar/lib.php
232
calendar/lib.php
|
@ -98,20 +98,17 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y
|
|||
// Navigated to this month
|
||||
$date = $thisdate;
|
||||
$display->thismonth = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Navigated to other month, let's do a nice trick and save us a lot of work...
|
||||
if(!checkdate($cal_month, 1, $cal_year)) {
|
||||
$date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']);
|
||||
$display->thismonth = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$date = array('mday' => 1, 'mon' => $cal_month, 'year' => $cal_year);
|
||||
$display->thismonth = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$date = usergetdate(time()); // Date and time the user sees at his location
|
||||
$display->thismonth = true;
|
||||
}
|
||||
|
@ -533,73 +530,19 @@ function calendar_add_event_metadata($event) {
|
|||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a calendar event
|
||||
*
|
||||
* @deprecated 2.0
|
||||
*/
|
||||
function calendar_print_event($event, $showactions=true) {
|
||||
global $CFG, $USER, $OUTPUT;
|
||||
|
||||
static $strftimetime;
|
||||
|
||||
$event = calendar_add_event_metadata($event);
|
||||
debugging('calendar_print_event is deprecated please update your code', DEBUG_DEVELOPER);
|
||||
$renderer = $PAGE->get_renderer('core_calendar');
|
||||
if (!($event instanceof calendar_event)) {
|
||||
$event = new calendar_event($event);
|
||||
}
|
||||
echo '<a name="event_'.$event->id.'"></a><table class="event" cellspacing="0">';
|
||||
echo '<tr><td class="picture">';
|
||||
if (!empty($event->icon)) {
|
||||
echo $event->icon;
|
||||
} else {
|
||||
echo $OUTPUT->spacer(array('height'=>16, 'width'=>16, 'br'=>true)); // should be done with CSS instead
|
||||
}
|
||||
echo '</td>';
|
||||
echo '<td class="topic">';
|
||||
|
||||
if (!empty($event->referer)) {
|
||||
echo '<div class="referer">'.$event->referer.'</div>';
|
||||
} else {
|
||||
echo '<div class="name">'.$event->name."</div>";
|
||||
}
|
||||
if (!empty($event->courselink)) {
|
||||
echo '<div class="course">'.$event->courselink.' </div>';
|
||||
}
|
||||
if (!empty($event->time)) {
|
||||
echo '<span class="date">'.$event->time.'</span>';
|
||||
} else {
|
||||
echo '<span class="date">'.calendar_time_representation($event->timestart).'</span>';
|
||||
}
|
||||
|
||||
echo '</td></tr>';
|
||||
echo '<tr><td class="side"> </td>';
|
||||
if (isset($event->cssclass)) {
|
||||
echo '<td class="description '.$event->cssclass.'">';
|
||||
} else {
|
||||
echo '<td class="description">';
|
||||
}
|
||||
|
||||
echo $event->description;
|
||||
if (calendar_edit_event_allowed($event) && $showactions) {
|
||||
echo '<div class="commands">';
|
||||
$calendarcourseid = '';
|
||||
if (!empty($event->calendarcourseid)) {
|
||||
$calendarcourseid = '&course='.$event->calendarcourseid;
|
||||
}
|
||||
if (empty($event->cmid)) {
|
||||
$editlink = CALENDAR_URL.'event.php?action=edit&id='.$event->id.$calendarcourseid;
|
||||
$deletelink = CALENDAR_URL.'delete.php?id='.$event->id.$calendarcourseid;
|
||||
} else {
|
||||
$editlink = $CFG->wwwroot.'/course/mod.php?update='.$event->cmid.'&return=true&sesskey='.sesskey();
|
||||
$deletelink = ''; // deleting activities directly from calendar is dangerous/confusing - see MDL-11843
|
||||
}
|
||||
echo ' <a href="'.$editlink.'"><img
|
||||
src="'.$OUTPUT->pix_url('t/edit') . '" alt="'.get_string('tt_editevent', 'calendar').'"
|
||||
title="'.get_string('tt_editevent', 'calendar').'" /></a>';
|
||||
if ($deletelink) {
|
||||
echo ' <a href="'.$deletelink.'"><img
|
||||
src="'.$OUTPUT->pix_url('t/delete') . '" alt="'.get_string('tt_deleteevent', 'calendar').'"
|
||||
title="'.get_string('tt_deleteevent', 'calendar').'" /></a>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</td></tr></table>';
|
||||
|
||||
echo $renderer->event($event);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -627,18 +570,15 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
|
|||
// Events from a number of users
|
||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||
$whereclause .= ' (userid IN ('.implode(',', $users).') AND courseid = 0 AND groupid = 0)';
|
||||
}
|
||||
else if(is_numeric($users)) {
|
||||
} else if(is_numeric($users)) {
|
||||
// Events from one user
|
||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||
$whereclause .= ' (userid = '.$users.' AND courseid = 0 AND groupid = 0)';
|
||||
}
|
||||
else if($users === true) {
|
||||
} else if($users === true) {
|
||||
// Events from ALL users
|
||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||
$whereclause .= ' (userid != 0 AND courseid = 0 AND groupid = 0)';
|
||||
}
|
||||
else if($users === false) {
|
||||
} else if($users === false) {
|
||||
// No user at all, do nothing
|
||||
}
|
||||
|
||||
|
@ -646,38 +586,27 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
|
|||
// Events from a number of groups
|
||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||
$whereclause .= ' groupid IN ('.implode(',', $groups).')';
|
||||
}
|
||||
else if(is_numeric($groups)) {
|
||||
} else if(is_numeric($groups)) {
|
||||
// Events from one group
|
||||
if(!empty($whereclause)) $whereclause .= ' OR ';
|
||||
$whereclause .= ' groupid = '.$groups;
|
||||
}
|
||||
else if($groups === true) {
|
||||
} else if($groups === true) {
|
||||
// Events from ALL groups
|
||||
if(!empty($whereclause)) $whereclause .= ' OR ';
|
||||
$whereclause .= ' groupid != 0';
|
||||
}
|
||||
// boolean false (no groups at all): we don't need to do anything
|
||||
|
||||
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).'))';
|
||||
if(is_array($courses) && !empty($courses)) {
|
||||
if(!empty($whereclause)) {
|
||||
$whereclause .= ' OR';
|
||||
}
|
||||
else {
|
||||
// This means NO courses, not that we don't care!
|
||||
// No need to do anything
|
||||
}
|
||||
}
|
||||
else if(is_numeric($courses)) {
|
||||
$whereclause .= ' (groupid = 0 AND courseid IN ('.implode(',', $courses).'))';
|
||||
} else if(is_numeric($courses)) {
|
||||
// One course
|
||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||
$whereclause .= ' (groupid = 0 AND courseid = '.$courses.')';
|
||||
}
|
||||
else if($courses === true) {
|
||||
} else if ($courses === true) {
|
||||
// Events from ALL courses
|
||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||
$whereclause .= ' (groupid = 0 AND courseid != 0)';
|
||||
|
@ -1529,11 +1458,9 @@ function calendar_format_event_time($event, $now, $morehref, $usecommonwords = t
|
|||
|
||||
function calendar_print_month_selector($name, $selected) {
|
||||
$months = array();
|
||||
|
||||
for ($i=1; $i<=12; $i++) {
|
||||
$months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B');
|
||||
}
|
||||
|
||||
echo html_writer::select($months, $name, $selected, false);
|
||||
}
|
||||
|
||||
|
@ -2323,3 +2250,118 @@ class calendar_event {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calendar information class
|
||||
*
|
||||
* This class is used simply to organise the information pertaining to a calendar
|
||||
* and is used primarily to make information easily available.
|
||||
*/
|
||||
class calendar_information {
|
||||
/**
|
||||
* The day
|
||||
* @var int
|
||||
*/
|
||||
public $day;
|
||||
/**
|
||||
* The month
|
||||
* @var int
|
||||
*/
|
||||
public $month;
|
||||
/**
|
||||
* The year
|
||||
* @var int
|
||||
*/
|
||||
public $year;
|
||||
|
||||
/**
|
||||
* A course id
|
||||
* @var int
|
||||
*/
|
||||
public $courseid = null;
|
||||
/**
|
||||
* An array of courses
|
||||
* @var array
|
||||
*/
|
||||
public $courses = array();
|
||||
/**
|
||||
* An array of groups
|
||||
* @var array
|
||||
*/
|
||||
public $groups = array();
|
||||
/**
|
||||
* An array of users
|
||||
* @var array
|
||||
*/
|
||||
public $users = array();
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param int $day
|
||||
* @param int $month
|
||||
* @param int $year
|
||||
*/
|
||||
public function __construct($day, $month, $year) {
|
||||
$this->day = $day;
|
||||
$this->month = $month;
|
||||
$this->year = $year;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the date for the calendar is correct and either sets it to now
|
||||
* or throws a moodle_exception if not
|
||||
*
|
||||
* @param bool $defaultonow
|
||||
* @return bool
|
||||
*/
|
||||
public function checkdate($defaultonow = true) {
|
||||
if (!checkdate($this->month, $this->day, $this->year)) {
|
||||
if ($defaultonow) {
|
||||
$now = usergetdate(time());
|
||||
$this->day = intval($now['mday']);
|
||||
$this->month = intval($now['mon']);
|
||||
$this->year = intval($now['year']);
|
||||
return true;
|
||||
} else {
|
||||
throw new moodle_exception('invaliddate');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Gets todays timestamp for the calendar
|
||||
* @return int
|
||||
*/
|
||||
public function timestamp_today() {
|
||||
return make_timestamp($this->year, $this->month, $this->day);
|
||||
}
|
||||
/**
|
||||
* Gets tomorrows timestamp for the calendar
|
||||
* @return int
|
||||
*/
|
||||
public function timestamp_tomorrow() {
|
||||
return make_timestamp($this->year, $this->month, $this->day+1);
|
||||
}
|
||||
/**
|
||||
* Adds the pretend blocks for teh calendar
|
||||
*
|
||||
* @param core_calendar_renderer $renderer
|
||||
* @param bool $showfilters
|
||||
* @param string|null $view
|
||||
*/
|
||||
public function add_sidecalendar_blocks(core_calendar_renderer $renderer, $showfilters=false, $view=null) {
|
||||
if ($showfilters) {
|
||||
$filters = new block_contents();
|
||||
$filters->content = $renderer->fake_block_filters($this->courseid, $this->day, $this->month, $this->year, $view, $this->courses);
|
||||
$filters->footer = '';
|
||||
$filters->title = get_string('eventskey', 'calendar');
|
||||
$renderer->add_pretend_calendar_block($filters, BLOCK_POS_RIGHT);
|
||||
}
|
||||
$block = new block_contents;
|
||||
$block->content = $renderer->fake_block_threemonths($this);
|
||||
$block->footer = '';
|
||||
$block->title = get_string('monthlyview', 'calendar');
|
||||
$renderer->add_pretend_calendar_block($block, BLOCK_POS_RIGHT);
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
<form method="post" action="preferences.php" id="prefform">
|
||||
|
||||
<table class="formtable">
|
||||
<tr>
|
||||
<th style="width: 30%;" scope="row"><?php print_string('pref_timeformat', 'calendar')?>:</th>
|
||||
<td>
|
||||
<?php
|
||||
$options = array();
|
||||
$options['0'] = get_string('default', 'calendar');
|
||||
$options[CALENDAR_TF_12] = get_string('timeformat_12', 'calendar');
|
||||
$options[CALENDAR_TF_24] = get_string('timeformat_24', 'calendar');
|
||||
echo html_writer::select($options, "timeformat", $prefs->timeformat, false);
|
||||
?>
|
||||
<p><?php print_string('explain_timeformat', 'calendar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php print_string('pref_startwday', 'calendar')?>:</th>
|
||||
<td>
|
||||
<?php
|
||||
$options = array();
|
||||
$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');
|
||||
echo html_writer::select($options, 'startwday', $prefs->startwday, false);
|
||||
?>
|
||||
<p><?php print_string('explain_startwday', 'calendar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php print_string('pref_maxevents', 'calendar')?>:</th>
|
||||
<td>
|
||||
<?php
|
||||
$options = NULL;
|
||||
for ($i=1; $i<=20; $i++) {
|
||||
$options[$i] = $i;
|
||||
}
|
||||
echo html_writer::select($options, "maxevents", $prefs->maxevents, false);
|
||||
?>
|
||||
<p><?php print_string('explain_maxevents', 'calendar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php print_string('pref_lookahead', 'calendar')?>:</th>
|
||||
<td>
|
||||
<?php
|
||||
$options = NULL;
|
||||
for ($i=1; $i<=200; $i++) {
|
||||
$options[$i] = $i;
|
||||
}
|
||||
echo html_writer::select($options, "lookahead", $prefs->lookahead, false);
|
||||
?>
|
||||
<p><?php print_string('explain_lookahead', 'calendar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php print_string('pref_persistflt', 'calendar')?>:</th>
|
||||
<td>
|
||||
<?php
|
||||
echo html_writer::select(array(0 => get_string('no'), 1 => get_string('yes')), 'persistflt', $prefs->persistflt, false);
|
||||
?>
|
||||
<p><?php print_string('explain_persistflt', 'calendar'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan="2" style="text-align: center;">
|
||||
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
|
||||
<input type="submit" value="<?php print_string("savechanges") ?>" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</form>
|
|
@ -4,84 +4,70 @@
|
|||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->dirroot.'/calendar/lib.php');
|
||||
require_once($CFG->dirroot.'/calendar/preferences_form.php');
|
||||
|
||||
$course = $site = get_site();
|
||||
if (isset($SESSION->cal_course_referer)) {
|
||||
if (! $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer))) {
|
||||
$course = get_site();
|
||||
}
|
||||
$course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer), '*', MUST_EXIST);
|
||||
}
|
||||
|
||||
$PAGE->set_url('/calendar/preferences.php');
|
||||
|
||||
if ($course->id != SITEID) {
|
||||
require_login($course->id);
|
||||
require_login($course);
|
||||
} else {
|
||||
require_login();
|
||||
}
|
||||
// Initialize the session variables
|
||||
calendar_session_vars();
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if ($form = data_submitted() and confirm_sesskey()) {
|
||||
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 (intval($value) >= 1) {
|
||||
set_user_preference('calendar_maxevents', $value);
|
||||
}
|
||||
break;
|
||||
case 'lookahead':
|
||||
if (intval($value) >= 1) {
|
||||
set_user_preference('calendar_lookahead', $value);
|
||||
}
|
||||
break;
|
||||
case 'persistflt':
|
||||
set_user_preference('calendar_persistflt', intval($value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
redirect('view.php?course='.$course->id, get_string('changessaved'), 1);
|
||||
exit;
|
||||
}
|
||||
|
||||
$site = get_site();
|
||||
|
||||
$strcalendar = get_string('calendar', 'calendar');
|
||||
$strpreferences = get_string('preferences', 'calendar');
|
||||
|
||||
if ($course->id != SITEID) {
|
||||
$PAGE->navbar-add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
|
||||
}
|
||||
$PAGE->navbar->add($strpreferences, new moodle_url('/calendar/view.php'));
|
||||
|
||||
$PAGE->set_title("$site->shortname: $strcalendar: $strpreferences");
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
echo $OUTPUT->heading($strpreferences);
|
||||
|
||||
echo $OUTPUT->box_start('generalbox boxaligncenter');
|
||||
|
||||
$prefs = new stdClass;
|
||||
$prefs->timeformat = get_user_preferences('calendar_timeformat', '');
|
||||
$prefs->startwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
|
||||
$prefs->maxevents = get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS);
|
||||
$prefs->lookahead = get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS);
|
||||
$prefs->persistflt = get_user_preferences('calendar_persistflt', 0);
|
||||
|
||||
include('./preferences.html');
|
||||
echo $OUTPUT->box_end();
|
||||
$form = new calendar_preferences_form();
|
||||
$form->set_data($prefs);
|
||||
|
||||
if ($data = $form->get_data() && confirm_sesskey()) {
|
||||
if ($data->timeformat != CALENDAR_TF_12 && $data->timeformat != CALENDAR_TF_24) {
|
||||
$data->timeformat = '';
|
||||
}
|
||||
set_user_preference('calendar_timeformat', $data->timeformat);
|
||||
|
||||
$data->startwday = intval($data->startwday);
|
||||
if ($data->startwday < 0 || $data->startwday > 6) {
|
||||
$data->startwday = abs($data->startwday % 7);
|
||||
}
|
||||
set_user_preference('calendar_startwday', $data->startwday);
|
||||
|
||||
if (intval($data->maxevents) >= 1) {
|
||||
set_user_preference('calendar_maxevents', $data->maxevents);
|
||||
}
|
||||
|
||||
if (intval($data->lookahead) >= 1) {
|
||||
set_user_preference('calendar_lookahead', $data->lookahead);
|
||||
}
|
||||
|
||||
set_user_preference('calendar_persistflt', intval($data->persistflt));
|
||||
redirect(new moodle_url('/calendar/view.php', array('course'=>$course->id)), get_string('changessaved'), 1);
|
||||
exit;
|
||||
}
|
||||
|
||||
$strcalendar = get_string('calendar', 'calendar');
|
||||
$strpreferences = get_string('calendarpreferences', 'calendar');
|
||||
|
||||
$PAGE->navbar->add($strpreferences, new moodle_url('/calendar/view.php'));
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_title("$site->shortname: $strcalendar: $strpreferences");
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($strpreferences);
|
||||
echo $OUTPUT->box_start('generalbox boxaligncenter');
|
||||
$form->display();
|
||||
echo $OUTPUT->box_end();
|
||||
echo $OUTPUT->footer();
|
90
calendar/preferences_form.php
Normal file
90
calendar/preferences_form.php
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle 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.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* The mform for settings user preferences
|
||||
*
|
||||
* @copyright 2010 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Always include formslib
|
||||
*/
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/lib/formslib.php');
|
||||
|
||||
/**
|
||||
* The mform class for setting user preferences
|
||||
*
|
||||
* @copyright 2010 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class calendar_preferences_form extends moodleform {
|
||||
|
||||
function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
$options = array(
|
||||
'0' => get_string('default', 'calendar'),
|
||||
CALENDAR_TF_12 => get_string('timeformat_12', 'calendar'),
|
||||
CALENDAR_TF_24 => get_string('timeformat_24', 'calendar')
|
||||
);
|
||||
$mform->addElement('select', 'timeformat', get_string('pref_timeformat', 'calendar'), $options);
|
||||
$mform->addHelpButton('timeformat', 'pref_timeformat', 'calendar');
|
||||
|
||||
$options = array(
|
||||
0 => get_string('sunday', 'calendar'),
|
||||
1 => get_string('monday', 'calendar'),
|
||||
2 => get_string('tuesday', 'calendar'),
|
||||
3 => get_string('wednesday', 'calendar'),
|
||||
4 => get_string('thursday', 'calendar'),
|
||||
5 => get_string('friday', 'calendar'),
|
||||
6 => get_string('saturday', 'calendar')
|
||||
);
|
||||
$mform->addElement('select', 'startwday', get_string('pref_startwday', 'calendar'), $options);
|
||||
$mform->addHelpButton('startwday', 'pref_startwday', 'calendar');
|
||||
|
||||
$options = array();
|
||||
for ($i=1; $i<=20; $i++) {
|
||||
$options[$i] = $i;
|
||||
}
|
||||
$mform->addElement('select', 'maxevents', get_string('pref_maxevents', 'calendar'), $options);
|
||||
$mform->addHelpButton('maxevents', 'pref_maxevents', 'calendar');
|
||||
|
||||
$options = array();
|
||||
for ($i=1; $i<=20; $i++) {
|
||||
$options[$i] = $i;
|
||||
}
|
||||
$mform->addElement('select', 'lookahead', get_string('pref_lookahead', 'calendar'), $options);
|
||||
$mform->addHelpButton('lookahead', 'pref_lookahead', 'calendar');
|
||||
|
||||
$options = array(
|
||||
0 => get_string('no'),
|
||||
1 => get_string('yes')
|
||||
);
|
||||
$mform->addElement('select', 'persistflt', get_string('pref_persistflt', 'calendar'), $options);
|
||||
$mform->addHelpButton('persistflt', 'pref_persistflt', 'calendar');
|
||||
|
||||
$this->add_action_buttons(false, get_string('savechanges'));
|
||||
}
|
||||
|
||||
}
|
663
calendar/renderer.php
Normal file
663
calendar/renderer.php
Normal file
|
@ -0,0 +1,663 @@
|
|||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle 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.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file contains the renderers for the calendar within Moodle
|
||||
*
|
||||
* @copyright 2010 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package calendar
|
||||
*/
|
||||
|
||||
/**
|
||||
* The primary renderer for the calendar.
|
||||
*/
|
||||
class core_calendar_renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Creates a basic export form
|
||||
*
|
||||
* @param bool $allowthisweek
|
||||
* @param bool $allownextweek
|
||||
* @param bool $allownextmonth
|
||||
* @param string $username
|
||||
* @param string $authtoken
|
||||
* @return string
|
||||
*/
|
||||
public function basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken) {
|
||||
|
||||
$output = html_writer::tag('div', get_string('export', 'calendar'), array('class'=>'header'));
|
||||
$output .= html_writer::start_tag('fieldset');
|
||||
$output .= html_writer::tag('legend', get_string('commontasks', 'calendar'));
|
||||
$output .= html_writer::start_tag('form', array('action'=>new moodle_url('/calendar/export_execute.php'), 'method'=>'get'));
|
||||
|
||||
$output .= html_writer::tag('div', get_string('iwanttoexport', 'calendar'));
|
||||
|
||||
$output .= html_writer::start_tag('div', array('class'=>'indent'));
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_all', 'value'=>'all', 'checked'=>'checked'));
|
||||
$output .= html_writer::tag('label', get_string('eventsall', 'calendar'), array('for'=>'pw_all'));
|
||||
$output .= html_writer::empty_tag('br');
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_course', 'value'=>'courses'));
|
||||
$output .= html_writer::tag('label', get_string('eventsrelatedtocourses', 'calendar'), array('for'=>'pw_course'));
|
||||
$output .= html_writer::empty_tag('br');
|
||||
$output .= html_writer::end_tag('div');
|
||||
|
||||
$output .= html_writer::tag('div', get_string('for', 'calendar').':');
|
||||
|
||||
$output .= html_writer::start_tag('div', array('class'=>'indent'));
|
||||
if ($allowthisweek) {
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknow', 'value'=>'weeknow', 'checked'=>'checked'));
|
||||
$output .= html_writer::tag('label', get_string('weekthis', 'calendar'), array('for'=>'pt_wknow'));
|
||||
$output .= html_writer::empty_tag('br');
|
||||
}
|
||||
if ($allownextweek) {
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknext', 'value'=>'weeknext'));
|
||||
$output .= html_writer::tag('label', get_string('weeknext', 'calendar'), array('for'=>'pt_wknext'));
|
||||
$output .= html_writer::empty_tag('br');
|
||||
}
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnow', 'value'=>'monthnow'));
|
||||
$output .= html_writer::tag('label', get_string('monththis', 'calendar'), array('for'=>'pt_monnow'));
|
||||
$output .= html_writer::empty_tag('br');
|
||||
if ($allownextmonth) {
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnext', 'value'=>'monthnext'));
|
||||
$output .= html_writer::tag('label', get_string('monthnext', 'calendar'), array('for'=>'pt_monnext'));
|
||||
$output .= html_writer::empty_tag('br');
|
||||
}
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_recupc', 'value'=>'recentupcoming'));
|
||||
$output .= html_writer::tag('label', get_string('recentupcoming', 'calendar'), array('for'=>'pt_recupc'));
|
||||
$output .= html_writer::empty_tag('br');
|
||||
$output .= html_writer::end_tag('div');
|
||||
|
||||
$output .= html_writer::start_tag('div', array('class'=>'rightalign'));
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>''));
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>''));
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>''));
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'username', 'value'=>$username));
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'authtoken', 'value'=>$authtoken));
|
||||
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'button', 'id'=>'generateurl', 'value'=>get_string('generateurlbutton', 'calendar')));
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('exportbutton', 'calendar')));
|
||||
|
||||
$output .= html_writer::end_tag('div');
|
||||
|
||||
$output .= html_writer::end_tag('form');
|
||||
$output .= html_writer::end_tag('fieldset');
|
||||
|
||||
$output .= html_writer::start_tag('div', array('id'=>'urlbox', 'style'=>'display:none;'));
|
||||
$output .= html_writer::tag('p', get_string('urlforical', 'calendar'));
|
||||
$output .= html_writer::tag('div', '', array('id'=>'url', 'style'=>'overflow:scroll;width:650px;'));
|
||||
$output .= html_writer::end_tag('div');
|
||||
|
||||
$this->page->requires->js_init_call('M.core_calendar.init_basic_export', array($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken));
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the standard layout for the page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function start_layout() {
|
||||
return html_writer::start_tag('div', array('class'=>'maincalendar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the remainder of the layout
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function complete_layout() {
|
||||
return html_writer::end_tag('div');
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces the content for the filters block (pretend block)
|
||||
*
|
||||
* @param int $courseid
|
||||
* @param int $day
|
||||
* @param int $month
|
||||
* @param int $year
|
||||
* @param int $view
|
||||
* @param int $courses
|
||||
* @return string
|
||||
*/
|
||||
public function fake_block_filters($courseid, $day, $month, $year, $view, $courses) {
|
||||
$getvars = 'id='.$courseid.'&cal_d='.$day.'&cal_m='.$month.'&cal_y='.$year;
|
||||
return html_writer::tag('div', calendar_filter_controls($view, $getvars, NULL, $courses), array('class'=>'calendar_filters filters'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces the content for the three months block (pretend block)
|
||||
*
|
||||
* This includes the previous month, the current month, and the next month
|
||||
*
|
||||
* @param calendar_information $calendar
|
||||
* @return string
|
||||
*/
|
||||
public function fake_block_threemonths(calendar_information $calendar) {
|
||||
|
||||
list($prevmon, $prevyr) = calendar_sub_month($calendar->month, $calendar->year);
|
||||
list($nextmon, $nextyr) = calendar_add_month($calendar->month, $calendar->year);
|
||||
|
||||
$content = html_writer::start_tag('div', array('class'=>'minicalendarblock'));
|
||||
$content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $prevmon, 'y' => $prevyr));
|
||||
$content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $prevmon, $prevyr);
|
||||
$content .= html_writer::end_tag('div');
|
||||
$content .= html_writer::start_tag('div', array('class'=>'minicalendarblock'));
|
||||
$content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year));
|
||||
$content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $calendar->month, $calendar->year);
|
||||
$content .= html_writer::end_tag('div');
|
||||
$content .= html_writer::start_tag('div', array('class'=>'minicalendarblock'));
|
||||
$content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $nextmon, 'y' => $nextyr));
|
||||
$content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $nextmon, $nextyr);
|
||||
$content .= html_writer::end_tag('div');
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a pretent calendar block
|
||||
*
|
||||
* @param block_contents $bc
|
||||
* @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT
|
||||
*/
|
||||
public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RIGHT) {
|
||||
$this->page->blocks->add_pretend_block($bc, $pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a button to add a new event
|
||||
*
|
||||
* @param int $courseid
|
||||
* @param int $day
|
||||
* @param int $month
|
||||
* @param int $year
|
||||
* @return string
|
||||
*/
|
||||
protected function add_event_button($courseid, $day=null, $month=null, $year=null) {
|
||||
$output = html_writer::start_tag('div', array('class'=>'buttons'));
|
||||
$output .= html_writer::start_tag('form', array('action'=>CALENDAR_URL.'event.php', 'method'=>'get'));
|
||||
$output .= html_writer::start_tag('div');
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'action', 'value'=>'new'));
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'course', 'value'=>$courseid));
|
||||
if ($day !== null) {
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>$day));
|
||||
}
|
||||
if ($month !== null) {
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>$month));
|
||||
}
|
||||
if ($year !== null) {
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>$year));
|
||||
}
|
||||
$output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('newevent', 'calendar')));
|
||||
$output .= html_writer::end_tag('div');
|
||||
$output .= html_writer::end_tag('form');
|
||||
$output .= html_writer::end_tag('div');
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the calendar for a single day
|
||||
*
|
||||
* @param calendar_information $calendar
|
||||
* @return string
|
||||
*/
|
||||
public function show_day(calendar_information $calendar) {
|
||||
$calendar->checkdate();
|
||||
$events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, 1, 100, $calendar->timestamp_today());
|
||||
|
||||
$output = html_writer::start_tag('div', array('class'=>'header'));
|
||||
if (!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
|
||||
$output .= $this->add_event_button($calendar->courseid, $calendar->day, $calendar->month, $calendar->year);
|
||||
}
|
||||
$output .= html_writer::tag('label', get_string('dayview', 'calendar'), array('for'=>'cal_course_flt_jump'));
|
||||
$output .= $this->course_filter_selector(array('from'=>'day', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year));
|
||||
$output .= html_writer::end_tag('div');
|
||||
// Controls
|
||||
$output .= html_writer::tag('div', calendar_top_controls('day', array('id' => $calendar->courseid, 'd' => $calendar->day, 'm' => $calendar->month, 'y' => $calendar->year)), array('class'=>'controls'));
|
||||
|
||||
if (empty($events)) {
|
||||
// There is nothing to display today.
|
||||
$output .= $this->output->heading(get_string('daywithnoevents', 'calendar'), 3);
|
||||
} else {
|
||||
$output .= html_writer::start_tag('div', array('class'=>'eventlist'));
|
||||
$underway = array();
|
||||
// First, print details about events that start today
|
||||
foreach ($events as $event) {
|
||||
$event = new calendar_event($event);
|
||||
$event->calendarcourseid = $calendar->courseid;
|
||||
if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow()-1) { // Print it now
|
||||
$event->time = calendar_format_event_time($event, time(), '', false, $calendar->timestamp_today());
|
||||
$output .= $this->event($event);
|
||||
} else { // Save this for later
|
||||
$underway[] = $event;
|
||||
}
|
||||
}
|
||||
|
||||
// Then, show a list of all events that just span this day
|
||||
if (!empty($underway)) {
|
||||
$output .= $this->output->heading(get_string('spanningevents', 'calendar'), 3);
|
||||
foreach ($underway as $event) {
|
||||
$event->time = calendar_format_event_time($event, time(), '', false, $calendar->timestamp_today());
|
||||
$output .= $this->event($event);
|
||||
}
|
||||
}
|
||||
|
||||
$output .= html_writer::end_tag('div');
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an event
|
||||
*
|
||||
* @param calendar_event $event
|
||||
* @param bool $showactions
|
||||
* @return string
|
||||
*/
|
||||
public function event(calendar_event $event, $showactions=true) {
|
||||
$event = calendar_add_event_metadata($event);
|
||||
|
||||
$output = html_writer::tag('a', '', array('name'=>'event_'.$event->id));
|
||||
|
||||
$table = new html_table();
|
||||
$table->attributes = array('class'=>'event', 'cellspacing'=>'0');
|
||||
$table->data = array(
|
||||
0 => new html_table_row(),
|
||||
1 => new html_table_row(),
|
||||
);
|
||||
|
||||
if (!empty($event->icon)) {
|
||||
$table->data[0]->cells[0] = new html_table_cell($event->icon);
|
||||
} else {
|
||||
$table->data[0]->cells[0] = new html_table_cell($this->output->spacer(array('height'=>16, 'width'=>16, 'br'=>true)));
|
||||
}
|
||||
$table->data[0]->cells[0]->attributes['class'] .= ' picture';
|
||||
|
||||
$table->data[0]->cells[1] = new html_table_cell();
|
||||
$table->data[0]->cells[1]->attributes['class'] .= ' topic';
|
||||
if (!empty($event->referer)) {
|
||||
$table->data[0]->cells[1]->text .= html_writer::tag('div', $event->referer, array('class'=>'referer'));
|
||||
} else {
|
||||
$table->data[0]->cells[1]->text .= html_writer::tag('div', $event->name, array('class'=>'name'));
|
||||
}
|
||||
if (!empty($event->courselink)) {
|
||||
$table->data[0]->cells[1]->text .= html_writer::tag('div', $event->courselink, array('class'=>'course'));
|
||||
}
|
||||
if (!empty($event->time)) {
|
||||
$table->data[0]->cells[1]->text .= html_writer::tag('span', $event->time, array('class'=>'date'));
|
||||
} else {
|
||||
$table->data[0]->cells[1]->text .= html_writer::tag('span', calendar_time_representation($event->timestart), array('class'=>'date'));
|
||||
}
|
||||
|
||||
$table->data[1]->cells[0] = new html_table_cell(' ');
|
||||
$table->data[1]->cells[0]->attributes['class'] .= 'side';
|
||||
|
||||
$table->data[1]->cells[1] = new html_table_cell($event->description);
|
||||
$table->data[1]->cells[1]->attributes['class'] .= ' description';
|
||||
if (isset($event->cssclass)) {
|
||||
$table->data[1]->cells[1]->attributes['class'] .= ' '.$event->cssclass;
|
||||
}
|
||||
|
||||
if (calendar_edit_event_allowed($event) && $showactions) {
|
||||
if (empty($event->cmid)) {
|
||||
$editlink = new moodle_url(CALENDAR_URL.'event.php', array('action'=>'edit', 'id'=>$event->id));
|
||||
$deletelink = new moodle_url(CALENDAR_URL.'delete.php', array('id'=>$event->id));
|
||||
if (!empty($event->calendarcourseid)) {
|
||||
$editlink->param('course', $event->calendarcourseid);
|
||||
$deletelink->param('course', $event->calendarcourseid);
|
||||
}
|
||||
} else {
|
||||
$editlink = new moodle_url('/course/mod.php', array('update'=>$event->cmid, 'return'=>true, 'sesskey'=>sesskey()));
|
||||
$deletelink = null;
|
||||
}
|
||||
|
||||
$commands = html_writer::start_tag('div', array('class'=>'commands'));
|
||||
$commands .= html_writer::start_tag('a', array('href'=>$editlink));
|
||||
$commands .= html_writer::empty_tag('img', array('src'=>$this->output->pix_url('t/edit'), 'alt'=>get_string('tt_editevent', 'calendar'), 'title'=>get_string('tt_editevent', 'calendar')));
|
||||
$commands .= html_writer::end_tag('a');
|
||||
if ($deletelink != null) {
|
||||
$commands .= html_writer::start_tag('a', array('href'=>$deletelink));
|
||||
$commands .= html_writer::empty_tag('img', array('src'=>$this->output->pix_url('t/delete'), 'alt'=>get_string('tt_deleteevent', 'calendar'), 'title'=>get_string('tt_deleteevent', 'calendar')));
|
||||
$commands .= html_writer::end_tag('a');
|
||||
}
|
||||
$commands .= html_writer::end_tag('div');
|
||||
$table->data[1]->cells[1]->text .= $commands;
|
||||
}
|
||||
return html_writer::table($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a month in detail
|
||||
*
|
||||
* @global array $CALENDARDAYS
|
||||
* @param calendar_information $calendar
|
||||
* @return string
|
||||
*/
|
||||
public function show_month_detailed(calendar_information $calendar) {
|
||||
global $CALENDARDAYS;
|
||||
|
||||
$date = usergetdate(time());
|
||||
list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display
|
||||
|
||||
$display = new stdClass;
|
||||
$display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
|
||||
$display->maxwday = $display->minwday + 6;
|
||||
$display->thismonth = true;
|
||||
$display->maxdays = calendar_days_in_month($m, $y);
|
||||
|
||||
$startwday = 0;
|
||||
if (get_user_timezone_offset() < 99) {
|
||||
// We 'll keep these values as GMT here, and offset them when the time comes to query the db
|
||||
$display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
|
||||
$display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
|
||||
$startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
|
||||
} else {
|
||||
// no timezone info specified
|
||||
$display->tstart = mktime(0, 0, 0, $m, 1, $y);
|
||||
$display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
|
||||
$startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
|
||||
}
|
||||
|
||||
// Align the starting weekday to fall in our display range
|
||||
if ($startwday < $display->minwday) {
|
||||
$startwday += 7;
|
||||
}
|
||||
|
||||
// Get events from database
|
||||
$events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $calendar->users, $calendar->groups, $calendar->courses);
|
||||
if (!empty($events)) {
|
||||
foreach($events as $eventid => $event) {
|
||||
$event = new calendar_event($event);
|
||||
if (!empty($event->modulename)) {
|
||||
$cm = get_coursemodule_from_instance($event->modulename, $event->instance);
|
||||
if (!groups_course_module_visible($cm)) {
|
||||
unset($events[$eventid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extract information: events vs. time
|
||||
calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses);
|
||||
|
||||
$output = html_writer::start_tag('div', array('class'=>'header'));
|
||||
if(!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
|
||||
$output .= $this->add_event_button($calendar->courseid, null, $calendar->month, $calendar->year);
|
||||
}
|
||||
$output .= get_string('detailedmonthview', 'calendar').': '.$this->course_filter_selector(array('from'=>'month', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year));
|
||||
$output .= html_writer::end_tag('div', array('class'=>'header'));
|
||||
// Controls
|
||||
$output .= html_writer::tag('div', calendar_top_controls('day', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year)), array('class'=>'controls'));
|
||||
|
||||
$table = new html_table();
|
||||
$table->attributes = array('class'=>'calendarmonth calendartable');
|
||||
$table->data = array();
|
||||
|
||||
$header = new html_table_row();
|
||||
$header->attributes = array('class'=>'weekdays');
|
||||
$header->cells = array();
|
||||
for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
|
||||
// This uses the % operator to get the correct weekday no matter what shift we have
|
||||
// applied to the $display->minwday : $display->maxwday range from the default 0 : 6
|
||||
$cell = new html_table_cell(get_string($CALENDARDAYS[$i % 7], 'calendar'));
|
||||
$cell->header = true;
|
||||
$header->cells[] = $cell;
|
||||
}
|
||||
|
||||
// For the table display. $week is the row; $dayweek is the column.
|
||||
$week = 1;
|
||||
$dayweek = $startwday;
|
||||
|
||||
$row = new html_table_row(array());
|
||||
// Paddding (the first week may have blank days in the beginning)
|
||||
for($i = $display->minwday; $i < $startwday; ++$i) {
|
||||
$cell = new html_table_cell(' ');
|
||||
$cell->attributes = array('class'=>'nottoday');
|
||||
$row->cells[] = $cell;
|
||||
}
|
||||
|
||||
// Now display all the calendar
|
||||
for ($calendar->day = 1; $calendar->day <= $display->maxdays; ++$calendar->day, ++$dayweek) {
|
||||
if($dayweek > $display->maxwday) {
|
||||
// We need to change week (table row)
|
||||
$table->data[] = $row;
|
||||
$row = new html_table_row(array());
|
||||
$dayweek = $display->minwday;
|
||||
++$week;
|
||||
}
|
||||
|
||||
// Reset vars
|
||||
$cell = new html_table_cell();
|
||||
$dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&course='.$calendar->courseid.'&', $calendar->day, $m, $y);
|
||||
|
||||
$cellclasses = array();
|
||||
|
||||
if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) {
|
||||
// Weekend. This is true no matter what the exact range is.
|
||||
$cellclasses[] = 'weekend';
|
||||
}
|
||||
|
||||
// Special visual fx if an event is defined
|
||||
if (isset($eventsbyday[$calendar->day])) {
|
||||
if(count($eventsbyday[$calendar->day]) == 1) {
|
||||
$title = get_string('oneevent', 'calendar');
|
||||
} else {
|
||||
$title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day]));
|
||||
}
|
||||
$cell->text = html_writer::tag('div', html_writer::link($dayhref, $calendar->day, array('title'=>$title)), array('class'=>'day'));
|
||||
} else {
|
||||
$cell->text = html_writer::tag('div', $calendar->day, array('class'=>'day'));
|
||||
}
|
||||
|
||||
// Special visual fx if an event spans many days
|
||||
$durationclass = false;
|
||||
if (isset($typesbyday[$calendar->day]['durationglobal'])) {
|
||||
$durationclass = 'duration_global';
|
||||
} else if (isset($typesbyday[$calendar->day]['durationcourse'])) {
|
||||
$durationclass = 'duration_course';
|
||||
} else if (isset($typesbyday[$calendar->day]['durationgroup'])) {
|
||||
$durationclass = 'duration_group';
|
||||
} else if (isset($typesbyday[$calendar->day]['durationuser'])) {
|
||||
$durationclass = 'duration_user';
|
||||
}
|
||||
if ($durationclass) {
|
||||
$cellclasses[] = 'duration';
|
||||
$cellclasses[] = $durationclass;
|
||||
}
|
||||
|
||||
// Special visual fx for today
|
||||
if($display->thismonth && $calendar->day == $d) {
|
||||
$cellclasses[] = 'today';
|
||||
} else {
|
||||
$cellclasses[] = 'nottoday';
|
||||
}
|
||||
$cell->attributes = array('class'=>join(' ',$cellclasses));
|
||||
|
||||
if (isset($eventsbyday[$calendar->day])) {
|
||||
$cell->text .= html_writer::start_tag('ul', array('class'=>'events-new'));
|
||||
foreach($eventsbyday[$calendar->day] as $eventindex) {
|
||||
// If event has a class set then add it to the event <li> tag
|
||||
$attributes = array();
|
||||
if (!empty($events[$eventindex]->class)) {
|
||||
$attributes['class'] = $events[$eventindex]->class;
|
||||
}
|
||||
$link = html_writer::link($dayhref.'#event_'.$events[$eventindex]->id, format_string($events[$eventindex]->name, true));
|
||||
$cell->text .= html_writer::tag('li', $link, $attributes);
|
||||
}
|
||||
$cell->text .= html_writer::end_tag('ul');
|
||||
}
|
||||
if (isset($durationbyday[$calendar->day])) {
|
||||
$cell->text .= html_writer::start_tag('ul', array('class'=>'events-underway'));
|
||||
foreach($durationbyday[$calendar->day] as $eventindex) {
|
||||
$cell->text .= html_writer::tag('li', '['.format_string($events[$eventindex]->name,true).']', array('class'=>'events-underway'));
|
||||
}
|
||||
$cell->text .= html_writer::end_tag('ul');
|
||||
}
|
||||
$row->cells[] = $cell;
|
||||
}
|
||||
|
||||
// Paddding (the last week may have blank days at the end)
|
||||
for($i = $dayweek; $i <= $display->maxwday; ++$i) {
|
||||
$cell = new html_table_cell(' ');
|
||||
$cell->attributes = array('class'=>'nottoday');
|
||||
$row->cells[] = $cell;
|
||||
}
|
||||
$table->data[] = $row;
|
||||
$output .= html_writer::table($table);
|
||||
|
||||
// OK, now for the filtering display
|
||||
$output .= $this->filter_selection_table($calendar);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a filter selection table
|
||||
*
|
||||
* @param calendar_information $calendar
|
||||
* @return string
|
||||
*/
|
||||
protected function filter_selection_table(calendar_information $calendar) {
|
||||
global $SESSION;
|
||||
|
||||
$output = html_writer::start_tag('div', array('class'=>'filters'));
|
||||
$output .= html_writer::start_tag('table');
|
||||
$output .= html_writer::start_tag('tr');
|
||||
|
||||
// Global events
|
||||
$link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showglobal', 'from'=>'month', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year));
|
||||
if($SESSION->cal_show_global) {
|
||||
$output .= html_writer::tag('td', '', array('class'=>'calendar_event_global', 'style'=>'width:8px;'));
|
||||
$output .= html_writer::tag('td', html_writer::tag('strong', get_string('globalevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
|
||||
} else {
|
||||
$output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
|
||||
$output .= html_writer::tag('td', html_writer::tag('strong', get_string('globalevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
|
||||
}
|
||||
|
||||
// Course events
|
||||
$link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showcourses', 'from'=>'month', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year));
|
||||
if(!empty($SESSION->cal_show_course)) {
|
||||
$output .= html_writer::tag('td', '', array('class'=>'calendar_event_course', 'style'=>'width:8px;'));
|
||||
$output .= html_writer::tag('td', html_writer::tag('strong', get_string('courseevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
|
||||
} else {
|
||||
$output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
|
||||
$output .= html_writer::tag('td', html_writer::tag('strong', get_string('courseevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
|
||||
}
|
||||
$output .= html_writer::end_tag('tr');
|
||||
|
||||
if(isloggedin() && !isguestuser()) {
|
||||
$output .= html_writer::start_tag('tr');
|
||||
// Group events
|
||||
$link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showgroups', 'from'=>'month', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year));
|
||||
if($SESSION->cal_show_groups) {
|
||||
$output .= html_writer::tag('td', '', array('class'=>'calendar_event_group', 'style'=>'width:8px;'));
|
||||
$output .= html_writer::tag('td', html_writer::tag('strong', get_string('groupevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
|
||||
} else {
|
||||
$output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
|
||||
$output .= html_writer::tag('td', html_writer::tag('strong', get_string('groupevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
|
||||
}
|
||||
// User events
|
||||
$link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showuser', 'from'=>'month', 'cal_d'=>$calendar->day, 'cal_m'=>$calendar->month, 'cal_y'=>$calendar->year));
|
||||
if($SESSION->cal_show_user) {
|
||||
$output .= html_writer::tag('td', '', array('class'=>'calendar_event_user', 'style'=>'width:8px;'));
|
||||
$output .= html_writer::tag('td', html_writer::tag('strong', get_string('userevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
|
||||
} else {
|
||||
$output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
|
||||
$output .= html_writer::tag('td', html_writer::tag('strong', get_string('userevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
|
||||
}
|
||||
$output .= html_writer::end_tag('tr');
|
||||
}
|
||||
$output .= html_writer::end_tag('table');
|
||||
$output .= html_writer::end_tag('div');
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays upcoming events
|
||||
*
|
||||
* @param calendar_information $calendar
|
||||
* @param int $futuredays
|
||||
* @param int $maxevents
|
||||
* @return string
|
||||
*/
|
||||
public function show_upcoming_events(calendar_information $calendar, $futuredays, $maxevents) {
|
||||
$events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, $futuredays, $maxevents);
|
||||
|
||||
$output = html_writer::start_tag('div', array('class'=>'header'));
|
||||
if (!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
|
||||
$output .= $this->add_event_button($calendar->courseid);
|
||||
}
|
||||
$output .= html_writer::tag('label', get_string('upcomingevents', 'calendar'), array('for'=>'cal_course_flt_jump'));
|
||||
$output .= $this->course_filter_selector(array('from'=>'upcoming'));
|
||||
$output .= html_writer::end_tag('div');
|
||||
|
||||
if ($events) {
|
||||
$output .= html_writer::start_tag('div', array('class'=>'eventlist'));
|
||||
foreach ($events as $event) {
|
||||
// Convert to calendar_event object so that we transform description
|
||||
// accordingly
|
||||
$event = new calendar_event($event);
|
||||
$event->calendarcourseid = $courseid;
|
||||
$output .= $this->event($event);
|
||||
}
|
||||
$output .= html_writer::end_tag('div');
|
||||
} else {
|
||||
$output .= $this->output->heading(get_string('noupcomingevents', 'calendar'));
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a course filter selector
|
||||
*
|
||||
* @param array $getvars
|
||||
* @return string
|
||||
*/
|
||||
protected function course_filter_selector(array $getvars = array()) {
|
||||
global $USER, $SESSION;
|
||||
|
||||
if (!isloggedin() or isguestuser()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
|
||||
$courses = get_courses('all', 'c.shortname','c.id,c.shortname');
|
||||
} else {
|
||||
$courses = enrol_get_my_courses();
|
||||
}
|
||||
|
||||
unset($courses[SITEID]);
|
||||
|
||||
$courseoptions = array();
|
||||
$courseoptions[SITEID] = get_string('fulllistofcourses');
|
||||
foreach ($courses as $course) {
|
||||
$courseoptions[$course->id] = format_string($course->shortname);
|
||||
}
|
||||
|
||||
if (is_numeric($SESSION->cal_courses_shown)) {
|
||||
$selected = $SESSION->cal_courses_shown;
|
||||
} else {
|
||||
$selected = '';
|
||||
}
|
||||
$getvars['var'] = 'setcourse';
|
||||
$select = new single_select(new moodle_url(CALENDAR_URL.'set.php', $getvars), 'id', $courseoptions, $selected, null);
|
||||
$select->class = 'cal_courses_flt';
|
||||
echo $this->output->render($select);
|
||||
}
|
||||
}
|
|
@ -73,9 +73,13 @@ $PAGE->set_url($url);
|
|||
if ($courseid && $courseid != SITEID) {
|
||||
require_login($courseid);
|
||||
} else if ($CFG->forcelogin) {
|
||||
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
require_login();
|
||||
}
|
||||
|
||||
$calendar = new calendar_information($day, $mon, $yr);
|
||||
$calendar->courseid = $courseid;
|
||||
|
||||
// Initialize the session variables
|
||||
calendar_session_vars();
|
||||
|
||||
|
@ -109,7 +113,6 @@ switch($view) {
|
|||
$pagetitle = get_string('upcomingevents', 'calendar');
|
||||
break;
|
||||
}
|
||||
|
||||
// If a course has been supplied in the URL, change the filters to show that one
|
||||
if (!empty($courseid)) {
|
||||
if ($course = $DB->get_record('course', array('id'=>$courseid))) {
|
||||
|
@ -127,15 +130,12 @@ if (!empty($courseid)) {
|
|||
} else {
|
||||
$course = null;
|
||||
}
|
||||
|
||||
if (!isloggedin() or isguestuser()) {
|
||||
$defaultcourses = calendar_get_default_courses();
|
||||
calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
|
||||
|
||||
calendar_set_filters($calendar->courses, $calendar->groups, $calendar->users, $defaultcourses, $defaultcourses);
|
||||
} else {
|
||||
calendar_set_filters($courses, $groups, $users);
|
||||
calendar_set_filters($calendar->courses, $calendar->groups, $calendar->users);
|
||||
}
|
||||
|
||||
// Let's see if we are supposed to provide a referring course link
|
||||
// but NOT for the "main page" course
|
||||
if ($SESSION->cal_course_referer != SITEID &&
|
||||
|
@ -153,27 +153,24 @@ $prefsbutton = calendar_preferences_button();
|
|||
$PAGE->set_title("$site->shortname: $strcalendar: $pagetitle");
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
$PAGE->set_button($prefsbutton);
|
||||
$PAGE->set_pagelayout('standard');
|
||||
|
||||
$renderer = $PAGE->get_renderer('core_calendar');
|
||||
$calendar->add_sidecalendar_blocks($renderer, true, $view);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// Layout the whole page as three big columns.
|
||||
echo '<table class="calendarlayout">';
|
||||
echo '<tr>';
|
||||
|
||||
// START: Main column
|
||||
|
||||
echo '<td class="maincalendar">';
|
||||
echo '<div class="heightcontainer">';
|
||||
echo $renderer->start_layout();
|
||||
echo html_writer::start_tag('div', array('class'=>'heightcontainer'));
|
||||
|
||||
switch($view) {
|
||||
case 'day':
|
||||
calendar_show_day($day, $mon, $yr, $courses, $groups, $users, $courseid);
|
||||
echo $renderer->show_day($calendar);
|
||||
break;
|
||||
case 'month':
|
||||
calendar_show_month_detailed($mon, $yr, $courses, $groups, $users, $courseid);
|
||||
echo $renderer->show_month_detailed($calendar);
|
||||
break;
|
||||
case 'upcoming':
|
||||
calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS), $courseid);
|
||||
echo $renderer->show_upcoming_events($calendar, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -181,478 +178,14 @@ switch($view) {
|
|||
echo $OUTPUT->container_start('bottom');
|
||||
if (!empty($CFG->enablecalendarexport)) {
|
||||
echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar'));
|
||||
|
||||
if (isloggedin()) {
|
||||
$authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
|
||||
$usernameencoded = urlencode($USER->username);
|
||||
|
||||
echo "<a href=\"export_execute.php?preset_what=all&preset_time=recentupcoming&username=$usernameencoded&authtoken=$authtoken\">"
|
||||
.'<img src="'.$OUTPUT->pix_url('i/ical') . '" height="14" width="36" '
|
||||
.'alt="'.get_string('ical', 'calendar').'" '
|
||||
.'title="'.get_string('quickdownloadcalendar', 'calendar').'" />'
|
||||
.'</a>';
|
||||
$link = new moodle_url('/calendar/export_execute.php', array('preset_what'=>'all', 'prest_time'=>'recentupcoming', 'username'=>$USER->username, 'authtoken'=>$authtoken));
|
||||
$icon = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('i/ical'), 'height'=>'14', 'width'=>'36', 'alt'=>get_string('ical', 'calendar'), 'title'=>get_string('quickdownloadcalendar', 'calendar')));
|
||||
echo html_writer::tag('a', $icon, array('href'=>$link));
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->container_end();
|
||||
echo '</div>';
|
||||
echo '</td>';
|
||||
|
||||
// END: Main column
|
||||
|
||||
// START: Last column (3-month display)
|
||||
echo '<td class="sidecalendar">';
|
||||
list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
|
||||
list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
|
||||
$getvars = 'id='.$courseid.'&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering
|
||||
|
||||
$content='<div class="filters">';
|
||||
$content.=calendar_filter_controls($view, $getvars, NULL, $courses);
|
||||
$content.='</div>';
|
||||
|
||||
$bc = new block_contents();
|
||||
$bc->content = $content;
|
||||
$bc->footer = '';
|
||||
$bc->title = strip_tags(get_string('eventskey', 'calendar'));
|
||||
echo $OUTPUT->block($bc, BLOCK_POS_LEFT);
|
||||
|
||||
$content='<div class="minicalendarblock minicalendartop">';
|
||||
$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
|
||||
$content.=calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
|
||||
$content.='</div><div class="minicalendarblock">';
|
||||
$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr));
|
||||
$content.=calendar_get_mini($courses, $groups, $users, $mon, $yr);
|
||||
$content.='</div><div class="minicalendarblock">';
|
||||
$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
|
||||
$content.=calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
|
||||
$content.='</div>';
|
||||
|
||||
$bc = new block_contents();
|
||||
$bc->content = $content;
|
||||
$bc->footer = '';
|
||||
$bc->title = strip_tags(get_string('monthlyview', 'calendar'));
|
||||
echo $OUTPUT->block($bc, BLOCK_POS_LEFT);
|
||||
|
||||
echo '</td>';
|
||||
|
||||
echo '</tr></table>';
|
||||
|
||||
echo html_writer::end_tag('div');
|
||||
echo $renderer->complete_layout();
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
|
||||
|
||||
function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) {
|
||||
global $CFG, $USER;
|
||||
|
||||
if (!checkdate($m, $d, $y)) {
|
||||
$now = usergetdate(time());
|
||||
list($d, $m, $y) = array(intval($now['mday']), intval($now['mon']), intval($now['year']));
|
||||
}
|
||||
|
||||
$getvars = 'from=day&cal_d='.$d.'&cal_m='.$m.'&cal_y='.$y; // For filtering
|
||||
|
||||
$starttime = make_timestamp($y, $m, $d);
|
||||
$endtime = make_timestamp($y, $m, $d + 1) - 1;
|
||||
|
||||
$events = calendar_get_upcoming($courses, $groups, $users, 1, 100, $starttime);
|
||||
|
||||
$text = '';
|
||||
if (!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
|
||||
$text.= '<div class="buttons">';
|
||||
$text.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
|
||||
$text.= '<div>';
|
||||
$text.= '<input type="hidden" name="action" value="new" />';
|
||||
$text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
|
||||
$text.= '<input type="hidden" name="cal_d" value="'.$d.'" />';
|
||||
$text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
|
||||
$text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
|
||||
$text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
|
||||
$text.= '</div></form></div>';
|
||||
}
|
||||
|
||||
$text .= '<label for="cal_course_flt_jump">'.
|
||||
get_string('dayview', 'calendar').
|
||||
':</label>'.
|
||||
calendar_course_filter_selector($getvars);
|
||||
|
||||
echo '<div class="header">'.$text.'</div>';
|
||||
|
||||
echo '<div class="controls">'.calendar_top_controls('day', array('id' => $courseid, 'd' => $d, 'm' => $m, 'y' => $y)).'</div>';
|
||||
|
||||
if (empty($events)) {
|
||||
// There is nothing to display today.
|
||||
echo '<h3>'.get_string('daywithnoevents', 'calendar').'</h3>';
|
||||
|
||||
} else {
|
||||
|
||||
echo '<div class="eventlist">';
|
||||
|
||||
$underway = array();
|
||||
|
||||
// First, print details about events that start today
|
||||
foreach ($events as $event) {
|
||||
|
||||
$event = new calendar_event($event);
|
||||
$event->calendarcourseid = $courseid;
|
||||
|
||||
if ($event->timestart >= $starttime && $event->timestart <= $endtime) { // Print it now
|
||||
|
||||
|
||||
/*
|
||||
$dayend = calendar_day_representation($event->timestart + $event->timeduration);
|
||||
$timeend = calendar_time_representation($event->timestart + $event->timeduration);
|
||||
$enddate = usergetdate($event->timestart + $event->timeduration);
|
||||
// Set printable representation
|
||||
echo calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&', $enddate['mday'], $enddate['mon'], $enddate['year']).' ('.$timeend.')';
|
||||
*/
|
||||
//unset($event->time);
|
||||
|
||||
$event->time = calendar_format_event_time($event, time(), '', false, $starttime);
|
||||
calendar_print_event($event);
|
||||
|
||||
} else { // Save this for later
|
||||
$underway[] = $event;
|
||||
}
|
||||
}
|
||||
|
||||
// Then, show a list of all events that just span this day
|
||||
if (!empty($underway)) {
|
||||
echo '<h3>'.get_string('spanningevents', 'calendar').':</h3>';
|
||||
foreach ($underway as $event) {
|
||||
$event->time = calendar_format_event_time($event, time(), '', false, $starttime);
|
||||
calendar_print_event($event);
|
||||
}
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) {
|
||||
global $CFG, $SESSION, $USER, $CALENDARDAYS;
|
||||
global $day, $mon, $yr;
|
||||
|
||||
$getvars = 'from=month&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering
|
||||
|
||||
$display = new stdClass;
|
||||
$display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
|
||||
$display->maxwday = $display->minwday + 6;
|
||||
|
||||
if(!empty($m) && !empty($y)) {
|
||||
$thisdate = usergetdate(time()); // Time and day at the user's location
|
||||
if($m == $thisdate['mon'] && $y == $thisdate['year']) {
|
||||
// Navigated to this month
|
||||
$date = $thisdate;
|
||||
$display->thismonth = true;
|
||||
}
|
||||
else {
|
||||
// Navigated to other month, let's do a nice trick and save us a lot of work...
|
||||
if(!checkdate($m, 1, $y)) {
|
||||
$date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']);
|
||||
$display->thismonth = true;
|
||||
}
|
||||
else {
|
||||
$date = array('mday' => 1, 'mon' => $m, 'year' => $y);
|
||||
$display->thismonth = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$date = usergetdate(time());
|
||||
$display->thismonth = true;
|
||||
}
|
||||
|
||||
// Fill in the variables we 're going to use, nice and tidy
|
||||
list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display
|
||||
$display->maxdays = calendar_days_in_month($m, $y);
|
||||
|
||||
$startwday = 0;
|
||||
if (get_user_timezone_offset() < 99) {
|
||||
// We 'll keep these values as GMT here, and offset them when the time comes to query the db
|
||||
$display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
|
||||
$display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
|
||||
$startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
|
||||
} else {
|
||||
// no timezone info specified
|
||||
$display->tstart = mktime(0, 0, 0, $m, 1, $y);
|
||||
$display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
|
||||
$startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
|
||||
}
|
||||
|
||||
// Align the starting weekday to fall in our display range
|
||||
if($startwday < $display->minwday) {
|
||||
$startwday += 7;
|
||||
}
|
||||
|
||||
// Get events from database
|
||||
$events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses);
|
||||
if (!empty($events)) {
|
||||
foreach($events as $eventid => $event) {
|
||||
$event = new calendar_event($event);
|
||||
if (!empty($event->modulename)) {
|
||||
$cm = get_coursemodule_from_instance($event->modulename, $event->instance);
|
||||
if (!groups_course_module_visible($cm)) {
|
||||
unset($events[$eventid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extract information: events vs. time
|
||||
calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses);
|
||||
|
||||
$text = '';
|
||||
if(!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
|
||||
$text.= '<div class="buttons"><form action="'.CALENDAR_URL.'event.php" method="get">';
|
||||
$text.= '<div>';
|
||||
$text.= '<input type="hidden" name="action" value="new" />';
|
||||
$text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
|
||||
$text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
|
||||
$text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
|
||||
$text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
|
||||
$text.= '</div></form></div>';
|
||||
}
|
||||
|
||||
$text .= get_string('detailedmonthview', 'calendar').': '.calendar_course_filter_selector($getvars);
|
||||
|
||||
echo '<div class="header">'.$text.'</div>';
|
||||
|
||||
echo '<div class="controls">';
|
||||
echo calendar_top_controls('month', array('id' => $courseid, 'm' => $m, 'y' => $y));
|
||||
echo '</div>';
|
||||
|
||||
// Start calendar display
|
||||
echo '<table class="calendarmonth calendartable"><tr class="weekdays">'; // Begin table. First row: day names
|
||||
|
||||
// Print out the names of the weekdays
|
||||
for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
|
||||
// This uses the % operator to get the correct weekday no matter what shift we have
|
||||
// applied to the $display->minwday : $display->maxwday range from the default 0 : 6
|
||||
echo '<th scope="col">'.get_string($CALENDARDAYS[$i % 7], 'calendar').'</th>';
|
||||
}
|
||||
|
||||
echo '</tr><tr>'; // End of day names; prepare for day numbers
|
||||
|
||||
// For the table display. $week is the row; $dayweek is the column.
|
||||
$week = 1;
|
||||
$dayweek = $startwday;
|
||||
|
||||
// Paddding (the first week may have blank days in the beginning)
|
||||
for($i = $display->minwday; $i < $startwday; ++$i) {
|
||||
echo '<td class="nottoday"> </td>'."\n";
|
||||
}
|
||||
|
||||
// Now display all the calendar
|
||||
for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
|
||||
if($dayweek > $display->maxwday) {
|
||||
// We need to change week (table row)
|
||||
echo "</tr>\n<tr>";
|
||||
$dayweek = $display->minwday;
|
||||
++$week;
|
||||
}
|
||||
|
||||
// Reset vars
|
||||
$cell = '';
|
||||
$dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&course='.$courseid.'&', $day, $m, $y);
|
||||
|
||||
if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) {
|
||||
// Weekend. This is true no matter what the exact range is.
|
||||
$class = 'weekend';
|
||||
}
|
||||
else {
|
||||
// Normal working day.
|
||||
$class = '';
|
||||
}
|
||||
|
||||
// Special visual fx if an event is defined
|
||||
if(isset($eventsbyday[$day])) {
|
||||
if(count($eventsbyday[$day]) == 1) {
|
||||
$title = get_string('oneevent', 'calendar');
|
||||
}
|
||||
else {
|
||||
$title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
|
||||
}
|
||||
$cell = '<div class="day"><a href="'.$dayhref.'" title="'.$title.'">'.$day.'</a></div>';
|
||||
}
|
||||
else {
|
||||
$cell = '<div class="day">'.$day.'</div>';
|
||||
}
|
||||
|
||||
// Special visual fx if an event spans many days
|
||||
$durationclass = false;
|
||||
if (isset($typesbyday[$day]['durationglobal'])) {
|
||||
$durationclass = ' duration_global';
|
||||
} else if(isset($typesbyday[$day]['durationcourse'])) {
|
||||
$durationclass = ' duration_course';
|
||||
} else if(isset($typesbyday[$day]['durationgroup'])) {
|
||||
$durationclass = ' duration_group';
|
||||
} else if(isset($typesbyday[$day]['durationuser'])) {
|
||||
$durationclass = ' duration_user';
|
||||
}
|
||||
if ($durationclass) {
|
||||
$class .= ' duration '.$durationclass;
|
||||
}
|
||||
|
||||
// Special visual fx for today
|
||||
if($display->thismonth && $day == $d) {
|
||||
$class .= ' today';
|
||||
} else {
|
||||
$class .= ' nottoday';
|
||||
}
|
||||
|
||||
// Just display it
|
||||
if(!empty($class)) {
|
||||
$class = ' class="'.trim($class).'"';
|
||||
}
|
||||
echo '<td'.$class.'>'.$cell;
|
||||
|
||||
if(isset($eventsbyday[$day])) {
|
||||
echo '<ul class="events-new">';
|
||||
foreach($eventsbyday[$day] as $eventindex) {
|
||||
|
||||
// If event has a class set then add it to the event <li> tag
|
||||
$eventclass = '';
|
||||
if (!empty($events[$eventindex]->class)) {
|
||||
$eventclass = ' class="'.$events[$eventindex]->class.'"';
|
||||
}
|
||||
|
||||
echo '<li'.$eventclass.'><a href="'.$dayhref.'#event_'.$events[$eventindex]->id.'">'.format_string($events[$eventindex]->name, true).'</a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
if(isset($durationbyday[$day])) {
|
||||
echo '<ul class="events-underway">';
|
||||
foreach($durationbyday[$day] as $eventindex) {
|
||||
echo '<li>['.format_string($events[$eventindex]->name,true).']</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
echo "</td>\n";
|
||||
}
|
||||
|
||||
// Paddding (the last week may have blank days at the end)
|
||||
for($i = $dayweek; $i <= $display->maxwday; ++$i) {
|
||||
echo '<td class="nottoday"> </td>';
|
||||
}
|
||||
echo "</tr>\n"; // Last row ends
|
||||
|
||||
echo "</table>\n"; // Tabular display of days ends
|
||||
|
||||
// OK, now for the filtering display
|
||||
echo '<div class="filters"><table><tr>';
|
||||
|
||||
// Global events
|
||||
if($SESSION->cal_show_global) {
|
||||
echo '<td class="calendar_event_global" style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
|
||||
echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
|
||||
} else {
|
||||
echo '<td style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
|
||||
echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
|
||||
}
|
||||
|
||||
// Course events
|
||||
if(!empty($SESSION->cal_show_course)) {
|
||||
echo '<td class="calendar_event_course" style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
|
||||
echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
|
||||
} else {
|
||||
echo '<td style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
|
||||
echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
|
||||
}
|
||||
|
||||
echo "</tr>\n";
|
||||
|
||||
if(isloggedin() && !isguestuser()) {
|
||||
echo '<tr>';
|
||||
// Group events
|
||||
if($SESSION->cal_show_groups) {
|
||||
echo '<td class="calendar_event_group" style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
|
||||
echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
|
||||
} else {
|
||||
echo '<td style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
|
||||
echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
|
||||
}
|
||||
// User events
|
||||
if($SESSION->cal_show_user) {
|
||||
echo '<td class="calendar_event_user" style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
|
||||
echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
|
||||
} else {
|
||||
echo '<td style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
|
||||
echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
|
||||
}
|
||||
echo "</tr>\n";
|
||||
}
|
||||
|
||||
echo '</table></div>';
|
||||
}
|
||||
|
||||
function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $maxevents, $courseid) {
|
||||
global $USER, $OUTPUT;
|
||||
|
||||
$events = calendar_get_upcoming($courses, $groups, $users, $futuredays, $maxevents);
|
||||
|
||||
$text = '';
|
||||
|
||||
if(!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
|
||||
$text.= '<div class="buttons">';
|
||||
$text.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
|
||||
$text.= '<div>';
|
||||
$text.= '<input type="hidden" name="action" value="new" />';
|
||||
$text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
|
||||
$text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
|
||||
$text.= '</div></form></div>';
|
||||
}
|
||||
|
||||
$text .= '<label for="cal_course_flt_jump">'.
|
||||
get_string('upcomingevents', 'calendar').
|
||||
': </label>'.
|
||||
calendar_course_filter_selector('from=upcoming');
|
||||
|
||||
echo '<div class="header">'.$text.'</div>';
|
||||
|
||||
if ($events) {
|
||||
|
||||
echo '<div class="eventlist">';
|
||||
foreach ($events as $event) {
|
||||
// Convert to calendar_event object so that we transform description
|
||||
// accordingly
|
||||
$event = new calendar_event($event);
|
||||
$event->calendarcourseid = $courseid;
|
||||
calendar_print_event($event);
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
echo $OUTPUT->heading(get_string('noupcomingevents', 'calendar'));
|
||||
}
|
||||
}
|
||||
|
||||
function calendar_course_filter_selector($getvars = '') {
|
||||
global $USER, $SESSION, $OUTPUT;
|
||||
|
||||
if (!isloggedin() or isguestuser()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
|
||||
$courses = get_courses('all', 'c.shortname','c.id,c.shortname');
|
||||
} else {
|
||||
$courses = enrol_get_my_courses();
|
||||
}
|
||||
|
||||
unset($courses[SITEID]);
|
||||
|
||||
$courseoptions = array();
|
||||
$courseoptions[SITEID] = get_string('fulllistofcourses');
|
||||
foreach ($courses as $course) {
|
||||
$courseoptions[$course->id] = format_string($course->shortname);
|
||||
}
|
||||
|
||||
if (is_numeric($SESSION->cal_courses_shown)) {
|
||||
$selected = $SESSION->cal_courses_shown;
|
||||
} else {
|
||||
$selected = '';
|
||||
}
|
||||
$select = new single_select(new moodle_url(CALENDAR_URL.'set.php?var=setcourse&'.$getvars), 'id', $courseoptions, $selected, null);
|
||||
$select->class = 'cal_courses_flt';
|
||||
echo $OUTPUT->render($select);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue