phpcompta-dev
[Top][All Lists]
Advanced

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

[Phpcompta-dev] r4974 - in phpcompta/trunk: include sql


From: phpcompta-dev
Subject: [Phpcompta-dev] r4974 - in phpcompta/trunk: include sql
Date: Fri, 22 Jun 2012 13:42:06 +0200 (CEST)

Author: danydb
Date: 2012-06-22 13:42:06 +0200 (Fri, 22 Jun 2012)
New Revision: 4974

Added:
   phpcompta/trunk/include/class_tool_uos.php
Modified:
   phpcompta/trunk/sql/upgrade.sql
Log:
0000636: Objet pour ?\195?\169viter le double encodage lors d'un recharchement 
de la page

Added: phpcompta/trunk/include/class_tool_uos.php
===================================================================
--- phpcompta/trunk/include/class_tool_uos.php                          (rev 0)
+++ phpcompta/trunk/include/class_tool_uos.php  2012-06-22 11:42:06 UTC (rev 
4974)
@@ -0,0 +1,101 @@
+<?php
+/*
+ *   This file is part of PhpCompta.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+/* $Revision: $Revision $ */
+/**
+ * @file
+ * Objec to check a double insert into the database, this duplicate occurs 
after 
+ * a refresh of the web page
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+require_once 'class_database.php';
+define ('CODE_EXCP_DUPLICATE',901);
+class Tool_Uos
+{
+    /**
+     * Constructor $p_name will be set to $this->name, it is also the name
+     * of the tag hidden in a form
+     * @global $cn Db connxion
+     * @param $p_name 
+     */
+    function __construct($p_name)
+    {
+          global $cn;
+        $this->name=$p_name;
+        $this->id=$cn->get_next_seq('uos_pk_seq');
+    }
+    /**
+     * @brief return a string with a tag hidden and a uniq value 
+     * @param $hHidden is the name of the tag hidden
+     * @return string : tag hidden
+     */
+    function hidden($hHidden)
+    {
+        return HtmlInput::hidden($hHidden,$this->id);
+    }
+    /**
+     * @brief Try to insert into the table tool_uos
+     * @global $cn Database connx
+     * @param $p_id integer is the value of hidden
+     * @throws Exception if the value $p_id is not unique
+     */
+    function save($p_id)
+    {
+        global $cn;
+        $sql="insert into tool_uos(uos_value) values ($1)";
+        try {
+            $cn->exec_sql($sql,array($this->id));   
+        } catch (Exception $e)
+        {
+            throw new Exception('Duplicate value','CODE_EXCP_DUPLICATE',$e);
+        }
+    }
+    /**
+     * Count how many time we have this->id into the table tool_uos
+     * @global $cn Database connx
+     * @param $p_array is the array where to find the key name, usually it is
+     * $_POST. The default value is $_POST
+     * @return integer : 0 or 1
+     */
+    function get_count($p_array=null)
+    {
+        global $cn;
+        if ( $p_array == null ) $p_array=$_POST;
+        $this->id=$p_array[$this->name];
+        $count=$cn->get_value('select count(*) from tool_uos where 
uos_value=$1',
+                array($p_id));
+        return $count;
+    }
+    function check ($p_array=null)
+    {
+        global $cn;
+        if ( $p_array == null ) $p_array=$_POST;
+        $this->id=$p_array[$this->name];
+        try 
+        {
+            $count=$cn->get_value('select count(*) from tool_uos where 
uos_value=$1',
+                    array($p_id));
+            if ($count != 0 ) throw new Exception 
('DUPLICATE',CODE_EXCP_DUPLICATE);
+        }catch (Exception $e)
+        {
+            throw $e;
+        }
+    }
+}
+?>

Modified: phpcompta/trunk/sql/upgrade.sql
===================================================================
--- phpcompta/trunk/sql/upgrade.sql     2012-06-21 18:42:07 UTC (rev 4973)
+++ phpcompta/trunk/sql/upgrade.sql     2012-06-22 11:42:06 UTC (rev 4974)
@@ -466,4 +466,8 @@
 CREATE INDEX quant_sold_jrn_fki
   ON quant_sold
   USING btree
-  (qs_internal );
\ No newline at end of file
+  (qs_internal );
+
+
+create sequence uos_pk_seq;
+create table tool_uos (  uos_value bigint default nextval ('uos_pk_seq') 
primary key );



---
PhpCompta est un logiciel de comptabilité libre en ligne (full web)
Projet opensource http://www.phpcompta.eu



reply via email to

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