type = $type; $this->id = $id; if($this->id!=0){ $this->_fetch_data(); }else{ $this->name = ""; $this->country = ""; $this->diffusible = true; } } private function _fetch_data(){ $query = "select * from origin_".$this->type." where id_origin_".$this->type." = ".$this->id; $result = mysql_query($query); if(mysql_num_rows($result)){ $row = mysql_fetch_assoc($result); $this->name = $row['origin_'.$this->type."_name"]; $this->country = $row['origin_'.$this->type."_country"]; $this->diffusible = ($row['origin_'.$this->type."_diffusible"]==1 ? true : false); } } public function is_diffusible(){ return $this->diffusible; } public function save(){ if($this->name != ""){ if($this->id){ $query = "update origin_".$this->type ." set "; $where = "where id_origin_".$this->type." = ".$this->id; }else{ $query = "insert into origin_".$this->type ." set "; $where = ""; } $query .= "origin_".$this->type."_name = '".addslashes($this->name)."',"; $query .= "origin_".$this->type."_country = '".addslashes($this->country)."',"; $query .= "origin_".$this->type."_diffusible = '".($this->is_diffusible() ? 1:0)."' "; $result = mysql_query($query.$where); if($result) return true; else return false; } return false; } public function delete(){ if($this->id < 2){ // le catalogue interne et la BnF, c'est pas négociable ! return false; }else{ //TODO check utilisation $query = "delete from origin_".$this->type." where id_origin_".$this->type." = ".$this->id; print $query; $result = mysql_query($query); if($result) return true; } return false; } public function show_form(){ global $msg,$charset; global $origin_form,$current_module; $form = str_replace("!!type!!",$this->type,$origin_form); $form = str_replace("!!id!!",$this->id,$form); $title = $this->id!= 0 ? $msg['authorities_origin_add']:$msg['authorities_origin_modif']; $form = str_replace("!!title!!",htmlentities($title,ENT_QUOTES,$charset),$form); $form = str_replace("!!origin_name!!",$this->name,$form); $form = str_replace("!!origin_country!!",$this->country,$form); $form = str_replace("!!checked!!",$this->diffusible ? "checked='checked'" : "",$form); print $form; } public function show_tab_row(){ global $msg,$charset; $row = "