Allows deletion based on 2 fields in plTableEditor.
authorStéphane Jacob <sj@m4x.org>
Tue, 28 Dec 2010 14:46:00 +0000 (15:46 +0100)
committerStéphane Jacob <sj@m4x.org>
Tue, 28 Dec 2010 14:59:04 +0000 (15:59 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/pltableeditor.php
templates/table-editor.tpl

index 88a4133..35113a3 100644 (file)
@@ -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)) {
index 85e28f9..ad792bf 100644 (file)
@@ -60,6 +60,9 @@
     {if $myfield eq $t->idfield}
         {assign var="idval" value=$myrow.$myfield}
     {/if}
+    {if $t->idfield2 && $myfield eq $t->idfield2}
+        {assign var="idval2" value=$myrow.$myfield}
+    {/if}
     {if $myval.Type eq 'timestamp'}
       <span class="smaller">{$myrow.$myfield|date_format:"%x %X"}</span>
     {elseif $myval.Type eq 'checkbox'}
@@ -77,7 +80,7 @@
     <a href="{$t->pl}/edit/{$idval}">{icon name=page_edit title='éditer'}</a>
     {/if}
     {if !$readonly}
-    <a href="{$t->pl}/delete/{$idval}?token={xsrf_token}">{icon name=delete title='supprimer'}</a>
+    <a href="{$t->pl}/delete/{$idval}{if t($idval2)}/{$idval2}{/if}?token={xsrf_token}">{icon name=delete title='supprimer'}</a>
     {/if}
   </td>
   {/if}