db=$p_cn; $this->id=$p_id; $this->name=""; $this->description=""; $this->get(); } /*!\brief get the list of all existing PA * \return an array of PA (not object) * */ function get_list() { $array=array(); $sql="select pa_id as id,pa_name as name,". "pa_description as description from plan_analytique order by pa_name"; $ret=ExecSql($this->db,$sql); $array=pg_fetch_all($ret); return $array; } function get() { if ( $this->id==0) return; $sql="select pa_name,pa_description from plan_analytique where pa_id=".$this->id; $ret= ExecSql($this->db,$sql); if ( pg_NumRows($ret) == 0) { return; } $a= pg_fetch_array($ret,0); $this->name=$a['pa_name']; $this->description=$a['pa_description']; } function delete() { if ( $this->id == 0 ) return; ExecSql($this->db,"delete from plan_analytique where pa_id=".$this->id); } function update() { if ( $this->id==0) return; $name=FormatString($this->name); if ( strlen($name) == 0) return; $description=FormatString($this->description); ExecSql($this->db,"update plan_analytique set pa_name='".$name."'". ", pa_description='".$description."'". " where pa_id=".$this->id); } function add() { $name=FormatString($this->name); if ( strlen($name) == 0) return; if ( $this->isAppend() == false) return; $description=FormatString($this->description); ExecSql($this->db,"insert into plan_analytique(pa_name,pa_description)". " values (". "'".$name."',". "'".$description."')"); $this->id=getSequence($this->db,'plan_analytique_pa_id_seq'); } function form() { $wName=new widget('TEXT','Nom','pa_name',$this->name); $wName->table=1; $wDescription=new widget('TEXT','Description','pa_description',$this->description); $wDescription->table=1; $wId=new widget("HIDDEN","pa_id",$this->id); $ret=""; $ret.=''.$wName->IOValue().''; $ret.="".$wDescription->IOValue().""; $ret.="
"; $ret.=$wId->IOValue(); return $ret; } function isAppend() { $count=getDbValue($this->db,"select count(pa_id) from plan_analytique"); if ( $count > 4) return false; else return true; } /*!\brief get all the poste related to the current * Analytic plan * \return an array of Poste_analytic object */ function get_poste_analytique() { $sql="select po_id from poste_analytique where pa_id=".$this->id; $r=ExecSql($this->db,$sql); $ret=array(); if ( pg_NumRows($r) == 0 ) return $ret; $all=pg_fetch_all($r); foreach ($all as $line) { $obj=new Poste_analytique($this->db,$line['po_id']); $obj->get_by_id(); $ret[]=clone $obj; } return $ret; } /*!\brief show the header for a table for PA * \return string like name... */ function header() { $res=""; $a_plan=$this->get_list(); if ( empty($a_plan)) return ""; foreach ($a_plan as $r_plan) { $res.="".$r_plan['name'].""; } return $res; } function count() { $a=CountSql($this->db,"select pa_id from plan_analytique"); return $a; } function exist() { $a=CountSql($this->db,"select pa_id from plan_analytique where pa_id=". pg_escape_string($this->pa_id)); return ($a==0)?false:true; } } ?>