db=$p_cn; $this->bh_id=$p_id; $this->pa_id=null; $this->bh_saldo=0; $this->bh_name="";$this->bh_description=""; } function load() { if ( $this->bh_id == 0 ) return ; $sql="select bh_name,bh_saldo,bh_description, pa_id ". " from bud_hypothese ". " where ". " bh_id =".$this->bh_id; $res=ExecSql($this->db,$sql); if ( pg_NumRows($res) == 0 ) return; $a=pg_fetch_array($res,0); $this->bh_name=$a['bh_name']; $this->bh_saldo=$a['bh_saldo']; $this->bh_description=$a['bh_description']; $this->pa_id=$a['pa_id']; } function delete () { $sql="delete from bud_hypothese where bh_id=".$this->bh_id; ExecSql($this->db,$sql); } function add() { $bh_saldo=(isNumber($this->bh_saldo) == 1 ) ?$this->bh_saldo:0; $pa_id=($this->pa_id <= 0 )?null:$this->pa_id; if ( strlen(trim ($this->bh_name)) == 0 ) return; $sql="insert into bud_hypothese( bh_name,bh_saldo,bh_description,pa_id) ". " values ($1,$2,$3,$4) returning bh_id"; $array=array( $this->bh_name, $bh_saldo, $this->bh_description, $pa_id ); $a=ExecSqlParam($this->db,$sql,$array); $this->bh_id=pg_fetch_result($a,0,0); } function update() { if ( strlen(trim ($this->bh_name)) == "" ) return; $bh_name=pg_escape_string($this->bh_name); $bh_saldo=(isNumber($this->bh_saldo) == 1 ) ?$this->bh_saldo:0; $bh_description=pg_escape_string($this->bh_description); $pa_id=($this->pa_id == null || $this->pa_id < 0 )?"NULL":$this->pa_id; $sql=sprintf( "update bud_hypothese set bh_name='%s',". " bh_saldo = %f ,bh_description='%s' ". " where bh_id= %d", $bh_name, $bh_saldo, $bh_description, $this->bh_id ); ExecSql($this->db,$sql); } function get_from_array($p_array) { $this->bh_id=(isset($p_array['bh_id']))?$p_array['bh_id']:0; $this->bh_saldo=(isset($p_array['bh_saldo']))?$p_array['bh_saldo']:0; $this->bh_description=(isset($p_array['bh_description']))?$p_array['bh_description']:0; $this->bh_name=(isset($p_array['bh_name']))?$p_array['bh_name']:0; $this->pa_id=(isset($p_array['pa_id']))?$p_array['pa_id']:0; } /*! * \brief retrieve a array of hypothese, * \param $p_cn, database connextion * * \return array of Bud_Hypo objects or null */ static function get_list($p_cn) { $sql="select * from bud_hypothese order by bh_name "; $r=ExecSql($p_cn,$sql); if ( pg_NumRows($r)==0 ) return null; $a=pg_fetch_all($r); foreach($a as $row) { $tmp=new Bud_Hypo($p_cn); $tmp->bh_id=$row['bh_id']; $tmp->bh_name=$row['bh_name']; $tmp->pa_id=$row['pa_id']; $tmp->bh_saldo=$row['bh_saldo']; $tmp->bh_description=$row['bh_description']; $result[]=clone $tmp; } return $result; } function form($p_update=0) { $wName=new widget("text","Nom","bh_name",$this->bh_name); $wDescription=new widget("text","Description","bh_description",$this->bh_description); $wSaldo=new widget("text","Solde","bh_saldo",$this->bh_saldo); $wBh_id=new widget("hidden","","bh_id",$this->bh_id); $array=make_array($this->db,"select pa_id,pa_name from plan_analytique",1); $wPa_id=new widget("select","Plan Analytique","pa_id",$array); $wPa_id->selected=$this->pa_id; if ( $p_update != 0 ) $wPa_id->readonly=true; $wName->table=1; $wDescription->table=1; $wSaldo->table=1; $wPa_id->table=1; $r="