From 4801f576daf4cae50206b260c6b5189efad57f22 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 13 Feb 2010 22:32:12 +0000 Subject: [PATCH] Fix: Photo for users and members were saved with .jpg even if .png --- htdocs/user.class.php | 6 +++++- htdocs/user/fiche.php | 33 +++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/htdocs/user.class.php b/htdocs/user.class.php index ad19fd4d5eb..d36545c54d5 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -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; diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index 02de3862d31..66ffe4425fa 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -1,7 +1,7 @@ * Copyright (C) 2002-2003 Jean-Louis Bergamo - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2005 Lionel Cousteix @@ -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 .= '
'.$langs->trans("ErrorFailedToSaveFile").'
'; } + 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); + } } } }