From: x2003bruneau Date: Thu, 30 Nov 2006 16:03:22 +0000 (+0000) Subject: Table editor fills the new entry form with the default values of the fields X-Git-Tag: xorg/0.9.13~248 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=1d10d3fd659fa8eb7c663d6bb599bc8bbc0feeb3;p=platal.git Table editor fills the new entry form with the default values of the fields git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1208 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/classes/pltableeditor.php b/classes/pltableeditor.php index 955ac30..c849f37 100644 --- a/classes/pltableeditor.php +++ b/classes/pltableeditor.php @@ -49,7 +49,8 @@ class PLTableEditor { * $idfield : the field of the table which is the id, ex: id * $editid : is the id editable or not (if not, it is considered as an int) */ - function PLTableEditor($plname, $table, $idfield, $editid=false) { + function PLTableEditor($plname, $table, $idfield, $editid=false) + { $this->pl = $plname; $this->table = $table; $this->idfield = $idfield; @@ -89,6 +90,15 @@ class PLTableEditor { } $this->vars[$idfield]['desc'] = 'id'; } + // called before creating a new entry + function prepare_new() + { + $entry = array(); + foreach ($this->vars as $field => $descr) { + $entry[$field] = $descr['Default']; + } + return $this->prepare_edit($entry); + } // called before editing $entry function prepare_edit(&$entry) { foreach ($this->vars as $field => $descr) { @@ -168,6 +178,7 @@ class PLTableEditor { if (!$this->idfield_editable) { $r = XDB::query("SELECT MAX({$this->idfield})+1 FROM {$this->table}"); $page->assign('id', $r->fetchOneCell()); + $page->assign('entry', $this->prepare_new()); } $list = false; }