Change locale to fr_FR.UTF-8
[platal.git] / classes / pltableeditor.php
index cad848a..ed37784 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -43,6 +43,9 @@ class PLTableEditor {
        // null => delete effectively, false => no deletion, SQL
     var $delete_action;
     var $delete_message;
+    // Should "Save" button return to the list view
+    var $auto_return = true;
+
     /* table editor for platal
      * $plname : the PLname of the page, ex: admin/payments
      * $table : the table to edit, ex: profile_medals
@@ -74,7 +77,7 @@ class PLTableEditor {
                 $a['Type'] = 'textarea';
             elseif (substr($a['Type'],0,4) == 'set(') {
                 // get the list of options
-                $a['List'] = explode('§',str_replace("','","§",substr($a['Type'], 5, strlen($a['Type']) - 7)));
+                $a['List'] = explode('§',str_replace("','","§",substr($a['Type'], 5, strlen($a['Type']) - 7)));
                 if (count($a['List']) == 1) {
                     $a['Type'] = 'checkbox';
                     $a['Value'] = $a['List'][0];
@@ -84,7 +87,7 @@ class PLTableEditor {
             }
             elseif (substr($a['Type'],0,5) == 'enum(') {
                 // get the list of options
-                $a['List'] = explode('§',str_replace("','","§",substr($a['Type'], 6, strlen($a['Type']) - 8)));
+                $a['List'] = explode('§',str_replace("','","§",substr($a['Type'], 6, strlen($a['Type']) - 8)));
                 $a['Type'] = 'enum';
             }
             elseif (substr($a['Type'],0,10) == 'timestamp(' || $a['Type'] == 'datetime') {
@@ -126,6 +129,11 @@ class PLTableEditor {
         }
         return $entry;
     }
+    // set whether the save button show redirect to list view or edit view
+    function list_on_edit($var)
+    {
+        $this->auto_return = $var;
+    }
     // change display of a field
     function describe($name, $desc, $display) {
         $this->vars[$name]['desc'] = $desc;
@@ -153,23 +161,23 @@ class PLTableEditor {
     }
     // call when done
     function apply(&$page, $action, $id = false) {
-        $page->changeTpl('table-editor.tpl');
+        $page->changeTpl('core/table-editor.tpl');
         $list = true;
         if ($action == 'delete') {
                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->trig("L'entrée ".$id." a été supprimée.");
+                   $page->trig("L'entrée ".$id." a été supprimée.");
                } else if ($this->delete_action) {
                        XDB::execute($this->delete_action, $id);
                        if (isset($this->delete_message)) {
                        $page->trig($this->delete_message);
                        } else {
-                       $page->trig("L'entrée ".$id." a été supprimée.");
+                       $page->trig("L'entrée ".$id." a été supprimée.");
                                }                       
                } else {
-                   $page->trig("Impossible de supprimer l'entrée.");
+                   $page->trig("Impossible de supprimer l'entrée.");
                }
         }
         if ($action == 'edit') {
@@ -236,11 +244,16 @@ class PLTableEditor {
                     XDB::execute("UPDATE {$this->table} SET {$this->idfield} = {?} WHERE {$this->idfield} = {?}", 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.");
-                else
-                    $page->trig("Une nouvelle entrée a été créée.");
+                    $page->trig("L'entrée ".$id." a été mise à jour.");
+                else {
+                    $page->trig("Une nouvelle entrée a été créée.");
+                    $id = XDB::insertId();
+                }
             } else
-                $page->trig("Impossible de mette à jour.");
+                $page->trig("Impossible de mette à jour.");
+            if (!$this->auto_return) {
+                return $this->apply($page, 'edit', $id);
+            }
         }
         if ($action == 'sort') {
                $this->sortfield = $id;
@@ -271,4 +284,5 @@ class PLTableEditor {
     }
 }
 
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>