*
@@ -1228,8 +1228,8 @@ if ($action == 'create')
print '| ';
$defaultselectuser=$user->id;
if (GETPOST('fk_user_author') > 0) $defaultselectuser=GETPOST('fk_user_author');
- $include_users = array($user->id);
- if (! empty($user->rights->expensereport->writeall)) $include_users=array();
+ $include_users = 'hierarchyme';
+ if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expensereport->writeall_advance)) $include_users=array();
$s=$form->select_dolusers($defaultselectuser, "fk_user_author", 0, "", 0, $include_users);
print $s;
print ' | ';
@@ -1313,10 +1313,10 @@ else
if ($result > 0)
{
- if ($object->fk_user_author != $user->id)
+ if (! in_array($object->fk_user_author, $user->getAllChildIds(1)))
{
if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
- && empty($user->rights->expensereport->writeall_advance))
+ && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
{
print load_fiche_titre($langs->trans('TripCard'));
@@ -2090,7 +2090,7 @@ if ($action != 'create' && $action != 'edit')
*/
if ($user->rights->expensereport->creer && $object->fk_statut==0)
{
- if ($object->fk_user_author == $user->id)
+ if (in_array($object->fk_user_author, $user->getAllChildIds(1)))
{
// Modify
print '';
@@ -2138,7 +2138,7 @@ if ($action != 'create' && $action != 'edit')
*/
if ($object->fk_statut == 2)
{
- if ($object->fk_user_author == $user->id)
+ if (in_array($object->fk_user_author, $user->getAllChildIds(1)))
{
// Brouillonner
print '';
diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php
index 574fde69c2a..209d7edb12c 100644
--- a/htdocs/expensereport/class/expensereport.class.php
+++ b/htdocs/expensereport/class/expensereport.class.php
@@ -1674,11 +1674,14 @@ class ExpenseReport extends CommonObject
$now=dol_now();
+ $userchildids = $user->getAllChildIds(1);
+
$sql = "SELECT ex.rowid, ex.date_valid";
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as ex";
if ($option == 'toapprove') $sql.= " WHERE ex.fk_statut = 2";
else $sql.= " WHERE ex.fk_statut = 5";
$sql.= " AND ex.entity IN (".getEntity('expensereport', 1).")";
+ $sql.= " AND ex.fk_user_author IN (".join(',',$userchildids).")";
$resql=$this->db->query($sql);
if ($resql)
diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php
index 7928e0f8e3d..cb54414fe35 100644
--- a/htdocs/expensereport/list.php
+++ b/htdocs/expensereport/list.php
@@ -240,7 +240,7 @@ if ($search_status != '' && $search_status >= 0)
}
// RESTRICT RIGHTS
if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
- && empty($user->rights->expensereport->writeall_advance))
+ && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
{
$childids = $user->getAllChildIds();
$childids[]=$user->id;
diff --git a/htdocs/index.php b/htdocs/index.php
index f4be0dc9c63..16126975b9f 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -178,8 +178,8 @@ if (empty($user->societe_id))
! empty($conf->supplier_order->enabled) && $user->rights->fournisseur->commande->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_ORDERS_STATS),
! empty($conf->supplier_invoice->enabled) && $user->rights->fournisseur->facture->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_INVOICES_STATS),
! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_PROPOSAL_STATS),
- ! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire,
- ! empty($conf->projet->enabled) && $user->rights->projet->lire
+ ! empty($conf->projet->enabled) && $user->rights->projet->lire,
+ ! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire
);
// Class file containing the method load_state_board for each line
$includes=array(
@@ -199,8 +199,8 @@ if (empty($user->societe_id))
DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.commande.class.php",
DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.facture.class.php",
DOL_DOCUMENT_ROOT."/supplier_proposal/class/supplier_proposal.class.php",
- DOL_DOCUMENT_ROOT."/expensereport/class/expensereport.class.php",
- DOL_DOCUMENT_ROOT."/projet/class/project.class.php"
+ DOL_DOCUMENT_ROOT."/projet/class/project.class.php",
+ DOL_DOCUMENT_ROOT."/expensereport/class/expensereport.class.php"
);
// Name class containing the method load_state_board for each line
$classes=array('User',
@@ -219,8 +219,8 @@ if (empty($user->societe_id))
'CommandeFournisseur',
'FactureFournisseur',
'SupplierProposal',
- 'ExpenseReport',
- 'Project'
+ 'Project',
+ 'ExpenseReport'
);
// Cle array returned by the method load_state_board for each line
$keys=array('users',
@@ -239,8 +239,8 @@ if (empty($user->societe_id))
'supplier_orders',
'supplier_invoices',
'askprice',
- 'expensereports',
- 'projects'
+ 'projects',
+ 'expensereports'
);
// Dashboard Icon lines
$icons=array('user',
@@ -259,8 +259,8 @@ if (empty($user->societe_id))
'order',
'bill',
'propal',
- 'trip',
- 'project'
+ 'project',
+ 'trip'
);
// Translation keyword
$titres=array("Users",
@@ -279,8 +279,8 @@ if (empty($user->societe_id))
"SuppliersOrders",
"SuppliersInvoices",
"SupplierProposalShort",
- "ExpenseReports",
- "Projects"
+ "Projects",
+ "ExpenseReports"
);
// Dashboard Link lines
$links=array(
@@ -300,8 +300,8 @@ if (empty($user->societe_id))
DOL_URL_ROOT.'/fourn/commande/list.php',
DOL_URL_ROOT.'/fourn/facture/list.php',
DOL_URL_ROOT.'/supplier_proposal/list.php',
- DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm',
- DOL_URL_ROOT.'/projet/list.php?mainmenu=project'
+ DOL_URL_ROOT.'/projet/list.php?mainmenu=project',
+ DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm'
);
// Translation lang files
$langfile=array("users",
@@ -318,8 +318,8 @@ if (empty($user->societe_id))
"supplier_proposal",
"contracts",
"interventions",
- "trips",
- "projects"
+ "projects",
+ "trips"
);
diff --git a/htdocs/user/card.php b/htdocs/user/card.php
index e7614f06f9d..f6ec03abf91 100644
--- a/htdocs/user/card.php
+++ b/htdocs/user/card.php
@@ -752,9 +752,10 @@ if (($action == 'create') || ($action == 'adduserldap'))
print '';
// Employee
+ $defaultemployee=1;
print '';
- print '| '.fieldLabel('Employee','employee',0).' | ';
- print $form->selectyesno("employee",(GETPOST('employee')?GETPOST('employee'):0),1);
+ print ' | '.$langs->trans('Employee').' | ';
+ print $form->selectyesno("employee",(GETPOST('employee')!=''?GETPOST('employee'):$defaultemployee),1);
print ' |
';
// Position/Job
diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php
index c215f5f29cc..68bfad3a988 100644
--- a/htdocs/user/class/user.class.php
+++ b/htdocs/user/class/user.class.php
@@ -127,6 +127,9 @@ class User extends CommonObject
public $dateemployment; // Define date of employment by company
+ private $cache_childids;
+
+
/**
* Constructor de la classe
*
@@ -2600,26 +2603,38 @@ class User extends CommonObject
}
/**
- * Return list of all child users id in herarchy (all sublevels).
+ * Return list of all child users id in herarchy of current user (all sublevels).
*
+ * @return int $addcurrentuser 1=Add also current user id to the list.
* @return array Array of user id lower than user. This overwrite this->users.
* @see get_children
*/
- function getAllChildIds()
+ function getAllChildIds($addcurrentuser=0)
{
- // Init this->users
- $this->get_full_tree();
-
- $idtoscan=$this->id;
- $childids=array();
-
- dol_syslog("Build childid for id = ".$idtoscan);
- foreach($this->users as $id => $val)
- {
- //var_dump($val['fullpath']);
- if (preg_match('/_'.$idtoscan.'_/', $val['fullpath'])) $childids[$val['id']]=$val['id'];
- }
-
+ $childids=array();
+
+ if (isset($this->cache_childids[$this->id]))
+ {
+ $childids = $this->cache_childids[$this->id];
+ }
+ else
+ {
+ // Init this->users
+ $this->get_full_tree();
+
+ $idtoscan=$this->id;
+
+ dol_syslog("Build childid for id = ".$idtoscan);
+ foreach($this->users as $id => $val)
+ {
+ //var_dump($val['fullpath']);
+ if (preg_match('/_'.$idtoscan.'_/', $val['fullpath'])) $childids[$val['id']]=$val['id'];
+ }
+ }
+ $this->cache_childids[$this->id] = $childids;
+
+ if ($addcurrentuser) $childids[$this->id]=$this->id;
+
return $childids;
}