noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_anc_plan.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 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief Concerns the Analytic plan (table plan_analytique)
00024  */
00025 
00026 /*! \brief
00027  *  Concerns the Analytic plan (table plan_analytique)
00028  */
00029 require_once("class_itext.php");
00030 require_once("class_ihidden.php");
00031 require_once("constant.php");
00032 require_once('class_database.php');
00033 require_once("class_anc_account.php");
00034 require_once ('class_dossier.php');
00035 
00036 class Anc_Plan
00037 {
00038     var $db; /*!<database connection */
00039     var $name;                                  /*!< name plan_analytique.pa_name */
00040     var $description;                           /*!< description of the PA plan_analytique.pa_description*/
00041     var $id;                                            /*!< id = plan_analytique.pa_id */
00042 
00043     function Anc_Plan($p_cn,$p_id=0)
00044     {
00045         $this->db=$p_cn;
00046         $this->id=$p_id;
00047         $this->name="";
00048         $this->description="";
00049         $this->get();
00050     }
00051     /*!\brief get the list of all existing PA
00052      * \return an array of PA (not object)
00053      *
00054      */
00055     function get_list($p_order=" order by pa_name")
00056     {
00057         $array=array();
00058         $sql="select pa_id as id,pa_name as name,".
00059              "pa_description as description from plan_analytique $p_order";
00060         $ret=$this->db->exec_sql($sql);
00061         $array=Database::fetch_all($ret);
00062         return $array;
00063     }
00064 
00065     function get()
00066     {
00067         if ( $this->id==0) return;
00068 
00069         $sql="select pa_name,pa_description from plan_analytique where pa_id=".$this->id;
00070         $ret= $this->db->exec_sql($sql);
00071         if ( Database::num_row($ret) == 0)
00072         {
00073             return;
00074         }
00075         $a=  Database::fetch_array($ret,0);
00076         $this->name=$a['pa_name'];
00077         $this->description=$a['pa_description'];
00078 
00079     }
00080 
00081     function delete()
00082     {
00083         if ( $this->id == 0 ) return;
00084         $this->db->exec_sql("delete from plan_analytique where pa_id=".$this->id);
00085     }
00086 
00087     function update()
00088     {
00089         if ( $this->id==0) return;
00090         $name=sql_string($this->name);
00091         if ( strlen($name) == 0)
00092             return;
00093 
00094         $description=sql_string($this->description);
00095         $this->db->exec_sql("update plan_analytique set pa_name=$1,
00096                             pa_description=$2 where pa_id=$3",array($name,$description,$this->id));
00097     }
00098 
00099     function add()
00100     {
00101         $name=sql_string($this->name);
00102         if ( strlen($name) == 0)
00103             return;
00104         if ( $this->isAppend() == false) return;
00105         $description=sql_string($this->description);
00106         $this->db->exec_sql("insert into plan_analytique(pa_name,pa_description)".
00107                             " values (".
00108                             "'".$name."',".
00109                             "'".$description."')");
00110         $this->id=$this->db->get_current_seq('plan_analytique_pa_id_seq');
00111 
00112     }
00113     function form()
00114     {
00115 
00116         $wName=new IText('pa_name',$this->name);
00117 
00118         $wName->table=1;
00119         $wDescription=new IText('pa_description',$this->description);
00120         $wDescription->table=1;
00121         $wId=new IHidden("pa_id",$this->id);
00122         $ret="<TABLE>";
00123         $ret.='<tr>'.td(_('Nom')).$wName->input().'</tr>';
00124         $ret.="<tr>".td(_('Description')).$wDescription->input()."</tr>";
00125         $ret.="</table>";
00126         $ret.=$wId->input();
00127         return $ret;
00128     }
00129     function isAppend()
00130     {
00131         $count=$this->db->get_value("select count(pa_id) from plan_analytique");
00132 
00133         if ( $count > 10 )
00134             return false;
00135         else
00136             return true;
00137     }
00138     /*!\brief get all the poste related to the current
00139      *        Analytic plan
00140      * \return an array of Poste_analytic object
00141      */
00142     function get_poste_analytique($p_order="")
00143     {
00144         $sql="select po_id,po_name from poste_analytique where pa_id=".$this->id." $p_order";
00145         $r=$this->db->exec_sql($sql);
00146         $ret=array();
00147         if ( Database::num_row($r) == 0 )
00148             return $ret;
00149 
00150         $all=Database::fetch_all($r);
00151         foreach ($all as $line)
00152         {
00153             $obj=new Anc_Account($this->db,$line['po_id']);
00154             $obj->get_by_id();
00155             $ret[]=clone $obj;
00156         }
00157         return $ret;
00158     }
00159     /*!\brief show the header for a table for PA
00160      * \return string like <th>name</th>...
00161      */
00162     function header()
00163     {
00164         $res="";
00165         $a_plan=$this->get_list(" order by pa_id");
00166         if ( empty($a_plan)) return "";
00167         foreach ($a_plan as $r_plan)
00168         {
00169             $res.="<th>".h($r_plan['name'])."</th>";
00170         }
00171         return $res;
00172     }
00173     function count()
00174     {
00175         $a=$this->db->count_sql("select pa_id from plan_analytique");
00176         return $a;
00177     }
00178     function exist()
00179     {
00180         $a=$this->db->count_sql("select pa_id from plan_analytique where pa_id=".
00181                                 Database::escape_string($this->pa_id));
00182 
00183         return ($a==0)?false:true;
00184 
00185     }
00186     /**
00187     *@brief return an HTML string containing hidden input type to
00188     * hold the differant PA_ID
00189     *@param $p_array contains a array, it is the result of the fct
00190     * Anc_Plan::get_list
00191     *@return html string
00192     *@see Anc_Plan::get_list
00193     */
00194     static function hidden($p_array)
00195     {
00196         $r='';
00197         for ($i_anc=0;$i_anc <count($p_array);$i_anc++)
00198         {
00199             $r.=HtmlInput::hidden('pa_id[]',$p_array[$i_anc]['id']);
00200         }
00201         return $r;
00202     }
00203     static function test_me()
00204     {
00205         $cn=new Database(dossier::id());
00206         echo "<h1>Plan analytique : test</h1>";
00207         echo "clean";
00208         $cn->exec_sql("delete from plan_analytique");
00209 
00210         $p=new Anc_Plan($cn);
00211         echo "<h2>Add</h2>";
00212         $p->name="Nouveau 1";
00213         $p->description="C'est un test";
00214         echo "Add<hr>";
00215         $p->add();
00216         $p->name="Nouveau 2";
00217         $p->add();
00218         $pa_id=$p->id;
00219         echo $p->id."/";
00220         $p->name="Nouveau 3";
00221         $p->add();
00222         echo $p->id."/";
00223 
00224 
00225         $p->name="Nouveau 4";
00226         $p->add();
00227         echo $p->id;
00228 
00229         echo "<h2>get</h2>";
00230         $p->get();
00231         var_dump($p);
00232         echo "<h2>Update</h2> ";
00233         $p->name="Update ";
00234         $p->description="c'est change";
00235         $p->update();
00236         $p->get();
00237         var_dump($p);
00238         echo "<h2>get_list</h2>";
00239         $a=$p->get_list();
00240         var_dump($a);
00241         echo "<h2>delete </h2>";
00242         $p->delete();
00243 
00244 
00245     }
00246 }
00247 
00248 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations