noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
single_record.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19/**
20 * @file
21 * @brief Objec to check a double insert into the database, this duplicate occurs after
22 * a refresh of the web page
23 */
24// Copyright Author Dany De Bontridder danydb@aevalys.eu
25
26define ('CODE_EXCP_DUPLICATE',901);
27/**
28 * @brief Objec to check a double insert into the database, this duplicate occurs after
29 * a refresh of the web page
30 */
31
33{
34 public $name;
35 public $id;
36 private $dbconx; //!< database connexion
37 /**
38 * @brief Constructor $p_name will be set to $this->name, it is also the name
39 * of the tag hidden in a form
40 * @remark $cn Db connexion
41 * @param $p_name (string) name of the HIDDEN INPUT
42 * @param $dbconx Database connx , if not given; use global $cn;
43 */
44 function __construct($p_name,$dbconx=-1)
45 {
46 $this->name=$p_name;
47 $this->id=0;
48 if ( is_numeric($dbconx ) ) {
49 global $cn;
50 $this->dbconx=$cn;
51 }else {
52 $this->dbconx=$dbconx;
53 }
54
55 }
56 function __toString(): string {
57 return "Single_Record[name=" . $this->name
58 . ", id=" . $this->id
59 . ", dbconx=" . $this->dbconx
60 . "]";
61 }
62 /**
63 * @brief return a string with a tag hidden and a uniq value
64 * @param $hHidden is the name of the tag hidden
65 * @return string : tag hidden
66 */
67 function hidden()
68 {
69 $this->id=$this->dbconx->get_next_seq('uos_pk_seq');
70 return HtmlInput::hidden($this->name,$this->id);
71 }
72 /**
73 * @brief Try to insert into the table Single_Record
74 * @remark global $cn Database connexion
75 * @throws Exception if the value $p_id is not unique
76 */
77 function save($p_array=null)
78 {
79 if ( $p_array == null ) $p_array=$_POST;
80 $this->id=$p_array[$this->name];
81 $sql="insert into tool_uos(uos_value) values ($1)";
82 try {
83 $this->dbconx->exec_sql($sql,array($this->id));
84 } catch (Exception $e)
85 {
86 throw new Exception('Duplicate value');
87 }
88 }
89 /**
90 * @brief Count how many time we have this->id into the table tool_uos
91 * @remark global $cn Database connexion
92 * @param $p_array is the array where to find the key name, usually it is
93 * $_POST. The default value is $_POST
94 * @return integer : 0 or 1
95 */
96 function get_count($p_array=null)
97 {
98 global $cn;
99 if ( $p_array == null ) $p_array=$_POST;
100 $this->id=$p_array[$this->name];
101 $count=$this->dbconx->get_value('select count(*) from tool_uos where uos_value=$1',
102 array($this->id));
103 return $count;
104 }
105 function check ($p_array=null)
106 {
107 global $cn;
108 if ( $p_array == null ) $p_array=$_POST;
109 $this->id=$p_array[$this->name];
110 try
111 {
112 $count=$this->dbconx->get_value('select count(*) from tool_uos where uos_value=$1',
113 array($this->id));
114 if ($count != 0 ) throw new Exception ('DUPLICATE',CODE_EXCP_DUPLICATE);
115 }catch (Exception $e)
116 {
117 throw $e;
118 }
119 }
120}
121?>
$from_poste name
$input_from id
Objec to check a double insert into the database, this duplicate occurs after a refresh of the web pa...
__construct($p_name, $dbconx=-1)
Constructor $p_name will be set to $this->name, it is also the name of the tag hidden in a form.
$dbconx
database connexion
hidden()
return a string with a tag hidden and a uniq value
check($p_array=null)
save($p_array=null)
Try to insert into the table Single_Record.
get_count($p_array=null)
Count how many time we have this->id into the table tool_uos.
$_POST['ac']
Definition do.php:323
$count
const CODE_EXCP_DUPLICATE