00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Forecast_Item
00035 {
00036
00037 private static $variable=array ("id"=>"fi_id","text"=>"fi_text","account"=>"fi_account",
00038 "card"=>"fi_card","order"=>"fi_order","cat_id"=>"fc_id","amount"=>"fi_amount","debit"=>"fi_debit","periode"=>"fi_pid");
00039 private $cn;
00040
00041
00042
00043
00044 function __construct ($p_init,$p_id=0)
00045 {
00046 $this->cn=$p_init;
00047 $this->fi_id=$p_id;
00048 }
00049 public function get_parameter($p_string)
00050 {
00051 if ( array_key_exists($p_string,self::$variable) )
00052 {
00053 $idx=self::$variable[$p_string];
00054 return $this->$idx;
00055 }
00056 else
00057 exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
00058 }
00059 public function set_parameter($p_string,$p_value)
00060 {
00061 if ( array_key_exists($p_string,self::$variable) )
00062 {
00063 $idx=self::$variable[$p_string];
00064 $this->$idx=$p_value;
00065 }
00066 else
00067 exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
00068
00069
00070 }
00071 public function get_info()
00072 {
00073 return var_export(self::$variable,true);
00074 }
00075 public function verify()
00076 {
00077 $this->fi_account= str_replace(" ", "", $this->fi_account);
00078
00079
00080 return 0;
00081 }
00082 public function save()
00083 {
00084
00085 if ( $this->get_parameter("id") == 0 )
00086 $this->insert();
00087 else
00088 $this->update();
00089 }
00090
00091 public function insert()
00092 {
00093 if ( $this->verify() != 0 ) return;
00094
00095 $sql="INSERT INTO forecast_item(
00096 fi_text, fi_account, fi_card, fi_order, fc_id, fi_amount,
00097 fi_debit,fi_pid)
00098 VALUES ($1, $2, $3, $4, $5, $6, $7,$8) returning fi_id;";
00099 $res=$this->cn->exec_sql(
00100 $sql,
00101 array($this->fi_text,$this->fi_account,$this->fi_card,$this->fi_order,$this->fc_id,$this->fi_amount,$this->fi_debit,$this->fi_pid)
00102 );
00103 $this->fi_id=Database::fetch_result($res,0,0);
00104 }
00105
00106 public function update()
00107 {
00108 if ( $this->verify() != 0 ) return;
00109
00110 $sql="UPDATE forecast_item
00111 SET fi_text=$1, fi_account=$2, fi_card=$3, fi_order=$4, fc_id=$5,
00112 fi_amount=$6, fi_debit=$7,fi_pid=$8
00113 WHERE fi_id=$9;";
00114 $res=$this->cn->exec_sql($sql,
00115 array($this->fi_text,
00116 $this->fi_account,
00117 $this->fi_card,
00118 $this->fi_order,
00119 $this->fc_id,
00120 $this->fi_amount,
00121 $this->fi_debit,
00122 $this->fi_pid,
00123 $this->fi_id)
00124 );
00125
00126 }
00127
00128 public function load()
00129 {
00130
00131 $sql="SELECT fi_id, fi_text, fi_account, fi_card, fi_order, fc_id, fi_amount,
00132 fi_debit,fi_pid
00133 FROM forecast_item where fi_id=$1";
00134
00135 $res=$this->cn->exec_sql(
00136 $sql,
00137 array($this->fi_id)
00138 );
00139
00140 if ( Database::num_row($res) == 0 ) return;
00141 $row=Database::fetch_array($res,0);
00142 foreach ($row as $idx=>$value)
00143 {
00144 $this->$idx=$value;
00145 }
00146
00147 }
00148
00149
00150
00151
00152 public function delete()
00153 {
00154 $sql="delete from forecast_item where fi_id=$1";
00155 $res=$this->cn->exec_sql($sql,array($this->fi_id));
00156 }
00157
00158
00159
00160 static function test_me()
00161 {}
00162
00163 }
00164
00165 ?>