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