<html><link rel="SHORTCUT ICON" href="favicon.ico"><body background='textblue.jpg'><head><title> Atenae - Catalog Explorer for DB2</title></head>

<div align="left"><img src="atp.gif" width="120" height="120" onclick=window.open('ajtb.html','ajuda','width=300,height=200,scrollbars=yes')></div><div align="center"><a href='index.html'> Principal  </a>
&nbsp&nbsp
<a href='lista_db.php'> DBs  </a>
&nbsp&nbsp
<a href='stmtr3.php?sql=&q=0&dbasef=&dban=&tban=&tabela=&criador=&cran='> Query  </a></div>
&nbsp&nbsp
</div>

<?php

$dbconn = odbc_connect('DB2P', 'XMG', 'ETLGIT', SQL_CUR_USE_ODBC) ;


if ($dbconn != 0) {

   $db=$_GET['db'];
   $tp=$_GET['tp'];
   $or=$_GET['or'];

   $stmt = "SELECT A.TSNAME, A.CREATOR, A.NAME, A.COLCOUNT, A.NPAGES, A.CARD, A.DBNAME, I.IX, V.VIEWS, P.PLANOS, PK.PACKAGES, TR.TRIGGERS, RF.RELF, RM.RELM
              from sysibm.systables A
              left join
              (select TBCREATOR, TBNAME, count(*) as ix from sysibm.sysindexes GROUP BY TBCREATOR, TBNAME) AS I
              ON A.CREATOR=I.TBCREATOR AND A.NAME=I.TBNAME
              left join
              (select BCREATOR, BNAME, count(*) as views from sysibm.sysviewdep GROUP BY BCREATOR, BNAME) AS V
              ON A.CREATOR=V.BCREATOR AND A.NAME=V.BNAME
              left join
              (select BCREATOR, BNAME, count(*) as planos from sysibm.sysplandep GROUP BY BCREATOR, BNAME) AS P
			                ON A.CREATOR=p.BCREATOR AND A.NAME=p.BNAME
              left join
              (select BQUALIFIER, BNAME, count(*) as packages from sysibm.syspackdep GROUP BY BQUALIFIER, BNAME) AS PK
			                ON A.CREATOR=PK.BQUALIFIER AND A.NAME=PK.BNAME
              left join
              (select TBOWNER, TBNAME, count(*) as triggers from sysibm.systriggers GROUP BY TBOWNER, TBNAME) AS TR
              ON A.CREATOR=TR.TBOWNER AND A.NAME=TR.TBNAME
              left join
              (select CREATOR, TBNAME, count(*) as relf from sysibm.sysrels GROUP BY CREATOR, TBNAME) AS RF
			                ON A.CREATOR=RF.CREATOR AND A.NAME=RF.TBNAME
              left join
              (select REFTBCREATOR, REFTBNAME, count(*) as relm from sysibm.sysrels GROUP BY REFTBCREATOR, REFTBNAME) AS RM
			                ON A.CREATOR=RM.REFTBCREATOR AND A.NAME=RM.REFTBNAME

              where A.type='$tp' and A.dbname='$db'
              order by $or" ;

   $result = odbc_exec($dbconn, $stmt);

   if ($result == 0) {

      $sqlerror = odbc_errormsg($dbconn);
      echo $sqlerror ; }

   else {

      echo "<table width='85%' border='0' align='center'>
            <caption>
            <h1> Tabelas do DB: $db </h1>
            <h2> ordenado por:  $or </h2>
            <br>
            </caption>
            <tr>
        	     <th onclick=alert('nome_do_tablespace(navega_para_backups)') bgcolor='#FFFF9F' scope='col'> Tablespace </th>
        	     <th onclick=alert('criador_da_tabela') bgcolor='#FFFF9F' scope='col'> Criador </th>
        	     <th onclick=alert('nome_da_tabela(navega_para_query)') bgcolor='#FFFF9F' scope='col'> Nome </th>
        	     <th onclick=alert('quantidade_de_colunas(navega_para_colunas)') bgcolor='#FFFF9F' scope='col'> Qtd. colunas </th>
        	     <th onclick=alert('quantidade_de_pginas_de_dados(estatstica)') bgcolor='#FFFF9F' scope='col'> Qtd. pginas </th>
        	     <th onclick=alert('quantidade_de_linhas(estatstica)') bgcolor='#FFFF9F' scope='col'> Qtd. linhas </th>
         	     <th onclick=alert('quantidade_de_ndices_da_tabela(alerta_qtd)_(navega_para_ndices)') bgcolor='#FFFF9F' scope='col'> ndices </th>
                 <th onclick=alert('quantidade_de_views_que_usam_a_tabela(navega_para_views)') bgcolor='#FFFF9F' scope='col'> Views </th>
        	     <th onclick=alert('quantidade_de_planos_que_usam_a_tabela(navega_para_planos)') bgcolor='#FFFF9F' scope='col'> Planos </th>
        	     <th onclick=alert('quantidade_de_packages_que_usam_a_tabela(navega_para_packages)') bgcolor='#FFFF9F' scope='col'> Packages </th>
        	     <th onclick=alert('quantidade_de_triggers_na_tabela(navega_para_triggers)') bgcolor='#FFFF9F' scope='col'> Triggers </th>
        	     <th onclick=alert('quantidade_de_tabelas_das_quais_esta_tabela_depende(navega_para_relacionamentos)') bgcolor='#FFFF9F' scope='col'> Filha de  </th>
        	     <th onclick=alert('quantidade_de_tabelas_dependentes_desta_tabela(navega_para_relacionamentos)') bgcolor='#FFFF9F' scope='col'> Me de </th>
        	     <th onclick=alert('nmero_de_sequncia_na_pgina') bgcolor='#FFFF9F' scope='col'> seq </th>
        	</tr>" ;

      $n=1;
      $icr=" ";
      $its=" ";
      $pgs=0;
      $mb=0;

      while ($row = odbc_fetch_array($result)) {

        echo "<tr onmouseover=style.backgroundColor='#e7e7e7' onmouseout=style.backgroundColor=''>";

        if ($row['TSNAME'] != $its)
          echo "<th align='left' scope='col'><a href='lista_cp_2i.php?ts=$row[TSNAME]&or=3 desc'> $row[TSNAME] </th>" ;
        else
          echo "<th align='left' scope='col'> </th>" ;

        if ($row['CREATOR'] != $icr)
          echo "<th align='left' scope='col'> $row[CREATOR] </th>" ;
        else
          echo "<th align='left' scope='col'> </th>" ;

        $icr=$row['CREATOR'];

        $tbname = $row['NAME'];

        echo "
          <th  align='left' scope='col'><a href='stmtr3.php?sql=select * from $icr.$tbname&dbasef=$db&dban=$db&tban=$tbname&tabela=$tbname&criador=$icr&cran=$icr&q=10&ff=&fu=&fp='> $row[NAME] </th>
          <th  align='center' scope='col'><a href='lista_co_2i.php?cr=$row[CREATOR]&tb=$row[NAME]'> $row[COLCOUNT] </th>
          <th  align='right' scope='col'> $row[NPAGES] </th>
          <th  align='right' scope='col'> $row[CARD] </th> ";

     if ($row['IX'] > 3 or $row['IX'] == '' )
         echo "<th  bgcolor='red' align='center' scope='col'><a href='lista_ix_2i.php?cr=$row[CREATOR]&tb=$row[NAME]'> $row[IX] </th>";
       else
         echo "<th  align='center' scope='col'><a href='lista_ix_2i.php?cr=$row[CREATOR]&tb=$row[NAME]'> $row[IX] </th>";

        echo "
          <th  align='center' scope='col'><a href='lista_views_2i.php?cr=$row[CREATOR]&tb=$row[NAME]'> $row[VIEWS] </th>
          <th  align='center' scope='col'><a href='lista_plandep_2i.php?cr=$row[CREATOR]&tb=$row[NAME]'> $row[PLANOS] </th>
          <th  align='center' scope='col'><a href='lista_packdep_2i.php?cr=$row[CREATOR]&tb=$row[NAME]'> $row[PACKAGES] </th>
          <th  align='center' scope='col'><a href='lista_triggers_2i.php?cr=$row[CREATOR]&tb=$row[NAME]'> $row[TRIGGERS] </th>
          <th  align='center' scope='col'><a href='lista_rels_2i.php?cr=$row[CREATOR]&tb=$row[NAME]&or=2,3'> $row[RELF] </th>
          <th  align='center' scope='col'><a href='lista_rels_2i.php?cr=$row[CREATOR]&tb=$row[NAME]&or=2,3'> $row[RELM] </th>
          <th  bgcolor='#FFFF9F' align='center' scope='col'> $n </th>
          </tr> ";

      $pgs=$pgs+$row['NPAGES'];
      $its=$row['TSNAME'];
      $n++;

      if (ceil($n / 20) == ($n / 20))
         echo "  <tr>
        	          <th onclick=alert('nome_do_tablespace') bgcolor='#FFFF9F' scope='col'> Tablespace </th>
        	          <th onclick=alert('criador_da_tabela') bgcolor='#FFFF9F' scope='col'> Criador </th>
        	          <th onclick=alert('nome_da_tabela') bgcolor='#FFFF9F' scope='col'> Nome </th>
        	          <th onclick=alert('quantidade_de_colunas') bgcolor='#FFFF9F' scope='col'> Qtd. colunas </th>
        	          <th onclick=alert('quantidade_de_pginas_de_dados(estatstica)') bgcolor='#FFFF9F' scope='col'> Qtd. pginas </th>
        	          <th onclick=alert('quantidade_de_linhas(estatstica)') bgcolor='#FFFF9F' scope='col'> Qtd. linhas </th>
         	          <th onclick=alert('quantidade_de_ndices_da_tabela/vermelho_para_mais_que_3_ndices(pode_perder_de_performance)') bgcolor='#FFFF9F' scope='col'> ndices </th>
                      <th onclick=alert('quantidade_de_views_que_usam_a_tabela') bgcolor='#FFFF9F' scope='col'> Views </th>
        	          <th onclick=alert('quantidade_de_planos_que_usam_a_tabela') bgcolor='#FFFF9F' scope='col'> Planos </th>
        	          <th onclick=alert('quantidade_de_packages_que_usam_a_tabela') bgcolor='#FFFF9F' scope='col'> Packages </th>
        	          <th onclick=alert('quantidade_de_triggers_na_tabela') bgcolor='#FFFF9F' scope='col'> Triggers </th>
        	          <th onclick=alert('quantidade_de_tabelas_das_quais_esta_tabela_depende') bgcolor='#FFFF9F' scope='col'> Filha de  </th>
        	          <th onclick=alert('quantidade_de_tabelas_dependentes_desta_tabela') bgcolor='#FFFF9F' scope='col'> Me de </th>
        	          <th onclick=alert('nmero_de_sequncia_na_pgina') bgcolor='#FFFF9F' scope='col'> seq </th>
        	</tr>" ;


      }

    if ($tp == 'T') {

      $mb=$pgs * 4 / 1000;

      echo "</table> <br> <br> <br>
            <table width='40%' border='0' align='center'>
              <tr>
                <th onclick=alert('somatria_de_qtd_pginas(estatstica)') bgcolor='#FFFF9F' scope='col'> Qtd. pginas </th>
                <th onclick=alert('calculo_de_espao_em_MBytes(estatstica)') bgcolor='#FFFF9F' scope='col'> Qtd. Mbytes </th>
              </tr>
              <tr>
                <th bgcolor='#FFFFFF' align='center' scope='col'> $pgs  </th>
                <th bgcolor='#FFFFFF' align='center' scope='col'> $mb </th>
              </tr>
            </table>";
    }

}}

odbc_close($dbconn);

?>