NEW Add gender property managed on user card

FIX Better error messages when uploading photo of user when permission
to write are not granted
This commit is contained in:
Laurent Destailleur 2015-05-30 02:17:05 +02:00
parent 6701b399ae
commit 13b78f9c17
4 changed files with 71 additions and 24 deletions

View File

@ -4788,11 +4788,12 @@ class Form
* @param string $modulepart Key to define module concerned ('societe', 'userphoto', 'memberphoto')
* @param object $object Object containing data to retrieve file name
* @param int $width Width of photo
* @param int $caneditfield Add edit fields
* @return string HTML code to output photo
*/
static function showphoto($modulepart,$object,$width=100)
static function showphoto($modulepart,$object,$width=100,$caneditfield=0)
{
global $conf;
global $conf,$langs;
$entity = (! empty($object->entity) ? $object->entity : $conf->entity);
$id = (! empty($object->id) ? $object->id : $object->rowid);
@ -4819,7 +4820,7 @@ class Form
if ($object->photo) $file=get_exdir($id, 2, 0, 0, $object, 'invoice_supplier').'photos/'.$object->photo;
if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
$email=$object->email;
}else {
} else {
$dir=$conf->$modulepart->dir_output;
if ($object->photo) $file=get_exdir($id, 2, 0, 0, $adherent, 'member').'photos/'.$object->photo;
if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
@ -4833,13 +4834,13 @@ class Form
{
// TODO Link to large image
$ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($file).'&cache='.$cache.'">';
$ret.='<img alt="Photo" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="photologo" border="0" width="'.$width.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($file).'&cache='.$cache.'">';
$ret.='<img alt="Photo" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="photologo" border="0"'.($width?' width="'.$width:'').'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($file).'&cache='.$cache.'">';
$ret.='</a>';
}
else if ($altfile && file_exists($dir."/".$altfile))
{
$ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($file).'&cache='.$cache.'">';
$ret.='<img alt="Photo alt" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="photologo" border="0" width="'.$width.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($altfile).'&cache='.$cache.'">';
$ret.='<img alt="Photo alt" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="photologo" border="0"'.($width?' width="'.$width:'').'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($altfile).'&cache='.$cache.'">';
$ret.='</a>';
}
else
@ -4848,13 +4849,24 @@ class Form
{
global $dolibarr_main_url_root;
$ret.='<!-- Put link to gravatar -->';
$ret.='<img alt="Photo found on Gravatar" title="Photo Gravatar.com - email '.$email.'" border="0" width="'.$width.'" src="http://www.gravatar.com/avatar/'.dol_hash($email,3).'?s='.$width.'&d='.urlencode(dol_buildpath('/theme/common/nophoto.jpg',2)).'">'; // gravatar need md5 hash
$ret.='<img alt="Photo found on Gravatar" title="Photo Gravatar.com - email '.$email.'" border="0"'.($width?' width="'.$width:'').'" src="http://www.gravatar.com/avatar/'.dol_hash($email,3).'?s='.$width.'&d='.urlencode(dol_buildpath('/theme/common/nophoto.jpg',2)).'">'; // gravatar need md5 hash
}
else
{
$ret.='<img alt="No photo" border="0" width="'.$width.'" src="'.DOL_URL_ROOT.'/theme/common/nophoto.jpg">';
$ret.='<img alt="No photo" border="0"'.($width?' width="'.$width:'').'" src="'.DOL_URL_ROOT.'/theme/common/nophoto.jpg">';
}
}
if ($caneditfield)
{
if ($object->photo) $ret.="<br>\n";
$ret.='<table class="nobordernopadding hideonsmartphone">';
if ($object->photo) $ret.='<tr><td align="center"><input type="checkbox" class="flat" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
$ret.='<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
$ret.='<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
$ret.='</table>';
}
}
else dol_print_error('','Call of showphoto with wrong parameters');

View File

@ -704,6 +704,8 @@ GoIntoSetupToChangeLogo=Go into Home - Setup - Company to change logo or go into
Deny=Deny
Denied=Denied
ListOfTemplates=List of templates
Genderman=Man
Genderwoman=Woman
# Week day
Monday=Monday
Tuesday=Tuesday

