Buongiorno
in questo sito c'è il "portale ferie" che significa che ogni utente può richiedere un giorno di ferie
Ho la tabella users che tramite le sessioni l'utente accede e la tabella ferie che contiene username, spettanti, godute, rimanenti.
Nella pagina ferie.php vorrei inserire una tabella con il riepilogo e poi c'è un pulsante nuova richiesta dove c'è il form modale che porta a registrazione-ferie.php che dovrebbe cambiare il valore dei 2 campi godute e rimanti con -1 e +1 ma prima controllare che il campo rimanenti sia maggiore di 0 altrimenti mostra messaggio.
ferie.php
registrazione-ferie.php (che è il file da completare)
Vi ringrazio in anticipo per l'aiuto
in questo sito c'è il "portale ferie" che significa che ogni utente può richiedere un giorno di ferie
Ho la tabella users che tramite le sessioni l'utente accede e la tabella ferie che contiene username, spettanti, godute, rimanenti.
Nella pagina ferie.php vorrei inserire una tabella con il riepilogo e poi c'è un pulsante nuova richiesta dove c'è il form modale che porta a registrazione-ferie.php che dovrebbe cambiare il valore dei 2 campi godute e rimanti con -1 e +1 ma prima controllare che il campo rimanenti sia maggiore di 0 altrimenti mostra messaggio.
ferie.php
PHP:
<?php
session_start();
require_once('database.php');
if (isset($_SESSION['session_id']))
{ $session_user = htmlspecialchars($_SESSION['session_user'], ENT_QUOTES, 'UTF-8');
$session_id = htmlspecialchars($_SESSION['session_id'], ENT_QUOTES, 'UTF-8');
$session_nome = htmlspecialchars($_SESSION['session_nome'], ENT_QUOTES, 'UTF-8');
$session_email = htmlspecialchars($_SESSION['session_email'], ENT_QUOTES, 'UTF-8');
$session_codice_dip = htmlspecialchars($_SESSION['session_codice_dip'], ENT_QUOTES, 'UTF-8');
$session_titolo = htmlspecialchars($_SESSION['session_titolo'], ENT_QUOTES, 'UTF-8');
$session_direzione = htmlspecialchars($_SESSION['session_direzione'], ENT_QUOTES, 'UTF-8');
$session_area = htmlspecialchars($_SESSION['session_area'], ENT_QUOTES, 'UTF-8');
$session_unita = htmlspecialchars($_SESSION['session_unita'], ENT_QUOTES, 'UTF-8');
$session_ufficio = htmlspecialchars($_SESSION['session_ufficio'], ENT_QUOTES, 'UTF-8');
$session_ruolo = htmlspecialchars($_SESSION['session_ruolo'], ENT_QUOTES, 'UTF-8');
$session_posizione = htmlspecialchars($_SESSION['session_posizione'], ENT_QUOTES, 'UTF-8');
$session_id_ufficio = htmlspecialchars($_SESSION['session_id_ufficio'], ENT_QUOTES, 'UTF-8');
$session_tipo_utente = htmlspecialchars($_SESSION['session_tipo_utente'], ENT_QUOTES, 'UTF-8');
$ip = $_SERVER['REMOTE_ADDR'];
$today = date("H:i:s d/m/Y");
$operazione = "Apertura Portale Ferie";
$query = "
INSERT INTO operazioni
VALUES (0, :username, :today, :ip, :operazione)
";
$check = $pdo->prepare($query);
$check->bindParam(':username', $session_user, PDO::PARAM_STR);
$check->bindParam(':today', $today, PDO::PARAM_STR);
$check->bindParam(':ip', $ip, PDO::PARAM_STR);
$check->bindParam(':operazione', $operazione, PDO::PARAM_STR);
$check->execute();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/style1.css">
<title> Portale Ferie <?=$session_nome?> </title>
<style type="text/css">
ul#menu li { float:left; list-style: none; padding: 0 8px; }
</style>
<div style="float: left; text-align: left;"> <h1> Arrigo Web</h1></div>
<section align='right'>
<div style="float: right; text-align: right;">
<?= $session_nome ?>
<br>
<?= $session_direzione ?>
<br>
<a href="logout.php">Esci</a>
</div>
<br>
<br>
</section>
<br>
<br>
<nav>
<ul id="menu">
<li> <a href="dashboard.php"> Home </a></li>
<? switch ($session_tipo_utente) {case '3':{ ?>
<li><a href="redazione.php">Portale Redazione </a></li>
<?;}} ?>
<? switch ($session_tipo_utente) {case '1':{ ?>
<li><a href="ferie.php"><strong>Portale Ferie</strong> </a></li>
<?;}} ?>
<li><a href="#">Voce 2 </a></li>
<li><a href="#">Voce 1 </a></li>
<li><a href="profilo.php">Profilo</a> </li>
</ul>
<br>
</nav>
<br>
<br>
<br>
<?
echo "<br>";
printf("Di seguito troverai il riepilogo delle tue Ferie.");
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
?>
<style>
///qua c'era un lungo codice di css che rimuovo per massimo caratteri
}
</style>
</head>
<body>
<br>
<button onclick="document.getElementById('id01').style.display='block'" data-aos="fade-left" data-aos-delay="400" style="width:auto;">Nuova Richiesta</button>
<div id="id01" class="modal">
<form method="post" action="registrazione-ferie.php" class="modal-content animate">
<center>
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
<h2> Nuova Richiesta - Ferie</h2>
</div>
<div class="container">
<input type="date" id="username" name="username" required>
</div>
<div class="container" >
<button type="submit" name="login">Invia</button>
</div>
<div class="container1" >
</div>
</center>
</form>
</div>
<script>
// Get the modal
var modal = document.getElementById('id01');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
<?
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
} else {
printf("Effettua il %s per accedere all'area riservata", '<a href="../login.html">login</a>');
}
?>
registrazione-ferie.php (che è il file da completare)
PHP:
<?php
session_start();
include('database.php');
if (isset($_SESSION['session_id']))
{ $session_user = htmlspecialchars($_SESSION['session_user'], ENT_QUOTES, 'UTF-8');
$session_id = htmlspecialchars($_SESSION['session_id'], ENT_QUOTES, 'UTF-8');
$session_nome = htmlspecialchars($_SESSION['session_nome'], ENT_QUOTES, 'UTF-8');
$session_email = htmlspecialchars($_SESSION['session_email'], ENT_QUOTES, 'UTF-8');
$session_codice_dip = htmlspecialchars($_SESSION['session_codice_dip'], ENT_QUOTES, 'UTF-8');
$session_direzione = htmlspecialchars($_SESSION['session_direzione'], ENT_QUOTES, 'UTF-8');
$session_area = htmlspecialchars($_SESSION['session_area'], ENT_QUOTES, 'UTF-8');
$session_unita = htmlspecialchars($_SESSION['session_unita'], ENT_QUOTES, 'UTF-8');
$session_ufficio = htmlspecialchars($_SESSION['session_ufficio'], ENT_QUOTES, 'UTF-8');
$session_ruolo = htmlspecialchars($_SESSION['session_ruolo'], ENT_QUOTES, 'UTF-8');
$session_tipo_utente = htmlspecialchars($_SESSION['session_tipo_utente'], ENT_QUOTES, 'UTF-8');
$giorni = "1";
$ip = $_SERVER['REMOTE_ADDR'];
$today = date("H:i:s d/m/Y");
$operazione = "Richiesta Ferie per il giorno $data";
if (isset($_POST['ferie'])) {
$data = $_POST['data'] ?? '';
if (empty($data) ) {
$msg = 'Compila il campo data %s';
} else {
$query1 = "
INSERT INTO richiesta_ferie
VALUES (0, :nome, :username, :data, :giorni, :today)
";
$check = $pdo->prepare($query1);
$check->bindParam(':nome', $session_nome, PDO::PARAM_STR);
$check->bindParam(':username', $session_username, PDO::PARAM_STR);
$check->bindParam(':data', $data, PDO::PARAM_STR);
$check->bindParam(':giorni', $giorni, PDO::PARAM_STR);
$check->bindParam(':today', $today, PDO::PARAM_STR);
$check->execute();
$richiesta = $check->fetchAll(PDO::FETCH_ASSOC);
//è qui che ho bisogno di aiuto
}
}
printf("error");
}
} else {
printf("Effettua il %s per accedere all'area riservata", '<a href="../login.html">login</a>');
}
Vi ringrazio in anticipo per l'aiuto