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

Source for file xmlsub.php

Documentation is available at xmlsub.php

  1. <?php
  2. /**
  3.  * File sperimentale che gestisce l'output delle tabelle in XML
  4.  * con i record delle sottomaschere
  5.  * 
  6.  * @desc Output XML comprese le sottomaschere
  7.  * @package VFront
  8.  * @subpackage VFront_XML
  9.  * @author M.Marcello Verona
  10.  * @copyright 2007 M.Marcello Verona
  11.  * @version 0.90
  12.  * @license http://www.gnu.org/licenses/gpl.html GNU Public License
  13.  */
  14.  
  15.  
  16. require("../inc/conn.php");
  17. require("../inc/func.comuni.php");
  18. require("../inc/func.frontend.php");
  19. require("../inc/func.xmlize.php");
  20.  
  21.  
  22.  
  23.  
  24. /**
  25.  * Funzione che genera l'XML con anche i record delle sottomaschere.
  26.  * Partendo da una tabella prestabilita con anche la gestione
  27.  * dei record figli presenti nelle sottomaschere attivate.
  28.  *
  29.  * @param int $oid ID della tabella per il gruppo
  30.  * @param string $filename Nome della tabella
  31.  * @param bool $sub Mostra anche i record delle sottomaschere
  32.  * @param int $offset Offset riportato nell'XML
  33.  * @param int $tot Totale di record, riportato nell'XML
  34.  * @param string $xsl Eventuale foglio di stile da associare
  35.  * @param string $dtd Eventuale DTD da associare
  36.  * @param bool $header Manda un header di tipo "Content-type=XML" (default: true)
  37.  * @return string XML output
  38.  * @see xml.php
  39.  * @todo Questa funzione se ottimizzata puņ sostituire la procedura richiamata dal file xml.php
  40.  */
  41. function xmlize_table_sub($oid,$filename=null,$sub=true,$offset=0,$tot=0,$xsl='',$dtd='',$header=true){
  42.     
  43.     global $link;
  44.     
  45.     
  46.     $cols=prendi_colonne_frontend($oid,"column_name,table_name, orderby, orderby_sort",true);
  47.     
  48. //    var_dump($cols);
  49.     
  50.  
  51.  
  52.     $ORDER_BY ($cols[2][0]!=''"ORDER BY ".$cols[2][0]." ".$cols[3][0"";
  53.  
  54.     $OFF($offset==0"" "$offset";
  55.     
  56.     $LIMIT ($tot==0"" limit_sintax($tot,$OFF);
  57.     
  58.     $sql="SELECT ".implode(",",$cols[0])." FROM ".$cols[1][0]." $ORDER_BY  $LIMIT";
  59.     
  60.     
  61.     
  62.     $q vmsql_query($sql,$link);
  63.     
  64.     if(vmsql_num_rows($q)==0){
  65.         
  66.         return null;    
  67.     }
  68.     
  69.     // Inizia a fare l'xml
  70.     
  71.     
  72.     
  73.     $XML="";
  74.     
  75.     
  76.     
  77.     $XML.= ($header"<?xml version='1.0' encoding='utf-8'?>\n" "";
  78.     
  79.     $XML.= ($dtd"<!DOCTYPE vfront SYSTEM \"$dtd\">\n"";
  80.     
  81.     $XML.= ($xsl!=''"<?xml-stylesheet type=\"text/xsl\" href=\"$xsl\" ?>\n"";
  82.     
  83.     $XML.="<recordset tot=\"$tot\">\n";
  84.     
  85.     if($offset==0){
  86.         $auto_offset=true;
  87.         $offset =1;
  88.     }else{
  89.         $auto_offset=false;
  90.     }
  91.     
  92.     $fkk prendi_K_relazione_sub($oid);
  93.     
  94.     while($RS=vmsql_fetch_assoc($q)){
  95.         
  96.         $XML.="\t".xmlize_campo('row',array("offset"=>$offset))."\n";
  97.         
  98.         foreach($RS as $k=>$val){
  99.             
  100.             $val utf8_encode(trim($val));
  101.             
  102.             if($val!="" && !is_numeric($val)){
  103.                 $val="<![CDATA[".$val."]]>";
  104.             }
  105.             
  106.             $XML.="\t\t".xmlize_campo($k,array());
  107.             $XML.=trim($val);
  108.             $XML.="</$k>\n";
  109.             
  110.             if($fkk[0][0]==$k){
  111.         
  112. //                echo "ORA!";
  113.                 $XML.=xmlize_sottomaschera($val,$oid);
  114.  
  115.             }
  116.         }
  117.         
  118.         
  119.         
  120.         $XML.="\t</row>\n";
  121.         
  122.         if($auto_offset){
  123.             $offset++;
  124.         }
  125.         
  126.     }
  127.     
  128.     $XML.="</recordset>\n";
  129.     
  130.     
  131.     
  132.     
  133.     if(is_null($filename)) return $XML;
  134.     else{
  135.         
  136.         $fp =fopen($filename,"w");
  137.         fwrite($fp,$XML);
  138.         fclose($fp);
  139.         return true;
  140.     }
  141.     
  142. }
  143.  
  144.  
  145. /**
  146.  * Funzione di generazione di XML da una sottomaschera
  147.  *
  148.  * @param int $id_parent id_table della tabella parent di questa sottomaschera
  149.  * @param int $oid ID della sottomaschera considerata
  150.  * @param int $gid ID del gruppo considerato
  151.  * @param bool $solo_campi_visibili Se vera mostra solo i campi con diritti SELECT della sottomaschera
  152.  * @return string Frammento di XML
  153.  */
  154. function xmlize_sottomaschera($id_parent,$oid,$gid=0,$solo_campi_visibili=false){
  155.  
  156.     global $link$db1;
  157.  
  158.     $sub=prendi_sottomaschere($oid);
  159.     
  160.     
  161.     for($i=0;$i<count($sub);$i++){
  162.         
  163.         $order_sub ($sub[$i]["orderby_sub"]!=''?  "ORDER BY ".$sub[$i]["orderby_sub""";
  164.         
  165.         $sql_sub="SELECT * FROM ".$sub[$i]['nome_tabella']." WHERE ".$sub[$i]['campo_fk_sub']."='$id_parent$order_sub limit 10";
  166.         
  167.         $q_sub=vmsql_query($sql_sub,$link);
  168.         
  169.         if(vmsql_num_rows($q_sub)>0){
  170.         
  171.             $XMLSUB.="\t\t<subrecordset tabella=\"".$sub[$i]['nome_tabella']."\" nomefrontend=\"".$sub[$i]['nome_frontend']."\">\n";
  172.         
  173.             $offset=1;
  174.             
  175.             while($RS=vmsql_fetch_assoc($q_sub)){
  176.         
  177.                 $XMLSUB.="\t\t\t".xmlize_campo('subrow',array("offset"=>$offset))."\n";
  178.                 
  179.                 foreach($RS as $k=>$val){
  180.                     
  181.                     $val utf8_encode(trim($val));
  182.                     
  183.                     if($val!="" && !is_numeric($val)){
  184.                         $val="<![CDATA[".$val."]]>";
  185.                     }
  186.                     
  187.                     $XMLSUB.="\t\t\t\t".xmlize_campo($k,array());
  188.                     $XMLSUB.=$val;
  189.                     $XMLSUB.="</$k>\n";
  190.                 }
  191.                 
  192.                 $XMLSUB.="\t\t\t</subrow>\n";
  193.                 
  194.                 $offset++;
  195.                 
  196.             }
  197.             
  198.             $XMLSUB.="\t\t</subrecordset>\n";
  199.         
  200.         }
  201.         
  202.     }
  203.     
  204.     return $XMLSUB;
  205. }
  206.  
  207. //header('Content-type: text/xml');
  208. //echo xmlize_table_sub(1,null,true,0,50);
  209.  
  210.  
  211.     $OID = (int) $_GET['oid'];
  212.     $SUB = (bool) $_GET['sub'];
  213.     
  214.     $xsl (isset($_GET['type']&& $_GET['type']=='XML'"" FRONT_DOCROOT."/xml/".oid2name($OID)."/stile.xml";
  215.  
  216.     
  217.     
  218. // SINGOLO RECORD BASATO SULLA SERIE ORDINATA
  219.     if(is_numeric($_GET['c'])){
  220.         $XML xmlize_table_sub($OID,null,$SUB,$_GET['c'],$tot_records,$xsl);
  221.         
  222.     }
  223.     
  224.     
  225.     // INTERVALLO DI RECORD BASATO SULLA SERIE ORDINATA
  226.     elseif(preg_match("'([0-9]+),([0-9]+)'",$_GET['c'],$match)>0){
  227.         
  228.         $offset=intval($match[1]);
  229.         $limit=intval($match[2]);
  230.         
  231.         $XML xmlize_table_sub($OID,null,$SUB,$offset,$limit,$xsl);
  232.         
  233. //        $XML = xmlize("SELECT ".$campi_tabella." FROM $tabella ORDER BY $orderby_doppio LIMIT $offset,$limit",null,true,false,$tot_records,$xsl,$dtd);
  234.     }
  235.     
  236.     
  237.     // TUTTI I RECORD 
  238.     elseif($_GET['c']=='all'){
  239.         
  240.         $XML xmlize_table_sub($OID,null,$SUB,0,0,$xsl);
  241. //        $XML = xmlize("SELECT ".$campi_tabella." FROM $tabella ORDER BY $orderby_doppio ",null,true,false,$tot_records,$xsl);
  242.     }
  243.     
  244.     
  245.     // RECORD PER SINGOLO ID (DA CAMPO PK)        
  246.     elseif($_GET['id']>0){
  247.         
  248.         $XML xmlize_table_sub($OID,null,$SUB,$offset,$limit,$xsl);
  249. //        $XML = xmlize("SELECT ".$campi_tabella." FROM $tabella WHERE $PK=".intval($_GET['id'])." ORDER BY $orderby_doppio ",null,true,false,$tot_records,$xsl,$dtd);
  250.     }
  251.  
  252.     header("Content-Type: text/xml");
  253.     echo $XML;
  254.  
  255.  
  256. ?>

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