From 382ca9537ef67d1fc6950a3a50893e9f1fb9c2f9 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Mon, 12 Oct 2015 15:36:07 +0200 Subject: [PATCH] Change Tool_Uos by Single_Record --- include/lib/class_single_record.php.php | 107 ++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 include/lib/class_single_record.php.php diff --git a/include/lib/class_single_record.php.php b/include/lib/class_single_record.php.php new file mode 100644 index 000000000..4db8d806a --- /dev/null +++ b/include/lib/class_single_record.php.php @@ -0,0 +1,107 @@ +name, it is also the name + * of the tag hidden in a form + * @global $cn Db connxion + * @param $p_name + */ + function __construct($p_name) + { + $this->name=$p_name; + } + /** + * @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() + { + global $cn; + $this->id=$cn->get_next_seq('uos_pk_seq'); + return HtmlInput::hidden($this->name,$this->id); + } + /** + * @brief Try to insert into the table Single_Record + * @global $cn Database connx + * @throws Exception if the value $p_id is not unique + */ + function save($p_array=null) + { + global $cn; + if ( $p_array == null ) $p_array=$_POST; + $this->id=$p_array[$this->name]; + $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'); + } + } + /** + * 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($this->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($this->id)); + if ($count != 0 ) throw new Exception ('DUPLICATE',CODE_EXCP_DUPLICATE); + }catch (Exception $e) + { + throw $e; + } + } +} +?>