phpDocumentor VFront
Function-Libraries
[ class tree: VFront ] [ index: VFront ] [ all elements ]

Source for file func.xmlize.php

Documentation is available at func.xmlize.php

  1. <?php
  2. /**
  3. * Libreria di funzioni per la trasformazione delle query al database in file XML.
  4. * La libreria č utilizzata sia per le chiamate AJAX nella scheda che per altre funzioni di VFront,
  5. * ad esempio i report.
  6. @package VFront
  7. @subpackage Function-Libraries
  8. @author Mario Marcello Verona <marcelloverona@gmail.com>
  9. @copyright 2007 Mario Marcello Verona
  10. @version 0.90
  11. @license http://www.gnu.org/licenses/gpl.html GNU Public License
  12. */
  13.  
  14.  
  15.  
  16.  
  17.  
  18. /**
  19.  * Funzione che genera l'XML da una data query.
  20.  * La funzione č utilizzata in molte occasioni da VFront.
  21.  *
  22.  * @param string $sql SQL SELECT che genera l'XML
  23.  * @param string $filename Eventuale nome del file, se č necessario scriverlo. In caso contrario l'XML viene mandato in output
  24.  * @param bool $header Scrive le intestazioni XML
  25.  * @param int $offset OFFSET della query SQL
  26.  * @param int $tot TOT di record dei risultati della query SQL
  27.  * @param string $xsl Se presente applica un file di stile XSL all'XML
  28.  * @param string $dtd Se presente genera ed applica un DTD all'XML
  29.  * @return string XML risultato della query
  30.  */
  31. function xmlize($sql,$filename=null,$header=false,$offset=0,$tot=0,$xsl='',$dtd=''){
  32.     
  33.     global $link;
  34.     
  35.     $q vmsql_query($sql,$link);
  36.     
  37.     if(vmsql_num_rows($q)==0){
  38.         
  39.         return null;    
  40.     }
  41.     
  42.     // Inizia a fare l'xml
  43.     
  44.     
  45.     
  46.     $XML="";
  47.     
  48.     
  49.     
  50.     $XML.= ($header"<?xml version='1.0' encoding='utf-8'?>\n" "";
  51.     
  52.     $XML.= ($dtd"<!DOCTYPE vfront SYSTEM \"$dtd\">\n"";
  53.     
  54.     $XML.= ($xsl!=''"<?xml-stylesheet type=\"text/xsl\" href=\"$xsl\" ?>\n"";
  55.     
  56.     $XML.="<recordset tot=\"$tot\">\n";
  57.     
  58.     if($offset===false){
  59.         $auto_offset=true;
  60.         $offset =1;
  61.     }else{
  62.         $auto_offset=false;
  63.     }
  64.     
  65.     while($RS=vmsql_fetch_assoc($q)){
  66.         
  67.         $XML.="\t".xmlize_campo('row',array("offset"=>$offset))."\n";
  68.         
  69.         foreach($RS as $k=>$val){
  70.             
  71.             $val utf8_encode(trim($val));
  72.             
  73.             if($val!="" && !is_numeric($val)){
  74.                 $val="<![CDATA[".$val."]]>";
  75.             }
  76.             
  77.             $XML.="\t\t".xmlize_campo($k,array());
  78.             $XML.=$val;
  79.             $XML.="</$k>\n";
  80.         }
  81.         
  82.         $XML.="\t</row>\n";
  83.         
  84.         if($auto_offset){
  85.             $offset++;
  86.         }
  87.         
  88.     }
  89.     
  90.     $XML.="</recordset>";
  91.     
  92.     
  93.     
  94.     
  95.     if(is_null($filename)) return $XML;
  96.     else{
  97.         
  98.         $fp =fopen($filename,"w");
  99.         fwrite($fp,$XML);
  100.         fclose($fp);
  101.         return true;
  102.     }
  103.     
  104. }
  105.  
  106.  
  107. /**
  108.  * Funzione che genera l'XML per uno specifico campo
  109.  *
  110.  * @param string $tag Il nome del campo (che diverrā il nome del tag)
  111.  * @param array $attr Array di attributi (nome_attributo=>valore)
  112.  * @return string XML
  113.  */
  114. function xmlize_campo($tag,$attr){
  115.     
  116.         $attributi="";
  117.     
  118.         foreach($attr as $k=>$val){
  119.             
  120.             $attributi .=" $k=\"$val\"";
  121.         }
  122.     
  123.         return "<".$tag.$attributi.">";
  124.     
  125. }
  126.  
  127. ?>

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