X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fpltableeditor.php;h=35113a38f5fcc4c7792acdc75c44ba467468b737;hb=80c3b5792bea15876ef8f79b8a64421733c1c001;hp=14cad9d53d63c17e47d606efcceacd2cce6a2ef5;hpb=4c603b95edc398a28dd8ea01d756ca14f01f95e5;p=platal.git diff --git a/classes/pltableeditor.php b/classes/pltableeditor.php index 14cad9d..35113a3 100644 --- a/classes/pltableeditor.php +++ b/classes/pltableeditor.php @@ -70,11 +70,12 @@ 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) */ - public function __construct($plname, $table, $idfield, $editid=false) + public function __construct($plname, $table, $idfield, $editid = false, $idfield2 = false) { $this->pl = $plname; $this->table = $table; $this->idfield = $idfield; + $this->idfield2 = $idfield2; $this->sortfield = $idfield; $this->idfield_editable = $editid; $this->whereclause = '1'; @@ -229,7 +230,7 @@ class PLTableEditor } // call when done - public function apply(PlPage &$page, $action, $id = false) + public function apply(PlPage &$page, $action, $id = false, $id2 = false) { $page->coreTpl('table-editor.tpl'); $list = true; @@ -239,8 +240,12 @@ class PLTableEditor if (!isset($this->delete_action)) { foreach ($this->jtables as $table => $j) XDB::execute("DELETE FROM {$table} WHERE {$j['joinid']} = {?}{$j['joinextra']}", $id); - XDB::execute("DELETE FROM {$this->table} WHERE {$this->idfield} = {?}",$id); - $page->trigSuccess("L'entrée ".$id." a été supprimée."); + $where = XDB::format("{$this->idfield} = {?}", $id); + if ($this->idfield2) { + $where .= XDB::format(" AND {$this->idfield2} = {?}", $id2); + } + XDB::rawExecute("DELETE FROM {$this->table} WHERE " . $where); + $page->trigSuccess("L'entrée " . $id . (($id2) ? '-' . $id2 : '') . ' a été supprimée.'); } else if ($this->delete_action) { XDB::execute($this->delete_action, $id); if (isset($this->delete_message)) { @@ -325,15 +330,15 @@ class PLTableEditor $update[] = $field . ' = ' . $value; } $update = implode(', ', $update); - XDB::execute("UPDATE {$this->table} - SET {$update} - WHERE {$this->idfield} = " . XDB::escape($id) . " - AND {$this->whereclause}"); + XDB::rawExecute("UPDATE {$this->table} + SET {$update} + WHERE {$this->idfield} = " . XDB::escape($id) . " + AND {$this->whereclause}"); } else { $fields = implode(', ', array_keys($values)); $values = implode(', ', $values); - XDB::execute("INSERT INTO {$this->table} ({$fields}) - VALUES ({$values})"); + XDB::rawExecute("INSERT INTO {$this->table} ({$fields}) + VALUES ({$values})"); } if ($id !== false && $id !== null) { $page->trigSuccess("L'entrée ".$id." a été mise à jour.");