id=$id+0;
$this->fetch_data();
}
protected function fetch_data() {
global $dbh;
$this->info=array();
if(!$this->id) return;
$req="select * from nomenclature_instruments where id_instrument=". $this->id;
$resultat=pmb_mysql_query($req,$dbh);
if (pmb_mysql_num_rows($resultat)) {
$r=pmb_mysql_fetch_object($resultat);
$this->info['id']= $r->id_instrument;
$this->info['code']= $r->instrument_code;
$this->info['name']= $r->instrument_name;
$this->info['standard']= $r->instrument_standard;
$this->info['musicstand_num']= $r->instrument_musicstand_num;
$this->info['musicstand']=array();
$req="select * from nomenclature_families,nomenclature_musicstands where musicstand_famille_num=id_family and id_musicstand=".$this->info['musicstand_num'];
$res_musicstands=pmb_mysql_query($req,$dbh);
if (pmb_mysql_num_rows($res_musicstands)) {
if($r_musicstand=pmb_mysql_fetch_object($res_musicstands)){
$this->info['musicstand']['id']=$r_musicstand->id_musicstand;
$this->info['musicstand']['name']=$r_musicstand->musicstand_name;
$this->info['musicstand']['division']=$r_musicstand->musicstand_division;
$this->info['musicstand']['display']="".$r_musicstand->musicstand_name."";
$req="select * from nomenclature_families where id_family=". $r_musicstand->id_family;
$res_family=pmb_mysql_query($req,$dbh);
if (pmb_mysql_num_rows($res_family)) {
$r_family=pmb_mysql_fetch_object($res_family);
$this->info['musicstand']['family']['id']= $r_family->id_family;
$this->info['musicstand']['family']['name']= $r_family->family_name;
$this->info['musicstand']['family']['display']= "".$r_family->family_name."";
}
}
}
}
}
public function get_form() {
global $nomenclature_instrument_form_tpl,$msg,$charset;
global $msg;
$tpl=$nomenclature_instrument_form_tpl;
if($this->id){
$tpl=str_replace('!!msg_title!!',$msg['admin_nomenclature_instrument_form_edit'],$tpl);
$tpl=str_replace('!!delete!!',"", $tpl);
$name=$this->info['name'];
$code=$this->info['code'];
if($this->info['standard'])$checked="checked"; else $checked="";
}else{
$tpl=str_replace('!!msg_title!!',$msg['admin_nomenclature_instrument_form_add'],$tpl);
$tpl_objet="";
$tpl=str_replace('!!delete!!',"",$tpl);
$name="";
$code="";
$checked="";
}
$tpl=str_replace('!!name!!',htmlentities($name, ENT_QUOTES, $charset),$tpl);
$tpl=str_replace('!!code!!',htmlentities($code, ENT_QUOTES, $charset),$tpl);
$tpl=str_replace('!!checked!!',$checked, $tpl);
$req="select id_musicstand, concat(musicstand_name,' ( ',family_name,' )')as label from nomenclature_musicstands,nomenclature_families where musicstand_famille_num=id_family order by musicstand_name";
$musicstand=gen_liste($req, "id_musicstand", "label", "id_musicstand", "", $this->info['musicstand']['id'],
0,$msg["admin_nomenclature_instrument_form_musicstand_no"], 0, $msg["admin_nomenclature_instrument_form_musicstand_no_sel"]);
$tpl=str_replace('!!musicstand!!',$musicstand,$tpl);
$tpl=str_replace('!!id!!',$this->id,$tpl);
return $tpl;
}
public function save_form() {
}
public function save() {
global $dbh;
global $msg;
global $name;
global $code;
global $id_musicstand;
global $standard;
global $force;
if($id_musicstand && $standard){
if($this->id) $restrict=" and id_instrument!=".$this->id;
$req="select * from nomenclature_instruments where instrument_musicstand_num=$id_musicstand and instrument_standard=1 $restrict ";
$res_instruments=pmb_mysql_query($req,$dbh);
$count_instrument=0;
if (pmb_mysql_num_rows($res_instruments)) {
if($r_instrument=pmb_mysql_fetch_object($res_instruments)){
if($force){
$req="UPDATE nomenclature_instruments SET instrument_standard=0 where id_instrument=".$r_instrument->id_instrument;
pmb_mysql_query($req, $dbh);
}else return "