View File

@ -184,10 +184,12 @@ if ($action == 'add' && $canadduser)
}
}
if (!$error) {
if (!$error)
{
$object->lastname = GETPOST("lastname",'alpha');
$object->firstname = GETPOST("firstname",'alpha');
$object->login = GETPOST("login",'alpha');
$object->gender = GETPOST("gender",'alpha');
$object->admin = GETPOST("admin",'alpha');
$object->office_phone = GETPOST("office_phone",'alpha');
$object->office_fax = GETPOST("office_fax",'alpha');
@ -339,6 +341,7 @@ if ($action == 'update' && ! $_POST["cancel"])
$object->lastname = GETPOST("lastname",'alpha');
$object->firstname = GETPOST("firstname",'alpha');
$object->login = GETPOST("login",'alpha');
$object->gender = GETPOST("gender",'alpha');
$object->pass = GETPOST("password");
$object->admin = empty($user->admin)?0:GETPOST("admin"); // A user can only be set admin by an admin
$object->office_phone=GETPOST("office_phone",'alpha');
@ -449,7 +452,7 @@ if ($action == 'update' && ! $_POST["cancel"])
$dir= $conf->user->dir_output . '/' . get_exdir($object->id,2,0,1,$object,'user');
dol_mkdir($dir);
if (@is_dir($dir))
{
$newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
@ -470,6 +473,12 @@ if ($action == 'update' && ! $_POST["cancel"])
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
}
}
else
{
$error++;
$langs->load("errors");
setEventMessages($langs->trans("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
}
}
}
@ -756,6 +765,13 @@ if (($action == 'create') || ($action == 'adduserldap'))
print '<input size="30" type="text" name="job" value="'.GETPOST('job').'">';
print '</td></tr>';
// Gender
print '<tr><td>'.$langs->trans("Gender").'</td>';
print '<td>';
$arraygender=array('man'=>$langs->trans("Genderman"),'woman'=>$langs->trans("Genderwoman"));
print $form->selectarray('gender', $arraygender, GETPOST('gender'), 1);
print '</td></tr>';
// Login
print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").'</span></td>';
print '<td>';
@ -1030,8 +1046,12 @@ if (($action == 'create') || ($action == 'adduserldap'))
dol_fiche_end();
print '<div align="center"><input class="button" value="'.$langs->trans("CreateUser").'" name="create" type="submit"></div>';
print '<div align="center">';
print '<input class="button" value="'.$langs->trans("CreateUser").'" name="create" type="submit">';
//print '&nbsp; &nbsp; &nbsp;';
//print '<input value="'.$langs->trans("Cancel").'" class="button" type="submit" name="cancel">';
print '</div>';
print "</form>";
}
else
@ -1183,6 +1203,12 @@ else
print '<td colspan="2">'.$object->job.'</td>';
print '</tr>'."\n";
// Gender
print '<tr><td>'.$langs->trans("Gender").'</td>';
print '<td>';
if ($object->gender) print $langs->trans("Gender".$object->gender);
print '</td></tr>';
// Login
print '<tr><td>'.$langs->trans("Login").'</td>';
if (! empty($object->ldap_sid) && $object->statut==0)
@ -1681,7 +1707,7 @@ else
dol_fiche_head($head, 'user', $title, 0, 'user');
$rowspan=16;
$rowspan=17;
if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file->main_authentication) && ! empty($conf->global->MAIN_OPENIDURL_PERUSER)) $rowspan++;
if (! empty($conf->societe->enabled)) $rowspan++;
if (! empty($conf->adherent->enabled)) $rowspan++;
@ -1711,18 +1737,10 @@ else
print $object->lastname;
}
print '</td>';
// Photo
print '<td align="center" valign="middle" width="25%" rowspan="'.$rowspan.'">';
print $form->showphoto('userphoto',$object);
if ($caneditfield)
{
if ($object->photo) print "<br>\n";
print '<table class="nobordernopadding hideonsmartphone">';
if ($object->photo) print '<tr><td align="center"><input type="checkbox" class="flat" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
print '</table>';
}
print $form->showphoto('userphoto',$object,0,$caneditfield);
print '</td>';
print '</tr>';
@ -1755,6 +1773,13 @@ else
}
print '</td></tr>';
// Gender
print '<tr><td>'.$langs->trans("Gender").'</td>';
print '<td>';
$arraygender=array('man'=>$langs->trans("Genderman"),'woman'=>$langs->trans("Genderwoman"));
print $form->selectarray('gender', $arraygender, GETPOST('gender')?GETPOST('gender'):$object->gender, 1);
print '</td></tr>';
// Login
print "<tr>".'<td><span class="fieldrequired">'.$langs->trans("Login").'</span></td>';
print '<td>';

