explnum_id = $id+0; $this->explnum_notice = $id_notice+0; $this->explnum_bulletin = $id_bulletin+0; $this->fetch_data(); } protected function init_repertoire() { $req = "select repertoire_id, repertoire_nom, repertoire_path from upload_repertoire, users where repertoire_id=deflt_upload_repertoire and username='" . SESSlogin . "'"; $res = pmb_mysql_query($req); if (pmb_mysql_num_rows($res)) { $item = pmb_mysql_fetch_object($res); $this->explnum_rep_nom = $item->repertoire_nom; $this->explnum_rep_path = $item->repertoire_path; $this->explnum_repertoire = $item->repertoire_id; } else { $this->explnum_rep_nom = ''; $this->explnum_rep_path = ''; $this->explnum_repertoire = 0; } } protected function fetch_data() { global $pmb_indexation_docnum_default, $deflt_explnum_statut, $deflt_lenders; $this->explnum_nom = ''; $this->explnum_mimetype = ''; $this->explnum_url = ''; $this->explnum_data = ''; $this->explnum_vignette = ''; $this->explnum_statut = '0'; $this->init_repertoire(); $this->explnum_index = ($pmb_indexation_docnum_default ? 'checked' : ''); $this->explnum_path = ''; $this->explnum_nomfichier = ''; $this->explnum_extfichier = ''; $this->explnum_location = ''; $this->explnum_docnum_statut = ($deflt_explnum_statut ? $deflt_explnum_statut : '1'); $this->lenders = array(0 => $deflt_lenders); $this->explnum_create_date = '0000-00-00 00:00:00'; $this->explnum_update_date = '0000-00-00 00:00:00'; $this->explnum_file_size = 0; $this->unzipped_files = array(); if ($this->explnum_id) { $requete = "SELECT explnum_id, explnum_notice, explnum_bulletin, explnum_nom, explnum_mimetype, explnum_extfichier, explnum_url, explnum_data, explnum_vignette, explnum_statut, explnum_index_sew, explnum_index_wew, explnum_repertoire, explnum_nomfichier, explnum_path, repertoire_nom, repertoire_path, group_concat(num_location SEPARATOR ',') as loc, explnum_docnum_statut, explnum_signature, explnum_create_date, explnum_update_date, explnum_file_size FROM explnum left join upload_repertoire on explnum_repertoire=repertoire_id left join explnum_location on num_explnum=explnum_id where explnum_id='".$this->explnum_id."' group by explnum_id"; $result = pmb_mysql_query($requete); if (pmb_mysql_num_rows($result)) { $item = pmb_mysql_fetch_object($result); $this->explnum_notice = $item->explnum_notice; $this->explnum_bulletin = $item->explnum_bulletin; $this->explnum_nom = $item->explnum_nom; $this->explnum_mimetype = $item->explnum_mimetype; $this->explnum_url = $item->explnum_url; $this->explnum_data = $item->explnum_data; $this->explnum_vignette = $item->explnum_vignette; $this->explnum_statut = $item->explnum_statut; $this->explnum_index_wew = $item->explnum_index_wew; $this->explnum_index_sew = $item->explnum_index_sew; $this->explnum_index = (($item->explnum_index_wew || $item->explnum_index_sew || $pmb_indexation_docnum_default) ? 'checked' : ''); $this->explnum_repertoire = $item->explnum_repertoire; $this->explnum_path = $item->explnum_path; $this->explnum_rep_nom = $item->repertoire_nom; $this->explnum_rep_path = $item->repertoire_path; $this->explnum_nomfichier = $item->explnum_nomfichier; $this->explnum_extfichier = $item->explnum_extfichier; $this->explnum_location = $item->loc ? explode(",", $item->loc) : ''; $this->explnum_docnum_statut = $item->explnum_docnum_statut; $this->explnum_signature = $item->explnum_signature; $this->explnum_create_date = $item->explnum_create_date; $this->explnum_update_date = $item->explnum_update_date; $this->explnum_file_size = $item->explnum_file_size; $this->lenders = array(); $query = 'select explnum_lender_num_lender from explnum_lenders where explnum_lender_num_explnum=' . $this->explnum_id; $result_lender = pmb_mysql_query($query); if (pmb_mysql_num_rows($result_lender)) { while ( $lender = pmb_mysql_fetch_object($result_lender) ) { $this->lenders[] = $lender->explnum_lender_num_lender; } } } } } /* * Construction du formulaire */ public function fill_form(&$form, $action, $suppr = '') { global $charset; global $msg, $lang; global $pmb_scan_pmbws_client_url, $pmb_scan_pmbws_url; global $pmb_indexation_docnum, $pmb_explnum_statut; global $b_mimetype; global $pmb_docnum_in_directory_allow, $pmb_docnum_in_database_allow; global $explnum_id; global $pmb_diarization_docnum; global $base_path; global $thesaurus_concepts_active; global $pmb_type_audit; $form = str_replace('!!action!!', $action, $form); $form = str_replace('!!explnum_id!!', $this->explnum_id, $form); $form = str_replace('!!bulletin!!', $this->explnum_bulletin, $form); $form = str_replace('!!notice!!', $this->explnum_notice, $form); $form = str_replace('!!nom!!', htmlentities($this->explnum_nom, ENT_QUOTES, $charset), $form); $form = str_replace('!!url!!', htmlentities($this->explnum_url, ENT_QUOTES, $charset), $form); if($this->explnum_id && $this->explnum_nomfichier) { $form = str_replace('!!disabled_url!!', "disabled='disabled' placeholder='".htmlentities($msg['explnum_url_associated_already'], ENT_QUOTES, $charset)."'", $form); } else { $form = str_replace('!!disabled_url!!', "", $form); } // Gestion de l'interface d'indexation if ($pmb_indexation_docnum) { $checkbox = "
explnum_index />
"; if ($this->explnum_index_sew != '' && $this->explnum_index_wew != '') { $fct = " "; $form = str_replace("!!submit_action!!", 'return suppr_index(this)', $form); } else { $fct = ""; $form = str_replace("!!submit_action!!", "return testing_file(" . $this->explnum_id . ");", $form); } $form = str_replace('!!ck_indexation!!', $checkbox . $fct, $form); } else { $form = str_replace("!!ck_indexation!!", "", $form); $form = str_replace("!!submit_action!!", "return testing_file(" . $this->explnum_id . ");", $form); } // Gestion de l'interface de segmentation if ($pmb_diarization_docnum) { $checkbox = "
"; $form = str_replace('!!ck_diarization!!', $checkbox, $form); } else { $form = str_replace("!!ck_diarization!!", "", $form); } // Gestion du scanner if (($pmb_scan_pmbws_client_url) && ($pmb_scan_pmbws_url)) { $scan_addon = " "; $form = str_replace('', $scan_addon, $form); } // Ajout du bouton d'association s'il y a des segments en base $associer = ""; $fct = ""; if ($this->explnum_id) { $nb = 0; $query = "select count(*) as nb from explnum_segments where explnum_segment_explnum_num = " . $this->explnum_id; $result = pmb_mysql_query($query); if ($result && pmb_mysql_num_rows($result)) { $nb = pmb_mysql_fetch_object($result)->nb; } if ($nb > 0) { $associer = "explnum_id . "';\" />"; if ($pmb_diarization_docnum) { // On ajoute une confirmation pour une deuxième segmentation => perte des associations $fct = ""; } } } $form = str_replace("!!associate_speakers!!", $associer, $form); $form = str_replace("!!fct_conf_diarize_again!!", $fct, $form); // Champs persos $this->get_p_perso(); $perso = ''; if (!$this->p_perso->no_special_fields) { $perso_ = $this->p_perso->show_editable_fields($this->explnum_id); //-----------------------------------------------LLIUREX CONVOCATORIA----------------------------- $c='Convoca'; for($i = 0; $i < count($perso_["FIELDS"]); $i++) { if (($i == count($perso_["FIELDS"]) - 1) && ($i % 2 == 0)) $element_class = 'row'; else $element_class = 'colonne2'; $p = $perso_["FIELDS"][$i]; if (strncmp($p["NAME"],$c,7)==0){ $perso .= "
" . $p["COMMENT_DISPLAY"] . "
" . $p["AFF"] . "
\n"; }else{ $perso .= "
" . $p["COMMENT_DISPLAY"] . "
" . $p["AFF"] . "
\n"; } //--------------------------------------------------------FIN LLIUREX CONVOCATORIA------------------------------ } $perso = $perso_["CHECK_SCRIPTS"] . "\n" . $perso; } else { $perso = "\n\n"; } $form = str_replace("!!champs_perso!!", $perso, $form); $form = str_replace("!!rights_form!!", $this->get_rights_form(), $form); // Ajout du bouton supprimer si modification if ($this->explnum_id && $suppr) { $supprimer = " "; } else { $supprimer = ""; } $form = str_replace('!!supprimer!!', $supprimer, $form); // Gestion du statut de notice if ($pmb_explnum_statut == '1') { $explnum_statut_form = " explnum_statut == '1') $explnum_statut_form .= "checked='checked' "; $explnum_statut_form .= "/> "; $form = str_replace('', $explnum_statut_form, $form); } // Conserver la vignette if ($this->explnum_vignette) $form = str_replace('!!vignette_existante!!', "  ", $form); else $form = str_replace('!!vignette_existante!!', '', $form); global $_mimetypes_bymimetype_; create_tableau_mimetype(); $selector_mimetype = " "; $form = str_replace('!!mimetype_list!!', $selector_mimetype, $form); // Intégration de la gestion de l'interface de l'upload if ($pmb_docnum_in_directory_allow) { $div_up = "
"; if ($pmb_docnum_in_database_allow) $div_up .= " "; $div_up .= "
"; $form = str_replace('!!div_upload!!', $div_up, $form); $up = new upload_folder($this->explnum_repertoire); // $nom_chemin = ($up->isHashing() ? $this->explnum_rep_nom : $this->explnum_rep_nom.$this->explnum_path); $nom_chemin = $this->explnum_rep_nom; if ($nom_chemin) { if ($up->isHashing()) { $nom_chemin .= "/"; } else { $nom_chemin .= ($this->explnum_path === '' ? "/" : $this->explnum_path); } } $form = str_replace('!!path!!', htmlentities($nom_chemin, ENT_QUOTES, $charset), $form); $form = str_replace('!!id_rep!!', htmlentities($this->explnum_repertoire, ENT_QUOTES, $charset), $form); if ($this->explnum_rep_nom || $this->isEnUpload()) { $form = str_replace('!!check_base!!', '', $form); $form = str_replace('!!check_up!!', "checked='checked'", $form); } else { $form = str_replace('!!check_base!!', "checked='checked'", $form); $form = str_replace('!!check_up!!', '', $form); } } else { $form = str_replace('!!div_upload!!', '', $form); } // Ajout du selecteur de localisation if ($explnum_id) { if (! $this->explnum_location) { $requete = "select idlocation from docs_location"; $res = pmb_mysql_query($requete); $i = 0; while ( $row = pmb_mysql_fetch_array($res) ) { $liste_id[$i] = $row["idlocation"]; $i++; } } else { $liste_id = $this->explnum_location; } } else { global $deflt_docs_location; $liste_id[0] = $deflt_docs_location; } $docloc = new docs_location(); $selector_location = $docloc->gen_multiple_combo($liste_id); $form = str_replace('!!location_explnum!!', "
" . $selector_location, $form); $form = str_replace('!!lenders!!', lender::gen_multiple_combo_box($this->lenders), $form); // statut $select_statut = gen_liste_multiple("select id_explnum_statut, gestion_libelle from explnum_statut order by 2", "id_explnum_statut", "gestion_libelle", "id_explnum_statut", "f_explnum_statut", "", $this->explnum_docnum_statut, "", "", "", "", 0); $form = str_replace('!!statut_list!!', $select_statut, $form); $explnum_licence_selector = explnum_licence::get_licence_selector(explnum_licence::get_explnum_licence_profiles($this->explnum_id)); if ($explnum_licence_selector) { $explnum_licence_selector = "
".$explnum_licence_selector."
 
