noalyss Version-9
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 * in
31 */
32
34{
35 public $name;
36 public $id;
37 /**
38 * 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
42 */
43 function __construct($p_name)
44 {
45 $this->name=$p_name;
46 }
47 /**
48 * @brief return a string with a tag hidden and a uniq value
49 * @param $hHidden is the name of the tag hidden
50 * @return string : tag hidden
51 */
52 function hidden()
53 {
54 global $cn;
55 $this->id=$cn->get_next_seq('uos_pk_seq');
56 return HtmlInput::hidden($this->name,$this->id);
57 }
58 /**
59 * @brief Try to insert into the table Single_Record
60 * @remark global $cn Database connexion
61 * @throws Exception if the value $p_id is not unique
62 */
63 function save($p_array=null)
64 {
65 global $cn;
66 if ( $p_array == null ) $p_array=$_POST;
67 $this->id=$p_array[$this->name];
68 $sql="insert into tool_uos(uos_value) values ($1)";
69 try {
70 $cn->exec_sql($sql,array($this->id));
71 } catch (Exception $e)
72 {
73 throw new Exception('Duplicate value');
74 }
75 }
76 /**
77 * Count how many time we have this->id into the table tool_uos
78 * @remark global $cn Database connexion
79 * @param $p_array is the array where to find the key name, usually it is
80 * $_POST. The default value is $_POST
81 * @return integer : 0 or 1
82 */
83 function get_count($p_array=null)
84 {
85 global $cn;
86 if ( $p_array == null ) $p_array=$_POST;
87 $this->id=$p_array[$this->name];
88 $count=$cn->get_value('select count(*) from tool_uos where uos_value=$1',
89 array($this->id));
90 return $count;
91 }
92 function check ($p_array=null)
93 {
94 global $cn;
95 if ( $p_array == null ) $p_array=$_POST;
96 $this->id=$p_array[$this->name];
97 try
98 {
99 $count=$cn->get_value('select count(*) from tool_uos where uos_value=$1',
100 array($this->id));
101 if ($count != 0 ) throw new Exception ('DUPLICATE',CODE_EXCP_DUPLICATE);
102 }catch (Exception $e)
103 {
104 throw $e;
105 }
106 }
107}
108?>
$from_poste name
Objec to check a double insert into the database, this duplicate occurs after a refresh of the web pa...
hidden()
return a string with a tag hidden and a uniq value
check($p_array=null)
__construct($p_name)
Constructor $p_name will be set to $this->name, it is also the name of the tag hidden in a form.
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:312
$count
const CODE_EXCP_DUPLICATE