Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2015-10-15 12:19:01 +02:00
commit 577776b950
9 changed files with 540 additions and 533 deletions

View File

@ -86,7 +86,7 @@ if (! defined('DONOTLOADCONF') && file_exists($conffile))
if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type=='mysqli' || $dolibarr_main_db_type=='mysql')) $dolibarr_main_db_port='3306'; // For backward compatibility if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type=='mysqli' || $dolibarr_main_db_type=='mysql')) $dolibarr_main_db_port='3306'; // For backward compatibility
// Clean parameters // Clean parameters
$dolibarr_main_data_root =isset($dolibarr_main_data_root)?trim($dolibarr_main_data_root):''; $dolibarr_main_data_root =isset($dolibarr_main_data_root)?trim($dolibarr_main_data_root):DOL_DOCUMENT_ROOT . '/../documents';
$dolibarr_main_url_root =isset($dolibarr_main_url_root)?trim($dolibarr_main_url_root):''; $dolibarr_main_url_root =isset($dolibarr_main_url_root)?trim($dolibarr_main_url_root):'';
$dolibarr_main_url_root_alt =isset($dolibarr_main_url_root_alt)?trim($dolibarr_main_url_root_alt):''; $dolibarr_main_url_root_alt =isset($dolibarr_main_url_root_alt)?trim($dolibarr_main_url_root_alt):'';
$dolibarr_main_document_root =isset($dolibarr_main_document_root)?trim($dolibarr_main_document_root):''; $dolibarr_main_document_root =isset($dolibarr_main_document_root)?trim($dolibarr_main_document_root):'';
@ -133,7 +133,7 @@ if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_m
define('MAIN_DB_PREFIX',(isset($dolibarr_main_db_prefix)?$dolibarr_main_db_prefix:'')); define('MAIN_DB_PREFIX',(isset($dolibarr_main_db_prefix)?$dolibarr_main_db_prefix:''));
define('DOL_CLASS_PATH', 'class/'); // Filsystem path to class dir define('DOL_CLASS_PATH', 'class/'); // Filsystem path to class dir
define('DOL_DATA_ROOT',(isset($dolibarr_main_data_root)?$dolibarr_main_data_root:'')); define('DOL_DATA_ROOT',(isset($dolibarr_main_data_root)?$dolibarr_main_data_root:DOL_DOCUMENT_ROOT . '/../documents'));
define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root)?$dolibarr_main_url_root:'')); // URL relative root define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root)?$dolibarr_main_url_root:'')); // URL relative root
$uri=preg_replace('/^http(s?):\/\//i','',constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http* $uri=preg_replace('/^http(s?):\/\//i','',constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
$suburi = strstr($uri, '/'); // $suburi contains url without domain $suburi = strstr($uri, '/'); // $suburi contains url without domain

View File

@ -66,44 +66,42 @@ $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;
$error=0; $errorsaved = 0;
$tabparam=array(); $error = 0;
$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') {
if ($color=='-1') $color=''; $color = '';
$enabled=trim(GETPOST('AGENDA_EXT_ENABLED_'.$id.'_'.$i,'alpha'));
if (! empty($src) && ! dol_is_url($src))
{
setEventMessage($langs->trans("ErrorParamMustBeAnUrl"),'errors');
$error++;
$errorsaved++;
break;
} }
$enabled = trim(GETPOST('AGENDA_EXT_ENABLED_'.$id.'_'.$i, 'alpha'));
$tabparam['AGENDA_EXT_NAME_'.$id.'_'.$i]=$name; if (!empty($src) && !dol_is_url($src)) {
$tabparam['AGENDA_EXT_SRC_'.$id.'_'.$i]=$src; setEventMessage($langs->trans("ErrorParamMustBeAnUrl"), 'errors');
$tabparam['AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i]=$offsettz; $error ++;
$tabparam['AGENDA_EXT_COLOR_'.$id.'_'.$i]=$color; $errorsaved ++;
$tabparam['AGENDA_EXT_ENABLED_'.$id.'_'.$i]=$enabled; break;
$i++;
} }
if (! $error) if (! $error)
@ -112,15 +110,25 @@ if ($actionsave)
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,143 +101,128 @@ $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;
} }
} }
} }
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;
} }
} }
} }
// 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
} }
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'); $object->api_key = GETPOST("api_key", 'alpha');
$object->api_key = GETPOST("api_key",'alpha'); $object->gender = GETPOST("gender", 'alpha');
$object->gender = GETPOST("gender",'alpha'); $object->admin = GETPOST("admin", 'alpha');
$object->admin = GETPOST("admin",'alpha'); $object->office_phone = GETPOST("office_phone", 'alpha');
$object->office_phone = GETPOST("office_phone",'alpha'); $object->office_fax = GETPOST("office_fax", 'alpha');
$object->office_fax = GETPOST("office_fax",'alpha');
$object->user_mobile = GETPOST("user_mobile"); $object->user_mobile = GETPOST("user_mobile");
$object->skype = GETPOST("skype"); $object->skype = GETPOST("skype");
$object->email = GETPOST("email",'alpha'); $object->email = GETPOST("email", 'alpha');
$object->job = GETPOST("job",'alpha'); $object->job = GETPOST("job", 'alpha');
$object->signature = GETPOST("signature"); $object->signature = GETPOST("signature");
$object->accountancy_code = GETPOST("accountancy_code"); $object->accountancy_code = GETPOST("accountancy_code");
$object->note = GETPOST("note"); $object->note = GETPOST("note");
$object->ldap_sid = GETPOST("ldap_sid"); $object->ldap_sid = GETPOST("ldap_sid");
$object->fk_user = GETPOST("fk_user")>0?GETPOST("fk_user"):0; $object->fk_user = GETPOST("fk_user") > 0 ? GETPOST("fk_user") : 0;
$object->thm = GETPOST("thm")!=''?GETPOST("thm"):''; $object->thm = GETPOST("thm") != '' ? GETPOST("thm") : '';
$object->tjm = GETPOST("tjm")!=''?GETPOST("tjm"):''; $object->tjm = GETPOST("tjm") != '' ? GETPOST("tjm") : '';
$object->salary = GETPOST("salary")!=''?GETPOST("salary"):''; $object->salary = GETPOST("salary") != '' ? GETPOST("salary") : '';
$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"):''; $object->color = GETPOST("color") != '' ? GETPOST("color") : '';
// 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,29 +232,28 @@ 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']));
} }
$db->commit(); $db->commit();
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');
$action="create"; // Go back to create page } else {
setEventMessage($object->error, 'errors');
}
$action = "create"; // Go back to create page
} }
} }
} }
// Action add usergroup // Action add usergroup
if (($action == 'addgroup' || $action == 'removegroup') && $caneditfield) if (($action == 'addgroup' || $action == 'removegroup') && $caneditfield)
@ -281,96 +265,73 @@ 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
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)
{
$db->begin();
$object->oldcopy = clone $object; $object->oldcopy = clone $object;
$object->lastname = GETPOST("lastname",'alpha'); if (!$error) {
$object->firstname = GETPOST("firstname",'alpha'); $db->begin();
$object->login = GETPOST("login",'alpha');
$object->gender = GETPOST("gender",'alpha'); $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->pass = GETPOST("password");
$object->api_key = (GETPOST("api_key", 'alpha'))?GETPOST("api_key", 'alpha'):$object->api_key; $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->admin = empty($user->admin) ? 0 : GETPOST("admin"); // A user can only be set admin by an admin
$object->office_phone=GETPOST("office_phone",'alpha'); $object->office_phone = GETPOST("office_phone", 'alpha');
$object->office_fax = GETPOST("office_fax",'alpha'); $object->office_fax = GETPOST("office_fax", 'alpha');
$object->user_mobile= GETPOST("user_mobile"); $object->user_mobile = GETPOST("user_mobile");
$object->skype = GETPOST("skype"); $object->skype = GETPOST("skype");
$object->email = GETPOST("email",'alpha'); $object->email = GETPOST("email", 'alpha');
$object->job = GETPOST("job",'alpha'); $object->job = GETPOST("job", 'alpha');
$object->signature = GETPOST("signature"); $object->signature = GETPOST("signature");
$object->accountancy_code = GETPOST("accountancy_code"); $object->accountancy_code = GETPOST("accountancy_code");
$object->openid = GETPOST("openid"); $object->openid = GETPOST("openid");
$object->fk_user = GETPOST("fk_user")>0?GETPOST("fk_user"):0; $object->fk_user = GETPOST("fk_user") > 0 ? GETPOST("fk_user") : 0;
$object->thm = GETPOST("thm")!=''?GETPOST("thm"):''; $object->thm = GETPOST("thm") != '' ? GETPOST("thm") : '';
$object->tjm = GETPOST("tjm")!=''?GETPOST("tjm"):''; $object->tjm = GETPOST("tjm") != '' ? GETPOST("tjm") : '';
$object->salary = GETPOST("salary")!=''?GETPOST("salary"):''; $object->salary = GETPOST("salary") != '' ? GETPOST("salary") : '';
$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))
{ {
@ -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) $error ++;
{
$ret=$object->update($user);
if ($ret < 0)
{
$error++;
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$langs->load("errors");
setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors');
} }
else
{ 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");
setEventMessage($langs->trans("ErrorLoginAlreadyExists", $object->login), 'errors');
} 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;
{ $dirthumbs = $conf->user->dir_output.'/'.get_exdir($object->id, 2, 0, 1, $object, 'user').'/logos/thumbs';
$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_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 {
$error ++;
$langs->load("errors");
setEventMessages($langs->trans("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
} }
else }
}
if (!$error && !count($object->errors)) {
setEventMessage($langs->trans("UserModified"));
$db->commit();
$login = $_SESSION["dol_login"];
if ($login && $login == $object->oldcopy->login && $object->oldcopy->login != $object->login) // Current user has changed its login
{ {
$error++; $error++;
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->transnoentitiesnoconv("ErrorFailedToCreateDir", $dir), $mesgs, 'errors'); setEventMessages($langs->transnoentitiesnoconv("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
} }
} } else {
}
if (! $error && ! count($object->errors))
{
setEventMessage($langs->trans("UserModified"));
$db->commit();
$login=$_SESSION["dol_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
}
}
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"]);
@ -519,41 +496,31 @@ 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));
{ } else {
setEventMessage($langs->trans("PasswordChangedAndSentTo",$object->email));
}
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,15 +566,13 @@ 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 * View
*/ */

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);
@ -56,12 +62,14 @@ if ($action == 'update' && ! GETPOST('cancel'))
$edituser->clicktodial_password = GETPOST("password"); $edituser->clicktodial_password = GETPOST("password");
$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 * View
*/ */

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,37 +45,41 @@ $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();
$result=$ldap->connect_bind(); $result = $ldap->connect_bind();
$info=$object->_load_ldap_info(); $info = $object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info); $dn = $object->_load_ldap_dn($info);
$olddn=$dn; // We can say that old dn = dn as we force synchro $olddn = $dn; // We can say that old dn = dn as we force synchro
$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,30 +48,32 @@ $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();
} }
}
} }
/******************************************************************************/ /******************************************************************************/
/* Affichage fiche */ /* Affichage fiche */
/******************************************************************************/ /******************************************************************************/

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');
{
$tabparam=array();
if ($_POST["check_MAIN_LANG_DEFAULT"]=="on") $tabparam["MAIN_LANG_DEFAULT"]=$_POST["main_lang_default"]; if (empty($reshook)) {
else $tabparam["MAIN_LANG_DEFAULT"]=''; if ($action == 'update' && ($caneditfield || !empty($user->admin))) {
if (!$_POST["cancel"]) {
$tabparam = array();
if ($_POST["check_SIZE_LISTE_LIMIT"]=="on") $tabparam["MAIN_SIZE_LISTE_LIMIT"]=$_POST["main_size_liste_limit"]; if ($_POST["check_MAIN_LANG_DEFAULT"] == "on") {
else $tabparam["MAIN_SIZE_LISTE_LIMIT"]=''; $tabparam["MAIN_LANG_DEFAULT"] = $_POST["main_lang_default"];
} else {
$tabparam["MAIN_LANG_DEFAULT"] = '';
}
if ($_POST["check_MAIN_THEME"]=="on") $tabparam["MAIN_THEME"]=$_POST["main_theme"]; if ($_POST["check_SIZE_LISTE_LIMIT"] == "on") {
else $tabparam["MAIN_THEME"]=''; $tabparam["MAIN_SIZE_LISTE_LIMIT"] = $_POST["main_size_liste_limit"];
} else {
$tabparam["MAIN_SIZE_LISTE_LIMIT"] = '';
}
$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']='';
@ -108,15 +116,18 @@ if ($action == 'update' && ($caneditfield || ! empty($user->admin)))
$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_PRODUITSERVICE"]=$_POST["main_searchform_produitservice"];
$result=dol_set_user_param($db, $conf, $object, $tabparam); $tabparam["MAIN_SEARCHFORM_CONTACT"] = $_POST["main_searchform_contact"];
$tabparam["MAIN_SEARCHFORM_SOCIETE"] = $_POST["main_searchform_societe"];
$tabparam["MAIN_SEARCHFORM_PRODUITSERVICE"] = $_POST["main_searchform_produitservice"];
$result = dol_set_user_param($db, $conf, $object, $tabparam);
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit; exit;
} }
}
} }
/* /*
* View * View
*/ */

View File

@ -67,45 +67,52 @@ 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();
} }
}
} }
/** /**
* View * View
*/ */
@ -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");