Ajout gnration de deux vignettes du logo de la socit

This commit is contained in:
Regis Houssin 2007-08-09 18:22:39 +00:00
parent 65c65ff366
commit 92715a4494
5 changed files with 92 additions and 32 deletions

View File

@ -65,6 +65,22 @@ if ( (isset($_POST["action"]) && $_POST["action"] == 'update')
if (doliMoveFileUpload($_FILES["logo"]["tmp_name"],$conf->societe->dir_logos.'/'.$original_file))
{
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO",$original_file);
// Création de la vignette de la page login
$imgThumbSmall = vignette($conf->societe->dir_logos.'/'.$original_file, 200, 100, '_small',80);
if (eregi('([^\\\/:]+)$',$imgThumbSmall,$reg))
{
$imgThumbSmall = $reg[1];
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall);
}
// Création de la vignette de la page "Société/Institution"
$imgThumbMini = vignette($conf->societe->dir_logos.'/'.$original_file, 100, 30, '_mini',80);
if (eregi('([^\\\/:]+)$',$imgThumbMini,$reg))
{
$imgThumbMini = $reg[1];
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini);
}
}
else
{
@ -95,12 +111,46 @@ if ( (isset($_POST["action"]) && $_POST["action"] == 'update')
}
}
if ($_GET["action"] == 'addthumb')
{
if (file_exists($conf->societe->dir_logos.'/'.$_GET["file"]))
{
// Création de la vignette de la page login
$imgThumbSmall = vignette($conf->societe->dir_logos.'/'.$_GET["file"], 200, 100, '_small',80);
if (eregi('([^\\\/:]+)$',$imgThumbSmall,$reg))
{
$imgThumbSmall = $reg[1];
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall);
}
// Création de la vignette de la page "Société/Institution"
$imgThumbMini = vignette($conf->societe->dir_logos.'/'.$_GET["file"], 100, 30, '_mini',80);
if (eregi('([^\\\/:]+)$',$imgThumbMini,$reg))
{
$imgThumbMini = $reg[1];
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini);
}
}
Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
if ($_GET["action"] == 'removelogo')
{
$logofile=$conf->societe->dir_logos.'/'.$mysoc->logo;
@unlink($logofile);
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO");
$mysoc->logo='';
$logosmallfile=$conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_small;
@unlink($logosmallfile);
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL");
$mysoc->logo_small='';
$logominifile=$conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_mini;
@unlink($logominifile);
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI");
$mysoc->logo_mini='';
}
/*
@ -187,16 +237,16 @@ if ((isset($_GET["action"]) && $_GET["action"] == 'edit')
print '<table width="100%" class="notopnoleftnoright"><tr><td valign="center">';
print '<input type="file" class="flat" name="logo" size="50">';
print '</td><td valign="middle" align="right">';
if ($mysoc->logo && file_exists($conf->societe->dir_logos.'/'.$mysoc->logo))
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=removelogo">'.img_delete($langs->trans("Delete")).'</a>';
print ' &nbsp; ';
print '<img height="30" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode($mysoc->logo).'">';
}
if ($mysoc->logo_mini && file_exists($conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_mini))
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=removelogo">'.img_delete($langs->trans("Delete")).'</a>';
print ' &nbsp; ';
print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode($mysoc->logo_mini).'">';
}
else
{
print '<img height="30" src="'.DOL_URL_ROOT.'/theme/common/nophoto.jpg">';
}
{
print '<img height="30" src="'.DOL_URL_ROOT.'/theme/common/nophoto.jpg">';
}
print '</td></tr></table>';
print '</td></tr>';
@ -425,9 +475,15 @@ else
print '<table width="100%" class="notopnoleftnoright"><tr><td valign="center">';
print $mysoc->logo;
print '</td><td valign="center" align="right">';
if ($mysoc->logo && file_exists($conf->societe->dir_logos.'/'.$mysoc->logo))
// On propose la génération de la vignette si elle n'existe pas
if (!file_exists($conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_mini) && eregi('(\.jpg|\.jpeg|\.png)$',$mysoc->logo))
{
print '<img height="30" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.$mysoc->logo.'">';
print '<a href="'.$_SERVER["PHP_SELF"].'?action=addthumb&amp;file='.urlencode($mysoc->logo).'">'.img_refresh($langs->trans('GenerateThumb')).'&nbsp;&nbsp;</a>';
}
else if ($mysoc->logo_mini && file_exists($conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_mini))
{
print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.$mysoc->logo_mini.'">';
}
else
{

View File

@ -1185,7 +1185,7 @@ function dol_loginfunction($notused,$pearstatus)
print '">';
// Table 1
print '<table cellpadding="0" cellspacing="0" border="0" align="center" width="400">';
print '<table cellpadding="0" cellspacing="0" border="0" align="center" width="450">';
if (file_exists(DOL_DOCUMENT_ROOT.'/logo.png'))
{
// Cas qui ne devrait pas arriver (pour compatibilité)
@ -1200,7 +1200,7 @@ function dol_loginfunction($notused,$pearstatus)
print '<br>';
// Table 2
print '<table cellpadding="2" align="center" width="400">';
print '<table cellpadding="2" align="center" width="450">';
print '<tr><td colspan="3">&nbsp;</td></tr>';
@ -1210,17 +1210,15 @@ function dol_loginfunction($notused,$pearstatus)
if ($conf->main_authentication) $title.=$langs->trans("AuthenticationMode").': '.$conf->main_authentication;
// Affiche logo du theme si existe, sinon logo commun
$urllogo=DOL_URL_ROOT.'/theme/login_logo.png';
if (is_readable($conf->societe->dir_logos.'/'.$mysoc->logo))
if (is_readable($conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_small))
{
$urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode($mysoc->logo);
$height=100; // \TODO Forcer la hauteur uniquement si hauteur > 100 ou largeur > 100
$urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode($mysoc->logo_small);
}
elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/login_logo.png'))
{
$urllogo=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_logo.png';
$height=80;
}
print '<td rowspan="2"><img title="'.$title.'" height="'.$height.'" src="'.$urllogo.'"></td>';
print '<td rowspan="2"><img title="'.$title.'" src="'.$urllogo.'"></td>';
print '</tr>';
@ -2951,9 +2949,11 @@ function print_date_range($date_start,$date_end)
* \param file Chemin du fichier image à redimensionner
* \param maxWidth Largeur maximum que dois faire la miniature (160 par défaut)
* \param maxHeight Hauteur maximum que dois faire l'image (120 par défaut)
* \param extName Extension pour différencier le nom de la vignette
* \param quality Qualité de compression jpeg
* \return imgThumbName Chemin de la vignette
*/
function vignette($file, $maxWidth = 160, $maxHeight = 120){
function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50){
// Vérification des erreurs dans les paramètres de la fonction
//============================================================
@ -2961,7 +2961,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){
// Si le fichier passé en paramètre n'existe pas
return 'Le fichier '.$file.' n\'a pas été trouvé sur le serveur.';
}
elseif(!eregi('(\.jpg|\.png)$',$file))
elseif(!eregi('(\.jpg|\.jpeg|\.png)$',$file))
{
// Todo: Ajouter création vignette pour les autres formats d'images
return 'Le fichier '.$file.' n\'ai pas géré pour le moment.';
@ -3035,7 +3035,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){
imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insère l'image de base redimensionnée
$fileName = basename($file, $extImg); // Nom du fichier sans son extension
$imgThumbName = $dirthumb.$fileName.'_small'.$extImg; // Chemin complet du fichier de la vignette
$imgThumbName = $dirthumb.$fileName.$extName.$extImg; // Chemin complet du fichier de la vignette
//Création du fichier de la vignette
$fp = fopen($imgThumbName, "w");
@ -3044,7 +3044,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){
// Renvoi la vignette créée
switch($infoImg[2]){
case 2:
imagejpeg($imgThumb, $imgThumbName, 50); // Renvoi d'une image jpeg avec une qualité de 50
imagejpeg($imgThumb, $imgThumbName, $quality); // Renvoi d'une image jpeg avec une qualité de 50
break;
case 3:
imagepng($imgThumb, $imgThumbName);

View File

@ -269,6 +269,8 @@ $mysoc->forme_juridique_code=$conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
$mysoc->email=$conf->global->MAIN_INFO_SOCIETE_MAIL;
$mysoc->adresse_full=$mysoc->adresse."\n".$mysoc->cp." ".$mysoc->ville;
$mysoc->logo=$conf->global->MAIN_INFO_SOCIETE_LOGO;
$mysoc->logo_small=$conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
$mysoc->logo_mini=$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
// Sert uniquement dans module telephonie

View File

@ -217,7 +217,7 @@ if ($_GET["id"] || $_GET["ref"])
print '<br>';
// On propose la génération de la vignette si elle n'existe pas et si la taille est supérieure aux limites
if (!$obj['photo_vignette'] && eregi('(\.jpg|\.png)$',$obj['photo']) && ($product->imgWidth > $maxWidth || $product->imgHeight > $maxHeight))
if (!$obj['photo_vignette'] && eregi('(\.jpg|\.jpeg|\.png)$',$obj['photo']) && ($product->imgWidth > $maxWidth || $product->imgHeight > $maxHeight))
{
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=addthumb&amp;file='.urlencode($pdir.$viewfilename).'">'.img_refresh($langs->trans('GenerateThumb')).'&nbsp;&nbsp;</a>';
}

View File

@ -62,20 +62,22 @@ if ($modulepart)
// Wrapping pour les photo utilisateurs
if ($modulepart == 'companylogo')
{
$accessallowed=1;
//}
$original_file=$conf->societe->dir_logos.'/'.$original_file;
$accessallowed=1;
if (eregi('_small',$original_file) || eregi('_mini',$original_file))
{
$original_file=$conf->societe->dir_logos.'/thumbs/'.$original_file;
}
else
{
$original_file=$conf->societe->dir_logos.'/'.$original_file;
}
}
// Wrapping pour les photos utilisateurs
if ($modulepart == 'userphoto')
{
//$user->getrights('facture');
//if ($user->rights->facture->lire)
//{
$accessallowed=1;
//}
$original_file=$conf->users->dir_output.'/'.$original_file;
$accessallowed=1;
$original_file=$conf->users->dir_output.'/'.$original_file;
}
// Wrapping pour les apercu factures