2
0
forked from Wavyzz/dolibarr

NEW Show photo of user into user list. A new function

getImageFileNameForSize was also introduced to choose image best size
according to usage to save bandwith.
This commit is contained in:
Laurent Destailleur
2015-10-25 19:31:13 +01:00
parent 1261ad43a1
commit b49d63c12f
8 changed files with 99 additions and 29 deletions

View File

@@ -5254,11 +5254,11 @@ class Form
* @param int $height Height of photo (auto if 0) * @param int $height Height of photo (auto if 0)
* @param int $caneditfield Add edit fields * @param int $caneditfield Add edit fields
* @param string $cssclass CSS name to use on img for photo * @param string $cssclass CSS name to use on img for photo
* @param int $genericifundef Use a generic image if no image avaiable * @param string $imagesize 'mini', 'small' or '' (original)
* @param int $addlinktofullsize Add link to fullsize image * @param int $addlinktofullsize Add link to fullsize image
* @return string HTML code to output photo * @return string HTML code to output photo
*/ */
static function showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $genericifundef=0,$addlinktofullsize=1) static function showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $imagesize='',$addlinktofullsize=1)
{ {
global $conf,$langs; global $conf,$langs;
@@ -5272,29 +5272,52 @@ class Form
$dir=$conf->societe->multidir_output[$entity]; $dir=$conf->societe->multidir_output[$entity];
$smallfile=$object->logo; $smallfile=$object->logo;
$smallfile=preg_replace('/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i','_small\\1',$smallfile); $smallfile=preg_replace('/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i','_small\\1',$smallfile);
if (! empty($object->logo)) $file=$id.'/logos/thumbs/'.$smallfile; if (! empty($object->logo))
{
if ($imagesize == 'mini') $file=$id.'/logos/thumbs/'.getImageFileNameForSize($object->logo, '_mini');
else if ($imagesize == 'small') $file=$id.'/logos/thumbs/'.getImageFileNameForSize($object->logo, '_small');
else $file=$id.'/logos/thumbs/'.$smallfile;
}
} }
else if ($modulepart=='contact') else if ($modulepart=='contact')
{ {
$dir=$conf->societe->multidir_output[$entity].'/contact'; $dir=$conf->societe->multidir_output[$entity].'/contact';
$file=$id.'/photos/'.$object->photo; if (! empty($object->photo))
{
if ($imagesize == 'mini') $file=$id.'/photos/thumbs/'.getImageFileNameForSize($object->photo, '_mini');
else if ($imagesize == 'small') $file=$id.'/photos/thumbs/'.getImageFileNameForSize($object->photo, '_small');
else $file=$id.'/photos/'.$object->photo;
}
} }
else if ($modulepart=='userphoto') else if ($modulepart=='userphoto')
{ {
$dir=$conf->user->dir_output; $dir=$conf->user->dir_output;
if (! empty($object->photo)) $file=get_exdir($id, 2, 0, 0, $object, 'user').$object->photo; if (! empty($object->photo))
{
//var_dump(getImageFileNameForSize($object->photo, '_mini'));
if ($imagesize == 'mini') $file=get_exdir($id, 2, 0, 0, $object, 'user').getImageFileNameForSize($object->photo, '_mini');
else if ($imagesize == 'small') $file=get_exdir($id, 2, 0, 0, $object, 'user').getImageFileNameForSize($object->photo, '_small');
else $file=get_exdir($id, 2, 0, 0, $object, 'user').$object->photo;
}
if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
$email=$object->email; $email=$object->email;
} }
else if ($modulepart=='memberphoto') else if ($modulepart=='memberphoto')
{ {
$dir=$conf->adherent->dir_output; $dir=$conf->adherent->dir_output;
if (! empty($object->photo)) $file=get_exdir($id, 2, 0, 0, $object, 'invoice_supplier').'photos/'.$object->photo; if (! empty($object->photo))
{
if ($imagesize == 'mini') $file=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_mini');
else if ($imagesize == 'small') $file=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_small');
else $file=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.$object->photo;
}
if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
$email=$object->email; $email=$object->email;
} else { }
else
{
$dir=$conf->$modulepart->dir_output; $dir=$conf->$modulepart->dir_output;
if (! empty($object->photo)) $file=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.$object->photo; if (! empty($object->photo)) $file=get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.$object->photo;
if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
$email=$object->email; $email=$object->email;
} }

View File

