#db {
}
-#db .rows {
+/*
+ List
+*/
+.rows {
margin: 0 auto;
}
}
.rows ul .edit { float: right; }
+.rows tr.nav td { border: none; }
+
+td.name,
+td.email,
+td.phone {
+ white-space: nowrap;
+}
/*
Menu
margin: 0 auto;
padding: 0.8em 0.8em 0.8em 0.5em;
padding: 0.5em 0.8em;
+ /*
display: table;
+ */
+}
+
+.db.menu hr {
+ clear: both;
+ margin: 0;
+ padding: 0.5px 0;
+ border: none;
+ background-color: #f4f4f4;
+}
+
+.db.menu .button,
+.db.menu input,
+.db.menu select,
+.db.menu label
+{
+ margin: 0.3em 0.3em 0.3em 0;
}
-.db.menu label {
- margin: 0.1em 0.1em 0 0.5em;
+.db.menu span.i,
+.db.menu span.i label {
+ float: left;
+}
+.db.menu span.i label {
+ display: inline-block;
+ width: 4em;
+ text-align: right;
}
.db.menu label:after {
max-width: 7em;
}
+li.tables {
+ float: left;
+}
+
+li.tables ul {
+ text-transform: capitalize;
+}
+
+li.tables li {
+ font-size: 0.8em;
+}
+
/*
Edit
*/
}
form.db.edit .buttons input {
+border: solid 1px red;
width: auto;
float: none;
}
-
-li.tables {
- float: left;
-}
-
-li.tables ul {
- text-transform: capitalize;
-}
-
-li.tables li {
- font-size: 0.8em;
-}
-
-td.name,
-td.email,
-td.phone {
- white-space: nowrap;
-}
require_once(dirname(__FILE__).'/db/table.php');
require_once(dirname(__FILE__).'/db/field.php');
if (!defined('DB_HTML_FORM_BUTTONS')) define('DB_HTML_FORM_BUTTONS',''
- .'<input type="submit" class="button" name="edit" value="Add"/>'
- .'<a class="button" href="#" onclick="return nb.form_clear(this.parentElement)">X</a>'
+ .'<input type="button" class="button" value="Add" onclick="this.setAttribute(\'type\',\'submit\');this.setAttribute(\'name\',\'edit\')?1:1"/>'
+ #.'<input type="button" class="button" value="Add" onclick="this.setAttribute(\'name\',\'edit\');this.parentElement.submit()?0:0"/>'
+ #.'<input type="button" class="button" onclick="return nb.form_clear(this.parentElement)" value="X"/>'
+ .'<a class="button" href="#" onclick="nb.form_clear(this.parentElement)?0:0">X</a>'
.'<input type="submit" class="button" value="GO"/>'
);
-if (!defined('DB_HTML_BUTTON_ADD')) define('DB_HTML_BUTTON_ADD','<input type="submit" class="button" name="edit" value="Add"/>');
-if (!defined('DB_HTML_BUTTON_SUBMIT')) define('DB_HTML_BUTTON_SUBMIT','<input type="submit" class="button" value="GO"/>');
+#if (!defined('DB_HTML_BUTTON_SUBMIT')) define('DB_HTML_BUTTON_SUBMIT','<input type="submit" class="button" value="GO"/>');
+#if (!defined('DB_HTML_BUTTON_ADD')) define('DB_HTML_BUTTON_ADD','<a class="button" href="?" onclick="nb.form_clear(this.parentElement) ? 0: 0">Add</a>');
+#if (!defined('DB_HTML_BUTTON_ADD')) define('DB_HTML_BUTTON_ADD','<input type="submit" class="button" value="Add" onclick="this.setAttribute(\'name\',\'edit\')?0:0"/>');
class db {
return $this->conn->exec($sql);
}
- function query($sql,$o='') {
- return $this->conn->query($sql);
+ function query($sql) {
+ # See: http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers
+
+ try {
+ $r = $this->conn->query($sql);
+ } catch (PDOException $e) {
+ err(array("Db.query()",$e->getMessage(),$sql));
+ $r = null;
+ }
+
+ return $r;
+
}
- function query2v($sql) {
- $r = $this->conn->query($sql,PDO::FETCH_COLUMN,0);
- return $r ? $r->fetch() : $r;
+ function row($sql,$sep=' ') {
+ #$sql = "SELECT * FROM addr LIMIT 1";
+ $query = $this->query($sql);
+ $result = $query->fetch(PDO::FETCH_NUM);
+ if (!is_array($result)) return $result;
+ return join($sep,$result);
+ return join($sep,$query->fetch(PDO::FETCH_NUM));
}
function query2a($sql) {
$html = ' onchange="this.parentElement.submit()"';
$r = '<form class="db menu" method="get" action="">'.PHP_EOL;
- if (!empty($table)) foreach ( array_keys($table->fields()) as $k ) {
+ if (!empty($table)) {
+ foreach ( array_keys($table->fields()) as $k ) {
- $v = $this->p($k);
+ $v = $this->p($k);
- $r .= ''
- . '<label>'.prettyText($k).'</label>'
- . '<input type="text" id="'.$k.'" name="'.$k.'" value="'.$v.'" />'
- ;
+ $r .= ''
+ .'<span class="i">'
+ . '<label>'.prettyText($k)
+ .'</label>'
+ . '<input type="text" id="'.$k.'" name="'.$k.'" value="'.$v.'" />'
+ .'</span>'
+ ;
+ }
+ #$r .= '<span class=""></span>';
+ $r .= '<hr/>';
}
/// Tables
function html_edit($value) {
- echo '<label for="'.$this->name.'">'.htmlspecialchars($this->name).'</label>'
+ return '<label for="'.$this->name.'">'.htmlspecialchars($this->name).'</label>'
.'<input name="'.$this->name.'" id="'.$this->name.'" value="'.htmlspecialchars($value).'" />'
.PHP_EOL;
'debug',
);
+ function __destruct() {
+ foreach (get_object_vars($this) as $k=>$v) { unset($this->$k); };
+ }
+
function __construct($name,$opt=array()) {
// Connection
} else {
err('table.sql(): Unknow db type: '.$this->db->type);
}
- $this->sql = $this->db->query($sql);
+ $this->sql = $this->db->row($sql);
+ #bye($this->sql);
return $this->sql;
}
foreach ($this->fields() as $name => $attr) {
$field = new field($name,$attr);
- $field->html_edit( (is_array($row) and array_key_exists($name,$row) ) ? $row[$name] : $attr['default']);
+ echo $field->html_edit( (is_array($row) and array_key_exists($name,$row) ) ? $row[$name] : $attr['default']);
+ unset($field);
}
}
}
function form_criterias($opt=array()) {
+ // Legacy from sem - NB 25.07.15
echo '<form class="criteria" method="get" action="">'.PHP_EOL;
echo '<div class="small help">Use: '.join(' | ',$this->db->help_criterias).'</div>'.PHP_EOL;
foreach ($this->fields() as $k => $spec) {
- $field = new field($k,$spec);
-
// No empty values
$v = isset($values[$k]) ? $values[$k] : null;
if (strcmp($v,'')==0 or $v=='!' or $v=='~') continue;
// NB 03.07.15 $number = preg_match('/int|float|number|currency/',$spec['type']) ? 1 : 0;
+ $field = new field($k,$spec);
$number = $field->is_num();
// Equal / Not Equal
$where[] = "$k$equal$v";
}
- }
+ unset($field);
+ } #foreach fields
$sql = '';
if ($where) $sql .= ' WHERE '.join(" $logic ",$where);
$colspan = 0;
if (DB_HTML_EDIT) $colspan++;
if (DB_HTML_DELETE) $colspan++;
- if (DB_HTML_NAV_TOP) $html .= '<thead><tr>'
- . '<td colspan="'.(count($this->fields())+$colspan).'">' . DB_HTML_NAV_TOP . '</td>'
- . '</tr></thead>'.PHP_EOL
+ if (DB_HTML_NAV_TOP) $html .= ''#'<thead>'.PHP_EOL
+ .'<tr class="nav top">'
+ . '<td colspan="'.(count($this->fields())+$colspan).'">' . DB_HTML_NAV_TOP . '</td>'
+ . '</tr>'#.'</thead>'.PHP_EOL
+ ;
+
+ $html .= ''#'<tbody>'.PHP_EOL
+ .'<tr class="'.$this->name.' row">'
;
- $html .= '<tr class="'.$this->name.' row bold">';
if (DB_HTML_EDIT) $html .= '<th class="'.DB_HTML_EDIT.'"></th>';
+
foreach (array_keys($this->fields()) as $f) {
$html .= '<th class="'.$f.'">'.$this->url_sort($f).'</th>';
}
if (DB_HTML_DELETE) $html .= '<th class="'.DB_HTML_DELETE.'"></th>';
- $html .= '</tr>'.PHP_EOL.'<tbody>'.PHP_EOL;
+ $html .= '</tr>'.PHP_EOL;#.'<tbody>'.PHP_EOL;
return $html;
}
}
function rows_end_table($opt=array()) {
- $html = PHP_EOL.'</tbody>'.PHP_EOL;
-
- if (!empty($opt['count'])) $html .= '<tfoot><tr>'
- . '<td colspan="'.(count($this->fields())+1).'">'
- . $this->nav($opt['count'],$opt['tot'],$opt['limit'])
+ #$html = '</tbody>'.PHP_EOL;
+
+ if (!empty($opt['count'])) $html .= ''#'<tfoot>'.PHP_EOL
+ .'<tr class="nav bottom">'
+ . '<td colspan="'.(
+ count($this->fields())
+ +(DB_HTML_EDIT ? 1 :0)
+ +(DB_HTML_DELETE ? 1 :0)
+ ).'">'
+ . $this->nav($opt['count'],$opt['tot'],$opt['limit'])
. '</td>'
- . '</tr></tfoot>'.PHP_EOL
- ;
+ . '</tr>'.PHP_EOL
+ ;#.'</tfoot>'.PHP_EOL;
$html .= '</table>'.PHP_EOL;
return $html;