Source for file view.php

Documentation is available at view.php

  1. <?php
  2. /**
  3. * View a list of instruments that are available
  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$
  9. * @package    Bumblebee
  10. * @subpackage Actions
  11. *
  12. *  path (bumblebee root)/inc/actions/view.php
  13. */
  14.  
  15. /** Load ancillary functions */
  16. require_once 'inc/typeinfo.php';
  17.  
  18. /** list of choices object */
  19. require_once 'inc/formslib/anchortablelist.php';
  20. /** translated string type */
  21. require_once 'inc/formslib/bbstring.php';
  22. /** parent object */
  23. require_once 'inc/actions/viewbase.php';
  24. /** list of bookings */
  25. require_once 'inc/actions/bookinglist.php';
  26.  
  27. /**
  28. * View a list of instruments so the user can view and make bookings
  29. * @package    Bumblebee
  30. * @subpackage Actions
  31. */
  32. class ActionView extends ActionViewBase {
  33.  
  34.   var $defaultListingLength = 14;
  35.  
  36.   /**
  37.   * Initialising the class
  38.   *
  39.   * @param  BumblebeeAuth $auth  Authorisation object
  40.   * @param  array $pdata   extra state data from the call path
  41.   * @return void nothing
  42.   */
  43.   function ActionView($auth, $PDATA) {
  44.     parent::ActionViewBase($auth, $PDATA);
  45.     $this->mungeInputData();
  46.   }
  47.  
  48.   function go() {
  49.     $this->selectInstrument();
  50.     $this->showMyBookings();
  51.     $this->showMyProjectBookings();
  52.     $this->showMyGroupBookings();
  53.   }
  54.  
  55.   /**
  56.   * Select which instrument for which the calendar should be displayed
  57.   */
  58.   function selectInstrument() {
  59.     $instrselect = new AnchorTableList('Instrument', T_('Select which instrument to view'), 3);
  60.  
  61.     $headings = array(new bbString('name', T_('name')),
  62.                       new bbString('longname', T_('description')),
  63.                   new bbString('location', T_('location')));
  64.  
  65.     $instrselect->setTableHeadings($headings);
  66.     $instrselect->sortByHeadings(true, $this->PD);
  67.     $instrselect->sortByHref = makeUrl('view', array($instrselect->sortbyKey => '__sortby__'));
  68.  
  69.     if ($this->auth->permitted(BBROLE_VIEW_LIST)) {
  70.       $instrselect->connectDB('instruments',
  71.                             array('id', 'name', 'longname', 'location')
  72.                             );
  73.     } else {
  74.       $instrselect->connectDB('instruments',
  75.                             array('id', 'name', 'longname', 'location'),
  76.                             'userid='.qw($this->auth->getEUID()),
  77.                             'name',
  78.                             'id',
  79.                             NULL,
  80.                             array('permissions'=>'instrid=id'));
  81.     }
  82.     $instrselect->hrefbase = makeURL('calendar', array('instrid'=>'__id__'));
  83.     $instrselect->setFormat('id', '%s', array('name'), ' %50.50s', array('longname'), ' %20.20s', array('location'));
  84.     echo '<h2>' . T_('Please select an instrument to view') . '</h2>';
  85.     echo $instrselect->display();
  86.   }
  87.  
  88.   function showMyBookings() {
  89.     $list = new ActionBookingList($this->auth, null);
  90.     $list->tableCaption = '<h2>' . T_('My bookings') . '</h2>';
  91.     $list->noneFoundNotice = T_('You have no bookings between %s and %s.');
  92.     $list->user = $this->auth->getEUID();
  93.     $list->setDefaultRestrictions($this->defaultListingLength);
  94.     $list->showBookings();
  95.   }
  96.  
  97.   function showMyGroupBookings() {
  98.     global $TABLEPREFIX;
  99.  
  100.     $list = new ActionBookingList($this->auth, null);
  101.     $list->tableCaption = '<h2>' . T_('My group\'s bookings') . '</h2>';
  102.     $list->noneFoundNotice = T_('Your group has no bookings between %s and %s.');
  103.  
  104.     $projects = array();
  105.     $userid = $this->auth->getEUID();
  106.     $q = "SELECT userprojects.projectid as projectid "
  107.         ."FROM {$TABLEPREFIX}projectgroups AS projectgroups "
  108.         ."LEFT JOIN {$TABLEPREFIX}userprojects AS userprojects "
  109.             ."ON userprojects.projectid=projectgroups.projectid "
  110.         ."WHERE userprojects.userid=".qw($userid);
  111.     $sql = db_get($q, false);
  112.     while ($g = db_fetch_array($sql)) {
  113.       $projects[] = $g['projectid'];
  114.     }
  115.     $list->projects = $projects;
  116.  
  117.     $list->setDefaultRestrictions($this->defaultListingLength);
  118.     $list->showBookings();
  119.   }
  120.  
  121.   function showMyProjectBookings() {
  122.     global $TABLEPREFIX;
  123.  
  124.     $list = new ActionBookingList($this->auth, null);
  125.     $list->tableCaption = '<h2>' . T_('My project\'s bookings') . '</h2>';
  126.     $list->noneFoundNotice = T_('Your project has no bookings between %s and %s.');
  127.  
  128.     $projects = array();
  129.     $userid = $this->auth->getEUID();
  130.     $q = "SELECT projectid FROM {$TABLEPREFIX}userprojects WHERE userid=".qw($userid);
  131.     $sql = db_get($q, false);
  132.     while ($g = db_fetch_array($sql)) {
  133.       $projects[] = $g['projectid'];
  134.     }
  135.     $list->projects = $projects;
  136.     $list->setDefaultRestrictions($this->defaultListingLength);
  137.     $list->showBookings();
  138.   }
  139.  
  140. } // class ActionView
  141.  
  142. ?>

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