mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-22 17:31:25 +01:00
Fix: Photo for users and members were saved with .jpg even if .png
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
require("./pre.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_type.class.php");
|
||||
@@ -88,6 +89,11 @@ if ($rowid)
|
||||
$caneditfieldmember=$user->rights->adherent->creer;
|
||||
}
|
||||
|
||||
// Define size of logo small and mini (might be set into other pages)
|
||||
$maxwidthsmall=270;$maxheightsmall=150;
|
||||
$maxwidthmini=128;$maxheightmini=72;
|
||||
$quality = 80;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@@ -244,6 +250,8 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adhe
|
||||
|
||||
$adh->amount = $_POST["amount"];
|
||||
|
||||
$adh->photo = $_FILES['photo']['name'];
|
||||
|
||||
// Get status and public property
|
||||
$adh->statut = $_POST["statut"];
|
||||
$adh->public = $_POST["public"];
|
||||
@@ -277,19 +285,27 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adhe
|
||||
{
|
||||
if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name']))
|
||||
{
|
||||
$dir= $conf->adherent->dir_output . '/' . get_exdir($adh->id,2,0,1);
|
||||
|
||||
// If photo is provided
|
||||
if (! is_dir($conf->adherent->dir_output))
|
||||
create_exdir($dir);
|
||||
|
||||
if (@is_dir($dir))
|
||||
{
|
||||
create_exdir($conf->adherent->dir_output);
|
||||
}
|
||||
if (is_dir($conf->adherent->dir_output))
|
||||
{
|
||||
$newfile=$conf->adherent->dir_output . "/" . $adh->id . ".jpg";
|
||||
$newfile=$dir.'/'.$_FILES['photo']['name'];
|
||||
if (! dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1) > 0)
|
||||
{
|
||||
$message .= '<div class="error">'.$langs->trans("ErrorFailedToSaveFile").'</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create small thumbs for company (Ratio is near 16/9)
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
|
||||
|
||||
// Create mini thumbs for company (Ratio is near 16/9)
|
||||
// Used on menu or for setup page for example
|
||||
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -219,11 +219,11 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 1)
|
||||
* Edition info modele document
|
||||
*/
|
||||
$constantes=array(
|
||||
'ADHERENT_CARD_TYPE',
|
||||
'ADHERENT_CARD_HEADER_TEXT',
|
||||
'ADHERENT_CARD_TEXT',
|
||||
'ADHERENT_CARD_TEXT_RIGHT',
|
||||
'ADHERENT_CARD_FOOTER_TEXT',
|
||||
'ADHERENT_CARD_TYPE'
|
||||
'ADHERENT_CARD_FOOTER_TEXT'
|
||||
);
|
||||
print_fiche_titre($langs->trans("MembersCards"),'','');
|
||||
|
||||
@@ -232,13 +232,31 @@ form_constantes($constantes);
|
||||
print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
|
||||
print '%DOL_MAIN_URL_ROOT%, %ID%, %PRENOM%, %NOM%, %LOGIN%, %PASSWORD%, ';
|
||||
print '%SOCIETE%, %ADRESSE%, %CP%, %VILLE%, %PAYS%, %EMAIL%, %NAISS%, %PHOTO%, %TYPE%, ';
|
||||
print '%YEAR%, %MONTH%, %DAY%, %LOGO%, %PHOTO%';
|
||||
print '%YEAR%, %MONTH%, %DAY%, %PHOTO%';
|
||||
//print '%INFOS%'; Deprecated
|
||||
print '<br>';
|
||||
|
||||
print '<br>';
|
||||
|
||||
|
||||
/*
|
||||
* Edition info modele document
|
||||
*/
|
||||
$constantes=array(
|
||||
'ADHERENT_ETIQUETTE_TYPE'
|
||||
);
|
||||
print_fiche_titre($langs->trans("MembersTickets"),'','');
|
||||
|
||||
form_constantes($constantes);
|
||||
|
||||
print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
|
||||
print '%DOL_MAIN_URL_ROOT%, %ID%, %PRENOM%, %NOM%, %LOGIN%, %PASSWORD%, ';
|
||||
print '%SOCIETE%, %ADRESSE%, %CP%, %VILLE%, %PAYS%, %EMAIL%, %NAISS%, %PHOTO%, %TYPE%, ';
|
||||
print '%YEAR%, %MONTH%, %DAY%, %PHOTO%';
|
||||
//print '%INFOS%'; Deprecated
|
||||
print '<br>';
|
||||
|
||||
print '<br>';
|
||||
/*
|
||||
* Edition des variables globales non rattache a un theme specifique
|
||||
*/
|
||||
@@ -252,7 +270,7 @@ $constantes=array(
|
||||
'ADHERENT_MAIL_RESIL_SUBJECT',
|
||||
'ADHERENT_MAIL_RESIL',
|
||||
'ADHERENT_MAIL_FROM',
|
||||
'ADHERENT_ETIQUETTE_TYPE'
|
||||
|
||||
);
|
||||
print_fiche_titre($langs->trans("Other"),'','');
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ $langs->load("companies");
|
||||
if (!$user->admin)
|
||||
accessforbidden();
|
||||
|
||||
// Define size of logo small and mini
|
||||
// Define size of logo small and mini (might be set into other pages)
|
||||
$maxwidthsmall=270;$maxheightsmall=150;
|
||||
$maxwidthmini=128;$maxheightmini=72;
|
||||
$quality = 80;
|
||||
|
||||
@@ -2914,7 +2914,7 @@ class Form
|
||||
/**
|
||||
* \brief Return HTML code to output a photo
|
||||
* \param modulepart Id to define module concerned
|
||||
* \param object Object containing data to retreive file name
|
||||
* \param object Object containing data to retrieve file name
|
||||
* \param width Width of photo
|
||||
* \return string HTML code to output photo
|
||||
*/
|
||||
@@ -2927,13 +2927,15 @@ class Form
|
||||
if ($modulepart=='userphoto')
|
||||
{
|
||||
$dir=$conf->user->dir_output;
|
||||
$file=$object->id.".jpg";
|
||||
$file=get_exdir($object->id,2).$object->photo;
|
||||
$altfile=$object->id.".jpg"; // For backward compatibility
|
||||
$email=$object->email;
|
||||
}
|
||||
if ($modulepart=='memberphoto')
|
||||
{
|
||||
$dir=$conf->adherent->dir_output;
|
||||
$file=$object->id.".jpg";
|
||||
$file=get_exdir($object->id,2).$object->photo;
|
||||
$altfile=$object->id.".jpg"; // For backward compatibility
|
||||
$email=$object->email;
|
||||
}
|
||||
|
||||
@@ -2942,6 +2944,10 @@ class Form
|
||||
if (file_exists($dir."/".$file))
|
||||
{
|
||||
$ret.='<img alt="Photo" width="'.$width.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($file).'">';
|
||||
}
|
||||
else if (file_exists($dir."/".$altfile))
|
||||
{
|
||||
$ret.='<img alt="Photo" width="'.$width.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($altfile).'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -51,6 +51,7 @@ ALTER TABLE llx_projet ADD COLUMN model_pdf varchar(50) AFTER note;
|
||||
ALTER TABLE llx_societe ADD COLUMN localtax1_assuj tinyint DEFAULT 0 after tva_assuj;
|
||||
ALTER TABLE llx_societe ADD COLUMN localtax2_assuj tinyint DEFAULT 0 after localtax1_assuj;
|
||||
|
||||
ALTER TABLE llx_user ADD COLUMN photo varchar(255) after statut;
|
||||
|
||||
-- Create table of extra fields
|
||||
create table llx_extra_fields
|
||||
|
||||
@@ -47,7 +47,7 @@ create table llx_adherent
|
||||
phone_perso varchar(30),
|
||||
phone_mobile varchar(30),
|
||||
naiss date, -- date de naissance
|
||||
photo varchar(255), -- url vers photo
|
||||
photo varchar(255), -- filename or url of photo
|
||||
statut smallint NOT NULL DEFAULT 0,
|
||||
public smallint NOT NULL DEFAULT 0, -- certain champ de la fiche sont ils public ou pas ?
|
||||
datefin datetime, -- date de fin de validite de la cotisation
|
||||
|
||||
@@ -51,6 +51,7 @@ create table llx_user
|
||||
egroupware_id integer,
|
||||
ldap_sid varchar(255) DEFAULT NULL,
|
||||
statut tinyint DEFAULT 1,
|
||||
photo varchar(255), -- filename or url of photo
|
||||
lang varchar(6)
|
||||
)type=innodb;
|
||||
|
||||
|
||||
@@ -2640,15 +2640,16 @@ function yn($yesno, $case=1, $color=0)
|
||||
* \remarks Examples: '001' with level 3->"0/0/1/", '015' with level 3->"0/1/5/"
|
||||
* \remarks Examples: 'ABC-1' with level 3 ->"0/0/1/", '015' with level 1->"5/"
|
||||
*/
|
||||
function get_exdir($num,$level=3,$alpha=0)
|
||||
function get_exdir($num,$level=3,$alpha=0,$withoutslash=0)
|
||||
{
|
||||
$path = '';
|
||||
if (empty($alpha)) $num = preg_replace('/([^0-9])/i','',$num);
|
||||
else $num = preg_replace('/^.*\-/i','',$num);
|
||||
$num = substr("000".$num, -$level);
|
||||
if ($level == 1) $path = substr($num,0,1).'/';
|
||||
if ($level == 2) $path = substr($num,1,1).'/'.substr($num,0,1).'/';
|
||||
if ($level == 3) $path = substr($num,2,1).'/'.substr($num,1,1).'/'.substr($num,0,1).'/';
|
||||
if ($level == 1) $path = substr($num,0,1);
|
||||
if ($level == 2) $path = substr($num,1,1).'/'.substr($num,0,1);
|
||||
if ($level == 3) $path = substr($num,2,1).'/'.substr($num,1,1).'/'.substr($num,0,1);
|
||||
if (empty($withoutslash)) $path.='/';
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,14 +30,14 @@
|
||||
* \brief Create a thumbnail from an image file (une small et un mini)
|
||||
* \brief Les extensions prises en compte sont jpg et png
|
||||
* \param file Chemin du fichier image a redimensionner
|
||||
* \param maxWidth Largeur maximum que dois faire la miniature (160 par defaut)
|
||||
* \param maxHeight Hauteur maximum que dois faire l'image (120 par defaut)
|
||||
* \param maxWidth Largeur maximum que dois faire la miniature (-1=unchanged, 160 par defaut)
|
||||
* \param maxHeight Hauteur maximum que dois faire l'image (-1=unchanged, 120 par defaut)
|
||||
* \param extName Extension pour differencier le nom de la vignette
|
||||
* \param quality Quality of compression (0=worst, 100=best)
|
||||
* \return string Full path of thumb
|
||||
* \remarks With file=myfile.jpg -> myfile_small.jpg
|
||||
*/
|
||||
function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50)
|
||||
function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50, $outdir='thumbs')
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
|
||||
|
||||
@@ -63,23 +63,26 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
|
||||
{
|
||||
return 'This file '.$file.' does not seem to be an image format file name.';
|
||||
}
|
||||
elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < 0){
|
||||
elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){
|
||||
// Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
|
||||
return 'Valeur de la largeur incorrecte.';
|
||||
}
|
||||
elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < 0){
|
||||
elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){
|
||||
// Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
|
||||
return 'Valeur de la hauteur incorrecte.';
|
||||
}
|
||||
|
||||
$fichier = realpath($file); // Chemin canonique absolu de l'image
|
||||
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image
|
||||
$dirthumb = $dir.'thumbs/'; // Chemin du dossier contenant les vignettes
|
||||
$dir = dirname($file); // Chemin du dossier contenant l'image
|
||||
$dirthumb = $dir.($outdir?'/'.$outdir:''); // Chemin du dossier contenant les vignettes
|
||||
|
||||
$infoImg = getimagesize($fichier); // Recuperation des infos de l'image
|
||||
$imgWidth = $infoImg[0]; // Largeur de l'image
|
||||
$imgHeight = $infoImg[1]; // Hauteur de l'image
|
||||
|
||||
if ($maxWidth == -1) $maxWidth=$infoImg[0]; // If size is -1, we keep unchanged
|
||||
if ($maxHeight == -1) $maxHeight=$infoImg[1]; // If size is -1, we keep unchanged
|
||||
|
||||
// Si l'image est plus petite que la largeur et la hauteur max, on ne cree pas de vignette
|
||||
if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight)
|
||||
{
|
||||
@@ -114,10 +117,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
|
||||
}
|
||||
|
||||
// On cree le repertoire contenant les vignettes
|
||||
if (! file_exists($dirthumb))
|
||||
{
|
||||
create_exdir($dirthumb);
|
||||
}
|
||||
|
||||
// Initialisation des variables selon l'extension de l'image
|
||||
switch($infoImg[2])
|
||||
@@ -214,7 +214,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
|
||||
|
||||
$fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file); // On enleve extension quelquesoit la casse
|
||||
$fileName = basename($fileName);
|
||||
$imgThumbName = $dirthumb.$fileName.$extName.$extImg; // Chemin complet du fichier de la vignette
|
||||
$imgThumbName = $dirthumb.'/'.$fileName.$extName.$extImg; // Chemin complet du fichier de la vignette
|
||||
|
||||
// Check if permission are ok
|
||||
//$fp = fopen($imgThumbName, "w");
|
||||
|
||||
@@ -2308,15 +2308,14 @@ class Product extends CommonObject
|
||||
*/
|
||||
function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120)
|
||||
{
|
||||
$dir = $sdir .'/'. get_exdir($this->id,2) . $this->id ."/";
|
||||
$dir .= "photos/";
|
||||
$dir = $sdir .'/'. get_exdir($this->id,2) . $this->id ."/photos";
|
||||
|
||||
create_exdir($dir);
|
||||
|
||||
$dir_osencoded=$dir;
|
||||
if (file_exists($dir_osencoded))
|
||||
if (is_dir($dir_osencoded))
|
||||
{
|
||||
$originImage = $dir . $file['name'];
|
||||
$originImage = $dir . '/' . $file['name'];
|
||||
|
||||
// Cree fichier en taille origine
|
||||
$result=dol_move_uploaded_file($file['tmp_name'], $originImage, 1);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
Reference in New Issue
Block a user