View File

@ -50,6 +50,7 @@ class User extends CommonObject
var $search_sid;
var $lastname;
var $firstname;
var $gender;
var $note;
var $email;
var $skype;
@ -151,7 +152,7 @@ class User extends CommonObject
$login=trim($login);
// Get user
$sql = "SELECT u.rowid, u.lastname, u.firstname, u.email, u.job, u.skype, u.signature, u.office_phone, u.office_fax, u.user_mobile,";
$sql = "SELECT u.rowid, u.lastname, u.firstname, u.gender, u.email, u.job, u.skype, u.signature, u.office_phone, u.office_fax, u.user_mobile,";
$sql.= " u.admin, u.login, u.note,";
$sql.= " u.pass, u.pass_crypted, u.pass_temp,";
$sql.= " u.fk_soc, u.fk_socpeople, u.fk_member, u.fk_user, u.ldap_sid,";
@ -212,6 +213,7 @@ class User extends CommonObject
$this->firstname = $obj->firstname;
$this->login = $obj->login;
$this->gender = $obj->gender;
$this->pass_indatabase = $obj->pass;
$this->pass_indatabase_crypted = $obj->pass_crypted;
$this->pass = $obj->pass;
@ -936,6 +938,7 @@ class User extends CommonObject
$this->admin = 0;
$this->lastname = $contact->lastname;
$this->firstname = $contact->firstname;
$this->gender = $contact->gender;
$this->email = $contact->email;
$this->skype = $contact->skype;
$this->office_phone = $contact->phone_pro;
@ -1007,6 +1010,7 @@ class User extends CommonObject
$this->admin = 0;
$this->lastname = $member->lastname;
$this->firstname = $member->firstname;
$this->gender = $member->gender;
$this->email = $member->email;
$this->fk_member = $member->id;
$this->pass = $member->pass;
@ -1129,6 +1133,7 @@ class User extends CommonObject
$this->lastname = trim($this->lastname);
$this->firstname = trim($this->firstname);
$this->login = trim($this->login);
$this->gender = trim($this->gender);
$this->pass = trim($this->pass);
$this->office_phone = trim($this->office_phone);
$this->office_fax = trim($this->office_fax);
@ -1156,11 +1161,12 @@ class User extends CommonObject
$this->db->begin();
// Mise a jour autres infos
// Update datas
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
$sql.= " lastname = '".$this->db->escape($this->lastname)."'";
$sql.= ", firstname = '".$this->db->escape($this->firstname)."'";
$sql.= ", login = '".$this->db->escape($this->login)."'";
$sql.= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
$sql.= ", admin = ".$this->admin;
$sql.= ", address = '".$this->db->escape($this->address)."'";
$sql.= ", zip = '".$this->db->escape($this->zip)."'";
@ -1235,6 +1241,7 @@ class User extends CommonObject
$adh->firstname=$this->firstname;
$adh->lastname=$this->lastname;
$adh->login=$this->login;
$adh->gender=$this->gender;
$adh->pass=$this->pass;
$adh->societe=(empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe);
@ -2047,6 +2054,7 @@ class User extends CommonObject
$this->lastname='DOLIBARR';
$this->firstname='SPECIMEN';
$this->gender='man';
$this->note='This is a note';
$this->email='email@specimen.com';
$this->skype='tom.hanson';