Skip to content

Commit

Permalink
Fix: Table holiday_user was not initialized anymore.
Browse files Browse the repository at this point in the history
Conflicts:
	htdocs/holiday/class/holiday.class.php
	htdocs/holiday/fiche.php
  • Loading branch information
eldy committed Aug 6, 2014
1 parent 8f73c7a commit 8574871
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 42 deletions.
61 changes: 37 additions & 24 deletions htdocs/holiday/class/holiday.class.php
Expand Up @@ -77,7 +77,7 @@ function __construct($db)


/**
* updateSold
* updateSold. Update sold and check table of users for holidays is complete. If not complete.
*
* @return int Return 1
*/
Expand Down Expand Up @@ -983,25 +983,31 @@ function getCheckOption($name) {
*/
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);
}

}

/**
Expand Down Expand Up @@ -1048,7 +1054,7 @@ function getCPforUser($user_id) {
* 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)
Expand Down Expand Up @@ -1263,50 +1269,56 @@ function countActiveUsersWithoutCP() {
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);

Expand All @@ -1333,11 +1345,12 @@ function verifNbUsers($userDolibarrWithoutCP,$userCP) {
$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;
}
}
Expand Down
7 changes: 5 additions & 2 deletions htdocs/holiday/define_holiday.php
Expand Up @@ -43,14 +43,17 @@
*/

$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']))
Expand Down
32 changes: 16 additions & 16 deletions htdocs/holiday/fiche.php
Expand Up @@ -237,9 +237,9 @@
if($user->rights->holiday->delete)
{
$error=0;

$db->begin();

$cp = new Holiday($db);
$cp->fetch($id);

Expand All @@ -251,12 +251,12 @@
{
$result=$cp->delete($id);
}
else
else
{
$error = $langs->trans('ErrorCantDeleteCP');
}
}

if (! $error)
{
$db->commit();
Expand All @@ -265,7 +265,7 @@
}
else
{
$db->rollback();
$db->rollback();
}
}
}
Expand Down Expand Up @@ -384,7 +384,7 @@
$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);
Expand Down Expand Up @@ -470,7 +470,7 @@
$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);
Expand Down Expand Up @@ -541,7 +541,7 @@
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;
Expand All @@ -568,16 +568,16 @@
$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)
{
Expand Down Expand Up @@ -874,7 +874,7 @@ function valider()
if($user->id == $cp->fk_user || $user->rights->holiday->lire_tous)
{

if ($action == 'delete')
if ($action == 'delete')
{
if($user->rights->holiday->delete)
{
Expand Down Expand Up @@ -943,8 +943,8 @@ function valider()
print $langs->trans($listhalfday[$starthalfday]);
print '</td>';
print '</tr>';
}
else
}
else
{
print '<tr>';
print '<td>'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')</td>';
Expand All @@ -965,8 +965,8 @@ function valider()
print $langs->trans($listhalfday[$endhalfday]);
print '</td>';
print '</tr>';
}
else
}
else
{
print '<tr>';
print '<td>'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')</td>';
Expand Down

0 comments on commit 8574871

Please sign in to comment.