@@ -5223,3 +5223,33 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0)
return $res; return $res;
} }
/**
* Return the filename of file to get the thumbs
*
* @param string $file Original filename
* @param string $extName Extension to differenciate thumb file name ('', '_small', '_mini')
* @param string $extImgTarget Force image format for thumbs. Use '' to keep same extension than original image.
* @return string New file name
*/
function getImageFileNameForSize($file, $extName, $extImgTarget='')
{
$dirName = dirname($file);
if ($dirName == '.') $dirName='';
$fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file); // On enleve extension quelquesoit la casse
$fileName = basename($fileName);
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpg$/i',$file)?'.jpg':'');
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpeg$/i',$file)?'.jpeg':'');
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.gif$/i',$file)?'.gif':'');
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.png$/i',$file)?'.png':'');
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.bmp$/i',$file)?'.bmp':'');
if (! $extImgTarget) return $file;
$subdir='';
if ($extName) $subdir = 'thumbs/';
return $dirName.$subdir.$fileName.$extName.$extImgTarget; // New filename for thumb
}

View File

@@ -483,7 +483,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
break; break;
case IMAGETYPE_JPEG: // 2 case IMAGETYPE_JPEG: // 2
$trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
$extImgTarget = (preg_match('/\.jpeg$/',$file)?'.jpeg':'.jpg'); $extImgTarget = (preg_match('/\.jpeg$/i',$file)?'.jpeg':'.jpg');
$newquality=$quality; $newquality=$quality;
break; break;
case IMAGETYPE_PNG: // 3 case IMAGETYPE_PNG: // 3
@@ -512,7 +512,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 = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file); // On enleve extension quelquesoit la casse
$fileName = basename($fileName); $fileName = basename($fileName);
$imgThumbName = $dirthumb.'/'.$fileName.$extName.$extImgTarget; // Chemin complet du fichier de la vignette $imgThumbName = $dirthumb.'/'.getImageFileNameForSize($file, $extName, $extImgTarget); // Chemin complet du fichier de la vignette
// Check if permission are ok // Check if permission are ok
//$fp = fopen($imgThumbName, "w"); //$fp = fopen($imgThumbName, "w");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 607 B

After

Width:  |  Height:  |  Size: 651 B

View File

@@ -1848,7 +1848,7 @@ class User extends CommonObject
* @param integer $notooltip 1=Disable tooltip on picto and name * @param integer $notooltip 1=Disable tooltip on picto and name
* @param int $maxlen Max length of visible user name * @param int $maxlen Max length of visible user name
* @param int $hidethirdpartylogo Hide logo of thirdparty if user is external user * @param int $hidethirdpartylogo Hide logo of thirdparty if user is external user
* @param string $mode 'firstname'=Show only firstname * @param string $mode ''=Show firstname and lastname, 'firstname'=Show only firstname, 'login'=Show login
* @param string $morecss Add more css on link * @param string $morecss Add more css on link
* @return string String with URL * @return string String with URL
*/ */
@@ -1885,7 +1885,7 @@ class User extends CommonObject
if (! empty($this->photo)) if (! empty($this->photo))
{ {
$label.= '<div class="photointooltip">'; $label.= '<div class="photointooltip">';
$label.= Form::showphoto('userphoto', $this, 80, 0, 0, 'photowithmargin photologintooltip'); $label.= Form::showphoto('userphoto', $this, 80, 0, 0, 'photowithmargin photologintooltip', 'small');
$label.= '</div><div style="clear: both;"></div>'; $label.= '</div><div style="clear: both;"></div>';
} }
@@ -1932,13 +1932,14 @@ class User extends CommonObject
$paddafterimage=''; $paddafterimage='';
if (abs($withpictoimg) == 1) $paddafterimage='style="padding-right: 3px;"'; if (abs($withpictoimg) == 1) $paddafterimage='style="padding-right: 3px;"';
if ($withpictoimg > 0) $picto='<div class="inline-block valignmiddle'.($morecss?' userimg'.$morecss:'').'">'.img_object('', 'user', $paddafterimage.' '.($notooltip?'':'class="classfortooltip"')).'</div>'; if ($withpictoimg > 0) $picto='<div class="inline-block valignmiddle'.($morecss?' userimg'.$morecss:'').'">'.img_object('', 'user', $paddafterimage.' '.($notooltip?'':'class="classfortooltip"')).'</div>';
else $picto='<div class="inline-block valignmiddle'.($morecss?' userimg'.$morecss:'').'"'.($paddafterimage?' '.$paddafterimage:'').'>'.Form::showphoto('userphoto', $this, 0, 0, 0, 'loginphoto',0,0).'</div>'; else $picto='<div class="inline-block valignmiddle'.($morecss?' userimg'.$morecss:'').'"'.($paddafterimage?' '.$paddafterimage:'').'>'.Form::showphoto('userphoto', $this, 0, 0, 0, 'loginphoto', 0, 0, 'mini').'</div>';
$result.=$picto; $result.=$picto;
} }
if (abs($withpictoimg) != 2) if (abs($withpictoimg) != 2)
{ {
if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result.='<div class="inline-block valignmiddle'.($morecss?' usertext'.$morecss:'').'">'; if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result.='<div class="inline-block valignmiddle'.($morecss?' usertext'.$morecss:'').'">';
$result.=$this->getFullName($langs,'',($mode == 'firstname' ? 2 : -1),$maxlen); if ($mode == 'login') $result.=dol_trunc($this->login, $maxlen);
else $result.=$this->getFullName($langs,'',($mode == 'firstname' ? 2 : -1),$maxlen);
if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result.='</div>'; if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result.='</div>';
} }
$result.=$linkend; $result.=$linkend;
@@ -2398,7 +2399,7 @@ class User extends CommonObject
$this->load_parentof(); $this->load_parentof();
// Init $this->users array // Init $this->users array
$sql = "SELECT DISTINCT u.rowid, u.firstname, u.lastname, u.fk_user, u.fk_soc, u.login, u.email, u.gender, u.admin, u.statut, u.entity"; // Distinct reduce pb with old tables with duplicates $sql = "SELECT DISTINCT u.rowid, u.firstname, u.lastname, u.fk_user, u.fk_soc, u.login, u.email, u.gender, u.admin, u.statut, u.photo, u.entity"; // Distinct reduce pb with old tables with duplicates
$sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && (! empty($conf->multicompany->transverse_mode) || (! empty($user->admin) && empty($user->entity)))) if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && (! empty($conf->multicompany->transverse_mode) || (! empty($user->admin) && empty($user->entity))))
{ {
@@ -2429,6 +2430,7 @@ class User extends CommonObject
$this->users[$obj->rowid]['email'] = $obj->email; $this->users[$obj->rowid]['email'] = $obj->email;
$this->users[$obj->rowid]['gender'] = $obj->gender; $this->users[$obj->rowid]['gender'] = $obj->gender;
$this->users[$obj->rowid]['admin'] = $obj->admin; $this->users[$obj->rowid]['admin'] = $obj->admin;
$this->users[$obj->rowid]['photo'] = $obj->photo;
$i++; $i++;
} }
} }

