Source for file consume.php

Documentation is available at consume.php

  1. <?php
  2. /**
  3. * Edit/create/delete consumables records
  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/consume.php
  13. */
  14.  
  15. /** Load ancillary functions */
  16. require_once 'inc/typeinfo.php';
  17.  
  18. /** ConsumableUse object */
  19. require_once 'inc/bb/consumableuse.php';
  20. /** Consumable object */
  21. require_once 'inc/bb/consumable.php';
  22. /** User object */
  23. require_once 'inc/bb/user.php';
  24. /** DateRange object */
  25. require_once 'inc/bb/daterange.php';
  26. /** date manipulation routines */
  27. require_once 'inc/date.php';
  28. /** list of choices */
  29. require_once 'inc/formslib/anchortablelist.php';
  30. /** parent object */
  31. require_once 'inc/actions/actionaction.php';
  32.  
  33. /**
  34. * Edit/create/delete consumables records
  35. @package    Bumblebee
  36. @subpackage Actions
  37. */
  38. class ActionConsume extends ActionAction {
  39.  
  40.   /**
  41.   * Initialising the class
  42.   *
  43.   * @param  BumblebeeAuth $auth  Authorisation object
  44.   * @param  array $pdata   extra state data from the call path
  45.   * @return void nothing
  46.   */
  47.   function ActionConsume($auth$pdata{
  48.     parent::ActionAction($auth$pdata);
  49.     $this->mungeInputData();
  50.   }
  51.  
  52.   function go({
  53.     if (isset($this->PD['list'])) {
  54.       $daterange new DateRange('daterange'T_('Select date range'),
  55.                       T_('Enter the dates over which you want to report consumable use'));
  56.       $daterange->update($this->PD);
  57.       $daterange->checkValid();
  58.       if ($daterange->newObject || !$daterange->isValid{
  59.         $daterange->setDefaults(DR_PREVIOUSDR_QUARTER);
  60.         echo $daterange->display($this->PD);
  61.       elseif (isset($this->PD['consumableid'])) {
  62.         $this->listConsumeConsumable($this->PD['consumableid']$daterange);
  63.       elseif (isset($this->PD['user'])) {
  64.         $this->listConsumeUser($this->PD['user']$daterange);
  65.       }
  66.     elseif (isset($this->PD['delete'])) {
  67.       if ($this->readOnly{
  68.         $this->readOnlyError();
  69.       else {
  70.         $this->delete();
  71.       }
  72.     elseif (
  73.                 (isset($this->PD['id'])) &&
  74.                 (
  75.                   (isset($this->PD['user'])) || (isset($this->PD['consumableid']))
  76.                 )
  77.              {
  78.       if (isset($this->PD['user'])) {
  79.         $this->selectConsumeUser();
  80.       }
  81.       if (isset($this->PD['consumableid'])) {
  82.         $this->selectConsumeConsumable();
  83.       }
  84.     else {
  85.       if ($this->readOnly$this->_dataCleanse(array('id''user''consumableid'));
  86.       $this->edit();
  87.     }
  88.     echo "<br /><br /><a href='".makeURL('consume')."'>".T_('Return to consumable use list')."</a>";
  89.   }
  90.  
  91.   /**
  92.   * Select which user is consuming the item
  93.   */
  94.   function selectConsumeUser({
  95.     $path array();
  96.     if (isset($this->PD['consumableid'])) {
  97.       $path['consumableid'$this->PD['consumableid'];
  98.     }
  99.     $userselect new AnchorTableList(T_('Users')T_('Select which user is consuming'));
  100.     $userselect->deleted false;  // don't show deleted users
  101.     $userselect->connectDB("users"array('id''name''username'));
  102.     $userselect->hrefbase makeURL('consume'array_merge($patharray('user' => '__id__')));
  103.     $userselect->setFormat('id''%s'array('name')' %s'array('username'));
  104.  
  105.     if (isset($this->PD['consumableid']&& $this->PD['consumableid'0{
  106.       echo '<p>'.sprintf(T_('<a href="%s">View listing</a> for selected consumable'),
  107.                   makeURL('consume'array_merge($patharray('list'=>1))))."</p>\n";
  108.     }
  109.     echo $userselect->display();
  110.     echo '<br />';
  111.   }
  112.  
  113.   /**
  114.   * Select what item is being consumed
  115.   */
  116.   function selectConsumeConsumable({
  117.     $path array();
  118.     if (isset($this->PD['user'])) {
  119.       $path['user'$this->PD['user'];
  120.     }
  121.     $consumableselect new AnchorTableList(T_('Consumables')T_('Select which Consumables to use'));
  122.     $consumableselect->deleted false;   // don't show deleted consumables
  123.     $consumableselect->connectDB('consumables'array('id''name''longname'));
  124.     $consumableselect->hrefbase makeURL('consume'array_merge($patharray('consumableid' => '__id__')));
  125.     $consumableselect->setFormat('id''%s'array('name')' %50.50s'array('longname'));
  126.  
  127.     if (isset($this->PD['user']&& $this->PD['user'0{
  128.       echo '<p>'.sprintf(T_('<a href="%s">View listing</a> for selected user'),
  129.                   makeURL('consume'array_merge($patharray('list'=>1))))."</p>\n";
  130.     }
  131.     echo $consumableselect->display();
  132.   }
  133.  
  134.   function edit({
  135.     $recordid = isset($this->PD['id']$this->PD['id': -1;
  136.     $userid   = isset($this->PD['user']$this->PD['user': -1;
  137.     $consumableid = isset($this->PD['consumableid']$this->PD['consumableid': -1;
  138.     $uid $this->auth->uid;
  139.     $ip $this->auth->getRemoteIP();
  140.     $today new SimpleDate(time());
  141.     $rec new ConsumableUse($recordid$userid$consumableid,
  142.                               $uid$ip$today->dateString());
  143.     $rec->update($this->PD);
  144.     $rec->checkValid();
  145.     echo $this->reportAction($rec->sync(),
  146.           array(
  147.               STATUS_OK =>   ($recordid T_('Consumption recorded')
  148.                                             : T_('Consumption record updated')),
  149.               STATUS_ERR =>  T_('Consumption record could not be changed:').' '.$rec->errorMessage
  150.           )
  151.         );
  152.     echo $rec->display();
  153.     if ($rec->id 0{
  154.       $submit T_('Record consumable use');
  155.       $delete '0';
  156.     else {
  157.       $submit T_('Update entry');
  158.       $delete T_('Delete entry');
  159.     }
  160.     echo "<input type='submitname='submitvalue='$submit' />";
  161.     if ($deleteecho "<input type='submitname='deletevalue='$delete' />";
  162.   }
  163.  
  164.   function delete({
  165.     $rec new ConsumableUse($this->PD['id']);
  166.     echo $this->reportAction($rec->delete(),
  167.               array(
  168.                   STATUS_OK =>   T_('Consumption record deleted'),
  169.                   STATUS_ERR =>  T_('Consumption record could not be deleted:')
  170.                                   .'<br/><br/>'.$rec->errorMessage
  171.               )
  172.             );
  173.   }
  174.  
  175.   /**
  176.   * list the consumption records for this particular consumable
  177.   *
  178.   * @param integer $consumableID   table ID number of consumable to be displayed
  179.   * @param DateRange $daterange    time period over which consumption records are to be displayed
  180.   * @return void nothing
  181.   */
  182.   function listConsumeConsumable($consumableID$daterange{
  183.     $start $daterange->getStart();
  184.     $stop  $daterange->getStop();
  185.     $stop->addDays(1);
  186.     $consumable new Consumable($consumableID);
  187.     echo '<p>'
  188.           .sprintf(T_('Consumption records for %s')$consumable->fields['name']->value)
  189.           ."</p>\n";
  190.     $recselect new AnchorTableList(T_('Consumption Record'),
  191.                               T_('Select the consumption record to view')3);
  192.     $recselect->deleted NULL;
  193.     $recselect->setTableHeadings(array(T_('Date')T_('User')T_('Quantity')));
  194.     $recselect->connectDB('consumables_use',
  195.                           array(array('consumables_use.id','conid')'consumable''usewhen''username''name''quantity'),
  196.                           'consumable='.qw($consumableID)
  197.                               .' AND usewhen >= '.qw($start->dateTimeString())
  198.                               .' AND usewhen < '.qw($stop->dateTimeString()),
  199.                           'usewhen',
  200.                           array('consumables_use.id','conid'),
  201.                           NULL,
  202.                           array('users'=>'userid=users.id'));
  203.     $recselect->hrefbase makeURL('consume'array('id'=>'__id__'));
  204.     $recselect->setFormat('conid''%s'array('usewhen')' %s (%s)'array('name''username')'%s'array('quantity'));
  205.  
  206.     echo $recselect->display();
  207.   }
  208.  
  209.   /**
  210.   * list the consumption records for this particular consumable
  211.   *
  212.   * @param integer $userID         table ID number of user to be displayed
  213.   * @param DateRange $daterange    time period over which consumption records are to be displayed
  214.   * @return void nothing
  215.   */
  216.   function listConsumeUser($userID$daterange{
  217.     $start $daterange->getStart();
  218.     $stop  $daterange->getStop();
  219.     $stop->addDays(1);
  220.     $user new User($userIDtrue);
  221.     echo '<p>'
  222.         .sprintf(T_('Consumption records for %s (%s)'),
  223.               $user->fields['username']->value,
  224.               $user->fields['name']->value)
  225.         .")</p>\n";
  226.     $recselect new AnchorTableList(T_('Consumption Record'),
  227.                     T_('Select the consumption record to view')3);
  228.     $recselect->deleted NULL;
  229.     $recselect->setTableHeadings(array(T_('Date')T_('Item')T_('Quantity')));
  230.     $recselect->connectDB('consumables_use',
  231.                           array(array('consumables_use.id','conid')'consumable''usewhen''name''longname''quantity'),
  232.                           'userid='.qw($userID)
  233.                               .' AND usewhen >= '.qw($start->dateTimeString())
  234.                               .' AND usewhen < '.qw($stop->dateTimeString()),
  235.                           'usewhen',
  236.                           array('consumables_use.id','conid'),
  237.                           NULL,
  238.                           array('consumables'=>'consumable=consumables.id'));
  239.     $recselect->hrefbase makeURL('consume'array('id'=>'__id__'));
  240.     $recselect->setFormat('conid''%s'array('usewhen')' %s (%30.30s)'array('name''longname')'%s'array('quantity'));
  241.  
  242.     echo $recselect->display();
  243.   }
  244. }
  245.  
  246. ?>

Documentation generated on Tue, 06 Mar 2007 10:01:08 +0000 by phpDocumentor 1.3.0