Merge pull request #3714 from marcosgdf/doactions-usercard

NEW Add doActions hooks to user card
This commit is contained in:
Laurent Destailleur 2015-10-15 12:05:26 +02:00
commit cee0364a1a
8 changed files with 538 additions and 531 deletions

View File

@ -66,61 +66,69 @@ $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
if (($object->id != $user->id) && (! $user->rights->user->user->lire)) if (($object->id != $user->id) && (! $user->rights->user->user->lire))
accessforbidden(); accessforbidden();
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('usercard','globalcard'));
/* /*
* Actions * Actions
*/ */
if ($actionsave)
{ $parameters=array('id'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) {
if ($actionsave) {
$db->begin(); $db->begin();
$i=1; $errorsaved=0; $i = 1;
$errorsaved = 0;
$error = 0; $error = 0;
$tabparam = array(); $tabparam = array();
// Save agendas // Save agendas
while ($i <= $MAXAGENDA) while ($i <= $MAXAGENDA) {
{
$name = trim(GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$i, 'alpha')); $name = trim(GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$i, 'alpha'));
$src = trim(GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$i, 'alpha')); $src = trim(GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$i, 'alpha'));
$offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i, 'alpha')); $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i, 'alpha'));
$color = trim(GETPOST('AGENDA_EXT_COLOR_'.$id.'_'.$i, 'alpha')); $color = trim(GETPOST('AGENDA_EXT_COLOR_'.$id.'_'.$i, 'alpha'));
if ($color=='-1') $color=''; if ($color == '-1') {
$color = '';
}
$enabled = trim(GETPOST('AGENDA_EXT_ENABLED_'.$id.'_'.$i, 'alpha')); $enabled = trim(GETPOST('AGENDA_EXT_ENABLED_'.$id.'_'.$i, 'alpha'));
if (! empty($src) && ! dol_is_url($src)) if (!empty($src) && !dol_is_url($src)) {
{
setEventMessage($langs->trans("ErrorParamMustBeAnUrl"), 'errors'); setEventMessage($langs->trans("ErrorParamMustBeAnUrl"), 'errors');
$error ++; $error ++;
$errorsaved ++; $errorsaved ++;
break; break;
} }
$tabparam['AGENDA_EXT_NAME_'.$id.'_'.$i]=$name;
$tabparam['AGENDA_EXT_SRC_'.$id.'_'.$i]=$src;
$tabparam['AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i]=$offsettz;
$tabparam['AGENDA_EXT_COLOR_'.$id.'_'.$i]=$color;
$tabparam['AGENDA_EXT_ENABLED_'.$id.'_'.$i]=$enabled;
$i++;
}
if (! $error) if (! $error)
{ {
$result=dol_set_user_param($db, $conf, $object, $tabparam); $result=dol_set_user_param($db, $conf, $object, $tabparam);
if (! $result > 0) $error++; if (! $result > 0) $error++;
} }
if (! $error) $i ++;
{ }
if (!$error) {
$result = dol_set_user_param($db, $conf, $fuser, $tabparam);
if (!$result > 0) {
$error ++;
}
}
if (!$error) {
$db->commit(); $db->commit();
setEventMessage($langs->trans("SetupSaved")); setEventMessage($langs->trans("SetupSaved"));
} } else {
else
{
$db->rollback(); $db->rollback();
if (empty($errorsaved)) setEventMessage($langs->trans("Error"),'errors'); if (empty($errorsaved)) {
setEventMessage($langs->trans("Error"), 'errors');
}
}
} }
} }

View File

