-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifica_spesa.php
More file actions
262 lines (222 loc) · 10.1 KB
/
modifica_spesa.php
File metadata and controls
262 lines (222 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
require ("x_session.php");
require("db_config.php");
$mysqli = new mysqli($host, $username, $password, $database);
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
function chi($id_utenti){
require("db_config.php");
$mysqli = new mysqli($host, $username, $password, $database);
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$sql = "SELECT * FROM utenti WHERE id_utenti = $id_utenti";
$result = $mysqli->query($sql);
if ($result->num_rows == 1) {
while($riga = $result->fetch_assoc()) {
return $riga['nome'];
}
}
}
$id_spesa = $_GET['id'];
$sql = "SELECT * FROM spesa WHERE id_spesa = $id_spesa";
$result = $mysqli->query($sql);
if ($result->num_rows == 1) {
while($riga = $result->fetch_assoc()) {
$id_spesa = $_GET['id'];
$nome = $riga['nome'];
$date = date_create($riga['dataora']);
$dataora = date_format($date, 'Y-m-d\TH:i');
$luogo = $riga['luogo'];
$descrizione = $riga['descrizione'];
$spesa_totale = $riga['spesa_totale'];
$valuta = $riga['valuta'];
$cambio = $riga['cambio'];
$spesa_totale_chf = $riga['spesa_totale_chf'];
$utente_pagante = $riga['id_utente_pagante'];
$utente_inserimento= $riga['id_utente_inserimento'];
$timestamp_ins = $riga['timestamp_inserimento'];
}
} else {
echo "ERRORE!";
}
$admin = false;
$sql = "SELECT * FROM utenti WHERE id_utenti = $x_id";
$result = $mysqli->query($sql);
if ($result->num_rows == 1) {
while($riga = $result->fetch_assoc()) {
if ($riga['admin'] == 1) {$admin = true;}
}
}
if($x_id == $utente_pagante OR $admin) {} else {die("Non sei autorizzato ad accedere a questa pagina");}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>FM20 - Modifica </title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href="https://fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<link rel="stylesheet" href="css/nuova_spesa.css">
<!-- Javascript
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<!--script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script-->
<script src="js/modifica.js"></script>
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png">
</head>
<body>
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="container">
<div class="row">
<div style="margin-top: 10%">
<!--h2>Gestione Eventi Oratorio Balerna</h2-->
<h3>Modifica spesa - ID <?echo $id_spesa?></h3>
<hr style ="margin-top: -2rem;">
</div>
</div>
<form action="x_modifica_spesa.php?id=<?echo $id_spesa?>" method="POST">
<!-- INFO AFFITTANTE -->
<!--h4>Informazioni base</h4-->
<div class="row">
<div class="four columns">
<label for="nome">Nome</label>
<input value="<?echo $nome?>" type="text" id="nome" name="nome" required>
</div>
<div class="four columns">
<label for="dataora">Data e ora</label>
<input value="<?echo $dataora?>" type="datetime-local" id="dataora" name="dataora" required>
</div>
</div>
<div class="row">
<div class="eight columns">
<label for="luogo">Luogo</label>
<input value="<?echo $luogo?>" type="text" id="luogo" name="luogo">
</div>
</div>
<div class="row">
<div class="eight columns">
<label for="descrizione">Descrizione / Riferimento</label>
<textarea value="<?echo $descrizione?>" class="u-full-width" id="descrizione" name="descrizione"></textarea>
</div>
</div>
<div class="row">
<div class="four columns">
<label for="spesa_totale">Spesa totale</label>
<input value="<?echo $spesa_totale?>" type="number" id="spesa_totale" name="spesa_totale" step="any" required>
</div>
<div class="four columns">
<label for="valuta">Valuta</label>
<select class="u-full-width" id="valuta" name="valuta" readonly>
<option value="<?echo $valuta?>"><?echo $valuta?></option>
</select>
</div>
</div>
<div class="row">
<div class="four columns">
<label for="spesa_totale_chf">Spesa totale CHF</label>
<input value="<?echo $spesa_totale_chf?>" type="number" step='any' id="spesa_totale_chf" name="spesa_totale_chf" readonly>
</div>
<div class="four columns">
<label for="cambio">Cambio</label>
<input value="<?echo $cambio?>" type="number" step='any' id="cambio" name="cambio" readonly>
</div>
</div>
<h4 style ="margin-top: 2rem;">Suddivisione</h4>
<hr style ="margin-top: -2rem;">
<div class="row">
<div class="four columns">
<label for="id_utente_pagante">Creditore</label>
<select class="u-full-width" id="id_utente_pagante" name="id_utente_pagante">
<?
$sql = "SELECT * FROM utenti";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
while($riga = $result->fetch_assoc()) {
if ($riga['id_utenti'] == $utente_pagante) {$mio = 'selected';} else {$mio = '';}
echo "<option value='".$riga['id_utenti']."'".$mio.">".$riga['nome']."</option>";
}
} else {
echo "ERRORE!";
}
?>
</select>
</div>
</div>
<div class="row">
<div class="four columns">
<label for="romana">Opzioni</label>
<a class="button" id="romana" onclick="romana();">Alla romana</a>
<a class="button" id="azzera" onclick="azzera();">Azzera</a>
</div>
</div>
<div class="row">
<div class="eight columns">
<table class="u-full-width">
<thead>
<tr>
<th>Spese</th>
<th></th>
</tr>
</thead>
<tbody>
<?
$sql = "SELECT * FROM utenti";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
while($riga = $result->fetch_assoc()) {
}
} else {
echo "ERRORE!";
}
$sql = "SELECT * FROM soldi WHERE id_spesa = $id_spesa";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
while($riga = $result->fetch_assoc()) {
$debito = $riga['debito'];
$utente = chi($riga['id_utente']);
$id_utente = $riga['id_utente'];
if (1 == 1) {
echo "<tr><td>$utente</td><td><input placeholder='0' type='number' step='any' class='spese' id='spesa[$id_utente]' name='spesa[$id_utente]' value='$debito' oninput='conti();'></td></tr>";
}
}
} else {
echo "ERRORE!";
}
$mysqli->close();
?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="four columns">
<span id="controllo"></span>
</div>
</div>
<input type="submit" value="MODIFICA">
</form>
Per cancellare:
<button onclick="cancella(<?echo $id_spesa?>)" class="button-primary">CANCELLA SPESA !</button>
</div>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>