diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 62863ffb1d1..27309ac811e 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -8285,22 +8285,31 @@ abstract class CommonObject
* Initialise object with example values
* Id must be 0 if object instance is a specimen
*
- * @return void
+ * @return int
*/
public function initAsSpecimenCommon()
{
global $user;
$this->id = 0;
- if (array_key_exists('label', $this->fields)) $this->label = 'This is label';
- if (array_key_exists('note_public', $this->fields)) $this->note_public = 'Public note';
- if (array_key_exists('note_private', $this->fields)) $this->note_private = 'Private note';
- if (array_key_exists('date_creation', $this->fields)) $this->date_creation = (dol_now() - 3600 * 24);
- if (array_key_exists('date_modification', $this->fields)) $this->date_modification = (dol_now() - 3600 * 24);
- if (array_key_exists('fk_user_creat', $this->fields)) $this->fk_user_creat = $user->id;
- if (array_key_exists('fk_user_modif', $this->fields)) $this->fk_user_modif = $user->id;
- if (array_key_exists('date', $this->fields)) $this->date = dol_now();
- // ...
+ $this->specimen = 1;
+ $fields = array(
+ 'label' => 'This is label',
+ 'ref' => 'ABCD1234',
+ 'description' => 'This is a description',
+ 'qty' => 123.12,
+ 'note_public' => 'Public note',
+ 'note_private' => 'Private note',
+ 'date_creation' => (dol_now() - 3600 * 48),
+ 'date_modification' => (dol_now() - 3600 * 24),
+ 'fk_user_creat' => $user->id,
+ 'fk_user_modif' => $user->id,
+ 'date' => dol_now(),
+ );
+ foreach ($fields as $key => $value) {
+ if (array_key_exists($key, $this->fields)) $this->{$key} = $value;
+ }
+ return 1;
}
diff --git a/htdocs/core/modules/societe/mod_codeclient_elephant.php b/htdocs/core/modules/societe/mod_codeclient_elephant.php
index 6fca19e40fd..083c3b57024 100644
--- a/htdocs/core/modules/societe/mod_codeclient_elephant.php
+++ b/htdocs/core/modules/societe/mod_codeclient_elephant.php
@@ -138,56 +138,39 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode
*/
public function getExample($langs, $objsoc = 0, $type = -1)
{
- if ($type == 0 || $type == -1)
- {
+ $errmsg = array(
+ "ErrorBadMask",
+ "ErrorCantUseRazIfNoYearInMask",
+ "ErrorCantUseRazInStartedYearIfNoYearMonthInMask",
+ );
+ if ($type != 1) {
$examplecust = $this->getNextValue($objsoc, 0);
- if (!$examplecust)
- {
+ if (!$examplecust) {
$examplecust = $langs->trans('NotConfigured');
}
- if ($examplecust == "ErrorBadMask")
- {
- $langs->load("errors");
- $examplecust = $langs->trans($examplecust);
- }
- if ($examplecust == "ErrorCantUseRazIfNoYearInMask")
- {
- $langs->load("errors");
- $examplecust = $langs->trans($examplecust);
- }
- if ($examplecust == "ErrorCantUseRazInStartedYearIfNoYearMonthInMask")
- {
+ if (in_array($examplecust, $errmsg)) {
$langs->load("errors");
$examplecust = $langs->trans($examplecust);
}
}
- if ($type == 1 || $type == -1)
- {
+ if ($type != 0) {
$examplesup = $this->getNextValue($objsoc, 1);
- if (!$examplesup)
- {
+ if (!$examplesup) {
$examplesup = $langs->trans('NotConfigured');
}
- if ($examplesup == "ErrorBadMask")
- {
- $langs->load("errors");
- $examplesup = $langs->trans($examplesup);
- }
- if ($examplesup == "ErrorCantUseRazIfNoYearInMask")
- {
- $langs->load("errors");
- $examplesup = $langs->trans($examplesup);
- }
- if ($examplesup == "ErrorCantUseRazInStartedYearIfNoYearMonthInMask")
- {
+ if (in_array($examplesup, $errmsg)) {
$langs->load("errors");
$examplesup = $langs->trans($examplesup);
}
}
- if ($type == 0) return $examplecust;
- if ($type == 1) return $examplesup;
- return $examplecust.'
'.$examplesup;
+ if ($type == 0) {
+ return $examplecust;
+ } elseif ($type == 1) {
+ return $examplesup;
+ } else {
+ return $examplecust.'
'.$examplesup;
+ }
}
/**
diff --git a/htdocs/core/modules/societe/modules_societe.class.php b/htdocs/core/modules/societe/modules_societe.class.php
index df280e11679..6fc84ed0669 100644
--- a/htdocs/core/modules/societe/modules_societe.class.php
+++ b/htdocs/core/modules/societe/modules_societe.class.php
@@ -140,11 +140,17 @@ abstract class ModeleThirdPartyCode
global $langs;
$langs->load("admin");
- if ($this->version == 'development') return $langs->trans("VersionDevelopment");
- if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
- if ($this->version == 'dolibarr') return DOL_VERSION;
- if ($this->version) return $this->version;
- return $langs->trans("NotAvailable");
+ if ($this->version == 'development') {
+ return $langs->trans("VersionDevelopment");
+ } elseif ($this->version == 'experimental') {
+ return $langs->trans("VersionExperimental");
+ } elseif ($this->version == 'dolibarr') {
+ return DOL_VERSION;
+ } elseif ($this->version) {
+ return $this->version;
+ } else {
+ return $langs->trans("NotAvailable");
+ }
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -153,7 +159,7 @@ abstract class ModeleThirdPartyCode
*
* @param DoliDB $db Database handler
* @param integer $maxfilenamelength Max length of value to show
- * @return array List of numbers
+ * @return array|int List of numbers
*/
public static function liste_modeles($db, $maxfilenamelength = 0)
{
@@ -193,31 +199,32 @@ abstract class ModeleThirdPartyCode
$langs->load("admin");
$s = '';
- if ($type == -1) $s .= $langs->trans("Name").': '.$this->getNom($langs).'
';
- if ($type == -1) $s .= $langs->trans("Version").': '.$this->getVersion().'
';
- if ($type == 0) $s .= $langs->trans("CustomerCodeDesc").'
';
- if ($type == 1) $s .= $langs->trans("SupplierCodeDesc").'
';
- if ($type != -1) $s .= $langs->trans("ValidityControledByModule").': '.$this->getNom($langs).'
';
+ if ($type == -1) {
+ $s .= $langs->trans("Name").': '.$this->getNom($langs).'
';
+ } elseif ($type == -1) {
+ $s .= $langs->trans("Version").': '.$this->getVersion().'
';
+ } elseif ($type == 0) {
+ $s .= $langs->trans("CustomerCodeDesc").'
';
+ } elseif ($type == 1) {
+ $s .= $langs->trans("SupplierCodeDesc").'
';
+ } elseif ($type != -1) {
+ $s .= $langs->trans("ValidityControledByModule").': '.$this->getNom($langs).'
';
+ }
$s .= '
';
$s .= ''.$langs->trans("ThisIsModuleRules").':
';
- if ($type == 0)
- {
+ if ($type == 0) {
$s .= $langs->trans("RequiredIfCustomer").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '';
$s .= yn(!$this->code_null, 1, 2);
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
$s .= '
';
- }
- if ($type == 1)
- {
+ } elseif ($type == 1) {
$s .= $langs->trans("RequiredIfSupplier").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '';
$s .= yn(!$this->code_null, 1, 2);
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
$s .= '
';
- }
- if ($type == -1)
- {
+ } elseif ($type == -1) {
$s .= $langs->trans("Required").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '';
$s .= yn(!$this->code_null, 1, 2);
@@ -230,14 +237,12 @@ abstract class ModeleThirdPartyCode
$s .= $langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide, 1, 2).'
';
$s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'
';
$s .= '
';
- if ($type == 0 || $type == -1)
- {
+ if ($type == 0 || $type == -1) {
$nextval = $this->getNextValue($soc, 0);
if (empty($nextval)) $nextval = $langs->trans("Undefined");
$s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Customer").')' : '').': '.$nextval.'
';
}
- if ($type == 1 || $type == -1)
- {
+ if ($type == 1 || $type == -1) {
$nextval = $this->getNextValue($soc, 1);
if (empty($nextval)) $nextval = $langs->trans("Undefined");
$s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Supplier").')' : '').': '.$nextval.'';
@@ -317,11 +322,17 @@ abstract class ModeleAccountancyCode
global $langs;
$langs->load("admin");
- if ($this->version == 'development') return $langs->trans("VersionDevelopment");
- if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
- if ($this->version == 'dolibarr') return DOL_VERSION;
- if ($this->version) return $this->version;
- return $langs->trans("NotAvailable");
+ if ($this->version == 'development') {
+ return $langs->trans("VersionDevelopment");
+ } elseif ($this->version == 'experimental') {
+ return $langs->trans("VersionExperimental");
+ } elseif ($this->version == 'dolibarr') {
+ return DOL_VERSION;
+ } elseif ($this->version) {
+ return $this->version;
+ } else {
+ return $langs->trans("NotAvailable");
+ }
}
/**
@@ -339,20 +350,20 @@ abstract class ModeleAccountancyCode
$langs->load("admin");
$s = '';
- if ($type == -1) $s .= $langs->trans("Name").': '.$this->name.'
';
- if ($type == -1) $s .= $langs->trans("Version").': '.$this->getVersion().'
';
+ if ($type == -1) {
+ $s .= $langs->trans("Name").': '.$this->name.'
';
+ $s .= $langs->trans("Version").': '.$this->getVersion().'
';
+ }
//$s.='
';
//$s.=''.$langs->trans("ThisIsModuleRules").':
';
$s .= '
';
- if ($type == 0 || $type == -1)
- {
+ if ($type == 0 || $type == -1) {
$result = $this->get_code($db, $soc, 'customer');
$nextval = $this->code;
if (empty($nextval)) $nextval = $langs->trans("Undefined");
$s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Customer").')' : '').': '.$nextval.'
';
}
- if ($type == 1 || $type == -1)
- {
+ if ($type == 1 || $type == -1) {
$result = $this->get_code($db, $soc, 'supplier');
$nextval = $this->code;
if (empty($nextval)) $nextval = $langs->trans("Undefined");
diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php
index 36a6b9a9aee..71cc3c40da5 100644
--- a/htdocs/fichinter/class/fichinter.class.php
+++ b/htdocs/fichinter/class/fichinter.class.php
@@ -6,7 +6,7 @@
* Copyright (C) 2015 Marcos García
* Copyright (C) 2015-2020 Charlene Benke
* Copyright (C) 2018 Nicolas ZABOURI
- * Copyright (C) 2018-2019 Frédéric France
+ * Copyright (C) 2018-2020 Frédéric France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -635,10 +635,6 @@ class Fichinter extends CommonObject
$this->statut = 1;
$this->brouillon = 0;
$this->date_validation = $now;
- }
-
- if (!$error)
- {
$this->db->commit();
return 1;
} else {
@@ -970,14 +966,13 @@ class Fichinter extends CommonObject
}
}
- if (!$error)
- {
- $main = MAIN_DB_PREFIX.'fichinterdet';
- $ef = $main."_extrafields";
- $sql = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_fichinter = ".$this->id.")";
+ if (!$error) {
+ $main = MAIN_DB_PREFIX.'fichinterdet';
+ $ef = $main."_extrafields";
+ $sql = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_fichinter = ".$this->id.")";
- $resql = $this->db->query($sql);
- if (!$resql) $error++;
+ $resql = $this->db->query($sql);
+ if (!$resql) $error++;
}
if (!$error)
diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php
index acfa9cca3d7..ff815036606 100644
--- a/htdocs/holiday/class/holiday.class.php
+++ b/htdocs/holiday/class/holiday.class.php
@@ -1600,201 +1600,229 @@ class Holiday extends CommonObject
*/
public function fetchUsers($stringlist = true, $type = true, $filters = '')
{
- global $conf;
-
dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
- if ($stringlist)
+ if ($stringlist) {
+ $this->fetchUsersById($type, $filters);
+ } else {
+ $this->fetchUsersByDetail($type, $filters);
+ }
+ }
+
+ /**
+ * Get list of Users or list of vacation balance by User Id
+ *
+ * @param boolean $type If true, read Dolibarr user list, if false, return vacation balance list.
+ * @param string $filters Filters
+ * @return array|string|int Return an array
+ */
+ public function fetchUsersById($type = true, $filters = '')
+ {
+ global $conf;
+
+ dol_syslog(get_class($this)."::fetchUsersById", LOG_DEBUG);
+
+ if ($type)
{
- if ($type)
+ // If user of Dolibarr
+ $sql = "SELECT";
+ if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
+ $sql .= " DISTINCT";
+ }
+ $sql .= " u.rowid";
+ $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
+
+ if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
{
- // If user of Dolibarr
- $sql = "SELECT";
- if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
- $sql .= " DISTINCT";
- }
- $sql .= " u.rowid";
- $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
-
- if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
- {
- $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
- $sql .= " WHERE ((ug.fk_user = u.rowid";
- $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
- $sql .= " OR u.entity = 0)"; // Show always superadmin
- } else {
- $sql .= " WHERE u.entity IN (".getEntity('user').")";
- }
- $sql .= " AND u.statut > 0";
- if ($filters) $sql .= $filters;
-
- $resql = $this->db->query($sql);
-
- // Si pas d'erreur SQL
- if ($resql) {
- $i = 0;
- $num = $this->db->num_rows($resql);
- $stringlist = '';
-
- // Boucles du listage des utilisateurs
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
-
- if ($i == 0) {
- $stringlist .= $obj->rowid;
- } else {
- $stringlist .= ', '.$obj->rowid;
- }
-
- $i++;
- }
- // Retoune le tableau des utilisateurs
- return $stringlist;
- } else {
- // Erreur SQL
- $this->error = "Error ".$this->db->lasterror();
- return -1;
- }
+ $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
+ $sql .= " WHERE ((ug.fk_user = u.rowid";
+ $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
+ $sql .= " OR u.entity = 0)"; // Show always superadmin
} else {
- // We want only list of vacation balance for user ids
- $sql = "SELECT DISTINCT cpu.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
- $sql .= " WHERE cpu.fk_user = u.rowid";
- if ($filters) $sql .= $filters;
+ $sql .= " WHERE u.entity IN (".getEntity('user').")";
+ }
+ $sql .= " AND u.statut > 0";
+ if ($filters) $sql .= $filters;
- $resql = $this->db->query($sql);
+ $resql = $this->db->query($sql);
- // Si pas d'erreur SQL
- if ($resql) {
- $i = 0;
- $num = $this->db->num_rows($resql);
- $stringlist = '';
+ // Si pas d'erreur SQL
+ if ($resql) {
+ $i = 0;
+ $num = $this->db->num_rows($resql);
+ $stringlist = '';
- // Boucles du listage des utilisateurs
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
+ // Boucles du listage des utilisateurs
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
- if ($i == 0) {
- $stringlist .= $obj->fk_user;
- } else {
- $stringlist .= ', '.$obj->fk_user;
- }
-
- $i++;
+ if ($i == 0) {
+ $stringlist .= $obj->rowid;
+ } else {
+ $stringlist .= ', '.$obj->rowid;
}
- // Retoune le tableau des utilisateurs
- return $stringlist;
- } else {
- // Erreur SQL
- $this->error = "Error ".$this->db->lasterror();
- return -1;
+
+ $i++;
}
+ // Retoune le tableau des utilisateurs
+ return $stringlist;
+ } else {
+ // Erreur SQL
+ $this->error = "Error ".$this->db->lasterror();
+ return -1;
}
} else {
- // Si faux donc return array
- // List for Dolibarr users
- if ($type)
- {
- // If user of Dolibarr
- $sql = "SELECT";
- if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
- $sql .= " DISTINCT";
- }
- $sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
+ // We want only list of vacation balance for user ids
+ $sql = "SELECT DISTINCT cpu.fk_user";
+ $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
+ $sql .= " WHERE cpu.fk_user = u.rowid";
+ if ($filters) $sql .= $filters;
- if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
+ $resql = $this->db->query($sql);
+
+ // Si pas d'erreur SQL
+ if ($resql) {
+ $i = 0;
+ $num = $this->db->num_rows($resql);
+ $stringlist = '';
+
+ // Boucles du listage des utilisateurs
+ while ($i < $num)
{
- $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
- $sql .= " WHERE ((ug.fk_user = u.rowid";
- $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
- $sql .= " OR u.entity = 0)"; // Show always superadmin
- } else {
- $sql .= " WHERE u.entity IN (".getEntity('user').")";
- }
+ $obj = $this->db->fetch_object($resql);
- $sql .= " AND u.statut > 0";
- if ($filters) $sql .= $filters;
-
- $resql = $this->db->query($sql);
-
- // Si pas d'erreur SQL
- if ($resql)
- {
- $i = 0;
- $tab_result = $this->holiday;
- $num = $this->db->num_rows($resql);
-
- // Boucles du listage des utilisateurs
- while ($i < $num) {
- $obj = $this->db->fetch_object($resql);
-
- $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
- $tab_result[$i]['name'] = $obj->lastname; // deprecated
- $tab_result[$i]['lastname'] = $obj->lastname;
- $tab_result[$i]['firstname'] = $obj->firstname;
- $tab_result[$i]['gender'] = $obj->gender;
- $tab_result[$i]['status'] = $obj->statut;
- $tab_result[$i]['employee'] = $obj->employee;
- $tab_result[$i]['photo'] = $obj->photo;
- $tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
- //$tab_result[$i]['type'] = $obj->type;
- //$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
-
- $i++;
+ if ($i == 0) {
+ $stringlist .= $obj->fk_user;
+ } else {
+ $stringlist .= ', '.$obj->fk_user;
}
- // Retoune le tableau des utilisateurs
- return $tab_result;
- } else {
- // Erreur SQL
- $this->errors[] = "Error ".$this->db->lasterror();
- return -1;
+
+ $i++;
}
+ // Retoune le tableau des utilisateurs
+ return $stringlist;
} else {
- // List of vacation balance users
- $sql = "SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
- $sql .= " WHERE cpu.fk_user = u.rowid";
- if ($filters) $sql .= $filters;
+ // Erreur SQL
+ $this->error = "Error ".$this->db->lasterror();
+ return -1;
+ }
+ }
+ }
- $resql = $this->db->query($sql);
+ /**
+ * Get list of Users or list of vacation balance by detail
+ *
+ * @param boolean $type If true, read Dolibarr user list, if false, return vacation balance list.
+ * @param string $filters Filters
+ * @return array|string|int Return an array
+ */
+ public function fetchUsersByDetail($type = true, $filters = '')
+ {
+ global $conf;
- // Si pas d'erreur SQL
- if ($resql)
- {
- $i = 0;
- $tab_result = $this->holiday;
- $num = $this->db->num_rows($resql);
+ dol_syslog(get_class($this)."::fetchUsersByDetail", LOG_DEBUG);
- // Boucles du listage des utilisateurs
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
+ // List for Dolibarr users
+ if ($type)
+ {
+ // If user of Dolibarr
+ $sql = "SELECT";
+ if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
+ $sql .= " DISTINCT";
+ }
+ $sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
+ $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
- $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
- $tab_result[$i]['name'] = $obj->lastname; // deprecated
- $tab_result[$i]['lastname'] = $obj->lastname;
- $tab_result[$i]['firstname'] = $obj->firstname;
- $tab_result[$i]['gender'] = $obj->gender;
- $tab_result[$i]['status'] = $obj->statut;
- $tab_result[$i]['employee'] = $obj->employee;
- $tab_result[$i]['photo'] = $obj->photo;
- $tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
+ if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
+ {
+ $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
+ $sql .= " WHERE ((ug.fk_user = u.rowid";
+ $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
+ $sql .= " OR u.entity = 0)"; // Show always superadmin
+ } else {
+ $sql .= " WHERE u.entity IN (".getEntity('user').")";
+ }
- $tab_result[$i]['type'] = $obj->fk_type;
- $tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
+ $sql .= " AND u.statut > 0";
+ if ($filters) $sql .= $filters;
- $i++;
- }
- // Retoune le tableau des utilisateurs
- return $tab_result;
- } else {
- // Erreur SQL
- $this->error = "Error ".$this->db->lasterror();
- return -1;
+ $resql = $this->db->query($sql);
+
+ // Si pas d'erreur SQL
+ if ($resql)
+ {
+ $i = 0;
+ $tab_result = $this->holiday;
+ $num = $this->db->num_rows($resql);
+
+ // Boucles du listage des utilisateurs
+ while ($i < $num) {
+ $obj = $this->db->fetch_object($resql);
+
+ $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
+ $tab_result[$i]['name'] = $obj->lastname; // deprecated
+ $tab_result[$i]['lastname'] = $obj->lastname;
+ $tab_result[$i]['firstname'] = $obj->firstname;
+ $tab_result[$i]['gender'] = $obj->gender;
+ $tab_result[$i]['status'] = $obj->statut;
+ $tab_result[$i]['employee'] = $obj->employee;
+ $tab_result[$i]['photo'] = $obj->photo;
+ $tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
+ //$tab_result[$i]['type'] = $obj->type;
+ //$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
+
+ $i++;
}
+ // Retoune le tableau des utilisateurs
+ return $tab_result;
+ } else {
+ // Erreur SQL
+ $this->errors[] = "Error ".$this->db->lasterror();
+ return -1;
+ }
+ } else {
+ // List of vacation balance users
+ $sql = "SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
+ $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
+ $sql .= " WHERE cpu.fk_user = u.rowid";
+ if ($filters) $sql .= $filters;
+
+ $resql = $this->db->query($sql);
+
+ // Si pas d'erreur SQL
+ if ($resql)
+ {
+ $i = 0;
+ $tab_result = $this->holiday;
+ $num = $this->db->num_rows($resql);
+
+ // Boucles du listage des utilisateurs
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
+ $tab_result[$i]['name'] = $obj->lastname; // deprecated
+ $tab_result[$i]['lastname'] = $obj->lastname;
+ $tab_result[$i]['firstname'] = $obj->firstname;
+ $tab_result[$i]['gender'] = $obj->gender;
+ $tab_result[$i]['status'] = $obj->statut;
+ $tab_result[$i]['employee'] = $obj->employee;
+ $tab_result[$i]['photo'] = $obj->photo;
+ $tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
+
+ $tab_result[$i]['type'] = $obj->fk_type;
+ $tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
+
+ $i++;
+ }
+ // Retoune le tableau des utilisateurs
+ return $tab_result;
+ } else {
+ // Erreur SQL
+ $this->error = "Error ".$this->db->lasterror();
+ return -1;
}
}
}
@@ -1805,7 +1833,7 @@ class Holiday extends CommonObject
* Return list of people with permission to validate leave requests.
* Search for permission "approve leave requests"
*
- * @return array Array of user ids
+ * @return array|int Array of user ids
*/
public function fetch_users_approver_holiday()
{
@@ -1936,7 +1964,8 @@ class Holiday extends CommonObject
$resql = $this->db->query($sql);
if (!$resql)
{
- $error++; $this->errors[] = "Error ".$this->db->lasterror();
+ $error++;
+ $this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error)
@@ -2007,7 +2036,7 @@ class Holiday extends CommonObject
return 2;
}
- // On liste les résultats et on les ajoutent dans le tableau
+ // On liste les résultats et on les ajoute dans le tableau
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php
index 2cc43fb9214..1f471e39ff2 100644
--- a/htdocs/user/class/user.class.php
+++ b/htdocs/user/class/user.class.php
@@ -12,7 +12,7 @@
* Copyright (C) 2015 Marcos García
* Copyright (C) 2018 charlene Benke
* Copyright (C) 2018 Nicolas ZABOURI
- * Copyright (C) 2019 Frédéric France
+ * Copyright (C) 2019-2020 Frédéric France
* Copyright (C) 2019 Abbes Bahfir
*
* This program is free software; you can redistribute it and/or modify
@@ -1408,18 +1408,17 @@ class User extends CommonObject
// phpcs:enable
global $conf;
+ $rd = array();
+ $num = 0;
$sql = "SELECT id FROM ".MAIN_DB_PREFIX."rights_def";
$sql .= " WHERE bydefault = 1";
$sql .= " AND entity = ".$conf->entity;
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
- $rd = array();
- while ($i < $num)
- {
+ while ($i < $num) {
$row = $this->db->fetch_row($resql);
$rd[$i] = $row[0];
$i++;
@@ -1427,8 +1426,7 @@ class User extends CommonObject
$this->db->free($resql);
}
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
$result = $this->db->query($sql);