<?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: archivio.php
*****************************************************************/
header('Content-type: text/html; charset=ISO-8859-1');
//includo il file di configurazione
require_once (dirname(__FILE__) . '/config.php');
require_once (dirname(__FILE__) . '/admin/functions.php');
//mi connetto a mysql
$db = @mysql_connect($db_host, $db_user, $db_password);
@mysql_select_db($db_name, $db);
//estraggo alcune impostazioni
$conf = mysql_query("SELECT nome_sito, url_sito, max_archivio, max_archivio_parole, sfondo_titolo, sfondo_notizia, sfondo_strumenti, larghezza, nuova_news_day FROM $tab_config");
$rowconf = @mysql_fetch_array($conf);
?>
<!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>
<?php echo $rowconf['nome_sito']; ?> - Archivio notizie
</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="alternate" type="application/rss+xml" title="Feed RSS News" href="<?php echo $rowconf['url_sito'] . "/" . $news_dir . "/rss.php"; ?>" />
</head>
<body>
<?php
//suddivisione news per x pagine
$rec_page = $rowconf['max_archivio'];
$start = (isset($_GET['start'])) ? abs(floor(intval($_GET['start']))) : 0;
if (isset($_GET['autore']) && preg_match('/^[0-9]{1,4}$/', $_GET['autore'])) {
$autore = abs(floor(intval($_GET['autore'])));
$get_autore = "&autore=" . abs(floor(intval($_GET['autore'])));
$q_autore = "WHERE nu.user_id=$autore";
}
else {
$autore = NULL;
$get_autore = NULL;
$q_autore = NULL;
}
if (isset($_GET['sortby']) && preg_match('/^[1-4]{1}$/', $_GET['sortby'])) {
$sortby = abs(floor(intval($_GET['sortby'])));
$get_sortby = "&sortby=$sortby";
switch ($sortby) {
case 1:
$q_sortby = "ORDER BY nt.letture DESC";
$view_letture = "<b>letture</b>";
$view_stampe = 'stampe';
break;
case 2:
$q_sortby = "ORDER BY nt.stampe DESC";
$view_stampe = "<b>stampe</b>";
$view_letture = 'letture';
break;
case 3:
$q_sortby = "ORDER BY nu.nome_cognome ASC";
$view_stampe = "stampe";
$view_letture = 'letture';
break;
case 4:
$q_sortby = "ORDER BY nt.data_pubb DESC";
$view_stampe = "stampe";
$view_letture = 'letture';
break;
default:
$q_sortby = "ORDER BY nt.data_pubb DESC";
$view_letture = "letture";
$view_stampe = 'stampe';
}
}
else {
$sortby = NULL;
$q_sortby = "ORDER BY nt.data_pubb DESC";
$get_sortby = NULL;
$view_letture = "letture";
$view_stampe = 'stampe';
}
echo "<div id=\"container\" style=\"width: " . $rowconf['larghezza'] . "px\">";
echo "<div id=\"titolo_art\" class=\"text\" style=\"background-color: " . $rowconf['sfondo_titolo'] . "\"><b>Archivio notizie pubblicate</b> [<a href=\"archivio.php?sortby=1$get_autore\" title=\"Ordina per...\">pù lette</a>, <a href=\"archivio.php?sortby=2$get_autore\" title=\"Ordina per...\">più stampate</a>, <a href=\"archivio.php?sortby=3$get_autore\" title=\"Ordina per...\">autore (A-Z)</a>, <a href=\"archivio.php?sortby=4$get_autore\" title=\"Ordina per...\">pù recenti</a>, <a href=\"archivio.php\" title=\"Torna all'archivio\">tutte</a>]</div>";
if ($rowconf['max_archivio_parole'] == 0) {
$sql_archivio = "SELECT nt.id, nu.nome_cognome, nt.data_pubb, nt.titolo, nt.letture, nt.stampe FROM $tab_news nt JOIN $tab_utenti nu ON nu.user_id=nt.user_id $q_autore $q_sortby LIMIT $start,$rec_page";
}
else {
$sql_archivio = "SELECT nt.id, nu.nome_cognome, nt.data_pubb, nt.titolo, nt.letture, nt.stampe, LEFT(nt.testo, " . $rowconf['max_archivio_parole'] . ") AS testo FROM $tab_news nt JOIN $tab_utenti nu ON nu.user_id=nt.user_id $q_autore $q_sortby LIMIT $start,$rec_page";
}
$result = mysql_query("$sql_archivio");
if ($rowconf['max_archivio_parole'] == 0) {
echo "<div id=\"archivio\" style=\"line-height: 22px; background-color: " . $rowconf['sfondo_notizia'] . "\">";
}
else {
echo "<div id=\"archivio\" style=\"line-height: 16px; background-color: " . $rowconf['sfondo_notizia'] . "\">";
}
while ($row = @mysql_fetch_array($result)) {
//vedo se nella query ho scelto di mostrare il testo, per evitare il Notice di variabile indefinita
$testo = isset($row['testo']) ? $row['testo'] : NULL;
//stampo l'icona di nuova notizia
$img_new = ((time() - $row['data_pubb']) <= 60 * 60 * 24 * $rowconf['nuova_news_day']) ? "<img src=\"$img_path/new.gif\" alt=\"New\" />" : "<img src=\"$img_path/news.png\" alt=\"Art\" />";
if ($rowconf['max_archivio_parole'] > 0) {
$testo = ($rowconf['max_archivio_parole'] == 0) ? NULL : "<br /><span class=\"text2\">" . $row['testo'] . "...</span>";
echo "<span class=\"text\">$img_new <a href=\"view.php?id=" . $row['id'] . "\" title=\"Leggi...\">" . $row['titolo'] . "</a> (" . strftime("%d/%m/%Y %H:%M", $row['data_pubb']) . " - " . $row['nome_cognome'] . ") [$view_letture " . $row['letture'] . ", $view_stampe " . $row['stampe'] . "]</span>$testo<br />";
}
else {
echo "<span class=\"text\">$img_new <a href=\"view.php?id=" . $row['id'] . "\" title=\"Leggi...\">" . $row['titolo'] . "</a> (" . strftime("%d/%m/%Y %H:%M", $row['data_pubb']) . " - " . $row['nome_cognome'] . ") [$view_letture " . $row['letture'] . ", $view_stampe " . $row['stampe'] . "]</span><br />\n\r";
}
}
?>
</div><br />
<div id="tool_art" class="text2" style="background-color: <?php echo $rowconf['sfondo_titolo']; ?>">
<?php
echo "<a href=\"search.php\" title=\"Cerca un termine nelle news\" class=\"piccolo\"><img src=\"$img_path/search.png\" border=\"0\" alt=\"Cerca\" />Cerca</a>";
?>
</div>
<div id="paginazione" class="text2">
<?php
//paginazione
$num_totale = @mysql_result(mysql_query("SELECT COUNT(nt.id) FROM $tab_news nt JOIN $tab_utenti nu ON nu.user_id=nt.user_id $q_autore") , 0);
$numero_pagine = @ceil($num_totale / $rec_page);
$pagina_attuale = @ceil(($start / $rec_page) + 1);
echo "<b>(Totale: $num_totale)</b> " . page_bar("archivio.php?$get_autore$get_sortby", $pagina_attuale, $numero_pagine, $rec_page);
?>
</div>
</div>
</body>
</html>