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

Source for file fop_exec.php

Documentation is available at fop_exec.php

  1. <?php
  2. /**
  3.  * Questo file gestisce i diritti e la sicurezza per l'esecuzione di Apache FOP.
  4.  * 
  5.  * @desc Esegue Apache FOP
  6.  * @package VFront
  7.  * @subpackage VFront_XML
  8.  * @author M.Marcello Verona
  9.  * @copyright 2007 M.Marcello Verona
  10.  * @version 0.90
  11.  * @license http://www.gnu.org/licenses/gpl.html GNU Public License
  12.  * @todo Mettere le estensioni possibili di FOP nelle variabili di ambiente, Verificare l'apertura dei report query_based
  13.  */
  14.  
  15. require("../inc/conn.php");
  16.  
  17. /**
  18.  * Funzione che lancia l'eseguibile FOP e manda a video il file generato.
  19.  * Il parametro $debug se impostato TRUE, mostra il codice di ritorno della shell e non manda in stream il file
  20.  *
  21.  * @param string $input_fo Eventuale file FO (non usato)
  22.  * @param string $input_xml File di input XML
  23.  * @param string $input_xsl File di input XSL
  24.  * @param string $output_file Nome per il file di output
  25.  * @param string $tipo Tipo di file da generare (default: pdf)
  26.  * @param bool $debug Parametro di debug: se attivo non viene generato il file ma l'output di FOP
  27.  */
  28. function fop_exec($input_fo='',$input_xml='',$input_xsl='',$output_file='',$tipo='pdf',$debug=false){
  29.     
  30.     global $types;
  31.     
  32.     if(!_FOP_ENABLED){
  33.         
  34.         die("FOP non attivato!<br />Modificare il file di configurazione per utilizzare l'eseguibile FOP");
  35.     }
  36.     
  37.     if($input_fo=='' && ($input_xml=='' && $input_xsl=='')){
  38.         
  39.         die("Files input non specificati");
  40.     }
  41.     
  42.     if(!is_file(_PATH_FOP)){
  43.     
  44.         die("File fop inesistente");
  45.     }
  46.     
  47.     if(!is_executable(_PATH_FOP)){
  48.         
  49.         die("File fop non eseguibile");
  50.     }
  51.     
  52.     if(in_array($tipo,$types)){
  53.     
  54.         $str_exec=_PATH_FOP
  55.         ." -xml ".$input_xml
  56.         ." -xsl ".$input_xsl
  57.         ." -$tipo ".$output_file;
  58.         
  59.         exec($str_exec
  60.         ,$output
  61.         ,$ret);
  62.     }
  63.     else{
  64.         
  65.         die('Tipo di output non supportato');
  66.     }
  67.     
  68.     
  69.     // SEZIONE DEBUG
  70.     $output=implode("\n",$output);
  71.     
  72.     if($debug){
  73.         print "<pre>";
  74.         echo $str_exec;
  75.         echo "\n";
  76.         var_dump($output);
  77.         print "\n";
  78.         var_dump($ret);
  79.         print "</pre>";
  80.     }
  81.     elseif($ret==0){
  82.         header("Content-typeapplication/$tipo");
  83.         $pezzi=explode("/",$output_file);
  84.         header ("Content-Disposition: inline; filename=".$pezzi[(count($pezzi)-1)]);
  85.         print join('',file($output_file));
  86.         unlink($output_file);
  87.     }
  88.     
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.     
  96. $tabella preg_replace("'[^a-z0-9_]'i","",$_GET['action']);
  97.  
  98. // SICUREZZA ---------------------------------------------
  99.  
  100.  
  101.  
  102.  
  103.     //Cerca le regole in DB// cerca i diritti
  104.     $q=vmsql_query("SELECT * FROM {$db1['frontend']}.xml_rules WHERE tabella='$tabellaORDER BY lastData DESC LIMIT 1",$link);
  105.     
  106.     if(vmsql_num_rows($q)==0){
  107.         echo "<h1>Accesso vietato</h1>\n"exit;
  108.     }
  109.     else $RS_rules=vmsql_fetch_assoc($q);
  110.     
  111.     
  112.     if($RS_rules['xslfo']=='-1'){
  113.         
  114.         echo "<h1>File non previsto</h1>\n"exit;
  115.     }
  116.     
  117.     
  118.     if($RS_rules['accesso']=='PUBLIC'){
  119.         
  120.         // non fa niente e continua con lo script
  121.     }
  122.     elseif($RS_rules['accesso']=='FRONTEND'){
  123.         proteggi(1);
  124.     }
  125.     elseif($RS_rules['accesso']=='GROUP'){
  126.         
  127.         $gruppi=explode(",",$RS_rules['accesso_gruppo']);
  128.         
  129.         if(is_array($gruppi&& in_array($_SESSION['gid'],$gruppi)){
  130.             
  131.             // va avanti
  132.         }
  133.         else{
  134.             echo "<h1>Accesso vietato</h1>\n"exit;
  135.         }
  136.     }
  137.     else// RESTRICT o altro...
  138.         
  139.         echo "<h1>Accesso vietato</h1>\n"exit;
  140.     }
  141.     
  142.     
  143.     
  144.     
  145.     
  146.     
  147. // ---------------------------------------------------------
  148.     
  149.     
  150.     
  151. if(isset($_GET['c'])){
  152.     
  153.     $file_xml_webFRONT_DOCROOT."/xml/$tabella/".$_GET['c']."/XML";
  154.  
  155. }
  156. else if(isset($_GET['id'])){
  157.     
  158.     $file_xml_webFRONT_DOCROOT."/xml/$tabella/id/".intval($_GET['id'])."/XML";
  159.  
  160. }
  161. else{
  162.     
  163.     $file_xml_webFRONT_DOCROOT."/xml/$tabella/all/XML";
  164. }
  165.  
  166. $file_xml=FRONT_REALPATH."/tmp/".$tabella.".xml";
  167.  
  168. copy($file_xml_web,$file_xml);
  169.  
  170.  
  171. // FILE XSL 
  172.  
  173. if($RS_rules['xslfo']==''){
  174.  
  175.     include("./fo.php");
  176.     
  177.     $file_xslFRONT_REALPATH."/tmp/$tabella.xslt";
  178.     
  179. }
  180. else{
  181.     
  182.     $file_xsl=_PATH_XSL."/".$RS_rules['xslfo'];
  183. }
  184.  
  185. // TIPI SUPPORTATI
  186. $types=array('pdf','rtf','ps','txt','tiff','png','pcl','apf','svg');
  187.  
  188. // tipo di documento
  189. $tipo_richiesto=trim(strtolower($_GET['type']));
  190.  
  191. if(in_array($tipo_richiesto,$types)){
  192.     
  193.     $TYPE_DOC=$tipo_richiesto;
  194. }
  195. else{
  196.     
  197.     $TYPE_DOC='pdf';
  198. }
  199.  
  200.  
  201. $file_outputFRONT_REALPATH."/tmp/".date("Ymd")."_".$tabella.".".strtolower($TYPE_DOC);
  202.  
  203. fop_exec('',$file_xml,$file_xsl,$file_output,$TYPE_DOC ,false);
  204.  
  205.  
  206. ?>

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