Fix: Table holiday_user was not initialized anymore.
Conflicts: htdocs/holiday/class/holiday.class.php htdocs/holiday/fiche.php
This commit is contained in:
parent
8f73c7a82a
commit
85748711b5
@ -77,7 +77,7 @@ class Holiday extends CommonObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updateSold
|
* updateSold. Update sold and check table of users for holidays is complete. If not complete.
|
||||||
*
|
*
|
||||||
* @return int Return 1
|
* @return int Return 1
|
||||||
*/
|
*/
|
||||||
@ -983,25 +983,31 @@ class Holiday extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function createCPusers($single=false,$userid='')
|
function createCPusers($single=false,$userid='')
|
||||||
{
|
{
|
||||||
// Si c'est l'ensemble des utilisateurs à ajoutés
|
// Si c'est l'ensemble des utilisateurs à ajouter
|
||||||
if(!$single)
|
if (! $single)
|
||||||
{
|
{
|
||||||
dol_syslog(get_class($this).'::createCPusers');
|
dol_syslog(get_class($this).'::createCPusers');
|
||||||
foreach($this->fetchUsers(false,true) as $users) {
|
$arrayofusers = $this->fetchUsers(false,true);
|
||||||
|
|
||||||
|
foreach($arrayofusers as $users)
|
||||||
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
|
||||||
$sql.= " (fk_user, nb_holiday)";
|
$sql.= " (fk_user, nb_holiday)";
|
||||||
$sql.= " VALUES ('".$users['rowid']."','0')";
|
$sql.= " VALUES ('".$users['rowid']."','0')";
|
||||||
|
|
||||||
$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
|
if (! $resql) dol_print_error($this->db);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
|
||||||
$sql.= " (fk_user, nb_holiday)";
|
$sql.= " (fk_user, nb_holiday)";
|
||||||
$sql.= " VALUES ('".$userid."','0')";
|
$sql.= " VALUES ('".$userid."','0')";
|
||||||
|
|
||||||
$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
|
if (! $resql) dol_print_error($this->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1048,7 +1054,7 @@ class Holiday extends CommonObject
|
|||||||
* uniquement pour vérifier si il existe de nouveau utilisateur
|
* uniquement pour vérifier si il existe de nouveau utilisateur
|
||||||
*
|
*
|
||||||
* @param boolean $liste si vrai retourne une liste, si faux retourne un array
|
* @param boolean $liste si vrai retourne une liste, si faux retourne un array
|
||||||
* @param boolean $type si vrai retourne pour Dolibarr si faux retourne pour CP
|
* @param boolean $type si vrai retourne pour Dolibarr, si faux retourne pour CP
|
||||||
* @return string retourne un tableau de tout les utilisateurs actifs
|
* @return string retourne un tableau de tout les utilisateurs actifs
|
||||||
*/
|
*/
|
||||||
function fetchUsers($liste=true,$type=true)
|
function fetchUsers($liste=true,$type=true)
|
||||||
@ -1263,50 +1269,56 @@ class Holiday extends CommonObject
|
|||||||
function verifNbUsers($userDolibarrWithoutCP,$userCP) {
|
function verifNbUsers($userDolibarrWithoutCP,$userCP) {
|
||||||
|
|
||||||
if (empty($userCP)) $userCP=0;
|
if (empty($userCP)) $userCP=0;
|
||||||
dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarr.' userCP='.$userCP);
|
dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
|
||||||
|
|
||||||
// On vérifie les users Dolibarr sans CP
|
// On vérifie les users Dolibarr sans CP
|
||||||
if ($userDolibarrWithoutCP > 0)
|
if ($userDolibarrWithoutCP > 0)
|
||||||
{
|
{
|
||||||
$this->updateConfCP('nbUser',$userDolibarr);
|
$this->db->begin();
|
||||||
|
|
||||||
|
$this->updateConfCP('nbUser',$userDolibarrWithoutCP);
|
||||||
|
|
||||||
$listUsersCP = $this->fetchUsers(true,false);
|
$listUsersCP = $this->fetchUsers(true,false);
|
||||||
|
|
||||||
// On séléctionne les utilisateurs qui ne sont pas déjà dans le module
|
// On séléctionne les utilisateurs qui ne sont pas déjà dans le module
|
||||||
$sql = "SELECT u.rowid, u.lastname, u.firstname";
|
$sql = "SELECT u.rowid, u.lastname, u.firstname";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
|
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
|
||||||
$sql.= " WHERE u.rowid NOT IN(".$listUsersCP.")";
|
if ($listUsersCP != '') $sql.= " WHERE u.rowid NOT IN(".$listUsersCP.")";
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
|
||||||
|
|
||||||
// Si pas d'erreur SQL
|
|
||||||
if($result) {
|
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
|
|
||||||
while($i < $num) {
|
while($i < $num)
|
||||||
|
{
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
$uid = $obj->rowid;
|
||||||
|
|
||||||
// On ajoute l'utilisateur
|
// On ajoute l'utilisateur
|
||||||
$this->createCPusers(true,$obj->rowid);
|
//print "Add user rowid = ".$uid." into database holiday";
|
||||||
|
|
||||||
|
$result = $this->createCPusers(true,$uid);
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
} else {
|
} else {
|
||||||
// Erreur SQL
|
// Erreur SQL
|
||||||
$this->error="Error ".$this->db->lasterror();
|
$this->error="Error ".$this->db->lasterror();
|
||||||
dol_syslog(get_class($this)."::verifNbUsers ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::verifNbUsers ".$this->error, LOG_ERR);
|
||||||
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Si il y a moins d'utilisateur Dolibarr que dans le module CP
|
$this->db->begin();
|
||||||
|
|
||||||
$this->updateConfCP('nbUser',$userDolibarr);
|
// Si il y a moins d'utilisateur Dolibarr que dans le module CP
|
||||||
|
|
||||||
|
$this->updateConfCP('nbUser',$userDolibarrWithoutCP);
|
||||||
|
|
||||||
$listUsersDolibarr = $this->fetchUsers(true,true);
|
$listUsersDolibarr = $this->fetchUsers(true,true);
|
||||||
|
|
||||||
@ -1333,11 +1345,12 @@ class Holiday extends CommonObject
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
} else {
|
} else {
|
||||||
// Erreur SQL
|
// Erreur SQL
|
||||||
$this->error="Error ".$this->db->lasterror();
|
$this->error="Error ".$this->db->lasterror();
|
||||||
dol_syslog(get_class($this)."::verifNbUsers ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::verifNbUsers ".$this->error, LOG_ERR);
|
||||||
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,14 +43,17 @@ $action=GETPOST('action');
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$form = new Form($db);
|
$form = new Form($db);
|
||||||
|
$userstatic=new User($db);
|
||||||
|
$holiday = new Holiday($db);
|
||||||
|
|
||||||
|
|
||||||
llxHeader(array(),$langs->trans('CPTitreMenu'));
|
llxHeader(array(),$langs->trans('CPTitreMenu'));
|
||||||
|
|
||||||
print_fiche_titre($langs->trans('MenuConfCP'));
|
print_fiche_titre($langs->trans('MenuConfCP'));
|
||||||
|
|
||||||
$holiday = new Holiday($db);
|
$holiday->updateSold(); // Create users into table holiday if they don't exists. TODO Remove if we use field into table user.
|
||||||
|
|
||||||
$listUsers = $holiday->fetchUsers(false,false);
|
$listUsers = $holiday->fetchUsers(false,false);
|
||||||
$userstatic=new User($db);
|
|
||||||
|
|
||||||
// Si il y a une action de mise à jour
|
// Si il y a une action de mise à jour
|
||||||
if ($action == 'update' && isset($_POST['update_cp']))
|
if ($action == 'update' && isset($_POST['update_cp']))
|
||||||
|
|||||||
@ -237,9 +237,9 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes')
|
|||||||
if($user->rights->holiday->delete)
|
if($user->rights->holiday->delete)
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
$cp = new Holiday($db);
|
$cp = new Holiday($db);
|
||||||
$cp->fetch($id);
|
$cp->fetch($id);
|
||||||
|
|
||||||
@ -251,12 +251,12 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes')
|
|||||||
{
|
{
|
||||||
$result=$cp->delete($id);
|
$result=$cp->delete($id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$error = $langs->trans('ErrorCantDeleteCP');
|
$error = $langs->trans('ErrorCantDeleteCP');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
@ -265,7 +265,7 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes')
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -384,7 +384,7 @@ if($action == 'confirm_valid')
|
|||||||
$verif = $cp->update($user->id);
|
$verif = $cp->update($user->id);
|
||||||
|
|
||||||
// Si pas d'erreur SQL on redirige vers la fiche de la demande
|
// Si pas d'erreur SQL on redirige vers la fiche de la demande
|
||||||
if ($verif > 0)
|
if ($verif > 0)
|
||||||
{
|
{
|
||||||
// Calculcate number of days consummed
|
// Calculcate number of days consummed
|
||||||
$nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1);
|
$nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1);
|
||||||
@ -470,7 +470,7 @@ if ($action == 'confirm_refuse')
|
|||||||
$verif = $cp->update($user->id);
|
$verif = $cp->update($user->id);
|
||||||
|
|
||||||
// Si pas d'erreur SQL on redirige vers la fiche de la demande
|
// Si pas d'erreur SQL on redirige vers la fiche de la demande
|
||||||
if ($verif > 0)
|
if ($verif > 0)
|
||||||
{
|
{
|
||||||
// To
|
// To
|
||||||
$destinataire = new User($db);
|
$destinataire = new User($db);
|
||||||
@ -541,7 +541,7 @@ if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
|
|||||||
if (($cp->statut == 2 || $cp->statut == 3) && ($user->id == $cp->fk_validator || $user->id == $cp->fk_user))
|
if (($cp->statut == 2 || $cp->statut == 3) && ($user->id == $cp->fk_validator || $user->id == $cp->fk_user))
|
||||||
{
|
{
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
$oldstatus = $cp->statut;
|
$oldstatus = $cp->statut;
|
||||||
$cp->date_cancel = dol_now();
|
$cp->date_cancel = dol_now();
|
||||||
$cp->fk_user_cancel = $user->id;
|
$cp->fk_user_cancel = $user->id;
|
||||||
@ -568,16 +568,16 @@ if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
|
|||||||
$error = $langs->trans('ErrorCantDeleteCP');
|
$error = $langs->trans('ErrorCantDeleteCP');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si pas d'erreur SQL on redirige vers la fiche de la demande
|
// Si pas d'erreur SQL on redirige vers la fiche de la demande
|
||||||
if (! $error && $result > 0)
|
if (! $error && $result > 0)
|
||||||
{
|
{
|
||||||
@ -874,7 +874,7 @@ else
|
|||||||
if($user->id == $cp->fk_user || $user->rights->holiday->lire_tous)
|
if($user->id == $cp->fk_user || $user->rights->holiday->lire_tous)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($action == 'delete')
|
if ($action == 'delete')
|
||||||
{
|
{
|
||||||
if($user->rights->holiday->delete)
|
if($user->rights->holiday->delete)
|
||||||
{
|
{
|
||||||
@ -943,8 +943,8 @@ else
|
|||||||
print $langs->trans($listhalfday[$starthalfday]);
|
print $langs->trans($listhalfday[$starthalfday]);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')</td>';
|
print '<td>'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')</td>';
|
||||||
@ -965,8 +965,8 @@ else
|
|||||||
print $langs->trans($listhalfday[$endhalfday]);
|
print $langs->trans($listhalfday[$endhalfday]);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')</td>';
|
print '<td>'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')</td>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user