<?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: elenco_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 sono un amministratore e voglio visualizzare questa pagina, redirigo alla gestione news
if ($_SESSION['livello_id'] == 1) {
header("Location: " . $dir_admin . "/gestione_news.php");
exit();
}
//calcolo il tempo di generazione della pagina (1a parte)
$mtime1 = explode(" ", microtime());
$starttime = $mtime1[1] + $mtime1[0];
// risultati visualizzati per pagina
$conf = mysql_query("SELECT max_news_personali FROM $tab_config");
$rowconf = mysql_fetch_array($conf);
$rec_page = $rowconf['max_news_personali'];
$query_msg = NULL;
//serve per la paginazione
$start = (isset($_GET['start'])) ? abs(floor(intval($_GET['start']))) : 0;
$q_user_id = intval($_SESSION['user_id']);
//se ho ordinato le news in base a....
if (isset($_GET['sortby'])) {
$get_sortby = "sortby=" . addslashes($_GET['sortby']);
switch ($_GET['sortby']) {
case "titolo_asc":
$order_query = "SELECT id, LEFT(titolo, 100) AS titolo, data_pubb, letture, stampe FROM $tab_news WHERE user_id=$q_user_id ORDER BY titolo ASC LIMIT $start,$rec_page";
$link_titolo = '<a href="elenco_news.php?sortby=titolo_desc&start=' . $start . '" title="Ordina per...">Titolo</a> <img src="' . $img_path . '/asc.gif" alt="ASC" title="ASC" />';
$link_data = '<a href="elenco_news.php?sortby=data_desc&start=' . $start . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="elenco_news.php?sortby=letture_desc&start=' . $start . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="elenco_news.php?sortby=stampe_desc&start=' . $start . '" title="Ordina per...">Stampe</a>';
break;
case "titolo_desc":
$order_query = "SELECT id, LEFT(titolo, 100) AS titolo, data_pubb, letture, stampe FROM $tab_news WHERE user_id=$q_user_id ORDER BY titolo DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="elenco_news.php?sortby=titolo_asc&start=' . $start . '" title="Ordina per...">Titolo</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_data = '<a href="elenco_news.php?sortby=data_desc&start=' . $start . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="elenco_news.php?sortby=letture_desc&start=' . $start . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="elenco_news.php?sortby=stampe_desc&start=' . $start . '" title="Ordina per...">Stampe</a>';
break;
case "data_asc":
$order_query = "SELECT id, LEFT(titolo, 100) AS titolo, data_pubb, letture, stampe FROM $tab_news WHERE user_id=$q_user_id ORDER BY data_pubb ASC LIMIT $start,$rec_page";
$link_titolo = '<a href="elenco_news.php?sortby=titolo_desc&start=' . $start . '" title="Ordina per...">Titolo</a>';
$link_data = '<a href="elenco_news.php?sortby=data_desc&start=' . $start . '" title="Ordina per...">Data pubblicazione</a> <img src="' . $img_path . '/asc.gif" alt="ASC" title="ASC" />';
$link_letture = '<a href="elenco_news.php?sortby=letture_desc&start=' . $start . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="elenco_news.php?sortby=stampe_desc&start=' . $start . '" title="Ordina per...">Stampe</a>';
break;
case "data_desc":
$order_query = "SELECT id, LEFT(titolo, 100) AS titolo, data_pubb, letture, stampe FROM $tab_news WHERE user_id=$q_user_id ORDER BY data_pubb DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="elenco_news.php?sortby=titolo_desc&start=' . $start . '" title="Ordina per...">Titolo</a>';
$link_data = '<a href="elenco_news.php?sortby=data_asc&start=' . $start . '" title="Ordina per...">Data pubblicazione</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_letture = '<a href="elenco_news.php?sortby=letture_desc&start=' . $start . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="elenco_news.php?sortby=stampe_desc&start=' . $start . '" title="Ordina per...">Stampe</a>';
break;
case "letture_asc":
$order_query = "SELECT id, LEFT(titolo, 100) AS titolo, data_pubb, letture, stampe FROM $tab_news WHERE user_id=$q_user_id ORDER BY letture ASC LIMIT $start,$rec_page";
$link_titolo = '<a href="elenco_news.php?sortby=titolo_desc&start=' . $start . '" title="Ordina per...">Titolo</a>';
$link_data = '<a href="elenco_news.php?sortby=data_asc&start=' . $start . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="elenco_news.php?sortby=letture_desc&start=' . $start . '" title="Ordina per...">Letture</a> <img src="' . $img_path . '/asc.gif" alt="ASC" title="ASC" />';
$link_stampe = '<a href="elenco_news.php?sortby=stampe_desc&start=' . $start . '" title="Ordina per...">Stampe</a>';
break;
case "letture_desc":
$order_query = "SELECT id, LEFT(titolo, 100) AS titolo, data_pubb, letture, stampe FROM $tab_news WHERE user_id=$q_user_id ORDER BY letture DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="elenco_news.php?sortby=titolo_desc&start=' . $start . '" title="Ordina per...">Titolo</a>';
$link_data = '<a href="elenco_news.php?sortby=data_desc&start=' . $start . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="elenco_news.php?sortby=letture_asc&start=' . $start . '" title="Ordina per...">Letture</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_stampe = '<a href="elenco_news.php?sortby=stampe_desc&start=' . $start . '" title="Ordina per...">Stampe</a>';
break;
case "stampe_asc":
$order_query = "SELECT id, LEFT(titolo, 100) AS titolo, data_pubb, letture, stampe FROM $tab_news WHERE user_id=$q_user_id ORDER BY stampe ASC LIMIT $start,$rec_page";
$link_titolo = '<a href="elenco_news.php?sortby=titolo_desc&start=' . $start . '" title="Ordina per...">Titolo</a>';
$link_data = '<a href="elenco_news.php?sortby=data_desc&start=' . $start . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="elenco_news.php?sortby=letture_desc&start=' . $start . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="elenco_news.php?sortby=stampe_desc&start=' . $start . '" title="Ordina per...">Stampe</a> <img src="' . $img_path . '/asc.gif" alt="ASC" title="ASC" />';
break;
case "stampe_desc":
$order_query = "SELECT id, LEFT(titolo, 100) AS titolo, data_pubb, letture, stampe FROM $tab_news WHERE user_id=$q_user_id ORDER BY stampe DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="elenco_news.php?sortby=titolo_desc&start=' . $start . '" title="Ordina per...">Titolo</a>';
$link_data = '<a href="elenco_news.php?sortby=data_asc&start=' . $start . '" title="Ordina per...">Data pubblicazione</a>';
$link_letture = '<a href="elenco_news.php?sortby=letture_desc&start=' . $start . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="elenco_news.php?sortby=stampe_asc&start=' . $start . '" title="Ordina per...">Stampe</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
break;
default:
$order_query = "SELECT id, LEFT(titolo, 100) AS titolo, data_pubb, letture, stampe FROM $tab_news WHERE user_id=$q_user_id ORDER BY data_pubb DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="elenco_news.php?sortby=titolo_desc&start=' . $start . '" title="Ordina per...">Titolo</a>';
$link_data = '<a href="elenco_news.php?sortby=data_asc&start=' . $start . '" title="Ordina per...">Data pubblicazione</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_letture = '<a href="elenco_news.php?sortby=letture_desc&start=' . $start . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="elenco_news.php?sortby=stampe_desc&start=' . $start . '" title="Ordina per...">Stampe</a>';
}
}
else {
$get_sortby = NULL;
$order_query = "SELECT id, LEFT(titolo, 100) AS titolo, data_pubb, letture, stampe FROM $tab_news WHERE user_id=$q_user_id ORDER BY data_pubb DESC LIMIT $start,$rec_page";
$link_titolo = '<a href="elenco_news.php?sortby=titolo_desc&start=' . $start . '" title="Ordina per...">Titolo</a>';
$link_data = '<a href="elenco_news.php?sortby=data_asc&start=' . $start . '" title="Ordina per...">Data pubblicazione</a> <img src="' . $img_path . '/desc.gif" alt="DESC" title="DESC" />';
$link_letture = '<a href="elenco_news.php?sortby=letture_desc&start=' . $start . '" title="Ordina per...">Letture</a>';
$link_stampe = '<a href="elenco_news.php?sortby=stampe_desc&start=' . $start . '" 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 user_id=$q_user_id AND 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 />";
}
}
}
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 - Elenco news personali
</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=\"elenco_news.php\" method=\"post\">
<table width=\"100%\" style=\"border: 3px solid #DDDDDD;\" cellpadding=\"2\" cellspacing=\"2\" bgcolor=\"#FFFFFF\" align=\"center\">
<tr><td width=\"2%\" bgcolor=\"#EEEEEE\"></td>
<td width=\"35%\" class=\"text\" align=\"center\" bgcolor=\"#EEEEEE\">$link_titolo</td>
<td width=\"19%\" class=\"text\" align=\"center\" bgcolor=\"#EEEEEE\">$link_data</td>
<td width=\"9%\" class=\"text\" align=\"center\" bgcolor=\"#EEEEEE\">$link_letture</td>
<td width=\"10%\" class=\"text\" align=\"center\" bgcolor=\"#EEEEEE\">$link_stampe</td>
<td width=\"12%\" 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++) {
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=\"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=\"cancella_news\">Cancella news</option>
</select></td>";
echo "<td colspan=\"4\" bgcolor=\"#EEEEEE\" class=\"text2\" align=\"right\">";
//paginazione
$num_totale = mysql_result(mysql_query("SELECT COUNT(id) FROM $tab_news WHERE user_id=$q_user_id") , 0);
$numero_pagine = ceil($num_totale / $rec_page);
$pagina_attuale = ceil(($start / $rec_page) + 1);
echo "<b>(Totale: $num_totale)</b> " . page_bar("elenco_news.php?$get_sortby", $pagina_attuale, $numero_pagine, $rec_page);
echo "</td></tr></table>";
?>
</form><br />
<?php include ("footer.php"); ?>
</body>
</html>