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

Source for file doc_tecnica.php

Documentation is available at doc_tecnica.php

  1. <?php
  2. /**
  3.  * @desc File di gestione della documentazione tecnica
  4.  * @package VFront
  5.  * @subpackage Administration
  6.  * @author M.Marcello Verona
  7.  * @copyright 2007 M.Marcello Verona
  8.  * @version 0.90
  9.  * @license http://www.gnu.org/licenses/gpl.html GNU Public License
  10.  */
  11. require_once("../inc/conn.php");
  12. require_once("../inc/layouts.php");
  13. require_once("../inc/func.comuni.php");
  14.  
  15.  
  16. // Dimensione del max_upload preso dal php.ini (è indicato in M)
  17. $max_kb=(int) ini_get('post_max_size'*1024 *1024;
  18.  
  19.  
  20.  
  21.  
  22. /**
  23.  * @desc Rileva il content-type dall'estensione
  24.  * @todo Ipotizzare un metodo alternativo e più sicuro
  25.  * @param string $filename Nome de file
  26.  * @return string Content-type
  27.  */
  28. function mime_content_type_($filename)
  29. {
  30.     
  31.     $info=pathinfo($filename);
  32.  
  33.    $mime array(
  34.        'rtf' => 'application/rtf',
  35.        'doc' => 'application/doc',
  36.        'pdf' => 'application/pdf',
  37.        'xls' => 'application/xls',
  38.        'odt' => 'application/odt',
  39.        'sxw' => 'application/sxw',
  40.        'zip' => 'application/x-zip-compressed',
  41.        'rar' => 'application/rar',
  42.        'txt' => 'text/txt'
  43.      
  44.    );
  45.    
  46.    
  47.    return $mime[$info['extension']];
  48. }
  49.  
  50.  
  51. /**
  52.  * @desc Rileva il content-type dall'estensione e genera una icona per i formati più comuni
  53.  * @param string $filename Nome de file
  54.  * @return string Icona in immagine HTML
  55.  */
  56. function mime_content_type_image($filename)
  57. {
  58.     
  59.     
  60.    $mime array(
  61.        '.rtf' => 'doc.gif',
  62.        '.doc' => 'doc.gif',
  63.        '.pdf' => 'pdf.gif',
  64.        '.xls' => 'xls.gif',
  65.        '.odt' => 'txt.gif',
  66.        '.sxw' => 'txt.gif',
  67.        '.zip' => 'zip.gif',
  68.        '.rar' => 'zip.gif',
  69.        '.txt' => 'generic.gif'     
  70.    );
  71.    
  72.    return "<img src=\"img/mime/".$mime[strrchr($filename,'.')]."\" alt=\"tipo: ".substr(strrchr($filename'.'),1)."\" />";
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. // Se c'è inserisce il file
  81. if(isset($_GET['add']&& count($_FILES)>&& $_SESSION['user']['livello']>1){
  82.     
  83.         // il formato è corretto?
  84.         if(strlen(mime_content_type_($_FILES['documento']['name']))==0){
  85.             header("Location: ".$_SERVER['PHP_SELF']."?ko=tipo_non_valido");
  86.             exit;
  87.         }
  88.         
  89.         // Se non è troppo grande
  90.         if($_FILES['documento']['size']>$max_kb){
  91.             
  92.             header("Location: ".$_SERVER['PHP_SELF']."?ko=max_kb");
  93.             exit;
  94.         }
  95.         
  96.         $NOME_FILE=preg_replace("'[^a-z0-9._-]+'i","_",$_FILES['documento']['name']);
  97.         
  98.         echo $_FILES['documento']['tmp_name'" ---- "_PATH_HELPDOCS2."/".$NOME_FILE;
  99.         
  100.         
  101.         $op=move_uploaded_file($_FILES['documento']['tmp_name']_PATH_HELPDOCS2."/".$NOME_FILE);
  102.         
  103.         if($op){
  104.             header("Location: ".$_SERVER['PHP_SELF']."?ok");
  105.             exit;
  106.         }
  107.         else{
  108.             header("Location: ".$_SERVER['PHP_SELF']."?ko=operazione_non_riuscita");
  109.             exit;
  110.         }
  111.     
  112.     
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. // CANCELLAZIONE DEL FILE:
  121.  
  122.  
  123. if(isset($_GET['del']&& $_SESSION['user']['livello']>1){
  124.     
  125.     $id_file$_GET['del'];
  126.     
  127.     // PRENDI I FILES
  128.     
  129.     $dir_PATH_HELPDOCS2;
  130.     
  131.     // Open a known directory, and proceed to read its contents
  132.     if (is_dir($dir)) {
  133.         if ($dh opendir($dir)) {
  134.             while (($file readdir($dh)) !== false{
  135.                 if(!is_dir($file)){
  136.                 
  137.                     $docs[]=array('nome'=>$file
  138.                                   'type'=>mime_content_type_($dir."/".$file)
  139.                                   'data'=>filectime($dir."/".$file),
  140.                                   'size'=>filesize($dir."/".$file)
  141.                                   );
  142.                 }
  143.             }
  144.             closedir($dh);
  145.         }
  146.     }
  147.     
  148.     $docs=ordina_matrice($docs,$data,'DESC');
  149.  
  150.     if(!is_file($dir."/".$docs[$id_file]['nome'])){
  151.         header("Location: ".$_SERVER['PHP_SELF']."?ko=file_inesistente");
  152.         exit;
  153.     }
  154.         
  155.  
  156.     $op=unlink($dir."/".$docs[$id_file]['nome']);
  157.     
  158.     if($op){
  159.             header("Location: ".$_SERVER['PHP_SELF']."?eliminato");
  160.             exit;
  161.     }
  162.     else{
  163.             header("Location: ".$_SERVER['PHP_SELF']."?ko=operazione_non_riuscita");
  164.             exit;
  165.     }
  166.     
  167. }
  168.  
  169. // DOWNLOAD DEL FILE
  170.     
  171.  
  172. else if(isset($_GET['doc'])){
  173.     
  174.     
  175.  
  176.     // PRENDI I FILES
  177.     
  178.     $dir_PATH_HELPDOCS2;
  179.     
  180.     // Open a known directory, and proceed to read its contents
  181.     if (is_dir($dir)) {
  182.         if ($dh opendir($dir)) {
  183.             while (($file readdir($dh)) !== false{
  184.                 if(!is_dir($file)){
  185.                 
  186.                     $docs[]=array('nome'=>$file
  187.                                   'type'=>mime_content_type_($dir."/".$file)
  188.                                   'data'=>filemtime($dir."/".$file),
  189.                                   'size'=>filesize($dir."/".$file)
  190.                                   );
  191.                 }
  192.             }
  193.             closedir($dh);
  194.         }
  195.     }
  196.     
  197.     $docs=ordina_matrice($docs,$data,'DESC');
  198.     
  199.     
  200.     $kk=(int) $_GET['doc'];
  201.     
  202.         if(file_exists(_PATH_HELPDOCS2."/".$docs[$kk]['nome'])){
  203.            header("Pragma: public");
  204.            header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  205.            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  206.            header("Cache-Control: private",false);
  207.            header("Content-Type: application/force-download");
  208.            header('Content-Disposition: attachment; filename="'.$docs[$kk]['nome'].'"');
  209.            header("Content-Transfer-Encoding: binary");
  210.            header('Content-Length: '.$docs[$kk]['size']);
  211.            set_time_limit(0);
  212.            @readfile(_PATH_HELPDOCS2."/".$docs[$kk]['nome']OR die("<html><body OnLoad=\"javascript: alert('Nessun file trovato');history.back();\" bgcolor=\"#F0F0F0\"></body></html>");
  213.        
  214.         }
  215.         else{    
  216.             
  217.             openErrorGenerico("File non trovato!",true);
  218.             
  219.         }
  220.   exit;
  221.     
  222. }
  223.  
  224.     $files array("sty/admin.css","sty/tabelle.css","js/confirm_delete.js");
  225.  
  226.     echo openLayout1("Documentazione tecnica",$files);
  227.     
  228.     echo "<div id=\"briciole\"><a href=\"index.php\">home amministrazione</a> &raquo; documentazione tecnica</div>";
  229.     
  230.     echo "<h1>Documentazione tecnica</h1>\n";
  231.     
  232.     
  233.     if(isset($_GET['ko'])){
  234.         
  235.         switch($_GET['ko']){
  236.             
  237.             case "max_kb": echo "<p><strong class=\"var\">Attenzione!</strong> file troppo grande. E' possibile inviare file fino a ".($max_kb/1024)." kb</p>\n";
  238.             break;
  239.             
  240.             case "tipo_non_valido": echo "<p><strong class=\"var\">Attenzione!</strong> formato non consentito. E' possibile inviare file dei seguenti formati: doc, xls, pdf, rtf, zip, txt, odt, sxw</p>\n";
  241.             break;
  242.             
  243.             case "operazione_non_riuscita": echo "<p><strong class=\"var\">Attenzione!</strong> operazione non riuscita. Qualora il tipo e le dimensioni del file (massimo ".($max_kb/1024)." kb) fossero corrette ed il problema continuasse a verificarsi, contattare l'<a href=\"mailto:"._SYS_ADMIN_MAIL."\">amministratore di sistema</a>.</p>\n";
  244.             break;
  245.         }
  246.     }
  247.     elseif (isset($_GET['ok'])){
  248.         
  249.         echo "<p><strong class=\"verde\">File caricato correttamente.</strong></p>\n";
  250.     }
  251.     elseif(isset($_GET['eliminato'])){
  252.         echo "<p><strong class=\"arancio\">File eliminato correttamente.</strong></p>\n";
  253.     }
  254.     
  255.     
  256.     // PRENDI I FILES
  257.     
  258.     $dir_PATH_HELPDOCS2;
  259.     
  260.     // Open a known directory, and proceed to read its contents
  261.     if (is_dir($dir)) {
  262.         if ($dh opendir($dir)) {
  263.             while (($file readdir($dh)) !== false{
  264.                 if(!is_dir($file)){
  265.                 
  266.                     $docs[]=array('nome'=>$file
  267.                                   'type'=>mime_content_type_($dir."/".$file)
  268.                                   'data'=>filemtime($dir."/".$file),
  269.                                   'size'=>filesize($dir."/".$file)
  270.                                   );
  271.                 }
  272.             }
  273.             closedir($dh);
  274.         }
  275.     }
  276.     
  277.     $docs=ordina_matrice($docs,$data,'DESC');
  278.     
  279.     echo "<div class=\"info\">
  280.         <p>In questa sezione sono presenti documenti con informazioni sul funzionamento dell'applicazione e sul database. <br />
  281.         Cliccare sul nome del documento per aprirlo, 
  282.         oppure cliccare con il tasto destro e scegliere <em>Salva oggetto con nome</em>
  283.          per scaricare il documento sul proprio computer.<br />
  284.         </p>
  285.         </div>\n";
  286.     
  287.     if($_SESSION['user']['livello']>1){
  288.         echo "<p><a href=\"javascript:;\" onclick=\"document.getElementById('add_record').style.display='';\">Aggiungi file</a></p>\n";
  289.     
  290.     }
  291.     
  292.     
  293.     echo "<table summary=\"Tabella file help\" class=\"tab-report-dip\">\n";
  294.     
  295.     echo "<tr>
  296.         <th class=\"lilla\" colspan=\"2\">Documento</th>
  297.         
  298.         <th class=\"lilla\">Ultima modifica</th>
  299.         <th class=\"lilla\">Dimensione</th>",
  300.         ($_SESSION['user']['livello']>2?
  301.         "<th class=\"lilla\">Elimina</th>" "",
  302.         "</tr>\n
  303.         ";
  304.         
  305. //    $dir_down=str_replace(FRONT_DOCROOT,'',_PATH_HELPDOCS);
  306.     
  307.     for($i=0;$i<count($docs);$i++){
  308.         
  309.         echo "\t\t<tr><td>".mime_content_type_image($docs[$i]['nome'])."</td>
  310.             <td><a href=\"?doc=$i\">".$docs[$i]['nome']."</a></td>
  311.             <td>".date("d/m/Y H:i",$docs[$i]['data'])."</td>
  312.             <td>".round($docs[$i]['size']/1024,0)." Kb</td>",
  313.             ($_SESSION['user']['livello']>2?
  314.             "<td><a href=\"javascript:;\" onclick=\"confirm_delete_f(this,$i);\" >elimina</a></td>"",
  315.             "</tr>";
  316.     }
  317.     
  318.     echo "</table>\n";
  319.     
  320.     $ADD_FILE=
  321.   '    
  322.     <div id="add_record" style="display: none; top: 20%; left: 20%; width:500px; height: 230px; ">
  323.                            
  324.         <div style="text-align: right;">
  325.         
  326.             <a href="javascript:;" onclick="document.getElementById(\'add_record\').style.display=\'none\';"> Chiudi X </a>
  327.         
  328.         </div>
  329.         
  330.                      
  331.         <div style="margin: 20px;">
  332.         
  333.             <h3> Aggiungi file</h3>
  334.         
  335.             <p>Sono consentiti i file dei seguenti formati: <strong>doc, xls, pdf, rtf, zip, txt, odt, sxw</strong></p>
  336.             
  337.             <form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?add"> 
  338.                 
  339.                  <label for="immagine"><strong>File da inserire</strong></label><br/>
  340.                   <input type="file" name="documento" id="documento" size="60" />
  341.                 <br /><br />
  342.                 <input name="invia" value="   Invia   " type="submit" />
  343.             
  344.             </form>
  345.         
  346.         </div>
  347.  
  348.      
  349. </div>';
  350.   
  351.   if($_SESSION['user']['livello']>1){
  352.       echo $ADD_FILE;
  353.   }
  354.   
  355.     
  356.     echo closeLayout1();
  357. ?>

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