@ -101,36 +101,35 @@ $hookmanager->initHooks(array('usercard','globalcard'));
* Actions * Actions
*/ */
if ($action == 'confirm_disable' && $confirm == "yes" && $candisableuser) $parameters=array('id'=>$socid);
{ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($id <> $user->id) if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
{
if (empty($reshook)) {
if ($action == 'confirm_disable' && $confirm == "yes" && $candisableuser) {
if ($id <> $user->id) {
$object->fetch($id); $object->fetch($id);
$object->setstatus(0); $object->setstatus(0);
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit; exit;
} }
} }
if ($action == 'confirm_enable' && $confirm == "yes" && $candisableuser) if ($action == 'confirm_enable' && $confirm == "yes" && $candisableuser) {
{
$error = 0; $error = 0;
if ($id <> $user->id) if ($id <> $user->id) {
{
$object->fetch($id); $object->fetch($id);
if (!empty($conf->file->main_limit_users)) if (!empty($conf->file->main_limit_users)) {
{
$nb = $object->getNbOfUsers("active"); $nb = $object->getNbOfUsers("active");
if ($nb >= $conf->file->main_limit_users) if ($nb >= $conf->file->main_limit_users) {
{
$error ++; $error ++;
setEventMessage($langs->trans("YourQuotaOfUsersIsReached"), 'errors'); setEventMessage($langs->trans("YourQuotaOfUsersIsReached"), 'errors');
} }
} }
if (! $error) if (!$error) {
{
$object->setstatus(1); $object->setstatus(1);
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit; exit;
@ -138,20 +137,15 @@ if ($action == 'confirm_enable' && $confirm == "yes" && $candisableuser)
} }
} }
if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser) if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser) {
{ if ($id <> $user->id) {
if ($id <> $user->id)
{
$object = new User($db); $object = new User($db);
$object->id = $id; $object->id = $id;
$result = $object->delete(); $result = $object->delete();
if ($result < 0) if ($result < 0) {
{
$langs->load("errors"); $langs->load("errors");
setEventMessage($langs->trans("ErrorUserCannotBeDelete"), 'errors'); setEventMessage($langs->trans("ErrorUserCannotBeDelete"), 'errors');
} } else {
else
{
header("Location: index.php"); header("Location: index.php");
exit; exit;
} }
@ -159,18 +153,15 @@ if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser)
} }
// Action Add user // Action Add user
if ($action == 'add' && $canadduser) if ($action == 'add' && $canadduser) {
{
$error = 0; $error = 0;
if (! $_POST["lastname"]) if (!$_POST["lastname"]) {
{
$error ++; $error ++;
setEventMessage($langs->trans("NameNotDefined"), 'errors'); setEventMessage($langs->trans("NameNotDefined"), 'errors');
$action = "create"; // Go back to create page $action = "create"; // Go back to create page
} }
if (! $_POST["login"]) if (!$_POST["login"]) {
{
$error ++; $error ++;
setEventMessage($langs->trans("LoginNotDefined"), 'errors'); setEventMessage($langs->trans("LoginNotDefined"), 'errors');
$action = "create"; // Go back to create page $action = "create"; // Go back to create page
@ -179,16 +170,14 @@ if ($action == 'add' && $canadduser)
if (!empty($conf->file->main_limit_users)) // If option to limit users is set if (!empty($conf->file->main_limit_users)) // If option to limit users is set
{ {
$nb = $object->getNbOfUsers("active"); $nb = $object->getNbOfUsers("active");
if ($nb >= $conf->file->main_limit_users) if ($nb >= $conf->file->main_limit_users) {
{
$error ++; $error ++;
setEventMessage($langs->trans("YourQuotaOfUsersIsReached"), 'errors'); setEventMessage($langs->trans("YourQuotaOfUsersIsReached"), 'errors');
$action = "create"; // Go back to create page $action = "create"; // Go back to create page
} }
} }
if (!$error) if (!$error) {
{
$object->lastname = GETPOST("lastname", 'alpha'); $object->lastname = GETPOST("lastname", 'alpha');
$object->firstname = GETPOST("firstname", 'alpha'); $object->firstname = GETPOST("firstname", 'alpha');
$object->login = GETPOST("login", 'alpha'); $object->login = GETPOST("login", 'alpha');
@ -217,27 +206,23 @@ if ($action == 'add' && $canadduser)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) $error++; if ($ret < 0) {
$error ++;
}
// Set entity property // Set entity property
$entity = GETPOST('entity', 'int'); $entity = GETPOST('entity', 'int');
if (! empty($conf->multicompany->enabled)) if (!empty($conf->multicompany->enabled)) {
{ if (!empty($_POST["superadmin"])) {
if (! empty($_POST["superadmin"]))
{
$object->entity = 0; $object->entity = 0;
} } else {
else if ($conf->multicompany->transverse_mode) if ($conf->multicompany->transverse_mode) {
{
$object->entity = 1; // all users are forced into master entity $object->entity = 1; // all users are forced into master entity
} } else {
else
{
$object->entity = ($entity == '' ? 1 : $entity); $object->entity = ($entity == '' ? 1 : $entity);
} }
} }
else } else {
{
$object->entity = ($entity == '' ? 1 : $entity); $object->entity = ($entity == '' ? 1 : $entity);
/*if ($user->admin && $user->entity == 0 && GETPOST("admin",'alpha')) /*if ($user->admin && $user->entity == 0 && GETPOST("admin",'alpha'))
{ {
@ -247,10 +232,8 @@ if ($action == 'add' && $canadduser)
$db->begin(); $db->begin();
$id = $object->create($user); $id = $object->create($user);
if ($id > 0) if ($id > 0) {
{ if (isset($_POST['password']) && trim($_POST['password'])) {
if (isset($_POST['password']) && trim($_POST['password']))
{
$object->setPassword($user, trim($_POST['password'])); $object->setPassword($user, trim($_POST['password']));
} }
@ -258,13 +241,14 @@ if ($action == 'add' && $canadduser)
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit; exit;
} } else {
else
{
$langs->load("errors"); $langs->load("errors");
$db->rollback(); $db->rollback();
if (is_array($object->errors) && count($object->errors)) setEventMessage($object->errors,'errors'); if (is_array($object->errors) && count($object->errors)) {
else setEventMessage($object->error, 'errors'); setEventMessage($object->errors, 'errors');
} else {
setEventMessage($object->error, 'errors');
}
$action = "create"; // Go back to create page $action = "create"; // Go back to create page
} }
@ -281,66 +265,49 @@ if (($action == 'addgroup' || $action == 'removegroup') && $caneditfield)
$editgroup->oldcopy=clone $editgroup; $editgroup->oldcopy=clone $editgroup;
$object->fetch($id); $object->fetch($id);
if ($action == 'addgroup') $object->SetInGroup($group,($conf->multicompany->transverse_mode?GETPOST("entity"):$editgroup->entity)); if ($action == 'addgroup') {
if ($action == 'removegroup') $object->RemoveFromGroup($group,($conf->multicompany->transverse_mode?GETPOST("entity"):$editgroup->entity)); $object->SetInGroup($group, ($conf->multicompany->transverse_mode ? GETPOST("entity") : $editgroup->entity));
}
if ($action == 'removegroup') {
$object->RemoveFromGroup($group, ($conf->multicompany->transverse_mode ? GETPOST("entity") : $editgroup->entity));
}
if ($result > 0) if ($result > 0) {
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit; exit;
} } else {
else
{
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
} }
if ($action == 'update' && ! $_POST["cancel"]) if ($action == 'update' && !$_POST["cancel"]) {
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
if ($caneditfield) // Case we can edit all field if ($caneditfield) // Case we can edit all field
{ {
$error = 0; $error = 0;
if (! $_POST["lastname"]) if (!$_POST["lastname"]) {
{
setEventMessage($langs->trans("NameNotDefined"), 'errors'); setEventMessage($langs->trans("NameNotDefined"), 'errors');
$action = "edit"; // Go back to create page $action = "edit"; // Go back to create page
$error ++; $error ++;
} }
if (! $_POST["login"]) if (!$_POST["login"]) {
{
setEventMessage($langs->trans("LoginNotDefined"), 'errors'); setEventMessage($langs->trans("LoginNotDefined"), 'errors');
$action = "edit"; // Go back to create page $action = "edit"; // Go back to create page
$error ++; $error ++;
} }
if (! $error) if (!$error) {
{
$object->fetch($id); $object->fetch($id);
// Test if new login $object->oldcopy = clone $object;
if (GETPOST("login") && GETPOST("login") != $object->login)
{
dol_syslog("New login ".$object->login." is requested. We test it does not exists.");
$tmpuser=new User($db);
$result=$tmpuser->fetch(0, GETPOST("login"));
if ($result > 0)
{
setEventMessage($langs->trans("ErrorLoginAlreadyExists", GETPOST('login')), 'errors');
$action="edit"; // Go back to create page
$error++;
}
}
}
if (! $error) if (!$error) {
{
$db->begin(); $db->begin();
$object->oldcopy = clone $object; $object->oldcopy = dol_clone($object);
$object->lastname = GETPOST("lastname", 'alpha'); $object->lastname = GETPOST("lastname", 'alpha');
$object->firstname = GETPOST("firstname", 'alpha'); $object->firstname = GETPOST("firstname", 'alpha');
@ -366,12 +333,6 @@ if ($action == 'update' && ! $_POST["cancel"])
$object->salaryextra = GETPOST("salaryextra") != '' ? GETPOST("salaryextra") : ''; $object->salaryextra = GETPOST("salaryextra") != '' ? GETPOST("salaryextra") : '';
$object->weeklyhours = GETPOST("weeklyhours") != '' ? GETPOST("weeklyhours") : ''; $object->weeklyhours = GETPOST("weeklyhours") != '' ? GETPOST("weeklyhours") : '';
$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($conf->multicompany->enabled))
{ {
if (! empty($_POST["superadmin"])) if (! empty($_POST["superadmin"]))
@ -392,83 +353,92 @@ if ($action == 'update' && ! $_POST["cancel"])
$object->entity = (! GETPOST('entity', 'int') ? 0 : GETPOST('entity', 'int')); $object->entity = (! GETPOST('entity', 'int') ? 0 : GETPOST('entity', 'int'));
} }
if (GETPOST('deletephoto')) $object->photo=''; // Fill array 'array_options' with data from add form
if (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) {
if (! $error)
{
$ret=$object->update($user);
if ($ret < 0)
{
$error ++; $error ++;
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') }
{
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"]);
}
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"); $langs->load("errors");
setEventMessage($langs->trans("ErrorLoginAlreadyExists", $object->login), 'errors'); setEventMessage($langs->trans("ErrorLoginAlreadyExists", $object->login), 'errors');
} } else {
else
{
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
} }
} }
if (! $error && isset($_POST['contactid'])) if (!$error && isset($_POST['contactid'])) {
{
$contactid = GETPOST('contactid'); $contactid = GETPOST('contactid');
if ($contactid > 0) if ($contactid > 0) {
{
$contact = new Contact($db); $contact = new Contact($db);
$contact->fetch($contactid); $contact->fetch($contactid);
$sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql .= " SET fk_socpeople=".$db->escape($contactid); $sql .= " SET fk_socpeople=".$db->escape($contactid);
if ($contact->socid) $sql.=", fk_soc=".$db->escape($contact->socid); if ($contact->socid) {
$sql.= " WHERE rowid=".$object->id; $sql .= ", fk_soc=".$db->escape($contact->socid);
} }
else $sql .= " WHERE rowid=".$object->id;
{ } else {
$sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql .= " SET fk_socpeople=NULL, fk_soc=NULL"; $sql .= " SET fk_socpeople=NULL, fk_soc=NULL";
$sql .= " WHERE rowid=".$object->id; $sql .= " WHERE rowid=".$object->id;
} }
dol_syslog("fiche::update", LOG_DEBUG); dol_syslog("fiche::update", LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if (! $resql) if (!$resql) {
{
$error ++; $error ++;
setEventMessage($db->lasterror(), 'errors'); setEventMessage($db->lasterror(), 'errors');
} }
} }
if (! $error && ! count($object->errors)) if (!$error && !count($object->errors)) {
{ if (GETPOST('deletephoto') && $object->photo) {
if (GETPOST('deletephoto') && $object->photo)
{
$fileimg = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user').'/logos/'.$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'; $dirthumbs = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user').'/logos/thumbs';
dol_delete_file($fileimg); dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs); dol_delete_dir_recursive($dirthumbs);
} }
if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name'])) 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'); $dir = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user');
dol_mkdir($dir); dol_mkdir($dir);
if (@is_dir($dir)) if (@is_dir($dir)) {
{
$newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']); $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']);
if (! $result > 0) if (!$result > 0) {
{
setEventMessage($langs->trans("ErrorFailedToSaveFile"), 'errors'); setEventMessage($langs->trans("ErrorFailedToSaveFile"), 'errors');
} } else {
else
{
// Create small thumbs for company (Ratio is near 16/9) // Create small thumbs for company (Ratio is near 16/9)
// Used on logon for example // Used on logon for example
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality); $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
@ -477,37 +447,44 @@ if ($action == 'update' && ! $_POST["cancel"])
// Used on menu or for setup page for example // Used on menu or for setup page for example
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality); $imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
} }
} } else {
else
{
$error ++; $error ++;
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->transnoentitiesnoconv("ErrorFailedToCreateDir", $dir), $mesgs, 'errors'); setEventMessages($langs->trans("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
} }
} }
} }
if (! $error && ! count($object->errors)) if (!$error && !count($object->errors)) {
{
setEventMessage($langs->trans("UserModified")); setEventMessage($langs->trans("UserModified"));
$db->commit(); $db->commit();
$login = $_SESSION["dol_login"]; $login = $_SESSION["dol_login"];
if ($login && $login == $object->oldcopy->login && $object->oldcopy->login != $object->login) // Current user has changed its login if ($login && $login == $object->oldcopy->login && $object->oldcopy->login != $object->login) // Current user has changed its login
{ {
$_SESSION["dol_login"]=$object->login; // Set new login to avoid disconnect at next page $error++;
$langs->load("errors");
setEventMessages($langs->transnoentitiesnoconv("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
} }
} } else {
else
{
$db->rollback(); $db->rollback();
} }
} }
} } else {
else if ($caneditpassword) // Case we can edit only password if ($caneditpassword) // Case we can edit only password
{ {
$object->fetch($id); $object->fetch($id);
$object->oldcopy = dol_clone($object);
$ret = $object->setPassword($user, $_POST["password"]);
if ($ret < 0) {
setEventMessage($object->error, 'errors');
}
}
}
}
$object->oldcopy = clone $object; $object->oldcopy = clone $object;
$ret=$object->setPassword($user,$_POST["password"]); $ret=$object->setPassword($user,$_POST["password"]);
@ -520,40 +497,30 @@ if ($action == 'update' && ! $_POST["cancel"])
// Change password with a new generated one // Change password with a new generated one
if ((($action == 'confirm_password' && $confirm == 'yes') if ((($action == 'confirm_password' && $confirm == 'yes')
|| ($action == 'confirm_passwordsend' && $confirm == 'yes')) && $caneditpassword) || ($action == 'confirm_passwordsend' && $confirm == 'yes')) && $caneditpassword
{ ) {
$object->fetch($id); $object->fetch($id);
$newpassword = $object->setPassword($user, ''); $newpassword = $object->setPassword($user, '');
if ($newpassword < 0) if ($newpassword < 0) {
{
// Echec // Echec
setEventMessage($langs->trans("ErrorFailedToSetNewPassword"), 'errors'); setEventMessage($langs->trans("ErrorFailedToSetNewPassword"), 'errors');
} } else {
else
{
// Succes // Succes
if ($action == 'confirm_passwordsend' && $confirm == 'yes') if ($action == 'confirm_passwordsend' && $confirm == 'yes') {
{ if ($object->send_password($user, $newpassword) > 0) {
if ($object->send_password($user,$newpassword) > 0)
{
setEventMessage($langs->trans("PasswordChangedAndSentTo", $object->email)); setEventMessage($langs->trans("PasswordChangedAndSentTo", $object->email));
} } else {
else
{
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} } else {
else
{
setEventMessage($langs->trans("PasswordChangedTo", $newpassword), 'errors'); setEventMessage($langs->trans("PasswordChangedTo", $newpassword), 'errors');
} }
} }
} }
// Action initialisation donnees depuis record LDAP // Action initialisation donnees depuis record LDAP
if ($action == 'adduserldap') if ($action == 'adduserldap') {
{
$selecteduser = $_POST['users']; $selecteduser = $_POST['users'];
$required_fields = array( $required_fields = array(
@ -571,22 +538,20 @@ if ($action == 'adduserldap')
$conf->global->LDAP_FIELD_MAIL, $conf->global->LDAP_FIELD_MAIL,
$conf->global->LDAP_FIELD_TITLE, $conf->global->LDAP_FIELD_TITLE,
$conf->global->LDAP_FIELD_DESCRIPTION, $conf->global->LDAP_FIELD_DESCRIPTION,
$conf->global->LDAP_FIELD_SID); $conf->global->LDAP_FIELD_SID
);
$ldap = new Ldap(); $ldap = new Ldap();
$result = $ldap->connect_bind(); $result = $ldap->connect_bind();
if ($result >= 0) if ($result >= 0) {
{
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
$required_fields = array_unique(array_values(array_filter($required_fields, "dol_validElement"))); $required_fields = array_unique(array_values(array_filter($required_fields, "dol_validElement")));
$ldapusers = $ldap->getRecords($selecteduser, $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields); $ldapusers = $ldap->getRecords($selecteduser, $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields);
//print_r($ldapusers); //print_r($ldapusers);
if (is_array($ldapusers)) if (is_array($ldapusers)) {
{ foreach ($ldapusers as $key => $attribute) {
foreach ($ldapusers as $key => $attribute)
{
$ldap_lastname = $attribute[$conf->global->LDAP_FIELD_NAME]; $ldap_lastname = $attribute[$conf->global->LDAP_FIELD_NAME];
$ldap_firstname = $attribute[$conf->global->LDAP_FIELD_FIRSTNAME]; $ldap_firstname = $attribute[$conf->global->LDAP_FIELD_FIRSTNAME];
$ldap_login = $attribute[$conf->global->LDAP_FIELD_LOGIN]; $ldap_login = $attribute[$conf->global->LDAP_FIELD_LOGIN];
@ -601,13 +566,11 @@ if ($action == 'adduserldap')
$ldap_sid = $attribute[$conf->global->LDAP_FIELD_SID]; $ldap_sid = $attribute[$conf->global->LDAP_FIELD_SID];
} }
} }
} } else {
else
{
setEventMessage($ldap->error, 'errors'); setEventMessage($ldap->error, 'errors');
} }
} }
}
/* /*

View File

@ -41,13 +41,19 @@ if ($user->id == $id) // A user can always read its own card
} }
$result = restrictedArea($user, 'user', $id, 'user&user', $feature2); $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('usercard','globalcard'));
/* /*
* Actions * Actions
*/ */
if ($action == 'update' && ! GETPOST('cancel')) $parameters=array('id'=>$socid);
{ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) {
if ($action == 'update' && !GETPOST('cancel')) {
$edituser = new User($db); $edituser = new User($db);
$edituser->fetch($id); $edituser->fetch($id);
@ -57,9 +63,11 @@ if ($action == 'update' && ! GETPOST('cancel'))
$edituser->clicktodial_poste = GETPOST("poste"); $edituser->clicktodial_poste = GETPOST("poste");
$result = $edituser->update_clicktodial(); $result = $edituser->update_clicktodial();
if ($result < 0) setEventMessage($edituser->error,'errors'); if ($result < 0) {
setEventMessage($edituser->error, 'errors');
}
}
} }
/* /*

View File

@ -93,12 +93,20 @@ if ($id > 0 || ! empty($ref))
$upload_dir = $conf->user->multidir_output[$entitytouseforuserdir] . "/" . $object->id ; $upload_dir = $conf->user->multidir_output[$entitytouseforuserdir] . "/" . $object->id ;
} }
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('usercard','globalcard'));
/* /*
* Actions * Actions
*/ */
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; $parameters=array('id'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) {
include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_pre_headers.tpl.php';
}
/* /*
* View * View

View File

@ -45,13 +45,20 @@ $object = new User($db);
$object->fetch($id); $object->fetch($id);
$object->getrights(); $object->getrights();
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('usercard','globalcard'));
/* /*
* Actions * Actions
*/ */
if ($_GET["action"] == 'dolibarr2ldap')
{ $parameters=array('id'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) {
if ($_GET["action"] == 'dolibarr2ldap') {
$db->begin(); $db->begin();
$ldap = new Ldap(); $ldap = new Ldap();
@ -63,18 +70,15 @@ if ($_GET["action"] == 'dolibarr2ldap')
$result = $ldap->update($dn, $info, $user, $olddn); $result = $ldap->update($dn, $info, $user, $olddn);
if ($result >= 0) if ($result >= 0) {
{
setEventMessage($langs->trans("UserSynchronized")); setEventMessage($langs->trans("UserSynchronized"));
$db->commit(); $db->commit();
} } else {
else
{
setEventMessage($ldap->error, 'errors'); setEventMessage($ldap->error, 'errors');
$db->rollback(); $db->rollback();
} }
} }
}
/* /*
* View * View

View File

@ -48,28 +48,30 @@ $feature2 = (($socid && $user->rights->user->self->creer)?'':'user');
if ($user->id == $id) $feature2=''; // A user can always read its own card if ($user->id == $id) $feature2=''; // A user can always read its own card
$result = restrictedArea($user, 'user', $id, 'user&user', $feature2); $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('usercard','globalcard'));
/******************************************************************************/ /******************************************************************************/
/* Actions */ /* Actions */
/******************************************************************************/ /******************************************************************************/
if ($action == 'update' && $user->rights->user->user->creer && ! $_POST["cancel"]) $parameters=array('id'=>$socid);
{ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) {
if ($action == 'update' && $user->rights->user->user->creer && !$_POST["cancel"]) {
$db->begin(); $db->begin();
$res = $object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES)); $res = $object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES));
if ($res < 0) if ($res < 0) {
{
$mesg = '<div class="error">'.$adh->error.'</div>'; $mesg = '<div class="error">'.$adh->error.'</div>';
$db->rollback(); $db->rollback();
} } else {
else
{
$db->commit(); $db->commit();
} }
} }
}
/******************************************************************************/ /******************************************************************************/

View File

@ -74,24 +74,32 @@ $searchformtitle=array($langs->trans("Companies"),$langs->trans("Contacts"),$lan
$form = new Form($db); $form = new Form($db);
$formadmin=new FormAdmin($db); $formadmin=new FormAdmin($db);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('usercard','globalcard'));
/* /*
* Actions * Actions
*/ */
if ($action == 'update' && ($caneditfield || ! empty($user->admin))) $parameters=array('id'=>$socid);
{ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (! $_POST["cancel"]) if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
{
if (empty($reshook)) {
if ($action == 'update' && ($caneditfield || !empty($user->admin))) {
if (!$_POST["cancel"]) {
$tabparam = array(); $tabparam = array();
if ($_POST["check_MAIN_LANG_DEFAULT"]=="on") $tabparam["MAIN_LANG_DEFAULT"]=$_POST["main_lang_default"]; if ($_POST["check_MAIN_LANG_DEFAULT"] == "on") {
else $tabparam["MAIN_LANG_DEFAULT"]=''; $tabparam["MAIN_LANG_DEFAULT"] = $_POST["main_lang_default"];
} else {
$tabparam["MAIN_LANG_DEFAULT"] = '';
}
if ($_POST["check_SIZE_LISTE_LIMIT"]=="on") $tabparam["MAIN_SIZE_LISTE_LIMIT"]=$_POST["main_size_liste_limit"]; if ($_POST["check_SIZE_LISTE_LIMIT"] == "on") {
else $tabparam["MAIN_SIZE_LISTE_LIMIT"]=''; $tabparam["MAIN_SIZE_LISTE_LIMIT"] = $_POST["main_size_liste_limit"];
} else {
if ($_POST["check_MAIN_THEME"]=="on") $tabparam["MAIN_THEME"]=$_POST["main_theme"]; $tabparam["MAIN_SIZE_LISTE_LIMIT"] = '';
else $tabparam["MAIN_THEME"]=''; }
$val=(join(',',(colorStringToArray(GETPOST('THEME_ELDY_TOPMENU_BACK1'),array())))); $val=(join(',',(colorStringToArray(GETPOST('THEME_ELDY_TOPMENU_BACK1'),array()))));
if ($val == '') $tabparam['THEME_ELDY_TOPMENU_BACK1']=''; if ($val == '') $tabparam['THEME_ELDY_TOPMENU_BACK1']='';
@ -106,6 +114,10 @@ if ($action == 'update' && ($caneditfield || ! empty($user->admin)))
$tabparam["MAIN_SEARCHFORM_CONTACT"]=$_POST["main_searchform_contact"]; $tabparam["MAIN_SEARCHFORM_CONTACT"]=$_POST["main_searchform_contact"];
$tabparam["MAIN_SEARCHFORM_SOCIETE"]=$_POST["main_searchform_societe"]; $tabparam["MAIN_SEARCHFORM_SOCIETE"]=$_POST["main_searchform_societe"];
$tabparam["MAIN_SEARCHFORM_PRODUITSERVICE"]=$_POST["main_searchform_produitservice"];
$tabparam["MAIN_SEARCHFORM_CONTACT"] = $_POST["main_searchform_contact"];
$tabparam["MAIN_SEARCHFORM_SOCIETE"] = $_POST["main_searchform_societe"];
$tabparam["MAIN_SEARCHFORM_PRODUITSERVICE"] = $_POST["main_searchform_produitservice"]; $tabparam["MAIN_SEARCHFORM_PRODUITSERVICE"] = $_POST["main_searchform_produitservice"];
$result = dol_set_user_param($db, $conf, $object, $tabparam); $result = dol_set_user_param($db, $conf, $object, $tabparam);
@ -114,8 +126,7 @@ if ($action == 'update' && ($caneditfield || ! empty($user->admin)))
exit; exit;
} }
} }
}
/* /*
* View * View

View File

@ -67,43 +67,50 @@ if ($user->id == $id && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user-
$result = restrictedArea($user, 'user', $id, 'user&user', $feature2); $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
if ($user->id <> $id && ! $canreaduser) accessforbidden(); if ($user->id <> $id && ! $canreaduser) accessforbidden();
$object = new User($db);
$object->fetch($id);
$object->getrights();
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('usercard','globalcard'));
/** /**
* Actions * Actions
*/ */
if ($action == 'addrights' && $caneditperms) $parameters=array('id'=>$socid);
{ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) {
if ($action == 'addrights' && $caneditperms) {
$edituser = new User($db); $edituser = new User($db);
$edituser->fetch($id); $edituser->fetch($id);
//$edituser->addrights($rights, $module, '', $entity); // TODO unused for the moment //$edituser->addrights($rights, $module, '', $entity); // TODO unused for the moment
$edituser->addrights($rights, $module); $edituser->addrights($rights, $module);
// Si on a touche a ses propres droits, on recharge // Si on a touche a ses propres droits, on recharge
if ($id == $user->id) if ($id == $user->id) {
{
$user->clearrights(); $user->clearrights();
$user->getrights(); $user->getrights();
$menumanager->loadMenu(); $menumanager->loadMenu();
} }
} }
if ($action == 'delrights' && $caneditperms) if ($action == 'delrights' && $caneditperms) {
{
$edituser = new User($db); $edituser = new User($db);
$edituser->fetch($id); $edituser->fetch($id);
//$edituser->delrights($rights, $module, '', $entity); // TODO unused for the moment //$edituser->delrights($rights, $module, '', $entity); // TODO unused for the moment
$edituser->delrights($rights, $module); $edituser->delrights($rights, $module);
// Si on a touche a ses propres droits, on recharge // Si on a touche a ses propres droits, on recharge
if ($id == $user->id) if ($id == $user->id) {
{
$user->clearrights(); $user->clearrights();
$user->getrights(); $user->getrights();
$menumanager->loadMenu(); $menumanager->loadMenu();
} }
} }
}
/** /**
@ -114,10 +121,6 @@ llxHeader('',$langs->trans("Permissions"));
$form=new Form($db); $form=new Form($db);
$object = new User($db);
$object->fetch($id);
$object->getrights();
$head = user_prepare_head($object); $head = user_prepare_head($object);
$title = $langs->trans("User"); $title = $langs->trans("User");