Source for file specialcosts.php

Documentation is available at specialcosts.php

  1. <?php
  2. /**
  3. * Edit/create/delete special instrument usage costs
  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/specialcosts.php
  13. */
  14.  
  15. /** Load ancillary functions */
  16. require_once 'inc/typeinfo.php';
  17.  
  18. /** specialcosts object */
  19. require_once 'inc/bb/specialcosts.php';
  20. /** list of choices */
  21. require_once 'inc/formslib/anchortablelist.php';
  22. /** parent object */
  23. require_once 'inc/actions/actionaction.php';
  24.  
  25. /**
  26. * Edit/create/delete special instrument usage costs
  27. *
  28. @package    Bumblebee
  29. @subpackage Actions
  30. */
  31. class ActionSpecialCosts extends ActionAction {
  32.  
  33.   /**
  34.   * Initialising the class
  35.   *
  36.   * @param  BumblebeeAuth $auth  Authorisation object
  37.   * @param  array $pdata   extra state data from the call path
  38.   * @return void nothing
  39.   */
  40.   function ActionSpecialCosts($auth$pdata{
  41.     parent::ActionAction($auth$pdata);
  42.     //$this->DEBUG=10;
  43.     $this->mungeInputData();
  44.   }
  45.  
  46.   function go({
  47.     if (isset($this->PD['project'])) {
  48.       if ($this->PD['createnew']{
  49.         $this->selectProjectCreate();
  50.       else {
  51.         $this->selectProject();
  52.       }
  53.     elseif (isset($this->PD['instrument'])) {
  54.       if ($this->PD['createnew']{
  55.         $this->selectInstrumentCreate();
  56.       else {
  57.         $this->selectInstrument();
  58.       }
  59.     elseif (isset($this->PD['delete'])) {
  60.       if ($this->readOnly{
  61.         $this->readOnlyError();
  62.       else {
  63.         $this->delete();
  64.       }
  65.     else {
  66.       if ($this->readOnly$this->_dataCleanse(array('project''instrument''createnew'));
  67.       $this->edit();
  68.     }
  69.     echo "<br /><br /><a href='".makeURL('specialcosts')."'>".T_('Return to special costs list')."</a>";
  70.   }
  71.  
  72.   function mungeInputData({
  73.     parent::mungeInputData();
  74.     $this->PD['createnew'= isset($this->PD['createnew']&& $this->PD['createnew'];
  75.     if (isset($this->PD['project']&& $this->PD['project'== -1{
  76.       $this->PD['createnew'true;
  77.       unset($this->PD['project']);
  78.     }
  79.     if (isset($this->PD['instrument']&& $this->PD['instrument'== -1{
  80.       $this->PD['createnew'true;
  81.       unset($this->PD['instrument']);
  82.     }
  83. /*    if (isset($this->PD[1]) && ($this->PDATA[1] == -1)) {
  84.       $this->PD['createnew'] = 1;
  85.       array_shift($this->PDATA);
  86.     }
  87.     if (isset($this->PDATA[1]) && ! empty($this->PDATA[1]) && is_numeric($this->PDATA[1])) {
  88.       $this->PD['project'] = $this->PDATA[1];
  89.     }
  90.     if (isset($this->PDATA[2]) && ! empty($this->PDATA[2]) && is_numeric($this->PDATA[2])) {
  91.       if ($this->PDATA[2] == -1) {
  92.         $this->PD['createnew'] = 1;
  93.       } else {
  94.         $this->PD['instrument'] = $this->PDATA[2];
  95.       }
  96.     }
  97.     if (isset($this->PD['delete']) && !empty($this->PD['delete'])) {
  98.       $this->PD['delete'] = 1;
  99.     }
  100.     echoData($this->PD, 0);*/
  101.   }
  102.  
  103.   /**
  104.   * Select for which project the special costs should be displayed
  105.   *
  106.   */
  107.   function selectProject({
  108.     $this->log("selectProject: which existing rate to edit");
  109.     $select new AnchorTableList(T_('Projects')T_('Select project to view rates'));
  110.     $select->connectDB('projects'array('id''name''longname'),
  111.                             'projectid IS NOT NULL',
  112.                             'name',
  113.                             'id',
  114.                             NULL,
  115.                             array('projectrates'=>'projectrates.projectid=projects.id')true);
  116.     $select->list->prepend(array('-1'T_('Create new project rate')));
  117.     $select->hrefbase makeURL('specialcosts'array('project'=>'__id__'));
  118.     $select->setFormat('id''%s'array('name')'%50.50s'array('longname'));
  119.     echo $select->display();
  120.   }
  121.  
  122.   /**
  123.   * Select for which project a special cost should be created
  124.   *
  125.   */
  126.   function selectProjectCreate({
  127.     $this->log("selectProjectCreate: which project to create a new rate for");
  128.     $select new AnchorTableList(T_('Projects')T_('Select project to create rate'));
  129.     $select->connectDB('projects'array('id''name''longname'));
  130.     $select->hrefbase makeURL('specialcosts'array('project'=>'__id__''createnew'=>1));
  131.     $select->setFormat('id''%s'array('name')'%50.50s'array('longname'));
  132.     echo $select->display();
  133.   }
  134.  
  135.   /**
  136.   * Select for which instrument the special costs should be displayed
  137.   *
  138.   */
  139.   function selectInstrument({
  140.     $this->log("selectInstrument: which existing rate to edit");
  141.     $select new AnchorTableList(T_('Instruments')T_('Select instrument to view rates'));
  142.     $select->connectDB('instruments'array('id''name''longname'),
  143.                             'projectid='.qw($this->PD['project']),
  144.                             'name',
  145.                             'id',
  146.                             NULL,
  147.                             array('projectrates'=>'projectrates.instrid=instruments.id')true);
  148.     $select->list->prepend(array('-1'T_('Create new project rate')));
  149.     $select->hrefbase makeURL('specialcosts'array('instrument'=>'__id__''createnew'=>$this->PD['createnew']'project'=>$this->PD['project']));
  150.     $select->setFormat('id''%s'array('name')'%50.50s'array('longname'));
  151.     echo $select->display();
  152.   }
  153.  
  154.   /**
  155.   * Select for which instrument a special cost should be created
  156.   *
  157.   */
  158.   function selectInstrumentCreate({
  159.     $this->log("selectInstrumentCreate: which instrument to create a new rate for");
  160.     $select new AnchorTableList(T_('Instruments')T_('Select instrument to create rate'));
  161.     $select->connectDB('instruments'array('id''name''longname'),
  162.                             'projectid IS NULL',        //find rows *not* in the join
  163.                             'name',
  164.                             'id',
  165.                             NULL,
  166.                             array('projectrates'=>'projectrates.instrid=instruments.id AND projectrates.projectid='.qw($this->PD['project']))true);
  167.     $select->hrefbase makeURL('specialcosts'array('instrument'=>'__id__''createnew'=>$this->PD['createnew']'project'=>$this->PD['project']));
  168.     $select->setFormat('id''%s'array('name')'%50.50s'array('longname'));
  169.     echo $select->display();
  170.   }
  171.  
  172.   function edit({
  173.     list($id$specCost$this->_getCostObject();
  174.     $specCost->update($this->PD);
  175.     $specCost->checkValid();
  176.     echo $this->reportAction($specCost->sync(),
  177.           array(
  178.               STATUS_OK =>   ($id T_('Cost schedule created'T_('Cost schedule updated')),
  179.               STATUS_ERR =>  T_('Cost schedule could not be changed:').' '.$specCost->errorMessage
  180.           )
  181.         );
  182.     echo $specCost->display();
  183.     if ($id 0{
  184.       $submit T_('Create new project cost');
  185.       $delete '0';
  186.     else {
  187.       $submit T_('Update entry');
  188.       $delete T_('Delete entry');
  189.     }
  190.     //echo '<input type="hidden" name="project" value="'.$this->PD['project'].'" />';
  191.     //echo '<input type="hidden" name="instrument" value="'.$this->PD['instrument'].'" />';
  192.     echo "<input type='submitname='submitvalue='$submit' />";
  193.     if ($deleteecho "<input type='submitname='deletevalue='$delete' />";
  194.   }
  195.  
  196.   function delete({
  197.     list($id$cost$this->_getCostObject();
  198.     echo $this->reportAction($cost->delete(),
  199.               array(
  200.                   STATUS_OK =>   T_('Cost deleted'),
  201.                   STATUS_ERR =>  T_('Cost could not be deleted:').'<br/><br/>'.$cost->errorMessage
  202.               )
  203.             );
  204.   }
  205.  
  206.   /**
  207.   * Create a SpecialCost object
  208.   *
  209.   * @return array ($id, $special_cost)
  210.   */
  211.   function _getCostObject({
  212.     if ($this->PD['createnew']{
  213.       $id = -1;
  214.     else {
  215.       $row quickSQLSelect('projectrates'array('projectid',         'instrid'),
  216.                                             array($this->PD['project']$this->PD['instrument']));
  217.       $id (is_array($row&& isset($row['rate'])) $row['rate': -1;
  218.     }
  219.     $specCost new SpecialCost($id$this->PD['project']$this->PD['instrument']);
  220.     return array($id$specCost);
  221.   }
  222.  
  223.  
  224. //ActionSpecialCost
  225.  
  226.  
  227. ?>

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