Source for file calendar.php
Documentation is available at calendar.php
* View a bookings calendar and make bookings
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: calendar.php,v 1.10 2007/02/09 00:19:48 themill Exp $
* path (bumblebee root)/inc/actions/calendar.php
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
require_once 'inc/bb/configreader.php';
require_once 'inc/bb/calendar.php';
/** date maniuplation objects */
require_once 'inc/date.php';
require_once 'inc/actions/viewbase.php';
/** Data reflector object */
require_once 'inc/formslib/datareflector.php';
* View a bookings calendar and make bookings
/** @var boolean logged in user can modify booking */
* @param BumblebeeAuth $auth Authorisation object
* @param array $pdata extra state data from the call path
#$this->mungeInputData();
// catch bad arguments and send them back to the front page straight away
if (! isset
($this->PD['instrid'])
||
$this->PD['instrid'] <
1
||
$this->PD['instrid'] ==
'') {
if (isset
($this->PD['isodate']) &&
! isset
($this->PD['bookid']) &&
! isset
($this->PD['startticks']) ) {
echo
"<br /><br /><a href='".
makeURL('view').
"'>".
T_('Return to instrument list') .
"</a>";
echo
"<br /><br /><a href='".
makeURL('view').
"'>".
T_('Return to instrument list') .
"</a>";
if (isset
($this->PD['caloffset']) &&
preg_match("/\d\d\d\d-\d\d-\d\d/", $this->PD['caloffset'])) {
$this->PD['caloffset'] =
floor($then->dsDaysBetween($now));
if (isset
($this->PD['configureview'])) {
foreach ($this->PD as $key =>
$value) {
if (preg_match('@^Instrument-(\d+)-include$@', $key, $matches)) {
if ($value && isset
($this->PD["Instrument-$id-instrument"])) {
$this->instrument[] =
$this->PD["Instrument-$id-instrument"];
/// FIXME: forcing a reload with a Location: header seems ugly and possibly fragile.
// force a reload of the page, converting from a POST to a GET so that
// later refreshes of the calendar can happen without generating a warning to the user
if (isset
($this->PD['caloffset'])) {
$d['caloffset'] =
$this->PD['caloffset'];
* Display the monthly calendar for the selected instrument
// Show a window $row['calendarlength'] weeks long starting $row['calendarhistory'] weeks
// before the current date. Displayed week starts on configured day of week.
if ($offset ==
'today') $offset =
0;
$start->addDays($offset);
$callength =
7 *
$this->row['callength'];
$week_offset =
$conf->value('language', 'week_offset', 1);
if ($now->dow() <
$week_offset) $start->addDays(-
7);
$start->addDays($week_offset -
7*
$this->row['calhistory']);
$stop->addDays($callength);
// check to see if this is an allowable calendar view (not too far into the future)
$off =
ceil($futureView /
7) *
7;
// $totaloffset = $offset + $callength - 7*$row['calhistory'] - $start->dow();
// $this->log("Found total offset of $totaloffset, calfuture=".$row['calfuture']." calhistory=".$row['calhistory']);
// //admin users are allowed to see further into the future.
// $this->_checkBookingAuth(-1);
// echo ! ($this->auth->permitted(BBROLE_VIEW_CALENDAR_FUTURE, $this->instrument));
// if (($totaloffset > $row['calfuture']) &&
// ! ($this->auth->permitted(BBROLE_VIEW_CALENDAR_FUTURE, $this->instrument))) {
// #echo "Found total offset of $totaloffset, but only ".$row['calfuture']." is permitted. ";
// $offset = $row['calfuture'] - $callength + 7*$row['calhistory'] + 7;
// $start->addDays($offset);
// #echo $start->dateTimeString();
// jump backwards to the start of that week.
//$day = $start->dow(); // the day of the week, 0=Sun, 6=Sat
//configure the calendar view granularity (not the same as booking granularity)
$granularity =
$this->row['calprecision'];
$timelines =
$this->row['caltimemarks'];
$cal->setTimeSlotPicture($this->row['timeslotpicture']);
/* if ($this->auth->permitted($futureView<-$callength ? BBROLE_MAKE_BOOKINGS_FUTURE : BBROLE_MAKE_BOOKINGS, $this->instrument)) {
$cal->bookhref = makeURL('book', array('instrid'=>$this->instrument));
$cal->bookhref = makeURL('bookcontact', array('instrid'=>$this->instrument));
$cal->bookhrefCallback =
array(&$this, 'MakeBookingHref');
$cal->setOutputStyles('', $conf->value('calendar', 'todaystyle'),
preg_split('{/}',$conf->value('calendar', 'monthstyle')), 'm');
echo
$cal->displayMonthAsTable($daystart,$daystop,$granularity,$timelines);
* Generate back | today | forward links for the calendar
* @return string html for links
$script =
'JumpCalendarTo';
$centreOffset =
$today->dsDaysBetween($centre);
array('instrid'=>
$this->instrument, 'caloffset'=>
$back),
.
'">« '.
T_('earlier') .
'</a>';
$links[] =
$this->_makeQuickJumpLinks(T_('jump back to:'), -
1, $calLength, $centre, $centreOffset, $script);
array('instrid'=>
$this->instrument, 'caloffset'=>
'today'),
.
'">'.
T_('today') .
'</a> ';
$select =
$this->_makeQuickJumpLinks(T_('jump forward to:'), 1, $calLength, $centre, $centreOffset, $script);
if ($select !==
'') $links[] =
$select;
array('instrid'=>
$this->instrument, 'caloffset'=>
$forward),
.
'">'.
T_('later') .
' »</a>';
$linkList =
join($links, ' | ');
<script type='text/javascript'>
function $script(offset) {
newLocation = '$location' + '&caloffset=' + offset;
document.location.href = newLocation;
return '<div style="text-align:center">' .
$js .
$linkList .
'</div>';
function _makeQuickJumpLinks($caption, $direction, $calLength, $centre, $centreOffset, $script) {
$backJumps =
array('<option value="0">'.
$caption .
'</option>');
for ($i=
1; $i <=
20; $i++
) {
$offset =
$direction *
$i *
$calLength;
$offsetDate =
clone($centre);
$offsetDate->addDays($offset);
$offset -=
$centreOffset;
$date =
$offsetDate->dateString();
$backJumps[] =
"<option value='$offset'>$date</option>";
return "<select name='backLink' onChange='$script(this.value)'>"
$reflector->excludeLogin();
$reflector->excludeRegex('@^Instrument-(\d+)-.+@');
$t .=
$reflector->display($this->PD);
$div =
'bumblebeeCalendarControls';
<script type='text/javascript'>
$t .=
'<div id="bumblebeeCalendarControls" style="display: none;">';
$t .=
"<div style='text-align: right'><a href='javascript:$func(false)'>".
T_('close').
'</a></div>';
.
'<legend>'.
T_('Select Instruments').
'</legend>'
.
'<input type="submit" name="configureview" value="'.
T_('Apply').
'" />';
$t .=
'<div id="bumblebeeCalendarControlsSwitch">';
$t .=
"<div id='toggle$div'>"
.
"<a href='javascript:$func(true)'>".
T_('Calendar controls').
'</a>'
$selectRow =
new nonDBRow('instrumentselect', NULL,
T_('Select which instruments you want to add to this calendar'));
$select->addFollowHidden($hidden);
$select->addCheckBox($include);
$select->connectDB('instruments', array('id', 'name'),
$select->setFormat('id', '%s', array('name'));
$selectRow->addElement($select);
return $selectRow->displayInTable(4);
* Display a single day's calendar for the selected instrument
* @todo ///TODO: combine this function with instrumentMonth to reduce duplication
$granularity =
$this->row['calprecision'];
$timelines =
$this->row['caltimemarks'];
if ($offset ==
'today') {
$start->addDays($offset);
// check to see if this is an allowable calendar view (not too far into the future)
$start->addDays($futureView);
$stop->addDays($futureView);
$totaloffset = $start->daysBetween($today);
$maxfuture = $row['calfuture'] + 7 - $today->dow();
//admin users are allowed to see further into the future.
$this->_checkBookingAuth(-1);
$this->log("Found total offset of $totaloffset, $maxfuture");
if ($totaloffset > $maxfuture && ! $this->auth->permitted(BBROLE_VIEW_CALENDAR_FUTURE, $this->instrument)) {
#echo "Found total offset of $totaloffset, but only ".$row['calfuture']." is permitted. ";
$delta = $maxfuture-$totaloffset;
#echo "Changing offset by $delta\n";
$cal->setTimeSlotPicture($this->row['timeslotpicture']);
/// FIXME: get this from the instrument table?
$cal->bookhrefCallback =
array(&$this, 'MakeBookingHref');
$cal->setOutputStyles('', 'caltoday', array('monodd', 'moneven'), 'm');
array('isodate'=>
$start->dateString()));
echo
$cal->displayDayAsTable($daystart,$daystop,$granularity,$timelines);
$this->_Forbidden(T_('Sorry, you are not permitted to view this instrument\'s calendar.'));
} // class ActionCalendar
Documentation generated on Tue, 06 Mar 2007 10:01:00 +0000 by phpDocumentor 1.3.0