From 0886412a7735ae0fca7b1889a6aa8a0806bc38b7 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Fri, 3 Jul 2015 16:47:03 +0100 Subject: [PATCH] class field --- lib/php/db.php | 88 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 25 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 5f4410f9..556b4867 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -11,17 +11,17 @@ if (!defined('DB_HTML_EDIT')) define('DB_HTML_EDIT','Edit'); class db { - var $tables = array(); - var $conn; - var $type; - var $help_criterias = array( + public $tables = array(); + public $conn; + public $type; + public $help_criterias = array( ' * or % for wildcar', ' ! to negate', ' ~ for regex', ' combine criterias with OR/AND', ); - function db($pdo) { + function __construct($pdo) { $this->conn = new PDO($pdo); $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$pdo)); @@ -242,19 +242,19 @@ EOF; class table { - var $name; - var $db; - var $sql; - var $fields = array(); - var $fields_keys = array(); - var $extras = array(); - var $params = array( + public $name; + public $db; + public $sql; + public $fields = array(); + public $fields_keys = array(); + public $extras = array(); + public $params = array( 'table', 'limit', 'debug', ); - function table($name,$opt=array()) { + function __construct($name,$opt=array()) { // Connection if (@$opt['db']) { @@ -452,16 +452,15 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $count ++; foreach ($this->fields() as $name => $attr) { - - if (array_key_exists($name,$row)) { - $value = $row[$name]; - } else { - $value = $attr['default']; - } - - echo '' - .'' - .PHP_EOL; + $field = new field($name,$attr); + $field->html_edit(array_key_exists($name,$row) ? $row[$name] : $attr['default']); +// NB 03.07.15 continue; +// NB 03.07.15 +// NB 03.07.15 $value = array_key_exists($name,$row) ? $row[$name] : $attr['default']; +// NB 03.07.15 +// NB 03.07.15 echo '' +// NB 03.07.15 .'' +// NB 03.07.15 .PHP_EOL; } } @@ -470,7 +469,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. .'' .'' .'' - .($_SERVER['HTTP_REFERER'] ? '' : '') + .( empty($_SERVER['HTTP_REFERER']) ? '' : '') .''.PHP_EOL .''.PHP_EOL; @@ -560,6 +559,15 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. if ($next<$tot) echo ' >>'; echo ''.PHP_EOL; + static $js = null; + if ($js === null) { + echo ''.PHP_EOL + ; + $js = '1'; + } + } function form_criterias($opt=array()) { @@ -608,6 +616,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. echo join(''.PHP_EOL,$criteria); echo ''.PHP_EOL; + } function where_criterias($values,$logic='AND') { @@ -615,10 +624,13 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. foreach ($this->fields() as $k => $spec) { + $field = new field($k,$spec); + // No empty values $v = @$values[$k]; if (strcmp($v,'')==0 or $v=='!' or $v=='~') continue; - $number = preg_match('/int|float|number|currency/',$spec['type']) ? 1 : 0; +// NB 03.07.15 $number = preg_match('/int|float|number|currency/',$spec['type']) ? 1 : 0; + $number = $field->is_num(); // Equal / Not Equal $equal = '='; @@ -968,5 +980,31 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } +class field { + + public $name; + public $extras = array(); + public $type = 'text'; + public $default = null; + public $key = false; + + function __construct($name,$attr=array()) { + foreach ($attr as $k => $v) { $this->$k = $v; } + } + + function is_num() { + return preg_match('/int|float|number|currency/',$this->type) ? 1 : 0; + } + + function html_edit($value) { + + echo '' + .'' + .PHP_EOL; + + } + +} + return; ?> -- 2.47.3