Source for file bitmask.php

Documentation is available at bitmask.php

  1. <?php
  2. /**
  3. * a table of checkboxes for different options that are condensed into a single value by bitmask
  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: bitmask.php,v 1.3 2006/10/10 19:44:35 themill Exp $
  9. @package    Bumblebee
  10. @subpackage FormsLibrary
  11. */
  12.  
  13. /** Load ancillary functions */
  14. require_once 'inc/typeinfo.php';
  15.  
  16. /** parent object */
  17. require_once 'textfield.php';
  18. /** uses checkbox table list */
  19. require_once 'checkboxtablelist.php';
  20.  
  21. // ===================  NOTE  ======================
  22. // $this->select suffers from a horrible hack around a PHP 4.x bug
  23. // All we want to do is something like:
  24. //    $this->select->foo($a);
  25. // but that causes $this->select to suddenly become a reference: Object not &Object (see a var_dump)
  26. // see http://bugs.php.net/bug.php?id=24485 and http://bugs.php.net/bug.php?id=30787
  27. // There is no prospect of this bug ever being fixed in PHP4.
  28. // If we can come up with a clone() function for PHP4 that deals with references then
  29. // we can at least get rid of some of these horrible hacks:
  30. //     $s = $this->select;
  31. //     $s->foo($a);
  32. //     $this->select = $s;
  33. // ================================================
  34.  
  35.  
  36. /**
  37. * a table of checkboxes for different options that are condensed into a single value by bitmask
  38. *
  39. @package    Bumblebee
  40. @subpackage FormsLibrary
  41. */
  42. class Bitmask extends TextField {
  43.   /** @var boolean  show "expand" and "collapse" links */
  44.   var $showHideButtons = false;
  45.  
  46.   /** @var CheckBoxTableList   the actual check box list that will be shown */
  47.   var $select;
  48.  
  49.   /** @var integer  number of columns in the table  */
  50.   var $numcols    = '';
  51.   /** @var integer  number of extra columns to be added to the table  */
  52.   var $numExtraInfoCols = '';
  53.   /** @var string   html/css class for each row in the table  */
  54.   var $trclass    = 'itemrow';
  55.   /** @var string   html/css class for left-side table cell */
  56.   var $tdlclass   = 'itemL';
  57.   /** @var string   html/css class for right-side table cell */
  58.   var $tdrclass   = 'checkBoxEntry';
  59.   /** @var string   html/css class for entire table */
  60.   var $tableclass = 'selectlist';
  61.   /** @var array    list of table headings to be put at the top of the table */
  62.   var $tableHeading;
  63.   /** @var array    list of strings to be included in the footer of the table */
  64.   var $footer;
  65.   /** @var boolean  generate select/deselect links at the bottom of each column */
  66.   var $includeSelectAll = false;
  67.  
  68.   /**
  69.   *  Create a new BitmaskPopup
  70.   *
  71.   * @param string $name   the name of the field (db name, and html field name
  72.   * @param string $description  used in the html title of the list
  73.   */
  74.   function Bitmask($name$title$description=''$checkbox_description{
  75.     parent::TextField($name$title$description);
  76.     // $this->DEBUG=10;
  77.     $select new CheckBoxTableList($name)// see note above before refactoring $select out
  78.     $bit new CheckBox('bit'$checkbox_description);
  79.     $hidden new TextField('value');
  80.     $select->addFollowHidden($hidden);
  81.     $select->addCheckBox($bit);
  82.     $select->setFormat('id''%s'array('iv'));
  83.     $select->addSelectAllFooter(true);
  84.     $this->select = $select;
  85.     $this->numcols=1;
  86.   }
  87.  
  88.   /**
  89.   * Provides a set of values for the droplist rather than filling it from a db query
  90.   *
  91.   * cf. ChoiceList::connectDB
  92.   *
  93.   * @param array $list List of label=>value pairs
  94.   */
  95.   function setValuesArray($list$idfield='id'$valfield='iv'){
  96.     $s $this->select;   // see note above for why we have this horrible hack
  97.     $s->setValuesArray($list$idfield$valfield);
  98.     $this->select = $s;
  99.   }
  100.  
  101.   /**
  102.   *  Accessor method to set the table column headings
  103.   *
  104.   * @param array   new headings to use for the table
  105.   */
  106.   function setTableHeadings($headings{
  107.     $s $this->select;   // see note above for why we have this horrible hack
  108.     $s->tableHeadings $headings;
  109.     $this->select = $s;
  110.   }
  111.  
  112.   function update($data{
  113.     #echo "Name=({$this->namebase},{$this->name})<br />";
  114.     $value 0;
  115.     $fieldSet false;
  116.     $s $this->select;   // see note above for why we have this horrible hack
  117.     $s->namebase $this->namebase;
  118.     $s->MakeBoxMatrix();
  119.     for ($i=0$i<count($s->list->choicelist)$i++{
  120.       $fieldname  $s->boxMatrix[$i][0]->namebase $s->boxMatrix[$i][0]->name;
  121.       $fieldvalue $s->boxMatrix[$i][0]->namebase 'value';
  122.       #echo "/$fieldname/$fieldvalue/";
  123.       if (isset($data[$fieldname]&& isset($data[$fieldvalue])) {
  124.         $value |= $data[$fieldvalue];
  125.         $fieldSet true;
  126.         #echo "(set)";
  127.         #echo "('$data[$fieldname]')";
  128.       }
  129.       #echo $data[$fieldvalue];
  130.       #echo "#$value<br />";
  131.     }
  132.     if ($fieldSet{
  133.       $data[$this->namebase.$this->name$value;
  134.     }
  135.     $this->select = $s;
  136.  
  137.     //$this->select->update($data);
  138.     if (parent::update($data)) {
  139.       $this->setChecks($value);
  140.     }
  141.     return $this->changed;
  142.   }
  143.  
  144.   function set($value{
  145.     #echo "Set Name=({$this->namebase},{$this->name})<br />";
  146.     parent::set($value);
  147.     $s $this->select;
  148.     $s->namebase $this->namebase;
  149.     $s->MakeBoxMatrix();
  150.     $this->select = $s;
  151.     $this->setChecks($value);
  152.   }
  153.  
  154.   function setChecks($value{
  155.     for ($i=0$i<count($this->select->list->choicelist)$i++{
  156.       #echo "Setting $i, $value => ";
  157.       #echo $this->select->boxMatrix[$i][0]->namebase;
  158.       $this->select->boxMatrix[$i][0]->value =
  159.           ($value $this->select->list->choicelist[$i]['id'])
  160.                  == $this->select->list->choicelist[$i]['id'];
  161.       #echo $this->select->list->choicelist[$i]['id'] . " " . $this->select->boxMatrix[$i][0]->value;
  162.       #echo "<br />";
  163.     }
  164.   }
  165.  
  166.   /**
  167.   * embed the html within a div to enable some creative js folding
  168.   *
  169.   * @return string  html snippet that will open a new window with the html report
  170.   */
  171.   function wrapHTMLBuffer($contents{
  172.     if ($this->showHideButtonsreturn $contents;
  173.  
  174.     $id preg_replace('/[^\w]/''_'$this->namebase.$this->name);
  175.     $func "toggle$id";
  176.  
  177.     $jsbuf "
  178.     <div class='collapsecontrolid='show$idstyle='displaynone;'><a href='javascript:$func(true)'>"
  179.                   .T_('expand')."</a></div>
  180.     <div class='collapsecontrolid='hide$idstyle='displaynone;'><a href='javascript:$func(false)'>"
  181.                   .T_('collapse')."</a></div>
  182.     <div id='table$id'>$contents</div>
  183.     <script type='text/javascript'>
  184.       function $func(show{
  185.         if (show{
  186.           var id1 = document.getElementById('show$id');
  187.           id1.style.display = 'none';
  188.           var id2 = document.getElementById('hide$id');
  189.           id2.style.display = 'block';
  190.           var id3 = document.getElementById('table$id');
  191.           id3.style.display = 'inline';
  192.         } else {
  193.           var id1 = document.getElementById('show$id');
  194.           id1.style.display = 'block';
  195.           var id2 = document.getElementById('hide$id');
  196.           id2.style.display = 'none';
  197.           var id3 = document.getElementById('table$id');
  198.           id3.style.display = 'none';
  199.         }
  200.       }
  201.       $func(false);
  202.     </script>
  203.       ";
  204.     return $jsbuf;
  205.   }
  206.  
  207.   function displayInTable($numCols=3{
  208.     #preDump($this->select);
  209.     $this->select->numcols    = $this->numcols;
  210.     $this->select->numExtraInfoCols = $this->numExtraInfoCols;
  211.     $this->select->trclass    = $this->trclass;
  212.     $this->select->tdlclass   = $this->tdlclass;
  213.     $this->select->tdrclass   = $this->tdrclass;
  214.     $this->select->tableclass = $this->tableclass;
  215.     $this->select->tableHeading = $this->tableHeading;
  216.     $this->select->footer     = $this->footer;
  217. //     $this->select->includeSelectAll = $this->includeSelectAll;
  218.  
  219.     $tableclass (isset($this->tableclass" class='$this->tableclass'"");
  220.     $t  #'<html><head></head><body>'
  221.          #.
  222.          "<table title='{$this->description}$tableclass>\n"
  223.          .$this->select->displayInTable($this->numcols)
  224.          ."</table>";#</body></html>\n";
  225.     $enc $this->wrapHTMLBuffer($t);
  226.     return "<tr><td>{$this->longname}</td><td>$enc</td></tr>\n";
  227.   }
  228.  
  229.   /**
  230.   * PHP5 clone method
  231.   *
  232.   * PHP5 clone statement will perform only a shallow copy of the object. Any subobjects must also be cloned
  233.   */
  234.   function __clone() {
  235.     //echo "<hr /><br />Cloning bitmask<br />";
  236.     // Force a copy of contents of $this->list
  237.     if (is_object($this->select)) $this->select clone($this->select);
  238.   }
  239.  
  240. } // class Bitmask
  241.  

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