<?php
/*****************************************************************
* Spacemarc News
* Version: 1.2.0
* Author and copyright (C): Marcello Vitagliano
* Web site: http://www.spacemarc.it
* License: GNU General Public License
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Current file: files_orfani.php
*****************************************************************/
session_start();
define('IN_NEWS', true);
//includo i file di configurazione
require_once (dirname(__FILE__) . '/../config.php');
require_once (dirname(__FILE__) . '/functions.php');
require_once (dirname(__FILE__) . '/../lang/lang.php');
$db = mysql_connect($db_host, $db_user, $db_password) or die("Impossibile connettersi a MySQL<br />Numero errore: " . mysql_errno() . "<br />Tipo di errore: " . mysql_error());
mysql_select_db($db_name, $db) or die("Impossibile selezionare il database $db_name<br />Numero errore: " . mysql_errno() . "<br />Tipo di errore: " . mysql_error());
check_login();
if ($_SESSION['livello_id'] != 1) {
die("Puoi visualizzare solo i tuoi file");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Allegati orfani
</title>
<link rel="stylesheet" href="../style.css" type="text/css" />
<script language="JavaScript" src="../javascript.js" type="text/JavaScript"></script>
</head>
<body>
<div align="center">
<span class="text"><b>Allegati orfani</b> (
<?php echo $lang['files_orfani_descr']; ?>)
</span><br /><br />
<form method="post" action="files_orfani.php" name="admin">
<table border="0" cellpadding="2" cellspacing="1" width="555">
<tr>
<td class="text" align="center" width="3%">ID Utente</td>
<td class="text" align="center" width="3%">ID news*</td>
<td class="text" align="center" width="5%">Nome file</td>
<td class="text" align="center" width="2%">Size</td>
<td class="text" align="center" width="4%">Data di invio</td>
</tr>
<?php
//seleziono gli user_id degli utenti e li metto in array
$result = mysql_query("SELECT user_id FROM $tab_utenti");
$all_userid = array();
while ($row = mysql_fetch_array($result)) {
$all_userid[] = $row['user_id'];
}
if ($handle = opendir("../$file_dir")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && !in_array($file, $all_userid)) {
//ricavo le info sui file
foreach(glob("../$file_dir/$file/" . "*.{gif,jpg,pdf,zip}", GLOB_BRACE) as $filename) {
$nome = basename($filename);
$dimensione = round(filesize($filename) / 1024, 1);
//icone estensione file
$estensione_file = pathinfo($filename);
switch ($estensione_file['extension']) {
case 'gif':
$icon_file = "<img src=\"$img_path/icon_gif.gif\" alt=\"gif\" />";
break;
case 'jpg':
$icon_file = "<img src=\"$img_path/icon_jpg.gif\" alt=\"jpg\" />";
break;
case 'zip':
$icon_file = "<img src=\"$img_path/icon_zip.gif\" alt=\"zip\" />";
break;
case 'pdf':
$icon_file = "<img src=\"$img_path/pdf.gif\" alt=\"pdf\" />";
break;
}
//vedo se il file รจ presente in qualche news pubblicata
$file_news = mysql_query("SELECT nt.id FROM $tab_news nt JOIN $tab_utenti nu ON nu.user_id=nt.user_id WHERE nt.testo LIKE '%$nome%' OR nu.user_id=$file");
$riga = mysql_fetch_array($file_news);
$link_news = ($riga['id'] != '') ? "<a href=\"../view.php?id=" . $riga['id'] . "\" title=\"Leggila [Nuova finestra]\" class=\"piccolo\" target=\"_blank\">" . $riga['id'] . "</a>" : NULL;
//mostro i file
echo "<tr><td class=\"text2\" align=\"center\" bgcolor=\"#EEEEEE\">$file</td>\n";
echo "<td class=\"text2\" align=\"center\" bgcolor=\"#EEEEEE\">$link_news</td>\n";
echo "<td class=\"text2\" align=\"left\" bgcolor=\"#EEEEEE\">$icon_file <a href=\"../$file_dir/$file/$nome\" target=\"blank\" class=\"piccolo\">$nome</a></td>\n";
echo "<td class=\"text2\" align=\"center\" bgcolor=\"#EEEEEE\">$dimensione KiB</td>\n";
echo "<td class=\"text2\" align=\"center\" bgcolor=\"#EEEEEE\">" . date("d/m/Y H:i", filemtime($filename)) . "</td></tr>";
}
}
}
closedir($handle);
}
echo "
<tr><td colspan=\"5\" class=\"text2\" align=\"left\">* " . $lang['files_orfani_descr2'] . " </td></tr>
<tr><td colspan=\"5\" class=\"text2\" align=\"center\"><br />
<input type=\"submit\" name=\"submit\" value=\"Cancella tutto\" onclick=\"return confirmSubmit()\" />
</td></tr></table></form><br />";
if (isset($_POST['submit'])) {
//seleziono gli user_id degli utenti e li metto in array
$result = mysql_query("SELECT user_id FROM $tab_utenti");
$all_userid = array();
while ($row = mysql_fetch_array($result)) {
$all_userid[] = $row['user_id'];
}
if ($handle = opendir("../$file_dir")) {
while (false !== ($oggetto = readdir($handle))) {
if ($oggetto != "." && $oggetto != ".." && $oggetto != "index.html" && !in_array($oggetto, $all_userid)) {
//cancello i file e le directories
$files = glob("../$file_dir/$oggetto/*.*");
foreach($files as $file) {
unlink($file);
}
rmdir("../$file_dir/$oggetto");
}
}
closedir($handle);
echo "<div id=\"success\">" . $lang['file_cancellati'] . "</div><br />
<script language=\"JavaScript\" type=\"text/javascript\">
<!--
function doRedirect() { location.href = \"files_orfani.php\"; }
window.setTimeout(\"doRedirect()\", 1500);
//-->
</script>";
}
}
?>
</div>
</body>
</html>