View File

@@ -94,7 +94,7 @@ if ($resql)
print_liste_field_titre($langs->trans("Entity"),$_SERVER["PHP_SELF"],"g.entity",$param,"",'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Entity"),$_SERVER["PHP_SELF"],"g.entity",$param,"",'align="center"',$sortfield,$sortorder);
} }
print_liste_field_titre($langs->trans("NbOfUsers"),$_SERVER["PHP_SELF"],"nb",$param,"",'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("NbOfUsers"),$_SERVER["PHP_SELF"],"nb",$param,"",'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"g.datec",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateCreationShort"),$_SERVER["PHP_SELF"],"g.datec",$param,"",'align="right"',$sortfield,$sortorder);
print "</tr>\n"; print "</tr>\n";
$var=True; $var=True;
while ($i < $num) while ($i < $num)

View File

@@ -82,6 +82,7 @@ foreach($fulltree as $key => $val)
{ {
$userstatic->id=$val['id']; $userstatic->id=$val['id'];
$userstatic->ref=$val['label']; $userstatic->ref=$val['label'];
$userstatic->login=$val['login'];
$userstatic->firstname=$val['firstname']; $userstatic->firstname=$val['firstname'];
$userstatic->lastname=$val['lastname']; $userstatic->lastname=$val['lastname'];
$userstatic->statut=$val['statut']; $userstatic->statut=$val['statut'];
@@ -90,6 +91,7 @@ foreach($fulltree as $key => $val)
$userstatic->societe_id=$val['fk_soc']; $userstatic->societe_id=$val['fk_soc'];
$userstatic->admin=$val['admin']; $userstatic->admin=$val['admin'];
$userstatic->entity=$val['entity']; $userstatic->entity=$val['entity'];
$userstatic->photo=$val['photo'];
$entity=$val['entity']; $entity=$val['entity'];
$entitystring=''; $entitystring='';
@@ -111,7 +113,7 @@ foreach($fulltree as $key => $val)
} }
} }
$li=$userstatic->getNomUrl(1,'',0,1); $li=$userstatic->getNomUrl(-1,'',0,1);
if (! empty($conf->multicompany->enabled) && $userstatic->admin && ! $userstatic->entity) if (! empty($conf->multicompany->enabled) && $userstatic->admin && ! $userstatic->entity)
{ {
$li.=img_picto($langs->trans("SuperAdministrator"),'redstar'); $li.=img_picto($langs->trans("SuperAdministrator"),'redstar');
@@ -126,7 +128,7 @@ foreach($fulltree as $key => $val)
'rowid'=>$val['rowid'], 'rowid'=>$val['rowid'],
'fk_menu'=>$val['fk_user'], 'fk_menu'=>$val['fk_user'],
'statut'=>$val['statut'], 'statut'=>$val['statut'],
'entry'=>'<table class="nobordernopadding centpercent"><tr><td class="'.($val['statut']?'usertdenabled':'usertddisabled').'">'.$li.'</td><td align="right" class="'.($val['statut']?'usertdenabled':'usertddisabled').'">'.$userstatic->getLibStatut(5).'</td></tr></table>' 'entry'=>'<table class="nobordernopadding centpercent"><tr><td class="'.($val['statut']?'usertdenabled':'usertddisabled').'">'.$li.'</td><td align="right" class="'.($val['statut']?'usertdenabled':'usertddisabled').'">'.$userstatic->getLibStatut(3).'</td></tr></table>'
); );
} }

