noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_tool_uos.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /**
00020  * @file
00021  * @brief Objec to check a double insert into the database, this duplicate occurs after
00022  * a refresh of the web page
00023  */
00024 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00025 
00026 require_once 'class_database.php';
00027 define ('CODE_EXCP_DUPLICATE',901);
00028 /**
00029  * @brief Objec to check a double insert into the database, this duplicate occurs after
00030  * a refresh of the web page
00031  * in
00032  */
00033 
00034 class Tool_Uos
00035 {
00036     /**
00037      * Constructor $p_name will be set to $this->name, it is also the name
00038      * of the tag hidden in a form
00039      * @global $cn Db connxion
00040      * @param $p_name
00041      */
00042     function __construct($p_name)
00043     {
00044         $this->name=$p_name;
00045     }
00046     /**
00047      * @brief return a string with a tag hidden and a uniq value
00048      * @param $hHidden is the name of the tag hidden
00049      * @return string : tag hidden
00050      */
00051     function hidden()
00052     {
00053                 global $cn;
00054         $this->id=$cn->get_next_seq('uos_pk_seq');
00055         return HtmlInput::hidden($this->name,$this->id);
00056     }
00057     /**
00058      * @brief Try to insert into the table tool_uos
00059      * @global $cn Database connx
00060      * @throws Exception if the value $p_id is not unique
00061      */
00062     function save($p_array=null)
00063     {
00064         global $cn;
00065                 if ( $p_array == null ) $p_array=$_POST;
00066                 $this->id=$p_array[$this->name];
00067         $sql="insert into tool_uos(uos_value) values ($1)";
00068         try {
00069             $cn->exec_sql($sql,array($this->id));
00070         } catch (Exception $e)
00071         {
00072             throw new Exception('Duplicate value');
00073         }
00074     }
00075     /**
00076      * Count how many time we have this->id into the table tool_uos
00077      * @global $cn Database connx
00078      * @param $p_array is the array where to find the key name, usually it is
00079      * $_POST. The default value is $_POST
00080      * @return integer : 0 or 1
00081      */
00082     function get_count($p_array=null)
00083     {
00084         global $cn;
00085         if ( $p_array == null ) $p_array=$_POST;
00086         $this->id=$p_array[$this->name];
00087         $count=$cn->get_value('select count(*) from tool_uos where uos_value=$1',
00088                 array($this->id));
00089         return $count;
00090     }
00091     function check ($p_array=null)
00092     {
00093         global $cn;
00094         if ( $p_array == null ) $p_array=$_POST;
00095         $this->id=$p_array[$this->name];
00096         try
00097         {
00098             $count=$cn->get_value('select count(*) from tool_uos where uos_value=$1',
00099                     array($this->id));
00100             if ($count != 0 ) throw new Exception ('DUPLICATE',CODE_EXCP_DUPLICATE);
00101         }catch (Exception $e)
00102         {
00103             throw $e;
00104         }
00105     }
00106 }
00107 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations