Merge pull request #4834 from hregis/3.9_bug
Fix: beware with merges in conflict !!
This commit is contained in:
commit
bbcc7d83ea
@ -3,7 +3,7 @@
|
||||
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
|
||||
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||
* Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2005-2016 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
|
||||
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
|
||||
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
|
||||
@ -298,220 +298,200 @@ if (empty($reshook)) {
|
||||
{
|
||||
$error = 0;
|
||||
|
||||
if (!$_POST["lastname"]) {
|
||||
setEventMessages($langs->trans("NameNotDefined"), null, 'errors');
|
||||
$action = "edit"; // Go back to create page
|
||||
$error ++;
|
||||
}
|
||||
if (!$_POST["login"]) {
|
||||
setEventMessages($langs->trans("LoginNotDefined"), null, 'errors');
|
||||
$action = "edit"; // Go back to create page
|
||||
$error ++;
|
||||
}
|
||||
if (!$_POST["lastname"]) {
|
||||
setEventMessages($langs->trans("NameNotDefined"), null, 'errors');
|
||||
$action = "edit"; // Go back to create page
|
||||
$error ++;
|
||||
}
|
||||
if (!$_POST["login"]) {
|
||||
setEventMessages($langs->trans("LoginNotDefined"), null, 'errors');
|
||||
$action = "edit"; // Go back to create page
|
||||
$error ++;
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$object->fetch($id);
|
||||
if (!$error) {
|
||||
$object->fetch($id);
|
||||
|
||||
$object->oldcopy = clone $object;
|
||||
$object->oldcopy = clone $object;
|
||||
|
||||
if (!$error) {
|
||||
$db->begin();
|
||||
if (!$error) {
|
||||
$db->begin();
|
||||
|
||||
$object->oldcopy = dol_clone($object);
|
||||
$object->oldcopy = dol_clone($object);
|
||||
|
||||
$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->api_key = (GETPOST("api_key", 'alpha')) ? GETPOST("api_key", 'alpha') : $object->api_key;
|
||||
$object->admin = empty($user->admin) ? 0 : GETPOST("admin"); // A user can only be set admin by an admin
|
||||
$object->address = GETPOST('address', 'alpha');
|
||||
$object->zip = GETPOST('zipcode', 'alpha');
|
||||
$object->town = GETPOST('town', 'alpha');
|
||||
$object->country_id = GETPOST('country_id', 'int');
|
||||
$object->state_id = GETPOST('state_id', 'int');
|
||||
$object->office_phone = GETPOST("office_phone", 'alpha');
|
||||
$object->office_fax = GETPOST("office_fax", 'alpha');
|
||||
$object->user_mobile = GETPOST("user_mobile");
|
||||
$object->skype = GETPOST("skype", 'alpha');
|
||||
$object->email = GETPOST("email", 'alpha');
|
||||
$object->job = GETPOST("job", 'alpha');
|
||||
$object->signature = GETPOST("signature");
|
||||
$object->accountancy_code = GETPOST("accountancy_code");
|
||||
$object->openid = GETPOST("openid");
|
||||
$object->fk_user = GETPOST("fk_user") > 0 ? GETPOST("fk_user") : 0;
|
||||
$object->employee = GETPOST('employee');
|
||||
$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->api_key = (GETPOST("api_key", 'alpha')) ? GETPOST("api_key", 'alpha') : $object->api_key;
|
||||
$object->admin = empty($user->admin) ? 0 : GETPOST("admin"); // A user can only be set admin by an admin
|
||||
$object->address = GETPOST('address', 'alpha');
|
||||
$object->zip = GETPOST('zipcode', 'alpha');
|
||||
$object->town = GETPOST('town', 'alpha');
|
||||
$object->country_id = GETPOST('country_id', 'int');
|
||||
$object->state_id = GETPOST('state_id', 'int');
|
||||
$object->office_phone = GETPOST("office_phone", 'alpha');
|
||||
$object->office_fax = GETPOST("office_fax", 'alpha');
|
||||
$object->user_mobile = GETPOST("user_mobile");
|
||||
$object->skype = GETPOST("skype", 'alpha');
|
||||
$object->email = GETPOST("email", 'alpha');
|
||||
$object->job = GETPOST("job", 'alpha');
|
||||
$object->signature = GETPOST("signature");
|
||||
$object->accountancy_code = GETPOST("accountancy_code");
|
||||
$object->openid = GETPOST("openid");
|
||||
$object->fk_user = GETPOST("fk_user") > 0 ? GETPOST("fk_user") : 0;
|
||||
$object->employee = GETPOST('employee');
|
||||
|
||||
$object->thm = GETPOST("thm") != '' ? GETPOST("thm") : '';
|
||||
$object->tjm = GETPOST("tjm") != '' ? GETPOST("tjm") : '';
|
||||
$object->salary = GETPOST("salary") != '' ? GETPOST("salary") : '';
|
||||
$object->salaryextra = GETPOST("salaryextra") != '' ? GETPOST("salaryextra") : '';
|
||||
$object->weeklyhours = GETPOST("weeklyhours") != '' ? GETPOST("weeklyhours") : '';
|
||||
$object->thm = GETPOST("thm") != '' ? GETPOST("thm") : '';
|
||||
$object->tjm = GETPOST("tjm") != '' ? GETPOST("tjm") : '';
|
||||
$object->salary = GETPOST("salary") != '' ? GETPOST("salary") : '';
|
||||
$object->salaryextra = GETPOST("salaryextra") != '' ? GETPOST("salaryextra") : '';
|
||||
$object->weeklyhours = GETPOST("weeklyhours") != '' ? GETPOST("weeklyhours") : '';
|
||||
|
||||
if (! empty($conf->multicompany->enabled))
|
||||
{
|
||||
if (! empty($_POST["superadmin"]))
|
||||
{
|
||||
$object->entity = 0;
|
||||
}
|
||||
else if ($conf->multicompany->transverse_mode)
|
||||
{
|
||||
$object->entity = 1; // all users in master entity
|
||||
}
|
||||
else
|
||||
{
|
||||
$object->entity = (! GETPOST('entity', 'int') ? 0 : GETPOST('entity', 'int'));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$object->entity = (! GETPOST('entity', 'int') ? 0 : GETPOST('entity', 'int'));
|
||||
}
|
||||
$object->color = GETPOST("color") != '' ? GETPOST("color") : '';
|
||||
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
|
||||
if ($ret < 0) {
|
||||
$error ++;
|
||||
}
|
||||
if (! empty($conf->multicompany->enabled))
|
||||
{
|
||||
if (! empty($_POST["superadmin"]))
|
||||
{
|
||||
$object->entity = 0;
|
||||
}
|
||||
else if ($conf->multicompany->transverse_mode)
|
||||
{
|
||||
$object->entity = 1; // all users in master entity
|
||||
}
|
||||
else
|
||||
{
|
||||
$object->entity = (! GETPOST('entity', 'int') ? 0 : GETPOST('entity', 'int'));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$object->entity = (! GETPOST('entity', 'int') ? 0 : GETPOST('entity', 'int'));
|
||||
}
|
||||
|
||||
if (!empty($conf->multicompany->enabled)) {
|
||||
if (!empty($_POST["superadmin"])) {
|
||||
$object->entity = 0;
|
||||
} else {
|
||||
if ($conf->multicompany->transverse_mode) {
|
||||
$object->entity = 1; // all users in master entity
|
||||
} else {
|
||||
$object->entity = (empty($_POST["entity"]) ? 0 : $_POST["entity"]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$object->entity = (empty($_POST["entity"]) ? 0 : $_POST["entity"]);
|
||||
}
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
|
||||
if ($ret < 0) {
|
||||
$error ++;
|
||||
}
|
||||
|
||||
if (GETPOST('deletephoto')) {
|
||||
$object->photo = '';
|
||||
}
|
||||
if (!empty($_FILES['photo']['name'])) {
|
||||
$object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
|
||||
}
|
||||
if (GETPOST('deletephoto')) {
|
||||
$object->photo = '';
|
||||
}
|
||||
if (!empty($_FILES['photo']['name'])) {
|
||||
$object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$ret = $object->update($user);
|
||||
if ($ret < 0) {
|
||||
$error ++;
|
||||
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorLoginAlreadyExists", $object->login), null, 'errors');
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$error) {
|
||||
$ret = $object->update($user);
|
||||
if ($ret < 0) {
|
||||
$error ++;
|
||||
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorLoginAlreadyExists", $object->login), null, 'errors');
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error && isset($_POST['contactid'])) {
|
||||
$contactid = GETPOST('contactid');
|
||||
if (!$error && isset($_POST['contactid'])) {
|
||||
$contactid = GETPOST('contactid', 'int');
|
||||
|
||||
if ($contactid > 0) {
|
||||
$contact = new Contact($db);
|
||||
$contact->fetch($contactid);
|
||||
if ($contactid > 0) {
|
||||
$contact = new Contact($db);
|
||||
$contact->fetch($contactid);
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
||||
$sql .= " SET fk_socpeople=".$db->escape($contactid);
|
||||
if ($contact->socid) {
|
||||
$sql .= ", fk_soc=".$db->escape($contact->socid);
|
||||
}
|
||||
$sql .= " WHERE rowid=".$object->id;
|
||||
} else {
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
||||
$sql .= " SET fk_socpeople=NULL, fk_soc=NULL";
|
||||
$sql .= " WHERE rowid=".$object->id;
|
||||
}
|
||||
dol_syslog("fiche::update", LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if (!$resql) {
|
||||
$error ++;
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
}
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
||||
$sql .= " SET fk_socpeople=".$db->escape($contactid);
|
||||
if (!empty($contact->socid)) {
|
||||
$sql .= ", fk_soc=".$db->escape($contact->socid);
|
||||
}
|
||||
$sql .= " WHERE rowid=".$object->id;
|
||||
} else {
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
||||
$sql .= " SET fk_socpeople=NULL, fk_soc=NULL";
|
||||
$sql .= " WHERE rowid=".$object->id;
|
||||
}
|
||||
dol_syslog("usercard::update", LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if (!$resql) {
|
||||
$error ++;
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error && !count($object->errors)) {
|
||||
if (GETPOST('deletephoto') && $object->photo) {
|
||||
$fileimg = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user').'/logos/'.$object->photo;
|
||||
$dirthumbs = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user').'/logos/thumbs';
|
||||
dol_delete_file($fileimg);
|
||||
dol_delete_dir_recursive($dirthumbs);
|
||||
}
|
||||
if (!$error && !count($object->errors)) {
|
||||
if (GETPOST('deletephoto') && $object->photo) {
|
||||
$fileimg = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user').'/logos/'.$object->photo;
|
||||
$dirthumbs = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user').'/logos/thumbs';
|
||||
dol_delete_file($fileimg);
|
||||
dol_delete_dir_recursive($dirthumbs);
|
||||
}
|
||||
|
||||
if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name'])) {
|
||||
$dir = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user');
|
||||
if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name'])) {
|
||||
$dir = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user');
|
||||
|
||||
dol_mkdir($dir);
|
||||
dol_mkdir($dir);
|
||||
|
||||
if (@is_dir($dir)) {
|
||||
$newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
|
||||
$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']);
|
||||
if (@is_dir($dir)) {
|
||||
$newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
|
||||
$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']);
|
||||
|
||||
if (!$result > 0) {
|
||||
setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
|
||||
} else {
|
||||
// Create small thumbs for company (Ratio is near 16/9)
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
|
||||
if (!$result > 0) {
|
||||
setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
|
||||
} 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);
|
||||
}
|
||||
} else {
|
||||
$error ++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
} else {
|
||||
$error ++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error && !count($object->errors)) {
|
||||
setEventMessages($langs->trans("UserModified"), null, 'mesgs');
|
||||
$db->commit();
|
||||
if (!$error && !count($object->errors)) {
|
||||
setEventMessages($langs->trans("UserModified"), null, 'mesgs');
|
||||
$db->commit();
|
||||
|
||||
$login = $_SESSION["dol_login"];
|
||||
if ($login && $login == $object->oldcopy->login && $object->oldcopy->login != $object->login) // Current user has changed its login
|
||||
{
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->transnoentitiesnoconv("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
|
||||
}
|
||||
} else {
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($caneditpassword) // Case we can edit only password
|
||||
{
|
||||
$object->fetch($id);
|
||||
$login = $_SESSION["dol_login"];
|
||||
if ($login && $login == $object->oldcopy->login && $object->oldcopy->login != $object->login) // Current user has changed its login
|
||||
{
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->transnoentitiesnoconv("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
|
||||
}
|
||||
} else {
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($caneditpassword) // Case we can edit only password
|
||||
{
|
||||
$object->fetch($id);
|
||||
|
||||
$object->oldcopy = dol_clone($object);
|
||||
$object->oldcopy = clone $object;
|
||||
|
||||
$ret = $object->setPassword($user, $_POST["password"]);
|
||||
if ($ret < 0)
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$object->oldcopy = clone $object;
|
||||
|
||||
$ret=$object->setPassword($user,$_POST["password"]);
|
||||
if ($ret < 0)
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
$ret = $object->setPassword($user, $_POST["password"]);
|
||||
if ($ret < 0)
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Change password with a new generated one
|
||||
if ((($action == 'confirm_password' && $confirm == 'yes')
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
* Copyright (c) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
||||
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
||||
* Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2005-2016 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
|
||||
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
|
||||
* Copyright (C) 2013-2014 Philippe Grand <philippe.grand@atoo-net.com>
|
||||
@ -1272,7 +1272,7 @@ class User extends CommonObject
|
||||
$nbrowsaffected+=$this->db->affected_rows($resql);
|
||||
|
||||
// Update password
|
||||
if ($this->pass)
|
||||
if (!empty($this->pass))
|
||||
{
|
||||
if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user