<?php
// +-------------------------------------------------+
// © 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: vig_num_collections.php,v 1.1.2.2 2025/06/12 09:13:53 rtigero Exp $

// définition du minimum nécéssaire
$base_path      = ".";
$base_auth      = ""; //"CIRCULATION_AUTH";
$base_title     = "";
$base_noheader  = 1;
$base_nocheck   = 1;
$base_nobody    = 1;
$base_nosession = 1;

require_once("$base_path/includes/init.inc.php");
session_write_close(); //Fermeture de la session dès que possible

$explnum_id = (int) $explnum_id;
$resultat = pmb_mysql_query("SELECT id_explnum_collections_explnums, explnum_collections_explnums_mimetype, explnum_collections_explnums_vignette, explnum_collections_explnums_extfichier FROM explnum_collections_explnums WHERE id_explnum_collections_explnums = '$explnum_id' ");
$nb_res = pmb_mysql_num_rows($resultat);

if (!$nb_res) {
	exit;
}
global $pmb_docnum_img_folder_id;
$ligne = pmb_mysql_fetch_object($resultat);
if (!empty($pmb_docnum_img_folder_id)) {
	$query = "select repertoire_path from upload_repertoire where repertoire_id ='$pmb_docnum_img_folder_id'";
	$result = pmb_mysql_query($query);
	if (pmb_mysql_num_rows($result)) {
		$row = pmb_mysql_fetch_object($result);
		$filename_output = $row->repertoire_path . "img_docnum_" . $ligne->id_explnum_collections_explnums;
		if (file_exists($filename_output)) {
			print file_get_contents($filename_output);
			exit;
		}
	}
}
if ($ligne->explnum_collections_explnums_vignette) {
	print stripslashes($ligne->explnum_collections_explnums_vignette);
	exit;
} else {
	require_once("$include_path/explnum.inc.php");
	require_once("$class_path/curl.class.php");

	//On charge le tableau de mimetypes
	create_tableau_mimetype();
	//On cherche l'image associee
	$image_filename = "/images/mimetype/" . icone_mimetype($ligne->explnum_collections_explnums_mimetype, $ligne->explnum_collections_explnums_extfichier);
	if ($pmb_curl_available) {
		$image_url = 'http';
		if ($_SERVER["HTTPS"] == "on") {
			$image_url .= "s";
		}
		$image_url .= "://";
		$image_url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . dirname($_SERVER["SCRIPT_NAME"]) . $image_filename;
		$aCurl = new Curl();
		$content = $aCurl->get($image_url);
		$contenu_vignette = $content->body;
	} else {
		$fp = fopen(".$image_filename", "r");
		$contenu_vignette = fread($fp, filesize(".$image_filename"));
		fclose($fp);
	}
	print $contenu_vignette;
}
