This commit is contained in:
Alexandre MOTTIER 2022-10-14 22:01:49 +02:00
parent 47dd68e273
commit 5c08473d89
Signed by: am
GPG Key ID: AF5BF6F50334C605
10 changed files with 343 additions and 0 deletions

29
class/class.ajout.php Normal file
View File

@ -0,0 +1,29 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width">
<?php
require('sqlconnect.php');
?>
</head>
<?php
require('sqlconnect.php');
$datedebut = $_POST['datedebut'];
$datefin = $_POST['datefin'];
$nbjours = $_POST['nbjours'];
$type = $_POST['type'];
$mysqli = new mysqli($servername, $username, $password, $dbname);
$mysqli->set_charset("utf8");
$req = "INSERT INTO $table VALUES ('$datedebut','$datefin','$nbjours','$type');";
$resultat = $mysqli->query($req);
if ($resultat) {
echo "<p>La saisie a été ajoutée !</p>";
header("refresh:2; url=index.php");
}else{
echo "<p>Erreur</p>";
};
//header("refresh:2; url=form.html");
?>

90
class/class.functions.php Normal file
View File

@ -0,0 +1,90 @@
<?php
//require('class/class.sqlconnect.php');
//require('config.php');
function soldertt($table, $rttparan, $conn){
$resultrtt = mysqli_query($conn, "SELECT SUM(nbjours) AS decomptertt FROM $table WHERE type='RTT' AND datedebut LIKE ");
$rowrtt = mysqli_fetch_assoc($resultrtt);
$sumrtt = $rowrtt['decomptertt'];
$rtt = ($rttparan - $sumrtt);
echo round($rtt,2);
}
function jours($nbjours){
if($nbjours < 2){
echo $nbjours . ' jour';
}
if($nbjours >= 2){
echo $nbjours . ' jours';
}
}
function soldecp($table, $cpparan, $conn){
$resultcp = mysqli_query($conn, "SELECT SUM(nbjours) AS decomptecp FROM $table WHERE type='CP'");
$rowcp = mysqli_fetch_assoc($resultcp);
$sumcp = $rowcp['decomptecp'];
$cp = ($cpparan - $sumcp);
echo round($cp,2);
}
function annee(){
if( (date('m') >= 06) && (date('m') <= 12) ){
echo date("Y")+1;
}
if( (date('m') >= 01) && (date('m') < 06) ){
echo date("Y");
}
}
function anneeplus(){
echo date("Y")+1;
}
function anneeencours(){
echo date("Y");
}
function cumuln1rtt($rttparmois){
$datertt = date('Y') . '-01-01';
$date2 = date('y-m-d');
$ts1rtt = strtotime($datertt);
$ts2 = strtotime($date2);
$year1rtt = date('Y', $ts1rtt);
$year2 = date('Y', $ts2);
$month1rtt = date('m', $ts1rtt);
$month2 = date('m', $ts2);
$diffrtt = (($year2 - $year1rtt) * 12) + ($month2 - $month1rtt);
$cumulrtt = ($rttparmois * $diffrtt);
echo round($cumulrtt, 2);
}
function cumuln1cp($cpparmois){
if( (date('m') >= 06) && (date('m') <= 12) ){
$anneecp = date("Y");
}
if( (date('m') >= 01) && (date('m') < 06) ){
$anneecp = date("Y")-1;
}
$datecp = $anneecp . '-06-01';
$date2 = date('y-m-d');
$ts1cp = strtotime($datecp);
$ts2 = strtotime($date2);
$year1cp = date('Y', $ts1cp);
$year2 = date('Y', $ts2);
$month1cp = date('m', $ts1cp);
$month2 = date('m', $ts2);
$diffcp = (($year2 - $year1cp) * 12) + ($month2 - $month1cp);
$cumulcp = ($cpparmois * $diffcp);
echo round($cumulcp, 2);
}
?>

29
class/class.remove.php Normal file
View File

@ -0,0 +1,29 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width">
<?php
require('sqlconnect.php');
?>
</head>
<?php
require('sqlconnect.php');
$actual_link = $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url_components = parse_url($actual_link);
parse_str($url_components['query'], $params);
$datedebut = $params['datedebut'];
$datefin = $params['datefin'];
$mysqli = new mysqli($servername, $username, $password, $dbname);
$req = "DELETE FROM $table WHERE datedebut = '$datedebut' AND datefin = '$datefin' ;";
$resultat = $mysqli->query($req);
if ($resultat) {
echo "<p>La saisie a été supprimée !</p>";
header("refresh:2; url=index.php");
}else{
echo "<p>Erreur</p>";
};
?>

15
class/class.sqlconnect.php Executable file
View File

@ -0,0 +1,15 @@
<?php
$servername = "localhost";
$username = "conges";
$password = "conges";
$dbname = "gestionconges";
$table = "gestionconges.conges";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>

8
config.php Normal file
View File

@ -0,0 +1,8 @@
<?php
$rttparan = 9; //Nombre de RTT par an
$cpparan = 25; //Nombre de CP par an
$rttparmois = 0.75; // Nombre de RTT par mois (pour calculer les acquis de l'année suivante)
$cpparmois = 2.0833333333; // Nombre de RTT par mois (pour calculer les acquis de l'année suivante)
?>

