* @copyright: Copyright (c) 2009-2012, Bunzia Alexander
* @version: 1.0
* @license: http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/
class controlForm
{
var $items = array();
var $rows = array();
function __construct($items){
foreach( $items as $k => $v ){
$this -> items[$k]=$v;
}
}
/* function __set(){
}
function __get(){
}*/
function add($v){
$this -> rows[] =$v;
return $this;
}
function html(){
$res = '';
foreach( $this -> items as $k=>$v ){
$res.=" $k='".$v."' ";
}
$res = "";
return $res;
}
}
/**
* Класс для чекбокса
*
*/
class controlChecked {
static function html($array){
$res = '';
foreach( $array as $k=>$v ){
if ( method_exists(__CLASS__,'set_'.$k) ){
$f = 'set_'.$k;
$v = self::$f($v);
}
$res.=" $k='".$v."' ";
}
return "";
}
static function sql($v){
//self::check($v);
return ($v == 'checked') ? 1 : 0 ;
}
static function set_checked($v){
return !empty($v) ? 'checked' : false;
}
}
class controlText{
static $comment;
static $desc;
static function html($array){
$res = self::$comment=self::$desc='';
foreach( $array as $k=>$v ){
if ( method_exists(__CLASS__,'set_'.$k) ){
$f = 'set_'.$k;
$v = self::$f($v);
if ( false===$v ){
continue;
}
}
$res.=" $k='".$v."' ";
}
return "".self::$desc." | |
";
}
static function sql($v,$row=array() ){
self::check_length($v,false,50);
//self::check_content($v,10,50);
return addslashes($v);
}
static function set_value($v){
return htmlspecialchars($v,ENT_QUOTES);
}
static function set_desc($v){
self::$desc = $v;
return false;
}
static function set_comment($v){
self::$comment = $v;
return false;
}
static function check_length($v, $min=false,$max=false){
if ( empty($v) ){
throw new Exception('Значение не определено');
}
$v = strlen($v);
if ( false!==$min && $v<$min ){
throw new Exception('Значение слишком короткое');
}
if ( false!==$min && $v>$max ){
throw new Exception('Значение слишком длинное');
}
return true;
}
static function check_content($v,$type = '*'){
if ( preg_match('#'.$type.'#is',$v) ){
throw new Exception('Запрещённые символы');
}
return true;
}
}
class controlHidden{
static function html($array){
foreach( $array as $k=>$v ){
if ( method_exists(__CLASS__,'set_'.$k) ){
$f = 'set_'.$k;
$v = self::$f($v);
if ( false===$v ){
continue;
}
}
$res.=" $k='".$v."' ";
}
return "";
}
static function sql($v){
return ($v);
}
static function set_value($v){
return sys_in_html($v);
}
}
class controlTextarea{
static $comment;
static $desc;
static $value;
static function html($array){
$res = self::$comment=self::$desc=self::$value='';
foreach( $array as $k=>$v ){
if ( method_exists(__CLASS__,'set_'.$k) ){
$f = 'set_'.$k;
$v = self::$f($v);
if ( false===$v ){
continue;
}
}
$res.=" $k='".$v."' ";
}
return "".self::$desc." | |
";
}
static function sql($v){
return ($v);
}
static function set_value($v){
self::$value = $v;
return false;
}
static function set_desc($v){
self::$desc = $v;
return false;
}
static function set_comment($v){
self::$comment = $v;
return false;
}
static function check_length($v, $min=false,$max=false){
if ( false===$v ){
throw new Exception('Значение не определено');
}
$v = strlen($v);
if ( false!==$min && $v<$min ){
throw new Exception('Значение слишком короткое');
}
if ( false!==$min && $v>$max ){
throw new Exception('Значение слишком длинное');
}
return true;
}
}
?>