Skip to content

Commit df24540

Browse files
committed
Modifica orario OK
1 parent 16dfe39 commit df24540

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

modificaorarioambulatorio.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
include 'config.php';
4+
5+
// RECUPERO DATI E AGGIUNGO
6+
define('CHARSET', 'UTF-8');
7+
define('REPLACE_FLAGS', ENT_COMPAT | ENT_XHTML);
8+
9+
$errors = array();
10+
11+
// METODO CON ROLLBACK
12+
$db = new PDO("mysql:host=" . $dbhost . ";dbname=" . $dbname, $dbuser, $dbpswd, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,PDO::ATTR_EMULATE_PREPARES => false ));
13+
14+
//Inizia la transazione
15+
$db->beginTransaction();
16+
17+
try {
18+
19+
// per ogni orario
20+
for($c = 1; $c<289 ; $c++) {
21+
22+
if(isset($_POST[$c])) {
23+
//Update attivo
24+
$sql = "UPDATE orario SET attivo = 1 WHERE orario.idorario = ?;";
25+
} else {
26+
//Update non attivo
27+
$sql = "UPDATE orario SET attivo = 0 WHERE orario.idorario = ?;";
28+
}
29+
30+
$stmt = $db->prepare($sql);
31+
$stmt->execute(array($c));
32+
}
33+
34+
//Se non ci sono eccezioni commit
35+
$db->commit();
36+
}
37+
//Se sollevate eccezioni
38+
catch(Exception $e){
39+
echo $e->getMessage();
40+
//Rollback la transazione
41+
$db->rollBack();
42+
$errors['DB'] = 'Errore nel database';
43+
}
44+
45+
$db = NULL;
46+
47+
// Mando il messaggio del risultato e redirigo
48+
49+
session_start();
50+
if (!empty($errors)) {
51+
$_SESSION['sqlerrori'] = implode(", ", $errors);
52+
} else {
53+
$_SESSION['sqlok'] = "OPERAZIONE RIUSCITA";
54+
}
55+
56+
header('Location: ./opzioni.php');

orario.php

-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ class Orario {
1111
public $attivo;
1212
}
1313

14-
// UPDATE `orario` SET `attivo` = '1' WHERE `orario`.`idorario` = 9;
15-
1614
function caricaDatiOrario() {
1715

1816
include 'config.php';
19-
2017
$orari = array();
2118

2219
try {

0 commit comments

Comments
 (0)