Source for file bitmask.php
Documentation is available at bitmask.php
* a table of checkboxes for different options that are condensed into a single value by bitmask
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: bitmask.php,v 1.3 2006/10/10 19:44:35 themill Exp $
* @subpackage FormsLibrary
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
require_once 'textfield.php';
/** uses checkbox table list */
require_once 'checkboxtablelist.php';
// =================== NOTE ======================
// $this->select suffers from a horrible hack around a PHP 4.x bug
// All we want to do is something like:
// $this->select->foo($a);
// but that causes $this->select to suddenly become a reference: Object not &Object (see a var_dump)
// see http://bugs.php.net/bug.php?id=24485 and http://bugs.php.net/bug.php?id=30787
// There is no prospect of this bug ever being fixed in PHP4.
// If we can come up with a clone() function for PHP4 that deals with references then
// we can at least get rid of some of these horrible hacks:
// ================================================
* a table of checkboxes for different options that are condensed into a single value by bitmask
* @subpackage FormsLibrary
/** @var boolean show "expand" and "collapse" links */
/** @var CheckBoxTableList the actual check box list that will be shown */
/** @var integer number of columns in the table */
/** @var integer number of extra columns to be added to the table */
/** @var string html/css class for each row in the table */
/** @var string html/css class for left-side table cell */
/** @var string html/css class for right-side table cell */
/** @var string html/css class for entire table */
/** @var array list of table headings to be put at the top of the table */
/** @var array list of strings to be included in the footer of the table */
/** @var boolean generate select/deselect links at the bottom of each column */
* Create a new BitmaskPopup
* @param string $name the name of the field (db name, and html field name
* @param string $description used in the html title of the list
function Bitmask($name, $title, $description=
'', $checkbox_description) {
parent::TextField($name, $title, $description);
$select =
new CheckBoxTableList($name); // see note above before refactoring $select out
$bit =
new CheckBox('bit', $checkbox_description);
$select->addFollowHidden($hidden);
$select->addCheckBox($bit);
$select->setFormat('id', '%s', array('iv'));
$select->addSelectAllFooter(true);
* Provides a set of values for the droplist rather than filling it from a db query
* cf. ChoiceList::connectDB
* @param array $list List of label=>value pairs
$s =
$this->select; // see note above for why we have this horrible hack
$s->setValuesArray($list, $idfield, $valfield);
* Accessor method to set the table column headings
* @param array new headings to use for the table
$s =
$this->select; // see note above for why we have this horrible hack
$s->tableHeadings =
$headings;
#echo "Name=({$this->namebase},{$this->name})<br />";
$s =
$this->select; // see note above for why we have this horrible hack
for ($i=
0; $i<
count($s->list->choicelist); $i++
) {
$fieldname =
$s->boxMatrix[$i][0]->namebase .
$s->boxMatrix[$i][0]->name;
$fieldvalue =
$s->boxMatrix[$i][0]->namebase .
'value';
#echo "/$fieldname/$fieldvalue/";
if (isset
($data[$fieldname]) && isset
($data[$fieldvalue])) {
$value |=
$data[$fieldvalue];
#echo "('$data[$fieldname]')";
#echo $data[$fieldvalue];
//$this->select->update($data);
if (parent::update($data)) {
#echo "Set Name=({$this->namebase},{$this->name})<br />";
for ($i=
0; $i<
count($this->select->list->choicelist); $i++
) {
#echo "Setting $i, $value => ";
#echo $this->select->boxMatrix[$i][0]->namebase;
($value & $this->select->list->choicelist[$i]['id'])
==
$this->select->list->choicelist[$i]['id'];
#echo $this->select->list->choicelist[$i]['id'] . " " . $this->select->boxMatrix[$i][0]->value;
* embed the html within a div to enable some creative js folding
* @return string html snippet that will open a new window with the html report
<div class='collapsecontrol' id='show$id' style='display: none;'><a href='javascript:$func(true)'>"
.
T_('expand').
"</a></div>
<div class='collapsecontrol' id='hide$id' style='display: none;'><a href='javascript:$func(false)'>"
.
T_('collapse').
"</a></div>
<div id='table$id'>$contents</div>
<script type='text/javascript'>
var id1 = document.getElementById('show$id');
id1.style.display = 'none';
var id2 = document.getElementById('hide$id');
id2.style.display = 'block';
var id3 = document.getElementById('table$id');
id3.style.display = 'inline';
var id1 = document.getElementById('show$id');
id1.style.display = 'block';
var id2 = document.getElementById('hide$id');
id2.style.display = 'none';
var id3 = document.getElementById('table$id');
id3.style.display = 'none';
// $this->select->includeSelectAll = $this->includeSelectAll;
$t =
#'<html><head></head><body>'
.
"</table>";#</body></html>\n";
return "<
tr><
td>{
$this->longname}</
td><
td>
$enc</
td></
tr>\n
";
* PHP5 clone statement will perform only a shallow copy of the object. Any subobjects must also be cloned
//echo "<hr /><br />Cloning bitmask<br />";
// Force a copy of contents of $this->list
if (is_object($this->select)) $this->select =
clone($this->select);
Documentation generated on Tue, 06 Mar 2007 10:00:44 +0000 by phpDocumentor 1.3.0