<?php
/*****************************************************************
* Spacemarc News
* Version: 1.2.0
* Author and copyright (C) 2003-2008: 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: impostazioni.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 al proprio profilo
if ($_SESSION['livello_id'] != 1) {
header("Location: " . $dir_admin . "/profilo_utente.php");
exit();
}
//calcolo il tempo di generazione della pagina (1a parte)
$mtime1 = explode(" ", microtime());
$starttime = $mtime1[1] + $mtime1[0];
$config = mysql_query("SELECT * FROM $tab_config");
$config_val = mysql_fetch_assoc($config);
$errore_sito = NULL;
$errore_news = NULL;
$errore_sfondo = NULL;
$update_msg = NULL;
$update_error = NULL;
$errore_tabella = NULL;
$opt_msg = NULL;
//controllo Instant messaging
switch ($config_val['formato_data']) {
case 1:
$fd_selected1 = 'selected="selected"';
$fd_selected2 = NULL;
$fd_selected3 = NULL;
$fd_selected4 = NULL;
$fd_selected5 = NULL;
break;
case 2:
$fd_selected1 = NULL;
$fd_selected2 = 'selected="selected"';
$fd_selected3 = NULL;
$fd_selected4 = NULL;
$fd_selected5 = NULL;
break;
case 3:
$fd_selected1 = NULL;
$fd_selected2 = NULL;
$fd_selected3 = 'selected="selected"';
$fd_selected4 = NULL;
$fd_selected5 = NULL;
break;
case 4:
$fd_selected1 = NULL;
$fd_selected2 = NULL;
$fd_selected3 = NULL;
$fd_selected4 = 'selected="selected"';
$fd_selected5 = NULL;
break;
case 5:
$fd_selected1 = NULL;
$fd_selected2 = NULL;
$fd_selected3 = NULL;
$fd_selected4 = NULL;
$fd_selected5 = 'selected="selected"';
break;
default:
$fd_selected1 = 'selected="selected"';
$fd_selected2 = NULL;
$fd_selected3 = NULL;
$fd_selected4 = NULL;
$fd_selected5 = NULL;
}
if (isset($_POST['submit'])) {
if (trim($_POST['nome_sito']) == '' || trim($_POST['url_sito']) == '') {
$errore_sito = "<div id=\"error\">" . $lang['required'] . "</div><br />";
}
else {
$errore_sito = NULL;
}
if (!preg_match('/^[0-9]{1,3}$/', $_POST['perpage']) || !preg_match('/^[0-9]{1,3}$/', $_POST['firstwords']) || !preg_match('/^[0-9]{1,3}$/', $_POST['perpagesearch']) || !preg_match('/^[0-9]{1,2}$/', $_POST['maxinclude']) || !preg_match('/^[0-9]{1,3}$/', $_POST['fwinclude']) || !preg_match('/^[0-9]{1,4}$/', $_POST['width']) || !preg_match('/^[0-9]{1,3}$/', $_POST['maxgestione']) || !preg_match('/^[0-9]{1,3}$/', $_POST['maxutenti']) || !preg_match('/^[0-9]{1,3}$/', $_POST['maxpersonali']) || !preg_match('/^[0-9]{1,4}$/', $_POST['width_pager']) || !preg_match('/^[0-9]{1,2}$/', $_POST['nuova_news_day'])) {
$errore_news = "<div id=\"error\">" . $lang['solo_numeri'] . "</div><br />";
}
else {
$errore_news = NULL;
}
if (!preg_match('/^#([a-f0-9]{6})/i', $_POST['coltitolo']) || !preg_match('/^#([a-f0-9]{6})/i', $_POST['colcorpo']) || !preg_match('/^#([a-f0-9]{6})/i', $_POST['coltools'])) {
$errore_sfondo = "<div id=\"error\">" . $lang['colore_corretto'] . "</div><br />";
}
else {
$errore_sfondo = NULL;
}
if ($errore_sito == NULL && $errore_news == NULL && $errore_sfondo == NULL) {
$trova = array(
"\\",
"'",
"\"",
"<",
">"
);
$_POST['nome_sito'] = str_replace($trova, "", trim($_POST['nome_sito']));
$_POST['url_sito'] = str_replace($trova, "", trim($_POST['url_sito']));
if (mysql_query("UPDATE $tab_config SET nome_sito='" . $_POST['nome_sito'] . "', url_sito='" . $_POST['url_sito'] . "', max_archivio=" . $_POST['perpage'] . ", max_archivio_parole=" . $_POST['firstwords'] . ", max_ricerche=" . $_POST['perpagesearch'] . ", max_tit_include=" . $_POST['maxinclude'] . ", max_parole_include=" . $_POST['fwinclude'] . ", sfondo_titolo='" . $_POST['coltitolo'] . "', sfondo_notizia='" . $_POST['colcorpo'] . "', sfondo_strumenti='" . $_POST['coltools'] . "', larghezza=" . $_POST['width'] . ", larghezza_pager=" . $_POST['width_pager'] . ", max_gest_news=" . $_POST['maxgestione'] . ", max_utenti=" . $_POST['maxutenti'] . ", max_news_personali=" . $_POST['maxpersonali'] . ", formato_data=" . $_POST['formato_data'] . ", nuova_news_day=" . $_POST['nuova_news_day'])) {
$update_msg = "<div align=\"center\"><span class=\"text\"><b>" . $lang['conf_updated'] . "</b></span> <img src=\"$img_path/attendi.gif\" title=\"Attendi\" alt=\"Attendi...\" /></div>
<script language=\"JavaScript\" type=\"text/javascript\">
<!--
function doRedirect() {
location.href = \"impostazioni.php\";
}
window.setTimeout(\"doRedirect()\", 2000);
//-->
</script><br />";
}
else {
$update_error = "<div id=\"error\">" . $lang['conf_problem'] . "</div><br /><span class=\"text2\">" . mysql_error() . "</span><br /><br />";
}
}
}
elseif (isset($_POST['backup'])) {
if (!isset($_POST['selected_tbl'])) {
$errore_tabella = "<div id=\"error\">" . $lang['err_tabella'] . "</div><br />";
}
else {
$errore_tabella = NULL;
require_once ("backup.php");
}
}
elseif (isset($_GET['action']) && (strcmp($_GET['action'], 'opt') == 0) && isset($_GET['tab'])) {
//posso ottimizzare solo le tabelle delle news
$tab_permesse = array(
$tab_news,
$tab_utenti,
$tab_config
);
if (!in_array($_GET['tab'], $tab_permesse)) {
die("Tabella selezionata non valida");
}
else {
if (mysql_query("OPTIMIZE TABLE " . $_GET['tab'])) {
$opt_msg = "<div id=\"success\">" . $lang['optimized_ok'] . "</div><br />";
}
else {
$opt_msg = "<div id=\"error\">" . $lang['optimized_error'] . "</div><br /><span class=\"text2\">" . mysql_error() . "</span><br /><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 - Impostazioni
</title>
<link rel="stylesheet" href="../style.css" type="text/css" />
<script language="JavaScript" src="../javascript.js" type="text/JavaScript"></script>
<script language="JavaScript" type="text/JavaScript">
//disabilito il tasto Invio dal form
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey;
</script>
</head>
<body>
<?php
include ("menu.php");
echo $errore_sito;
echo $errore_news;
echo $errore_sfondo;
echo $update_msg;
echo $update_error;
echo $errore_tabella;
echo $opt_msg;
?>
<form action="impostazioni.php" method="post" name="config">
<table width="100%" align="center" style="border: 3px solid #DDDDDD;" cellpadding="4" cellspacing="2" class="text">
<tr>
<td bgcolor="#DEE3E7" align="left" width="31%"><b>Nome e URL del sito web</b><br />
<span class="text2">
<?php echo $lang['url_sito_descr']; ?>
</span></td>
<td bgcolor="#EEEEEE" align="left" class="text">Nome
<input type="text" name="nome_sito" value="<?php echo $config_val['nome_sito']; ?>" size="28" maxlength="40" /> URL
<input type="text" name="url_sito" value="<?php echo $config_val['url_sito']; ?>" size="28" maxlength="40" /></td>
</tr>
<tr>
<td bgcolor="#DEE3E7" align="left"><b>Archivio notizie</b></td>
<td bgcolor="#EEEEEE" align="left" class="text">
<?php echo $lang['per_page']; ?>
<input type="text" value="<?php echo $config_val['max_archivio']; ?>" name="perpage" maxlength="3" size="2" onkeypress="return onlynumbers(event,'0123456789')" /> Mostra le prime
<input type="text" value="<?php echo $config_val['max_archivio_parole']; ?>" name="firstwords" maxlength="3" size="2" onkeypress="return onlynumbers(event,'0123456789')" /> lettere del testo</td>
</tr>
<tr>
<td bgcolor="#DEE3E7" align="left"><b>Risultati delle ricerche</b></td>
<td bgcolor="#EEEEEE" align="left" class="text">
<?php echo $lang['per_page_search']; ?>
<input type="text" value="<?php echo $config_val['max_ricerche']; ?>" name="perpagesearch" maxlength="3" size="2" onkeypress="return onlynumbers(event,'0123456789')" /></td>
</tr>
<tr>
<td bgcolor="#DEE3E7" align="left"><b>Box ultime notizie</b></td>
<td bgcolor="#EEEEEE" align="left" class="text">
<?php echo $lang['max_include']; ?>
<input type="text" value="<?php echo $config_val['max_tit_include']; ?>" name="maxinclude" maxlength="2" size="2" onkeypress="return onlynumbers(event,'0123456789')" /> Mostra le prime
<input type="text" value="<?php echo $config_val['max_parole_include']; ?>" name="fwinclude" maxlength="3" size="2" onkeypress="return onlynumbers(event,'0123456789')" /> lettere del testo</td>
</tr>
<tr>
<td bgcolor="#DEE3E7" align="left"><b>Immagine nuova notizia</b></td>
<td bgcolor="#EEEEEE" align="left" class="text">
<?php echo $lang['nuova_news_day']; ?>
<input type="text" value="<?php echo $config_val['nuova_news_day']; ?>" name="nuova_news_day" maxlength="2" size="2" onkeypress="return onlynumbers(event,'0123456789')" /> giorni</td>
</tr>
<tr>
<td bgcolor="#DEE3E7" align="left"><b>Colori e dimensioni box news</b></td>
<td bgcolor="#EEEEEE" align="left" class="text">
<?php echo $lang['col_titolo']; ?>
<input type="text" value="<?php echo $config_val['sfondo_titolo']; ?>" name="coltitolo" maxlength="7" size="7" />
<?php echo $lang['col_news']; ?>
<input type="text" value="<?php echo $config_val['sfondo_notizia']; ?>" name="colcorpo" maxlength="7" size="7" />
<?php echo $lang['col_tools']; ?>
<input type="text" value="<?php echo $config_val['sfondo_strumenti']; ?>" name="coltools" maxlength="7" size="7" /><br />
<?php echo $lang['larghezza']; ?>
<input type="text" value="<?php echo $config_val['larghezza']; ?>" name="width" maxlength="4" size="2" onkeypress="return onlynumbers(event,'0123456789')" />px
<?php echo $lang['larghezza_nav']; ?>
<input type="text" value="<?php echo $config_val['larghezza_pager']; ?>" name="width_pager" maxlength="4" size="2" onkeypress="return onlynumbers(event,'0123456789')" />px</td>
</tr>
<tr>
<td bgcolor="#DEE3E7" align="left"><b>Amministrazione: record visualizzati</b></td>
<td bgcolor="#EEEEEE" align="left" class="text">Gestione news
<input type="text" value="<?php echo $config_val['max_gest_news']; ?>" name="maxgestione" maxlength="3" size="2" onkeypress="return onlynumbers(event,'0123456789')" /> Gestione utenti
<input type="text" value="<?php echo $config_val['max_utenti']; ?>" name="maxutenti" maxlength="3" size="2" onkeypress="return onlynumbers(event,'0123456789')" /> News utente
<input type="text" value="<?php echo $config_val['max_news_personali']; ?>" name="maxpersonali" maxlength="3" size="2" onkeypress="return onlynumbers(event,'0123456789')" /></td>
</tr>
<tr>
<td bgcolor="#DEE3E7" align="left"><b>Formato data delle news</b></td>
<td bgcolor="#EEEEEE" align="left" class="text">Seleziona
<select name="formato_data">
<?php
echo "<option value=\"1\" $fd_selected1>" . strftime("%a %d %b %Y %H:%M") . "</option>";
echo "<option value=\"2\" $fd_selected2>" . str_replace("ì", "ì", strftime("%A %d %B %Y %H:%M")) . "</option>";
echo "<option value=\"3\" $fd_selected3>" . strftime("%d/%m/%Y %H:%M") . "</option>";
echo "<option value=\"4\" $fd_selected4>" . strftime("%d %b %Y %H:%M") . "</option>";
echo "<option value=\"5\" $fd_selected5>" . strftime("%d %B %Y %H:%M") . "</option>";
?>
</select></td>
</tr>
<tr>
<td bgcolor="#DEE3E7" align="left"><b>Allegati orfani</b></td>
<td bgcolor="#EEEEEE" align="left" class="text">
<?php echo $lang['files_orfani_descr']; ?>:
<a href="javascript:;" onclick="window.open('files_orfani.php', '', 'width=580, height=370, resizable=1, scrollbars=1, location=1, status=1');" title="Popup">visualizza</a></td>
</tr>
<tr>
<td bgcolor="#DEE3E7" align="left"><b>Informazioni e backup</b><br /></td>
<td bgcolor="#EEEEEE" align="left" class="text">
<?php
echo "<b>PHP</b>: " . phpversion() . " <b>MySQL</b>: " . mysql_get_server_info() . " <b>Web Server</b>: " . apache_get_version() . "<br /><b>OS</b>: " . php_uname() . "<br />";
//ricavo le info sulle tabelle
if (mysql_get_server_info() >= 5) {
$status_table = mysql_query("SHOW TABLE STATUS WHERE Name IN ('$tab_news', '$tab_utenti', '$tab_config')");
}
else {
$status_table = mysql_query("SHOW TABLE STATUS LIKE 'news_%'");
}
while ($status_tb = mysql_fetch_array($status_table)) {
$eccesso = ($status_tb['Data_free'] > 0) ? " - <span style=\"color: rgb(255, 0, 0);\">In eccesso di " . round($status_tb['Data_free'] / 1024, 1) . " KiB</span>: <a href=\"impostazioni.php?action=opt&tab=" . $status_tb['Name'] . "\" title=\"OPTIMIZE TABLE\">ottimizza</a>" : NULL;
$size = $status_tb['Data_length'] + $status_tb['Index_length'];
//converto i bytes in KiB e MiB
$tipo = "bytes";
if ($size > 1024) {
$size = $size / 1024;
$tipo = " KiB";
}
if ($size > 2048) {
$size = $size / 2048;
$tipo = " MiB";
}
$size = number_format($size, 1);
echo "<label for=\"" . $status_tb['Name'] . "\"><input type=\"checkbox\" id=\"" . $status_tb['Name'] . "\" name=\"selected_tbl[]\" value=\"" . $status_tb['Name'] . "\" checked=\"checked\" />" . $status_tb['Name'] . "</label> - Dimensione: " . $size . $tipo . " " . $eccesso . "<br/>";
}
$comp = (extension_loaded("zlib") ? "<img src=\"$img_path/sel_all.gif\" alt=\"select\" />Backup compresso <select name=\"compress\"><option value=\"1\" selected=\"selected\">Sì (.gz)</option><option value=\"0\">No (.sql)</option></select> <input type=\"submit\" name=\"backup\" value=\"Backup\" style=\"font-weight: bold;\" />" : NULL);
echo $comp . "<br />";
?></td>
</tr>
<tr>
<td bgcolor="#DEE3E7" align="center" colspan="2">
<input type="submit" name="submit" value="Modifica" style="font-weight: bold;" />
<input type="reset" name="reset" value="Ripristina" /></td>
</tr>
</table>
</form><br />
<?php include ("footer.php"); ?>
</body>
</html>