<?php
/*
*******************************************************************************
FiForms -- A collection of PHP classes designed
to facilitate rapid development of web-database software
Copyright (C) 2003-2007 Daniel McFeeters
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The original author of this library can be contacted at the following
address:
Daniel McFeeters
182 Baker Rd.
Faubush, KY 42544-6526
email:databases [at] fiforms [dot] org
http://www.fiforms.org/
iNumber class
*******************************************************************************
FiForms_iNumber.inc.php
iNumber Definition File
This file contains the definitions for the iNumber input class
*******************************************************************************
*/
require_once("FiForms_iInput.inc.php");
/* ?><code><?php */
$FIFORM_XML_INPUTS[] = 'f:iNumber';
class iNumber extends iInput
// The most generic type of iInput. Simply outputs an html input filled
// with data
{
public $size;
public $class;
public $prefix;
public $suffix;
public $digits;
public $decimals;
public $thseperator;
public $decpoint;
function iNumber()
{
$this->class = "number";
$this->size = 20;
$this->decimals = 0;
$this->digits = 63;
$this->thseperator = ",";
$this->decpoint = ".";
$this->prefix = "";
$this->suffix = "";
$this->value = '';
$this->iInput(func_get_args());
$this->ajaxLoad = true;
}
function getSettingsCode()
{
return <<<EOD
<script type="text/javascript">
fiformsiNumber[iNumberCount] = new iNumberSetting("$this->dbField",$this->digits,$this->decimals,"$this->thseperator","$this->decpoint");
iNumberCount++;
</script>
EOD;
}
function getValueToSave()
// Retreives a value from _POST with the key matching dbField. This
// can be overridden in child classes to do any processing necessary
// before the value is committed to the database.
{
if(!isset($this->dbField))
{
$this->valueToSave = FALSE;
return(TRUE);
}
if(array_key_exists($this->dbField,$_POST))
{
$num = $_POST[$this->dbField];
$num = str_replace($this->thseperator,"",$num);
$num = str_replace($this->decpoint,".",$num);
$this->valueToSave = $num;
$this->validateBeforeSave();
return(TRUE);
} // if key exists
else
{
$this->valueToSave = FALSE;
}
}
function formatOutput()
{
if($this->readOnly)
{
return(($this->value === '' ? '' :
"<div style=\"float:left;\">".$this->prefix.
"</div><div style=\"float:right;\">".
number_format($this->value,$this->decimals,$this->decpoint,
$this->thseperator).
$this->suffix."</div>"));
}
else
{
return("<span class=\"text\">$this->prefix<input type=\"text\"".
" name=\"$this->dbField\" id=\"$this->dbField\" value=\"".
($this->value === '' ? '' : number_format($this->value,$this->decimals,$this->decpoint,$this->thseperator))
."\" ".
"size=\"$this->size\" class=\"$this->class\" ".
" onkeypress=\"filterNumberKeys(event,'$this->dbField');\"".
" onblur=\"validateNumberField('$this->dbField');\" $this->otherTags />$this->suffix</span>".$this->getRefreshLink().$this->getSettingsCode());
}
} // function formatOutput
function disableIn()
{
$this->otherTags .= " readonly=\"readonly\" ";
$this->class = "disabled_text";
}
} // class iText
/* ?></code><?php */
?>