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));
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']) {
$count ++;
foreach ($this->fields() as $name => $attr) {
-
- if (array_key_exists($name,$row)) {
- $value = $row[$name];
- } else {
- $value = $attr['default'];
- }
-
- echo '<label for="'.$name.'">'.htmlspecialchars($name).'</label>'
- .'<input name="'.$name.'" id="'.$name.'" value="'.htmlspecialchars($value).'" />'
- .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 '<label for="'.$name.'">'.htmlspecialchars($name).'</label>'
+// NB 03.07.15 .'<input name="'.$name.'" id="'.$name.'" value="'.htmlspecialchars($value).'" />'
+// NB 03.07.15 .PHP_EOL;
}
}
.'<input type="submit" name="update"/>'
.'<input type="text" name="table" value="'.$this->db->p('table').'"/>'
.'<input type="reset" />'
- .($_SERVER['HTTP_REFERER'] ? '<input type="button" onclick="document.location=document.referrer" value="Cancel" />' : '')
+ .( empty($_SERVER['HTTP_REFERER']) ? '' : '<input type="button" onclick="document.location=document.referrer" value="Cancel" />')
.'</div>'.PHP_EOL
.'</form>'.PHP_EOL;
if ($next<$tot) echo ' <span class="prev"><a href="'.$this->url_params('limit',"$next,$y").'">>></a></span>';
echo '</div>'.PHP_EOL;
+ static $js = null;
+ if ($js === null) {
+ echo '<script type="text/javascript"><!-- '.PHP_EOL
+ ."var rb = document.getElementById('nav_bottom'); var rt = document.getElementById('nav_top'); if (rb && rt) rt.innerHTML = rb.innerHTML;\n"
+ . ' --></script>'.PHP_EOL
+ ;
+ $js = '1';
+ }
+
}
function form_criterias($opt=array()) {
echo join(''.PHP_EOL,$criteria);
echo '</form>'.PHP_EOL;
+
}
function where_criterias($values,$logic='AND') {
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 = '=';
}
+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 '<label for="'.$this->name.'">'.htmlspecialchars($this->name).'</label>'
+ .'<input name="'.$this->name.'" id="'.$this->name.'" value="'.htmlspecialchars($value).'" />'
+ .PHP_EOL;
+
+ }
+
+}
+
return;
?>