get_storages_list(); $this->fetch_datas(); } protected function fetch_datas(){ $this->defined_list[] = array(); $query = "select * from storages order by storage_name"; $result = pmb_mysql_query($query); $this->defined_list = array(); if(pmb_mysql_num_rows($result)){ while($row = pmb_mysql_fetch_object($result)){ $this->defined_list[] = array( 'id' => $row->id_storage, 'name' => $row->storage_name, 'class' => $row->storage_class, 'params' => unserialize($row->storage_params) ); } } } public function process($action="",$id){ switch($action){ case "edit": print $this->get_form($id); break; case "delete" : $this->delete($id); $this->fetch_datas(); print $this->get_table(); break; case "save" : $this->save_form(); $this->fetch_datas(); print $this->get_table(); break; default : print $this->get_table(); break; } } protected function get_storages_list(){ global $class_path; global $charset,$msg; $xml = new DOMDocument(); if(file_exists($class_path."/storages/storages_subst.xml")){ $file = $class_path."/storages/storages_subst.xml"; }else{ $file = $class_path."/storages/storages.xml"; } $xml->load($file); $storages = $xml->getElementsByTagName("storage"); for($i=0 ; $i<$storages->length ; $i++){ $storage = array(); $storage['class'] = ($charset != "utf-8" ? utf8_decode($storages->item($i)->getAttribute('class')) : $storages->item($i)->getAttribute('class')); $storage['label'] = ($charset != "utf-8" ? utf8_decode($storages->item($i)->nodeValue) : $storages->item($i)->nodeValue); if(substr($storage['label'],0,4) == "msg:"){ $storage['label'] = $msg[substr($storage['label'],4)]; } $this->list[] = $storage; } } public function get_item_form($id=0){ global $charset,$msg; $form = "

".htmlentities($msg['storage_form_title'],ENT_QUOTES,$charset)."

 
"; $id+=0; $form.="
"; return $form; } public function get_table($form_link=""){ global $msg,$charset; if(!$form_link){ $form_link="./admin.php?categ=docnum&sub=storages&action=edit"; } $table = " "; for($i=0 ; $idefined_list) ; $i++){ $table.=" "; } $table.="
".$msg['storage_name']." ".$msg['storage_type']." ".$msg['storage_resume']."
".htmlentities($this->defined_list[$i]['name'],ENT_QUOTES,$charset)." ".htmlentities($this->get_type($this->defined_list[$i]['class']),ENT_QUOTES,$charset)." ".$this->get_stockage_infos($this->defined_list[$i]['id'])."
 
"; return $table; } public function get_type($class){ foreach($this->list as $method){ if($method['class'] == $class){ return $method['label']; } } return ""; } public static function get_storage_class($id){ global $base_path,$include_path,$class_path; $query = "select storage_class from storages where id_storage = ".($id*1); $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result)){ $row = pmb_mysql_fetch_object($result); require_once($class_path."/storages/".$row->storage_class.".class.php"); $obj = new $row->storage_class($id); return $obj; } return false; } public function get_stockage_infos($id){ $obj = self::get_storage_class($id); if($obj){ return $obj->get_infos(); } return ""; } public function get_form($id,$action="./admin.php?categ=docnum&sub=storages&action=save&id="){ global $charset,$msg; $form = "

".htmlentities($msg['storage_form_title'],ENT_QUOTES,$charset)."

 
"; $id+=0; $row =array(); if($id){ $query ="select * from storages where id_storage = '".$id."'"; $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result)){ $row = pmb_mysql_fetch_assoc($result); } } $form.="
 
"; if(!empty($row['storage_class'])){ $form.= $this->get_params_form($row['storage_class'],$row['id_storage']); } $form.= "
 
 
"; if(!empty($row['id_storage'])) { $form.= "
"; } $form.= "
 
"; return $form; } public function save_form(){ global $id,$storage_name,$storage_method,$storage_params; $id = intval($id); $row = array(); if($id){ $query ="select * from storages where id_storage = '".$id."'"; $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result)){ $row = pmb_mysql_fetch_assoc($result); } } if(!empty($row['id_storage'])) { $query = "update storages set "; $clause =" where id_storage = ".$row['id_storage']; }else{ $query = "insert into storages set "; $clause= ""; } if($storage_method){ $query.= "storage_name='".$storage_name."', storage_class = '".$storage_method."', storage_params = '".addslashes(serialize($storage_params))."'"; }else if (!empty($row['id_storage'])){ $query = "delete from storages"; } pmb_mysql_query($query.$clause); } public function delete($id){ $id+=0; pmb_mysql_query("delete from storages where id_storage='".$id."'"); } public function get_params_form($class_name,$id){ global $base_path,$include_path,$class_path; $storage = new storage($id); return $storage->get_form($class_name); } }