repertoire_path.static::get_img_prefix($object_type).$object_id;
}
if (($fp=@fopen($_FILES['f_img_load']['tmp_name'], "rb")) && $filename_output) {
$image="";
$size=0;
$flag=true;
while (!feof($fp)) {
$image.=fread($fp,4096);
$size=strlen($image);
}
if ($img=imagecreatefromstring($image)) {
$parameter_img_pics_max_size = static::get_parameter_img_pics_max_size($object_type);
if(!($parameter_img_pics_max_size*1)) $parameter_img_pics_max_size=100;
$redim=false;
if (imagesx($img) >= imagesy($img)) {
if(imagesx($img) <= $parameter_img_pics_max_size){
$largeur=imagesx($img);
$hauteur=imagesy($img);
}else{
$redim=true;
$largeur=$parameter_img_pics_max_size;
$hauteur = ($largeur*imagesy($img))/imagesx($img);
}
} else {
if(imagesy($img) <= $parameter_img_pics_max_size){
$hauteur=imagesy($img);
$largeur=imagesx($img);
}else{
$redim=true;
$hauteur=$parameter_img_pics_max_size;
$largeur = ($hauteur*imagesx($img))/imagesy($img);
}
}
if($redim){
$dest = imagecreatetruecolor($largeur,$hauteur);
imagecopyresampled($dest, $img, 0, 0, 0, 0, $largeur, $hauteur,imagesx($img),imagesy($img));
imagepng($dest,$filename_output);
imagedestroy($dest);
}else{
imagepng($img,$filename_output);
}
imagedestroy($img);
$thumbnail_url=$opac_url_base."getimage.php?noticecode=&vigurl=";
$manag_cache=array();
switch ($object_type) {
case 'shelve':
$thumbnail_url .= "&etagere_id=".$object_id;
$manag_cache = getimage_cache(0, $etagere_id);
break;
case 'authority':
$thumbnail_url .= "&authority_id=".$object_id;
$manag_cache = getimage_cache(0, 0, $object_id);
break;
case 'record':
default:
$thumbnail_url .= "¬ice_id=".$object_id;
$manag_cache = getimage_cache($object_id);
break;
}
//On détruit l'image si elle est en cache
global $pmb_img_cache_folder;
if ($pmb_img_cache_folder) {
if($manag_cache["location"] && preg_match("#^".$pmb_img_cache_folder."(.+)$#",$manag_cache["location"])){
unlink($manag_cache["location"]);
global $opac_img_cache_folder;
if($opac_img_cache_folder && file_exists(str_replace($pmb_img_cache_folder, $opac_img_cache_folder, $manag_cache["location"]))){
unlink(str_replace($pmb_img_cache_folder, $opac_img_cache_folder, $manag_cache["location"]));
}
}
}
}
}
}
return $thumbnail_url;
}
public static function create_from_base64($object_id, $object_type = 'record', $thumbnail_base64='') {
global $opac_url_base;
$thumbnail_url = '';
// vignette de la notice uploadé dans un répertoire
if(static::get_parameter_img_folder_id($object_type) && $object_id){
$query = "select repertoire_path from upload_repertoire where repertoire_id ='".static::get_parameter_img_folder_id($object_type)."'";
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
$row=pmb_mysql_fetch_object($result);
$filename_output=$row->repertoire_path.static::get_img_prefix($object_type).$object_id;
}
if(is_dir($row->repertoire_path) && $filename_output) {
$details = explode(',', $thumbnail_base64);
$ini =substr($details[0], 11);
$type = explode(';', $ini);
if($type[0]) {
$created = file_put_contents($filename_output, base64_decode($details[1]));
if($created) {
return true;
}
}
}
}
return false;
}
//Suppression de la vignette de la notice si il y en a une d'uploadée
public static function delete($object_id, $object_type = 'record') {
if(static::get_parameter_img_folder_id($object_type)){
$query = "select repertoire_path from upload_repertoire where repertoire_id ='".static::get_parameter_img_folder_id($object_type)."'";
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
$rep=pmb_mysql_fetch_object($result);
$img=$rep->repertoire_path.static::get_img_prefix($object_type).$object_id;
@unlink($img);
}
}
}
public static function is_valid_folder($object_type='record') {
$is_valid = false;
if(static::get_parameter_img_folder_id($object_type)){
$req = "select repertoire_path from upload_repertoire where repertoire_id ='".static::get_parameter_img_folder_id($object_type)."'";
$res = pmb_mysql_query($req);
if(pmb_mysql_num_rows($res)){
$rep=pmb_mysql_fetch_object($res);
if(is_dir($rep->repertoire_path)){
$is_valid = true;
}
}
}
return $is_valid;
}
public static function get_message_folder($object_type='record') {
global $msg;
$message_folder="";
if(static::get_parameter_img_folder_id($object_type)){
if(!static::is_valid_folder($object_type)){
if (SESSrights & ADMINISTRATION_AUTH){
$requete = "select * from parametres where gestion=0 and type_param='pmb' and sstype_param='notice_img_folder_id' ";
$res = pmb_mysql_query($requete);
$i=0;
if($param=pmb_mysql_fetch_object($res)) {
$message_folder=" ".$msg['notice_img_folder_admin_no_access']." ";
}
}else{
$message_folder=$msg['notice_img_folder_no_access'];
}
}
}
return $message_folder;
}
public static function get_image($code, $thumbnail_url) {
global $charset;
global $opac_show_book_pics;
global $opac_book_pics_url;
global $opac_book_pics_msg;
if(!isset(static::$image[$code."_".$thumbnail_url])) {
if ($code || $thumbnail_url) {
if ($opac_show_book_pics=='1' && ($opac_book_pics_url || $thumbnail_url)) {
if ($thumbnail_url) {
$title_image_ok="";
} else {
$title_image_ok = htmlentities($opac_book_pics_msg, ENT_QUOTES, $charset);
}
static::$image[$code."_".$thumbnail_url] = "";
} else {
static::$image[$code."_".$thumbnail_url] = "";
}
} else {
static::$image[$code."_".$thumbnail_url] = "";
}
}
return static::$image[$code."_".$thumbnail_url];
}
public static function get_url_image($code, $thumbnail_url) {
global $opac_show_book_pics;
global $opac_book_pics_url;
global $pmb_opac_url;
if(!isset(static::$url_image[$code."_".$thumbnail_url])) {
if ($code || $thumbnail_url) {
if ($opac_show_book_pics=='1' && ($opac_book_pics_url || $thumbnail_url)) {
static::$url_image[$code."_".$thumbnail_url] = getimage_url($code, $thumbnail_url);
} else {
static::$url_image[$code."_".$thumbnail_url] = get_url_icon("no_image.jpg");
}
} else {
static::$url_image[$code."_".$thumbnail_url] = '';
}
}
return static::$url_image[$code."_".$thumbnail_url];
}
public static function get_js_function_chklnk_tpl() {
global $js_function_chklnk_tpl;
return $js_function_chklnk_tpl;
}
public static function get_form($object_type, $value = '') {
global $msg, $charset;
$form = static::get_js_function_chklnk_tpl();
$form .= "
";
if(static::get_parameter_img_folder_id($object_type)){
$message_folder = static::get_message_folder($object_type);
$form .= "
";
}
return $form;
}
public static function do_image(&$entree, $notice) {
global $charset;
global $pmb_book_pics_show ;
global $pmb_book_pics_url ;
global $pmb_book_pics_msg;
// pour url OPAC en diff DSI
global $prefix_url_image ;
global $depliable ;
global $opac_url_base;
if(!isset($prefix_url_image)){
$prefix_url_image = "./";
}
if (!empty($notice->code) || !empty($notice->thumbnail_url)) {
if ($pmb_book_pics_show=='1' && ($pmb_book_pics_url || $notice->thumbnail_url)) {
$url_image=$url_image_ok = getimage_url((!empty($notice->code) ? $notice->code : ''), ($notice->thumbnail_url ?? ""));
if ($depliable) {//MB - 22/06/2017: dépliable à 0 ou pas défini, on ne passe jamais ici je pense
$image = "thumbnail_url."\">";
} else {
/*
if ($notice->thumbnail_url) {
$title_image_ok="";
} else {
$title_image_ok = htmlentities($pmb_book_pics_msg, ENT_QUOTES, $charset) ;
}
*/
if($pmb_book_pics_msg) {
$title_image_ok = htmlentities($pmb_book_pics_msg, ENT_QUOTES, $charset);
}else {
$title_image_ok = htmlentities($notice->tit1, ENT_QUOTES, $charset);
}
$image = "";
}
} else {
$image="";
}
if ($image) {
$entree = "" ;
} else {
$entree = "" ;
}
} else {
$entree = "" ;
}
}
} // fin de déclaration de la classe thumbnail