Fix: Photo for users and members were saved with .jpg even if .png

This commit is contained in:
Laurent Destailleur 2010-02-13 22:32:12 +00:00
parent d5c786d805
commit 4801f576da
2 changed files with 30 additions and 9 deletions

View File

@ -86,6 +86,7 @@ class User extends CommonObject
var $datelastlogin;
var $datepreviouslogin;
var $statut;
var $photo;
var $lang;
var $userpref_limite_liste;
@ -153,7 +154,8 @@ class User extends CommonObject
$sql.= " u.datec as datec,";
$sql.= " u.tms as datem,";
$sql.= " u.datelastlogin as datel,";
$sql.= " u.datepreviouslogin as datep";
$sql.= " u.datepreviouslogin as datep,";
$sql.= " u.photo as photo";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
if ($sid)
@ -197,6 +199,7 @@ class User extends CommonObject
$this->admin = $obj->admin;
$this->note = $obj->note;
$this->statut = $obj->statut;
$this->photo = $obj->photo;
$this->lang = $obj->lang;
$this->entity = $obj->entity;
@ -1023,6 +1026,7 @@ class User extends CommonObject
$sql.= ", phenix_login = '".addslashes($this->phenix_login)."'";
$sql.= ", phenix_pass = '".addslashes($this->phenix_pass)."'";
$sql.= ", note = '".addslashes($this->note)."'";
$sql.= ", photo = ".($this->photo?"'".addslashes($this->photo)."'":"null");
//$sql.= ", entity = '".$this->entity."'";
$sql.= " WHERE rowid = ".$this->id;

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
@ -31,6 +31,7 @@ require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/user.class.php");
require_once(DOL_DOCUMENT_ROOT."/usergroup.class.php");
require_once(DOL_DOCUMENT_ROOT."/contact.class.php");
require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php");
if ($conf->ldap->enabled) require_once(DOL_DOCUMENT_ROOT."/lib/ldap.class.php");
if ($conf->adherent->enabled) require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php");
@ -70,6 +71,11 @@ $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
$form = new Form($db);
// Define size of logo small and mini (might be set into other pages)
$maxwidthsmall=270;$maxheightsmall=150;
$maxwidthmini=128;$maxheightmini=72;
$quality = 80;
/**
@ -254,6 +260,8 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $caneditfield)
$edituser->phenix_pass = $_POST["phenix_pass"];
$edituser->entity = $_POST["entity"];
$edituser->photo = $_FILES['photo']['name'];
$ret=$edituser->update($user);
if ($ret < 0)
{
@ -281,18 +289,27 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $caneditfield)
{
if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name']))
{
// If photo is provided
if (! is_dir($conf->user->dir_output))
$dir= $conf->user->dir_output . '/' . get_exdir($edituser->id,2,0,1);
create_exdir($dir);
if (@is_dir($dir))
{
create_exdir($conf->user->dir_output);
}
if (is_dir($conf->user->dir_output))
{
$newfile=$conf->user->dir_output . "/" . $edituser->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);
}
}
}
}