Example #1
0
function affiche_cellule_jour_cal_saisie($login, $j_timestamp, $td_second_class, $result)
{
    $date_j = date('Y-m-d', $j_timestamp);
    $j = date('d', $j_timestamp);
    $class_am = 'travail_am';
    $class_pm = 'travail_pm';
    $val_matin = '';
    $val_aprem = '';
    // recup des infos ARTT ou Temps Partiel :
    // la fonction suivante change les valeurs de $val_matin $val_aprem ....
    recup_infos_artt_du_jour($login, $j_timestamp, $val_matin, $val_aprem);
    //## AFICHAGE ##
    if ($val_matin == 'Y') {
        $class_am = 'rtt_am';
    }
    if ($val_aprem == 'Y') {
        $class_pm = 'rtt_pm';
    }
    $jour_today = date('j');
    $mois_today = date('m');
    $year_today = date('Y');
    $timestamp_today = mktime(0, 0, 0, $mois_today, $jour_today, $year_today);
    // si la saisie de conges pour une periode passée est interdite : pas de case à cocher dans les dates avant aujourd'hui
    if ($_SESSION['config']['interdit_saisie_periode_date_passee'] && $j_timestamp < $timestamp_today) {
        echo '<td  class="cal-saisie ' . $td_second_class . ' ' . $class_am . ' ' . $class_pm . '">' . $j . '</td>';
    } else {
        echo '<td  class="cal-saisie ' . $td_second_class . ' ' . $class_am . ' ' . $class_pm . '">' . $j . '<input type="radio" name="' . $result . '" ';
        if ($_SESSION['config']['rempli_auto_champ_nb_jours_pris']) {
            // attention : IE6 : bug avec les "OnChange" sur les boutons radio!!! (on remplace par OnClick)
            if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE') != FALSE) {
                echo 'onClick="compter_jours();return true;"';
            } else {
                echo 'onChange="compter_jours();return false;"';
            }
        }
        echo ' value="' . $date_j . '"></td>';
    }
}
function compter($user, $num_current_periode, $date_debut, $date_fin, $opt_debut, $opt_fin, &$comment, $DEBUG = FALSE, $num_update = null)
{
    // verif si date_debut est bien anterieure à date_fin
    // ou si meme jour mais debut l'apres midi et fin le matin
    if (strtotime($date_debut) > strtotime($date_fin) || $date_debut == $date_fin && $opt_debut == "pm" && $opt_fin == "am") {
        $comment = _('calcul_nb_jours_commentaire_bad_date');
        return 0;
    }
    if ($date_debut != 0 && $date_fin != 0) {
        // On ne peut pas calculer si, pour l'année considérée, les jours feries ont ete saisis
        if (verif_jours_feries_saisis($date_debut, $DEBUG, $num_update) == FALSE || verif_jours_feries_saisis($date_fin, $DEBUG, $num_update) == FALSE) {
            $comment = _('calcul_impossible') . "<br>\n" . _('jours_feries_non_saisis') . "<br>\n" . _('contacter_admin') . "<br>\n";
            return 0;
        }
        /************************************************************/
        // 1 : on fabrique un tableau de jours (divisé chacun en 2 demi-jour) de la date_debut à la date_fin
        // 2 : on verifie que le conges demandé ne chevauche pas une periode deja posée
        // 3 : on affecte à 0 ou 1 chaque demi jour, en fonction de s'il est travaillé ou pas
        // 4 : à la fin , on parcours le tableau en comptant le nb de demi-jour à 1, on multiplie ce total par 0.5, ça donne le nb de jours du conges !
        $nb_jours = 0;
        /************************************************************/
        // 1 : fabrication et initialisation du tableau des demi-jours de la date_debut à la date_fin
        $tab_periode_calcul = make_tab_demi_jours_periode($date_debut, $date_fin, $opt_debut, $opt_fin, $DEBUG);
        /************************************************************/
        // 2 : on verifie que le conges demandé ne chevauche pas une periode deja posée
        if (verif_periode_chevauche_periode_user($date_debut, $date_fin, $user, $num_current_periode, $tab_periode_calcul, $comment, $DEBUG, $num_update)) {
            return 0;
        }
        /************************************************************/
        // 3 : on affecte à 0 ou 1 chaque demi jour, en fonction de s'il est travaillé ou pas
        // on initialise le tableau global des jours fériés s'il ne l'est pas déjà :
        if (!isset($_SESSION["tab_j_feries"])) {
            init_tab_jours_feries();
            //print_r($_SESSION["tab_j_feries"]);   // verif DEBUG
        }
        // on initialise le tableau global des jours fermés s'il ne l'est pas déjà :
        if (!isset($_SESSION["tab_j_fermeture"])) {
            init_tab_jours_fermeture($user, $DEBUG);
            //print_r($_SESSION["tab_j_fermeture"]);   // verif DEBUG
        }
        $current_day = $date_debut;
        $date_limite = jour_suivant($date_fin);
        // on va avancer jour par jour jusqu'à la date limite et voir si chaque jour est travaillé, férié, rtt, etc ...
        while ($current_day != $date_limite) {
            // calcul du timestamp du jour courant
            $pieces = explode("-", $current_day);
            // date de la forme yyyy-mm-jj
            $y = $pieces[0];
            $m = $pieces[1];
            $j = $pieces[2];
            $timestamp_du_jour = mktime(0, 0, 0, $m, $j, $y);
            // on regarde si le jour est travaillé ou pas dans la config de l'appli
            $j_name = date("D", $timestamp_du_jour);
            if ($j_name == "Sat" && $_SESSION['config']['samedi_travail'] == FALSE || $j_name == "Sun" && $_SESSION['config']['dimanche_travail'] == FALSE) {
                // on ne compte ce jour à 0
                $tab_periode_calcul[$current_day]['am'] = 0;
                $tab_periode_calcul[$current_day]['pm'] = 0;
            } elseif (est_chome($timestamp_du_jour)) {
                // on ne compte ce jour à 0
                $tab_periode_calcul[$current_day]['am'] = 0;
                $tab_periode_calcul[$current_day]['pm'] = 0;
            } else {
                /***************/
                // verif des rtt ou temp partiel (dans la table rtt)
                $val_matin = "N";
                $val_aprem = "N";
                recup_infos_artt_du_jour($user, $timestamp_du_jour, $val_matin, $val_aprem);
                if ($val_matin == "Y") {
                    // rtt le matin
                    $tab_periode_calcul[$current_day]['am'] = 0;
                }
                if ($val_aprem == "Y") {
                    // rtt l'après midi
                    $tab_periode_calcul[$current_day]['pm'] = 0;
                }
            }
            $current_day = jour_suivant($current_day);
        }
        if ($DEBUG) {
            echo "tab_periode_calcul :<br>\n";
            print_r($tab_periode_calcul);
            echo "<br>\n";
        }
        /************************************************************/
        // 3 : on va avancer jour par jour jusqu'à la date limite pour compter le nb de demi jour à 1
        $current_day = $date_debut;
        $date_limite = jour_suivant($date_fin);
        while ($current_day != $date_limite) {
            $nb_jours = $nb_jours + $tab_periode_calcul[$current_day]['am'] + $tab_periode_calcul[$current_day]['pm'];
            $current_day = jour_suivant($current_day);
        }
        $nb_jours = $nb_jours * 0.5;
        return $nb_jours;
    } else {
        return 0;
    }
}
Example #3
0
 public static function affiche_calendrier_saisie_jour_absence($user_login, $year, $mois)
 {
     $return = '';
     $jour_today = date('j');
     $jour_today_name = date('D');
     $first_jour_mois_timestamp = mktime(0, 0, 0, $mois, 1, $year);
     $last_jour_mois_timestamp = mktime(0, 0, 0, $mois + 1, 0, $year);
     $mois_name = date_fr('F', $first_jour_mois_timestamp);
     $first_jour_mois_rang = date('w', $first_jour_mois_timestamp);
     // jour de la semaine en chiffre (0=dim , 6=sam)
     $last_jour_mois_rang = date('w', $last_jour_mois_timestamp);
     // jour de la semaine en chiffre (0=dim , 6=sam)
     $nb_jours_mois = ($last_jour_mois_timestamp - $first_jour_mois_timestamp + 60 * 60 * 12) / (24 * 60 * 60);
     // + 60*60 *12 for f*****g DST
     if ($first_jour_mois_rang == 0) {
         $first_jour_mois_rang = 7;
     }
     // jour de la semaine en chiffre (1=lun , 7=dim)
     if ($last_jour_mois_rang == 0) {
         $last_jour_mois_rang = 7;
     }
     // jour de la semaine en chiffre (1=lun , 7=dim)
     $return .= '<table class="table calendrier_saisie_date">';
     $return .= '<thead><tr><th colspan="7" class="titre"> ' . $mois_name . ' ' . $year . ' </th></tr><tr><th class="cal-saisie2">' . _('lundi_1c') . '</th><th class="cal-saisie2">' . _('mardi_1c') . '</th><th class="cal-saisie2">' . _('mercredi_1c') . '</th><th class="cal-saisie2">' . _('jeudi_1c') . '</th><th class="cal-saisie2">' . _('vendredi_1c') . '</th><th class="cal-saisie2">' . _('samedi_1c') . '</th><th class="cal-saisie2">' . _('dimanche_1c') . '</th></tr></thead>';
     $return .= '<tbody>';
     $start_nb_day_before = $first_jour_mois_rang - 1;
     $stop_nb_day_before = 7 - $last_jour_mois_rang;
     for ($i = -$start_nb_day_before; $i <= $nb_jours_mois + $stop_nb_day_before; $i++) {
         if (($i + $start_nb_day_before) % 7 == 0) {
             $return .= '<tr>';
         }
         $j_timestamp = mktime(0, 0, 0, $mois, $i + 1, $year);
         $td_second_class = get_td_class_of_the_day_in_the_week($j_timestamp);
         if ($i < 0 || $i > $nb_jours_mois || $td_second_class == 'weekend') {
             $return .= '<td class="' . $td_second_class . '">-</td>';
         } else {
             $val_matin = '';
             $val_aprem = '';
             recup_infos_artt_du_jour($user_login, $j_timestamp, $val_matin, $val_aprem);
             $return .= \utilisateur\Fonctions::affiche_cellule_calendrier_echange_absence_saisie_semaine($val_matin, $val_aprem, $year, $mois, $i + 1);
         }
         if (($i + $start_nb_day_before) % 7 == 6) {
             $return .= '<tr>';
         }
     }
     $return .= '</tbody>';
     $return .= '</table>';
     return $return;
 }
