Source for file book.php

Documentation is available at book.php

  1. <?php
  2. /**
  3. * Make, edit and delete bookings
  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: book.php,v 1.16 2007/02/05 23:36:50 themill Exp $
  9. @package    Bumblebee
  10. @subpackage Actions
  11. *
  12. *  path (bumblebee root)/inc/actions/book.php
  13. */
  14.  
  15. /** Load ancillary functions */
  16. require_once 'inc/typeinfo.php';
  17.  
  18. /** calendar object */
  19. require_once 'inc/bb/calendar.php';
  20. /** generic booking entry object */
  21. require_once 'inc/bb/bookingentry.php';
  22. /** read-only booking entry object */
  23. require_once 'inc/bb/bookingentryro.php';
  24. /** list of choices object */
  25. require_once 'inc/formslib/anchortablelist.php';
  26. /** date maniuplation objects */
  27. require_once 'inc/date.php';
  28. /** parent object */
  29. require_once 'inc/actions/viewbase.php';
  30.  
  31. /**
  32. * Make edit or delete a booking
  33. @package    Bumblebee
  34. @subpackage Actions
  35. */
  36. class ActionBook extends ActionViewBase {
  37.   /**
  38.   * booking is for the logged in user
  39.   * @var boolean 
  40.   */
  41.   var $_isOwnBooking    = false;
  42.   /**
  43.   * logged in user can modify booking
  44.   * @var boolean 
  45.   */
  46.   var $_haveWriteAccess = false;
  47.  
  48.  
  49.   /**
  50.   * Initialising the class
  51.   *
  52.   * @param  BumblebeeAuth $auth  Authorisation object
  53.   * @param  array $pdata   extra state data from the call path
  54.   * @return void nothing
  55.   */
  56.   function ActionBook($auth$PDATA{
  57.     parent::ActionViewBase($auth$PDATA);
  58.     $this->mungeInputData();
  59.   }
  60.  
  61.   function go({
  62.     if (isset($this->PD['bookid'])
  63.         && isset($this->PD['instrid'])
  64.               || $this->PD['instrid'1
  65.               || $this->PD['instrid'== '')) {
  66.       $err 'Invalid action specification in actions/book.php::go(): no instrument specified';
  67.       $this->log($err);
  68.       trigger_error($errE_USER_WARNING);
  69.       return;
  70.     }
  71.  
  72.     if (isset($this->PD['bookid'])
  73.         && isset($this->PD['instrid'])
  74.               || $this->PD['instrid'1
  75.               || $this->PD['instrid'== '')) {
  76.        $booking quickSQLSelect('bookings''id'$this->PD['bookid']);
  77.        if (isset($booking['id'])) return $this->_UnknownBooking();
  78.        $this->instrument = $booking['instrument'];
  79.        $start new SimpleDate($booking['bookwhen']);
  80.        $this->PD['isodate'$start->dateString();
  81.     }
  82.  
  83.     $this->row = quickSQLSelect('instruments''id'$this->instrument);
  84.     foreach ($this->instrument as $i{
  85.       $this->row[$iquickSQLSelect('instruments''id'$i);
  86.     }
  87.  
  88.     if (isset($this->PD['delete']&& isset($this->PD['bookid']&& $this->readOnly{
  89.       $this->deleteBooking();
  90.       echo $this->_calendarViewLink($this->instrument);
  91.     elseif (isset($this->PD['bookid']&& isset($this->PD['edit']&& $this->readOnly{
  92.       $this->editBooking(true);
  93.       echo $this->_calendarViewLink($this->instrument);
  94.     elseif (isset($this->PD['bookid']&& isset($this->PD['editform'])) {
  95.       $this->editBooking(false);
  96.       echo $this->_calendarViewLink($this->instrument);
  97.     elseif (isset($this->PD['bookid'])) {
  98.       $this->viewBooking();
  99.       echo $this->_calendarViewLink($this->instrument);
  100.     elseif ( (isset($this->PD['startticks']&& isset($this->PD['stopticks']))
  101.                || (isset($this->PD['bookwhen-time']&& isset($this->PD['bookwhen-date']&& isset($this->PD['duration']) ) ) {
  102.       $this->createBooking();
  103.       echo $this->_calendarViewLink($this->instrument);
  104.     else {
  105.       # shouldn't get here
  106.       $err 'Invalid action specification in action/book.php::go()';
  107.       $this->log($err);
  108.       trigger_error($errE_USER_WARNING);
  109.       return;
  110.     }
  111.   }
  112.  
  113.   function mungeInputData({
  114.     parent::mungeInputData();
  115.     if (strpos($this->instrument',')) {
  116.       $this->instrument = explode(','$this->instrument);
  117.     else {
  118.       $this->instrument = array($this->instrument);
  119.     }
  120.     echoData($this->PD0);
  121.   }
  122.  
  123.   /**
  124.   * Make a new booking
  125.   */
  126.   function createBooking({
  127.     $start new SimpleDate(issetSet($this->PD'startticks'));
  128.     $stop  new SimpleDate(issetSet($this->PD'stopticks'));
  129.     $duration new SimpleTime($stop->subtract($start));
  130.     $this->log($start->dateTimeString().', '.$duration->timeString().', '.$start->dow());
  131.  
  132.     if ($this->MakeBookingPermitted($start)) {
  133.       $this->_editCreateBooking(-1$start->dateTimeString()$duration->timeString());
  134.     else {
  135.       $this->_createBookingForbidden();
  136.     }
  137.   }
  138.  
  139.   /**
  140.   * Editing an existing booking
  141.   */
  142.   function editBooking($doSync{
  143.     $start new SimpleDate(issetSet($this->PD'startticks'));
  144.     $this->_editCreateBooking($this->PD['bookid']$start->dateTimeString()-1$doSync);
  145.   }
  146.  
  147.   /**
  148.   * Do the hard work to edit or create the booking
  149.   */
  150.   function _editCreateBooking($bookid$start$duration$doSync=false{
  151.     $ip $this->auth->getRemoteIP();
  152.     //echo $ip;
  153.     $booking new BookingEntry($bookid$this->auth$this->instrument$this->row['mindatechange'],$ip,
  154.                                 $start$duration$this->row['timeslotpicture']);
  155.     $this->_checkBookingAuth($booking->fields['userid']->getValue());
  156.     if ($this->_haveWriteAccess{
  157.       return $this->_forbiddenError(T_('Edit booking'));
  158.     }
  159.     $booking->update($this->PD);
  160.     $booking->checkValid();
  161.     echo $this->displayInstrumentHeader();
  162.  
  163.     if ($doSync{
  164.       echo $this->reportAction($booking->sync(),
  165.                 array(
  166.                     STATUS_OK =>   ($bookid T_('Booking made'T_('Booking updated')),
  167.                     STATUS_ERR =>  T_('Booking could not be made:').'<br/><br/>'.$booking->errorMessage
  168.                 )
  169.               );
  170.     }
  171.     echo $booking->display();
  172.     $submit ($booking->id 0T_('Make booking'T_('Update booking');
  173.     $delete ($booking->id >= && $booking->deletableT_('Delete booking''';
  174.     echo "<input type='submitname='submitvalue='$submit' />";
  175.     if ($deleteecho "<input type='submitname='deletevalue='$delete' />";
  176.     echo $this->displayInstrumentFooter();
  177.   }
  178.  
  179.   /**
  180.   * Display a booking in read-only format (i.e. not in a form to allow it to be edited)
  181.   */
  182.   function viewBooking({
  183.     $booking new BookingEntryRO($this->PD['bookid']);
  184.     $this->_checkBookingAuth($booking->data->userid);
  185.     echo $this->displayInstrumentHeader();
  186.     $adminView $this->auth->permitted(BBROLE_VIEW_BOOKINGS_DETAILS$this->instrument);
  187.     echo $booking->display($adminView$this->_isOwnBooking);
  188.     $adminEdit $this->auth->permitted(BBROLE_EDIT_ALL$this->instrument);
  189.     if ($this->_isOwnBooking || $adminEdit{
  190.       echo "<p><a href='"
  191.             .makeURL('book',
  192.                 array('instrid'  => $this->instrument,
  193.                       'bookid'   => $this->PD['bookid'],
  194.                       'editform' => 1,
  195.                       'isodate'  => $this->PD['isodate']))
  196.             ."'>"T_('Edit booking'."</a></p>\n";
  197.     }
  198.   }
  199.  
  200.   /**
  201.   * Delete a booking
  202.   */
  203.   function deleteBooking({
  204.     $booking new BookingEntry($this->PD['bookid']$this->auth$this->instrument$this->row['mindatechange']);
  205.     $this->_checkBookingAuth($booking->fields['userid']->getValue());
  206.     if ($this->_haveWriteAccess{
  207.       return $this->_forbiddenError(T_('Delete booking'));
  208.     }
  209.     echo $this->displayInstrumentHeader();
  210.     echo $this->reportAction($booking->delete(),
  211.               array(
  212.                   STATUS_OK =>   T_('Booking deleted'),
  213.                   STATUS_ERR =>  T_('Booking could not be deleted:').'<br/><br/>'.$booking->errorMessage
  214.               )
  215.             );
  216.   }
  217.  
  218.   function _createBookingForbidden({
  219.     $this->_Forbidden(T_('Sorry, making bookings at that time is not permitted.'));
  220.   }
  221.  
  222. // class ActionBook
  223. ?>

Documentation generated on Tue, 06 Mar 2007 10:00:46 +0000 by phpDocumentor 1.3.0