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

Source for file helpdocs.php

Documentation is available at helpdocs.php

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

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