function affiche_cellule_jour_cal_saisie($login, $j_timestamp, $td_second_class, $result, $DEBUG = FALSE)
{
    $date_j = date('Y-m-d', $j_timestamp);
    $j = date('d', $j_timestamp);
    $class_am = 'travail_am';
    $class_pm = 'travail_pm';
    $val_matin = '';
    $val_aprem = '';
    // recup des infos ARTT ou Temps Partiel :
    // la fonction suivante change les valeurs de $val_matin $val_aprem ....
    recup_infos_artt_du_jour($login, $j_timestamp, $val_matin, $val_aprem, $DEBUG);
    //## AFICHAGE ##
    if ($val_matin == 'Y') {
        $class_am = 'rtt_am';
    }
    if ($val_aprem == 'Y') {
        $class_pm = 'rtt_pm';
    }
    $jour_today = date('j');
    $mois_today = date('m');
    $year_today = date('Y');
    $timestamp_today = mktime(0, 0, 0, $mois_today, $jour_today, $year_today);
    // si la saisie de conges pour une periode passée est interdite : pas de case à cocher dans les dates avant aujourd'hui
    if ($_SESSION['config']['interdit_saisie_periode_date_passee'] && $j_timestamp < $timestamp_today) {
        echo '<td  class="cal-saisie ' . $td_second_class . ' ' . $class_am . ' ' . $class_pm . '">' . $j . '</td>';
    } else {
        // Si le client est sous IE, on affiche pas les jours de rtt (car IE ne gère pas les appels standart de classe de feuille e style)
        // if( (isset($_SERVER["HTTP_USER_AGENT"])) && (stristr($_SERVER["HTTP_USER_AGENT"], "MSIE")!=FALSE) )
        // {
        // echo "<td  class=\"cal-saisie\">$j<input type=\"radio\" name=\"$result\" ";
        // if($_SESSION['config']['rempli_auto_champ_nb_jours_pris'])
        // {
        // attention : IE6 : bug avec les "OnChange" sur les boutons radio!!! (on remplace par OnClick)
        // if( (isset($_SERVER["HTTP_USER_AGENT"])) && (stristr($_SERVER["HTTP_USER_AGENT"], "MSIE")!=FALSE) )
        // echo "onClick=\"compter_jours(new_debut, new_fin, login_user, new_demi_jour_deb, new_demi_jour_fin);return true;\"" ;
        // else
        // echo "onChange=\"compter_jours(new_debut, new_fin, login_user, new_demi_jour_deb, new_demi_jour_fin);return false;\"" ;
        // }
        // echo " value=\"$date_j\"></td>";
        // }
        // else
        // {
        echo '<td  class="cal-saisie ' . $td_second_class . ' ' . $class_am . ' ' . $class_pm . '">' . $j . '<input type="radio" name="' . $result . '" ';
        if ($_SESSION['config']['rempli_auto_champ_nb_jours_pris']) {
            // attention : IE6 : bug avec les "OnChange" sur les boutons radio!!! (on remplace par OnClick)
            if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE') != FALSE) {
                echo 'onClick="compter_jours(new_debut, new_fin, login_user, new_demi_jour_deb, new_demi_jour_fin);return true;"';
            } else {
                echo 'onChange="compter_jours(new_debut, new_fin, login_user, new_demi_jour_deb, new_demi_jour_fin);return false;"';
            }
        }
        echo ' value="' . $date_j . '"></td>';
        // }
    }
}
function  affiche_calendrier_saisie_jour_presence($user_login, $year, $mois, $DEBUG=FALSE)
{
	$jour_today					= date('j');
	$jour_today_name			= date('D');

	$first_jour_mois_timestamp	= mktime(0,0,0,$mois,1,$year);
	$last_jour_mois_timestamp	= mktime(0,0,0,$mois +1 , 1,$year);
	
	$mois_name					= date_fr('F', $first_jour_mois_timestamp);
	
	$first_jour_mois_rang		= date('w', $first_jour_mois_timestamp);      // jour de la semaine en chiffre (0=dim , 6=sam)
	$last_jour_mois_rang		= date('w', $last_jour_mois_timestamp);      // jour de la semaine en chiffre (0=dim , 6=sam)
	$nb_jours_mois				= ( $last_jour_mois_timestamp - $first_jour_mois_timestamp  + 60*60 *12 ) / (24 * 60 * 60);// + 60*60 *12 for f*****g DST
	
	if( $first_jour_mois_rang == 0 )
		$first_jour_mois_rang=7 ;    // jour de la semaine en chiffre (1=lun , 7=dim)
		
	if( $last_jour_mois_rang == 0 )
		$last_jour_mois_rang=7 ;    // jour de la semaine en chiffre (1=lun , 7=dim)

	echo '<table class="calendrier_saisie_date_debut" cellpadding="0" cellspacing="0">';
		echo '<thead>
				<tr align="center" bgcolor="'.$_SESSION['config']['light_grey_bgcolor'].'">
						<td colspan=7 class="titre"> '.$mois_name.' '.$year.' </td>
				</tr>
				<tr bgcolor="'.$_SESSION['config']['light_grey_bgcolor'].'">
					<td class="cal-saisie2">'. _('lundi_1c') .'</td>
					<td class="cal-saisie2">'. _('mardi_1c') .'</td>
					<td class="cal-saisie2">'. _('mercredi_1c') .'</td>
					<td class="cal-saisie2">'. _('jeudi_1c') .'</td>
					<td class="cal-saisie2">'. _('vendredi_1c') .'</td>
					<td class="cal-saisie2">'. _('samedi_1c') .'</td>
					<td class="cal-saisie2">'. _('dimanche_1c') .'</td>
				</tr>
			</thead>';
		echo '<tbody>';

			$start_nb_day_before = $first_jour_mois_rang -1;
			$stop_nb_day_before = 7 - $last_jour_mois_rang ;
			
			
			for ( $i = - $start_nb_day_before; $i <= $nb_jours_mois + $stop_nb_day_before; $i ++) {
				if ( ($i + $start_nb_day_before ) % 7 == 0)
					echo '<tr>';
				
				
				$j_timestamp=mktime (0,0,0,$mois, $i +1 ,$year);
				$td_second_class = get_td_class_of_the_day_in_the_week($j_timestamp);
				
				if ($i < 0 || $i > $nb_jours_mois || $td_second_class == 'weekend') {
					echo '<td class="'.$td_second_class.'">-</td>';
				}
				else {	
					$val_matin='';
					$val_aprem='';
					recup_infos_artt_du_jour($user_login, $j_timestamp, $val_matin, $val_aprem,  $DEBUG);
					affiche_cellule_calendrier_echange_presence_saisie_semaine($val_matin, $val_aprem, $year, $mois, $i + 1, $DEBUG);
				}
				
				if ( ($i + $start_nb_day_before ) % 7 == 6)
					echo '<tr>';
			}

		echo '</tbody>';
	echo '</table>';
	

}