id=$id+0;
$this->fetch_data();
}
protected function fetch_data(){
$this->name="";
$this->unit_price = 0;
$this->quick_allowed = 0;
if(!$this->id) return false;
// les infos générales...
$rqt = "select * from transactype where transactype_id ='".$this->id."'";
$res = mysql_query($rqt);
if(mysql_num_rows($res)){
$row = mysql_fetch_object($res);
$this->id = $row->transactype_id;
$this->name = $row->transactype_name;
$this->unit_price = $row->transactype_unit_price;
$this->quick_allowed = $row->transactype_quick_allowed;
}
}
public function get_form(){
global $msg, $charset;
global $pmb_droits_explr_localises;
global $transactype_form,$deflt_docs_location;
$form=$transactype_form;
if($this->id){
$titre=$msg["transactype_form_titre_edit"];
$form = str_replace('!!supprimer!!', "", $form);
}else{
$titre=$msg["transactype_form_titre_add"];
$form = str_replace('!!supprimer!!', "", $form);
}
$form = str_replace('!!titre!!', $titre, $form);
$form = str_replace('!!name!!', htmlentities($this->name,ENT_QUOTES, $charset), $form);
$form = str_replace('!!unit_price!!', htmlentities($this->unit_price,ENT_QUOTES, $charset), $form);
if($this->quick_allowed) $quick_allowed_checked=" checked='checked' ";
else $quick_allowed_checked;
$form = str_replace('!!quick_allowed_checked!!', $quick_allowed_checked, $form);
$form = str_replace('!!action!!', "./admin.php?categ=finance&sub=transactype&action=save&id=!!id!!", $form);
$form = str_replace('!!id!!', $this->id, $form);
return $form;
}
public function get_from_form(){
global $f_name;
global $f_locations;
global $id;
global $f_unit_price;
global $f_quick_allowed;
$this->id=$id+0;
$this->name=stripslashes($f_name);
$this->unit_price=$f_unit_price+0;
$this->quick_allowed=$f_quick_allowed+0;
}
public function check_delete(){
return 1;
}
public function delete(){
global $dbh;
$rqt = "delete FROM transactype WHERE transactype_id ='".$this->id."'";
mysql_query($rqt, $dbh);
$this->id=0;
}
public function save(){
global $dbh;
if($this->id){
$save = "update ";
$clause = "where transactype_id = '".$this->id."'";
}else{
$save = "insert into ";
}
$save.=" transactype set transactype_name='". addslashes( $this->name). "', transactype_unit_price='".$this->unit_price. "' ,transactype_quick_allowed='". $this->quick_allowed. "' $clause";
mysql_query($save,$dbh);
if(!$this->id){
$this->id=mysql_insert_id();
}
$this->fetch_data();
}
public function proceed(){
global $action,$msg;
switch($action) {
case 'edit':
print $this->get_form();
break;
case 'save':
$this->get_from_form();
$this->save();
print "";
break;
case 'delete':
if($this->check_delete()){
$this->delete();
print "";
}else{
print "";
}
break;
default:
break;
}
}
}