fetch_datas(); } protected function fetch_datas(){ $this->collections=array(); $query = "select id_collection from cms_collections order by collection_title asc"; $result = mysql_query($query); if(mysql_num_rows($result)){ while($row = mysql_fetch_object($result)){ $this->collections[] = new cms_collection($row->id_collection); } } } public function get_table($form_link=""){ global $msg; if(!$form_link){ $form_link="./cms.php?categ=collection&sub=collection&action=edit"; } $table = " "; for($i=0 ; $icollections) ; $i++){ $table.=" "; } $table.="
".$msg['cms_collection_title']." ".$msg['cms_collection_description']." ".$msg['cms_collection_nb_doc']."
".htmlentities($this->collections[$i]->title,ENT_QUOTES,$charset)." ".htmlentities($this->collections[$i]->description,ENT_QUOTES,$charset)." ".htmlentities($this->collections[$i]->nb_doc,ENT_QUOTES,$charset)." collections[$i]->id."'\" value='".htmlentities($msg['cms_collection_edit_document'],ENT_QUOTES,$charset)."'/>
 
"; return $table; } public function process($action=""){ global $id; switch($action){ case "edit" : $collection = new cms_collection($id); print $collection->get_form(); break; case "delete" : $collection = new cms_collection($id); $collection->delete(); $this->fetch_datas(); print $this->get_table(); break; case "save" : $collection = new cms_collection(); $collection->save_form(); $this->fetch_datas(); print $this->get_table(); break; case "list" : default : print $this->get_table(); break; } } public function get_documents_form($selected=array()){ global $msg,$charset; $list ="
 

".htmlentities($msg['cms_documents_add'])."

"; foreach($this->collections as $collection){ $coll_form = "
 
"; $coll_form = $collection->get_documents_form($selected); $coll_form.= "
 
"; $list.=gen_plus('collection'.$collection->id,$collection->title." (".$collection->nb_doc." ".$msg['cms_document'].")",$coll_form); } return $list; } } class cms_collection extends cms_root{ public $id=0; public $title =""; public $description = ""; public $num_parent = 0; public $num_storage = 0; public $nb_doc=0; public $documents =array(); public function __construct($id=0){ $this->id = $id*1; $this->fetch_datas_cache(); } protected function fetch_datas_cache(){ if($tmp=cms_cache::get_at_cms_cache($this)){ $this->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; } } public function fetch_datas(){ $query = "select id_collection,collection_title, collection_description, collection_num_parent, collection_num_storage, count(id_document) as nb_doc from cms_collections left join cms_documents on document_type_object='collection' and document_num_object = id_collection where id_collection = ".$this->id." group by id_collection"; $result = mysql_query($query); if(mysql_num_rows($result)){ $row = mysql_fetch_object($result); $this->id = $row->id_collection; $this->title = $row->collection_title; $this->description = $row->collection_description; $this->num_parent = $row->collection_num_parent; $this->num_storage = $row->collection_num_storage; $this->nb_doc = $row->nb_doc; }else{ $this->id = 0; $this->title = ""; $this->description = ""; $this->num_parent = 0; $this->nb_doc = 0; } } public function get_form($form_link=""){ global $cms_collection_form; global $msg,$charset; if(!$form_link){ $form_link="./cms.php?categ=collection&sub=collection&action=save"; } //lien pour la soumission du formulaire $form = str_replace("!!action!!",$form_link,$cms_collection_form); //id $form = str_replace("!!id!!",htmlentities($this->id,ENT_QUOTES,$charset), $form); //titre $form = str_replace("!!label!!",htmlentities($this->title,ENT_QUOTES,$charset), $form); //description $form = str_replace("!!comment!!",htmlentities($this->description,ENT_QUOTES,$charset), $form); //bouton supprimer if($this->id){ $form = str_replace("!!form_title!!",$msg['cms_collection_edit'],$form); $form = str_replace("!!bouton_supprimer!!","",$form); $form.= confirmation_delete($form_link); }else{ $form = str_replace("!!form_title!!",$msg['cms_collection_add'],$form); $form = str_replace("!!bouton_supprimer!!","", $form); } $storages = new storages(); $form=str_replace("!!storage_form!!",$storages->get_item_form($this->num_storage),$form); return $form; } public function save_form(){ global $cms_collection_id,$cms_collection_title,$cms_collection_description,$cms_collection_num_parent,$storage_method; $this->id = $cms_collection_id*1; $this->title= $cms_collection_title; $this->description = $cms_collection_description; $this->num_parent = $cms_collection_num_parent; $this->num_storage = $storage_method; if($this->id){ $query = "update cms_collections set "; $clause = "where id_collection = ".$this->id; }else{ $query = "insert into cms_collections set "; $clause = ""; } $query.=" collection_title = '".addslashes($this->title)."', collection_description = '".addslashes($this->description)."', collection_num_parent = '".addslashes($this->num_parent)."', collection_num_storage = '".addslashes($this->num_storage)."'"; $result = mysql_query($query.$clause); if(!$this->id &&$result){ $this->id = mysql_insert_id(); } // $storages = new storages(); // $storages->save_form("collection",$this->id); } public function delete(){ global $msg; //on commence par vérifier si on a des documents dans la collection $query = "select id_document from cms_documents where document_type_object = 'collection' and document_num_object='".$this->id."'"; $result = mysql_query($query); if(mysql_num_rows($result)){ //oui, on affiche une erreur error_message($msg['540'], $msg['cms_collection_cant_delete_with_documents']); }else{ $query = "delete from cms_collections where id_collection = ".$this->id; $result = mysql_query($query); if($result) { return true; } } return false; } public function get_documents(){ $this->documents =array(); $query = "select id_document from cms_documents where document_type_object = 'collection' and document_num_object='".$this->id."'"; $result = mysql_query($query); if(mysql_num_rows($result)){ while($row = mysql_fetch_object($result)){ $this->documents[] = new cms_document($row->id_document); } } } public function get_documents_list(){ global $msg,$charset; $this->get_documents(); $list = "
"; foreach($this->documents as $document){ $list.= $document->get_item_render("openEditDialog"); } $list.= "

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

"; return $list; } public function get_documents_form($used){ global $msg,$charset; $this->get_documents(); $form = "
"; foreach($this->documents as $document){ if(in_array($document->id,$used)){ $selected = true; }else{ $selected = false; } $form.=$document->get_item_form($selected); } $form.="

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

"; return $form; } public function add_document($infos,$get_item_render=true,$from=''){ $result = ""; $query = "insert into cms_documents set document_title = '".addslashes($infos['title'])."', document_filename = '".addslashes($infos['filename'])."', document_mimetype = '".addslashes($infos['mimetype'])."', document_filesize = '".addslashes($infos['filesize'])."', document_vignette = '".addslashes($infos['vignette'])."', document_url = '".addslashes($infos['url'])."', document_path = '".addslashes($infos['path'])."', document_create_date = '".addslashes($infos['create_date'])."', document_num_storage = ".($infos['num_storage']*1).", document_type_object = 'collection', document_num_object = ".$this->id." "; if(mysql_query($query)){ if($get_item_render){ $document = new cms_document(mysql_insert_id()); $document->regen_vign(); if($from == "form"){ $result = $document->get_item_form(true); }else{ $result = $document->get_item_render(); } }else{ $result = true; } }else{ $result = false; } return $result; } public function get_infos(){ return array( 'id' => $this->id, 'title' => $this->title, 'description' => $this->description ); } } //TODO AR