57
index.php Executable file
View File

@ -0,0 +1,57 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width">
<title>Affichage des congés</title>
<?php
require('class/class.sqlconnect.php');
require('config.php');
require('class/class.functions.php');
?>
</head>
<body>
<h1>Gestion des congés - Affichage</h1>
<h2>Année en cours : <?php echo date('Y'); ?></h2>
<a href="saisie.php">Saisir des congés</a>
<br><br>
<?php
$sql = "SELECT * FROM $table";
$result = $conn->query($sql);
?>
<table>
<thead>
<tr>
<th colspan="5">Congés saisis</th>
</tr>
</thead>
<tbody>
<tr>
<td><b>Date début</b></td>
<td><b>Date fin</b></td>
<td><b>Durée</b></td>
<td><b>Type de congé</b></td>
<td><b>Suppression</b></td>
</tr>
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$debutdate = str_replace('-"', '/', $row["datedebut"]);
$datedebut = date("d/m/Y", strtotime($debutdate));
$findate = str_replace('-"', '/', $row["datefin"]);
$datefin = date("d/m/Y", strtotime($findate));
$nombrejours = $row["nbjours"];
echo "<tr><td> " . $datedebut. " </td><td> " . $datefin. " </td><td> " . $nombrejours . " jour(s) </td><td> ". $row["type"]." </td><td><a href=\"class.remove.php?datedebut=" . $row["datedebut"] . "&datefin=" . $row["datefin"]. "\">Supprimer la ligne</a></td></tr>";
}
} else {
echo "<tr colspan='4'><td>Pas de résultat</td></tr>";
}
$conn->close();
?>
</tbody>
</table>
<br><br>
<?php require('solde.php') ?>
</body>
</html>

33
saisie.php Normal file
View File

@ -0,0 +1,33 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width">
<title>Saisie des congés</title>
<?php
require('class/class.sqlconnect.php');
require('config.php');
require('class/class.functions.php');
?>
</head>
<body>
<h1>Gestion des congés - Saisie</h1>
<a href="index.php">Afficher les congés</a><br><br>
<form class="generated-form" method="POST" action="class.ajout.php" target="_self">
<fieldset>
<legend> Saisie de congés </legend>
<label for="datedebut">Date de début :</label><br>
<input type="date" id="datedebut" name="datedebut"><br>
<label for="datefin">Date de fin :</label><br>
<input type="date" id="datefin" name="datefin"><br>
<label for="nbjours">Nombre de jours :</label><br>
<input type="text" id="nbjours" name="nbjours"><br><br>
<label for="nbjours">Type de congés :</label><br>
<select name="type">
<option value="RTT" stud_name="sre">RTT</option>
<option value="CP" stud_name="sam">Congé payé</option>
</select><br><br>
<input type="submit" value="Valider">
</fieldset>
</body>
</html>

57
solde.php Normal file
View File

@ -0,0 +1,57 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
require('class/class.sqlconnect.php');
require('config.php');
// require('class/class.functions.php');
?>
<fieldset>
<legend>Soldes</legend>
<table>
<thead>
<tr>
<th colspan="3">Solde restant année <?php echo anneeencours(); ?> au <?php echo date('d/m/Y'); ?> </th>
</tr>
</thead>
<tbody>
<tr>
<td>RTT</td>
<td><?php soldertt($table, $rttparan, $conn); ?> jour(s)</td>
<td>Date limite : 31 décembre <?php echo anneeencours(); ?></td>
</tr>
<tr>
<td>Congés payés</td>
<td><?php soldecp($table, $cpparan, $conn); ?> jour(s)</td>
<td>Date limite : 31 mai <?php echo annee(); ?></td>
</tr>
</tbody>
</table>
<br><br>
<table>
<thead>
<tr>
<th colspan="3">Solde acquis année <?php anneeplus(); ?> au 01/<?php echo date('m/Y') ?></th>
</tr>
</thead>
<tbody>
<tr>
<td>RTT</td>
<td><?php echo cumuln1rtt($rttparmois); ?> jour(s)</td>
<td>Entre en vigueur le : 1er janvier <?php anneeplus(); ?></td>
</tr>
<tr>
<td>Congés payés</td>
<td><?php echo cumuln1cp($cpparmois); ?> jour(s)</td>
<td>Entre en vigueur le : 1er juin <?php echo annee(); ?></td>
</tr>
</tbody>
</table>
</fieldset>
</body>
</html>

15
sql/conges.sql Normal file
View File

@ -0,0 +1,15 @@
SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
DROP DATABASE IF EXISTS `gestionconges`;
CREATE DATABASE `gestionconges` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `gestionconges`;
DROP TABLE IF EXISTS `conges`;
CREATE TABLE `conges` (
`datedebut` date NOT NULL,
`datefin` date NOT NULL,
`nbjours` decimal(10,2) NOT NULL,
`type` varchar(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

10
style.css Normal file
View File

@ -0,0 +1,10 @@
table,
td {
border: 1px solid #333;
}
thead,
tfoot {
background-color: #1D4699;
color: #fff;
}