Fix: Table holiday_user was not initialized anymore.

Conflicts:
	htdocs/holiday/class/holiday.class.php
	htdocs/holiday/fiche.php
This commit is contained in:
Laurent Destailleur 2014-08-06 09:08:28 +02:00
parent 8f73c7a82a
commit 85748711b5
3 changed files with 58 additions and 42 deletions

View File

@ -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
*/
@ -983,25 +983,31 @@ class Holiday extends CommonObject
*/
function createCPusers($single=false,$userid='')
{
// Si c'est l'ensemble des utilisateurs à ajoutés
if(!$single)
// Si c'est l'ensemble des utilisateurs à ajouter
if (! $single)
{
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.= " (fk_user, nb_holiday)";
$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.= " (fk_user, nb_holiday)";
$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
*
* @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
*/
function fetchUsers($liste=true,$type=true)
@ -1263,50 +1269,56 @@ class Holiday extends CommonObject
function verifNbUsers($userDolibarrWithoutCP,$userCP) {
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
if ($userDolibarrWithoutCP > 0)
{
$this->updateConfCP('nbUser',$userDolibarr);
$this->db->begin();
$this->updateConfCP('nbUser',$userDolibarrWithoutCP);
$listUsersCP = $this->fetchUsers(true,false);
// On séléctionne les utilisateurs qui ne sont pas déjà dans le module
$sql = "SELECT u.rowid, u.lastname, u.firstname";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE u.rowid NOT IN(".$listUsersCP.")";
$result = $this->db->query($sql);
// Si pas d'erreur SQL
if($result) {
if ($listUsersCP != '') $sql.= " WHERE u.rowid NOT IN(".$listUsersCP.")";
$resql = $this->db->query($sql);
if ($resql)
{
$i = 0;
$num = $this->db->num_rows($resql);
while($i < $num) {
while($i < $num)
{
$obj = $this->db->fetch_object($resql);
$uid = $obj->rowid;
// On ajoute l'utilisateur
$this->createCPusers(true,$obj->rowid);
//print "Add user rowid = ".$uid." into database holiday";
$result = $this->createCPusers(true,$uid);
$i++;
}
$this->db->commit();
} else {
// Erreur SQL
$this->error="Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::verifNbUsers ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
} 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);
@ -1333,11 +1345,12 @@ class Holiday extends CommonObject
$i++;
}
$this->db->commit();
} else {
// Erreur SQL
$this->error="Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::verifNbUsers ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
}

View File

@ -43,14 +43,17 @@ $action=GETPOST('action');
*/
$form = new Form($db);
$userstatic=new User($db);
$holiday = new Holiday($db);
llxHeader(array(),$langs->trans('CPTitreMenu'));
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);
$userstatic=new User($db);
// Si il y a une action de mise à jour
if ($action == 'update' && isset($_POST['update_cp']))

View File

@ -237,9 +237,9 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes')
if($user->rights->holiday->delete)
{
$error=0;
$db->begin();
$cp = new Holiday($db);
$cp->fetch($id);
@ -251,12 +251,12 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes')
{
$result=$cp->delete($id);
}
else
else
{
$error = $langs->trans('ErrorCantDeleteCP');
}
}
if (! $error)
{
$db->commit();
@ -265,7 +265,7 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes')
}
else
{
$db->rollback();
$db->rollback();
}
}
}
@ -384,7 +384,7 @@ if($action == 'confirm_valid')
$verif = $cp->update($user->id);
// Si pas d'erreur SQL on redirige vers la fiche de la demande
if ($verif > 0)
if ($verif > 0)
{
// Calculcate number of days consummed
$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);
// Si pas d'erreur SQL on redirige vers la fiche de la demande
if ($verif > 0)
if ($verif > 0)
{
// To
$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))
{
$db->begin();
$oldstatus = $cp->statut;
$cp->date_cancel = dol_now();
$cp->fk_user_cancel = $user->id;
@ -568,16 +568,16 @@ if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
$error = $langs->trans('ErrorCantDeleteCP');
}
}
if (! $error)
{
$db->commit();
$db->commit();
}
else
{
$db->rollback();
}
// Si pas d'erreur SQL on redirige vers la fiche de la demande
if (! $error && $result > 0)
{
@ -874,7 +874,7 @@ else
if($user->id == $cp->fk_user || $user->rights->holiday->lire_tous)
{
if ($action == 'delete')
if ($action == 'delete')
{
if($user->rights->holiday->delete)
{
@ -943,8 +943,8 @@ else
print $langs->trans($listhalfday[$starthalfday]);
print '</td>';
print '</tr>';
}
else
}
else
{
print '<tr>';
print '<td>'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')</td>';
@ -965,8 +965,8 @@ else
print $langs->trans($listhalfday[$endhalfday]);
print '</td>';
print '</tr>';
}
else
}
else
{
print '<tr>';
print '<td>'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')</td>';