/
admin_gare.php
299 lines (280 loc) · 8.59 KB
/
admin_gare.php
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
require_once "inc/config.php";
$tit_pag="Gare e gironi";
$admin_class="active";
ob_start();
switch($_POST[op].$_GET[op]) {
case "gen":
$type = ssql("select get_tipo(".$_GET[torneo].")");
if($type != 1) {
$res = ssql("select genera_torneo(".$_GET[torneo].")");
}
else
$res=0;
if($res>0) {
$_SESSION[notify][type]="ok";
$_SESSION[notify][text]="Giornate create con successo.";
}
else {
$_SESSION[notify][type]="err";
$_SESSION[notify][text]="Errore! Giornate non create, riprovare. Se il problema persiste contattare l'amministratore.";
}
break;
case "regris":
if(isset($_POST[gara])) {
$altro=$resf=0;
$res = ssql("select registra_risultato('".$_POST[gara]."', '".$_POST[g1]."', '".$_POST[gioc1]."', '".$_POST[g2]."', '".$_POST[gioc2]."')");
if($res>0) {
$_SESSION[notify][type]="ok";
$_SESSION[notify][text]="Risultato aggiornato con successo.";
if($_POST[tipo]==3)
$resf = ssql("select genera_fase_succ(".$_GET[torneo].")");
elseif($_POST[tipo]==2)
$resf = ssql("select genera_ita_misto(".$_GET[torneo].")");
else
$altro=1;
if($altro) {
$end = ssql("select is_ended(".$_GET[torneo].")");
if($end>0)
$res = ssql("select ins_vincitore(".$_GET[torneo].")");
}
}
else {
$_SESSION[notify][type]="err";
$_SESSION[notify][text]="Errore! Risultato non aggiornato, riprovare. Se il problema persiste contattare l'amministratore.";
}
}
break;
case "new":
if(isset($_POST[data]) && $_POST[gg1]!=$_POST[gg2]) {
$res = ssql("select ins_gara(".$_GET[torneo].", '".$_POST[gg1]."', '".$_POST[gg2]."', '".$_POST[data]."')");
if($res>0) {
$_SESSION[notify][type]="ok";
$_SESSION[notify][text]="Gara inserita con successo.";
}
else {
$_SESSION[notify][type]="err";
$_SESSION[notify][text]="Errore! Gara non inserita, riprovare. Se il problema persiste contattare l'amministratore.";
}
}
else {
$_SESSION[notify][type]="err";
$_SESSION[notify][text]="Errore! Gara non inserita, controllare il form e riprovare.";
}
break;
case "close":
if(isset($_GET[torneo])) {
$res = ssql("select set_fine(".$_GET[torneo].")");
if($res>0) {
$_SESSION[notify][type]="ok";
$_SESSION[notify][text]="Generazione manuale del torneo terminata con successo.";
}
else {
$_SESSION[notify][type]="err";
$_SESSION[notify][text]="Errore! Operazione non effettuata, riprovare. Se il problema persiste contattare l'amministratore.";
}
}
break;
case "read":
if(isset($_GET[id2read])) {
$res = ssql("select leggi_notifica(".$_GET[id2read].")");
}
break;
default:
break;
}
if(isset($_GET[torneo])) {
$n = ssql("select get_nomet(".$_GET[torneo].")");
$e = ssql("select get_edizione(".$_GET[torneo].")");
$tit_pag.=" del torneo $n ed.$e";
$tipo = ssql("select get_tipo(".$_GET[torneo].")");
$end = ssql("select is_ended(".$_GET[torneo].")");
$isend = ssql("select has_fine(".$_GET[torneo].")");
if($end>0) {
$res=sql("select concat(u.nome,' ',u.cognome,' ') as winner
from utenti u
join vince v on u.id=v.IDutente
where v.IDtorneo='".$_GET[torneo]."'");
$vincitori="";
while($v=pg_fetch_array($res)) {
$vincitori.=$v[winner];
$_SESSION[notify][type]="ok";
$_SESSION[notify][text]="Torneo concluso e vinto da $vincitori";
}
}
$hasg = ssql("select has_gare(".$_GET[torneo].")");
if($hasg>0) {
$rows="";
$res=sql("select g.id as id,
g.data as data,
g.vincitore as vincitore,
case when g.vincitore is null
then '-'
else concat(u.nome,' ',u.cognome)
end as vincitore,
array_to_string(array_agg(concat(u2.nome,' ',u2.cognome)), '<br>') as giocatori,
array_to_string(array_agg(pa.risultato), '<br>') as risultati,
array_to_string(array_agg(concat('+',pa.punteggio)), '<br>') as punteggi,
g.girone as girone
from gara g
left join utenti u on u.id=g.vincitore
left join partecipa_a pa on pa.IDgara=g.id
left join utenti u2 on u2.id=pa.IDutente
where g.IDtorneo='".$_GET[torneo]."'
group by g.id, u.cognome, u.nome
order by g.girone, g.data asc");
if($tipo==1 && !$isend) {
while($g=pg_fetch_array($res)) {
$rows.="
<tr>
<td>".$g[data]."</td>
<td>".$g[vincitore]."</td>
<td>".$g[giocatori]."</td>
<td>".$g[risultati]."</td>
<td>".$g[punteggi]."</td>
<td><a href='#' disabled><i class='fa fa-edit fadisabled'></i></a></td>
</tr>
";
}
}
elseif($tipo==2) {
$girone = "<th>Girone</th>";
while($g=pg_fetch_array($res)) {
$rows.="
<tr>
<td>".$g[girone]."</td>
<td class='data'>".$g[data]."</td>
<td>".$g[vincitore]."</td>
<td class='players'>".$g[giocatori]."</td>
<td class='res'>".$g[risultati]."</td>
<td class='points'>".$g[punteggi]."</td>
<td class='mod'><a href='admin_gare.php?open=1&torneo=".$_GET[torneo]."&gid=".$g[id]."'><i class='fa fa-edit'></i></a></td>
</tr>
";
}
}
else {
while($g=pg_fetch_array($res)) {
$rows.="
<tr>
<td class='data'>".$g[data]."</td>
<td>".$g[vincitore]."</td>
<td class='players'>".$g[giocatori]."</td>
<td class='res'>".$g[risultati]."</td>
<td class='points'>".$g[punteggi]."</td>
<td class='mod'><a href='admin_gare.php?open=1&torneo=".$_GET[torneo]."&gid=".$g[id]."'><i class='fa fa-edit'></i></a></td>
</tr>
";
}
}
$start="
<table class='table table-striped table-bordered table-hover ui-datatable' id='garet'>
<thead>
<tr>
".$girone."
<th>Data</th>
<th>Vincitore</th>
<th>Giocatori</th>
<th>Risultati</th>
<th>Punteggi</th>
<th></th>
</tr>
</thead>
<tbody>
";
$end="
</tbody>
</table>
";
echo $start.$rows.$end;
}
elseif($tipo!=1) {
echo '<a href="admin_gare.php?op=gen&torneo='.$_GET[torneo].'" class="btn btn-warning btn-sm">Genera gare</a>
<br><br>Per questo torneo non sono state ancora generate gare e/o gironi.';
}
else {
echo 'Per questo torneo non sono state ancora generate gare e/o gironi.';
}
# modulo di creazione gare per torneo libero
if($tipo==1) {
BSspacer();
if(!$isend)
echo '<a href="admin_gare.php?op=close&torneo='.$_GET[torneo].'" class="btn btn-warning btn-sm">Termina la creazione delle gare</a>';
BSspacer();
BSheader("Inserisci gara");
BSformo();
hidden("new");
$data = ssql("select get_inizio(".$_GET[torneo].")");
BSdate("data", "Data", $data);
BSdropdown("gg1", "Giocatore 1", "select u.id as user, concat(u.nome,' ',u.cognome) as nome
from utenti u
join iscritto_a ia on u.id=ia.IDutente
where ia.IDtorneo='".$_GET[torneo]."'
and u.id>2", "user", "nome", "");
BSdropdown("gg2", "Giocatore 2", "select u.id as user, concat(u.nome,' ',u.cognome) as nome
from utenti u
join iscritto_a ia on u.id=ia.IDutente
where ia.IDtorneo='".$_GET[torneo]."'
and u.id>2", "user", "nome", "");
BSbutton("Inserisci");
BSformc();
$jq2footer.='
var fine = '.$isend.';
if(fine) {
$("#data").prop("disabled", true);
$("#gg1").prop("disabled", true);
$("#gg2").prop("disabled", true);
$("#formo button").prop("disabled", true);
}
';
}
BSformomod("admin_gare.php?torneo=".$_GET[torneo]);
if($_GET[open]>0 && $_GET[gid]>0) {
hidden("regris");
hidden($_GET[gid], "gara");
$gara = multisqlarr("select * from gara where id='".$_GET[gid]."'");
$tipo = ssql("select get_tipo(".$_GET[torneo].")");
hidden($tipo, "tipo");
$jq2footer='$("#modal-title").empty();
$("#modal-title").append("Risultati della gara del '.$gara[data].'");
$("#edithere").modal("show");';
$res = sql("select nome,
cognome,
risultato,
id
from utenti
left join partecipa_a on IDutente=id
where IDgara='".$gara[id]."'");
$c=1;
while($g=pg_fetch_array($res)) {
BSnum("gioc$c", $g[nome]." ".$g[cognome], $g[risultato]);
hidden($g[id], "g$c");
$c++;
}
BSbutton("Inserisci");
}
BSformcmod("admin_gare.php?torneo=".$_GET[torneo]);
}
else
echo "Per poter gestire le gare e i gironi dei tuoi tornei devi selezionare il torneo da <a href='admin_tornei.php'>qui</a>.";
$jq2footer.='
$("#garet > tbody tr").each(function() {
var players = $(this).find(".players").html();
console.log(players);
if(players.indexOf("Direttamente") >= 0){
var data = $(this).find(".data");
data.empty();
var res = $(this).find(".res");
res.empty();
var points = $(this).find(".points");
points.empty();
points.append("+3");
var mod = $(this).find(".mod");
mod.empty();
}
})
';
$corpoPagina=ob_get_contents();
ob_end_clean();
include "inc/template_all.php";
?>