Source for file viewbase.php

Documentation is available at viewbase.php

  1. <?php
  2. /**
  3. * Base class for viewing and editing booking information
  4. *
  5. @author    Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id: viewbase.php,v 1.12 2007/02/05 23:36:50 themill Exp $
  9. @package    Bumblebee
  10. @subpackage Actions
  11. *
  12. *  path (bumblebee root)/inc/actions/viewbase.php
  13. */
  14.  
  15. /** Load ancillary functions */
  16. require_once 'inc/typeinfo.php';
  17.  
  18. require_once 'inc/bb/configreader.php';
  19.  
  20. /** date maniuplation objects */
  21. require_once 'inc/date.php';
  22. /** URL manipulation/generation functions */
  23. require_once 'inc/menu.php';
  24. /** parent object */
  25. require_once 'inc/actions/actionaction.php';
  26.  
  27. /**
  28. * Base class for booking and viewing bookings
  29. @package    Bumblebee
  30. @subpackage Actions
  31. */
  32. class ActionViewBase extends ActionAction {
  33.  
  34.   /** @var integer   instrument id number being viewed/booked etc */
  35.   var $instrument;
  36.   /** @var array     row of data representing the database entry for the instrument */
  37.   var $row;
  38.   /** @var integer   maximum number of days into the future that bookings can be made */
  39.   var $maxFutureDays = 0;
  40.  
  41.   /**
  42.   * Initialising the class
  43.   *
  44.   * @param  BumblebeeAuth $auth  Authorisation object
  45.   * @param  array $pdata   extra state data from the call path
  46.   * @return void nothing
  47.   */
  48.   function ActionViewBase($auth$PDATA{
  49.     parent::ActionAction($auth$PDATA);
  50.     $this->mungeInputData();
  51.   }
  52.  
  53.   function mungeInputData({
  54.     parent::mungeInputData();
  55.     $this->instrument = issetSet($this->PD'instrid',0);
  56.   }
  57.  
  58.   /**
  59.   * Set flags according to the permissions of the logged in user
  60.   */
  61.   function _checkBookingAuth($userid{
  62.     $this->_isOwnBooking $this->auth->isMe($userid);
  63.     $this->_haveWriteAccess $this->_isOwnBooking
  64.                               || $this->auth->permitted(BBROLE_MAKE_BOOKINGS$this->instrument);
  65.   }
  66.  
  67.   /**
  68.   * Polite "go away" message if someone tries to delete a booking that they can't
  69.   */
  70.   function _forbiddenError($msg{
  71.     $this->log('Action forbidden: '.$msg);
  72.     echo $this->reportAction(STATUS_FORBIDDEN,
  73.               array(
  74.                   STATUS_FORBIDDEN => $msg.': <br/>'.T_('Sorry, you do not have permission to do this.'),
  75.               )
  76.             );
  77.     return STATUS_FORBIDDEN;
  78.   }
  79.  
  80.   /**
  81.   * Calculate calendar offset in days
  82.   *
  83.   * calculates the number of days between the current date and the last date that was selected
  84.   * by the user (in making a booking etc)
  85.   * @return string URL string for inclusion in href (examples: '28' '-14')
  86.   */
  87.   function _offset({
  88.     $now new SimpleDate(time());
  89.     if (isset($this->PD['isodate'])) {
  90.       $then new SimpleDate($this->PD['isodate']);
  91.       return floor($then->dsDaysBetween($now));
  92.     elseif (isset($this->PD['startticks'])) {
  93.       $then new SimpleDate($this->PD['startticks']);
  94.       return $then->dateString();
  95.     elseif (isset($this->PD['bookwhen-date'])) {
  96.       $then new SimpleDate($this->PD['bookwhen-date']);
  97.       return floor($then->dsDaysBetween($now));
  98.     }
  99.   }
  100.  
  101.   /**
  102.   * Makes a link back to the current calendar
  103.   *
  104.   * @return string URL string for link back to calendar view
  105.   */
  106.   function _calendarViewLink($instrument{
  107.     return '<br /><br /><a href="'.
  108.         makeURL('calendar'array('instrid'=>$instrument'caloffset'=>$this->_offset()))
  109.       .'">'.T_('Return to calendar view'.'</a>';
  110.   }
  111.  
  112.   /**
  113.   * Display a heading on the page with the instrument name and location
  114.   */
  115.   function displayInstrumentHeader({
  116.     $name '';
  117.     $location '';
  118.     if (is_array($this->instrument&& count($this->instrument1{
  119.       $name T_('Combined instrument display');
  120.       $names array();
  121.       foreach ($this->instrument as $i{
  122.         $names[sprintf(T_('%s (%s)')$this->row[$i]['longname']$this->row[$i]['location']);
  123.       }
  124.       $location join(', '$names);
  125.     else {
  126.       $name $this->row['longname'];
  127.       $location $this->row['location'];
  128.     }
  129.     $t '<h2 class="instrumentname">'
  130.         .xssqw($name)
  131.         .'</h2>'
  132.         .'<p class="instrumentlocation">'
  133.         .xssqw($location)
  134.         .'</p>'."\n";
  135.     $t .= $this->_instrumentNotes(false);
  136.     return $t;
  137.   }
  138.  
  139.   /**
  140.   * Display a footer for the page with the instrument comments and who looks after the instrument
  141.   */
  142.   function displayInstrumentFooter({
  143.     $t '';
  144.     $t .= $this->_instrumentNotes($this->rowtrue);
  145.     if ($this->row['supervisors']{
  146.       $t .= '<h3>'.T_('Instrument supervisors').'</h3>';
  147.       $t .= '<ul>';
  148.       foreach(preg_split('/,\s*/'$this->row['supervisors']as $username{
  149.         $user quickSQLSelect('users''username'$username);
  150.         $t .= '<li><a href="mailto:'xssqw($user['email'].'">'xssqw($user['name'].'</a></li>';
  151.       }
  152.       $t .= '</ul>';
  153.     }
  154.     return $t;
  155.   }
  156.  
  157.   /**
  158.   * Display the instrument comment in either header or footer as configured
  159.   *
  160.   * @param boolean $footer   called in the footer
  161.   * @returns string          header/footer to display for notes section
  162.   */
  163.   function _instrumentNotes($footer=true{
  164.     $conf ConfigReader::getInstance();
  165.     $t '';
  166.     $notesbottom $conf->value('calendar''notesbottom'true);
  167.     if ($notesbottom == $footer && $this->row['calendarcomment']{
  168.       $t '<div class="calendarcomment">'
  169.           .'<p>'
  170.           .preg_replace("/\n+/",
  171.                         '</p><p>',
  172.                           xssqw_relaxed($this->row['calendarcomment']))
  173.           .'</p></div>';
  174.     }
  175.     return $t;
  176.   }
  177.  
  178.  
  179.   /**
  180.   * Check if a date is within the permitted booking period for this user on this instrument.
  181.   *
  182.   * @param  SimpleDate   date to be checked
  183.   * @returns   1 if date is within permitted calendar period, returns 0 or number of days (negative) that the booking is beyond the end of the calendar
  184.   */
  185.   function BookingPastNormalCalendar($date$calcOffset=0{
  186.     #$this->DEBUG = 10;
  187.     $today new SimpleDate(time());
  188.     $today->dayRound();
  189.     $totaloffset $date->dsDaysBetween($today);
  190.  
  191.     if ($this->maxFutureDays == 0{
  192.       $this->maxFutureDays = $this->row['calfuture'$today->dow();
  193.     }
  194.  
  195.     #printf ('today = %s, checkDate = %s, ', $today->dateTimeString(), $date->dateTimeString());
  196.     $this->log("Found total offset of $totaloffset, {$this->maxFutureDays}");
  197.  
  198.     $offset = floor($this->maxFutureDays - $totaloffset $calcOffset);
  199.     if ($offset <= 0{
  200.       return $offset;
  201.     }
  202.  
  203.     return 1;
  204.   }
  205.  
  206.   function MakeBookingHref($date) {
  207.     if ($this->MakeBookingPermitted($date)) {
  208.       return makeURL('book',        array('instrid'=>$this->instrument));
  209.     } else {
  210.       return makeURL('bookcontact', array('instrid'=>$this->instrument));
  211.     }
  212.   }
  213.  
  214.   function MakeBookingPermitted($date) {
  215.     $permission = $this->BookingPastNormalCalendar($date10
  216.                       ? BBROLE_MAKE_BOOKINGS_FUTURE
  217.                       : BBROLE_MAKE_BOOKINGS;
  218.     return $this->auth->permitted($permission$this->instrument);
  219.   }
  220.  
  221.   function ViewCalendarPermitted($offset) {
  222.     if (type_is_a($offset, 'SimpleDate')) {
  223.       $date = $offset;
  224.     } else {
  225.       $date = new SimpleDate(time());
  226.       $date->addDays($offset);
  227.     }
  228.     #echo "Checking calendar for ". $date->dateTimeString();
  229.     $permission = $this->BookingPastNormalCalendar($date0
  230.                       ? BBROLE_VIEW_CALENDAR_FUTURE
  231.                       : BBROLE_VIEW_CALENDAR;
  232.     return $this->auth->permitted($permission$this->instrument);
  233.   }
  234.  
  235.   function _loadMultiInstrument() {
  236.     $this->row = quickSQLSelect('instruments''id'$this->instrument);
  237.     if (isset($this->row['id'])) {
  238.       $this->_UnknownInstrument();
  239.       return false;
  240.     }
  241.     foreach ($this->instrument as $i{
  242.       $this->row[$iquickSQLSelect('instruments''id'$i);
  243.       if (isset($this->row['id'])) {
  244.         $this->_UnknownInstrument();
  245.         return false;
  246.       }
  247.     }
  248.     return true;
  249.   }
  250.  
  251.   function _Forbidden($message=null) {
  252.     if ($message == null) {
  253.       $message = T_('Sorry, you are not permitted to do that with this instrument.');
  254.     }
  255.     echo $this->reportAction(STATUS_FORBIDDEN,
  256.                 array(
  257.                   STATUS_FORBIDDEN => $message
  258.                 )
  259.               );
  260.   }
  261.  
  262.   function _UnknownInstrument($message=null) {
  263.     if ($message == null) {
  264.       $message = T_('Sorry, that instrument does not exist.');
  265.     }
  266.     echo $this->reportAction(STATUS_FORBIDDEN,
  267.                 array(
  268.                   STATUS_FORBIDDEN => $message
  269.                 )
  270.               );
  271.   }
  272.  
  273.   function _UnknownBooking($message=null) {
  274.     if ($message == null) {
  275.       $message = T_('Sorry, that booking does not exist.');
  276.     }
  277.     echo $this->reportAction(STATUS_FORBIDDEN,
  278.                 array(
  279.                   STATUS_FORBIDDEN => $message
  280.                 )
  281.               );
  282.   }
  283.  
  284. }

Documentation generated on Tue, 06 Mar 2007 10:02:11 +0000 by phpDocumentor 1.3.0