0x1998 - MANAGER
Edit File: calendrier.php
<?php include "config/auth-config.php"; include "config/authcheck.php"; include "config/garde.php"; $libelle_value=array("J"=>"Jour","N"=>"Nuit","W"=>"WE","M"=>"Matin","AM"=>"Ap. M","AM1"=>"12-16","AM2"=>"16-20","AM3"=>"12-18", "Soir3"=>"18-00","Soir"=>"20-00"); $libelle_items=array("++"=>"Souhaité","+"=>"Disponible","-"=>"Ne préfère pas","--"=>"Indisponible","CA"=>"Congés annuels", "RT"=>"RTT", "CF"=>"Congés 'Formation'</small> <span class=\"glyphicon glyphicon-exclamation-sign\" aria-hidden=\"true\" title=\"cliquez pour plus d'explications\" id=\"legende\"></span>"); if (isset($_GET['current_month'])) $current_month=$_GET['current_month']; if (isset($_GET['current_year'])) $current_year=$_GET['current_year']; // On cherche la skill concernée ! if (isset($_SESSION['skill'])) $skill=$_SESSION['skill']; else { $choix_skill=cherche_skill($_SESSION['user'],'dispo'); if ($choix_skill[0]==1) { $skill=$choix_skill[1][1]; $_SESSION['skill']=$skill;} else {$skill=''; $_SESSION['skill']='';} } $result=mysqli_query($link,"select list_skill_denom, list_skill_mois from list_skill where list_skill_id=".$skill); if($result) { $val=mysqli_fetch_array($result); $profil=$val['list_skill_denom']; $decalage=$val['list_skill_mois']; mysqli_free_result($result); } else $profil=''; // VERIFICATION if (!verif_skill_type($_SESSION['user'],'list_skill_dispo')) { $msg="Vos autorisations sont insuffisantes pour cette action"; echo "<meta http-equiv=\"refresh\" content=\"0;url=accueil.php?msg=$msg\"> "; die(); } $liste=autor_liste($_SESSION['user']); $jour_nuit=$liste['journuit']; $quotite=$liste['presence']; if ( (isset($current_month) && $current_month=="") || !isset($current_month)) { $current_month=date("m",time())+$decalage; $current_year=date("Y",time()); } if ($current_month=="0") { $current_month="12"; $current_year=$current_year-1; } else if ($current_month>="13") { $current_month=$current_month-12; $current_year=$current_year+1; } if (strlen($current_month)==1) { $current_month="0".$current_month; } $next_month=$current_month+1; $firstday_nextmonth=mktime(12,0,0,$next_month,1,$current_year); $firstday_currentmonth=mktime(0,0,0,$current_month,1,$current_year); $lastday_previousmonth=$firstday_currentmonth-86400; $lastday_currentmonth=$firstday_nextmonth - 86400; $get_lastday_previousmonth=getdate($lastday_previousmonth); $get_lastday_currentmonth=getdate($lastday_currentmonth); $get_firstday_nextmonth=getdate($firstday_nextmonth); $get_firstday_currentmonth=getdate($firstday_currentmonth); $currentmonth_firstday=$get_firstday_currentmonth['wday']; $previousmonth_lastday=$get_lastday_previousmonth['mday']; $currentmonth_lastday=$get_lastday_currentmonth['mday']; $requete="select limit_bloc from limite_dispo where limit_month='".$current_month."' AND limit_year='".$current_year."' and limit_skill='".$skill."' and limit_type='dispo'"; $result = mysqli_query($link,$requete) or die("requete impossible ...$requete"); $a_row=mysqli_fetch_array($result); if ($a_row[0]!='Y') { $depot=1; } else { $depot=0; $msg = " gelées par l'administrateur !"; } $mois_encours=array(1=>"Janvier", 2=>"Février", 3=>"Mars", 4=>"Avril", 5=>"Mai", 6=>"Juin", 7=>"Juillet", 8=>"Août", 9=>"Septembre", 10=>"Octobre", 11=>"Novembre", 12=>"Décembre"); $bb=date("n",$firstday_currentmonth); // ON CHARGE LES VALEURS -- Si il y a une skill // ON CHARGE LES MATRICES if ($skill!='') { // VALEURS $result=mysqli_query($link,"select day(dispo_date), dispo_etat, dispo_type from dispo where dispo_user=".$_SESSION['user']." and dispo_skill=".$skill." and year(dispo_date)=".$current_year." and month(dispo_date)=".$current_month); while ($row=mysqli_fetch_array($result)) { $dispo[$row[0]][$row['dispo_type']]=$row['dispo_etat']; } mysqli_free_result($result); // MATRICE $result=mysqli_query($link,"select list_matrice_ferie, list_matrice_lundi, list_matrice_mardi, list_matrice_mercredi, list_matrice_jeudi, list_matrice_vendredi, list_matrice_samedi, list_matrice_dimanche from list_matrice_jours where list_matrice_skill=".$skill); $row=mysqli_fetch_array($result); for ($i=0;$i<=7;$i++) { $matrice[$i]=$row[$i]; } mysqli_free_result($result); //ITEMS $result=mysqli_query($link,"select list_matrice_items from list_matrice_jours where list_matrice_skill=".$skill); $row=mysqli_fetch_array($result); $items=explode(";",$row[0]); // DEFAULT $result=mysqli_query($link,"select list_matrice_default from list_matrice_jours where list_matrice_skill=".$skill); $row=mysqli_fetch_array($result); $default_items=$row[0]; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <title>Calendrier</title> <?php entete(); ?> <link href="config/stylePage.css" rel="stylesheet" type="text/css" /> <meta http-equiv='Content-Type' content='text/html; charset=utf8' /> <script type="text/javascript" src="js_fonction.js"></script> <script type="text/javascript"> $(document).ready(function() { if (document.calendrier.skill.value=='') { $("#myModalLabel").html("<center>Fonction</center>"); var loadurl='modal_skill.php'; var targ="#modal-body"; $.get(loadurl, function(data) { $(targ).html(data); $("#modal").modal('show'); }); } $('#update').on('change', function() { changeVal=this.value; if (changeVal!='') { $('.update').val(changeVal); change_trigger(); } }); $("#skill").click(function(){ $("#myModalLabel").html("<center>Fonction</center>"); var loadurl='modal_skill.php'; var targ="#modal-body"; $.get(loadurl, function(data) { $(targ).html(data); $("#modal").modal('show'); }); }) $("#legende").click(function(){ $("#myModalLabel").html("<center>Congés</center>"); var targ="#modal-body"; texte="Indiquez si vous planifiez de poser des congés : Congés Annuels (CA), RTT ou Congés Formation.<br/>"; texte=texte+"Ainsi votre nombre de présences mensuelles sera calculé en fonction du nombre de jours posés."; $(targ).html(texte); $("#modal").modal('show'); }); }); function change(month,year) { window.location.href="calendrier.php?current_month="+month+"¤t_year="+year; } function change_journuit(index) { jour=index.split("_"); nuit='N_'+jour[1]; hhh=document.getElementById(index).value; document.getElementById(nuit).value=hhh; document.calendrier.trigger.value="1"; } function change_trigger() { document.calendrier.trigger.value="1"; } function change_trigger_r() { document.calendrier.trigger.value="0"; } function verifTextarea() { maxlength=150; if (document.calendrier.rem.value.length > maxlength) { alert('Votre remarque ne doit pas dépasser '+maxlength+' caractères!'); return false; } var tab = document.getElementsByTagName("select"); var test=0; for (var i = 0; i < tab.length; i++) { if (tab[i].value == 'CA' || tab[i].value == 'RT' ) test=test+1; } if (test>0) { mess_conf= confirm("Vous avez positionné des CA ou RTT dans vos dispos.\nVoulez-vous revevoir par mail les formulaires de demande ?") if (mess_conf==true) { document.calendrier.printForm.value="1"; } } } function closeModal() { $("#modal").modal('hide'); } function envoiForm2() { $.ajaxSetup({async: false}); if (!validForm('skillz','0')) return false; $.post( "garde_do.php", $( "#skillz" ).serialize(), function(html) {$("#modal").modal('hide'); window.location.reload(); } ); return false; } </script> <script type="text/javascript"> window.onbeforeunload = fermeture_calendrier; </script> </head> <body> <div class="col-md-12 "> <div class="panel panel-primary"> <div class="panel-heading"> <h3><center>Calendrier</center></h3> </div> <div class="panel-body"> <?php if (isset($_GET['msg'])) { $msg=$_GET['msg']; echo "<tr><td class=\"intro\"><font color=red><center>$msg</center></font></td></tr>"; } // DEBUT du FORMULAIRE echo " <div class=\"row\"> <div class=\"col-md-12\"><center> Bienvenue ".$_SESSION['realname']; if ($jour_nuit=='Y') echo " (vos nuits sont identiques à vos jours)"; echo " <span class=\"glyphicon glyphicon-user\" aria-hidden=\"true\" title=\"cliquez pour changer de compétence\" id=\"skill\"></span>"; echo" <div style=\"text-align:center; font-weight:bold;\">Disponibilités de ".$mois_encours[$bb]." ".$current_year." - Profil : ".$profil."</div> "; //------ SI AUTOR 9 ON PEUT GELER LES DISPO----- if (verif_autor($_SESSION['user'],9) && $skill!="") { print " <div style=\"text-align:center;\"> <form method=\"post\" name=\"limit_dispo\" action=\"insertEnreg.php\" > Geler les dispos : NON <input type=\"radio\" name=\"lvalue[0]\" value=\"N\" "; if ($a_row[0]!='Y') echo " checked"; echo " /> OUI <input type=\"radio\" name=\"lvalue[0]\" value=\"Y\" "; if ($a_row[0]=='Y') echo " checked"; echo " /> <input type=\"hidden\" name=\"lvalue[1]\" value=\"$current_month\" /> <input type=\"hidden\" name=\"lvalue[2]\" value=\"$current_year\" /> <input type=\"hidden\" name=\"lvalue[3]\" value=\"$skill\" /> <input type=\"submit\" class=\"btn btn-primary\" name=\"enregLimit\" value=\"Enregistrer\" /> </form><br/></div>"; } echo" </center></div> </div>"; // PANEL N°2-1 echo" <div class=\"col-md-9\"> <div class=\"panel panel-primary\"> <div class=\"panel-body\"><center>"; // TABLEAU DES DISPOS .... echo " <form method=\"post\" name=\"calendrier\" action=\"insertEnreg.php\" onsubmit=\"return verifTextarea()\" > <input type=\"hidden\" name=\"mois\" value=\"$current_month\" /> <input type=\"hidden\" name=\"annee\" value=\"$current_year\" /> <table class=\"table table-bordered\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\" > <tr> <td width=\"110\" style=\"text-align:center;\">Lun</td> <td width=\"110\" style=\"text-align:center;\">Mar</td> <td width=\"110\" style=\"text-align:center;\">Mer</td> <td width=\"110\" style=\"text-align:center;\">Jeu</td> <td width=\"110\" style=\"text-align:center;\">Ven</td> <td width=\"110\" style=\"text-align:center;\">Sam</td> <td width=\"110\" style=\"text-align:center;\">Dim</td></tr> <tr>"; //------------------------------------ // Grisage des premières cellules //------------------------------------ $previous_month=$current_month-1; $previous_year=$current_year; if ($previous_month==0) { $previous_month=12; $previous_year=$current_year-1; } $js=$currentmonth_firstday; if ($js=="0") $js="7"; if ($js!=1) { $jjs=1; for ($counter2=$js-1;$counter2>=1;$counter2--) { creatcell ("","","",$previousmonth_lastday+1-$counter2,$jjs,"2",$jour_nuit,$skill); $jjs++; } } //------------------------------------ // Cellules du mois en cours //------------------------------------ for ($counter3=1;$counter3<=$currentmonth_lastday;$counter3++) { unset($champ); unset($valeur); unset($color); $jour=EstFerie($current_year,$current_month,$counter3)=='N' ? $js:0; // Si ferié jour =0 sinon js ; $matrice_split=explode(";" , $matrice[$jour]); foreach ($matrice_split as $key => $value) { //VALEUR $champ[]=$value; $valeur[$value]=interbase($current_year,$current_month,$counter3,$value); $color[$value]=rechcolor($valeur[$value]); } creatcell ($champ,$color,$valeur,$counter3,$js,"1",$jour_nuit,$skill); if ($js=="7") { echo "</tr><tr>"; $js="1"; } else { $js=$js+1; } } $jj=1; //------------------------------------ // Cellules du mois suivant //------------------------------------ $next_year=$current_year; if ($next_month==13) { $next_month=1; $next_year++; } if ($js!=1) { for ($counter4=$js;$counter4<=7;$counter4++) { creatcell ("","","",$jj,$js,"2",$jour_nuit,$skill); $jj++; } } echo " </tr></table>"; // CHANGEMENT EN MASSE echo " Mettre toutes les valeurs à : <select id=\"update\" > <option value=\"\">--choisir--</option>"; foreach($items as $item) { echo " <option value=\"".$item."\">".$item."</option> "; } echo"</select>"; // $query="select du_rem from dispo_user where du_year='".$current_year."' AND du_user='".$_SESSION['user']."' AND du_month='".$current_month."' AND du_type='dispo' and du_skill=".$skill; $result=mysqli_query($link,$query); $a_row=mysqli_fetch_array($result); echo" <br/> <center> Remarques : <br/> <textarea placeholder=\" 150 caractères maximum ! Soyez concis\" name=\"rem\" rows=\"3\" cols=\"40\" class=\"form-control\">".$a_row[0]."</textarea> <input type=\"hidden\" name=\"trigger\" value=\"0\" /> <input type=\"hidden\" name=\"printForm\" value=\"0\" /> <input type=\"hidden\" name=\"skill\" value=\"".$skill."\" /> <br/>"; if ($depot==1 && $skill!="") echo "<input type=\"submit\" name=\"enregNew\" value=\"Enregistrer\" class=\"btn btn-primary\" onclick=\"change_trigger_r()\" />"; echo " </center></form><br/> <table align=\"center\"> <tr><td align=\"left\"> <a href=\"#\" onclick='change($current_month-1,$current_year)'>Mois précédent</a> </td><td align=\"center\"> <select size=\"1\" class=\"form-control\" name=\"Mois\" onchange=\"change(this[this.selectedIndex].value,$current_year)\">"; for ($counter=1;$counter<13;$counter++) { $mois=date("n",mktime(0,0,0,$counter,1,$current_year)); echo "<option "; if ($counter==$current_month) echo "selected=\"selected\" "; echo "value=\"".$counter."\">".$mois_encours[$mois]."</option>"; } print "</select></td><td align=\"right\"> <a href=\"javascript:change($current_month+1,$current_year)\">Mois suivant</a> </td></tr></table>"; // FIN PANEL 2.1 echo " </center></div> </div> </div>"; // DEBUT DU PANEL 2.2 echo" <div class=\"col-md-3\"> <div class=\"panel panel-primary\"> <div class=\"panel-heading\"> <center>Légende</center> </div> <div class=\"panel-body\"><center><small>"; foreach ($items as $item) { echo $item." : ".$libelle_items[$item]."<br/>"; } // FIN DU PANEL 2.2 echo " </center></div> </div>"; ?> <div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> <h4 class="modal-title" id="myModalLabel"></h4> </div> <div class="modal-body" id="modal-body"> </div> </div> </div> </div> <?php // DEBUT DU PANEL 2.3 if($_SESSION['simpleStats']==0) {$intitule="Statistiques des 3 mois précédents";} else {$intitule="Vos disponibilités de week-end au cours des 3 mois précédents";} echo" <div class=\"panel panel-primary\"> <div class=\"panel-heading\"> <center>".$intitule."</center> </div> <div class=\"panel-body\">"; include_stats($current_month,$current_year); echo" </center></div> </div> </div>"; // ROW INF echo" <div class=\"row\"> <div class=\"col-md-12\"> <center><button class=\"btn btn-default\" onclick=\"location.href = 'accueil.php'\">Retour à l'accueil</button></center> </div></div>"; // FIN DU FORMULAIRE ET DE LA CELLULE ?> </div> </div> </div> </body> </html> <?php // FONCTIONS function creatcell($champ,$color,$valeur,$text,$js,$sel,$jour_nuit,$skill) { global $libelle_value; global $items; print "<td width=\"100\" valign=\"top\" bgcolor=\"#FFFFFF\" class=\"calendar\"> <table cellpadding=\"0\" cellspacing=\"0\" > <tr> <td width=\"1\" valign=\"top\"> <img src=\"config/spacer.gif\" width=\"1\" height=\"50\" alt=\"\" /> </td> <td width=\"80\" > <table cellpadding=\"0\" cellspacing=\"0\" >"; if ($sel==1) { //$nbre_champ=count($champ); // On compte le nombre de champ à mettre echo "<input type=\"hidden\" name=\"champjs[".$text."]\" value=\"".$js."\" />"; // champ js foreach($champ as $key => $value) { echo "<tr>";// ouverture de la ligne echo "<td bgcolor=\"".$color[$value]."\">"; echo "<span style=\"text-align:center;font-size:11px;\">".$libelle_value[$value]."</span></td>"; echo" <td><select name=\"champ[$text][$value]\" id=\"".$value."_".$text."\" size=\"1\" "; if ($jour_nuit=='Y' && $value=='J') echo "onchange=\"change_journuit(this.id)\" "; else echo "onchange=\"change_trigger()\" "; echo " class=\"update\" style=\"font-size:10px;\" >"; foreach($items as $item) { echo " <option "; if ($valeur[$value]==$item) echo "selected=\"selected\" "; echo "value=\"".$item."\">".$item."</option> "; } echo" </select> </td></tr>"; } // SORTIE DE BOUCLE CHAMP } // SORTIE DE IF SEL==1 echo " </table></td> <td width=\"9\" valign=\"center\"><span style=\"text-align:center;font-size:11px;\"><b>".$text."</b></span> </td> </tr> </table> </td>"; } function interbase($year,$month,$day,$type) { global $dispo; global $default_items; $reponse= isset($dispo[$day][$type]) ? $dispo[$day][$type] : $default_items; return $reponse; } function rechcolor($val) { if ($val=="++" || $val=="") { return "#66FF66"; } elseif ($val=="+") { return "#BEF781"; } elseif ($val=="-" ) { return "#FE9A2E"; } elseif ($val=="--") { return "#FF0000"; } elseif ($val=="Abs" || $val=="CA"|| $val=="RT"|| $val=="CF") { return "#71C4F8"; } } function include_stats($month,$year) { global $link; $dateDeb="'".$year."-".$month."-01'"; $id=$_SESSION['user']; $query="SELECT dispo_js, dispo_type,count(dispo_id) FROM `dispo` WHERE dispo_user=$id and dispo_skill=".$_SESSION['skill']." and `dispo_date` >= ($dateDeb-INTERVAL 3 MONTH) and `dispo_date`< $dateDeb group by dispo_js, dispo_type"; $result=mysqli_query($link,$query); while ($a_row=mysqli_fetch_array($result)) { $index=$a_row[0].$a_row[1]; $stats0[$index]=$a_row[2]; } $query2="SELECT dispo_js, dispo_type,count(dispo_id) FROM `dispo` WHERE `dispo_date` >= ($dateDeb-INTERVAL 3 MONTH) and `dispo_date`< $dateDeb and dispo_skill='".$_SESSION['skill']."' group by dispo_js, dispo_type"; $result2=mysqli_query($link,$query2); while ($a_row=mysqli_fetch_array($result2)) { $index=$a_row[0].$a_row[1]; $stats5[$index]=$a_row[2]; } $query="SELECT dispo_js, dispo_type,count(dispo_id) FROM `dispo` WHERE dispo_user=$id and `dispo_date` >= ($dateDeb-INTERVAL 3 MONTH) and `dispo_date`< $dateDeb and (dispo_etat='++' or dispo_etat='+') group by dispo_js, dispo_type"; $result=mysqli_query($link,$query); while ($a_row=mysqli_fetch_array($result)) { $index=$a_row[0].$a_row[1]; $stats1[$index]=$a_row[2]; } $query="SELECT dispo_js, dispo_type,count(dispo_id) FROM `dispo` WHERE `dispo_date` >= ($dateDeb-INTERVAL 3 MONTH) and `dispo_date`< $dateDeb and dispo_skill='".$_SESSION['skill']."' and (dispo_etat='++' or dispo_etat='+') group by dispo_js, dispo_type"; $result=mysqli_query($link,$query); while ($a_row=mysqli_fetch_array($result)) { $index=$a_row[0].$a_row[1]; $stats3[$index]=$a_row[2]; } /* Je pense que cela ne sert à rien ... a supprimer si prouvé ! $query="SELECT distinct dispo_user FROM `dispo` WHERE `dispo_date` >= ($dateDeb-INTERVAL 3 MONTH) and `dispo_date`< $dateDeb "; $result=mysqli_query($link,$query); $num_rows = mysql_num_rows($result); */ if (isset($stats0)) { foreach ($stats0 as $key => $value) { if (!isset($stats1[$key])) $stats1[$key]=0; if (!isset($stats3[$key])) $stats3[$key]=0; $stats2[$key]=round(($stats1[$key]/$stats0[$key])*100,0); $stats4[$key]=round((($stats3[$key]/$stats5[$key]))*100,0); } } $indexJour=array( 1 => 'Lundi', 2 => 'Mardi', 3 => 'Mercredi', 4 => 'Jeudi', 5 => 'Vendredi', 6 => 'Samedi', 7 => 'Dimanche', ); echo" <table class=\"table table-bordered\" style=\"font-size:12px;\"> <tr> <th style=\"text-align: center;\">Jour</th> <th colspan=\"2\">Disponibilité</th>"; if($_SESSION['simpleStats']==0) echo" <th>Générale</th>"; echo" </tr>"; if ($_SESSION['simpleStats']==0) { for($j=1;$j<6;$j++) { if (isset($stats2)) { $detailJ=$j."J"; $detailN=$j."N"; $classJ=rechClass($stats2[$detailJ],$stats4[$detailJ]); $classN=rechClass($stats2[$detailN],$stats4[$detailN]); echo" <tr> <td rowspan=2 style=\"vertical-align: middle;\">".$indexJour[$j]."</td> <td>Jour</td> <td ".$classJ.">".$stats2[$detailJ]."%". "</td> <td style=\"text-align: center;\">".$stats4[$detailJ]."% </tr> <tr> <td>Nuit</td> <td ".$classN.">".$stats2[$detailN]."%". "</td> <td style=\"text-align: center;\">".$stats4[$detailN]."% </tr>"; } } } for($j=6;$j<8;$j++) { if (isset($stats2)) { $detailW=$j."W"; $classW=rechClass($stats2[$detailW],$stats4[$detailW]); echo" <tr> <td style=\"vertical-align: middle;\">".$indexJour[$j]."</td> <td>WE</td> <td ".$classW.">".$stats2[$detailW]."%". "</td>"; if($_SESSION['simpleStats']==0) echo" <td style=\"text-align: center;\">".$stats4[$detailW]."% </td>"; echo" </tr>"; } } echo" </table> "; } function rechClass($valeur,$moyenne) { if ($valeur<$moyenne-5) { $class="class='danger'"; } elseif ($moyenne-5<=$valeur && $valeur<=$moyenne+5) { $class="class='warning'"; } elseif($valeur>$moyenne+5) { $class="class='success'"; } return $class; } mysqli_close($link); ?>