"; } $form = str_replace('!!explnum_licence_selectors!!', $explnum_licence_selector, $form); // Indexation concept if ($thesaurus_concepts_active == 1) { $index_concept = new index_concept($this->explnum_id, TYPE_EXPLNUM); $form = str_replace('!!index_concept_form!!', $index_concept->get_form('explnum'), $form); } else { $form = str_replace('!!index_concept_form!!', "", $form); } if($pmb_type_audit && $this->explnum_id) { $form = str_replace('!!link_audit!!', audit::get_dialog_button($this->explnum_id, AUDIT_EXPLNUM), $form); } else { $form = str_replace('!!link_audit!!', '', $form); } } /* * Appel au constructeur du formulaire puis retourne le formulaire créé */ public function explnum_form($action, $annuler = '', $suppr = '') { global $explnum_form; // $action .= '&id='.$this->explnum_id; $this->fill_form($explnum_form, $action, $suppr); // action du bouton annuler if (! $annuler) // default : retour à la liste des exemplaires $annuler = './catalog.php?categ=expl&id=' . $this->id_notice; $explnum_form = str_replace('!!annuler_action!!', $annuler, $explnum_form); // affichage return $explnum_form; } /* * Mise à jour des documents numériques */ public function mise_a_jour($f_notice, $f_bulletin, $f_nom, $f_url, $retour, $conservervignette, $f_statut_chk, $f_explnum_statut, $book_lender_id = array(), $forcage = 0, $f_url_vignette='') { global $multi_ck, $base_path, $iframe; $this->recuperer_explnum($f_notice, $f_bulletin, $f_nom, $f_url, $retour, $conservervignette, $f_statut_chk, $f_explnum_statut, $forcage, $f_url_vignette); if ($multi_ck) { // Gestion multifichier $this->unzip($base_path . "/temp/" . $this->infos_docnum["userfile_moved"]); if (! is_array($this->unzipped_files) || ! count($this->unzipped_files)) { // Si la décompression n'a pas fonctionnée on reprend le fonctionnement normal $this->infos_docnum["nom"] = "-x-x-x-x-"; $this->analyser_docnum(); $this->update(!$iframe); } else { $this->analyse_multifile(); } if (file_exists($base_path . "/temp/" . $this->infos_docnum["userfile_moved"])) unlink($base_path . "/temp/" . $this->infos_docnum["userfile_moved"]); } else { // Gestion normale du fichier $this->analyser_docnum(); $this->update(!$iframe); } if ($f_notice) { // Mise a jour de la table notices_mots_global_index notice::majNoticesMotsGlobalIndex($f_notice, "explnum"); } elseif ($f_bulletin) { // Mise a jour de la table notices_mots_global_index pour toutes les notices en relation avec l'exemplaire $req_maj = "SELECT bulletin_notice,num_notice FROM bulletins WHERE bulletin_id='" . $f_bulletin . "'"; $res_maj = pmb_mysql_query($req_maj); if ($res_maj && pmb_mysql_num_rows($res_maj)) { if ($tmp = pmb_mysql_result($res_maj, 0, 0)) { // Périodique notice::majNoticesMotsGlobalIndex($tmp, "explnum"); } if ($tmp = pmb_mysql_result($res_maj, 0, 1)) { // Notice de bulletin notice::majNoticesMotsGlobalIndex($tmp, "explnum"); } } } if($iframe){ return true; } } /* * Effacement de l'exemplaire numérique */ public function delete() { /** * Publication d'un évenement après la mise à jour */ $evt_handler = events_handler::get_instance(); $event = new event_explnum("explnum", "before_delete"); $event->set_explnum($this); $evt_handler->send($event); if ($this->isEnUpload()) { $up = new upload_folder($this->explnum_repertoire); $chemin = str_replace("//", "/", $this->explnum_rep_path . $this->explnum_path . $this->explnum_nomfichier); $chemin = $up->encoder_chaine($chemin); if (file_exists($chemin)) unlink($chemin); } $requete = "DELETE FROM explnum WHERE explnum_id=" . $this->explnum_id; pmb_mysql_query($requete); audit::delete_audit(AUDIT_EXPLNUM, $this->explnum_id); // on oublie pas la localisation associé $requete = "delete from explnum_location where num_explnum = " . $this->explnum_id; pmb_mysql_query($requete); // Suppression des segments et locuteurs $requete = "delete from explnum_speakers where explnum_speaker_explnum_num = " . $this->explnum_id; pmb_mysql_query($requete); $requete = "delete from explnum_segments where explnum_segment_explnum_num = " . $this->explnum_id; pmb_mysql_query($requete); // Nettoyage demande de numérisation $requete = "delete from scan_request_explnum where scan_request_explnum_num_explnum = " . $this->explnum_id; pmb_mysql_query($requete); // Nettoyage indexation concepts $index_concept = new index_concept($this->explnum_id, TYPE_EXPLNUM); $index_concept->delete(); // Nettoyage des régimes de licence explnum_licence::delete_explnum_licence_profiles($this->explnum_id); // Supression des champs perso $this->get_p_perso(); $this->p_perso->delete_values($this->explnum_id); // On recalcule l'index global pour la notice if ($this->explnum_notice) { // Mise a jour de la table notices_mots_global_index notice::majNoticesMotsGlobalIndex($this->explnum_notice, "explnum"); } elseif ($this->explnum_bulletin) { // Mise a jour de la table notices_mots_global_index pour toutes les notices en relation avec l'exemplaire $req_maj = "SELECT bulletin_notice,num_notice FROM bulletins WHERE bulletin_id='" . $this->explnum_bulletin . "'"; $res_maj = pmb_mysql_query($req_maj); if ($res_maj && pmb_mysql_num_rows($res_maj)) { if ($tmp = pmb_mysql_result($res_maj, 0, 0)) { // Périodique notice::majNoticesMotsGlobalIndex($tmp, "explnum"); } if ($tmp = pmb_mysql_result($res_maj, 0, 1)) { // Notice de bulletin notice::majNoticesMotsGlobalIndex($tmp, "explnum"); } } } } protected function save_lenders() { global $book_lender_id; $query = "delete from explnum_lenders where explnum_lender_num_explnum='" . $this->explnum_id . "'"; pmb_mysql_query($query); if (isset($book_lender_id) && is_array($book_lender_id) && count($book_lender_id)) { if ((count($book_lender_id) == 1) && ($book_lender_id[0] == - 1)) { } else { foreach ($book_lender_id as $lender_id) { $query = 'insert into explnum_lenders set explnum_lender_num_explnum=' . $this->explnum_id . ', explnum_lender_num_lender=' . $lender_id; pmb_mysql_query($query); } } } } /** * On enregistre la ou les localisations */ protected function save_locations() { global $loc_selector; $query = "delete from explnum_location where num_explnum='" . $this->explnum_id . "'"; pmb_mysql_query($query); if(isset($loc_selector)) { if ((count($loc_selector) == 1) && ($loc_selector[0] == - 1)) { } else { for($i = 0; $i < count($loc_selector); $i++) { $req = "replace into explnum_location set num_explnum='" . $this->explnum_id . "', num_location='" . $loc_selector[$i] . "'"; pmb_mysql_query($req); } } } } public function save() { global $id_rep, $up_place; global $gestion_acces_active, $gestion_acces_empr_docnum; global $res_prf, $chk_rights, $prf_rad, $r_rad; global $pmb_diarization_docnum; global $thesaurus_concepts_active; if (empty($this->params["erreur"])) { $update = false; if ($this->explnum_id) { $query = "UPDATE explnum SET "; $limiter = " WHERE explnum_id='".$this->explnum_id."' "; $update = true; } else { $query = "INSERT INTO explnum SET "; $limiter = ""; } $query .= " explnum_notice='".$this->explnum_notice."'"; $query .= ", explnum_bulletin='".$this->explnum_bulletin."'"; $query .= ", explnum_nom='".addslashes($this->explnum_nom)."'"; $query .= ", explnum_url='".$this->explnum_url."'"; $query .= ", explnum_mimetype='".addslashes($this->explnum_mimetype)."'"; $query .= ", explnum_data='".addslashes($this->explnum_data)."'"; $query .= ", explnum_nomfichier='".addslashes($this->explnum_nomfichier)."'"; $query .= ", explnum_extfichier='".addslashes($this->explnum_extfichier)."'"; $query .= ", explnum_vignette='".addslashes($this->explnum_vignette)."'"; $query .= ", explnum_statut='".$this->explnum_statut."'"; $query .= ", explnum_repertoire='".$this->explnum_repertoire."'"; $query .= ", explnum_path='".$this->explnum_path."'"; $query .= ", explnum_docnum_statut='".$this->explnum_docnum_statut."'"; $query .= ", explnum_signature = '".$this->gen_signature()."'". (!$this->explnum_id ? ", explnum_create_date=sysdate() " : "")." , explnum_update_date=sysdate() "; $query.= ", explnum_file_size = '".$this->explnum_file_size."'"; $query .= $limiter; pmb_mysql_query($query); if(!$this->explnum_id) { $this->explnum_id = pmb_mysql_insert_id(); audit::insert_creation (AUDIT_EXPLNUM, $this->explnum_id); } else { audit::insert_modif (AUDIT_EXPLNUM, $this->explnum_id); } $this->save_lenders(); $this->save_locations(); // traitement des droits acces user_docnum if ($gestion_acces_active == 1 && $gestion_acces_empr_docnum == 1) { $ac = new acces(); $dom_3 = $ac->setDomain(3); if ($update) { $dom_3->storeUserRights(1, $this->explnum_id, $res_prf, $chk_rights, $prf_rad, $r_rad); } else { $dom_3->storeUserRights(0, $this->explnum_id, $res_prf, $chk_rights, $prf_rad, $r_rad); } } // Segmentation du document if ($pmb_diarization_docnum) { $this->diarization_docnum(); } $this->get_p_perso(); $this->p_perso->rec_fields_perso($this->explnum_id); // Indexation concepts if ($thesaurus_concepts_active == 1) { $index_concept = new index_concept($this->explnum_id, TYPE_EXPLNUM); $index_concept->save(); } explnum_licence::save_explnum_licence_profiles($this->explnum_id); return true; } else { return false; } } protected function update_explnum_vignette($explnum_vignette) { $query = "update explnum set explnum_vignette='" . addslashes($explnum_vignette) . "' where explnum_id='" . $this->explnum_id . "'"; pmb_mysql_query($query); } /* * Mise à jour de l'exemplaire numérique */ public function update($with_print = true) { global $msg; global $current_module, $pmb_explnum_statut; global $id_rep, $up_place; global $mime_vign; /** * Publication d'un évenement avant la mise à jour */ $evt_handler = events_handler::get_instance(); $event = new event_explnum("explnum", "before_update"); $event->set_explnum($this); $evt_handler->send($event); $update = false; if ($this->explnum_id) { $update = true; } if ($with_print) { print "

