Source for file stat.personal.php
Documentation is available at stat.personal.php
* Mediante questo file si possono creare, modificare e cancellare nuove statistiche sul database.
* Le statistiche sono impostata come query e sono registrate nella tabella di registro "stats"
* @desc File di gestione delle statistiche impostate dall'utente.
* @author Mario Marcello Verona <marcelloverona@gmail.com>
* @copyright 2007 Mario Marcello Verona
* @license http://www.gnu.org/licenses/gpl.html GNU Public License
require_once("../inc/conn.php");
require_once("../inc/layouts.php");
require_once("../inc/func.comuni.php");
require_once("../inc/func.frontend.php");
require_once("../inc/func.stat.php");
require_once("./stat.graph.php");
############################################
if(isset ($_GET['crea']) && count($_POST)> 0){
$sql= sprintf("INSERT INTO {$db1['frontend']}.stat
(nome_stat, desc_stat, def_stat, auth_stat , autore, tipo_graph)
('%s','%s','%s',%d,%d,'%s')",
$_SESSION['user']['uid'],
header("Location: ". $_SERVER['PHP_SELF']. "?id_s=$id");
header("Location: index.php?feed=konew");
############################################
if(isset ($_GET['applica_mod']) && count($_POST)> 0){
$sql= sprintf("UPDATE {$db1['frontend']}.stat
SET nome_stat='%s', desc_stat='%s', def_stat='%s', auth_stat=%d , tipo_graph='%s'
header("Location: index.php?feed=okmod");
header("Location: index.php?feed=komod");
############################################
if(isset ($_POST['elimina_stat']) && intval($_POST['elimina_stat'])> 0){
$sql= sprintf("DELETE FROM {$db1['frontend']}.stat
header("Location: index.php?feed=okdel");
header("Location: ". $_SERVER['PHP_SELF']. "?feed=kodel");
####################################################
# CREA UNA NUOVA STATISTICA
if(isset ($_GET['new']) || isset ($_GET['modifica'])){
if(isset ($_GET['modifica'])){
$q= vmsql_query("SELECT nome_stat, desc_stat, def_stat, autore, auth_stat, tipo_graph
FROM {$db1['frontend']}.stat WHERE id_stat=". intval($_GET['modifica']),$link);
// Verifica il diritto di modifica!
if($RS['autore']!= $_SESSION['user']['uid'] && $_SESSION['user']['livello']< 3){
header("Location: ". $_SERVER['PHP_SELF']. "?errore=noauth");
$titolo= 'Modifica statistica';
$titolo2= $titolo. " <span class=\"var\">". $RS['nome_stat']. "</span>";
$txt_button= "Modifica statistica";
$RS= array('nome_stat'=> '',
$titolo= $titolo2= "Crea nuova statistica";
$txt_button= "Registra nuova statistica";
$chk_auth[1] = ($RS['auth_stat']== 1) ? "checked=\"checked\"" : "";
$chk_auth[2] = ($RS['auth_stat']== 2) ? "checked=\"checked\"" : "";
$chk_auth[3] = ($RS['auth_stat']== 3) ? "checked=\"checked\"" : "";
$chk_tipo_graph[1] = ($RS['tipo_graph']== 'barre') ? "checked=\"checked\"" : "";
$chk_tipo_graph[2] = ($RS['tipo_graph']== 'torta') ? "checked=\"checked\"" : "";
$files= array('js/test_query.js','js/yav/yav.js','js/yav/yav-config-it.js');
echo "<div id=\"briciole\"><a href=\"../admin/index.php\">home amministrazione</a> » <a href=\"index.php\">statistiche</a> » ". strtolower($titolo). "</div>\n";
echo "<h1>$titolo2</h1>\n";
echo "<script type=\"text/javascript\">
rules[0]='nome_stat|required|Il nome per la statistica è obbligatorio';
rules[1]='def_stat|required|Non è stata inserita nessuna definizione SQL per la statistica';
echo "<form name=\"f1\" action=\"". $_SERVER['PHP_SELF']. "?$azione\" method=\"post\" onsubmit=\"return performCheck('f1', rules, 'classic');\" >\n";
echo "<fieldset style=\"width:70%; padding:20px;\">\n";
echo "<legend style=\"font-weigth:bold\">Parametri nuova statistica</legend>\n";
$input_modifica = (isset ($_GET['modifica'])) ? "<input type=\"hidden\" name=\"id_stat\" value=\"". intval($_GET['modifica']). "\" />\n" : "";
<label for=\"nome_stat\">Nome statistica:</label><br />
<input type=\"text\" id=\"nome_stat\" name=\"nome_stat\" size=\"40\" maxlength=\"240\" value=\"". $RS['nome_stat']. "\" />
<div class=\"info-campo\" >Nome della statistica personalizzata</div>
<label for=\"desc_stat\">Descrizione statistica:</label><br />
<textarea id=\"desc_stat\" name=\"desc_stat\" cols=\"50\" rows=\"4\" >". $RS['desc_stat']. "</textarea>
<div class=\"info-campo\" >Descrizione della statistica personalizzata</div>
<p>Tipo di accesso per la nuova statistica:</p>
<input type=\"radio\" id=\"auth_stat1\" name=\"auth_stat\" value=\"1\" ". $chk_auth[1]. " /> <label for=\"auth_stat1\">Pubblica</label><br />
<input type=\"radio\" id=\"auth_stat2\" name=\"auth_stat\" value=\"2\" ". $chk_auth[2]. " /> <label for=\"auth_stat2\">Accessibile solo al mio gruppo</label><br />
<input type=\"radio\" id=\"auth_stat3\" name=\"auth_stat\" value=\"3\" ". $chk_auth[3]. " /> <label for=\"auth_stat3\">Accessibile solo a me</label><br />
<p>Tipo di grafico desiderato:</p>
<input type=\"radio\" id=\"graph_type1\" name=\"tipo_graph\" value=\"barre\" ". $chk_tipo_graph[1]. " /> <label for=\"graph_type1\">A barre</label><br />
<input type=\"radio\" id=\"graph_type2\" name=\"tipo_graph\" value=\"torta\" ". $chk_tipo_graph[2]. " /> <label for=\"graph_type2\">A torta</label><br />
<label for=\"def_stat\">Definizione statistica:</label>
<input value=\"Test\" onclick=\"try_query(document.getElementById('def_stat').value,2)\" type=\"button\" />
<span id=\"feed_altro_2\" class=\"feed_altro\"> </span>
<textarea id=\"def_stat\" name=\"def_stat\" cols=\"60\" rows=\"7\" >". $RS['def_stat']. "</textarea>
<div class=\"info-campo\" >Query per la definizione della statistica</div>
<input type=\"submit\" name=\"invia\" value=\" $txt_button \" />\n";
#####################################################
# MOSTRA UNA STATISTICA DA ID
#####################################################
if(isset ($_GET['id_s'])){
$ID_STAT= (int) $_GET['id_s'];
$sql= "SELECT s.nome_stat, s.desc_stat, s.def_stat, s.auth_stat , s.autore, s.tipo_graph, s.data_stat, u.gid
FROM {$db1['frontend']}.stat s, {$db1['frontend']}.utente u
AND u.id_utente=s.autore";
// Controllo di proprietà validi per i non admin
if($_SESSION['user']['livello']< 3){
if($RS['auth_stat']== 2 && $RS['gid']!= $_SESSION['gid']){
if($RS['auth_stat']== 3 && $RS['autore']!= $_SESSION['user']['uid']) {
// Non ci sono errori fino a qui, vai avanti
// prendo la frequenza più grande per la scala
$duplicato_freq= $frequenze;
$scala= $duplicato_freq[0]* 1.1;
$scala = ($scala< 5) ? 5: $scala;
$stima_altezza = ($stima_altezza< 300) ? 300: $stima_altezza;
$nome_file_tmp = 'img_pers';
if($RS['tipo_graph']== 'barre'){
$grafico= barre($frequenze,$etichette,$scala,$RS['nome_stat'],$nome_file_tmp,550,$stima_altezza);
else if($RS['tipo_graph']== 'torta'){
$grafico= torta($frequenze,$etichette,$RS['nome_stat'],$nome_file_tmp);
$OUT.= "<table summary=\"cont\" class=\"tab-cont\">\n<tr>";
$OUT.= "<td><img src=\"". FRONT_DOCROOT. "/tmp/$nome_file_tmp.png?". time(). "\" alt=\"test\" class=\"img-stat\" /></td>\n";
$OUT.= "<td>". stat_tabella($etichette,$frequenze,array("valore","n")) . "</td>";
$files= array("sty/stat.css");
echo openLayout1("Statistica ". $RS['nome_stat'],$files);
echo "<div id=\"briciole\"><a href=\"../admin/index.php\">home amministrazione</a> » <a href=\"index.php\">statistiche</a> » ". $nome_stat_html. " </div>\n";
echo "<h1>$nome_stat_html</h1>\n";
echo "<div style=\"padding:10px; background-color:#FFF2CF;width:40em;margin:3px 3px 16px 3px;border:1px solid #444;\">\n";
echo "<p><b>Descrizione</b>: ". htmlentities($RS['desc_stat'],ENT_QUOTES). "</p>";
echo "<p><b>Autore</b>: ". $nome_autore. "</p>";
echo "<p><b>Data definizione</b>: ". dataITA($RS['data_stat']). "</p>";
$files= array("sty/stat.css");
echo openLayout1("Statistica ". $RS['nome_stat'],$files);
echo "<div id=\"briciole\"><a href=\"../admin/index.php\">home amministrazione</a> » <a href=\"index.php\">statistiche</a> » ". $nome_stat_html. " </div>\n";
echo "<h1>Impossibile visualizzare i dati</h1>\n";
case 'nogid' : echo "<p><strong>Attenzione!</strong> Si sta provando ad accedere ad una statistica aperta solo ad un gruppo di utenti del quale tu non fai parte.</p>\n";
case 'nouser' : echo "<p><strong>Attenzione!</strong> Si sta provando ad accedere ad una statistica personale della quale tu non sei autore.</p>\n";
case 'noquery' : echo "<p><strong>Attenzione!</strong> Si sta provando ad accedere ad una statistica che sembra avere un errore nell'SQL. Prego rivedere la definizione della query</p>\n";
case 'nodata' : echo "<p>Non ci sono dati per questa statistica</p>\n";
case 'norecord' : echo "<p><strong>Attenzione!</strong> Si sta interrogando una statistica inesistente</p>\n";
default : echo "<p><strong>Attenzione!</strong> C'è un errore generico nella visualizzazione della statistica</p>\n";
if(isset ($_GET['elimina'])){
$ID_STAT= (int) $_GET['elimina'];
$sql= "SELECT s.nome_stat, s.desc_stat, s.def_stat, s.auth_stat , s.autore, s.tipo_graph, s.data_stat, u.gid, ". concat_sintax("u.nome, ' ' , u.cognome", 'nomecognome'). "
FROM {$db1['frontend']}.stat s, {$db1['frontend']}.utente u
AND u.id_utente=s.autore";
echo "<div id=\"briciole\"><a href=\"../admin/index.php\">home amministrazione</a> » <a href=\"index.php\">statistiche</a> » elimina statistica </div>\n";
echo "<h1>Elimina statistica</h1>\n";
echo "<div style=\"padding:10px; background-color:#FFF2CF;width:40em;margin:3px 3px 16px 3px;border:1px solid #444;\">\n";
echo "<p><b>ID</b>: $ID_STAT</p>";
echo "<p><b>Descrizione</b>: ". htmlentities($RS['desc_stat'],ENT_QUOTES). "</p>";
echo "<p><b>Autore</b>: ". $RS['nomecognome']. "</p>";
echo "<p><b>Tipo grafico</b>: ". $RS['tipo_graph']. "</p>";
echo "<p><b>Data definizione</b>: ". dataITA($RS['data_stat']). "</p>";
echo "<form action=\"". $_SERVER['PHP_SELF']. "\" method=\"post\" >\n";
echo "<p><strong>Attenzione!</strong> Vuoi veramente eliminare la statistica? L'operazione è irreversibile.</p>\n";
echo "<input type=\"hidden\" name=\"elimina_stat\" value=\"". intval($_GET['elimina']). "\" />\n";
echo "<input type=\"submit\" name=\"esegui_elimina_stat\" value=\"Elimina statistica\" />\n";
echo " oppure <a href=\"index.php\">torna indietro</a>";
|