function explnum_update($f_explnum_id, $f_notice, $f_bulletin, $f_nom, $f_url, $retour, $conservervignette = 0, $f_statut_chk = 0) { global $dbh, $msg, $scanned_image, $scanned_image_ext; global $current_module, $pmb_explnum_statut; global $ck_index, $scanned_texte, $up_place, $path, $id_rep; create_tableau_mimetype(); if ($f_explnum_id) { $requete = "UPDATE explnum SET "; $limiter = " WHERE explnum_id='{$f_explnum_id}' "; } else { $requete = "INSERT INTO explnum SET "; $limiter = ""; } print "<div class=\"row\"><h1>{$msg['explnum_doc_associe']}</h1>"; $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); $userfile_ext = ''; if ($userfile_name) { $userfile_ext = extension_fichier($userfile_name); } if ($f_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("./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) { if (move_uploaded_file($userfile_temp, './temp/' . $userfile_moved)) { $fic = 1; $f_url = ""; $maj_data = 1; move_uploaded_file($vignette_temp, './temp/' . $vignette_moved); } else { $erreur++; } } } $contenu_vignette = construire_vignette($vignette_moved, $userfile_moved); $maj_vignette = 1; $mimetype = trouve_mimetype($userfile_moved, $userfile_ext); if (!$mimetype) { $mimetype = "application/data"; } $maj_mimetype = 1; } else { if ($vignette_name) { move_uploaded_file($vignette_temp, './temp/' . $vignette_moved); $contenu_vignette = construire_vignette($vignette_moved, $userfile_moved); $maj_vignette = 1; } if ($f_url) { move_uploaded_file($vignette_temp, './temp/' . $vignette_moved); $contenu_vignette = construire_vignette($vignette_moved, $userfile_moved); $maj_vignette = 1; $mimetype = "URL"; $maj_mimetype = 1; $contenu = ""; $maj_data = 1; } } } else { // creation //Y-a-t-il une image exterieure ? if ($scanned_image) { //Si oui ! $tmpid = str_replace(" ", "_", microtime()); $fp = @fopen("./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 (move_uploaded_file($userfile_temp, './temp/' . $userfile_moved)) { $fic = 1; $f_url = ""; $maj_data = 1; } elseif (!$f_url) { $erreur++; } } move_uploaded_file($vignette_temp, './temp/' . $vignette_moved); $contenu_vignette = construire_vignette($vignette_moved, $userfile_moved); $maj_vignette = 1; 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; } $upfolder = new upload_folder($id_rep); if ($fic) { $is_upload = false; if (!$f_explnum_id && ($path && $up_place)) { if ($upfolder->isHashing()) { $rep = $upfolder->hachage($userfile_name); @mkdir($rep); $path = $upfolder->formate_path_to_nom($rep); $file_name = $rep . $userfile_name; } else { $file_name = $upfolder->formate_nom_to_path($path) . $userfile_name; } $path = $upfolder->formate_path_to_save($path); $file_name = $upfolder->encoder_chaine($file_name); rename('./temp/' . $userfile_moved, $file_name); $is_upload = true; } else { $file_name = './temp/' . $userfile_moved; } $fp = fopen($file_name, "r"); $contenu = fread($fp, filesize($file_name)); if (!$fp || $contenu == "") { $erreur++; } fclose($fp); } //Dans le cas d'une modification, on regarde si il y a eu un déplacement du stockage if ($f_explnum_id) { $explnum = new explnum($f_explnum_id); if ($explnum->isEnBase() && ($up_place && $path)) { $explnum->remove_from_base($path, $id_rep); $contenu = ""; $is_upload = false; } elseif ($explnum->isEnUpload() && !$up_place) { $contenu = $explnum->remove_from_upload(); $id_rep = 0; $path = ""; } elseif ($explnum->isEnUpload() && ($up_place && $path)) { $path = $explnum->change_rep_upload($upfolder, $upfolder->formate_nom_to_path($path)); $path = $upfolder->formate_path_to_save($upfolder->formate_path_to_nom($path)); } } if (!$f_nom) { if ($userfile_name) { $f_nom = $userfile_name; } elseif ($f_url) { $f_nom = $f_url; } else { $f_nom = "-x-x-x-x-"; } } if ($userfile_name && !$is_upload) { unlink($file_name); } if ($vignette_name) { unlink('./temp/' . $vignette_moved); } if (!$erreur) { $requete .= " explnum_notice='{$f_notice}'"; $requete .= ", explnum_bulletin='{$f_bulletin}'"; $requete .= ", explnum_nom='{$f_nom}'"; $requete .= ", explnum_url='{$f_url}'"; if ($maj_mimetype) { $requete .= ", explnum_mimetype='" . $mimetype . "' "; } if ($maj_data) { if (!$is_upload) { $requete .= ", explnum_data='" . addslashes($contenu) . "'"; } $requete .= ", explnum_nomfichier='" . addslashes($userfile_name) . "'"; $requete .= ", explnum_extfichier='" . addslashes($userfile_ext) . "'"; } if ($maj_vignette && !$conservervignette) { $requete .= ", explnum_vignette='" . addslashes($contenu_vignette) . "'"; } if ($pmb_explnum_statut == '1') { $requete .= ", explnum_statut='" . $f_statut_chk . "'"; } $requete .= ", explnum_repertoire='" . $id_rep . "'"; $requete .= ", explnum_path='" . $path . "'"; $requete .= $limiter; pmb_mysql_query($requete, $dbh); //Indexation du document global $pmb_indexation_docnum; if ($pmb_indexation_docnum) { if (!$f_explnum_id && $ck_index) { $id_explnum = pmb_mysql_insert_id(); $indexation = new indexation_docnum($id_explnum, $scanned_texte); $indexation->indexer(); } elseif ($f_explnum_id && $ck_index) { $indexation = new indexation_docnum($f_explnum_id, $scanned_texte); $indexation->indexer(); } elseif ($f_explnum_id && !$ck_index) { $indexation = new indexation_docnum($f_explnum_id); $indexation->desindexer(); } } // on reaffiche l'ISBD print "<div class='row'><div class='msg-perio'>" . $msg['maj_encours'] . "</div></div>"; $id_form = md5(microtime()); if (pmb_mysql_error()) { echo "MySQL error : " . pmb_mysql_error(); print "\n\t\t\t\t<form class='form-{$current_module}' name=\"dummy\" method=\"post\" action=\"{$retour}\" >\n\t\t\t\t\t<input type='submit' class='bouton' name=\"id_form\" value=\"Ok\">\n\t\t\t\t\t</form>"; print "</div>"; exit; } print "\n\t\t<form class='form-{$current_module}' name=\"dummy\" method=\"post\" action=\"{$retour}\" style=\"display:none\">\n\t\t\t<input type=\"hidden\" name=\"id_form\" value=\"{$id_form}\">\n\t\t\t</form>"; print "<script type=\"text/javascript\">document.dummy.submit();</script>"; } else { eval("\$bid=\"" . $msg['explnum_erreurupload'] . "\";"); print "<div class='row'><div class='msg-perio'>" . $bid . "</div></div>"; print "\n\t\t\t<form class='form-{$current_module}' name=\"dummy\" method=\"post\" action=\"{$retour}\" >\n\t\t\t\t<input type='submit' class='bouton' name=\"id_form\" value=\"Ok\">\n\t\t\t</form>"; } print "</div>"; }