<?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: gestione_news.php
*****************************************************************/
session_start();
define('IN_NEWS', true);
header('Content-type: text/html; charset=ISO-8859-1');
//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();
//se NON sono un amministratore e voglio visualizzare questa pagina, redirigo all'elenco news personale
if ($_SESSION['livello_id'] != 1) {
header("Location: " . $dir_admin . "/elenco_news.php");
exit();
}
//calcolo il tempo di generazione della pagina (1a parte)
$mtime1 = explode(" ", microtime());
$starttime = $mtime1[1] + $mtime1[0];
$conf = mysql_query("SELECT max_gest_news FROM $tab_config");
$rowconf = mysql_fetch_array($conf);
// risultati visualizzati per pagina per la paginazione
$rec_page = $rowconf['max_gest_news'];
$start = (isset($_GET['start'])) ? abs(floor(intval($_GET['start']))) : 0;
$query_msg = NULL;
if (isset($_GET['user_id']) && preg_match('/^[0-9]{1,4}$/', $_GET['user_id'])) {
$q_user_id = " WHERE nu.user_id=" . intval($_GET['user_id']) . "";
$get_user_id = "&user_id=" . intval($_GET['user_id']) . "";
$query_count = "SELECT COUNT(id) FROM $tab_news WHERE user_id=" . intval($_GET['user_id']);
$action = "gestione_news.php?user_id=" . intval($_GET['user_id']) . "";
}
else {
$q_user_id = NULL;
$get_user_id = NULL;
$query_count = "SELECT COUNT(id) FROM $tab_news";
$action = "gestione_news.php";
}
//se c'รจ sortby via get...NO paginazione, solo per costruire i link
if (isset($_GET['sortby'])) {
$get_sortby = "sortby=" . addslashes($_GET['sortby']);
switch ($_GET['sortby']) {
case 'titolo_asc':
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id=nu.user_id " . $q_user_id . " ORDER BY nt.titolo ASC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a> <img src="' . $img_path . '/asc.gif" alt="ASC" title="ASC" />';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a>';
$link_data = '<a href="gestione_news.php?sortby=data_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a>';
break;
case 'titolo_desc':
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nt.titolo DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_asc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a>';
$link_data = '<a href="gestione_news.php?sortby=data_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a>';
break;
case 'autore_asc':
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nu.nome_cognome ASC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a>';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a> <img src="' . $img_path . '/asc.gif" alt="ASC" title="ASC" />';
$link_data = '<a href="gestione_news.php?sortby=data_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a>';
break;
case 'autore_desc':
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nu.nome_cognome DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a>';
$link_autore = '<a href="gestione_news.php?sortby=autore_asc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_data = '<a href="gestione_news.php?sortby=data_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a>';
break;
case 'data_asc':
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nt.data_pubb ASC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a>';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a>';
$link_data = '<a href="gestione_news.php?sortby=data_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a> <img src="' . $img_path . '/asc.gif" alt="ASC" title="ASC" />';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a>';
break;
case 'data_desc':
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nt.data_pubb DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a>';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a>';
$link_data = '<a href="gestione_news.php?sortby=data_asc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a>';
break;
case 'letture_asc':
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nt.letture ASC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a>';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a>';
$link_data = '<a href="gestione_news.php?sortby=data_asc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a> <img src="' . $img_path . '/asc.gif" alt="ASC" title="ASC" />';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a>';
break;
case 'letture_desc':
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nt.letture DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a>';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a>';
$link_data = '<a href="gestione_news.php?sortby=data_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="gestione_news.php?sortby=letture_asc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a>';
break;
case 'stampe_asc':
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nt.stampe ASC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a>';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a>';
$link_data = '<a href="gestione_news.php?sortby=data_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a> <img src="' . $img_path . '/asc.gif" alt="ASC" title="ASC" />';
break;
case 'stampe_desc':
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nt.stampe DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a>';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a>';
$link_data = '<a href="gestione_news.php?sortby=data_asc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_asc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
break;
default:
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nt.data_pubb DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a>';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a>';
$link_data = '<a href="gestione_news.php?sortby=data_asc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a>';
}
}
else {
$get_sortby = NULL;
$order_query = "SELECT nu.user_id, nt.id, LEFT(nt.titolo, 100) AS titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nt.user_id = nu.user_id " . $q_user_id . " ORDER BY nt.data_pubb DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="gestione_news.php?sortby=titolo_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Titolo</a>';
$link_autore = '<a href="gestione_news.php?sortby=autore_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Autore</a>';
$link_data = '<a href="gestione_news.php?sortby=data_asc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Data pubblicazione</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_letture = '<a href="gestione_news.php?sortby=letture_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="gestione_news.php?sortby=stampe_desc&start=' . $start . '' . $get_user_id . '" title="Ordina per...">Stampe</a>';
}
//cancellazione news e immagini
if (isset($_POST['submit_sel'])) {
if (isset($_POST['cb_id'])) {
$nid = implode(",", $_POST['cb_id']);
//se cancello le news
if ($_POST['submit_sel'] == 'cancella_news') {
if (mysql_query("DELETE FROM $tab_news WHERE id IN ($nid)")) {
$query_msg = "<div id=\"success\">" . $lang['canc_news_user_ok'] . "</div><br />";
}
else {
$query_msg = "<div id=\"error\">" . $lang['canc_news_user_error'] . "</div><br /><span class=\"text2\">" . mysql_error() . "</span><br /><br />";
}
//se azzero letture e stampe
}
elseif ($_POST['submit_sel'] == 'azzera_ls') {
if (mysql_query("UPDATE $tab_news SET letture=0, stampe=0 WHERE id IN ($nid) AND letture>0 OR stampe>0")) {
$query_msg = "<div id=\"success\">" . $lang['azzera_ls_ok'] . "</div><br />";
}
else {
$query_msg = "<div id=\"error\">" . $lang['azzera_ls_error'] . "</div><br /><span class=\"text2\">" . mysql_error() . "</span><br /><br />";
}
}
}
else {
$nid = NULL;
$query_msg = "<div id=\"error\">" . $lang['selez_news_error'] . "</div><br />";
}
}
?>
<!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>Amministrazione news - Gestione news
</title>
<link rel="stylesheet" href="../style.css" type="text/css" />
<script language="JavaScript" src="../javascript.js" type="text/JavaScript"></script>
</head>
<body>
<?php
include ("menu.php");
echo $query_msg;
echo "<form name=\"admin\" action=\"$action\" method=\"post\">
<table width=\"100%\" style=\"border: 3px solid #DDDDDD;\" cellpadding=\"2\" cellspacing=\"2\" bgcolor=\"#FFFFFF\" align=\"center\">
<tr><td width=\"1%\" bgcolor=\"#EEEEEE\"> </td>
<td width=\"18%\" class=\"text\" align=\"center\" bgcolor=\"#EEEEEE\">$link_titolo</td>
<td width=\"10%\" class=\"text\" align=\"center\" bgcolor=\"#EEEEEE\">$link_autore</td>
<td width=\"13%\" class=\"text\" align=\"center\" bgcolor=\"#EEEEEE\">$link_data</td>
<td width=\"6%\" class=\"text\" align=\"center\" bgcolor=\"#EEEEEE\">$link_letture</td>
<td width=\"6%\" class=\"text\" align=\"center\" bgcolor=\"#EEEEEE\">$link_stampe</td>
<td width=\"6%\" class=\"text\" align=\"center\" bgcolor=\"#EEEEEE\">Opzioni</td>
</tr>";
$q_order = mysql_query("$order_query");
for ($i = 1;$q_riga = @mysql_fetch_assoc($q_order);$i++) {
$autore = ($q_riga['user_id'] == NULL) ? $q_riga['nome_cognome'] : "<a href=\"profilo_admin.php?user_id=" . $q_riga['user_id'] . "\" title=\"Visualizza il profilo\">" . $q_riga['nome_cognome'] . "</a>";
echo "<tr onmouseover=\"this.bgColor='#F1F9FF'\" onmouseout=\"this.bgColor='#FFFFFF'\">
<td align=\"center\"><input type=\"checkbox\" name=\"cb_id[]\" value=\"" . $q_riga['id'] . "\" id=\"news_" . $q_riga['id'] . "\" /></td>
<td align=\"left\" class=\"text\"><label for=\"news_" . $q_riga['id'] . "\">" . $q_riga['titolo'] . "</label></td>
<td align=\"left\" class=\"text\">$autore</td>
<td align=\"center\" class=\"text\">" . strftime("%d %b %Y %H:%M", $q_riga['data_pubb']) . "</td>
<td align=\"center\" class=\"text\">" . $q_riga['letture'] . "</td>
<td align=\"center\" class=\"text\">" . $q_riga['stampe'] . "</td>
<td align=\"center\" class=\"text\"><a href=\"modifica.php?id=" . $q_riga['id'] . "\" title=\"Modifica\">Modifica</a>•<a href=\"../view.php?id=" . $q_riga['id'] . "\" target=\"_blank\" title=\"Leggila sul sito [Nuova finestra]\">Leggi</a></td>
</tr>";
}
echo "<tr>
<td colspan=\"3\" bgcolor=\"#EEEEEE\" class=\"text2\" align=\"left\">
Seleziona: <a href=\"javascript:onClick=checkTutti()\" class=\"piccolo\">tutti</a>, <a href=\"javascript:onClick=uncheckTutti()\" class=\"piccolo\">nessuno</a>
<select name=\"submit_sel\" onchange=\"return dropdown(this);\">
<option selected=\"selected\">- OPERAZIONI -</option>
<option value=\"azzera_ls\">Azzera letture/stampe</option>
<option value=\"cancella_news\">Cancella news</option>
</select></td>
<td colspan=\"4\" bgcolor=\"#EEEEEE\" class=\"text2\" align=\"right\">";
//paginazione
$num_totale = @mysql_result(mysql_query("$query_count") , 0);
$numero_pagine = ceil($num_totale / $rec_page);
$pagina_attuale = ceil(($start / $rec_page) + 1);
echo "<b>(Totale: $num_totale)</b> " . page_bar("gestione_news.php?$get_sortby$get_user_id", $pagina_attuale, $numero_pagine, $rec_page);
echo "</td></tr></table>";
?>
</form><br />
<?php include ("footer.php"); ?>
</body>
</html>