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_Cat
00035 {
00036
00037 private static $variable=array ("id"=>"fc_id","order"=>"fc_order","desc"=>"fc_desc","forecast"=>"f_id");
00038 private $cn;
00039
00040
00041
00042
00043 function __construct ($p_init,$p_id=0)
00044 {
00045 $this->cn=$p_init;
00046 $this->fc_id=$p_id;
00047 }
00048 public function get_parameter($p_string)
00049 {
00050 if ( array_key_exists($p_string,self::$variable) )
00051 {
00052 $idx=self::$variable[$p_string];
00053 return $this->$idx;
00054 }
00055 else
00056 exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
00057 }
00058 public function set_parameter($p_string,$p_value)
00059 {
00060 if ( array_key_exists($p_string,self::$variable) )
00061 {
00062 $idx=self::$variable[$p_string];
00063 $this->$idx=$p_value;
00064 }
00065 else
00066 exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
00067
00068
00069 }
00070 public function get_info()
00071 {
00072 return var_export(self::$variable,true);
00073 }
00074 public function verify()
00075 {
00076 if (strlen(trim($this->fc_order))==0)
00077 {
00078 $this->fc_order="1";
00079 }
00080
00081
00082 return 0;
00083 }
00084 public function save()
00085 {
00086 if ( $this->get_parameter("id") == 0 )
00087 $this->insert();
00088 else
00089 $this->update();
00090 }
00091
00092 public function insert()
00093 {
00094 if ( $this->verify() != 0 ) return;
00095
00096 $sql="insert into forecast_cat (fc_desc,fc_order,f_id) ".
00097 " values ($1,$2,$3) returning fc_id";
00098 $res=$this->cn->exec_sql(
00099 $sql,
00100 array($this->fc_desc,$this->fc_order,$this->f_id)
00101 );
00102 $this->fc_id=Database::fetch_result($res,0,0);
00103 }
00104
00105 public function update()
00106 {
00107 if ( $this->verify() != 0 ) return;
00108
00109 $sql="update forecast_cat set fc_desc=$1,f_id=$2,fc_order=$3 ".
00110 " where fc_id = $4";
00111 $res=$this->cn->exec_sql(
00112 $sql,
00113 array($this->fc_desc,$this->f_id, $this->fc_order,$this->fc_id)
00114 );
00115 }
00116
00117
00118
00119
00120
00121
00122 public static function load_all($p_cn,$p_id)
00123 {
00124 $sql="select fc_id,fc_desc,fc_order from forecast_cat where f_id=$1";
00125
00126 $res=$p_cn->get_array($sql,array($p_id));
00127
00128 return $res;
00129 }
00130 public function load()
00131 {
00132
00133 $sql="select fc_desc, f_id,fc_order from forecast_cat where fc_id=$1";
00134
00135 $res=$this->cn->exec_sql(
00136 $sql,
00137 array($this->fc_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
00153
00154 public function make_array($id)
00155 {
00156 $sql="select fc_id,fc_desc from forecast_cat where f_id=$id";
00157 $ret=$this->cn->make_array($sql);
00158 return $ret;
00159 }
00160 public function delete()
00161 {
00162 $sql="delete from forecast_cat where fc_id=$1";
00163 $res=$this->cn->exec_sql($sql,array($this->fc_id));
00164 }
00165
00166
00167
00168 static function test_me()
00169 {}
00170
00171 }
00172
00173 ?>