-
Notifications
You must be signed in to change notification settings - Fork 15
/
helpdocs.php
357 lines (251 loc) · 9.26 KB
/
helpdocs.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
<?php
/**
* Script che permette di vedere, carica e scaricare documenti.
* I documenti sono poi visibili dal link "Documenti utili" presenti in home page
*
* @package VFront
* @author Mario Marcello Verona <marcelloverona@gmail.com>
* @copyright 2007-2010 M.Marcello Verona
* @version 0.96 $Id: helpdocs.php 1173 2017-05-12 20:46:23Z marciuz $
* @license http://www.gnu.org/licenses/gpl.html GNU Public License
*/
include_once("./inc/conn.php");
include_once("./inc/layouts.php");
proteggi();
// Dimensione del max_upload preso dal php.ini (� indicato in M)
$max_kb=(int) ini_get('post_max_size') *1024 *1024;
/**
* Dato un nome di file restituisce il mime/type dall'estensione utilizzata
*
* @param string $filename
* @return string Il content-type per l'header
*/
function mime_content_type_($filename)
{
$info=pathinfo($filename);
$mime = array(
'rtf' => 'application/rtf',
'doc' => 'application/doc',
'pdf' => 'application/pdf',
'xls' => 'application/xls',
'odt' => 'application/odt',
'sxw' => 'application/sxw',
'zip' => 'application/x-zip-compressed',
'rar' => 'application/rar',
'txt' => 'text/txt'
);
return $mime[$info['extension']];
}
/**
* Dato un nome di file restituisce un frammento HTML per richiamare l'immagine associata.
* Le immagini sono presenti nella directory img/mime/
*
* @param string $filename
* @return string HTML image
*/
function mime_content_type_image($filename)
{
$mime = array(
'.rtf' => 'doc.gif',
'.doc' => 'doc.gif',
'.pdf' => 'pdf.gif',
'.xls' => 'xls.gif',
'.odt' => 'txt.gif',
'.sxw' => 'txt.gif',
'.zip' => 'zip.gif',
'.rar' => 'zip.gif',
'.txt' => 'generic.gif'
);
return "<img src=\"img/mime/".$mime[strrchr($filename,'.')]."\" alt=\"tipo: ".substr(strrchr($filename, '.'),1)."\" />";
}
// Se c'� inserisce il file
if(isset($_GET['add']) && count($_FILES)>0 && User_Session::level()>1){
// il formato � corretto?
if(strlen(mime_content_type_($_FILES['documento']['name']))==0){
header("Location: ".$_SERVER['PHP_SELF']."?ko=tipo_non_valido");
exit;
}
// Se non � troppo grande
if($_FILES['documento']['size']>$max_kb){
header("Location: ".$_SERVER['PHP_SELF']."?ko=max_kb");
exit;
}
$NOME_FILE=preg_replace("'[^a-z0-9._-]+'i","_",$_FILES['documento']['name']);
// echo $_FILES['documento']['tmp_name'] . " ---- ". _PATH_HELPDOCS."/".$NOME_FILE;
$op=move_uploaded_file($_FILES['documento']['tmp_name'], _PATH_HELPDOCS."/".$NOME_FILE);
if($op){
header("Location: ".$_SERVER['PHP_SELF']."?ok");
exit;
}
else{
header("Location: ".$_SERVER['PHP_SELF']."?ko=operazione_non_riuscita");
exit;
}
}
// CANCELLAZIONE DEL FILE:
if(isset($_GET['del']) && User_Session::level()>1){
$id_file= $_GET['del'];
// PRENDI I FILES
$dir= _PATH_HELPDOCS;
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(!is_dir($file)){
$docs[]=array('nome'=>$file,
'type'=>mime_content_type_($dir."/".$file),
'data'=>filectime($dir."/".$file),
'size'=>filesize($dir."/".$file)
);
}
}
closedir($dh);
}
}
$docs=Common::ordina_matrice($docs,$data,'DESC');
if(!is_file($dir."/".$docs[$id_file]['nome'])){
header("Location: ".$_SERVER['PHP_SELF']."?ko=file_inesistente");
exit;
}
$op=unlink($dir."/".$docs[$id_file]['nome']);
if($op){
header("Location: ".$_SERVER['PHP_SELF']."?eliminato");
exit;
}
else{
header("Location: ".$_SERVER['PHP_SELF']."?ko=operazione_non_riuscita");
exit;
}
}
// DOWNLOAD DEL FILE
else if(isset($_GET['doc'])){
// PRENDI I FILES
$dir= _PATH_HELPDOCS;
$docs=array();
$data='';
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(!is_dir($file)){
$docs[]=array('nome'=>$file,
'type'=>mime_content_type_($dir."/".$file),
'data'=>filemtime($dir."/".$file),
'size'=>filesize($dir."/".$file)
);
}
}
closedir($dh);
}
}
$docs=Common::ordina_matrice($docs,$data,'DESC');
$kk=(int) $_GET['doc'];
if(file_exists(_PATH_HELPDOCS."/".$docs[$kk]['nome'])){
header("Pragma: public");
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/force-download");
header('Content-Disposition: attachment; filename="'.$docs[$kk]['nome'].'"');
header("Content-Transfer-Encoding: binary");
header('Content-Length: '.$docs[$kk]['size']);
set_time_limit(0);
@readfile(_PATH_HELPDOCS."/".$docs[$kk]['nome']) OR die("<html><body OnLoad=\"javascript: alert('Nessun file trovato');history.back();\" bgcolor=\"#F0F0F0\"></body></html>");
}
else{
openErrorGenerico(_("File not found!"),true);
}
exit;
}
$files=array("sty/tabelle.css","sty/admin.css","js/confirm_delete.js");
echo openLayout1(_("Useful documents"),$files);
echo breadcrumbs(array("HOME",_('useful documents')));
echo "<h1>"._('Useful documents')."</h1>\n";
if(isset($_GET['ko'])){
switch($_GET['ko']){
case "max_kb": echo "<p><strong class=\"var\">"._('Warning!')."</strong> "._("File too big. It is only possible to send a file up to this size")." ".($max_kb/1024)." kb</p>\n";
break;
case "tipo_non_valido": echo "<p><strong class=\"var\">"._('Warning!')."</strong> "._("not a valid file format. Permitted formats: doc, xls, pdf, rtf, zip, txt, odt, sxw")."</p>\n";
break;
case "operazione_non_riuscita": echo "<p><strong class=\"var\">"._('Warning!')."</strong> "
.sprintf(_("operation failed. If the type and size of file (%s kb maximum) were correct and the problem still happened,"),($max_kb/1024))
." "._('contact the')."<a href=\"mailto:"._SYS_ADMIN_MAIL."\">"._('system administrator')."</a>.</p>\n";
break;
}
}
elseif (isset($_GET['ok'])){
echo "<p><strong class=\"verde\">"._('File uploaded')."</strong></p>\n";
}
elseif(isset($_GET['eliminato'])){
echo "<p><strong class=\"arancio\">"._('File correctly deleted.')."</strong></p>\n";
}
// PRENDI I FILES
$dir= _PATH_HELPDOCS;
$docs=array();
$data='';
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(!is_dir($file)){
$docs[]=array('nome'=>$file,
'type'=>mime_content_type_($dir."/".$file),
'data'=>filemtime($dir."/".$file),
'size'=>filesize($dir."/".$file)
);
}
}
closedir($dh);
}
}
$docs=Common::ordina_matrice($docs,$data,'DESC');
echo "<div class=\"info\">
<p>"._("This section contains documentation about using the application and the database.")
." <br />"
._('Left-click on the document name to open it, or right -click on the document name and select <em> Save target as </em> to download it to your computer')."<br />
</p>
</div>\n";
if(User_Session::level()>1){
echo "<p><a href=\"javascript:;\" onclick=\"document.getElementById('add_record').style.display='';\">"._('Add file')."</a></p>\n";
}
echo "<table summary=\"Tabella file help\" class=\"tab-report-dip\">\n";
echo "<tr>
<th class=\"lilla\" colspan=\"2\">"._('Document')."</th>
<th class=\"lilla\">"._('Last modified')."</th>
<th class=\"lilla\">"._('Size')."</th>",
(User_Session::level()>1) ?
"<th class=\"lilla\">"._('Delete')."</th>" : "",
"</tr>\n
";
// $dir_down=str_replace(FRONT_DOCROOT,'',_PATH_HELPDOCS);
for($i=0;$i<count($docs);$i++){
echo "\t\t<tr><td>".mime_content_type_image($docs[$i]['nome'])."</td>
<td><a href=\"?doc=$i\">".$docs[$i]['nome']."</a></td>
<td>".date("d/m/Y H:i",$docs[$i]['data'])."</td>
<td>".round($docs[$i]['size']/1024,0)." Kb</td>",
(User_Session::level()>1) ?
"<td><a href=\"javascript:;\" onclick=\"confirm_delete_f(this,$i);\" >"._('delete')."</a></td>" : "",
"</tr>";
}
echo "</table>\n";
$ADD_FILE=
'
<div id="add_record" style="display: none; top: 20%; left: 20%; width:500px; height: 230px; ">
<div style="text-align: right;">
<a href="javascript:;" onclick="document.getElementById(\'add_record\').style.display=\'none\';"> '._('Close').' X </a>
</div>
<div style="margin: 20px;">
<h3> '._('Add file').'</h3>
<p>'._('The following file extensions are allowed: <strong>doc, xls, pdf, rtf, zip, txt, odt, sxw').'</strong></p>
<form method="post" enctype="multipart/form-data" action="'.Common::phpself().'?add">
<label for="immagine"><strong>'._('File to add').'</strong></label><br/>
<input type="file" name="documento" id="documento" size="60" />
<br /><br />
<input name="invia" value=" '._('Send').' " type="submit" />
</form>
</div>
</div>';
if(User_Session::level()>1){
echo $ADD_FILE;
}
echo closeLayout1();