From c7835363a3ce1dc4fac5f86bf0fd10290ff280a2 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Fri, 22 Jun 2012 11:42:06 +0000 Subject: [PATCH] =?UTF-8?q?0000636:=20Objet=20pour=20=C3=A9viter=20le=20do?= =?UTF-8?q?uble=20encodage=20lors=20d'un=20recharchement=20de=20la=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/class_tool_uos.php | 101 +++++++++++++++++++++++++++++++++++++ sql/upgrade.sql | 6 ++- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 include/class_tool_uos.php diff --git a/include/class_tool_uos.php b/include/class_tool_uos.php new file mode 100644 index 000000000..2b4094a36 --- /dev/null +++ b/include/class_tool_uos.php @@ -0,0 +1,101 @@ +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; + } + } +} +?> diff --git a/sql/upgrade.sql b/sql/upgrade.sql index cd766088f..680e00b18 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -466,4 +466,8 @@ ALTER TABLE quant_sold 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 );