noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 02/02: Task #1047 - Protection de la catégor


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 02/02: Task #1047 - Protection de la catégorie de fiches '
Date: Tue, 11 Nov 2014 19:26:57 +0000

sparkyx pushed a commit to branch master
in repository noalyss.

commit b777353054c39c6d3393a03b80e4c4465871b29f
Author: Dany De Bontridder <address@hidden>
Date:   Tue Nov 11 20:25:58 2014 +0100

    Task #1047 - Protection de la catégorie de fiches
    '
---
 include/cfgfiche.inc.php    |   25 ++++++++++++++++---------
 include/class_fiche_def.php |    3 +++
 sql/upgrade.sql             |   19 +++++++++++++++++++
 3 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/include/cfgfiche.inc.php b/include/cfgfiche.inc.php
index 16392e4..2f641fc 100644
--- a/include/cfgfiche.inc.php
+++ b/include/cfgfiche.inc.php
@@ -62,21 +62,28 @@ if ( isset ($_POST['remove_line']))
 
/*******************************************************************************************/
 if ( isset ($_POST['remove_cat']))
 {
-       $fd_id=new Fiche_Def($cn,$_POST['fd_id']);
-    $remains=$fd_id->remove();
-    if ( $remains != 0 )
-        /* some card are not removed because it is used */
-        alert(_('Impossible d\'enlever cette catégorie, certaines fiches sont 
encore utilisées'."\n".
-              'Les fiches non utilisées ont cependant été effacées'));
+    $post_id=HtmlInput::default_value_post('fd_id', 0);
+    if ($post_id == 0 || $post_id >= 500000)
+    {
+        alert(_('Impossible d\'enlever cette catégorie'));
+    } else {
+        $fd_id=new Fiche_Def($cn,$post_id);
+        $remains=$fd_id->remove();
+        if ( $remains != 0 ) {
+            /* some card are not removed because it is used */
+            alert(_('Impossible d\'enlever cette catégorie, certaines fiches 
sont encore utilisées'."\n".
+                  'Les fiches non utilisées ont cependant été effacées'));
+        }
+    }
 }
 
/*******************************************************************************************/
 // Change some basis info
 
/*******************************************************************************************/
 if ( isset ($_POST['change_name']))
 {
-        if (isset ($_REQUEST['label']) )
+    if (isset ($_REQUEST['label']) )
     {
-                $fiche_def=new Fiche_Def($cn,$_REQUEST['fd_id']);
+       $fiche_def=new Fiche_Def($cn,$_REQUEST['fd_id']);
         $fiche_def->SaveLabel($_REQUEST['label']);
         if ( isset($_REQUEST['create']))
         {
@@ -87,7 +94,7 @@ if ( isset ($_POST['change_name']))
             $fiche_def->set_autocreate(false);
         }
         $fiche_def->save_class_base($_REQUEST['class_base']);
-               $fiche_def->save_description($_REQUEST['fd_description']);
+       $fiche_def->save_description($_REQUEST['fd_description']);
 
     }
        echo $fiche_def->input_detail();
diff --git a/include/class_fiche_def.php b/include/class_fiche_def.php
index ab634e2..27d96d9 100644
--- a/include/class_fiche_def.php
+++ b/include/class_fiche_def.php
@@ -683,6 +683,9 @@ $order
      */
     function remove()
     {
+        if ( $this->id >= 500000 ) {
+            throw new Exception(_('Catégorie verrouillée '));
+        }
         $remain=0;
         /* get all the card */
         $aFiche=fiche::get_fiche_def($this->cn,$this->id);
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index fad1c60..7421d80 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -161,3 +161,22 @@ ALTER TABLE action_gestion ADD CONSTRAINT fiche_f_id_fk3  
FOREIGN KEY (f_id_dest
 alter table action_gestion alter f_id_dest drop not null;
 update action_gestion set f_id_dest = null where f_id_dest = 0;
 
+CREATE OR REPLACE FUNCTION comptaproc.category_card_before_delete()
+  RETURNS trigger AS
+$BODY$
+
+begin
+    if OLD.fd_id > 499000 then
+        return null;
+    end if;
+    return OLD;
+
+end;
+$BODY$
+language plpgsql;
+
+CREATE TRIGGER trg_category_card_before_delete
+  BEFORE delete
+  ON fiche_def
+  FOR EACH ROW
+  EXECUTE PROCEDURE comptaproc.category_card_before_delete();
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]