restore($tmp); }else{ $this->fetch_datas(); cms_cache::set_at_cms_cache($this); } } protected function restore($cms_object){ foreach(get_object_vars($cms_object) as $propertieName=>$propertieValue){ $this->{$propertieName}=$propertieValue; } } protected function fetch_datas(){ parent::fetch_datas(); if($this->id){ //récupération des utilisations $query = "select * from cms_documents_links where document_link_num_document = ".$this->id; $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result)){ while($row=pmb_mysql_fetch_object($result)){ if(!isset($this->used[$row->document_link_type_object]) || !$this->used[$row->document_link_type_object]) $this->used[$row->document_link_type_object] = array(); $this->used[$row->document_link_type_object][] = $row->document_link_num_object; } } } } public function get_item_form($selected = false,$edit_js_function="openEditDialog"){ global $msg,$charset; $item = "

".htmlentities(($this->title ? $this->title : $this->filename),ENT_QUOTES,$charset)."
".htmlentities($this->mimetype,ENT_QUOTES,$charset).($this->filesize ? " - (".$this->get_human_size().")" : "")."

"; return $item; } public function get_vignette_url(){ global $pmb_url_base,$pmb_img_cache_url, $pmb_img_cache_folder; $vign_url = "./ajax.php?module=cms&categ=document&action=thumbnail&id=".$this->id; //On prend l'URL absolu pour avoir un hash de l'image correcte $img = getimage_cache(0,0,0,$pmb_url_base.$vign_url); if ($img['location']) { $vign_url = str_replace($pmb_img_cache_folder, $pmb_img_cache_url, $img['location']); } return $vign_url; } public function get_document_url(){ global $opac_url_base; return "./ajax.php?module=cms&categ=document&action=render&id=".$this->id; } public function get_form($action="./ajax.php?module=cms&categ=documents&action=save_form&id=") { global $msg, $charset, $opac_url_base, $_mimetypes_bymimetype_, $base_path; $form = "
"; if($this->url){ $form.= "
"; } create_tableau_mimetype(); $selector_mimetype = ""; if($this->id){ $form.= "
".$selector_mimetype."
"; } $collections=new cms_collections(); $form.="
 



".htmlentities($this->filename,ENT_QUOTES,$charset)."
".htmlentities($this->mimetype,ENT_QUOTES,$charset)."
".htmlentities($this->get_human_size(),ENT_QUOTES,$charset)."
".htmlentities(format_date($this->create_date),ENT_QUOTES,$charset)."

".$this->storage->get_storage_infos()."
".$collections->get_collections_selector('cms_document_collection', $this->num_object)."
"; if ($this->id) { $form .= "
"; } $form.="
 
"; //utilisation if(count($this->used)){ $form.=" "; $array_ids = array(); $id=1; foreach($this->used as $type => $used){ $query =""; switch($type){ case "article" : $query = "select id_article as id ,article_title as title from cms_articles where id_article in (".implode(",",$used).") order by 2"; $use_link = "./cms.php?categ=article&sub=edit&id="; break; case "section" : $query = "select id_section as id,section_title as title from cms_sections where id_section in (".implode(",",$used).") order by 2"; $use_link = "./cms.php?categ=section&sub=edit&id="; break; } if($query){ $result = pmb_mysql_query($query) ; if(pmb_mysql_num_rows($result)){ while($row = pmb_mysql_fetch_object($result)){ $form.=" "; $array_ids[]=$id; $id++; } } } } $form.="
".htmlentities($msg['cms_document_used_type'],ENT_QUOTES,$charset)." ".htmlentities($msg['cms_document_used_title'],ENT_QUOTES,$charset)."
".htmlentities($msg['cms_document_used_type_'.$type],ENT_QUOTES,$charset)." ".htmlentities($row->title,ENT_QUOTES,$charset)."
"; }else{ $form.=" "; } $form.="

"; return $form; } public function save_form($caller="collection"){ global $msg, $charset; global $cms_document_title, $cms_document_description, $cms_document_url, $cms_document_vign; global $cms_document_mime_vign; global $cms_document_collection, $base_path; global $prefix_url_image; $this->title = stripslashes($cms_document_title); $this->description = stripslashes($cms_document_description); $this->url = stripslashes($cms_document_url); $flag_collection_change=0; if($cms_document_collection){ if($this->num_object != $cms_document_collection){ $this->num_object = $cms_document_collection*1; $flag_collection_change=1; } } // gestion de la vignette if(!$cms_document_mime_vign && $vignette_name = $_FILES['cms_document_vign_file']['name']) { $vignette_temp = $_FILES['cms_document_vign_file']['tmp_name']; $vignette_moved = basename($vignette_temp); $vignette_name = preg_replace("/ |'|\\|\"|\//m", "_", $vignette_name); move_uploaded_file($vignette_temp,$base_path.'/temp/'.$vignette_moved); $this->vignette = construire_vignette($vignette_moved, $userfile_moved); $maj_vignette = 1 ; }elseif(!$cms_document_mime_vign && $cms_document_vign){ $this->calculate_vignette(); $maj_vignette = 1 ; }else if($cms_document_mime_vign) { if ($prefix_url_image) { $tmpprefix_url_image = $prefix_url_image; }else { $tmpprefix_url_image = "./"; } $vignette = $tmpprefix_url_image."images/mimetype/".icone_mimetype($cms_document_mime_vign, ""); if(file_exists($vignette)){ $fp = fopen($vignette , "r" ); if ($fp) $contenu_vignette = fread ($fp, filesize($vignette)); } if($contenu_vignette) { $this->vignette = $contenu_vignette; $maj_vignette = 1 ; } } if($this->id){ $query = "update cms_documents set "; $clause = " where id_document = ".$this->id; }else{ $query = "insert into cms_documents set "; $clause=""; } $query.= " document_title = '".addslashes($this->title)."', document_description = '".addslashes($this->description)."', document_url = '".addslashes($this->url)."', document_num_object = '".$this->num_object."' "; if($maj_vignette){ $query.= ", document_vignette = '".addslashes($this->vignette)."'"; } if(pmb_mysql_query($query.$clause)){ if($caller = "editorial_form"){ if($flag_collection_change){ return "
"; } return $this->get_item_form(true,"openEditDialog"); }else{ return $this->get_item_render("openEditDialog"); } } } public function delete(){ global $msg; //vérification d'utilisation $query = "select * from cms_documents_links where document_link_num_document = ".$this->id; $result = pmb_mysql_query($query); if(!pmb_mysql_num_rows($result)){ return parent::delete(); }else{ return $msg['cms_document_delete_document_used']; } return false; } public function format_datas(){ $datas = parent::format_datas(); $collection = new cms_collection($this->num_object); $datas['collection'] = $collection->get_infos(); return $datas; } public static function get_format_data_structure(){ global $msg; $format_datas = array(); $format_datas[] = array( 'var' => "id", 'desc'=> $msg['cms_document_format_data_id'] ); $format_datas[] = array( 'var' => "name", 'desc'=> $msg['cms_document_format_data_name'] ); $format_datas[] = array( 'var' => "description", 'desc'=> $msg['cms_document_format_data_description'] ); $format_datas[] = array( 'var' => "filename", 'desc'=> $msg['cms_document_format_data_filename'] ); $format_datas[] = array( 'var' => "mimetype", 'desc'=> $msg['cms_document_format_data_mimetype'] ); $format_datas[] = array( 'var' => "filesize", 'desc'=> $msg['cms_document_format_data_filesize'], 'children' => array( array( 'var' => "filesize.human", 'desc'=> $msg['cms_document_format_data_filesize_human'] ), array( 'var' => "filesize.value", 'desc'=> $msg['cms_document_format_data_filesize_value'] ) ) ); $format_datas[] = array( 'var' => "url", 'desc'=> $msg['cms_document_format_data_url'] ); $format_datas[] = array( 'var' => "create_date", 'desc'=> $msg['cms_document_format_data_create_date'] ); $format_datas[] = array( 'var' => "thumbnails_url", 'desc'=> $msg['cms_document_format_data_thumbnails_url'] ); $format_datas[] = array( 'var' => "collection", 'desc'=> $msg['cms_document_format_data_collection'], 'children' => array( array( 'var' => "collection.id", 'desc'=> $msg['cms_document_format_data_collection_id'] ), array( 'var' => "collection.name", 'desc'=> $msg['cms_document_format_data_collection_name'] ), array( 'var' => "collection.description", 'desc'=> $msg['cms_document_format_data_collection_description'] ) ) ); return $format_datas; } public function delete_use(){ global $used; $elem =array(); for($i=0 ; $i $elem){ //TODO, vérifier utilisation du document dans l'association $query = "delete from cms_documents_links where document_link_type_object = '".$type."' and document_link_num_object in (".implode(",",$elem).") and document_link_num_document = ".$this->id; $result = pmb_mysql_query($query); if(!$result) return false; } return true; } }