X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fpltableeditor.php;h=7cfc2e835cb56b67ce9e1f36abfed441f5cae4e7;hb=e2cea47d18a6c2f1449e220c90103181229e939f;hp=be664fd4d5875a90f8ef4e7d758e6be67c5e33b5;hpb=787bb3d745141f2f85bd947ad7dd775d2c63f908;p=platal.git diff --git a/classes/pltableeditor.php b/classes/pltableeditor.php index be664fd..7cfc2e8 100644 --- a/classes/pltableeditor.php +++ b/classes/pltableeditor.php @@ -1,6 +1,6 @@ idfield = $idfield; $this->sortfield = $idfield; $this->idfield_editable = $editid; - $r = XDB::iterator("SHOW COLUMNS FROM $table"); + $this->whereclause = '1'; + $r = XDB::iterator("SHOW FULL COLUMNS FROM $table"); $this->vars = array(); while ($a = $r->next()) { // desc will be the title of the column @@ -94,6 +97,9 @@ class PLTableEditor elseif (substr($a['Type'],0,10) == 'timestamp(' || $a['Type'] == 'datetime') { $a['Type'] = 'timestamp'; } + elseif ($a['Comment'] == 'ip_address') { + $a['Type']='ip_address'; + } $this->vars[$a['Field']] = $a; } @@ -130,6 +136,10 @@ class PLTableEditor $date =& $entry[$field]; $date = preg_replace('/([0-9]{4})-?([0-9]{2})-?([0-9]{2})/', '\3/\2/\1', $date); } + if ($descr['Type'] == 'ip_address') { + $ip = & $entry[$field]; + $ip = long2ip($ip); + } } return $entry; } @@ -164,6 +174,12 @@ class PLTableEditor } } + // add a where clause to limit table listing + public function set_where_clause($whereclause="1") + { + $this->whereclause = $whereclause; + } + // set an action when trying to delete row public function on_delete($action = NULL, $message = NULL) { @@ -188,13 +204,13 @@ class PLTableEditor $page->trig($this->delete_message); } else { $page->trig("L'entrée ".$id." a été supprimée."); - } + } } else { $page->trig("Impossible de supprimer l'entrée."); } } if ($action == 'edit') { - $r = XDB::query("SELECT * FROM {$this->table} WHERE {$this->idfield} = {?}",$id); + $r = XDB::query("SELECT * FROM {$this->table} WHERE {$this->idfield} = {?} AND {$this->whereclause}",$id); $entry = $r->fetchOneAssoc(); $page->assign('entry', $this->prepare_edit($entry)); $page->assign('id', $id); @@ -245,6 +261,9 @@ class PLTableEditor elseif ($descr['Type'] == 'date') { $val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})/', '\3-\2-\1', $val); } + elseif ($descr['Type'] == 'ip_address') { + $val = ip2long($val); + } $val = "'".addslashes($val)."'"; } else { $cancel = true; @@ -254,7 +273,7 @@ class PLTableEditor } if (!$cancel) { if ($this->idfield_editable && ($id != Post::v($this->idfield)) && $action != 'new') - XDB::execute("UPDATE {$this->table} SET {$this->idfield} = {?} WHERE {$this->idfield} = {?}", Post::v($this->idfield), $id); + XDB::execute("UPDATE {$this->table} SET {$this->idfield} = {?} WHERE {$this->idfield} = {?} AND {$this->whereclause}", Post::v($this->idfield), $id); XDB::execute("REPLACE INTO {$this->table} VALUES ($values)"); if ($id !== false) $page->trig("L'entrée ".$id." a été mise à jour."); @@ -263,7 +282,7 @@ class PLTableEditor $id = XDB::insertId(); } } else - $page->trig("Impossible de mette à jour."); + $page->trig("Impossible de mettre à jour."); if (!$this->auto_return) { return $this->apply($page, 'edit', $id); } @@ -287,7 +306,7 @@ class PLTableEditor if (count($this->sort) > 0) { $sort = 'ORDER BY ' . join($this->sort, ','); } - $it = XDB::iterator("SELECT * FROM {$this->table} $sort"); + $it = XDB::iterator("SELECT * FROM {$this->table} WHERE {$this->whereclause} $sort"); $this->nbfields = 0; foreach ($this->vars as $field => $descr) if ($descr['display']) $this->nbfields++;