}
                    }
                }
            }
            $step .= '<br>' . $test . '
				<input type="hidden" name="step" value="3"><input type="hidden" name="salle" value="' . $salle . '">
				<input type="submit" name="retour" class="btn btn-default btn-flat" value=" <<">
				
				<input type="submit" class="btn btn-success btn-flat" name="valider" value="Valider la r&eacute;servation">
					 </form>
					';
            break;
    }
}
//affichage
if (TRUE == checkInter($_SESSION['resa']['idcomp'])) {
    ?>
  <div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                    <h4><i class="icon fa fa-warning"></i> <b>ATTENTION</b> </h4>Une intervention est en cours sur cette machine, veuillez vous adresser &agrave;
votre animateur afin qu'il vous confirme la possibilit&eacute; de r&eacute;server cette machine</div>
<?php 
}
?>

<div class="row"><section class="col-lg-7 connectedSortable"> 

<div class="box"><div class="box-header"><h3 class="box-title">Réservation</h3></div>
<div class="box-body">

<a class="<?php 
echo $step1;
function getPlanning($dotd, $h1begin, $h1end, $h2begin, $h2end, $epn, $salle)
{
    if ($h1begin == 0 and $h2begin > 0) {
        $h1begin = $h2begin;
    }
    if ($h2end == 0 and $h1begin > 0) {
        $h2end = $h1end;
    }
    if ($h1begin == 0 and $h2end == 0) {
        return FALSE;
        exit;
    }
    // Initialisation des variables
    $graf = "";
    $unit = getConfig("unit_config", "unit_default_config", $epn);
    // unité dans la table config
    $unitLabel = 30;
    // echelle de division du temps pour les labels des heures
    $h1begin = floor($h1begin / 60) * 60;
    // on recupere l"heure de debut ex : 9h15 =>9h => 540mn
    if ($h2end != floor($h2end / 60) * 60) {
        $h2end = floor($h2end / 60) * 60 + 60;
    }
    // on recupere l"heure de fin ex : 19h15 =>20h
    $nbTotM = $h2end - $h1begin;
    // nombre total de minute d'ouverture
    $widthPause = getWidth($h2begin - $h1end, $nbTotM, $unit) * (60 / $unit);
    $positionPause = getPosition($h1end, $h1begin, getWidthPerUnit($nbTotM, $unit)) * (60 / $unit);
    // selection des machines par salle
    $result = getAllMaterielDispo($salle);
    // affichage du resultat
    if (mysqli_num_rows($result) < 1) {
        $graf = "Aucun ordinateur dans la salle s&eacute;lection&eacute;e, veuillez choisir une autre salle";
    } else {
        // Creation du tableau
        $graf .= "<table  class=\"table table-condensed\">";
        // ligne des horaires - echelle au dessus des reservations
        $graf .= "<tr><td></td><td >";
        for ($i = 0; $i < $nbTotM / $unitLabel; $i++) {
            if ($i == $nbTotM / $unitLabel - 1) {
                $largeur = getWidth(60, $nbTotM, $unitLabel) - 2;
                if (strlen(getTime($h1begin + $i * $unitLabel)) <= 3) {
                    $graf .= "<div class=\"labelHor\" style=\"width:" . $largeur . "%;\">|" . getTime($h1begin + $i * $unitLabel) . "</div>";
                } else {
                    $graf .= "<div class=\"labelHor1\" style=\"width:" . $largeur . "%;\">|30</div>";
                }
            } else {
                $time = getTime($h1begin + $i * $unitLabel);
                if (strlen(getTime($h1begin + $i * $unitLabel)) <= 3) {
                    $graf .= "<div class=\"labelHor\" style=\"width:" . getWidth(60, $nbTotM, $unitLabel) . "%;\">|" . $time . "</div>";
                } else {
                    $graf .= "<div class=\"labelHor1\" style=\"width:" . getWidth(60, $nbTotM, $unitLabel) . "%;\">|30</div>";
                }
            }
        }
        $graf .= "</td></tr>";
        //affichage des machines + liste des reservations
        while ($row = mysqli_fetch_array($result)) {
            //old function affichage par usage//
            if ($row['NB'] == "") {
                $nbCritere = '';
            } else {
                $nbCritere = ' (' . $row['NB'] . ')';
            }
            ///
            if (strtotime($dotd) < strtotime(date("Y-m-d"))) {
                $graf .= "<tr><td class=\"computer\" >" . $row["nom_computer"] . "</td>\n                        <td class=\"horaire\">";
            } else {
                /*if(COUNT($usage)==$row['NB']) // si la recherche est exacte
                  {
                    $graf .= "<tr><td class=\"computer2\"><a href=\"index.php?m=7&idepn=".$epn."&idcomp=".$row["id_computer"]."&nomcomp=".$row["nom_computer"]."&date=".$dotd."\">".$row["nom_computer"]."".$nbCritere."</a></td>
                                <td class=\"horaire\">" ;
                    $lineExist = TRUE ;         
                                
                  }
                  else // sinon on affiche les resultats avec les autres criteres de recherche
                  {*/
                if (FALSE == checkInter($row["id_computer"])) {
                    //si pas d'intervention
                    $graf .= "<tr><td class=\"computer\"><a href=\"index.php?m=7&idepn=" . $epn . "&idcomp=" . $row["id_computer"] . "&nomcomp=" . $row["nom_computer"] . "&date=" . $dotd . "\">" . $row["nom_computer"] . "" . $nbCritere . "</a></td>\n                            <td class=\"horaire\">";
                } else {
                    $graf .= "<tr><td class=\"computer\"><span data-toggle=\"tooltip\" title=\"Une intervention est en cours sur ce poste, pas de réservation possible !\" class=\"text-red\">" . $row["nom_computer"] . "</span></td>\n                            <td class=\"horaire\">";
                }
                //  }
            }
            // affichage des horaires et des occupations
            $result2 = getResa($row["id_computer"], $dotd);
            $width = 0;
            $position = 0;
            $widthTmp = 0;
            $widthTmp2 = 0;
            $i = 0;
            while ($row2 = mysqli_fetch_array($result2)) {
                $i = 0;
                // largeur en % du div representant la resa
                $width = getWidth($row2["duree_resa"], $nbTotM, $unit) * (60 / $unit);
                // recupere la position absolue dans le tableau
                $positionTmp = getPosition($row2["debut_resa"], $h1begin, getWidthPerUnit($nbTotM, $unit));
                // position en % du div en cours (represente l'ecart avec celui de devant)
                $position = ($positionTmp - $widthTmp2) * (60 / $unit) - $unit / 60 * $i;
                if ($position < 0) {
                    $position = 0;
                }
                // Affichage de la ligne d'une machine;
                $urlGraf = "#p" . $row2["id_user_resa"];
                //Ajout lien vers ancre dans la liste//$_SERVER['REQUEST_URI'] ; //."&idResa=".$row2['id_resa'];
                if ($_SESSION['status'] == 3 or $_SESSION['status'] == 4) {
                    // comment d'admin et d'anim
                    $altGraf = "(" . getUserName($row2["id_user_resa"]) . " - " . getTime($row2["debut_resa"]) . " &agrave; " . getTime($row2["debut_resa"] + $row2["duree_resa"]) . ")";
                } else {
                    // comment d'utilisateur
                    $altGraf = "(" . getTime($row2["debut_resa"]) . " &agrave; " . getTime($row2["debut_resa"] + $row2["duree_resa"]) . ")";
                }
                $graf .= "<div class=\"unitbusy\" style=\"width:" . $width . "%;left:" . $position . "%;\">\n                                <a href=\"" . $urlGraf . "\" alt=\"" . $altGraf . "\" title=\"" . $altGraf . "\">" . getTime($row2["duree_resa"]) . "</a>\n                            </div>";
                $widthTmp = $widthTmp + $width;
                $widthTmp2 = $widthTmp / (60 / $unit);
                ++$i;
                //echo $position.'% = (PA:'.$positionTmp.'-W'.$widthTmp.')*(60/'.$unit.') -- width:'.$width.'% -- nbTotM:'.$nbTotM.'<br/>';
            }
            // fin de l'affichage des horaires et des occupations
            $graf .= "</td></tr>";
        }
        // ligne des horaires - echelle en dessous du tableau de reservation 2
        $graf .= "<tr><td></td><td >";
        for ($i = 0; $i < $nbTotM / $unitLabel; $i++) {
            if ($i == $nbTotM / $unitLabel - 1) {
                if (strlen(getTime($h1begin + $i * $unitLabel)) <= 3) {
                    $graf .= "<div class=\"labelHor\" style=\"width:" . (getWidth(60, $nbTotM, $unitLabel) - 2) . "%;\">|" . getTime($h1begin + $i * $unitLabel) . "</div>";
                } else {
                    $graf .= "<div class=\"labelHor1\" style=\"width:" . (getWidth(60, $nbTotM, $unitLabel) - 2) . "%;\">|30</div>";
                }
            } else {
                if (strlen(getTime($h1begin + $i * $unitLabel)) <= 3) {
                    $graf .= "<div class=\"labelHor\" style=\"width:" . getWidth(60, $nbTotM, $unitLabel) . "%;\">|" . getTime($h1begin + $i * $unitLabel) . "</div>";
                } else {
                    $graf .= "<div class=\"labelHor1\" style=\"width:" . getWidth(60, $nbTotM, $unitLabel) . "%;\">|30</div>";
                }
            }
        }
        $graf .= "</td></tr>";
        $graf .= "</table>";
    }
    return $graf;
}