From 7828a0e39796e7cc45e3e63b67347da4d96db0c2 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 14 Jul 2015 11:11:13 +0100 Subject: [PATCH] update, add, delete --- lib/css/db.css | 20 -------------------- lib/js/tools.js | 12 +++++++++++- lib/php/db.php | 12 ++++++++---- lib/php/db/table.php | 37 ++++++++++++++++++++++--------------- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/lib/css/db.css b/lib/css/db.css index c0c421d5..c30e33cf 100644 --- a/lib/css/db.css +++ b/lib/css/db.css @@ -94,23 +94,3 @@ td.email, td.phone { white-space: nowrap; } - -.button { - display: inline-block; - text-decoration: none; - font-size: 13px; - line-height: 26px; - height: 28px; - margin: 0; - padding: 0 10px 1px; - cursor: pointer; - border-width: 1px; - border-style: solid; - -webkit-appearance: none; - -webkit-border-radius: 3px; - border-radius: 3px; - white-space: nowrap; - -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; - box-sizing: border-box; -} diff --git a/lib/js/tools.js b/lib/js/tools.js index 3a277bc8..b63eb722 100644 --- a/lib/js/tools.js +++ b/lib/js/tools.js @@ -3,7 +3,17 @@ * * Date: 28.03.15 */ -function Tools() { +function NB() { + + this.form_clear = function(form) { + var e; + for(i=0;i'); +if (!defined('DB_HTML_FORM_BUTTONS')) define('DB_HTML_FORM_BUTTONS','' + .'' + .'X' + .'' +); +if (!defined('DB_HTML_BUTTON_ADD')) define('DB_HTML_BUTTON_ADD',''); if (!defined('DB_HTML_BUTTON_SUBMIT')) define('DB_HTML_BUTTON_SUBMIT',''); class db { @@ -190,7 +195,7 @@ EOF; function html_menu($table=null) { $html = ' onchange="this.parentElement.submit()"'; - $r = ''.PHP_EOL; return $r; } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 8e4cec99..2087edb5 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1,6 +1,7 @@ '.PHP_EOL); class table { @@ -118,17 +119,17 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. return $this->fields; } - function url_edit($values=null,$sep='&') { + function url_keys($values=null,$params=array(),$sep='&') { if ($values === null) $values = $this->db->p(); - $url_edit = array(); + $url = is_array($params) ? $params : array($params); foreach ($this->fields_keys() as $name => $spec) { - $url_edit[] = $name . '=' .urlencode($values[$name]); + if (isset($values[$name]) and strcmp($values[$name],'')!=0) + $url[] = $name . '=' .urlencode($values[$name]) + ; } - $url_edit[] = 'edit=1'; - return $url_edit ? '?table='.$this->db->p('table').$sep.join($sep,$url_edit) : ''; - + return $url ? '?table='.$this->db->p('table').$sep.join($sep,$url) : ''; } function fields_keys(&$others=array()) { @@ -185,7 +186,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. echo '' .'
' .'' - .'' + .'' .'' .( empty($_SERVER['HTTP_REFERER']) ? '' : '') .'
'.PHP_EOL @@ -340,8 +341,9 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } - function where_criterias($values,$logic='AND') { + function where_criterias($values,$logic='') { $having = $where = array(); + if (empty($logic)) $logic = 'AND'; foreach ($this->fields() as $k => $spec) { @@ -411,8 +413,8 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } $sql = ''; - if ($where) $sql .= ' WHERE '.join(' '. $logic.' ',$where); - if ($having) $sql .= ' HAVING '.join(' '. $logic.' ',$having); + if ($where) $sql .= ' WHERE '.join(" $logic ",$where); + if ($having) $sql .= ' HAVING '.join(" $logic ",$having); return $sql; } @@ -533,7 +535,11 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } - if ($opt['is_html']) array_unshift($row,''.DB_HTML_EDIT.''); + if ($opt['is_html']) { + array_unshift($row,''.DB_HTML_EDIT.''); + array_push($row,''.DB_HTML_DELETE.''); + } + echo $this->{"rows_rec_$format"}($row); } @@ -645,17 +651,18 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $colspan = 0; if (DB_HTML_EDIT) $colspan++; + if (DB_HTML_DELETE) $colspan++; if (DB_HTML_NAV_TOP) $html .= '' . '' . DB_HTML_NAV_TOP . '' . ''.PHP_EOL ; $html .= ''; - $html .= ''; + if (DB_HTML_EDIT) $html .= ''; foreach (array_keys($this->fields()) as $f) { $html .= ''.$this->url_sort($f).''; } - + if (DB_HTML_DELETE) $html .= ''; $html .= ''.PHP_EOL.''.PHP_EOL; return $html; @@ -757,11 +764,11 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } function delete($hvalues) { - $where = str_replace(' LIKE ','=',$this->where_criterias($values)); + $where = str_replace(' LIKE ','=',$this->where_criterias($hvalues)); if (!$where) return 0; $sql = 'DELETE FROM ' . $this->sql_name() . $where; debug($sql); - $execute = $this->db->conn($sql); + $execute = $this->db->query($sql); if (!$execute) return err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .PHP_EOL); return $execute; } -- 2.47.3