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

This commit is contained in:
Laurent Destailleur 2020-11-02 11:41:19 +01:00
commit 5f290e0de1
6 changed files with 296 additions and 271 deletions

View File

@ -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;
}

View File

@ -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.'<br>'.$examplesup;
if ($type == 0) {
return $examplecust;
} elseif ($type == 1) {
return $examplesup;
} else {
return $examplecust.'<br>'.$examplesup;
}
}
/**

View File

@ -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").': <b>'.$this->getNom($langs).'</b><br>';
if ($type == -1) $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
if ($type == 0) $s .= $langs->trans("CustomerCodeDesc").'<br>';
if ($type == 1) $s .= $langs->trans("SupplierCodeDesc").'<br>';
if ($type != -1) $s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
if ($type == -1) {
$s .= $langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>';
} elseif ($type == -1) {
$s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
} elseif ($type == 0) {
$s .= $langs->trans("CustomerCodeDesc").'<br>';
} elseif ($type == 1) {
$s .= $langs->trans("SupplierCodeDesc").'<br>';
} elseif ($type != -1) {
$s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
}
$s .= '<br>';
$s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
if ($type == 0)
{
if ($type == 0) {
$s .= $langs->trans("RequiredIfCustomer").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
$s .= yn(!$this->code_null, 1, 2);
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
$s .= '<br>';
}
if ($type == 1)
{
} elseif ($type == 1) {
$s .= $langs->trans("RequiredIfSupplier").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
$s .= yn(!$this->code_null, 1, 2);
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
$s .= '<br>';
}
if ($type == -1)
{
} elseif ($type == -1) {
$s .= $langs->trans("Required").': ';
if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
$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).'<br>';
$s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>';
$s .= '<br>';
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").')' : '').': <b>'.$nextval.'</b><br>';
}
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").')' : '').': <b>'.$nextval.'</b>';
@ -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").': <b>'.$this->name.'</b><br>';
if ($type == -1) $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
if ($type == -1) {
$s .= $langs->trans("Name").': <b>'.$this->name.'</b><br>';
$s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
}
//$s.='<br>';
//$s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
$s .= '<br>';
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").')' : '').': <b>'.$nextval.'</b><br>';
}
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");

View File

@ -6,7 +6,7 @@
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015-2020 Charlene Benke <charlie@patas-monkey.com>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
*
* 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)

View File

@ -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);

View File

@ -12,7 +12,7 @@
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 charlene Benke <charlie@patas-monkey.com>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019-2020 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019 Abbes Bahfir <dolipar@dolipar.org>
*
* 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);