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

Source for file gestione_registro.inc.php

Documentation is available at gestione_registro.inc.php

  1. <?php
  2. /**
  3.  * Sono qui presenti numerose funzioni per la gestione del registro di VFront.
  4.  * Il file viene incluso da /admin/gestione_tabelle_gruppi.php
  5.  * 
  6.  * @desc Libreria di funzioni per la gestione del registro di VFront
  7.  * @package VFront
  8.  * @subpackage Administration
  9.  * @author M.Marcello Verona
  10.  * @copyright 2007 M.Marcello Verona
  11.  * @version 0.90
  12.  * @see gestione_tabelle_gruppi.php
  13.  * @license http://www.gnu.org/licenses/gpl.html GNU Public License
  14.  */
  15.  
  16.  
  17.  
  18. require_once("../inc/conn.php");
  19. require_once("../inc/func.comuni.php");
  20. require_once("../inc/func.frontend.php");
  21.  
  22.  
  23.     
  24.     
  25.  
  26.  
  27. /**
  28.  * Funzione di inserimento di una tabella nel registro.
  29.  * Questa funzione scrive nelle tabelle registro_tab e registro_col
  30.  * informazioni su una tabella del database, recuperate a sua volta dall'information_schema
  31.  *
  32.  * @param string $val Nome della tabella
  33.  * @param int $gid Identificativo del gruppo
  34.  * @return void 
  35.  */
  36. function inserisci_registro($val,$gid=0){
  37.     
  38.     global $link,$db1;
  39.     
  40.         // Verifica che non ci siano già record per questo gruppo
  41.         $test_gid=vmsql_test_id($link,"gid",$gid,"{$db1['frontend']}.registro_tab""AND table_name='{$val['table_name']}'");
  42.         
  43.         if($test_gid){
  44.             return null;
  45.         }
  46.     
  47.     
  48.         $val str_replace("'","\\'",$val);
  49.         
  50.         $gid= (int) $gid;
  51.         
  52.         $sql_tab_dett"INSERT INTO {$db1['frontend']}.registro_tab (
  53.                 gid,
  54.                 table_name
  55.                 table_type
  56.                 commento)
  57.                 VALUES 
  58.                 (".$gid.",".
  59.                 "'".$val['table_name']."',"
  60.                 "'".$val['table_type']."',"
  61.                 "'".$val['table_comment']."')";
  62.                 
  63.         $q_dett=vmsql_query($sql_tab_dett,$link,true);
  64.     
  65.         $ID_TABLE vmsql_insert_id($link,"{$db1['frontend']}.registro_tab",'id_table');
  66.     
  67.     
  68.     
  69.     
  70.     #########################
  71.     #
  72.     #    Dettagli di tabella
  73.     #
  74.     
  75.     if($db1['dbtype']=='postgres'){
  76.         
  77.         $sql="SELECT 
  78.             column_name,
  79.             ordinal_position,
  80.         column_default,
  81.         is_nullable,
  82.         udt_name as column_type,
  83.         character_maximum_length,
  84.         data_type,
  85.         CASE WHEN column_default LIKE 'nextval(%' THEN 'auto_incrementELSE '' END AS extra,
  86.         col_description(a.attrelida.attnum::integerAS column_comment
  87.         
  88.         
  89.         FROM information_schema.columns ipg_attribute apg_class cpg_namespace ns
  90.         
  91.         WHERE i.table_schema='{$db1['dbname']}'
  92.         
  93.         AND i.table_name='".$val['table_name']."'
  94.         
  95.         AND c.relname=i.table_name
  96.         AND ns.oid=c.relnamespace
  97.         AND a.attrelid = c.oid
  98.         AND a.attname = i.column_name
  99.         
  100.         ORDER BY table_name ASC, ordinal_position ASC ";
  101.     
  102.     }
  103.     else{
  104.         
  105.         $sql="SELECT 
  106.         column_name,
  107.         ordinal_position,
  108.         column_default,
  109.         is_nullable,
  110.         column_type,
  111.         character_maximum_length,
  112.         data_type,
  113.         extra,
  114.         SUBSTRING_INDEX(column_comment,'InnoDB',1) as column_comment
  115.         
  116.         FROM information_schema.columns
  117.         
  118.         WHERE table_schema='{$db1['dbname']}'
  119.         
  120.         AND table_name='".$val['table_name']."'
  121.         
  122.         ORDER BY table_name ASC, ordinal_position ASC ";
  123.     }
  124.     
  125.     
  126.     $q1=vmsql_query($sql,$link,true);
  127.     
  128.     $matrice1 vmsql_fetch_assoc_all($q1);
  129.     
  130.     //print_r($matrice1);
  131.     
  132.     foreach ($matrice1 as $k=>$valori){
  133.         
  134.         $valori str_replace("'","\\'",$valori);
  135.         
  136.         $gid = (int) $gid;
  137.         
  138.         $sql2"INSERT INTO {$db1['frontend']}.registro_col (
  139.                 gid,
  140.                 id_table
  141.                 column_name,
  142.                 ordinal_position,
  143.                 column_default,
  144.                 is_nullable,
  145.                 column_type,
  146.                 character_maximum_length,
  147.                 data_type,
  148.                 extra,
  149.                 commento)
  150.                 VALUES 
  151.                 (".$gid.",".
  152.                 intval($ID_TABLE).","
  153.                 "'".$valori['column_name']."',".
  154.                 intval($valori['ordinal_position']).",".
  155.                 "'".$valori['column_default']."',".
  156.                 "'".$valori['is_nullable']."',".
  157.                 "'".$valori['column_type']."',".
  158.                 intval($valori['character_maximum_length']).",".
  159.                 "'".$valori['data_type']."',".
  160.                 "'".$valori['extra']."',".
  161.                 "'".$valori['column_comment']."')";
  162.                 
  163.         $q2=vmsql_query($sql2,$link,true);
  164.     }
  165. }
  166.     
  167.  
  168.  
  169.  
  170.  
  171. /**
  172.  * Funzione di clonazione registro.
  173.  * Prende le impostazioni del gruppo $gid_old (il gruppo default è 0)
  174.  * e le applica al nuovo gruppo $gid_new
  175.  *
  176.  * @param int $gid_new ID del nuovo gruppo
  177.  * @param int $gid_old ID del gruppo origine
  178.  * @return bool Esito dell'operazione
  179.  */
  180. function clona_settaggio($gid_new,$gid_old=0,$solo_tabella=false){
  181.  
  182.     global $link,$db1;
  183.     
  184.     // Pulisco le tabelle temporanee
  185.         
  186.     vmsql_begin($link);
  187.  
  188.     
  189.     // Se è una sola tabella da copiare...
  190.     $vincolo_sola_tabella=($solo_tabella>0)" AND id_table=".intval($solo_tabella)." " "";
  191.     
  192.     
  193.     
  194.     // prendo i dati tabella
  195.     
  196.     $sql_tab1 "SELECT id_table,
  197.                 visibile,
  198.                 in_insert,
  199.                 in_update,
  200.                 in_delete,
  201.                 in_export,
  202.                 data_modifica,
  203.                 orderby,
  204.                 table_name,
  205.                 table_type,
  206.                 commento,
  207.                 orderby_sort,
  208.                 permetti_allegati,
  209.                 permetti_allegati_ins,
  210.                 permetti_allegati_del,
  211.                 permetti_link,
  212.                 permetti_link_ins,
  213.                 permetti_link_del,
  214.                 view_pk,
  215.                 fonte_al
  216.  
  217.  
  218.                 FROM {$db1['frontend']}.registro_tab 
  219.                 WHERE gid=".intval($gid_old)."
  220.                 $vincolo_sola_tabella
  221.                 ORDER BY table_name";
  222.     
  223.     $q_tab1=vmsql_query($sql_tab1,$link);
  224.     
  225.     
  226.     while($RS1=vmsql_fetch_assoc($q_tab1)){
  227.     
  228.  
  229.         $RS1=pulisci_dom($RS1);
  230.         
  231.         // Preparo l'inserimento del master
  232.         $sql_ins1=sprintf("INSERT INTO {$db1['frontend']}.registro_tab (gid,visibile,in_insert,in_duplica,in_update,in_delete,in_export,
  233.                                                               data_modifica,orderby,table_name,table_type,commento,orderby_sort,
  234.                                                               permetti_allegati,permetti_allegati_ins,permetti_allegati_del,permetti_link,permetti_link_ins,permetti_link_del,
  235.                                                               view_pk,fonte_al)
  236.                         VALUES (%d,%d,%d,%d,%d,%d,%d,
  237.                                 %d,'%s','%s','%s','%s','%s',
  238.                                 %d,%d,%d,%d,%d,%d,'%s','%s')",
  239.                         $gid_new,
  240.                         $RS1['visibile'],
  241.                         $RS1['in_insert'],
  242.                         $RS1['in_duplica'],
  243.                         $RS1['in_update'],
  244.                         $RS1['in_delete'],
  245.                         $RS1['in_export'],
  246.                         $RS1['data_modifica'],
  247.                         $RS1['orderby'],
  248.                         $RS1['table_name'],
  249.                         $RS1['table_type'],
  250.                         $RS1['commento'],
  251.                         $RS1['orderby_sort'],
  252.                         $RS1['permetti_allegati'],
  253.                         $RS1['permetti_allegati_ins'],
  254.                         $RS1['permetti_allegati_del'],
  255.                         $RS1['permetti_link'],
  256.                         $RS1['permetti_link_ins'],
  257.                         $RS1['permetti_link_del'],
  258.                         $RS1['view_pk'],
  259.                         $RS1['fonte_al']
  260.                         
  261.                         );
  262.                         
  263.         $q_ins1=vmsql_query($sql_ins1,$link);
  264.                         
  265.         $ID_NEW_TABLE vmsql_insert_id($link,"{$db1['frontend']}.registro_tab",'id_table');
  266.                 
  267.  
  268.         
  269.         
  270.         // Prendi i valori del vecchio gid
  271.         $sql_col1 "SELECT column_name,
  272.                             ordinal_position,
  273.                             column_default,
  274.                             is_nullable,
  275.                             column_type,
  276.                             character_maximum_length,
  277.                             data_type,
  278.                             extra,
  279.                             in_tipo,
  280.                             in_default,
  281.                             in_visibile,
  282.                             in_richiesto,
  283.                             in_search,
  284.                             in_suggest,
  285.                             in_table,
  286.                             in_ordine,
  287.                             jstest,
  288.                             commento
  289.                             
  290.                     FROM {$db1['frontend']}.registro_col
  291.                     WHERE gid=".intval($gid_old)."
  292.                     AND id_table=".intval($RS1['id_table'])."
  293.                     ORDER BY column_name, ordinal_position
  294.                     
  295.         ";
  296.         
  297.         $q_col1 vmsql_query($sql_col1,$link);
  298.         
  299.         while($RS2=vmsql_fetch_assoc($q_col1)){
  300.             
  301.             $RS2=pulisci_dom($RS2);
  302.             
  303.             // Inserisci i valori duplicati
  304.             
  305.                 // Preparo l'inserimento del master
  306.         $sql_ins1=sprintf("INSERT INTO {$db1['frontend']}.registro_col 
  307.                             (gidid_tablecolumn_name,
  308.                             ordinal_positioncolumn_defaultis_nullable,
  309.                             column_typecharacter_maximum_lengthdata_type,
  310.                             extrain_tipoin_default,
  311.                             in_visibilein_richiestoin_search,
  312.                             in_suggestin_tablein_ordinejstestcommento)
  313.                         VALUES (%d,%d,'%s',
  314.                         %d,'%s',%d,
  315.                         '%s',%d,'%s',
  316.                         '%s',%d,'%s',
  317.                         %d,%d,%d,
  318.                         %d,%d,%d,'%s','%s')",
  319.                         $gid_new,
  320.                         $ID_NEW_TABLE,
  321.                         $RS2['column_name'],
  322.                         $RS2['ordinal_position'],
  323.                         $RS2['column_default'],
  324.                         $RS2['is_nullable'],
  325.                         $RS2['column_type'],
  326.                         $RS2['character_maximum_length'],
  327.                         $RS2['data_type'],
  328.                         $RS2['extra'],
  329.                         $RS2['in_tipo'],
  330.                         $RS2['in_default'],
  331.                         $RS2['in_visibile'],
  332.                         $RS2['in_richiesto'],
  333.                         $RS2['in_search'],
  334.                         $RS2['in_suggest'],
  335.                         $RS2['in_table'],
  336.                         $RS2['in_ordine'],
  337.                         $RS2['jstest'],
  338.                         $RS2['commento']);
  339.                         
  340.             $q_ins2 vmsql_query($sql_ins1,$link);
  341.                         
  342.         }
  343.                         
  344.                         
  345.                         
  346.                         
  347.     }
  348.     
  349.     if(isset($GLOBALS['VMSQL_ERROR'])){
  350.         
  351.         vmsql_rollback($link);
  352.         return false;
  353.     }
  354.         
  355.     else {
  356.         vmsql_commit($link);
  357.         return true;
  358.     }
  359.         
  360.     
  361. }
  362.  
  363.  
  364. /**
  365.  * Dato un gid crea un registro tabelle per quel gruppo partendo da zero.
  366.  * Come inizializza registro ma non crea il record nel gruppo.
  367.  * Restituisce vero|falso
  368.  * @param int $gid Id del gruppo
  369.  * @return bool Esito dell'operazione
  370.  */
  371. function genera_registro_vuoto($gid){
  372.     
  373.     global $link$db1;
  374.     
  375.         // Inizio
  376.             vmsql_begin($link);
  377.     
  378.             /*// Verifico l'esistenza del gruppo $gid
  379.             $test_gid_0 = vmsql_test_id($link,'gid',$gid,'{$db1['frontend']}.gruppo');
  380.             
  381.             // se c'è manda errore
  382.             if($test_gid_0){
  383.                 
  384.                 openErrorGenerico("Attenzione! Esiste già un gid con questo valore");
  385.             }
  386.             */
  387.             
  388.             
  389.             ########################
  390.             #
  391.             # Def tabelle
  392.             #
  393.             
  394.             if($db1['dbtype']=='postgres'){
  395.             
  396.                 $sql_tab="SELECT table_nametable_typeobj_description(c.oid, 'pg_class'::nameAS comment 
  397.                           FROM information_schema.tables , pg_catalog.pg_class AS c
  398.                           WHERE TABLE_SCHEMA='{$db1['dbname']}'
  399.                           AND (TABLE_TYPE='BASE TABLEOR TABLE_TYPE='VIEW')
  400.                           AND  table_name=c.relname
  401.                           ORDER BY TABLE_NAME ASC
  402.                 ";
  403.             
  404.             }
  405.             else{
  406.                 
  407.             $sql_tab="SELECT table_nametable_typeSUBSTRING_INDEX(table_comment,'InnoDB',1) as comment
  408.                       FROM information_schema.tables
  409.                       WHERE TABLE_SCHEMA='{$db1['dbname']}'
  410.                       AND (TABLE_TYPE='BASE TABLEOR TABLE_TYPE='VIEW')
  411.                       
  412.                       ORDER BY TABLE_NAME ASC
  413.             ";
  414.                 
  415.             }
  416.             
  417.             
  418.             $q0=vmsql_query($sql_tab,$link);
  419.             
  420.             $matrice0 vmsql_fetch_assoc_all($q0);
  421.             
  422.             foreach ($matrice0 as $k=>$val){
  423.                     
  424.                 inserisci_registro($val,$gid);
  425.             }    
  426.             
  427.             if(isset($GLOBALS['VMSQL_ERROR'])){
  428.                 
  429.                 vmsql_rollback($link);
  430.                 return false;
  431.             }
  432.             else{
  433.                 
  434.                 vmsql_commit($link);
  435.                 return true;
  436.             }
  437.     
  438. }
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445. /**
  446.  * Inizializzazione del registro.
  447.  * Viene creato il gid 0 e la prima copia del registro e viene eliminato il gruppo -1
  448.  * creato nell'installazione.
  449.  * Restituisce vero se l'operazione va a buon fine, falso se fallisce.
  450.  * @return bool Esito dell'operazione
  451.  */
  452.     
  453.     global $link$db1;
  454.     
  455.         // Inizio
  456.             vmsql_begin($link);
  457.     
  458.             
  459.             // Verifico l'esistenza del gruppo 0
  460.             
  461.             $test_gid_0 vmsql_test_id($link,'gid','0',"{$db1['frontend']}.gruppo");
  462.             
  463.             // se non c'è lo creo
  464.             if(!$test_gid_0){
  465.                 $q_gruppo_0 vmsql_query("INSERT INTO {$db1['frontend']}.gruppo (gid,nome_gruppo,descrizione_gruppo)
  466.                                              VALUES(0,'default','gruppo di default')",$link);
  467.             }
  468.             
  469.             
  470.             
  471.             ########################
  472.             #
  473.             # Def tabelle
  474.             #
  475.             
  476.             if($db1['dbtype']=='postgres'){
  477.                 
  478.                 $sql_tab="SELECT table_nametable_type , obj_description(c.oid, 'pg_class'::nameAS comment 
  479.                       FROM information_schema.tablespg_catalog.pg_class AS c
  480.                       WHERE table_schema='{$db1['dbname']}'
  481.                       AND  table_name=c.relname
  482.                       AND (table_type='BASE TABLEOR table_type='VIEW')
  483.                       ORDER BY table_name ASC
  484.                 ";
  485.                 
  486.             }else{
  487.                 
  488.                 $sql_tab="SELECT table_nameSUBSTRING_INDEX(table_comment,'InnoDB',1) as commenttable_type
  489.                       FROM information_schema.tables
  490.                       WHERE TABLE_SCHEMA='{$db1['dbname']}'
  491.                       AND (TABLE_TYPE='BASE TABLEOR TABLE_TYPE='VIEW')
  492.                       ORDER BY TABLE_NAME ASC
  493.                 ";
  494.                 
  495.             }
  496.             
  497.             
  498.             
  499.             
  500.             $q0=vmsql_query($sql_tab,$link);
  501.             
  502.             $matrice0 vmsql_fetch_assoc_all($q0);
  503.             
  504.             foreach ($matrice0 as $k=>$val){
  505.                     
  506.                 inserisci_registro($val,0);
  507.             }    
  508.             
  509.             if(isset($GLOBALS['VMSQL_ERROR'])){
  510.                 
  511.                 vmsql_rollback($link);
  512.                 return false;
  513.             }
  514.             else{
  515.                 
  516.                 // metti l'utente 1 (admin) nel gruppo 0
  517.                 $q_ut=vmsql_query("UPDATE {$db1['frontend']}.utente SET gid=0 WHERE id_utente=1",$link);
  518.                 
  519.                 // aggiorna la sessione
  520.                 $_SESSION['user']['gid']=0;
  521.                 $_SESSION['gid']=0;
  522.                 
  523.                 // Elimina il gruppo temporaneo -1
  524.                 $q_del_g=vmsql_query("DELETE FROM {$db1['frontend']}.gruppo WHERE gid=-1 ",$link);
  525.                 
  526.                 vmsql_commit($link);
  527.                 
  528.                 return true;
  529.             }
  530.     
  531. }
  532.  
  533.  
  534. /**
  535.  * Funzione di aggiornamento dei registri di VFront.
  536.  * Vengono confrontate le tabelle attualmente presenti in registro e quelle presenti in information_schema,
  537.  * inserite nel registro quelle nuove e cancellate quelle obsolete
  538.  *
  539.  */
  540. function aggiorna_registri(){
  541.     
  542.     global $link$db1;
  543.     
  544.     
  545.             
  546.     
  547.             if($db1['dbtype']=="postgres"){
  548.                 
  549.                 $sql_nuove="SELECT t.table_namet.table_type , obj_description(c.oid, 'pg_class'::nameAS comment
  550.                       FROM information_schema.tables t
  551.                       INNER JOIN pg_catalog.pg_class AS c ON t.table_name=c.relname
  552.                       LEFT OUTER JOIN  {$db1['frontend']}.registro_tab r ON t.table_name=r.table_name
  553.                       WHERE t.table_schema='{$db1['dbname']}'
  554.                       AND (t.table_type='BASE TABLEOR t.table_type='VIEW')
  555.                       AND t.table_name NOT IN (SELECT r.table_name FROM {$db1['frontend']}.registro_tab r)
  556.                       ";
  557.                 
  558.             }
  559.             else{
  560.                 
  561.                 $sql_nuove="SELECT t.table_name , SUBSTRING_INDEX(t.table_comment,'InnoDB',1) as comment
  562.                     FROM information_schema.tables t 
  563.                     LEFT OUTER JOIN  {$db1['frontend']}.registro_tab r ON t.table_name=r.table_name
  564.                     WHERE t.table_schema='{$db1['dbname']}'
  565.                     AND (t.table_type='BASE TABLEOR t.table_type='VIEW')
  566.                     AND t.table_name NOT IN (SELECT r.table_name FROM {$db1['frontend']}.registro_tab r)";
  567.             }
  568.     
  569.             // Prendi tabelle attualmente esistenti non presenti nel registro:
  570.             $q_nuove=vmsql_query($sql_nuove,$link);
  571.                     
  572.             
  573.                     
  574.             $mat_nuove_tabelle=vmsql_fetch_assoc_all($q_nuove);
  575.             
  576.             if(is_array($mat_nuove_tabelle)){
  577.             
  578.                 foreach($mat_nuove_tabelle as $k=>$val){
  579.                     
  580.                     inserisci_registro($val);
  581.                 }
  582.             }
  583.             
  584.             // Elimina le tabelle presenti  nel registro e non più nel database
  585.             
  586.             vmsql_begin($link);
  587.             
  588.             $q_vecchie=vmsql_query(
  589.                     "SELECT r.id_tabler.table_name
  590.                     FROM {$db1['frontend']}.registro_tab r 
  591.                     WHERE r.table_name NOT IN (
  592.                         SELECT t.TABLE_NAME FROM information_schema.tables t 
  593.                         WHERE t.TABLE_SCHEMA='{$db1['dbname']}AND (t.TABLE_TYPE='BASE TABLEOR t.TABLE_TYPE='VIEW')",
  594.                     $link);
  595.                     
  596.             while($RS_del=vmsql_fetch_row($q_vecchie)){
  597.                     
  598.                 // Elimina da registro_col
  599.                 $q_del_col vmsql_query("DELETE FROM {$db1['frontend']}.registro_col WHERE id_table=".intval($RS_del[0]),$link);
  600.                 
  601.                 // Elimina da registro_tab
  602.                 $q_del_col vmsql_query("DELETE FROM {$db1['frontend']}.registro_tab WHERE id_table=".intval($RS_del[0]),$link);
  603.                 
  604.             }
  605.             
  606.             if(isset($GLOBALS['VMSQL_ERROR']&& $GLOBALS['VMSQL_ERROR']===true){
  607.                 vmsql_rollback($link);
  608.             }
  609.             else{
  610.                 vmsql_commit($link);
  611.             }
  612.             
  613.             
  614.         
  615.     
  616.     // -- fine caso aggiorna
  617. }
  618.  
  619.  
  620.  
  621.  
  622. /**
  623.  * Inizializzazione (creazione) della sottomaschera.
  624.  * Viene inserita in registro la nuova sottomaschera e le sue caratteristiche di dettaglio.
  625.  *
  626.  * @param int $oid_parent ID della tabella padre (la maschera di cui questa sarà sottomaschera)
  627.  * @param string $tabella_sub Tabella che svolgerà il ruolo di sottomaschera
  628.  * @return bool Esito dell'operazione
  629.  */
  630. function inizializza_sottomaschera($oid_parent,$tabella_sub){
  631.     
  632.     global $db1$link;
  633.     
  634.     vmsql_begin($link);
  635.     
  636.     // Inserimento dati minimi del master
  637.     $sql_ins_sub "INSERT INTO ".$db1['frontend'].".registro_submask (id_table,nome_tabella
  638.                         VALUES ('$oid_parent','$tabella_sub')";
  639.         
  640.     $q_ins_sub=vmsql_query($sql_ins_sub,$link);
  641.     
  642.     if(vmsql_affected_rows($link,$q_ins_sub)==1){
  643.         
  644.         // inserimento del dettaglio
  645.         $id_submask vmsql_insert_id($link$db1['frontend'].".registro_submask" ,'id_submask');
  646.         
  647.         
  648.             // prendi info della tabella
  649.         
  650.             #########################
  651.             #
  652.             #    Dettagli di tabella
  653.             #
  654.             
  655.             
  656.             //POSTGRES
  657.             if($db1['dbtype']=='postgres'){
  658.                 
  659.                 
  660.                 $sql="SELECT 
  661.                 column_name,
  662.                 ordinal_position,
  663.                 column_default,
  664.                 is_nullable,
  665.                 character_maximum_length,
  666.                 data_type,
  667.                 col_description(a.attrelida.attnum::integerAS column_comment
  668.                 
  669.                 FROM information_schema.columns ipg_attribute apg_class cpg_namespace ns
  670.                 
  671.                 WHERE table_schema='{$db1['dbname']}'
  672.                 
  673.                 AND table_name='".$tabella_sub."'
  674.                 
  675.                 AND c.relname=i.table_name
  676.                 AND ns.oid=c.relnamespace
  677.                 AND a.attrelid = c.oid
  678.                 AND a.attname = i.column_name
  679.                 
  680.                 ORDER BY table_name ASC, ordinal_position ASC ";
  681.                 
  682.             }
  683.             
  684.             //MYSQL
  685.             else{
  686.                 
  687.             $sql="SELECT 
  688.                 column_name,
  689.                 ordinal_position,
  690.             column_default,
  691.             is_nullable,
  692.             column_type,
  693.             character_maximum_length,
  694.             data_type,
  695.             SUBSTRING_INDEX(column_comment,'InnoDB',1) as column_comment
  696.             
  697.             FROM information_schema.columns
  698.             
  699.             WHERE table_schema='{$db1['dbname']}'
  700.             
  701.             AND table_name='".$tabella_sub."'
  702.             
  703.             ORDER BY table_name ASC, ordinal_position ASC ";
  704.             
  705.             }
  706.             
  707.             
  708.             
  709.             
  710.             $q1=vmsql_query($sql,$link,true);
  711.             
  712.             $matrice1 vmsql_fetch_assoc_all($q1);
  713.             
  714.             //print_r($matrice1);
  715.             
  716.             foreach ($matrice1 as $k=>$valori){
  717.                 
  718.                 $valori str_replace("'","\\'",$valori);
  719.                 
  720.                 $gid = (int) $gid;
  721.                 
  722.                 $sql2"INSERT INTO {$db1['frontend']}.registro_submask_col (
  723.                         id_submask
  724.                         column_name
  725.                         ordinal_position
  726.                         column_default
  727.                         is_nullable
  728.                         column_type
  729.                         character_maximum_length
  730.                         data_type
  731.                         extra
  732.                         commento)
  733.                         VALUES 
  734.                         (".intval($id_submask).","
  735.                         "'".$valori['column_name']."',".
  736.                         "'".$valori['ordinal_position']."',".
  737.                         "'".$valori['column_default']."',".
  738.                         "'".$valori['is_nullable']."',".
  739.                         "'".$valori['column_type']."',".
  740.                         intval($valori['character_maximum_length']).",".
  741.                         "'".$valori['data_type']."',".
  742.                         "'".$valori['extra']."',".
  743.                         "'".$valori['column_comment']."')";
  744.                         
  745.                 $q2=vmsql_query($sql2,$link,true);
  746.             }
  747.             
  748.             
  749.         
  750.     }
  751.     else{
  752.         vmsql_rollback($link);
  753.         return false;
  754.     }
  755.     
  756.     
  757.     vmsql_commit($link);
  758.     
  759.     return true;
  760. }
  761.  
  762.  
  763.  
  764.  
  765.  
  766. /**
  767.  * Funzione di clonazione delle sottomaschere.
  768.  * Questa è un'utiliti per copiare una sottomaschera di un gruppo per un altro gruppo
  769.  * 
  770.  * @param int $gid_new ID del gruppo destinazione
  771.  * @param int $gid_old ID del gruppo origine
  772.  * @param bool $solo_id_table 
  773.  * @return bool Esito dell'operazione
  774.  */
  775. function clona_sottomaschere($gid_new,$gid_old,$solo_id_table=0){
  776.     
  777.     global $link$db1;
  778.     
  779.     
  780.         
  781.     $clausola_id_table ($solo_id_table>0"AND t.id_table=".intval($solo_id_table"";
  782.     
  783.     // prendi le tabelle che hanno sottomaschere da clonare
  784.     
  785.     $q0 =vmsql_query("SELECT s.id_submask, s.id_table ,t.table_name
  786.                     FROM ".$db1['frontend'].".registro_submask s, ".$db1['frontend'].".registro_tab t
  787.                     WHERE t.gid=$gid_old
  788.                     AND s.id_table=t.id_table
  789.                     $clausola_id_table
  790.                     ORDER BY t.table_name",$link);
  791.     
  792.     if(vmsql_num_rows($q0)==0){
  793.         
  794.         return 0// si ferma qui.
  795.     }
  796.             
  797.     list($old_id_submask,$old_id_table$old_table_name=vmsql_fetch_row_all($q0,true);
  798.     
  799.     // ora prende l'array delle tabelle del nuovo gid
  800.     
  801.     for($j=0;$j<count($old_table_name);$j++){
  802.         
  803.         $new_id_table[name2oid($old_table_name[$j],$gid_new);
  804.         
  805.     }
  806.     
  807.     
  808.     # CICLO CLONAZIONE SUBMASK MASTER
  809.     
  810.     # INIZIO
  811.     vmsql_begin($link);
  812.     
  813.     
  814.     for($i=0;$i<count($old_id_submask);$i++){
  815.         
  816.         // PRENDI UNA SOTTOMASCHERA
  817.         
  818.         $q1 =vmsql_query("SELECT id_submask,
  819.                                 id_table,
  820.                                 sub_select,
  821.                                 sub_insert,
  822.                                 sub_update,
  823.                                 sub_delete,
  824.                                 nome_tabella,
  825.                                 nome_frontend,
  826.                                 campo_pk_parent,
  827.                                 campo_fk_sub,
  828.                                 orderby_sub,
  829.                                 orderby_sub_sort,
  830.                                 data_modifica,
  831.                                 max_records,
  832.                                 tipo_vista
  833.  
  834.                     FROM ".$db1['frontend'].".registro_submask
  835.                     WHERE id_submask=".$old_id_submask[$i]."
  836.                     ",$link);
  837.         
  838.         $RS1=vmsql_fetch_assoc($q1);
  839.         
  840.         
  841.         // ---> PREPARA LA QUERY DI INSERIMENTO
  842.         $sql_ins1 =sprintf("
  843.         INSERT INTO ".$db1['frontend'].".registro_submask
  844.         
  845.         (id_table,    sub_select,    sub_insert,    sub_update,    sub_delete,    nome_tabella,nome_frontend,
  846.         campo_pk_parent,campo_fk_sub, orderby_sub, orderby_sub_sort, data_modifica, max_records,tipo_vista)
  847.         
  848.         VALUES (%d,%d,%d,%d,%d,'%s','%s',
  849.                 '%s','%s','%s','%s',%d,%d,'%s')",
  850.             $new_id_table[$i],
  851.             $RS1['sub_select'],
  852.             $RS1['sub_insert'],
  853.             $RS1['sub_update'],
  854.             $RS1['sub_delete'],
  855.             $RS1['nome_tabella'],
  856.             addslashes($RS1['nome_frontend']),
  857.             $RS1['campo_pk_parent'],
  858.             $RS1['campo_fk_sub'],
  859.             $RS1['orderby_sub'],
  860.             $RS1['orderby_sub_sort'],
  861.             time(),
  862.             $RS1['max_records'],
  863.             $RS1['tipo_vista']
  864.             );
  865.             
  866.         // INSERISCI IL MASTER 
  867.         
  868.         $q_ins1 vmsql_query($sql_ins1,$link);
  869.         
  870.         if(vmsql_affected_rows($link,$q_ins1)!=1){
  871.             
  872.             vmsql_rollback($link);
  873.             openErrorGenerico("Errore nella clonazione delle sottomaschere",true);
  874.         }
  875.         
  876.         
  877.             // recupera l'id inserito.
  878.             
  879.             $new_id_submask vmsql_insert_id($link$db1['frontend'].".registro_submask",'id_submask');
  880.             
  881.             // REcupera i dati del dettaglio
  882.             
  883.             $q2 =vmsql_query("SELECT *
  884.                     FROM ".$db1['frontend'].".registro_submask_col
  885.                     WHERE id_submask=".$old_id_submask[$i]."
  886.                     ",$link);
  887.         
  888.             while($RS2=vmsql_fetch_assoc($q2)){
  889.                 
  890.                 
  891.                 // Prepara la query di inserimento
  892.                 
  893.                 $sql_ins2=sprintf("INSERT INTO ".$db1['frontend'].".registro_submask_col
  894.                     
  895.                     (id_submask,  column_name,    ordinal_position, column_default, is_nullable,
  896.                     column_type, character_maximum_length,    data_type,    extra, in_tipo,
  897.                     in_default,    in_visibile, in_richiesto,    commento)
  898.                     
  899.                     VALUES
  900.                     
  901.                     (%d,'%s',%d,'%s','%s',
  902.                     '%s','%s','%s','%s','%s',
  903.                     '%s',%d,%d,'%s')
  904.                     ",
  905.                 $new_id_submask,
  906.                 $RS2['column_name'],
  907.                 $RS2['ordinal_position'],
  908.                 $RS2['column_default'],
  909.                 $RS2['is_nullable'],
  910.                 $RS2['column_type'],
  911.                 $RS2['character_maximum_length'],
  912.                 $RS2['data_type'],
  913.                 $RS2['extra'],
  914.                 $RS2['in_tipo'],
  915.                 addslashes($RS2['in_default']),
  916.                 $RS2['in_visibile'],
  917.                 $RS2['in_richiesto'],
  918.                 addslashes($RS2['commento']));
  919.                 
  920.                 $q_ins2=vmsql_query($sql_ins2,$link);
  921.                 
  922.                 if(vmsql_affected_rows($link,$q_ins2)!=1){
  923.             
  924.                     vmsql_rollback($link);
  925.                     openErrorGenerico("Errore nella clonazione delle sottomaschere",true);
  926.                 }
  927.  
  928.  
  929.                 
  930.             }
  931.                 
  932.  
  933.         
  934.         
  935.     }
  936.     
  937.     vmsql_commit($link);
  938.     
  939.     return true;
  940.     
  941.     
  942. }
  943.  
  944.  
  945.  
  946. /**
  947.  * Funzione di manutenzione dei registri.
  948.  * Copia le sottomaschere per le viste
  949.  *
  950.  * @param int $id_vista_new 
  951.  * @param int $id_tabella_old 
  952.  * @return bool 
  953.  */
  954. function copia_sottomaschere_viste($id_vista_new,$id_tabella_old){
  955.     
  956.     global $link$db1;
  957.     
  958.     
  959.  
  960.     # CICLO CLONAZIONE SUBMASK MASTER
  961.     
  962.     # INIZIO
  963.     vmsql_begin($link);
  964.     
  965.     
  966.     
  967.     
  968.         // PRENDI UNA SOTTOMASCHERA
  969.         
  970.         $q1 =vmsql_query("SELECT id_submask,
  971.                                 id_table,
  972.                                 sub_select,
  973.                                 sub_insert,
  974.                                 sub_update,
  975.                                 sub_delete,
  976.                                 nome_tabella,
  977.                                 nome_frontend,
  978.                                 campo_pk_parent,
  979.                                 campo_fk_sub,
  980.                                 orderby_sub,
  981.                                 orderby_sub_sort,
  982.                                 data_modifica,
  983.                                 max_records,
  984.                                 tipo_vista
  985.  
  986.                     FROM ".$db1['frontend'].".registro_submask
  987.                     WHERE id_table=$id_tabella_old
  988.                     
  989.                     ",$link);
  990.         
  991.         
  992.         
  993.         while($RS1=vmsql_fetch_assoc($q1)){
  994.         
  995.         
  996.         
  997.             
  998.             
  999.             // ---> PREPARA LA QUERY DI INSERIMENTO
  1000.             $sql_ins1 =sprintf("
  1001.             INSERT INTO ".$db1['frontend'].".registro_submask
  1002.             
  1003.             (id_table,    sub_select,    sub_insert,    sub_update,    sub_delete,    nome_tabella,nome_frontend,
  1004.             campo_pk_parent,campo_fk_sub, orderby_sub, orderby_sub_sort, data_modifica, max_records,tipo_vista)
  1005.             
  1006.             VALUES (%d,%d,%d,%d,%d,'%s','%s',
  1007.                     '%s','%s','%s','%s',%d,%d,'%s')",
  1008.                 $id_vista_new,
  1009.                 $RS1['sub_select'],
  1010.                 $RS1['sub_insert'],
  1011.                 $RS1['sub_update'],
  1012.                 $RS1['sub_delete'],
  1013.                 $RS1['nome_tabella'],
  1014.                 addslashes($RS1['nome_frontend']),
  1015.                 $RS1['campo_pk_parent'],
  1016.                 $RS1['campo_fk_sub'],
  1017.                 $RS1['orderby_sub'],
  1018.                 $RS1['orderby_sub_sort'],
  1019.                 time(),
  1020.                 $RS1['max_records'],
  1021.                 $RS1['tipo_vista']
  1022.                 );
  1023.                 
  1024.             // INSERISCI IL MASTER 
  1025.             
  1026.             $q_ins1 vmsql_query($sql_ins1,$link);
  1027.             
  1028.             if(vmsql_affected_rows($link,$q_ins1)!=1){
  1029.                 
  1030.                 vmsql_rollback($link);
  1031.                 openErrorGenerico("Errore nella clonazione delle sottomaschere",true);
  1032.             }
  1033.             
  1034.             
  1035.                 // recupera l'id inserito.
  1036.                 
  1037.                 $new_id_submask vmsql_insert_id($link,$db1['frontend'].".registro_submask""id_submask");
  1038.                 
  1039.                 // REcupera i dati del dettaglio
  1040.                 
  1041.                 $q2 =vmsql_query("SELECT *
  1042.                         FROM ".$db1['frontend'].".registro_submask_col
  1043.                         WHERE id_submask=".$RS1['id_submask'],$link);
  1044.             
  1045.                 while($RS2=vmsql_fetch_assoc($q2)){
  1046.                     
  1047.                     
  1048.                     // Prepara la query di inserimento
  1049.                     
  1050.                     $sql_ins2=sprintf("INSERT INTO ".$db1['frontend'].".registro_submask_col
  1051.                         
  1052.                         (id_submask,  column_name,    ordinal_position, column_default, is_nullable,
  1053.                         column_type, character_maximum_length,    data_type,    extra, in_tipo,
  1054.                         in_default,    in_visibile, in_richiesto,    commento)
  1055.                         
  1056.                         VALUES
  1057.                         
  1058.                         (%d,'%s',%d,'%s','%s',
  1059.                         '%s','%s','%s','%s','%s',
  1060.                         '%s',%d,%d,'%s')
  1061.                         ",
  1062.                     $new_id_submask,
  1063.                     $RS2['column_name'],
  1064.                     $RS2['ordinal_position'],
  1065.                     $RS2['column_default'],
  1066.                     $RS2['is_nullable'],
  1067.                     $RS2['column_type'],
  1068.                     $RS2['character_maximum_length'],
  1069.                     $RS2['data_type'],
  1070.                     $RS2['extra'],
  1071.                     $RS2['in_tipo'],
  1072.                     addslashes($RS2['in_default']),
  1073.                     $RS2['in_visibile'],
  1074.                     $RS2['in_richiesto'],
  1075.                     addslashes($RS2['commento']));
  1076.                     
  1077.                     $q_ins2=vmsql_query($sql_ins2,$link);
  1078.                     
  1079.                     if(vmsql_affected_rows($link,$q_ins2)!=1){
  1080.                 
  1081.                         vmsql_rollback($link);
  1082.                         openErrorGenerico("Errore nella clonazione delle sottomaschere",true);
  1083.                     }
  1084.     
  1085.     
  1086.                     
  1087.                 // -fine while interno
  1088.                 
  1089.         // -fine while esterno
  1090.  
  1091.         
  1092.     
  1093.     
  1094.     vmsql_commit($link);
  1095.     
  1096.     return true;
  1097.     
  1098.     
  1099. }
  1100.  
  1101.  
  1102. /**
  1103.  * Funzionedi utility per le operazioni interne
  1104.  * Copia le impostazioni dei campi di una tabella per un gruppo
  1105.  * e le applica alla tabella per un altro gruppo
  1106.  *
  1107.  * @param int $id_table_fonte id_table della tabella fonte
  1108.  * @param int $id_table_destinazione id_table della tabella destinazione
  1109.  * @return bool Esito dell'operazione
  1110.  */
  1111. function copia_impostazione_campi($id_table_fonte,$id_table_destinazione){
  1112.     
  1113.     global $link,$db1;
  1114.     
  1115.     
  1116.     // Prendi i valori del vecchio gid
  1117.         $sql_col1 "SELECT column_name,
  1118.                             extra,
  1119.                             in_tipo,
  1120.                             in_default,
  1121.                             in_visibile,
  1122.                             in_richiesto,
  1123.                             in_search,
  1124.                             in_suggest,
  1125.                             in_table,
  1126.                             in_ordine,
  1127.                             jstest
  1128.                             
  1129.                     FROM {$db1['frontend']}.registro_col
  1130.                     WHERE id_table=".intval($id_table_fonte)."
  1131.                     ORDER BY column_name, ordinal_position
  1132.                     
  1133.         ";
  1134.         
  1135.         $q_col1 vmsql_query($sql_col1,$link);
  1136.         
  1137.         vmsql_begin($link);
  1138.         
  1139.         while($RS2=vmsql_fetch_assoc($q_col1)){
  1140.             
  1141.             
  1142.             // prende l'id_reg corrispettivo
  1143.             
  1144.             $RS2=pulisci_dom($RS2);
  1145.             
  1146.             $q_reg=vmsql_query("SELECT id_reg FROM {$db1['frontend']}.registro_col 
  1147.                                 WHERE id_table=".intval($id_table_destinazione)."
  1148.                                 AND column_name='".$RS2['column_name']."'",$link);
  1149.             
  1150.             list($ID_REG)=vmsql_fetch_row($q_reg);
  1151.             
  1152.             // Prepara la query di aggiornamento
  1153.             
  1154.             $sql_up=sprintf("UPDATE {$db1['frontend']}.registro_col 
  1155.                             SET 
  1156.                             extra='%s',
  1157.                             in_tipo='%s', 
  1158.                             in_default='%s',
  1159.                             in_visibile=%d
  1160.                             in_richiesto=%d
  1161.                             in_search=%d,
  1162.                             in_suggest=%d
  1163.                             in_table=%d,
  1164.                             in_ordine=%d,
  1165.                             jstest='%s'
  1166.                             WHERE id_reg=%d
  1167.                             LIMIT 1
  1168.                             ",
  1169.                             $RS2['extra'],
  1170.                             $RS2['in_tipo'],
  1171.                             $RS2['in_default'],
  1172.                             $RS2['in_visibile'],
  1173.                             $RS2['in_richiesto'],
  1174.                             $RS2['in_search'],
  1175.                             $RS2['in_suggest'],
  1176.                             $RS2['in_table'],
  1177.                             $RS2['in_ordine'],
  1178.                             $RS2['jstest'],
  1179.                             $ID_REG);
  1180.                             
  1181.             
  1182.                         
  1183.             $res_up vmsql_try($sql_up,$link,false);
  1184.             
  1185.             if(!$res_up){
  1186.                 
  1187.                 vmsql_rollback($link);
  1188.                 openErrorGenerico("Errore nella copia di impostazione dei campi",true);
  1189.             }
  1190.                         
  1191.         }
  1192.         
  1193.     vmsql_commit($link);
  1194.     
  1195.     return true;
  1196.     
  1197.         
  1198.         
  1199. }
  1200.  
  1201.  
  1202.  
  1203.  
  1204. /**
  1205.  * Funzione di utilità
  1206.  * 
  1207.  * @param int $gid_new 
  1208.  * @param int $gid_old 
  1209.  * @param int $id_table_fonte 
  1210.  * @param int $id_table_dest 
  1211.  */
  1212. function copia_impostazione_sottomaschere($gid_new,$gid_old,$id_table_fonte,$id_table_dest){
  1213.     
  1214.     global $link,$db1;
  1215.     
  1216.     
  1217.     // Elimina eventuali vecchie sottomaschere
  1218.     
  1219.     $q_del_sub vmsql_query("DELETE FROM {$db1['frontend']}.registro_submask WHERE id_table=".intval($id_table_dest),$link);
  1220.     
  1221.     $esito clona_sottomaschere($gid_new,$gid_old,$id_table_fonte);
  1222.     
  1223. }
  1224.  
  1225.  
  1226. /**
  1227.  * Funzione di sincronizzazione dei campi del registro frontend.
  1228.  * Si associa a aggiorna registri, ma opera a livello di confronto di campo.
  1229.  *
  1230.  * @see function aggiorna_registri
  1231.  * @param string $tabella 
  1232.  * @param string $campo 
  1233.  * @param string $tipo_aggiornamento (UPDATE | INSERT | DELETE)
  1234.  */
  1235. function aggiorna_campo($tabella,$campo,$tipo_aggiornamento="UPDATE"){
  1236.     
  1237.     global $link,$db1;
  1238.     
  1239.     if($tipo_aggiornamento=="UPDATE"){
  1240.         
  1241.         // prendi gli id dal frontend
  1242.         
  1243.         $sql_c="SELECT c.id_regc.id_table FROM {$db1['frontend']}.registro_col c, {$db1['frontend']}.registro_tab t
  1244.                 WHERE c.id_table=t.id_table 
  1245.                 AND t.table_name='$tabella'
  1246.                 AND c.column_name='$campo'";
  1247.         
  1248.         $qc=vmsql_query($sql_c,$link);
  1249.         
  1250.         $mat_c=vmsql_fetch_assoc_all($qc);
  1251.         
  1252.         
  1253.         // prendi le info del campo dal information_schema
  1254.         $sql_i="SELECT * FROM information_schema.columns
  1255.                 WHERE TABLE_SCHEMA='".$db1['dbname']."'
  1256.                 AND TABLE_NAME='$tabella'
  1257.                 AND COLUMN_NAME='$campo'";
  1258.         
  1259.         $qi=vmsql_query($sql_i,$link);
  1260.         
  1261.         $RSi=vmsql_fetch_assoc($qi);
  1262.         
  1263.         
  1264.         
  1265.         // PREPARA l'update
  1266.         
  1267.         for($i=0;$i<count($RSi);$i++){
  1268.             
  1269.             $max_length(is_numeric($RSi['character_maximum_length'])) $RSi['character_maximum_length''NULL';
  1270.             
  1271.             if($db1['dbtype']=='postgres'){
  1272.                 $sql_up="UPDATE {$db1['frontend']}.registro_col
  1273.                          SET column_default='".addslashes($RSi['column_default'])."',
  1274.                          is_nullable='".$RSi['is_nullable']."',
  1275.                          ordinal_position=".intval($RSi['ordinal_position']).",
  1276.                          column_type='".$RSi['udt_name']."',
  1277.                          character_maximum_length=".$max_length.",
  1278.                          data_type='".$RSi['data_type']."',
  1279.                          extra='',
  1280.                          in_tipo = NULL,
  1281.                          in_default = NULL,
  1282.                          in_visibile=0,
  1283.                          in_richiesto=0,
  1284.                          in_search=0,
  1285.                          in_table=0,
  1286.                          in_ordine=0,
  1287.                          jstest = NULL,
  1288.                          commento='".addslashes(utf8_decode($RSi['column_comment']))."'
  1289.                          
  1290.                          WHERE id_table=".intval($mat_c[$i]['id_table'])."
  1291.                          AND id_reg=".intval($mat_c[$i]['id_reg'])."
  1292.                          
  1293.                         ";
  1294.             }
  1295.             else{
  1296.                     $sql_up="UPDATE {$db1['frontend']}.registro_col
  1297.                          SET column_default='".$RSi['COLUMN_DEFAULT']."',
  1298.                          is_nullable='".$RSi['IS_NULLABLE']."',
  1299.                          ordinal_position='".$RSi['ORDINAL_POSITION']."',
  1300.                          column_type='".$RSi['COLUMN_TYPE']."',
  1301.                          character_maximum_length='".$RSi['CHARACTER_MAXIMUM_LENGTH']."',
  1302.                          data_type='".$RSi['DATA_TYPE']."',
  1303.                          extra='',
  1304.                          in_tipo = NULL,
  1305.                          in_default = NULL,
  1306.                          in_visibile=0,
  1307.                          in_richiesto=0,
  1308.                          in_search=0,
  1309.                          in_table=0,
  1310.                          in_ordine=0,
  1311.                          jstest = NULL,
  1312.                          commento='".addslashes(utf8_decode($RSi['COLUMN_COMMENT']))."'
  1313.                          
  1314.                          WHERE id_table=".intval($mat_c[$i]['id_table'])."
  1315.                          AND id_reg=".intval($mat_c[$i]['id_reg'])."
  1316.                          
  1317.                         ";
  1318.             }
  1319. //            rpc_debug($sql_up,"../rpc.debug.txt");
  1320.             $q_up vmsql_query($sql_up,$link);
  1321.             
  1322.             
  1323.         }
  1324.         
  1325.     }
  1326.     
  1327.     
  1328.     else if($tipo_aggiornamento=="INSERT"){
  1329.         
  1330.         
  1331.         // prendi le info del campo dal information_schema
  1332.         $sql_i="SELECT * FROM information_schema.columns
  1333.                 WHERE TABLE_SCHEMA='".$db1['dbname']."'
  1334.                 AND TABLE_NAME='$tabella'
  1335.                 AND COLUMN_NAME='$campo'";
  1336.         $qi=vmsql_query($sql_i,$link);
  1337.         
  1338.         $RSi=vmsql_fetch_assoc($qi);
  1339.         
  1340.         // prendi gli ID table da coinvolgere
  1341.         
  1342.         $q_idt=vmsql_query("SELECT id_table,gid FROM {$db1['frontend']}.registro_tab
  1343.                             WHERE table_name='$tabella'",$link);
  1344.  
  1345.         
  1346.         list($idtables,$gids)=vmsql_fetch_row_all($q_idt,true);
  1347.         
  1348.         
  1349.         // prepara la query
  1350.         
  1351.         for($i=0;$i<count($idtables);$i++){
  1352.         
  1353.             
  1354.             if($db1['dbtype']=='postgres'){
  1355.                 
  1356.                 $sql_in="INSERT INTO {$db1['frontend']}.registro_col
  1357.                     
  1358.                     (id_table,gid,column_name,
  1359.                     column_default,is_nullable,ordinal_position,
  1360.                     column_type,character_maximum_length,data_type,in_visibile,
  1361.                     commento)
  1362.                     
  1363.                     VALUES
  1364.                     
  1365.                     (".$idtables[$i].", ".$gids[$i]." ,'$campo',
  1366.                     '".$RSi['column_default']."','".$RSi['is_nullable']."',".intval($RSi['ordinal_position']).",
  1367.                     '".$RSi['column_type']."',".intval($RSi['character_maximum_length']).",'".$RSi['data_type']."',0,
  1368.                     '".addslashes(utf8_decode($RSi['column_comment']))."')
  1369.                     
  1370.                     ";
  1371.             }
  1372.  
  1373.             else{
  1374.                 $sql_in="INSERT INTO {$db1['frontend']}.registro_col
  1375.                         
  1376.                         (id_table,gid,column_name,
  1377.                         column_default,is_nullable,ordinal_position,
  1378.                         column_type,character_maximum_length,data_type,in_visibile,
  1379.                         commento)
  1380.                         
  1381.                         VALUES
  1382.                         
  1383.                         (".$idtables[$i].", ".$gids[$i]." ,'$campo',
  1384.                         '".$RSi['COLUMN_DEFAULT']."','".$RSi['IS_NULLABLE']."','".$RSi['ORDINAL_POSITION']."',
  1385.                         '".$RSi['COLUMN_TYPE']."',".intval($RSi['CHARACTER_MAXIMUM_LENGTH']).",'".$RSi['DATA_TYPE']."',0,
  1386.                         '".addslashes(utf8_decode($RSi['COLUMN_COMMENT']))."')
  1387.                         
  1388.                         ";
  1389.             }
  1390.             
  1391.             
  1392.             $q_in vmsql_query($sql_in,$link);
  1393.         }
  1394.     }
  1395.     
  1396.     
  1397.     else if($tipo_aggiornamento=="DELETE"){
  1398.         
  1399.         // prendi le colonne coinvolte
  1400.         
  1401.         $sql_del="SELECT c.id_reg FROM {$db1['frontend']}.registro_col c, {$db1['frontend']}.registro_tab t
  1402.                 WHERE c.id_table=t.id_table 
  1403.                 AND t.table_name='$tabella'
  1404.                 AND c.column_name='$campo'";
  1405.  
  1406.         $q_del=vmsql_query($sql_del,$link);
  1407.         
  1408.         list($idregsvmsql_fetch_row_all($q_del,true);
  1409.         
  1410.         if(count($idregs)>0){
  1411.         
  1412.             $sql_del2="DELETE FROM {$db1['frontend']}.registro_col WHERE id_reg IN (".implode(",",$idregs).")";
  1413.         
  1414. //            rpc_debug($sql_del2,"../rpc.debug.txt");    
  1415.             $q_del2 vmsql_query($sql_del2,$link);
  1416.             
  1417.         }
  1418.     }
  1419.     
  1420.     
  1421. }
  1422.  
  1423.  
  1424. ?>

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