Source for file xml.php
Documentation is available at xml.php
* File che getisce la creazione dinamica e lo stream dell'XML di VFront
* Viene utilizzato anche per generare report HTML e PDF, se associato a fogli di stile
* Il file non è richiamato direttamente ma mediante riscrittura degli URL
* da parte del file .htaccess presente nella stessa cartella
* @author M.Marcello Verona
* @copyright 2007 M.Marcello Verona
* @license http://www.gnu.org/licenses/gpl.html GNU Public License
require ("../inc/conn.php");
require ("../inc/layouts.php");
require ("../inc/func.comuni.php");
require ("../inc/func.frontend.php");
require ("../inc/func.xmlize.php");
* Funzione per recuperare le impostazioni del gruppo attuale per la tabella in oggetto
* Restituisce SQL con eventuali subquery
* @param string $nome_tabella
* @param bool $only_visibile
$clausola_visibile = ($only_visibile) ? "AND c.in_visibile=1" : "";
// PRENDI INFO Colonne della TABELLA
$query2 = vmsql_query("SELECT c.column_name , c.data_type , c.character_maximum_length as maxsize, c.is_nullable,
c.in_tipo, c.in_default, t.orderby, t.orderby_sort
FROM {$db1['frontend']}.registro_col c, {$db1['frontend']}.registro_tab t
AND c.id_table=t.id_table
ORDER BY c.ordinal_position",$link);
foreach($matrice_info as $k=> $info){
$ORDERBY = ($info['orderby']!= '') ? "ORDER BY ". $info['orderby']. " ". $info['orderby_sort'] : "";
if($info['in_tipo']== "select_from"){
$test = preg_match("'SELECT ([\w]+) ?, ?([\w]+) +FROM +([\w]+).*?'i",$info['in_default'],$campo_k);
$campi.= " (SELECT t$k.{$campo_k[2]} FROM {$campo_k[3]} t$k WHERE t$k.{$campo_k[1]}=t.{$info['column_name']}) as ". $info['column_name']. ",";
$campi.= " t.". $info['column_name']. ",";
$QB = (isset ($_GET['querybased']) && $_GET['querybased']== '@') ? 1: 0;
$nome_report = preg_replace("'[^a-z0-9_-]'i","",$_GET['action']);
$tabella = preg_replace("'[^a-z0-9_]'i","",$_GET['action']);
########################################
########################################
// cerca i diritti come report tabella
$q= vmsql_query("SELECT * FROM {$db1['frontend']}.xml_rules WHERE nome_report='$nome_report' ORDER BY lastData DESC LIMIT 1",$link);
// cerca i diritti come report tabella
$q= vmsql_query("SELECT * FROM {$db1['frontend']}.xml_rules WHERE tabella='$tabella' ORDER BY lastData DESC LIMIT 1",$link);
echo "<h1>Accesso vietato</h1>\n"; exit;
if($RS_rules['accesso']== 'PUBLIC'){
// non fa niente e continua con lo script
elseif($RS_rules['accesso']== 'FRONTEND'){
elseif($RS_rules['accesso']== 'GROUP'){
$gruppi= explode(",",$RS_rules['accesso_gruppo']);
echo "<h1>Accesso vietato</h1>\n"; exit;
else{ // RESTRICT o altro...
echo "<h1>Accesso vietato</h1>\n"; exit;
if(trim($orderby)== 'ASC') $orderby = 1;
//aggiungi l'ID all'order by
$orderby_doppio= $orderby. ", $PK ";
$campo_orderby = str_replace(array(" ASC"," DESC"),"",$orderby);
$operatore_orderby = ereg(' DESC',$orderby) ? " > " : " < ";
// CASO RISULTATO DI RICERCA-------------------------------------------------------
// SE c'è l'id in GET prendi calcola a che punto dell'elenco si è arrivati
if(isset ($_GET['id']) && intval($_GET['id'])> 0){
// Prendi il moe del campo orderby ed il vaolre relativo all'id
$sql_calcola_sub = "SELECT s.$campo_orderby
FROM $tabella s WHERE s.". $PK. "='". $_GET['id']. "'";
$sql_calcola = "SELECT count(*) FROM ". $_GET['action']. " t
WHERE t.$campo_orderby $operatore_orderby ($sql_calcola_sub) OR t.$campo_orderby IS NULL";
$offset= (int) $_GET['c'];
// OPZIONE PER AVERE I CAMPI ROW
// i campi row sono quelli non elaborati, in caso contrario mostra i campi richiesti in tabella con le subquery
$tabella = $tabella . " t ";
} // report basato su tabella
// foglio di stile personalizzato
$xsl= (isset ($_GET['type']) && $_GET['type']== 'XML') ? "" : _PATH_WEB_XSL. "/". $RS_rules['xsl'];
$chiocciola = ($QB) ? "@": "";
$xsl = (isset ($_GET['type']) && $_GET['type']== 'XML') ? "" : FRONT_DOCROOT. "/xml/". $chiocciola. $_GET['action']. "/stile.xml";
########################################################################################
if(isset ($_GET['riepilogo'])){
$q_conta= vmsql_query("SELECT count(*) FROM $tabella ",$link);
echo "<h1>$titolo_pag ". $tab. "</h1>\n";
echo "<p><b>Tutti i record:</b></p>\n";
// se è query based metti una @ davanti al nome
echo "<a href=\"". FRONT_DOCROOT. "/xml/$tab/all/XML\">XML ($n_record records)</a>\n";
echo " | <a href=\"". FRONT_DOCROOT. "/xml/$tab/all/\">HTML ($n_record records)</a>\n";
$q_fo= vmsql_query("SELECT xslfo FROM {$db1['frontend']}.xml_rules WHERE tabella='$tab' ORDER BY lastData DESC",$link);
echo " | <a href=\"". FRONT_DOCROOT. "/xml/$tab/PDF\">PDF ($n_record records)</a>\n";
echo "<p><b>Viste con paginazione:</b></p>\n";
echo "<p>Versione XML: ";
for($i= 0;$i< ceil($n_record/ 50);$i++ ){
$XML_PAG.= " <a href=\"". FRONT_DOCROOT. "/xml/$tab/$of,$n_pag/XML\">". ($i+ 1) . "</a> |";
echo substr($XML_PAG,0,- 2). "</p>\n";
echo "<p>Versione HTML: ";
for($i= 0;$i< ceil($n_record/ 50);$i++ ){
$XML_PAG.= " <a href=\"". FRONT_DOCROOT. "/xml/$tab/$of,$n_pag/\">". ($i+ 1) . "</a> |";
echo substr($XML_PAG,0,- 2). "</p>\n";
/*if($xslfo!='-1' && _FOP_ENABLED){
echo "<p>Versione PDF: ";
for($i=0;$i<ceil($n_record/50);$i++){
$XML_PAG.= " <a href=\"".FRONT_DOCROOT."/xml/$tab/$of,$n_pag/PDF\">". ($i+1) ."</a> |";
echo substr($XML_PAG,0,-2)."</p>\n";
if(preg_match("'([0-9]+),([0-9]+)'",$_GET['c'],$match)> 0 && !eregi(" LIMIT",$RS_rules['def_query'])){
else if(is_numeric($_GET['c']) && !eregi(" LIMIT",$RS_rules['def_query'])){
$offset= (int) $_GET['c'];
// SINGOLO RECORD BASATO SULLA SERIE ORDINATA
$XML = xmlize("SELECT ". $campi_tabella. " FROM $tabella ORDER BY $orderby_doppio ". limit_sintax(1,$offset),null,true,$offset,$tot_records,$xsl,$dtd);
// INTERVALLO DI RECORD BASATO SULLA SERIE ORDINATA
elseif(preg_match("'([0-9]+),([0-9]+)'",$_GET['c'],$match)> 0){
$XML = xmlize("SELECT ". $campi_tabella. " FROM $tabella ORDER BY $orderby_doppio ". limit_sintax($limit,$offset),null,true,false,$tot_records,$xsl,$dtd);
elseif($_GET['c']== 'all'){
$XML = xmlize("SELECT ". $campi_tabella. " FROM $tabella ORDER BY $orderby_doppio ",null,true,false,$tot_records,$xsl);
// RECORD PER SINGOLO ID (DA CAMPO PK)
$XML = xmlize("SELECT ". $campi_tabella. " FROM $tabella WHERE $PK=". intval($_GET['id']). " ORDER BY $orderby_doppio ",null,true,false,$tot_records,$xsl,$dtd);
// TRASFORMAZIONE XSLT - Lato client o lato server?
if($_GET['type']== 'XML'){
header("Content-Type: text/xml");
// verifica se la trasformazione debba essere ottenuta lato client o lato server
if(!isset ($GLOBALS['_VARIABILI'])){
require_once("../inc/func.var_frontend.php");
if($GLOBALS['_VARIABILI']['server_xslt']== '1'){
require_once("./xslparser.php");
$fp= fopen($file_xml,"w");
header("Content-Type: text/xml");
|