-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin_groups.php
executable file
·391 lines (293 loc) · 10.8 KB
/
admin_groups.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<?php
/* I codici qui inseriti sono proprietà di
* Francesco Stasi, pertanto ne è vietata la
* vendita e la cessione a terzi senza previa
* autorizzazione dell' autore.
*/
require_once("config.php");
require_once("libs/common.php");
require_once("upload_lib.php");
require_once("libs/character_lib.php");
require_once("libs/group_lib.php");
if(!isset($_SESSION))
{
session_start();
}
logged();
$MyChar_obj=new Character(null,$_SESSION['char_name']);
$MyChar_obj->parseFromDb();
if(!($MyChar_obj->exists())){
echo "Personaggio inesistente.";
exit();
}
$_SESSION['modlevel']=$MyChar_obj->Account()->getModLevel();
if ($admin_groups_level_required>$_SESSION['modlevel']){
echo "Accesso negato, permessi insufficienti.";
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="author" content="Francesco Stasi"/>
<title><?php echo $nome_land;?></title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript">
$(document).ready(function(){
var FormOptions = {
success: function(data) {
alert('Gruppo Aggiornato');
}
};
$('form.special').ajaxForm(FormOptions);
$(".toggle_newSyBox").click(function(){
$(this).next(".Sy_upload").toggle();
});
$(".cancElement").click(function(){
if(!confirm('Cancellare la carica e rimuoverla da tutti i pg a cui è assegnata.\nSei sicuro di voler cancellare?')){
return false;
}else{
//post the ajax request
$.post("admin_groups.php", { element_delete_nG: $(this).attr("ref_elem") },function(data){
//remove the element
$(this).remove();
//show the message
});
}
});
$('#nelem_nG').change(function() {
$(".added_row").remove();
$("select option:selected").each(function () {
for(i=0;i<parseInt($(this).text());i++){
$('#elements_nG').append('<div class="added_row">nome carica: <input type="text" name="element_name_nG[]" /> salario giorn.: <input type="text" name="element_salary_nG[]" style="width:50px;" /> group admin: <select name="element_admin_nG[]"><option value="0">No</option><option value="1">Si</option></select> simbolo: <input type="file" name="element_symbol_nG[]" /></div>');
}
});
});
});
</script>
</head>
<body>
<?php
if(isset($_REQUEST['element_delete_nG'])){
//get the chars having that group element and remove them that element
$delElem = new GroupElement(null,$_REQUEST['element_delete_nG']);
if($delElem->deleteElement()){
echo "Elemento cancellato correttamente";
}else{
echo "Impossibile cancellare Elemento";
}
exit();
}
if (isset($_REQUEST['del'])){
$delG=new Group(null,$_REQUEST['del']);
$delG->readFromDb();
if($delG->deleteGroup($MyChar_obj->Account())){
echo "Gruppo {$delG->getName} Cancellato!";
}else{
echo "Impossibile Cancellare il gruppo";
}
}elseif(isset($_REQUEST['undel'])){
$delG=new Group(null,$_REQUEST['undel']);
$delG->readFromDb();
if($delG->undeleteGroup($MyChar_obj->Account())){
echo "Gruppo {$delG->getName} Ripristinato!";
}else{
echo "Impossibile Ripristinare il gruppo";
}
}elseif (isset($_REQUEST["save"])){ //se mi arriva il save sto creando o editando.
//per prima cosa lavoro sul gruppo
$group_id=$_REQUEST['id_nG'];
$group_name=$_REQUEST['name_nG'];
$group_type=$_REQUEST['type_nG'];
$group_website=$_REQUEST['site_nG'];
$tfile=$_FILES['logo_nG']['tmp_name'];
$pp = pathinfo($_FILES['logo_nG']['name']);
$tfilext=$pp['extension'];
$savArr=array();
$savArr['name']=$group_name;
$savArr['type']=$group_type;
$savArr['website']=$group_website;
$savArr['statute']=$_REQUEST['statute_nG'];
if(isset($group_id) && $group_id>0){ //se è settato l'id lo carico
$newG=new Group(null,$group_id);
$newG->readFromDb();
$newG->parse($savArr);
}
else{
$newG= new Group($savArr);
}
//in ogni caso salvo il gruppo
$newG->writeToDb();
if (isset($tfile) && $tfile!=''){ //se sto caricando un file devo salvarlo
$newG->storeImage($tfile,$tfilext);
}
//arrivato qui ho di sicuro un id del gruppo...se non ce l'ho mi fermo
if ($newG->getId()<1){
echo "Errore sul gruppo.";
exit();
}
//scorro tutto l'array delle richieste.
if (isset($_REQUEST['element_name_nG'])){
foreach ($_REQUEST['element_name_nG'] as $key => $value) {
$element_id=$_REQUEST["element_id_nG"][$key];
$element_name=$_REQUEST["element_name_nG"][$key];
$element_salary=$_REQUEST["element_salary_nG"][$key];
$element_admin=$_REQUEST["element_admin_nG"][$key];
$element_old_img=$_REQUEST["element_oldsymbol_nG"][$key];
$element_image=$_FILES['element_symbol_nG']['tmp_name'][$key];
$ppe = pathinfo($_FILES['element_symbol_nG']['name'][$key]);
$element_imageext=$ppe['extension'];
$arrE=array();
$arrE['element_name']=$element_name;
$arrE['element_image']=$element_old_img;
$arrE['salary']=$element_salary;
$arrE['group_admin']=$element_admin;
$arrE['id_group']=$newG->getId();
if(isset($element_id) && $element_id>0){ //se l'id è settato è una modifica
$newE=new GroupElement($arrE,$element_id);
}else{ //altrimenti è una creazione
if(!isset($element_name) || $element_name=='')
continue;
//in tal caso devo forzare l'immagine alla stessa del gruppo
$arrE['element_image']=$newG->getLogo();
$newE=new GroupElement($arrE);
}
//in ogni caso salvo l'elemento
$newE->writeToDb();
if (isset($element_image) && $element_image!=''){ //se sto caricando un file devo salvarlo
echo "carico file: $element_image";
$newE->storeImage($element_image,$element_imageext);
}
}
}
echo "Salvataggio Completato.<br /><a href=\"admin_groups.php\">Torna alla gestione gruppi</a>";
exit();
}
if (isset($_REQUEST["new"])){ //voglio creare
?>
<h2>Crezione nuovo gruppo</h2>
<form id="create_nG" name="create_nG" action="admin_groups.php?new=1&save=1" enctype="multipart/form-data" method="post" class="special">
<div style="float:left;width:50%;">
<div>nome: <input type="text" name="name_nG" id="name_nG" /></div>
<div>tipo: <select name="type_nG" id="type_nG">
<?php
foreach ($groups_name_array as $key => $value) {
echo "<option value=\"$key\">$value</option>\n";
}
?></select>
</div>
<div>sito: <input type="text" name="site_nG" id="site_nG" /></div>
<div>logo: <input type="file" name="logo_nG" id="logo_nG" /></div>
</div>
<div style="float:right;width:50%;">
Statuto:<br />
<textarea placeholder="Inserisci lo statuto per il gruppo" name="statute_nG" style="width:300px; height: 100px;"></textarea>
</div>
<div class="clearboth">numero cariche:
<select id="nelem_nG">
<?php
for($i=0;$i<30;$i++)
echo "<option>$i</option>\n";
?>
</select>
</div>
<div id="elements_nG"></div>
<input type="submit" value="Salva" />
</form>
<?php
}elseif(isset($_REQUEST['edit'])){
$editG=new Group(null,$_REQUEST['edit']);
$editG->readFromDb();
$editG->loadElements();
?>
<h2>Modifica gruppo</h2>
<form id="mod_nG" name="mod_nG" action="admin_groups.php?edit=1&save=1" enctype="multipart/form-data" method="post" class="special">
<div style="float:left;width:50%;">
<input type="hidden" name="id_nG" value="<?php echo $editG->getId(); ?>" />
<div>nome: <input type="text" name="name_nG" id="name_nG" value="<?php echo $editG->getName(); ?>" /></div>
<div>tipo: <select name="type_nG" id="type_nG">
<?php
foreach ($groups_name_array as $key => $value) {
$sel=null;
if ($editG->getTypeN()==$key)
$sel="selected=\"selected\" ";
echo "<option value=\"$key\" $sel >$value</option>\n";
}
?></select>
</div>
<div>sito: <input type="text" name="site_nG" id="site_nG" value="<?php echo $editG->getSite(); ?>" /></div>
<div>logo: <?echo $editG->getLogo(true); ?> <label for="changeLogo">Cambia Logo</label><input type="checkbox" id="changeLogo" class="toggle_newSyBox" value="1"/><span class="Sy_upload" style="display:none;" ><input type="file" name="logo_nG" id="logo_nG" /></span></div>
</div>
<div style="float:right;width:50%;">
Statuto:<br />
<textarea placeholder="Inserisci lo statuto per il gruppo" name="statute_nG" style="width:300px; height: 100px;"><?php echo $editG->getStatute(); ?></textarea>
</div>
<div class="clearboth">cariche:
<?php
$elemList=$editG->getElements();
foreach ($elemList as $key => $value) {
$isAdm=null;
if($value->getAdmin()==1)
$isAdm="selected=\"selected\" ";
echo "<div class=\"element\">
<input type=\"hidden\" name=\"element_id_nG[]\" value=\"{$value->getId()}\" />
nome carica: <input type=\"text\" name=\"element_name_nG[]\" value=\"{$value->getName()}\" />
salario giorn.: <input type=\"text\" name=\"element_salary_nG[]\" style=\"width:50px;\" value=\"{$value->getSalary()}\" />
group admin: <select name=\"element_admin_nG[]\"><option value=\"0\">No</option><option value=\"1\" $isAdm >Si</option></select>
elimina: <a class=\"cancElement\" href=\"#\" ref_elem=\"{$value->getId()}\"><img src=\"images/icons/delete.png\" border=\"0\" title=\"Cancella\" alt=\"Cancella\" /></a>
{$value->getImage(true)}<input type=\"hidden\" name=\"element_oldsymbol_nG[]\" value=\"{$value->getImage()}\" /> <label for=\"changeSy_{$value->getId()}\">Cambia Simbolo</label><input type=\"checkbox\" id=\"changeSy_{$value->getId()}\" class=\"toggle_newSyBox\" value=\"1\"/><span class=\"Sy_upload\" style=\"display:none;\" ><input type=\"file\" name=\"element_symbol_nG[]\"/></span>
</div>";
}
?>
</div>
<div>Aggiungi cariche:
<select id="nelem_nG">
<?php
for($i=0;$i<30;$i++)
echo "<option>$i</option>\n";
?>
</select>
</div>
<div id="elements_nG"></div>
<input type="submit" value="Salva" />
</form>
<?php
}
else{
?>
<h2>Gestione dei gruppi</h2>
<p><a href="admin_groups.php?new=1">CREA GRUPPO</a></p>
<p>MODIFICA GRUPPI</p>
<ul>
<?php
foreach ($groups_name_array as $key => $value) {
echo "<li>$value:</li>";
$groupList=new GroupList($key);
$glisted=$groupList->GetList();
foreach ($glisted as $k => $v){
echo "{$glisted[$k]->getName()} <a href=\"admin_groups.php?edit={$v->getId()}\">[modifica]</a> <a href=\"admin_groups.php?del={$v->getId()}\">[cancella]</a><br />";
}
}
?>
</ul>
<p>RIPRISTINA CANCELLATI</p>
<ul>
<?php
foreach ($groups_name_array as $key => $value) {
echo "<li>$value:</li>";
$groupList=new GroupList($key,1);
$glisted=$groupList->GetList();
foreach ($glisted as $k => $v){
echo "{$glisted[$k]->getName()} <a href=\"admin_groups.php?undel={$v->getId()}\">[ripristina]</a><br />";
}
}
?>
</ul>
<?php
}
?>
</body>
</html>