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

Source for file rpc.xmlgrid.php

Documentation is available at rpc.xmlgrid.php

  1. <?php
  2. /**
  3. * File di gestione della tabella dinamica dhtmlGrid.
  4. * Viene richiamato dallo script {@link scheda.php} e dalle funzioni javascript.
  5. @package VFront
  6. @subpackage RPC
  7. @author Mario Marcello Verona <marcelloverona@gmail.com>
  8. @copyright 2007 Mario Marcello Verona
  9. @version 0.90
  10. @license http://www.gnu.org/licenses/gpl.html GNU Public License
  11. */
  12.  
  13. require("./inc/conn.php");
  14. require("./inc/func.frontend.php");
  15. require("./inc/func.comuni.php");
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. /**
  23.  * Da una query SQL viene restituito l'XML generato per la griglia dxhtmlGrid
  24.  *
  25.  * @param string $sql 
  26.  * @param int $offset 
  27.  * @param string $filename 
  28.  * @param bool $header 
  29.  * @param string $PK 
  30.  * @return void 
  31.  */
  32. function xmlize_grid($sql,$offset=0,$filename=null,$header=true,$PK=null){
  33.     
  34.     global $link,$_VARIABILI;
  35.     
  36.     $q vmsql_query($sql,$link);
  37.     
  38.     if(vmsql_num_rows($q)==0){
  39.         
  40.         return null;    
  41.     }
  42.     
  43.     // Inizia a fare l'xml
  44.     $offset++;
  45.     
  46.     $XML($header"<?xml version='1.0' encoding='utf-8'?>\n" "";
  47.     
  48.     $XML.="<rows>\n";
  49.     
  50.     while($RS=vmsql_fetch_assoc($q)){
  51.         
  52.         
  53.         
  54.         
  55.         # Se è un contesto di ricerca...
  56.         if(isset($_GET['q'])){
  57.             # identificativo ($RS)
  58.             $offset_ricerca=$RS['n_offset']+1;
  59.             
  60.             $XML.="\t".xmlize_campo('row',array("id"=>$RS['pk']))."\n";
  61.             $XML.="\t\t<cell>".$offset_ricerca."</cell>\n";
  62.             
  63.         }
  64.         else{
  65.             # identificativo (offset)
  66.             $XML.="\t".xmlize_campo('row',array("id"=>$RS['pk']))."\n";
  67.             $XML.="\t\t<cell>".$offset."</cell>\n";
  68.         }
  69.         
  70.         foreach($RS as $k=>$val){
  71.             
  72.                     
  73.             // Il campo speciale prendi valore imposta l'offset per la ricerca
  74.             if($k!='pk'){
  75.                 
  76.                 $XML.="\t\t".xmlize_campo('cell',array());
  77.                 $val utf8_encode(trim($val));
  78.                 
  79.                 if(isset($_VARIABILI['max_char_tabella']&& intval($_VARIABILI['max_char_tabella'])>0){
  80.                     
  81.                     if(strlen($val)>$_VARIABILI['max_char_tabella']$val substr($val,0,$_VARIABILI['max_char_tabella'])."...";
  82.                     
  83.                 }
  84.                 
  85.                 // togli new line e sostituisci gli spazi
  86.                 $val str_replace(array(" ","-","\n","\r","\n\r","\r\n"),array("&nbsp;","&nbsp;","","","",""),$val);
  87.                 
  88.                 if($val!='' && !is_numeric($val)) $val="<![CDATA[".$val."]]>";
  89.                 
  90.                 $XML.=$val;
  91.                 $XML.="</cell>\n";
  92.             }
  93.         }
  94.         
  95.         $XML.="\t</row>\n";
  96.         
  97.         
  98.         $offset++;
  99.     }
  100.     
  101.     $XML.="</rows>\n";
  102.     
  103.     
  104.     
  105.     
  106.     if(is_null($filename)){
  107.         
  108.         
  109.         if stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) 
  110.             header("Content-type: application/xhtml+xml")
  111.         
  112.         else 
  113.             header("Content-type: text/xml")
  114.         }
  115.         
  116.         print $XML;
  117.         
  118.     }
  119.     else{
  120.         
  121.         $fp =fopen($filename,"w");
  122.         fwrite($fp,$XML);
  123.         fclose($fp);
  124.         return true;
  125.     }
  126.     
  127. }
  128.  
  129.  
  130. /**
  131.  * Genera l'XML dal campo dato con gli eventuali attributi
  132.  *
  133.  * @param string $tag 
  134.  * @param array $attr 
  135.  * @return string 
  136.  */
  137. function xmlize_campo($tag,$attr){
  138.     
  139.         $attributi="";
  140.     
  141.         foreach($attr as $k=>$val){
  142.             
  143.             $attributi .=" $k=\"$val\"";
  144.         }
  145.     
  146.         return "<".$tag.$attributi.">";
  147.     
  148. }
  149.  
  150.  
  151. ##########################################################################################################
  152.  
  153.     
  154.     $tabella $_GET['t'];
  155.     
  156.     if(!is_tabella($tabella)){
  157.         
  158.         echo "Tabella inesistente";
  159.         exit;
  160.     }
  161.  
  162.     
  163.     $OFFSET (isset($_GET['rowsLoaded'])) intval($_GET['rowsLoaded']0;
  164.     // altro modo di prendere l'offset... e sovrascrivo.
  165.     $OFFSET (isset($_GET['of'])) intval($_GET['of']$OFFSET;
  166.     
  167.     // PRENDI CAMPI VISIBILI
  168. //    $info_campi = prendi_colonne_frontend($tabella,"column_name",false);
  169.  
  170.     $sql_campi_tab="SELECT column_name FROM {$db1['frontend']}.registro_col c, {$db1['frontend']}.registro_tab t 
  171.                     WHERE c.id_table=t.id_table
  172.                     AND t.table_name='$tabella'
  173.                     AND t.gid='".intval($_SESSION['gid'])."'
  174.                     AND c.in_table=1
  175.                     ORDER BY c.ordinal_position";
  176.     
  177.     $q_info_campi_tab vmsql_query($sql_campi_tab,$link);
  178.     
  179.     $info_campi vmsql_fetch_row_all($q_info_campi_tab,true);
  180.     
  181.     
  182.     
  183.     list($column_name$info_campi;
  184.     
  185.     unset($info_campi);
  186.     
  187.     if(!isset($_VARIABILI)){
  188.         
  189.         include("./inc/func.var_frontend.php");
  190.         var_frontend();
  191.     }
  192.     
  193.     // Prendi la variabile di LIMIT
  194.     $LIMIT (isset($_VARIABILI['n_record_tabella']&& ($_VARIABILI['n_record_tabella']>0)) 
  195.             ? $_VARIABILI['n_record_tabella'20;
  196.     
  197.     $campi_vis=implode(',',$column_name);
  198.     
  199.     
  200.     // Genera l'order BY
  201.     if(isset($_GET['ord'])){
  202.     
  203.         $orderby_val addslashes(stripslashes($_GET['ord']));
  204.         $ORDERBY (is_campo($orderby_val)) "ORDER BY ".$orderby_val "";
  205.         
  206.     }
  207.     else{
  208.         
  209.         $orderby_val prendi_orderby($tabella,$_SESSION['gid']);        
  210.         $ORDERBY ($orderby_val!="""ORDER BY ".$orderby_val "";    
  211.         
  212.     }
  213.     
  214.     
  215.     
  216.  
  217.     
  218.     // prendi la chiave primaria:
  219.         $PK prendi_PK($tabella);
  220.         
  221.         
  222.         
  223.     ######################################################################
  224.     #
  225.     #    RISPOSTA DI RICERCA CON MOLTI RISULTATI:
  226.     #
  227.     #
  228.     
  229.     if(isset($_GET['q'])){
  230.         $ids str_replace("|" "','" addslashes($_GET['q']));
  231.     
  232.     
  233.         
  234.         
  235.         $WHERE " WHERE $PK IN ('".$ids."') ";
  236.         
  237.         $orderby_campo str_replace(array("ASC","DESC"),"",$orderby_val);
  238.         
  239.         // Imposto un alias per 
  240.         $campi_vis_rep str_replace("$orderby_campo""$orderby_campo as prendi_valore"$campi_vis);
  241.         
  242.         $sql ="SELECT $PK as pk$campi_vis "
  243.         "
  244.           FROM $tabella 
  245.           $WHERE
  246.           $ORDERBY 
  247.           ".limit_sintax($LIMIT,$OFFSET);
  248.         
  249.         rpc_debug($sql);
  250.         
  251.     }
  252.     
  253.     
  254.  
  255.     ######################################################################
  256.     #
  257.     #    TABELLA NORMALE
  258.     
  259.     else {
  260.         
  261.          $sql="SELECT $PK as pk$campi_vis 
  262.           FROM $tabella 
  263.           $ORDERBY 
  264.           ".limit_sintax($LIMIT,$OFFSET);
  265.          
  266.          rpc_debug($sql);
  267.     }
  268.     
  269.     
  270.      
  271.     
  272.     // mando il file
  273.     //    DEBUG : 
  274.     //  xmlize_grid($sql,$OFFSET,'test.xml',true,$PK);
  275.     
  276.     
  277.     xmlize_grid($sql,$OFFSET,null,true,$PK);
  278.     
  279.  
  280.  
  281.  
  282. ?>

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