From b970f4eca621654f0b82e0be7474bd85d4864e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 26 Feb 2021 13:18:40 +0100 Subject: [PATCH] code syntax user directory --- htdocs/user/admin/group_extrafields.php | 17 +- htdocs/user/admin/user_extrafields.php | 17 +- htdocs/user/agenda_extsites.php | 26 +- htdocs/user/bank.php | 221 ++--- htdocs/user/card.php | 846 +++++++++----------- htdocs/user/class/userbankaccount.class.php | 40 +- htdocs/user/class/usergroup.class.php | 269 ++++--- htdocs/user/clicktodial.php | 40 +- htdocs/user/document.php | 43 +- htdocs/user/group/card.php | 173 ++-- htdocs/user/group/ldap.php | 41 +- htdocs/user/group/list.php | 86 +- htdocs/user/group/perms.php | 114 ++- htdocs/user/hierarchy.php | 38 +- htdocs/user/home.php | 63 +- htdocs/user/info.php | 12 +- htdocs/user/ldap.php | 42 +- htdocs/user/list.php | 704 +++++++++------- htdocs/user/logout.php | 62 +- htdocs/user/note.php | 28 +- htdocs/user/notify/card.php | 165 ++-- htdocs/user/param_ihm.php | 113 +-- htdocs/user/passwordforgotten.php | 224 +++--- htdocs/user/perms.php | 167 ++-- htdocs/user/vcard.php | 53 +- 25 files changed, 1866 insertions(+), 1738 deletions(-) diff --git a/htdocs/user/admin/group_extrafields.php b/htdocs/user/admin/group_extrafields.php index fd71d43d4f0..627af1c3b9d 100644 --- a/htdocs/user/admin/group_extrafields.php +++ b/htdocs/user/admin/group_extrafields.php @@ -38,13 +38,17 @@ $form = new Form($db); // List of supported format $tmptype2label = ExtraFields::$type2label; $type2label = array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); +foreach ($tmptype2label as $key => $val) { + $type2label[$key] = $langs->transnoentitiesnoconv($val); +} $action = GETPOST('action', 'aZ09'); $attrname = GETPOST('attrname', 'alpha'); $elementtype = 'usergroup'; //Must be the $table_element of the class that manage extrafield -if (!$user->admin) accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} /* @@ -79,8 +83,7 @@ print dol_get_fiche_end(); // Buttons -if ($action != 'create' && $action != 'edit') -{ +if ($action != 'create' && $action != 'edit') { print '
'; print "".$langs->trans("NewAttribute").""; print "
"; @@ -93,8 +96,7 @@ if ($action != 'create' && $action != 'edit') /* */ /* ************************************************************************** */ -if ($action == 'create') -{ +if ($action == 'create') { print '
'; print load_fiche_titre($langs->trans('NewAttribute')); @@ -106,8 +108,7 @@ if ($action == 'create') /* Edition of an optional field */ /* */ /* ************************************************************************** */ -if ($action == 'edit' && !empty($attrname)) -{ +if ($action == 'edit' && !empty($attrname)) { print "
"; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/user/admin/user_extrafields.php b/htdocs/user/admin/user_extrafields.php index 45d645ce3dd..25141ed4fcd 100644 --- a/htdocs/user/admin/user_extrafields.php +++ b/htdocs/user/admin/user_extrafields.php @@ -37,13 +37,17 @@ $form = new Form($db); // List of supported format $tmptype2label = ExtraFields::$type2label; $type2label = array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); +foreach ($tmptype2label as $key => $val) { + $type2label[$key] = $langs->transnoentitiesnoconv($val); +} $action = GETPOST('action', 'aZ09'); $attrname = GETPOST('attrname', 'alpha'); $elementtype = 'user'; //Must be the $table_element of the class that manage extrafield -if (!$user->admin) accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} /* @@ -78,8 +82,7 @@ print dol_get_fiche_end(); // Buttons -if ($action != 'create' && $action != 'edit') -{ +if ($action != 'create' && $action != 'edit') { print '
'; print "".$langs->trans("NewAttribute").""; print "
"; @@ -92,8 +95,7 @@ if ($action != 'create' && $action != 'edit') /* */ /* ************************************************************************** */ -if ($action == 'create') -{ +if ($action == 'create') { print '
'; print load_fiche_titre($langs->trans('NewAttribute')); @@ -105,8 +107,7 @@ if ($action == 'create') /* Editing an optional field */ /* */ /* ************************************************************************** */ -if ($action == 'edit' && !empty($attrname)) -{ +if ($action == 'edit' && !empty($attrname)) { print "
"; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/user/agenda_extsites.php b/htdocs/user/agenda_extsites.php index 8d320a839ef..3bd0468cc27 100644 --- a/htdocs/user/agenda_extsites.php +++ b/htdocs/user/agenda_extsites.php @@ -41,7 +41,9 @@ $actiontest = GETPOST('test', 'alpha'); $actionsave = GETPOST('save', 'alpha'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'useragenda'; // To manage different context of search -if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB = 5; +if (empty($conf->global->AGENDA_EXT_NB)) { + $conf->global->AGENDA_EXT_NB = 5; +} $MAXAGENDA = $conf->global->AGENDA_EXT_NB; // List of available colors @@ -55,14 +57,17 @@ $object->getrights(); // Security check $socid = 0; -if ($user->socid > 0) $socid = $user->socid; +if ($user->socid > 0) { + $socid = $user->socid; +} $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user'); $result = restrictedArea($user, 'user', $id, 'user&user', $feature2); // If user is not user that read and no permission to read other users, we stop -if (($object->id != $user->id) && (!$user->rights->user->user->lire)) - accessforbidden(); +if (($object->id != $user->id) && (!$user->rights->user->user->lire)) { + accessforbidden(); +} // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('usercard', 'useragenda', 'globalcard')); @@ -73,7 +78,9 @@ $hookmanager->initHooks(array('usercard', 'useragenda', 'globalcard')); $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 ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} if (empty($reshook)) { if ($actionsave) { @@ -168,7 +175,11 @@ print ''.$langs->trans("AgendaExtSitesDesc")."\n"; $selectedvalue = $conf->global->AGENDA_DISABLE_EXT; -if ($selectedvalue == 1) $selectedvalue = 0; else $selectedvalue = 1; +if ($selectedvalue == 1) { + $selectedvalue = 0; +} else { + $selectedvalue = 1; +} print '
'; @@ -183,8 +194,7 @@ print ''.$langs->trans("Color").''; print ""; $i = 1; -while ($i <= $MAXAGENDA) -{ +while ($i <= $MAXAGENDA) { $key = $i; $name = 'AGENDA_EXT_NAME_'.$id.'_'.$key; $src = 'AGENDA_EXT_SRC_'.$id.'_'.$key; diff --git a/htdocs/user/bank.php b/htdocs/user/bank.php index 20369e37d69..65bf7c5c8ac 100644 --- a/htdocs/user/bank.php +++ b/htdocs/user/bank.php @@ -32,9 +32,15 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php'; -if (!empty($conf->holiday->enabled)) require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; -if (!empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; -if (!empty($conf->salaries->enabled)) require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +if (!empty($conf->holiday->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; +} +if (!empty($conf->expensereport->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; +} +if (!empty($conf->salaries->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +} // Load translation files required by page $langs->loadLangs(array('companies', 'commercial', 'banks', 'bills', 'trips', 'holiday', 'salaries')); @@ -47,35 +53,44 @@ $cancel = GETPOST('cancel', 'alpha'); // Security check $socid = 0; -if ($user->socid > 0) $socid = $user->socid; +if ($user->socid > 0) { + $socid = $user->socid; +} $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user'); // Ok if user->rights->salaries->read or user->rights->hrm->read //$result = restrictedArea($user, 'salaries|hrm', $id, 'user&user', $feature2); $ok = false; -if ($user->id == $id) $ok = true; // A user can always read its own card -if (!empty($user->rights->salaries->read)) $ok = true; -if (!empty($user->rights->hrm->read)) $ok = true; -if (!empty($user->rights->expensereport->lire) && ($user->id == $object->id || $user->rights->expensereport->readall)) $ok = true; -if (!$ok) -{ +if ($user->id == $id) { + $ok = true; // A user can always read its own card +} +if (!empty($user->rights->salaries->read)) { + $ok = true; +} +if (!empty($user->rights->hrm->read)) { + $ok = true; +} +if (!empty($user->rights->expensereport->lire) && ($user->id == $object->id || $user->rights->expensereport->readall)) { + $ok = true; +} +if (!$ok) { accessforbidden(); } $object = new User($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $result = $object->fetch($id, $ref, '', 1); $object->getrights(); } $account = new UserBankAccount($db); -if (!$bankid) -{ +if (!$bankid) { $account->fetch(0, '', $id); } else { $account->fetch($bankid); } -if (empty($account->userid)) $account->userid = $object->id; +if (empty($account->userid)) { + $account->userid = $object->id; +} $permissiontoaddbankaccount = (!empty($user->rights->salaries->write) || !empty($user->rights->hrm->employee->write) || !empty($user->rights->user->creer)); @@ -84,8 +99,7 @@ $permissiontoaddbankaccount = (!empty($user->rights->salaries->write) || !empty( * Actions */ -if ($action == 'add' && !$cancel) -{ +if ($action == 'add' && !$cancel) { $account->userid = $object->id; $account->bank = GETPOST('bank', 'alpha'); @@ -103,8 +117,7 @@ if ($action == 'add' && !$cancel) $result = $account->create($user); - if (!$result) - { + if (!$result) { setEventMessages($account->error, $account->errors, 'errors'); $action = 'edit'; // Force chargement page edition } else { @@ -113,52 +126,51 @@ if ($action == 'add' && !$cancel) } } -if ($action == 'update' && !$cancel) -{ +if ($action == 'update' && !$cancel) { $account->userid = $object->id; /* - if ($action == 'update' && !$cancel) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + if ($action == 'update' && !$cancel) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - if ($canedituser) // Case we can edit all field - { - $error = 0; + if ($canedituser) // Case we can edit all field + { + $error = 0; - if (!$error) - { - $objectuser->fetch($id); + if (!$error) + { + $objectuser->fetch($id); - $objectuser->oldcopy = clone $objectuser; + $objectuser->oldcopy = clone $objectuser; - $db->begin(); + $db->begin(); - $objectuser->default_range = GETPOST('default_range'); - $objectuser->default_c_exp_tax_cat = GETPOST('default_c_exp_tax_cat'); + $objectuser->default_range = GETPOST('default_range'); + $objectuser->default_c_exp_tax_cat = GETPOST('default_c_exp_tax_cat'); - if (!$error) { - $ret = $objectuser->update($user); - if ($ret < 0) { - $error++; - if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - setEventMessages($langs->trans("ErrorLoginAlreadyExists", $objectuser->login), null, 'errors'); - } else { - setEventMessages($objectuser->error, $objectuser->errors, 'errors'); - } - } - } + if (!$error) { + $ret = $objectuser->update($user); + if ($ret < 0) { + $error++; + if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorLoginAlreadyExists", $objectuser->login), null, 'errors'); + } else { + setEventMessages($objectuser->error, $objectuser->errors, 'errors'); + } + } + } - if (!$error && !count($objectuser->errors)) { - setEventMessages($langs->trans("UserModified"), null, 'mesgs'); - $db->commit(); - } else { - $db->rollback(); - } - } - } - }*/ + if (!$error && !count($objectuser->errors)) { + setEventMessages($langs->trans("UserModified"), null, 'mesgs'); + $db->commit(); + } else { + $db->rollback(); + } + } + } + }*/ $account->bank = GETPOST('bank', 'alpha'); $account->label = GETPOST('label', 'alpha'); @@ -188,28 +200,36 @@ if ($action == 'update' && !$cancel) if ($action == 'setpersonal_email') { $object->personal_email = (string) GETPOST('personal_email', 'alphanohtml'); $result = $object->update($user); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // update personal mobile if ($action == 'setpersonal_mobile') { $object->personal_mobile = (string) GETPOST('personal_mobile', 'alphanohtml'); $result = $object->update($user); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // update default_c_exp_tax_cat if ($action == 'setdefault_c_exp_tax_cat') { $object->default_c_exp_tax_cat = GETPOST('default_c_exp_tax_cat', 'int'); $result = $object->update($user); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // update default range if ($action == 'setdefault_range') { $object->default_range = GETPOST('default_range', 'int'); $result = $object->update($user); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } @@ -226,16 +246,14 @@ llxHeader(null, $langs->trans("BankAccounts")); $head = user_prepare_head($object); -if ($id && $bankid && $action == 'edit' && $user->rights->user->user->creer) -{ +if ($id && $bankid && $action == 'edit' && $user->rights->user->user->creer) { print '
'; print ''; print ''; print ''; print ''; } -if ($id && $action == 'create' && $user->rights->user->user->creer) -{ +if ($id && $action == 'create' && $user->rights->user->user->creer) { print ''; print ''; print ''; @@ -244,8 +262,7 @@ if ($id && $action == 'create' && $user->rights->user->user->creer) // View -if ($action != 'edit' && $action != 'create') // If not bank account yet, $account may be empty -{ +if ($action != 'edit' && $action != 'create') { // If not bank account yet, $account may be empty $title = $langs->trans("User"); print dol_get_fiche_head($head, 'bank', $title, -1, 'user'); @@ -283,8 +300,7 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco print ''; print ''; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) - { + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { print ''; print ''; print $form->editfieldkey("DefaultCategoryCar", 'default_c_exp_tax_cat', $object->default_c_exp_tax_cat, $object, $user->rights->user->user->creer); @@ -338,8 +354,7 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco // Latest payments of salaries if (!empty($conf->salaries->enabled) && $user->rights->salaries->read && (in_array($object->id, $childids) || $object->id == $user->id) - ) - { + ) { $salary = new PaymentSalary($db); $sql = "SELECT ps.rowid, ps.datesp, ps.dateep, ps.amount"; @@ -349,20 +364,18 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco $sql .= " ORDER BY ps.datesp DESC"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); print ''; print ''; - print ''; - print ''; + print ''; + print ''; $i = 0; - while ($i < $num && $i < $MAXLIST) - { + while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object($resql); print ''; @@ -381,7 +394,9 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco } $db->free($resql); - if ($num <= 0) print '
'; - print '
'.$langs->trans("LastSalaries", ($num <= $MAXLIST ? "" : $MAXLIST)).''.$langs->trans("AllSalaries").''.$num.'
'; + print '
'.$langs->trans("LastSalaries", ($num <= $MAXLIST ? "" : $MAXLIST)).''.$langs->trans("AllSalaries").''.$num.'
'.$langs->trans("None").''; + if ($num <= 0) { + print ''.$langs->trans("None").''; + } print "
"; } else { dol_print_error($db); @@ -393,8 +408,7 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco */ if (!empty($conf->holiday->enabled) && ($user->rights->holiday->readall || ($user->rights->holiday->read && $object->id == $user->id)) - ) - { + ) { $holiday = new Holiday($db); $sql = "SELECT h.rowid, h.statut as status, h.fk_type, h.date_debut, h.date_fin, h.halfday"; @@ -404,20 +418,18 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco $sql .= " ORDER BY h.date_debut DESC"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); print ''; print ''; - print ''; - print ''; + print ''; + print ''; $i = 0; - while ($i < $num && $i < $MAXLIST) - { + while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object($resql); $holiday->id = $objp->rowid; @@ -436,7 +448,9 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco } $db->free($resql); - if ($num <= 0) print '
'; - print '
'.$langs->trans("LastHolidays", ($num <= $MAXLIST ? "" : $MAXLIST)).''.$langs->trans("AllHolidays").''.$num.'
'; + print '
'.$langs->trans("LastHolidays", ($num <= $MAXLIST ? "" : $MAXLIST)).''.$langs->trans("AllHolidays").''.$num.'
'.$langs->trans("None").''; + if ($num <= 0) { + print ''.$langs->trans("None").''; + } print "
"; } else { dol_print_error($db); @@ -448,8 +462,7 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco */ if (!empty($conf->expensereport->enabled) && ($user->rights->expensereport->readall || ($user->rights->expensereport->lire && $object->id == $user->id)) - ) - { + ) { $exp = new ExpenseReport($db); $sql = "SELECT e.rowid, e.ref, e.fk_statut as status, e.date_debut, e.total_ttc"; @@ -459,20 +472,18 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco $sql .= " ORDER BY e.date_debut DESC"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); print ''; print ''; - print ''; - print ''; + print ''; + print ''; $i = 0; - while ($i < $num && $i < $MAXLIST) - { + while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object($resql); $exp->id = $objp->rowid; @@ -490,7 +501,9 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco } $db->free($resql); - if ($num <= 0) print '
'; - print '
'.$langs->trans("LastExpenseReports", ($num <= $MAXLIST ? "" : $MAXLIST)).''.$langs->trans("AllExpenseReports").''.$num.'
'; + print '
'.$langs->trans("LastExpenseReports", ($num <= $MAXLIST ? "" : $MAXLIST)).''.$langs->trans("AllExpenseReports").''.$num.'
'.$langs->trans("None").''; + if ($num <= 0) { + print ''.$langs->trans("None").''; + } print "
"; } else { dol_print_error($db); @@ -589,8 +602,7 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco } - if ($account->id == 0) - { + if ($account->id == 0) { $colspan = 6; print ''.$langs->trans("NoBANRecord").''; } @@ -600,8 +612,7 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco } // Edit -if ($id && ($action == 'edit' || $action == 'create') && $user->rights->user->user->creer) -{ +if ($id && ($action == 'edit' || $action == 'create') && $user->rights->user->user->creer) { $title = $langs->trans("User"); print dol_get_fiche_head($head, 'bank', $title, 0, 'user'); @@ -679,9 +690,13 @@ if ($id && ($action == 'edit' || $action == 'create') && $user->rights->user->us print '
'; } -if ($id && $action == 'edit' && $user->rights->user->user->creer) print ''; +if ($id && $action == 'edit' && $user->rights->user->user->creer) { + print ''; +} -if ($id && $action == 'create' && $user->rights->user->user->creer) print ''; +if ($id && $action == 'create' && $user->rights->user->user->creer) { + print ''; +} // End of page llxFooter(); diff --git a/htdocs/user/card.php b/htdocs/user/card.php index c5820db60b7..45da6f2d6d0 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -48,10 +48,18 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; -if (!empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; -if (!empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; -if (!empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; -if (!empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; +if (!empty($conf->ldap->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; +} +if (!empty($conf->adherent->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; +} +if (!empty($conf->categorie->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +} +if (!empty($conf->stock->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; +} $id = GETPOST('id', 'int'); $action = GETPOST('action', 'aZ09'); @@ -74,15 +82,13 @@ $canedituser = (!empty($user->admin) || $user->rights->user->user->creer); $candisableuser = (!empty($user->admin) || $user->rights->user->user->supprimer); $canreadgroup = $canreaduser; $caneditgroup = $canedituser; -if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) -{ +if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { $canreadgroup = (!empty($user->admin) || $user->rights->user->group_advance->read); $caneditgroup = (!empty($user->admin) || $user->rights->user->group_advance->write); } // Define value to know what current user can do on properties of edited user -if ($id) -{ +if ($id) { // $user est le user qui edite, $id est l'id de l'utilisateur edite $caneditfield = ((($user->id == $id) && $user->rights->user->self->creer) || (($user->id != $id) && $user->rights->user->user->creer)); @@ -92,11 +98,15 @@ if ($id) // Security check $socid = 0; -if ($user->socid > 0) $socid = $user->socid; +if ($user->socid > 0) { + $socid = $user->socid; +} $feature2 = 'user'; $result = restrictedArea($user, 'user', $id, 'user', $feature2); -if ($user->id <> $id && !$canreaduser) accessforbidden(); +if ($user->id <> $id && !$canreaduser) { + accessforbidden(); +} // Load translation files required by page $langs->loadLangs(array('users', 'companies', 'ldap', 'admin', 'hrm', 'stocks')); @@ -120,7 +130,9 @@ $hookmanager->initHooks(array('usercard', 'globalcard')); $parameters = array('id' => $id, 'socid' => $socid, 'group' => $group, 'caneditgroup' => $caneditgroup); $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 ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} if (empty($reshook)) { if ($action == 'confirm_disable' && $confirm == "yes" && $candisableuser) { @@ -153,12 +165,9 @@ if (empty($reshook)) { } } - if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser) - { - if ($id <> $user->id) - { - if (!GETPOSTISSET('token')) - { + if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser) { + if ($id <> $user->id) { + if (!GETPOSTISSET('token')) { print 'Error, token required for this critical operation'; exit; } @@ -315,10 +324,8 @@ if (empty($reshook)) { } // Action add usergroup - if (($action == 'addgroup' || $action == 'removegroup') && $caneditgroup) - { - if ($group) - { + if (($action == 'addgroup' || $action == 'removegroup') && $caneditgroup) { + if ($group) { $editgroup = new UserGroup($db); $editgroup->fetch($group); $editgroup->oldcopy = clone $editgroup; @@ -340,12 +347,10 @@ if (empty($reshook)) { } } - if ($action == 'update' && !$cancel) - { + if ($action == 'update' && !$cancel) { 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; if (!GETPOST("lastname", 'alpha')) { @@ -359,8 +364,7 @@ if (empty($reshook)) { $error++; } - if (!$error) - { + if (!$error) { $object->fetch($id); $object->oldcopy = clone $object; @@ -374,7 +378,9 @@ if (empty($reshook)) { $object->gender = GETPOST("gender", 'aZ09'); $object->pass = GETPOST("password", 'none'); $object->api_key = (GETPOST("api_key", 'alphanohtml')) ? GETPOST("api_key", 'alphanohtml') : $object->api_key; - if (!empty($user->admin)) $object->admin = GETPOST("admin", "int"); // admin flag can only be set/unset by an admin user. A test is also done later when forging sql request + if (!empty($user->admin)) { + $object->admin = GETPOST("admin", "int"); // admin flag can only be set/unset by an admin user. A test is also done later when forging sql request + } $object->address = GETPOST('address', 'alphanohtml'); $object->zip = GETPOST('zipcode', 'alphanohtml'); $object->town = GETPOST('town', 'alphanohtml'); @@ -421,20 +427,16 @@ if (empty($reshook)) { $object->dateendvalidity = $dateendvalidity; $object->birth = $dateofbirth; - if (!empty($conf->stock->enabled)) - { + if (!empty($conf->stock->enabled)) { $object->fk_warehouse = GETPOST('fk_warehouse', 'int'); } $object->lang = GETPOST('default_lang', 'aZ09'); - if (!empty($conf->multicompany->enabled)) - { - if (!empty($_POST["superadmin"])) - { + if (!empty($conf->multicompany->enabled)) { + if (!empty($_POST["superadmin"])) { $object->entity = 0; - } elseif (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) - { + } elseif (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { $object->entity = 1; // all users in master entity } else { $object->entity = (!GETPOST('entity', 'int') ? 0 : GETPOST('entity', 'int')); @@ -452,11 +454,9 @@ if (empty($reshook)) { if (GETPOST('deletephoto')) { $object->photo = ''; } - if (!empty($_FILES['photo']['name'])) - { + if (!empty($_FILES['photo']['name'])) { $isimage = image_format_supported($_FILES['photo']['name']); - if ($isimage > 0) - { + if ($isimage > 0) { $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); } else { $error++; @@ -541,8 +541,7 @@ if (empty($reshook)) { } } - if (!$error && !count($object->errors)) - { + if (!$error && !count($object->errors)) { // Then we add the associated categories $categories = GETPOST('usercats', 'array'); $object->setCategories($categories); @@ -553,8 +552,7 @@ if (empty($reshook)) { $db->commit(); $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 $error++; $langs->load("errors"); setEventMessages($langs->transnoentitiesnoconv("WarningYourLoginWasModifiedPleaseLogin"), null, 'warnings'); @@ -564,8 +562,7 @@ if (empty($reshook)) { } } } else { - if ($caneditpassword) // Case we can edit only password - { + if ($caneditpassword) { // Case we can edit only password dol_syslog("Not allowed to change fields, only password"); $object->fetch($id); @@ -574,8 +571,7 @@ if (empty($reshook)) { $object->oldcopy = clone $object; $ret = $object->setPassword($user, GETPOST("password", "none")); - if ($ret < 0) - { + if ($ret < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } @@ -596,8 +592,7 @@ if (empty($reshook)) { } else { // Succes if ($action == 'confirm_passwordsend' && $confirm == 'yes') { - if ($object->send_password($user, $newpassword) > 0) - { + if ($object->send_password($user, $newpassword) > 0) { setEventMessages($langs->trans("PasswordChangedAndSentTo", $object->email), null, 'mesgs'); } else { setEventMessages($object->error, $object->errors, 'errors'); @@ -686,25 +681,24 @@ $formother = new FormOther($db); $formcompany = new FormCompany($db); $formadmin = new FormAdmin($db); $formfile = new FormFile($db); -if (!empty($conf->stock->enabled)) $formproduct = new FormProduct($db); +if (!empty($conf->stock->enabled)) { + $formproduct = new FormProduct($db); +} llxHeader('', $langs->trans("UserCard")); -if ($action == 'create' || $action == 'adduserldap') -{ +if ($action == 'create' || $action == 'adduserldap') { print load_fiche_titre($langs->trans("NewUser"), '', 'user'); print ''.$langs->trans("CreateInternalUserDesc")."
\n"; print "
"; - if (!empty($conf->ldap->enabled) && (isset($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr')) - { + if (!empty($conf->ldap->enabled) && (isset($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr')) { // Show form to add an account from LDAP if sync LDAP -> Dolibarr is set $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result >= 0) - { + if ($result >= 0) { $required_fields = array( $conf->global->LDAP_KEY_USERS, $conf->global->LDAP_FIELD_FULLNAME, @@ -730,21 +724,17 @@ if ($action == 'create' || $action == 'adduserldap') // Get from LDAP database an array of results $ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1); - if (is_array($ldapusers)) - { + if (is_array($ldapusers)) { $liste = array(); - foreach ($ldapusers as $key => $ldapuser) - { + foreach ($ldapusers as $key => $ldapuser) { // Define the label string for this user $label = ''; - foreach ($required_fields as $value) - { - if ($value === $conf->global->LDAP_FIELD_PASSWORD || $value === $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) - { - $label .= $value."=******* "; - } elseif ($value) { - $label .= $value."=".$ldapuser[$value]." "; - } + foreach ($required_fields as $value) { + if ($value === $conf->global->LDAP_FIELD_PASSWORD || $value === $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) { + $label .= $value."=******* "; + } elseif ($value) { + $label .= $value."=".$ldapuser[$value]." "; + } } $liste[$key] = $label; } @@ -756,35 +746,36 @@ if ($action == 'create' || $action == 'adduserldap') } // If user list is full, we show drop-down list - print "\n\n\n"; + print "\n\n\n"; - print '
'; - print ''; - print ''; - print ''; - print '
'; - print $langs->trans("LDAPUsers"); - print ''; - print ''; - if (is_array($liste) && count($liste)) - { + print ''; + print ''; + print ''; + print ''; + print '
'; + print $langs->trans("LDAPUsers"); + print ''; + print ''; + if (is_array($liste) && count($liste)) { print $form->selectarray('users', $liste, '', 1, 0, 0, '', 0, 0, 0, '', 'maxwidth500'); print ajax_combobox('users'); } - print ''; - print ''; - print '
'; - print ''; + print '
'; + print ''; + print '
'; + print ''; - print "\n\n\n"; - print '
'; + print "\n\n\n"; + print '
'; } print '
'; print ''; print ''; - if (!empty($ldap_sid)) print ''; + if (!empty($ldap_sid)) { + print ''; + } print ''; print dol_get_fiche_head('', '', '', 0, ''); @@ -802,8 +793,7 @@ if ($action == 'create' || $action == 'adduserldap') print ''; print ''.$langs->trans("Lastname").''; print ''; - if (!empty($ldap_lastname)) - { + if (!empty($ldap_lastname)) { print ''; print $ldap_lastname; } else { @@ -814,8 +804,7 @@ if ($action == 'create' || $action == 'adduserldap') // Firstname print ''.$langs->trans("Firstname").''; print ''; - if (!empty($ldap_firstname)) - { + if (!empty($ldap_firstname)) { print ''; print $ldap_firstname; } else { @@ -826,12 +815,10 @@ if ($action == 'create' || $action == 'adduserldap') // Login print ''.$langs->trans("Login").''; print ''; - if (!empty($ldap_login)) - { + if (!empty($ldap_login)) { print ''; print $ldap_login; - } elseif (!empty($ldap_loginsmb)) - { + } elseif (!empty($ldap_loginsmb)) { print ''; print $ldap_loginsmb; } else { @@ -840,8 +827,7 @@ if ($action == 'create' || $action == 'adduserldap') print ''; $generated_password = ''; - if (empty($ldap_sid)) // ldap_sid is for activedirectory - { + if (empty($ldap_sid)) { // ldap_sid is for activedirectory $generated_password = getRandomPassword(false); } $password = (GETPOSTISSET('password') ?GETPOST('password') : $generated_password); @@ -850,18 +836,14 @@ if ($action == 'create' || $action == 'adduserldap') print ''.$langs->trans("Password").''; print ''; $valuetoshow = ''; - if (preg_match('/ldap/', $dolibarr_main_authentication)) - { + if (preg_match('/ldap/', $dolibarr_main_authentication)) { $valuetoshow .= ($valuetoshow ? ', ' : '').$langs->trans("PasswordOfUserInLDAP"); } - if (preg_match('/http/', $dolibarr_main_authentication)) - { + if (preg_match('/http/', $dolibarr_main_authentication)) { $valuetoshow .= ($valuetoshow ? ', ' : '').$langs->trans("HTTPBasicPassword"); } - if (preg_match('/dolibarr/', $dolibarr_main_authentication)) - { - if (!empty($ldap_pass)) // For very old system comaptibilty. Now clear password can't be viewed from LDAP read - { + if (preg_match('/dolibarr/', $dolibarr_main_authentication)) { + if (!empty($ldap_pass)) { // For very old system comaptibilty. Now clear password can't be viewed from LDAP read $valuetoshow .= ($valuetoshow ? ', ' : '').''; // Dolibarr password is preffiled with LDAP known password $valuetoshow .= preg_replace('/./i', '*', $ldap_pass); } else { @@ -873,21 +855,24 @@ if ($action == 'create' || $action == 'adduserldap') // Other form for user password $parameters = array('valuetoshow' => $valuetoshow, 'password' => $password); $reshook = $hookmanager->executeHooks('printUserPasswordField', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if ($reshook > 0) $valuetoshow = $hookmanager->resPrint; // to replace - else $valuetoshow .= $hookmanager->resPrint; // to add + if ($reshook > 0) { + $valuetoshow = $hookmanager->resPrint; // to replace + } else { + $valuetoshow .= $hookmanager->resPrint; // to add + } print $valuetoshow; print ''; - if (!empty($conf->api->enabled)) - { + if (!empty($conf->api->enabled)) { // API key //$generated_password = getRandomPassword(false); print ''.$langs->trans("ApiKey").''; print ''; print ''; - if (!empty($conf->use_javascript_ajax)) + if (!empty($conf->use_javascript_ajax)) { print ' '.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_api_key" class="linkobject"'); + } print ''; } else { // PARTIAL WORKAROUND @@ -896,16 +881,13 @@ if ($action == 'create' || $action == 'adduserldap') } // Administrator - if (!empty($user->admin)) - { + if (!empty($user->admin)) { print ''.$langs->trans("Administrator").''; print ''; print $form->selectyesno('admin', GETPOST('admin'), 1); - if (!empty($conf->multicompany->enabled) && !$user->entity) - { - if (!empty($conf->use_javascript_ajax)) - { + if (!empty($conf->multicompany->enabled) && !$user->entity) { + if (!empty($conf->use_javascript_ajax)) { print '';*/ + if (!empty($conf->use_javascript_ajax)) {/* + print '';*/ } - if (!empty($conf->use_javascript_ajax)) - { + if (!empty($conf->use_javascript_ajax)) { print '