noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_document_type.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  *   This file is part of NOALYSS.
00005  *
00006  *   NOALYSS is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   NOALYSS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with NOALYSS; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00022 /** \file
00023  * \brief  class for the table document_type
00024  */
00025 
00026 /** \brief class for the table document_type
00027  * < dt_id pk document_type
00028  * < dt_value value
00029  */
00030 class Document_type
00031 {
00032         /** document_type
00033          * \brief constructor
00034          * \param $p_cn database connx
00035          */
00036 
00037         function document_type($p_cn, $p_id = -1)
00038         {
00039                 $this->db = $p_cn;
00040                 $this->dt_id = $p_id;
00041         }
00042 
00043         /**
00044          * \brief Get all the data for this dt_id
00045          */
00046 
00047         function get()
00048         {
00049                 $sql = "select * from document_type where dt_id=$1";
00050                 $R = $this->db->exec_sql($sql, array($this->dt_id));
00051                 if (count($R) == 0) return 1;
00052                 $r = Database::fetch_array($R, 0);
00053                 $this->dt_id = $r['dt_id'];
00054                 $this->dt_value = $r['dt_value'];
00055                 $this->dt_prefix = $r['dt_prefix'];
00056                 return 0;
00057         }
00058 
00059         /**
00060          * @brief get a list
00061          * @parameter $p_cn database connection
00062          * @return array of data from document_type
00063          */
00064         static function get_list($p_cn)
00065         {
00066                 $sql = "select * from document_type order by dt_value";
00067                 $r = $p_cn->get_array($sql);
00068                 $array = array();
00069                 for ($i = 0; $i < count($r); $i++)
00070                 {
00071                         $tmp['dt_value'] = $r[$i]['dt_value'];
00072                         $tmp['dt_prefix'] = $r[$i]['dt_prefix'];
00073 
00074                         $bt = new IButton('X' . $r[$i]['dt_id']);
00075                         $bt->label = _('Modifier');
00076                         $bt->javascript = "cat_doc_change('" . $r[$i]['dt_id'] . "','" . Dossier::id() . "');";
00077 
00078                         $tmp['js_mod'] = $bt->input();
00079                         $tmp['dt_id'] = $r[$i]['dt_id'];
00080 
00081                         $bt = new IButton('X' . $r[$i]['dt_id']);
00082                         $bt->label = _('Effacer');
00083                         $bt->javascript = "if (confirm('" . _('Vous confirmez') . "')==true) {";
00084                         $bt->javascript.="cat_doc_remove('" . $r[$i]['dt_id'] . "','" . Dossier::id() . "');";
00085                         $bt->javascript.='}';
00086 
00087                         $tmp['js_remove'] = $bt->input();
00088 
00089 
00090                         $array[$i] = $tmp;
00091                 }
00092                 return $array;
00093         }
00094 
00095         function insert($p_value, $p_prefix)
00096         {
00097                 $sql = "insert into document_type(dt_value,dt_prefix) values ($1,$2)";
00098                 try
00099                 {
00100                         if ($this->db->count_sql('select * from document_type where upper(dt_value)=upper(trim($1))', array($p_value)) > 0)
00101                                 throw new Exception('Nom en double');
00102                         if (strlen(trim($p_value)) > 0)
00103                                 $this->db->exec_sql($sql, array($p_value, $p_prefix));
00104                 }
00105                 catch (Exception $e)
00106                 {
00107                         alert(j(_("Impossible d'ajouter [$p_value] ") . $e->getMessage()));
00108                 }
00109         }
00110 
00111         /**
00112          * Update
00113          */
00114         function update()
00115         {
00116                 try
00117                 {
00118                         $this->db->exec_sql("update document_type set dt_value=$1,dt_prefix=$2 where dt_id=$3", array($this->dt_value,
00119                                 $this->dt_prefix, $this->dt_id));
00120                 }
00121                 catch (Exception $e)
00122                 {
00123                         alert(" Erreur " . $e->getMessage());
00124                 }
00125         }
00126 
00127         function set_number($p_int)
00128         {
00129                 try
00130                 {
00131                         $this->db->exec_sql("alter sequence seq_doc_type_" . $this->dt_id . " restart " . $p_int);
00132                 }
00133                 catch (Exception $e)
00134                 {
00135                         alert("Erreur " . $e->getMessage());
00136                 }
00137         }
00138 }
 All Data Structures Namespaces Files Functions Variables Enumerations