View File

@@ -124,11 +124,11 @@ $buttonviewhierarchy='<form action="'.DOL_URL_ROOT.'/user/hierarchy.php'.(($sear
print load_fiche_titre($langs->trans("ListOfUsers"), $buttonviewhierarchy); print load_fiche_titre($langs->trans("ListOfUsers"), $buttonviewhierarchy);
$sql = "SELECT u.rowid, u.lastname, u.firstname, u.admin, u.fk_soc, u.login, u.email, u.gender,"; $sql = "SELECT u.rowid, u.lastname, u.firstname, u.admin, u.fk_soc, u.login, u.email, u.gender, u.photo,";
$sql.= " u.datelastlogin, u.datepreviouslogin,"; $sql.= " u.datelastlogin, u.datepreviouslogin,";
$sql.= " u.ldap_sid, u.statut, u.entity,"; $sql.= " u.ldap_sid, u.statut, u.entity,";
$sql.= " u.tms as date_update, u.datec as date_creation,"; $sql.= " u.tms as date_update, u.datec as date_creation,";
$sql.= " u2.login as login2, u2.firstname as firstname2, u2.lastname as lastname2,"; $sql.= " u2.rowid as id2, u2.login as login2, u2.firstname as firstname2, u2.lastname as lastname2, u2.admin as admin2, u2.fk_soc as fk_soc2, u2.email as email2, u2.gender as gender2, u2.photo as photo2, u2.entity as entity2,";
$sql.= " s.nom as name, s.canvas"; $sql.= " s.nom as name, s.canvas";
// Add fields from extrafields // Add fields from extrafields
foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key; foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key;
@@ -341,10 +341,11 @@ if ($result)
$userstatic->email=$obj->email; $userstatic->email=$obj->email;
$userstatic->gender=$obj->gender; $userstatic->gender=$obj->gender;
$userstatic->societe_id=$obj->fk_soc; $userstatic->societe_id=$obj->fk_soc;
$userstatic->firstname=''; $userstatic->firstname=$obj->firstname;
$userstatic->lastname=$obj->login; $userstatic->lastname=$obj->lastname;
$userstatic->photo=$obj->photo;
$li=$userstatic->getNomUrl(1,'',0,0,24,1); $li=$userstatic->getNomUrl(-1,'',0,0,24,1,'login');
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
if (! empty($arrayfields['u.login']['checked'])) if (! empty($arrayfields['u.login']['checked']))
@@ -418,12 +419,24 @@ if ($result)
print '<td class="nowrap">'; print '<td class="nowrap">';
if ($obj->login2) if ($obj->login2)
{ {
$user2->id=$obj->id2;
$user2->login=$obj->login2; $user2->login=$obj->login2;
//$user2->lastname=$obj->lastname2; $user2->lastname=$obj->lastname2;
//$user2->firstname=$obj->firstname2; $user2->firstname=$obj->firstname2;
$user2->lastname=$user2->login; $user2->gender=$obj->gender2;
$user2->firstname=''; $user2->photo=$obj->photo2;
print $user2->getNomUrl(1); $user2->admin=$obj->admin2;
$user2->email=$obj->email2;
$user2->societe_id=$obj->fk_soc2;
print $user2->getNomUrl(-1,'',0,0,24,0,'');
if (! empty($conf->multicompany->enabled) && $obj->admin2 && ! $obj->entity2)
{
print img_picto($langs->trans("SuperAdministrator"),'redstar');
}
else if ($obj->admin2)
{
print img_picto($langs->trans("Administrator"),'star');
}
} }
print '</td>'; print '</td>';
} }