phpDocumentor VFront
Stats
[ class tree: VFront ] [ index: VFront ] [ all elements ]

Source for file stat.personal.php

Documentation is available at stat.personal.php

  1. <?php
  2. /**
  3.  * Mediante questo file si possono creare, modificare e cancellare nuove statistiche sul database.
  4.  * Le statistiche sono impostata come query e sono registrate nella tabella di registro "stats"
  5.  * 
  6.  * @desc File di gestione delle statistiche impostate dall'utente.
  7.  * @package VFront
  8.  * @subpackage Stats
  9.  * @author Mario Marcello Verona <marcelloverona@gmail.com>
  10.  * @copyright 2007 Mario Marcello Verona
  11.  * @version 0.90
  12.  * @license http://www.gnu.org/licenses/gpl.html GNU Public License
  13.  */
  14.  
  15.  
  16. require_once("../inc/conn.php");
  17. require_once("../inc/layouts.php");
  18. require_once("../inc/func.comuni.php");
  19. require_once("../inc/func.frontend.php");
  20. require_once("../inc/func.stat.php");
  21. require_once("./stat.graph.php");
  22.  
  23.  
  24.  
  25.  
  26.  
  27. ############################################
  28. #
  29. #    REGISTRA NUOVA
  30. #
  31.  
  32. if(isset($_GET['crea']&& count($_POST)>0){
  33.     
  34.     $_dati pulisci_dom($_POST);
  35.     
  36.     
  37.     $sql=sprintf("INSERT INTO {$db1['frontend']}.stat 
  38.                   (nome_statdesc_statdef_statauth_stat , autoretipo_graph)
  39.                   VALUES
  40.                   ('%s','%s','%s',%d,%d,'%s')",
  41.                   $_dati['nome_stat'],
  42.                   $_dati['desc_stat'],
  43.                   $_dati['def_stat'],
  44.                   $_dati['auth_stat'],
  45.                   $_SESSION['user']['uid'],
  46.                   $_dati['tipo_graph']);
  47.                   
  48.     $q=vmsql_query($sql,$link);
  49.     
  50.     if(vmsql_affected_rows($link,$q)==1){
  51.         
  52.         $id=vmsql_insert_id($link,$db1['frontend'].".stat",'id_stat');
  53.         
  54.         header("Location: ".$_SERVER['PHP_SELF']."?id_s=$id");
  55.         
  56.     }
  57.     else{
  58.         
  59.         header("Location: index.php?feed=konew");
  60.     }
  61.                  
  62.     
  63.     exit;
  64.     
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. ############################################
  75. #
  76. #    APPLICA MODIFICA 
  77. #
  78.  
  79. if(isset($_GET['applica_mod']&& count($_POST)>0){
  80.     
  81.     $_dati pulisci_dom($_POST);
  82.     
  83.     
  84.     $sql=sprintf("UPDATE {$db1['frontend']}.stat 
  85.                   SET nome_stat='%s', desc_stat='%s', def_stat='%s', auth_stat=%d , tipo_graph='%s'
  86.                   WHERE id_stat=%d
  87.                   LIMIT 1
  88.                   ",
  89.                   $_dati['nome_stat'],
  90.                   $_dati['desc_stat'],
  91.                   $_dati['def_stat'],
  92.                   $_dati['auth_stat'],
  93.                   $_dati['tipo_graph'],
  94.                   $_dati['id_stat']);
  95.                   
  96.     $q=vmsql_query($sql,$link);
  97.     
  98.     if(vmsql_affected_rows($link,$q)==1){
  99.         
  100.         header("Location: index.php?feed=okmod");
  101.         
  102.     }
  103.     else{
  104.         
  105.         header("Location: index.php?feed=komod");
  106.     }
  107.                  
  108.     
  109.     exit;
  110.     
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. ############################################
  122. #
  123. #    APPLICA ELIMINA
  124. #
  125.  
  126. if(isset($_POST['elimina_stat']&& intval($_POST['elimina_stat'])>0){
  127.     
  128.     $_dati pulisci_dom($_POST);
  129.     
  130.     
  131.     $sql=sprintf("DELETE FROM  {$db1['frontend']}.stat 
  132.                   WHERE id_stat=%d
  133.                   LIMIT 1
  134.                   ",
  135.                   $_dati['elimina_stat']);
  136.                   
  137.     $q=vmsql_query($sql,$link);
  138.     
  139.     if(vmsql_affected_rows($link,$q)==1){
  140.         
  141.         header("Location: index.php?feed=okdel");
  142.         
  143.     }
  144.     else{
  145.         
  146.         header("Location: ".$_SERVER['PHP_SELF']."?feed=kodel");
  147.     }
  148.                  
  149.     
  150.     exit;
  151.     
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168. ####################################################
  169. #
  170. #    CREA UNA NUOVA STATISTICA
  171. #
  172. #
  173.  
  174. if(isset($_GET['new']|| isset($_GET['modifica'])){
  175.     
  176.     
  177.     // Caso modifica
  178.     if(isset($_GET['modifica'])){
  179.         
  180.         // prendi i dati
  181.         $q=vmsql_query("SELECT nome_statdesc_statdef_statautoreauth_stattipo_graph 
  182.                         FROM {$db1['frontend']}.stat WHERE id_stat=".intval($_GET['modifica']),$link);
  183.         
  184.         $RS=vmsql_fetch_assoc($q);
  185.         
  186.         
  187.         // Verifica il diritto di modifica!
  188.         if($RS['autore']!=$_SESSION['user']['uid'&& $_SESSION['user']['livello']<3){
  189.             
  190.             header("Location: ".$_SERVER['PHP_SELF']."?errore=noauth");
  191.             exit;
  192.         }
  193.         
  194.         $azione='applica_mod';
  195.         $titolo='Modifica statistica';
  196.         $titolo2=$titolo." <span class=\"var\">".$RS['nome_stat']."</span>";
  197.         
  198.         $txt_button="Modifica statistica";
  199.         
  200.     }
  201.     else{
  202.         
  203.         // valori predefiniti
  204.         
  205.         $RS=array('nome_stat'=>''
  206.                   'desc_stat'=>'',
  207.                   'def_stat'=>'',
  208.                   'auth_stat'=>1,
  209.                   'autore'=>'',
  210.                   'tipo_graph'=>'barre');
  211.                   
  212.                   
  213.         $azione='crea';
  214.         
  215.         $titolo=$titolo2="Crea nuova statistica";
  216.         
  217.         $txt_button="Registra nuova statistica";
  218.     }
  219.     
  220.     
  221.     
  222.     $chk_auth[1($RS['auth_stat']==1"checked=\"checked\"" "";
  223.     $chk_auth[2($RS['auth_stat']==2"checked=\"checked\"" "";
  224.     $chk_auth[3($RS['auth_stat']==3"checked=\"checked\"" "";
  225.     
  226.     $chk_tipo_graph[1($RS['tipo_graph']=='barre'"checked=\"checked\"" "";
  227.     $chk_tipo_graph[2($RS['tipo_graph']=='torta'"checked=\"checked\"" "";
  228.     
  229.     
  230.     
  231.     
  232.     
  233.     
  234.     
  235.     $files=array('js/test_query.js','js/yav/yav.js','js/yav/yav-config-it.js');
  236.     
  237.     echo openLayout1($titolo,$files);
  238.     
  239.     echo "<div id=\"briciole\"><a href=\"../admin/index.php\">home amministrazione</a> &raquo; <a href=\"index.php\">statistiche</a> &raquo; ".strtolower($titolo)."</div>\n";
  240.     
  241.     echo "<h1>$titolo2</h1>\n";
  242.     
  243.     echo "<script type=\"text/javascript\">
  244.     
  245.     var rules=new Array();
  246.     
  247.     rules[0]='nome_stat|required|Il nome per la statistica è obbligatorio';
  248.     rules[1]='def_stat|required|Non è stata inserita nessuna definizione SQL per la statistica';
  249.     
  250.     </script>\n";
  251.     
  252.     
  253.     echo "<form name=\"f1\" action=\"".$_SERVER['PHP_SELF']."?$azione\" method=\"post\" onsubmit=\"return performCheck('f1', rules, 'classic');\" >\n";
  254.     
  255.     echo "<fieldset style=\"width:70%; padding:20px;\">\n";
  256.     echo "<legend style=\"font-weigth:bold\">Parametri nuova statistica</legend>\n";
  257.     
  258.     
  259.     $input_modifica (isset($_GET['modifica'])) "<input type=\"hidden\" name=\"id_stat\" value=\"".intval($_GET['modifica'])."\" />\n" "";
  260.     
  261.     
  262.     echo "
  263.     
  264.         <label for=\"nome_stat\">Nome statistica:</label><br />
  265.         <input type=\"text\" id=\"nome_stat\" name=\"nome_stat\" size=\"40\" maxlength=\"240\" value=\"".$RS['nome_stat']."\" />
  266.         <div class=\"info-campo\" >Nome della statistica personalizzata</div>
  267.         
  268.         <label for=\"desc_stat\">Descrizione statistica:</label><br />
  269.         <textarea id=\"desc_stat\" name=\"desc_stat\" cols=\"50\" rows=\"4\" >".$RS['desc_stat']."</textarea>
  270.         <div class=\"info-campo\" >Descrizione della statistica personalizzata</div>
  271.         
  272.         <br />
  273.         
  274.         <p>Tipo di accesso per la nuova statistica:</p>
  275.         <input type=\"radio\" id=\"auth_stat1\" name=\"auth_stat\" value=\"1\" ".$chk_auth[1]." /> <label for=\"auth_stat1\">Pubblica</label><br />
  276.         <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 />
  277.         <input type=\"radio\" id=\"auth_stat3\" name=\"auth_stat\" value=\"3\" ".$chk_auth[3]." /> <label for=\"auth_stat3\">Accessibile solo a me</label><br />
  278.         
  279.         <br /><br />
  280.         
  281.         <p>Tipo di grafico desiderato:</p>
  282.         <input type=\"radio\" id=\"graph_type1\" name=\"tipo_graph\" value=\"barre\" ".$chk_tipo_graph[1]." /> <label for=\"graph_type1\">A barre</label><br />
  283.         <input type=\"radio\" id=\"graph_type2\" name=\"tipo_graph\" value=\"torta\" ".$chk_tipo_graph[2]." /> <label for=\"graph_type2\">A torta</label><br />
  284.         
  285.         <br /><br />
  286.         
  287.         
  288.         <label for=\"def_stat\">Definizione statistica:</label> 
  289.             <input value=\"Test\" onclick=\"try_query(document.getElementById('def_stat').value,2)\" type=\"button\" />
  290.             <span id=\"feed_altro_2\" class=\"feed_altro\">&nbsp;</span>
  291.             <br />
  292.         <textarea  id=\"def_stat\" name=\"def_stat\" cols=\"60\" rows=\"7\" >".$RS['def_stat']."</textarea>
  293.         <div class=\"info-campo\" >Query per la definizione della statistica</div>
  294.                 
  295.         $input_modifica
  296.         
  297.         <input type=\"submit\"  name=\"invia\" value=\"  $txt_button  \" />\n";
  298.     
  299.     
  300.     echo "</fieldset>\n";
  301.     
  302.     echo "</form>\n";
  303.     
  304.     echo closeLayout1();
  305.     
  306.     exit;
  307.     
  308. }
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319. #####################################################
  320. #
  321. #    MOSTRA UNA STATISTICA DA ID
  322. #
  323. #####################################################
  324.  
  325.  
  326.  
  327. if(isset($_GET['id_s'])){
  328.     
  329.     $errore=false;
  330.         
  331.     $ID_STAT= (int) $_GET['id_s'];
  332.     
  333.     $sql="SELECT s.nome_stats.desc_stats.def_stats.auth_stat , s.autores.tipo_graphs.data_statu.gid
  334.           FROM {$db1['frontend']}.stat s, {$db1['frontend']}.utente u 
  335.           WHERE id_stat=$ID_STAT
  336.           AND u.id_utente=s.autore";
  337.     
  338.     $q=vmsql_query($sql,$link);
  339.  
  340.     $RS=vmsql_fetch_assoc($q);
  341.  
  342.  
  343.     if(vmsql_num_rows($q)==0){
  344.             
  345.             $errore='norecord';
  346.     }
  347.     
  348.     
  349.     
  350.     // Controllo di proprietà validi per i non admin
  351.     
  352.     
  353.     
  354.     if($_SESSION['user']['livello']<3){
  355.     
  356.         if($RS['auth_stat']==&& $RS['gid']!=$_SESSION['gid']){
  357.             
  358.             $errore='nogid';
  359.         }
  360.         
  361.         if($RS['auth_stat']==&& $RS['autore']!=$_SESSION['user']['uid']{
  362.             
  363.             $errore='nouser';
  364.         }
  365.     
  366.     }
  367.     
  368.     
  369.     // testo la query
  370.     $test_q1=vmsql_try($RS['def_stat'],$link);
  371.     
  372.     if(!$test_q1){
  373.         
  374.         $errore='noquery';
  375.     }
  376.     else{
  377.     
  378.     
  379.         // Non ci sono errori fino a qui, vai avanti
  380.         
  381.         $q_stat=vmsql_query($RS['def_stat'],$link);
  382.         
  383.         list($etichette$frequenze)=vmsql_fetch_row_all($q_stat,true);
  384.         
  385.         
  386.         // se non ci sono dati
  387.         if(count($etichette)==|| count($frequenze)==0){
  388.             
  389.             $errore='nodata';
  390.         }
  391.     }
  392.     
  393.     
  394.     
  395.     // se non ci sono errori
  396.     if($errore===false){
  397.     
  398.         // prendo la frequenza più grande per la scala
  399.         $duplicato_freq=$frequenze;    
  400.         rsort($duplicato_freq);
  401.         $scala=$duplicato_freq[0]*1.1;
  402.         
  403.         $scala ($scala<55$scala;
  404.         
  405.         $stima_altezza round(count($frequenze)*22.5,0);
  406.         
  407.         $stima_altezza ($stima_altezza<300300$stima_altezza;
  408.         
  409.         $nome_file_tmp 'img_pers';
  410.         
  411.         // Grafico a barre
  412.         if($RS['tipo_graph']=='barre'){
  413.             
  414.             $grafico=barre($frequenze,$etichette,$scala,$RS['nome_stat'],$nome_file_tmp,550,$stima_altezza);
  415.         }
  416.         
  417.         // Grafico a torta
  418.         else if($RS['tipo_graph']=='torta'){
  419.             
  420.             $grafico=torta($frequenze,$etichette,$RS['nome_stat'],$nome_file_tmp);
  421.         }
  422.         
  423.         
  424.         
  425.         
  426.         if($grafico){
  427.     
  428.             $OUT='';
  429.             
  430.             // SCRIVE UNA TABELLA:
  431.             
  432.             $OUT.="<table summary=\"cont\" class=\"tab-cont\">\n<tr>";
  433.             
  434.             if($grafico){
  435.                 
  436.                 $OUT.= "<td><img src=\"".FRONT_DOCROOT."/tmp/$nome_file_tmp.png?".time()."\" alt=\"test\"   class=\"img-stat\" /></td>\n";
  437.             }
  438.             
  439.             
  440.             $OUT.= "<td>".stat_tabella($etichette,$frequenze,array("valore","n")) "</td>";
  441.             
  442.             $OUT.="</tr></table>\n";
  443.             
  444.         }
  445.         
  446.         
  447.         $nome_stat_html=htmlentities(stripslashes($RS['nome_stat']),ENT_QUOTES);
  448.         
  449.         $files=array("sty/stat.css");
  450.         
  451.         // prendi autore
  452.         $q_a=vmsql_query("SELECT ".concat_sintax("nome, ' ' , cognome")." FROM {$db1['frontend']}.utente WHERE id_utente=".intval($RS['autore']),$link);
  453.         
  454.         list($nome_autorevmsql_fetch_row($q_a);
  455.         
  456.         echo openLayout1("Statistica ".$RS['nome_stat'],$files);
  457.         
  458.         echo "<div id=\"briciole\"><a href=\"../admin/index.php\">home amministrazione</a> &raquo; <a href=\"index.php\">statistiche</a> &raquo; ".$nome_stat_html." </div>\n";
  459.         echo "<h1>$nome_stat_html</h1>\n";
  460.         
  461.         echo "<div style=\"padding:10px; background-color:#FFF2CF;width:40em;margin:3px 3px 16px 3px;border:1px solid #444;\">\n";
  462.         
  463.         echo "<p><b>Descrizione</b>: ".htmlentities($RS['desc_stat'],ENT_QUOTES)."</p>";
  464.         echo "<p><b>Autore</b>: ".$nome_autore."</p>";
  465.         echo "<p><b>Data definizione</b>: ".dataITA($RS['data_stat'])."</p>";
  466.         
  467.         echo "</div>\n";
  468.         
  469.         echo $OUT;
  470.         
  471.         echo closeLayout1();
  472.     }
  473.     
  474.     else{
  475.         
  476.         $files=array("sty/stat.css");
  477.         
  478.         echo openLayout1("Statistica ".$RS['nome_stat'],$files);
  479.         
  480.         echo "<div id=\"briciole\"><a href=\"../admin/index.php\">home amministrazione</a> &raquo; <a href=\"index.php\">statistiche</a> &raquo; ".$nome_stat_html." </div>\n";
  481.         echo "<h1>Impossibile visualizzare i dati</h1>\n";
  482.         
  483.         switch($errore){
  484.             
  485.             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";
  486.             break;
  487.             
  488.             case 'nouser' : echo "<p><strong>Attenzione!</strong> Si sta provando ad accedere ad una statistica personale della quale tu non sei autore.</p>\n";
  489.             break;
  490.             
  491.             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";
  492.             break;
  493.             
  494.             case 'nodata' : echo "<p>Non ci sono dati per questa statistica</p>\n";
  495.             break;
  496.             
  497.             case 'norecord' : echo "<p><strong>Attenzione!</strong> Si sta interrogando una statistica inesistente</p>\n";
  498.             break;
  499.             
  500.             default : echo "<p><strong>Attenzione!</strong> C'&egrave; un errore generico nella visualizzazione della statistica</p>\n";
  501.             
  502.         }
  503.         
  504.             
  505.         
  506.         echo closeLayout1();
  507.         
  508.     }
  509.     
  510.     
  511.     
  512. }
  513.  
  514.  
  515. if(isset($_GET['elimina'])){
  516.     
  517.         $ID_STAT= (int) $_GET['elimina'];
  518.     
  519.         $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')."
  520.               FROM {$db1['frontend']}.stat s, {$db1['frontend']}.utente u 
  521.               WHERE id_stat=$ID_STAT
  522.               AND u.id_utente=s.autore";
  523.         
  524.         $q=vmsql_query($sql,$link);
  525.     
  526.         $RS=vmsql_fetch_assoc($q);
  527.     
  528.         echo openLayout1("Statistica ".$RS['nome_stat']);
  529.         
  530.         echo "<div id=\"briciole\"><a href=\"../admin/index.php\">home amministrazione</a> &raquo; <a href=\"index.php\">statistiche</a> &raquo; elimina statistica </div>\n";
  531.         
  532.         echo "<h1>Elimina statistica</h1>\n";
  533.         
  534.         echo "<div style=\"padding:10px; background-color:#FFF2CF;width:40em;margin:3px 3px 16px 3px;border:1px solid #444;\">\n";
  535.         
  536.         echo "<p><b>ID</b>: $ID_STAT</p>";
  537.         echo "<p><b>Descrizione</b>: ".htmlentities($RS['desc_stat'],ENT_QUOTES)."</p>";
  538.         echo "<p><b>Autore</b>: ".$RS['nomecognome']."</p>";
  539.         echo "<p><b>Tipo grafico</b>: ".$RS['tipo_graph']."</p>";
  540.         echo "<p><b>Data definizione</b>: ".dataITA($RS['data_stat'])."</p>";
  541.         
  542.         echo "</div>\n";
  543.         
  544.         
  545.         echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" >\n";
  546.         
  547.         // info statistica...
  548.         
  549.         echo "<p><strong>Attenzione!</strong> Vuoi veramente eliminare la statistica? L'operazione &egrave; irreversibile.</p>\n";
  550.         
  551.         echo "<input type=\"hidden\" name=\"elimina_stat\" value=\"".intval($_GET['elimina'])."\" />\n";
  552.         echo "<input type=\"submit\" name=\"esegui_elimina_stat\" value=\"Elimina statistica\" />\n";
  553.         
  554.         echo "&nbsp; oppure &nbsp; <a href=\"index.php\">torna indietro</a>";
  555.         
  556.         echo "</form>\n";
  557.         
  558.         
  559.         echo closeLayout1();
  560.     
  561.     
  562. }
  563.  
  564.  
  565. ?>

Documentation generated on Sat, 22 Sep 2007 11:51:26 +0200 by phpDocumentor 1.4.0a2