" . $msg['explnum_doc_associe'] . "

"; } if (empty($this->params["erreur"])) { $this->explnum_notice = $this->infos_docnum["notice"]+0; $this->explnum_bulletin = $this->infos_docnum["bull"]+0; $this->explnum_nom = stripslashes($this->infos_docnum["nom"]); $this->explnum_url = stripslashes($this->infos_docnum["url"]); if ($this->params["maj_mimetype"]) { $this->explnum_mimetype = stripslashes($this->infos_docnum["mime"]); } if ($this->params["maj_data"]) { if (!isset($this->params["is_upload"]) || !$this->params["is_upload"]) { $this->explnum_data = (isset($this->infos_docnum["contenu"]) ? $this->infos_docnum["contenu"] : ''); } else { $this->explnum_data = ''; } $this->explnum_nomfichier = $this->infos_docnum["userfile_name"]; $this->explnum_extfichier = $this->infos_docnum["userfile_ext"]; } if ($this->params["maj_vignette"] && (!isset($this->params["conservervignette"]) || !$this->params["conservervignette"])) { $this->explnum_vignette = $this->infos_docnum["contenu_vignette"]; } if ($pmb_explnum_statut == '1') { $this->explnum_statut = $this->params["statut"]; } $this->explnum_repertoire = (($up_place) ? $id_rep : 0); $this->explnum_path = $this->infos_docnum["path"]; $this->explnum_docnum_statut = ((isset($this->params["explnum_statut"]) && $this->params["explnum_statut"]) ? $this->params["explnum_statut"] : 1); if ($this->params["maj_data"]) { $this->explnum_file_size = $this->get_file_size(true); } } $saved = $this->save(); if ($saved) { // Indexation du document global $pmb_indexation_docnum; if ($pmb_indexation_docnum) { $vign_index = $this->indexer_docnum(); if (! $mime_vign && (!isset($this->params["conservervignette"]) || !$this->params["conservervignette"]) && (!isset($this->infos_docnum["vignette_name"]) || !$this->infos_docnum["vignette_name"])) { if ($vign_index) { $this->update_explnum_vignette($vign_index); } else { if($this->params["maj_vignette"] && $this->infos_docnum["contenu_vignette"]) { $contenu_vignette = $this->infos_docnum["contenu_vignette"]; } else { $contenu_vignette = construire_vignette("", "", $this->infos_docnum["url"]); } if ($contenu_vignette) { $this->update_explnum_vignette($contenu_vignette); } } } } elseif (! $mime_vign && ! $this->params["conservervignette"] && ! $this->infos_docnum["vignette_name"] && $this->infos_docnum["url"]) { // Si pas d'indexation et que je ne force pas la vignette en fonction du mimetype et si j'ai une url if($this->params["maj_vignette"] && $this->infos_docnum["contenu_vignette"]) { $contenu_vignette = $this->infos_docnum["contenu_vignette"]; } else { $contenu_vignette = construire_vignette("", "", $this->infos_docnum["url"]); } if ($contenu_vignette) { $this->update_explnum_vignette($contenu_vignette); } } /** * Publication d'un évenement après la mise à jour */ $evt_handler = events_handler::get_instance(); $event = new event_explnum("explnum", "after_update"); $event->set_explnum($this); $evt_handler->send($event); // on reaffiche l'ISBD if ($with_print) { print "
" . $msg['maj_encours'] . "
"; } $id_form = md5(microtime()); if (pmb_mysql_error()) { if ($with_print) { echo "MySQL error : " . pmb_mysql_error(); print "
params["retour"] . "\" >
"; print "
"; } exit(); } if ($with_print) { print "
params["retour"] . "\" style=\"display:none\">
"; print ""; } } else { eval("\$bid=\"" . $msg['explnum_erreurupload'] . "\";"); if ($with_print) { print "
" . $bid . "
"; print "
params["retour"] . "\" >
"; } } if ($with_print) { print ""; } } /* * Indexation du document */ public function indexer_docnum() { global $scanned_texte, $ck_index; if (! $this->explnum_id && $ck_index) { $id_explnum = $this->explnum_id; $indexation = new indexation_docnum($id_explnum, $scanned_texte); $indexation->indexer(); } elseif ($this->explnum_id && $ck_index) { $indexation = new indexation_docnum($this->explnum_id, $scanned_texte); $indexation->indexer(); } elseif ($this->explnum_id && ! $ck_index && ($this->explnum_index_sew != '' || $this->explnum_index_wew != '')) { $indexation = new indexation_docnum($this->explnum_id); $indexation->desindexer(); } return isset($indexation) ? $indexation->vignette : ''; } /** * Segmentation du document */ protected function diarization_docnum() { global $ck_diarization; if (in_array($this->infos_docnum['mime'], array( "audio/mpeg", "audio/ogg", "video/mp4", "video/webm" ))) { if ($ck_diarization) { $diarization = new diarization_docnum($this); $diarization->diarize(); } } } public static function clean_explnum_file_name($filename){ $filename = convert_diacrit($filename); $filename = preg_replace('/[^\x20-\x7E]/','_', $filename); $filename = str_replace(',', '_', $filename); return $filename; } /* * Analyse du document */ public function analyser_docnum() { global $path, $id_rep, $up_place, $base_path; $is_upload = false; if (! $this->infos_docnum["nom"]) { if ($this->infos_docnum["userfile_name"]) $this->infos_docnum["nom"] = $this->infos_docnum["userfile_name"]; elseif ($this->infos_docnum["url"]) $this->infos_docnum["nom"] = $this->infos_docnum["url"]; else $this->infos_docnum["nom"] = "-x-x-x-x-"; } $path = stripslashes($path); $upfolder = new upload_folder($id_rep); $chemin = ''; $contenu = ''; if ($this->infos_docnum["fic"]) { $chemin_hasher = ""; $this->infos_docnum["userfile_name"] = static::clean_explnum_file_name($this->infos_docnum["userfile_name"]); if (($up_place && $path != '')) { if ($upfolder->isHashing()) { $rep = $upfolder->hachage($this->infos_docnum["userfile_name"]); @mkdir($rep); $chemin_hasher = $upfolder->formate_path_to_nom($rep); $file_name = $rep . $this->infos_docnum["userfile_name"]; } else { $file_name = $upfolder->formate_nom_to_path($path) . $this->infos_docnum["userfile_name"]; } $chemin = $upfolder->formate_path_to_save($chemin_hasher ? $chemin_hasher : $path); $file_name = $upfolder->encoder_chaine($file_name); $nom_tmp = $this->infos_docnum["userfile_name"]; $continue = true; $compte = 1; do { $query = "select explnum_notice,explnum_id,explnum_bulletin from explnum where explnum_nomfichier = '" . addslashes($nom_tmp) . "' AND explnum_repertoire='" . $id_rep . "' AND explnum_path='" . addslashes($chemin) . "'"; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result) && ((pmb_mysql_result($result, 0, 0) != $this->infos_docnum["notice"]) || (pmb_mysql_result($result, 0, 2) != $this->infos_docnum["bull"]))) { // Si j'ai déjà un document numérique avec ce fichier pour une autre notice je dois le renommer pour ne pas perdre l'ancien if (preg_match("/^(.+)(\..+)$/i", $this->infos_docnum["userfile_name"], $matches)) { $nom_tmp = $matches[1] . "_" . $compte . $matches[2]; } else { $nom_tmp = $this->infos_docnum["userfile_name"] . "_" . $compte; } $compte++; } else { if (pmb_mysql_num_rows($result) && (! $this->explnum_id || ($this->explnum_id != pmb_mysql_result($result, 0, 1)))) { // J'ai déjà ce fichier pour cette notice et je ne suis pas en modification // Je dois enlever l'ancien document numérique pour ne pas l'avoir en double $old_docnum = new explnum(pmb_mysql_result($result, 0, 1)); $old_docnum->delete(); } elseif (pmb_mysql_num_rows($result)) { } $continue = false; } } while ( $continue ); if ($compte != 1) { $this->infos_docnum["userfile_name"] = $nom_tmp; if ($upfolder->isHashing()) { $file_name = $rep . $this->infos_docnum["userfile_name"]; } else { $file_name = $upfolder->formate_nom_to_path($path) . $this->infos_docnum["userfile_name"]; } $file_name = $upfolder->encoder_chaine($file_name); } rename($base_path . '/temp/' . $this->infos_docnum["userfile_moved"], $file_name); $is_upload = true; } else $file_name = $base_path . '/temp/' . $this->infos_docnum["userfile_moved"]; $fp = fopen($file_name, "r"); $contenu = fread($fp, filesize($file_name)); if (! $fp || $contenu == "") { if (!isset($this->params["erreur"])) { $this->params["erreur"] = 0; } $this->params["erreur"]++; } fclose($fp); } // Dans le cas d'une modification, on regarde si il y a eu un déplacement du stockage if ($this->explnum_id) { if ($this->isEnBase() && ($up_place && $path != '')) { $new_path = $this->remove_from_base($path, $upfolder, $id_rep); $contenu = ""; if (! $upfolder->isHashing()) { $chemin = $upfolder->formate_path_to_save($path); } else $chemin = $upfolder->formate_path_to_save($upfolder->formate_path_to_nom($new_path)); $this->params["maj_data"] = true; } elseif ($this->isEnUpload() && (! $up_place)) { $contenu = $this->remove_from_upload(); $id_rep = 0; $path = ""; $this->params["maj_data"] = true; } elseif ($this->isEnUpload() && ($up_place && $path)) { $contenu = ""; $chemin = $this->change_rep_upload($upfolder, $upfolder->formate_nom_to_path($path)); if (! $upfolder->isHashing()) { $chemin = $upfolder->formate_path_to_save($upfolder->formate_path_to_nom($path)); } else $chemin = $upfolder->formate_path_to_save($upfolder->formate_path_to_nom($chemin)); $this->params["maj_data"] = true; } } $this->params["is_upload"] = $is_upload; $this->infos_docnum["contenu"] = $contenu; $this->infos_docnum["path"] = $chemin; if ($this->infos_docnum["userfile_name"] && $this->infos_docnum["userfile_moved"] && file_exists($base_path . '/temp/' . $this->infos_docnum["userfile_moved"])) unlink($base_path . '/temp/' . $this->infos_docnum["userfile_moved"]); if ($this->infos_docnum["vignette_name"]) unlink($base_path . '/temp/' . $this->infos_docnum["vignette_moved"]); if ($this->explnum_id && $this->infos_docnum["userfile_name"] && ($this->infos_docnum["userfile_name"] != $this->explnum_nomfichier)) { $up = new upload_folder($this->explnum_repertoire); $old_file = str_replace('//', '/', $this->explnum_rep_path . $this->explnum_path . $this->explnum_nomfichier); if (file_exists($old_file)) unlink($up->encoder_chaine($old_file)); } } /* * Récupère les informations de l'exemplaire à ajouter à la la notice */ public function recuperer_explnum($f_notice, $f_bulletin, $f_nom, $f_url, $retour, $conservervignette = 0, $f_statut_chk = 0, $f_explnum_statut = 1, $forcage = 0, $f_url_vignette='') { global $scanned_image, $scanned_image_ext, $base_path; global $f_new_name, $mime_vign; $maj_mimetype = 0; $maj_data = 0; $maj_vignette = 0; $fic = 0; $this->infos_docnum = array(); $this->params = array(); create_tableau_mimetype(); $erreur = 0; $userfile_name = $_FILES['f_fichier']['name']; $userfile_temp = $_FILES['f_fichier']['tmp_name']; $userfile_moved = basename($userfile_temp); $vignette_name = $_FILES['f_vignette']['name']; $vignette_temp = $_FILES['f_vignette']['tmp_name']; $vignette_moved = basename($vignette_temp); $userfile_name = preg_replace("/ |'|\\|\"|\//m", "_", $userfile_name); $vignette_name = preg_replace("/ |'|\\|\"|\//m", "_", $vignette_name); $contenu_vignette = ""; $userfile_ext = ''; if ($userfile_name) { $userfile_ext = extension_fichier($userfile_name); } if ($this->explnum_id) { // modification // si $userfile_name est vide on ne fera pas la maj du data if (($scanned_image) || ($userfile_name)) { // Avant tout, y-a-t-il une image extérieure ? if ($scanned_image) { // Si oui ! $tmpid = str_replace(" ", "_", microtime()); $fp = @fopen($base_path . "/temp/scanned_$tmpid." . $scanned_image_ext, "w+"); if ($fp) { fwrite($fp, base64_decode($scanned_image)); $nf = 1; $part_name = "scanned_image_" . $nf; global ${$part_name}; while ( ${$part_name} ) { fwrite($fp, base64_decode(${$part_name})); $nf++; $part_name = "scanned_image_" . $nf; global ${$part_name}; } fclose($fp); $fic = 1; $maj_data = 1; $userfile_name = "scanned_$tmpid." . $scanned_image_ext; $userfile_ext = $scanned_image_ext; $userfile_moved = $userfile_name; $f_url = ""; } else $erreur++; } else if ($userfile_name) { $move_return = true; if (!$forcage) { $move_return = move_uploaded_file($userfile_temp, $base_path . '/temp/' . $userfile_moved); } if ($move_return) { $fic = 1; $f_url = ""; $maj_data = 1; move_uploaded_file($vignette_temp, $base_path . '/temp/' . $vignette_moved); } else { $erreur++; } } $mimetype = trouve_mimetype($userfile_moved, $userfile_ext); if (! $mimetype) $mimetype = "application/data"; $maj_mimetype = 1; if (! $conservervignette && ! $mime_vign) { if (! $f_url_vignette) { $contenu_vignette = construire_vignette($vignette_moved, $userfile_moved); } else { $contenu_vignette = construire_vignette('', '', $f_url_vignette); } } $maj_vignette = 1; } else { if ($vignette_name) { move_uploaded_file($vignette_temp, $base_path . '/temp/' . $vignette_moved); if (! $conservervignette && ! $mime_vign) $contenu_vignette = construire_vignette($vignette_moved, $userfile_moved); $maj_vignette = 1; } elseif($f_url_vignette) { if (! $conservervignette && ! $mime_vign) $contenu_vignette = construire_vignette('', '', $f_url_vignette); $maj_vignette = 1; } if ($f_url) { $mimetype = "URL"; $maj_mimetype = 1; move_uploaded_file($vignette_temp, $base_path . '/temp/' . $vignette_moved); if (!$maj_vignette && ! $conservervignette && ! $mime_vign) $contenu_vignette = construire_vignette($vignette_moved, $userfile_moved); $maj_vignette = 1; $contenu = ""; $maj_data = 1; } //Option "Conserver la vignette existante ?" décochée if(!$conservervignette && !$maj_vignette) { $contenu_vignette = ""; $maj_vignette = 1; } } } else { // creation // Y-a-t-il une image exterieure ? if ($scanned_image) { // Si oui ! $tmpid = str_replace(" ", "_", microtime()); $fp = @fopen($base_path . "/temp/scanned_$tmpid." . $scanned_image_ext, "w+"); if ($fp) { fwrite($fp, base64_decode($scanned_image)); $nf = 1; $part_name = "scanned_image_" . $nf; global ${$part_name}; while ( ${$part_name} ) { fwrite($fp, base64_decode(${$part_name})); $nf++; $part_name = "scanned_image_" . $nf; global ${$part_name}; } fclose($fp); $fic = 1; $maj_data = 1; $userfile_name = "scanned_$tmpid." . $scanned_image_ext; $userfile_ext = $scanned_image_ext; $userfile_moved = $userfile_name; $f_url = ""; } else $erreur++; } else { $move_return = true; if (!$forcage) { $move_return = move_uploaded_file($userfile_temp, $base_path . '/temp/' . $userfile_moved); } if ($move_return) { $fic = 1; $f_url = ""; $maj_data = 1; } elseif (! $f_url) { $erreur++; } } if (! $f_url && ! $fic) $erreur++; if ($f_url) { $mimetype = "URL"; } else { $mimetype = trouve_mimetype($userfile_moved, $userfile_ext); if (! $mimetype) $mimetype = "application/data"; } $maj_mimetype = 1; if (!empty($vignette_moved)) { move_uploaded_file($vignette_temp, $base_path . '/temp/' . $vignette_moved); } if (! $mime_vign) { if (! $f_url_vignette) { $contenu_vignette = construire_vignette($vignette_moved, $userfile_moved); } else { $contenu_vignette = construire_vignette('', '', $f_url_vignette); } } $maj_vignette = 1; } if ($mime_vign && ! $conservervignette) { global $prefix_url_image; if ($prefix_url_image) $tmpprefix_url_image = $prefix_url_image; else $tmpprefix_url_image = "./"; $vignette = $tmpprefix_url_image . "images/mimetype/" . icone_mimetype($mime_vign, ""); $fp = fopen($vignette, "r"); if ($fp) $contenu_vignette = fread($fp, filesize($vignette)); if ($contenu_vignette) $maj_vignette = 1; } // Initialisation des tableaux d'infos $this->infos_docnum["mime"] = (($this->explnum_id && ! $maj_mimetype) ? $this->explnum_mimetype : $mimetype); $this->infos_docnum["nom"] = $f_nom; $this->infos_docnum["notice"] = $f_notice+0; $this->infos_docnum["bull"] = $f_bulletin+0; $this->infos_docnum["url"] = $f_url; $this->infos_docnum["fic"] = $fic; $this->infos_docnum["contenu_vignette"] = $contenu_vignette; $this->infos_docnum["userfile_name"] = (($this->explnum_id && ! $userfile_name) ? $this->explnum_nomfichier : ($f_new_name ? $f_new_name : $userfile_name)); $this->infos_docnum["userfile_ext"] = (($this->explnum_id && ! $userfile_ext) ? $this->explnum_extfichier : $userfile_ext); $this->infos_docnum["userfile_moved"] = $userfile_moved; $this->infos_docnum["vignette_name"] = $vignette_name; $this->infos_docnum["vignette_moved"] = $vignette_moved; $this->params["error"] = $erreur; $this->params["maj_mimetype"] = $maj_mimetype; $this->params["maj_data"] = $maj_data; $this->params["maj_vignette"] = $maj_vignette; $this->params["retour"] = $retour; $this->params["conservervignette"] = $conservervignette; $this->params["statut"] = $f_statut_chk; $this->params["explnum_statut"] = $f_explnum_statut; } /* * Teste si l'exemplaire est stocké en base */ public function isEnBase() { if ($this->explnum_data && ! $this->explnum_repertoire && ! $this->explnum_path) return true; return false; } /* * Teste si l'exemplaire est stocké sur le disque */ public function isEnUpload() { if ($this->explnum_repertoire && $this->explnum_path) return true; return false; } /* * Teste si l'exemplaire est stocké sous forme d'URL */ public function isURL() { if ($this->explnum_url) return true; return false; } /* * Retire l'exemplaire de la base pour le mettre en upload */ public function remove_from_base($chemin, $upfolder, $id_rep) { $content = $this->explnum_data; $chemin_hasher = ""; if ($upfolder->isHashing()) { $rep = $upfolder->hachage($this->explnum_nomfichier); @mkdir($rep); $chemin_hasher = $upfolder->formate_path_to_nom($rep); } $chemin_query = $upfolder->formate_path_to_save($chemin_hasher ? $chemin_hasher : $chemin); $nom_tmp = $this->explnum_nomfichier; $continue = true; $compte = 1; do { $query = "select explnum_notice,explnum_id,explnum_bulletin from explnum where explnum_nomfichier = '" . addslashes($nom_tmp) . "' AND explnum_repertoire='" . $id_rep . "' AND explnum_path='" . addslashes($chemin_query) . "' AND explnum_id<>" . $this->explnum_id; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result)) { // Si j'ai déjà un document numérique avec ce fichier pour une autre notice je dois le renommer pour ne pas perdre l'ancien if (preg_match("/^(.+)(\..+)$/i", $this->explnum_nomfichier, $matches)) { $nom_tmp = $matches[1] . "_" . $compte . $matches[2]; } else { $nom_tmp = $this->explnum_nomfichier . "_" . $compte; } $compte++; } else { $continue = false; } } while ( $continue ); // on renomme aussi le champ dans la table $this->infos_docnum["userfile_name"] = $nom_tmp; $new_path = ""; if ($upfolder->isHashing()) { $hashname = $upfolder->hachage($nom_tmp); $file_path = $upfolder->encoder_chaine($hashname . $nom_tmp); if (! is_dir($hashname)) mkdir($hashname); $new_path = $upfolder->encoder_chaine($hashname); } else { $file_path = $upfolder->encoder_chaine($upfolder->formate_nom_to_path($chemin) . $nom_tmp); } file_put_contents($file_path, $content); return $new_path; } /* * Supprime le fichier uploadé pour le mettre en base */ public function remove_from_upload() { $up = new upload_folder($this->explnum_repertoire); $contenu = ''; $path = $up->repertoire_path . $this->explnum_path . $this->explnum_nomfichier; $path = str_replace('//', '/', $path); $path = $up->encoder_chaine($path); if (is_file($path)) { $contenu = file_get_contents($path); unlink($path); } return $contenu; } /* * Permet le changement de répertoire d'upload */ public function change_rep_upload($rep, $new_path) { $nom_fich = ($this->explnum_nomfichier != "" ? $this->explnum_nomfichier : $this->explnum_nom); $old_path = $this->explnum_rep_nom . $this->explnum_path; $old_path = str_replace('//', '/', $old_path); if ($rep->isHashing()) { $new_rep = $rep->hachage($nom_fich); if (! is_dir($new_rep)) mkdir($new_rep); } else { $new_rep = $new_path; } $up = new upload_folder($this->explnum_repertoire); $old_path = $up->formate_nom_to_path($old_path); $ancien_fichier = $up->encoder_chaine($old_path . $nom_fich); $nouveau_fichier = $rep->encoder_chaine($new_rep . $nom_fich); if (! file_exists($nouveau_fichier) && ($nouveau_fichier != $ancien_fichier)) { rename($ancien_fichier, $nouveau_fichier); if (file_exists($ancien_fichier)) unlink($ancien_fichier); $nom_rep = $new_path; } return (isset($nom_rep) && $nom_rep ? $nom_rep : $new_rep); } /* * Copie dans un répertoire */ public function copy_to($new_dir_id = 0, $rename = false) { $ret = false; $old_dir_id = $this->explnum_repertoire; if ($old_dir_id && $new_dir_id) { $old_dir = new upload_folder($old_dir_id); $new_dir = new upload_folder($new_dir_id); $old_file_name = ($this->explnum_nomfichier != '' ? $this->explnum_nomfichier : $this->explnum_nom); if ($rename) { $new_file_name = $this->rename(); } else { $new_file_name = $old_file_name; } $old_path = $old_dir->repertoire_path . $this->explnum_path; $old_path = str_replace('//', '/', $old_path); if ($new_dir->isHashing()) { $new_sub_dir = $new_dir->hachage($new_file_name); if (! is_dir($new_sub_dir)) mkdir($new_sub_dir); $new_path = $new_dir->repertoire_path . $new_sub_dir; } else { $new_path = $new_dir->repertoire_path; } $new_path = str_replace('//', '/', $new_path); $old_file = $old_dir->encoder_chaine($old_path . $old_file_name); $new_file = $new_dir->encoder_chaine($new_path . $new_file_name); if (file_exists($new_file)) { $new_file_name = $this->rename(); $new_file = $new_dir->encoder_chaine($new_path . $new_file_name); } if (! file_exists($new_file)) { if (copy($old_file, $new_file)) { $ret = true; } } } else if ($new_dir_id) { $new_dir = new upload_folder($new_dir_id); $old_file_name = ($this->explnum_nomfichier != '' ? $this->explnum_nomfichier : $this->explnum_nom); if ($rename) { $new_file_name = $this->rename(); } else { $new_file_name = $old_file_name; } if ($new_dir->isHashing()) { $new_sub_dir = $new_dir->hachage($new_file_name); if (! is_dir($new_sub_dir)) mkdir($new_sub_dir); $new_path = $new_dir->repertoire_path . $new_sub_dir; } else { $new_path = $new_dir->repertoire_path; } $new_path = str_replace('//', '/', $new_path); $new_file = $new_dir->encoder_chaine($new_path . $new_file_name); if (file_exists($new_file)) { $new_file_name = $this->rename(); $new_file = $new_dir->encoder_chaine($new_path . $new_file_name); } if (! file_exists($new_file)) { if (file_put_contents($new_file, $this->explnum_data)) { $ret = true; } } } return ($ret) ? $new_file : $ret; } // fournit un nom de fichier unique public function rename() { $new_file_name = 'file_' . md5(microtime()) . (($this->explnum_extfichier) ? '.' . $this->explnum_extfichier : ''); return $new_file_name; } public static function static_rename($ext = '') { $new_file_name = 'file_' . md5(microtime()) . (($ext) ? '.' . $ext : ''); return $new_file_name; } /* * Fonction qui dézippe dans le bon répertoire */ public function unzip($filename) { global $up_place, $path, $id_rep, $charset, $base_path; $zip = new zip($filename); $zip->readZip(); $cpt = 0; if ($up_place && $path != '') { $up = new upload_folder($id_rep); } if (is_array($zip->entries) && count($zip->entries)) { foreach ( $zip->entries as $file ) { $file_name_for_get_file_content = $file['fileName']; $encod = mb_detect_encoding($file['fileName'], "UTF-8,ISO-8859-1"); if ($encod && ($encod == 'UTF-8') && ($charset == "iso-8859-1")) { $file['fileName'] = utf8_decode($file['fileName']); } elseif ($encod && ($encod == 'ISO-8859-1') && ($charset == "utf-8")) { $file['fileName'] = utf8_encode($file['fileName']); } $file['fileName'] = static::clean_explnum_file_name($file['fileName']); if ($up_place && $path != '') { $chemin = $path; if ($up->isHashing()) { $hashname = $up->hachage($file['fileName']); @mkdir($hashname); $filepath = $up->encoder_chaine($hashname . $file['fileName']); } else $filepath = $up->encoder_chaine($up->formate_nom_to_path($chemin) . $file['fileName']); // On regarde si le fichier existe avant de le créer $continue = true; $compte = 0; $filepath_tmp = $filepath; do { if (! file_exists($filepath_tmp)) { $continue = false; } else { $compte++; if (preg_match("/^(.+)(\..+)$/i", $filepath, $matches)) { $filepath_tmp = $matches[1] . "_" . $compte . $matches[2]; } else { $filepath_tmp = $filepath . "_" . $compte; } } } while ( $continue ); if ($compte) { $filepath = $filepath_tmp; } $fh = fopen($filepath, 'w+'); fwrite($fh, $zip->getFileContent($file_name_for_get_file_content)); fclose($fh); if ($compte) { if (preg_match("/^(.+)(\..+)$/i", $file['fileName'], $matches)) { $file['fileName'] = $matches[1] . "_" . $compte . $matches[2]; } else { $file['fileName'] = $file['fileName'] . "_" . $compte; } } } else { $chemin = $base_path . '/temp/' . $file['fileName']; $fh = fopen($chemin, 'w'); fwrite($fh, $zip->getFileContent($file['fileName'])); $base = true; } $this->unzipped_files[$cpt]['chemin'] = $chemin; $this->unzipped_files[$cpt]['nom'] = $file['fileName']; $this->unzipped_files[$cpt]['base'] = $base; $cpt++; } } } /* * Gestion de l'ajout multifichier */ public function analyse_multifile() { global $id_rep; create_tableau_mimetype(); $repup = new upload_folder($id_rep); if (is_array($this->unzipped_files) && !empty($this->unzipped_files)) { $nb_unzipped_files = count($this->unzipped_files); for ($i = 0; $i < $nb_unzipped_files; $i++) { $this->infos_docnum['userfile_name'] = $this->unzipped_files[$i]['nom']; if ($repup->isHashing()) { $hashname = $repup->hachage($this->infos_docnum['userfile_name']); $chemin = $repup->formate_path_to_save($repup->formate_path_to_nom($hashname)); } else $chemin = $repup->formate_path_to_save($this->unzipped_files[$i]["chemin"]); if ($this->unzipped_files[$i]['base']) { $this->infos_docnum['contenu'] = file_get_contents($this->unzipped_files[$i]['chemin']); $this->infos_docnum['path'] = ''; } else { $this->infos_docnum['contenu'] = ''; $this->infos_docnum['path'] = $chemin; } $ext = ''; if ($this->infos_docnum['userfile_name']) { $ext = extension_fichier($this->infos_docnum['userfile_name']); $this->infos_docnum['userfile_ext'] = $ext; } if ($this->unzipped_files[$i]['base']) { $this->infos_docnum['contenu_vignette'] = construire_vignette("", $this->infos_docnum['userfile_name']); } else { if ($repup->isHashing()) $this->infos_docnum['contenu_vignette'] = construire_vignette("", $repup->encoder_chaine($hashname . $this->infos_docnum['userfile_name'])); else $this->infos_docnum['contenu_vignette'] = construire_vignette("", $repup->encoder_chaine($repup->formate_nom_to_path($this->unzipped_files[$i]['chemin']) . $this->infos_docnum['userfile_name'])); } $mimetype = trouve_mimetype($this->unzipped_files[$i]['chemin'], $this->infos_docnum['userfile_ext']); if (! $mimetype) $mimetype = "application/data"; $this->infos_docnum['mime'] = $mimetype; if ($this->unzipped_files[$i]['base']) { unlink($this->unzipped_files[$i]['chemin']); } if ($mimetype == 'URL') { $this->infos_docnum['url'] = $this->unzipped_files[$i]['nom']; $this->infos_docnum['nom'] = ''; } else { $this->infos_docnum['nom'] = $this->unzipped_files[$i]['nom']; $this->infos_docnum['url'] = ''; } $this->update(); $this->explnum_id = 0; } } } public function get_file_from_temp($filename, $name, $upload_place, $integrator_docnum = false) { global $base_path; global $ck_index; global $id_rep, $up_place; global $pmb_indexation_docnum_default; $up_place = $upload_place; create_tableau_mimetype(); if (!isset($ck_index)) { $ck_index = $pmb_indexation_docnum_default; } // Initialisation des tableaux d'infos $this->infos_docnum = $this->params = array(); $this->infos_docnum["mime"] = trouve_mimetype($filename, extension_fichier($name)); if ($integrator_docnum) { $this->infos_docnum["nom"] = $filename; } else { $this->infos_docnum["nom"] = substr($name, 0, strrpos($name, ".")); if (! $this->infos_docnum["nom"]) { $this->infos_docnum["nom"] = $name; } } $this->infos_docnum["notice"] = $this->explnum_notice; $this->infos_docnum["bull"] = $this->explnum_bulletin; $this->infos_docnum["url"] = ""; $this->infos_docnum["fic"] = false; if ($this->infos_docnum["mime"] != 'text/plain') { $this->infos_docnum["contenu_vignette"] = construire_vignette('', substr($filename, strrpos($filename, "/"))); } $this->infos_docnum["userfile_name"] = static::clean_explnum_file_name($name); $this->infos_docnum["userfile_ext"] = extension_fichier($name); if ($up_place && $id_rep != 0) { $upfolder = new upload_folder($id_rep); $chemin_hasher = "/"; if ($upfolder->isHashing()) { $rep = $upfolder->hachage($this->infos_docnum["userfile_name"]); @mkdir($rep); $chemin_hasher = $upfolder->formate_path_to_nom($rep); $file_name = $rep . $this->infos_docnum["userfile_name"]; $chemin = $upfolder->formate_path_to_save($chemin_hasher); } else { $file_name = $upfolder->get_path($this->infos_docnum["userfile_name"]) . $this->infos_docnum["userfile_name"]; $chemin = $upfolder->formate_path_to_save("/"); } $this->infos_docnum["path"] = $chemin; $file_name = $upfolder->encoder_chaine($file_name); if (! $this->explnum_nomfichier) { // Si je suis en création de fichier numérique $nom_tmp = $this->infos_docnum["userfile_name"]; $continue = true; $compte = 1; do { $query = "select explnum_notice,explnum_id from explnum where explnum_nomfichier = '" . addslashes($nom_tmp) . "' AND explnum_repertoire='" . $id_rep . "' AND explnum_path='" . addslashes($this->infos_docnum["path"]) . "'"; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result) && (pmb_mysql_result($result, 0, 0) != $this->infos_docnum["notice"])) { // Si j'ai déjà un document numérique avec ce fichier pour une autre notice je dois le renommer pour ne pas perdre l'ancien if (preg_match("/^(.+)(\..+)$/i", $this->infos_docnum["userfile_name"], $matches)) { $nom_tmp = $matches[1] . "_" . $compte . $matches[2]; } else { $nom_tmp = $this->infos_docnum["userfile_name"] . "_" . $compte; } $compte++; } else { if (pmb_mysql_num_rows($result)) { // J'ai déjà ce fichier pour cette notice // Je dois enlever l'ancien document numérique pour ne pas l'avoir en double $old_docnum = new explnum(pmb_mysql_result($result, 0, 1)); $old_docnum->delete(); } else { } $continue = false; } } while ( $continue ); if ($compte != 1) { $this->infos_docnum["userfile_name"] = $nom_tmp; if ($upfolder->isHashing()) { $file_name = $rep . $this->infos_docnum["userfile_name"]; } else { $file_name = $upfolder->get_path($this->infos_docnum["userfile_name"]) . $this->infos_docnum["userfile_name"]; } $file_name = $upfolder->encoder_chaine($file_name); } else { } } else { } rename($filename, $file_name); } else { // enregistrement en base $this->infos_docnum["contenu"] = file_get_contents($filename); } $this->params["maj_mimetype"] = true; $this->params["maj_data"] = true; $this->params["maj_vignette"] = true; } public function get_file_content() { $data = ""; /** * Publication d'un évenement avant la récupération */ $evt_handler = events_handler::get_instance(); $event = new event_explnum("explnum", "before_get_file_content"); $event->set_explnum($this); $evt_handler->send($event); if (! $this->explnum_id) { exit(); } if ($this->explnum_data && ($this->explnum_data != 'NULL')) { $data = $this->explnum_data; } else if ($this->explnum_path) { $up = new upload_folder($this->explnum_repertoire); $path = str_replace("//", "/", $this->explnum_rep_path . $this->explnum_path . $this->explnum_nomfichier); $path = $up->encoder_chaine($path); if (file_exists($path)) { $fo = fopen($path, 'rb'); if ($fo) { while ( ! feof($fo) ) { $data .= fread($fo, 4096); } fclose($fo); } } } return $data; } public function get_is_file() { $path = ''; if (! $this->explnum_id) { return ''; } if ($this->explnum_data && ($this->explnum_data != 'NULL')) { return ''; } else if ($this->explnum_path) { $up = new upload_folder($this->explnum_repertoire); $path = str_replace("//", "/", $this->explnum_rep_path . $this->explnum_path . $this->explnum_nomfichier); $path = $up->encoder_chaine($path); if (file_exists($path)) { return $path; } } return ''; } public function get_file_name() { $nomfichier = ""; if ($this->explnum_nomfichier) { $nomfichier = $this->explnum_nomfichier; } elseif ($this->explnum_extfichier) { if ($this->explnum_nom) { $nomfichier = $this->explnum_nom; if (! preg_match("/\." . $this->explnum_extfichier . "$/", $nomfichier)) { $nomfichier .= "." . $this->explnum_extfichier; } } else { $nomfichier = "pmb" . $this->explnum_id . "." . $this->explnum_extfichier; } } $nomfichier = static::clean_explnum_file_name($nomfichier); return $nomfichier; } public function get_file_size($force=false) { $size = $this->explnum_file_size; if ($force || !$this->explnum_file_size) { if ($this->explnum_data) { $size = strlen($this->explnum_data); } elseif ($this->explnum_path) { $up = new upload_folder($this->explnum_repertoire); $path = str_replace("//", "/", $up->repertoire_path . $this->explnum_path . $this->explnum_nomfichier); $path = $up->encoder_chaine($path); $size = filesize($path); } $this->explnum_file_size = $size; } return $size; } public function get_create_date() { return $this->explnum_create_date; } public function get_update_date() { return $this->explnum_update_date; } public function get_rights_form() { global $msg, $charset; global $gestion_acces_active, $gestion_acces_empr_docnum; global $gestion_acces_empr_docnum_def; if ($gestion_acces_active != 1) return ''; $ac = new acces(); $form = ''; $c_form = "
\">
 
" . htmlentities($msg['dom_cur_prf'], ENT_QUOTES, $charset) . "
" . htmlentities($msg['dom_cur_rights'], ENT_QUOTES, $charset) . "
"; if ($gestion_acces_empr_docnum == 1) { $r_form = $c_form; $dom_3 = $ac->setDomain(3); $r_form = str_replace('', htmlentities($dom_3->getComment('long_name'), ENT_QUOTES, $charset), $r_form); if ($this->explnum_id) { // profil ressource $def_prf = $dom_3->getComment('res_prf_def_lib'); $res_prf = $dom_3->getResourceProfile($this->explnum_id); $q = $dom_3->loadUsedResourceProfiles(); // Recuperation droits generiques utilisateur $user_rights = $dom_3->getDomainRights(0, $res_prf); if ($user_rights & 2) { $p_sel = gen_liste($q, 'prf_id', 'prf_name', 'res_prf[3]', '', $res_prf, '0', $def_prf, '0', $def_prf); $p_rad = ""; $r_form = str_replace('', $p_rad, $r_form); } else { $r_form = str_replace('', htmlentities($dom_3->getResourceProfileName($res_prf), ENT_QUOTES, $charset), $r_form); } // droits/profils utilisateurs if ($user_rights & 1) { $r_rad = ""; $r_form = str_replace('', $r_rad, $r_form); } // recuperation profils utilisateurs $t_u = array(); $t_u[0] = $dom_3->getComment('user_prf_def_lib'); // niveau par defaut $qu = $dom_3->loadUsedUserProfiles(); $ru = pmb_mysql_query($qu); if (pmb_mysql_num_rows($ru)) { while ( ($row = pmb_mysql_fetch_object($ru)) ) { $t_u[$row->prf_id] = $row->prf_name; } } // recuperation des controles dependants de l'utilisateur $t_ctl = $dom_3->getControls(0); // recuperation des droits $t_rights = $dom_3->getResourceRights($this->explnum_id); if (count($t_u)) { $h_tab = "
"; foreach ( $t_u as $k => $v ) { $h_tab .= ""; } $h_tab .= "
" . htmlentities($v, ENT_QUOTES, $charset) . "
"; $c_tab = ''; foreach ( $t_u as $k => $v ) { $c_tab .= "
"; $t_rows = ""; foreach ( $t_ctl as $k2 => $v2 ) { $t_rows .= " "; } else { $t_rows .= "/> "; } } $c_tab = str_replace('', $t_rows, $c_tab); } $c_tab .= ""; } $h_tab = str_replace('', $c_tab, $h_tab); ; $r_form = str_replace('', $h_tab, $r_form); } else { $r_form = str_replace('', htmlentities($msg['dom_prf_unknown'], ENT_QUOTES, $charset), $r_form); $r_form = str_replace('', htmlentities($msg['dom_rights_unknown'], ENT_QUOTES, $charset), $r_form); } $form .= $r_form; } return $form; } public function gen_signature($full_path = '', $explnum_data = '', $explnum_path = '', $explnum_repertoire = 0, $explnum_nomfichier = '') { $this->explnum_signature = ''; if (!$explnum_data) $explnum_data = $this->explnum_data; if (!$explnum_path) $explnum_path = $this->explnum_path; if (!$explnum_repertoire) $explnum_repertoire = $this->explnum_repertoire; if (!$explnum_nomfichier) $explnum_nomfichier = $this->explnum_nomfichier; if ($explnum_data && ($explnum_data != 'NULL')) { $this->explnum_signature = md5($explnum_data); } else if ($full_path) { $fo = @fopen($full_path, 'r'); if ($fo) { $this->explnum_signature = md5_file($full_path); fclose($fo); } } else if ($explnum_path) { $up = new upload_folder($explnum_repertoire); $path = str_replace("//", "/", $up->repertoire_path . $explnum_path . $explnum_nomfichier); $path = $up->encoder_chaine($path); if (file_exists($path)) { $this->explnum_signature = md5_file($path); } } return $this->explnum_signature; } public function get_statut_libelle() { $statut_libelle = ''; $res = pmb_mysql_query("SELECT gestion_libelle FROM explnum_statut WHERE id_explnum_statut=".$this->explnum_docnum_statut); if ($res && pmb_mysql_num_rows($res)) { $statut_libelle = pmb_mysql_result($res, 0, 0); } return $statut_libelle; } public static function get_default_upload_directory(){ $query = "select repertoire_id from upload_repertoire join users on users.deflt_upload_repertoire=upload_repertoire.repertoire_id and users.username='" . SESSlogin . "'"; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result)) { return pmb_mysql_result($result, 0, 0); } return false; } public static function get_drop_zone($entity_id, $entity_type, $bul_id = ''){ global $explnum_drop_zone; $explnum_drop_zone_filled = str_replace('!!entity_id!!', $entity_id, $explnum_drop_zone); $explnum_drop_zone_filled = str_replace('!!entity_type!!', $entity_type, $explnum_drop_zone_filled); $explnum_drop_zone_filled = str_replace('!!bul_id!!', $bul_id, $explnum_drop_zone_filled); return $explnum_drop_zone_filled; } public static function getBytes($val) { $val = trim($val); $last = strtolower($val[strlen($val) - 1]); switch ($last) { case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; } public static function create_doc_from_file(){ global $charset; global $fnc; global $record_id; global $bulletin_id; global $id_rep; global $pmb_indexation_docnum_default; $headers = getallheaders(); //Uniformisons les retours en minuscules pour la compatibilité sur tous les environnements $headers = array_change_key_case($headers, CASE_LOWER); if($charset == 'utf-8') { $headers['x-file-name'] = utf8_encode($headers['x-file-name']); } $protocol = $_SERVER["SERVER_PROTOCOL"]; if (!isset($headers['content_length'])) { if (!isset($headers['x-file-size'])) { header($protocol.' 411 Length Required'); exit('Header \'Content-Length\' not set.'); }else{ $headers['content-length']=preg_replace('/\D*/', '', $headers['x-file-size']); } } if (isset($headers['x-file-size'], $headers['x-file-name'])) { $file = new stdClass(); $file->name = basename($headers['x-file-name']); $file->filename = preg_replace('/[^ \.\w_\-\(\)]*/', '', basename(reg_diacrit($headers['x-file-name']))); $file->size = preg_replace('/\D*/', '', $headers['x-file-size']); $maxUpload = static::getBytes(ini_get('upload_max_filesize')); // can only be set in php.ini and not by ini_set() $maxPost = static::getBytes(ini_get('post_max_size')); // can only be set in php.ini and not by ini_set() $memoryLimit = static::getBytes(ini_get('memory_limit')); if($memoryLimit > -1){ $limit = min($maxUpload, $maxPost, $memoryLimit); }else{ $limit = min($maxUpload, $maxPost); } if ($headers['content-length'] > $limit) { header($protocol.' 403 Forbidden'); exit('File size to big. Limit is '.$limit. ' bytes.'); } $i=1; while(file_exists("./temp/".$file->filename)){ if($i==1){ $file->filename = substr($file->filename,0,strrpos($file->filename,"."))."_".$i.substr($file->filename,strrpos($file->filename,".")); }else{ $file->filename = substr($file->filename,0,strrpos($file->filename,($i-1).".")).$i.substr($file->filename,strrpos($file->filename,".")); } $i++; } $fh = fopen("php://input", "r"); $th = fopen("./temp/".$file->filename, "w"); $part = 5 * 1024 * 1024; while (!feof($fh)) { fwrite($th, fread($fh, $part)); } fclose($fh); fclose($th); if (filesize("./temp/".$file->filename) > $limit) { header($protocol.' 403 Forbidden'); return false; } if (filesize("./temp/".$file->filename) !== false) { header($protocol.' 201 Created'); if($bulletin_id){ $bulletin_id = intval($bulletin_id); $explnum = new explnum(0,0,$bulletin_id); }else if($record_id){ $record_id = intval($record_id); $explnum = new explnum(0,$record_id,0); }else{ return false; } $id_rep = explnum::get_default_upload_directory(); $explnum->get_file_from_temp("./temp/".$file->filename, $file->name, true); if($pmb_indexation_docnum_default){ global $ck_index; $ck_index = 1; } $explnum->update(false); return $explnum; }else { header($protocol.' 505 Internal Server Error'); return false; } }else { header($protocol.' 500 Internal Server Error'); exit('Correct headers are not set.'); } } public static function get_pattern_link() { global $base_path; return $base_path.'/catalog.php?categ=edit_explnum&id=!!notice_id!!&explnum_id=!!explnum_id!!'; } public function get_display_link(){ /** * Si un bulletin possède un document numérique * il a forcement une notice associée */ if($this->explnum_bulletin){ return "./catalog.php?categ=serials&sub=explnum_form&serial_id=!!serial_id!!&explnum_id=!!explnum_id!!"; } if($this->explnum_notice){ $notice = new notice($this->explnum_notice); if ($notice->biblio_level =='a' && $notice->hierar_level == 2) { return "./catalog.php?categ=serials&sub=analysis&action=explnum_form&bul_id=!!bul_id!!&analysis_id=!!analysis_id!!&explnum_id=!!explnum_id!!"; } elseif ($notice->biblio_level=='m' && $notice->hierar_level== 0) { return static::get_pattern_link(); } elseif ($notice->biblio_level=='b' && $notice->hierar_level==2) { // on est face à une notice de bulletin $query = 'select bulletin_id from bulletins where num_notice = '.$notice->id; $result = pmb_mysql_query($query); if($result && pmb_mysql_num_rows($result)){ return "./catalog.php?categ=serials&sub=bulletinage&action=explnum_form&bul_id=".pmb_mysql_result($result, 0, 0)."&explnum_id=!!explnum_id!!"; } } } return ''; } /** * * @param parametres_perso $p_perso */ public function set_p_perso(parametres_perso $p_perso) { $this->p_perso = $p_perso; } public function get_p_perso() { if (isset($this->p_perso)) { return $this->p_perso; } $this->p_perso = new parametres_perso("explnum"); return $this->p_perso; } } // fin de la classe explnum } # fin de définition