From 3e80a02b9b6988baa577334cea87398d8d7ddc7f Mon Sep 17 00:00:00 2001 From: sparkyx Date: Fri, 14 Dec 2007 17:07:04 +0000 Subject: [PATCH] Module Budget : card --- html/budget.php | 14 +++++ include/bud_card.inc.php | 112 +++++++++++++++++++++++++++++++++++++ include/class_bud_card.php | 44 ++++++++++++--- 3 files changed, 162 insertions(+), 8 deletions(-) create mode 100644 include/bud_card.inc.php diff --git a/html/budget.php b/html/budget.php index adc06f438..ef0c21b57 100644 --- a/html/budget.php +++ b/html/budget.php @@ -60,6 +60,10 @@ switch($p_action) { case 'hypo': $def=1; break; + case 'fiche': + $def=2; + break; + } @@ -86,6 +90,16 @@ if ( $p_action == "hypo" ) { require_once("bud_hypo.inc.php"); } + +//----------------------------------------------------- +// p_action == fiche +//----------------------------------------------------- +if ( $p_action == "fiche" ) +{ + require_once("bud_card.inc.php"); +} + + //----------------------------------------------------- // p_action == //----------------------------------------------------- diff --git a/include/bud_card.inc.php b/include/bud_card.inc.php new file mode 100644 index 000000000..59b9d77b6 --- /dev/null +++ b/include/bud_card.inc.php @@ -0,0 +1,112 @@ +'; +$wHypo=new widget("select","","bh_id"); +$wHypo->value=make_array($cn,"select bh_id,bh_name from bud_hypothese"); +echo $wHypo->IOValue(); +echo widget::submit('recherche','recherche'); +echo dossier::hidden(); +echo widget::hidden("p_action","fiche"); +echo ''; +echo '
'; +if ( ! isset($_REQUEST['bh_id'])) { + exit(); +} + +if ( isset($_POST['remove'])){ + $obj=new Bud_Card($cn); + $obj->from_array($_POST); + $obj->delete(); + } + +if ( isset($_POST['add'])){ + $obj=new Bud_Card($cn); + $obj->from_array($_POST); + $obj->add(); + + } + +if ( isset($_POST['update'])){ + $obj=new Bud_Card($cn); + $obj->from_array($_POST); + $obj->update(); + + } + +$list=Bud_Card::get_list($cn,$_REQUEST['bh_id']); + +echo ''; + + +$sa=( isset($_REQUEST['sa']))?$_REQUEST['sa']:''; + +//------------------------------------------------------------------------------ +// Add +//------------------------------------------------------------------------------ +if ( $sa == "add" ) { + echo '
'; + $obj=new Bud_Card($cn); + echo '
'; + echo $obj->form(); + echo widget::submit_button('add','Ajout'); + echo '
'; + echo '
'; + } + + +//------------------------------------------------------------------------------ +// Detail +//------------------------------------------------------------------------------ +if ( $sa == "detail" ) { + $obj=new Bud_Card($cn,$_GET['bc_id']); + $obj->load(); + echo '
'; + echo '
'; + echo $obj->form(); + echo widget::submit_button('remove','Effacer','onClick="return confirm(\'Vous confirmez cet effacement ?\')"'); + echo widget::submit_button('update','Mise à jour'); + + echo '
'; + } + diff --git a/include/class_bud_card.php b/include/class_bud_card.php index 63bfc1e9f..bdedec887 100644 --- a/include/class_bud_card.php +++ b/include/class_bud_card.php @@ -76,7 +76,20 @@ class Bud_Card { ExecSqlParam($this->db,$sql,$array); } - + /*! + *\brief convert an array to an object, if a idx is not set then the + * corresponding property will be null + * \param $p_array array to convert + */ + function from_array($p_array) { + if ( empty($p_array) ) return; + foreach (array ('bc_id','bc_code','bc_description','bc_price_unit','bc_unit') + as $key ){ + $this->$key=(isset($p_array[$key]))?$p_array[$key]:null; + } + if ( $this->bc_id == null ) + throw new Exception(__FILE__.":".__LINE__." bc ne peut pas etre nul"); + } function delete() { ExecSql($this->db,"delete from bud_card where bc_id=".$this->bc_id); } @@ -84,22 +97,37 @@ class Bud_Card { function load() { if ( $this->bc_id == 0 ) return ; - $sql="select bc_code,bc_description, bc_price_unit,bc_unit ". + $sql="select bc_id,bc_code,bc_description, bc_price_unit,bc_unit ". " from bud_card ". " where ". - " bh_id =".$this->bc_id; + " bc_id =".$this->bc_id; $res=ExecSql($this->db,$sql); - if ( pg_NumRows($res) == 0 ) return; + if ( pg_NumRows($res) == 0 ) return null; $a=pg_fetch_array($res,0); - foreach ( array('bc_code','bc_description','bc_price','bc_price_unit') as $key) { - $this->{"$key"}=$a[$key]; - } - + $this->from_array($a); } + static function get_list($p_cn,$p_bh_id) { + $sql="select * from bud_card where bh_id"; + $r=ExecSql($p_cn,$sql); + $result=array(); + $get=pg_fetch_all($res); + + if (empty ($get)) + return array(); + + foreach ($get as $row ) { + $obj=new Bud_Card($p_cn); + $obj->from_array($row); + $result[]=clone $obj; + } + return result; + } + function form() { + } static function testme() { $cn=DbConnect(dossier::id()); $a=new Bud_Card($cn);