<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>

</head>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<body>
<form id="form1" name="form1" method="post" action="">
<span class="text_mensaje">
<input name="vali" type="hidden" 
<?php
 
if (isset($_REQUEST['vali'])){
	echo ' value = "'.$_REQUEST['vali'].'"';
	$nr = $_REQUEST['vali'];
}else{
	echo ' value = "0"';
	$nr = 0;
}
$nr2 =  20;
?>
/>
DESARROLLO INCOMPLETO</span> <br>
  <table  align="center" >
    <tr>
      <td colspan="3"><div align="center">ACCIONES</div></td>
    </tr>
    <tr>
      <td>Base: </td>
      <td><input name="t1" type="text" tabindex="1" maxlength="255" 
  <?php
 
  if (isset($_REQUEST['t1'])){
  	echo ' value = "'.$_REQUEST['t1'].'"';
  }
  ?>
  /></td>
      <td>Tabla a buscar:
<input name="t2" type="text" tabindex="1" maxlength="255" 
  <?php
 
  if (isset($_REQUEST['t2'])){
  	echo ' value = "'.$_REQUEST['t2'].'"';
  }
  ?>
  /></td>
    </tr>
    <tr>
      <td>Condicion</td>
      <td colspan="2"><input name="t3" type="text" tabindex="1" size="50" maxlength="255" 
  <?php
 
  if (isset($_REQUEST['t3'])){
  	echo ' value = "'.$_REQUEST['t3'].'"';
  }
  ?>
  /></td>
    </tr>
    
    <tr>
      <td colspan="3">SQL:      
      <textarea name="t4" cols="50" rows="3" id="t4"><?php
 if (isset($_REQUEST['t4'])) echo $_REQUEST['t4'];?></textarea></td>
    </tr>
    <tr>
      <td colspan="3"><div align="center">
        <input type="submit" name="Submit" value="Buscar" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="submit" name="Submit2" value="Ejecutar" />
      </div></td>
    </tr>
  </table>

<a href="http://insecoin/SIAD/" target="_blank">Entrar al sistema del SIAD</a>
  <?php
 
$con = mysqli_connect("localhost","root","castillejos");
$cag=mysqli_select_db($_REQUEST['t1']);
$sql = mysqli_query($con ,"select * from ".$_REQUEST['t2']." ".$_REQUEST['t3']);
@$num_reg = mysqli_num_rows($sql);
@$n_campos = mysqli_num_fields($sql);
//echo 'Valor :'.$num_reg.'<br>';

//echo 'valor: '. $nr;

//   --->  Paginacion

//numeros 
echo '<table border="0" align="center" >
  <tr><td width="100%">';
  	$y = 0;
	$paginas = $num_reg / 20;
	//$pag2 = $num_reg % 10;
	//if ($pag2 <> 0)	$paginas++;
  	for ($i=0;$i<=$paginas;$i++){
		//$j = $y - 1;
		if($i == 0){
echo '<a class="thcon" href="'.$_SERVER["PHP_SELF"].'?vali='.$y.'&t1='.$_REQUEST['t1'].'&t2='.$_REQUEST['t2'].'&t3='.$_REQUEST['t3'].'&t4='.$_REQUEST['t4'].'">1</a> . ';
	    }else{
echo '<a class="thcon" href="'.$_SERVER["PHP_SELF"].'?vali='.$y.'&t1='.$_REQUEST['t1'].'&t2='.$_REQUEST['t2'].'&t3='.$_REQUEST['t3'].'&t4='.$_REQUEST['t4'].'">'.$y.'</a> . ';
		 }
		$y+=20;
	}
 echo '</td></tr>
</table>';

if(isset($_REQUEST['t1']) or isset($_REQUEST['t4'])){
	echo '<table border="0"><tr><td colspan = "'.$n_campos.'"  class="thimprime">'.$_REQUEST['t2'].'&nbsp;</td></tr>';
	$_REQUEST['t4']=trim($_REQUEST['t4']);
	if($_REQUEST['t4']==""){
		
		//$cad = "select * from ".$_REQUEST['t2']." ".$_REQUEST['t3']. " Limit ".$nr.",".$nr + 10;
		$sql = mysqli_query($con ,"select * from ".$_REQUEST['t2']." ".$_REQUEST['t3']. " Limit ".$nr.",".$nr2);
		$n = mysqli_num_fields($sql);
		echo '<tr>';
		for ($j=0;$j<$n;$j++){
			echo '<th>'.mysqli_field_name($sql, $j).'&nbsp;</th>';
		}
		echo '</tr>';
		include ('DECOLOR.php');
		while($reg=mysqli_fetch_array($sql)){
			//mandar datos a la tabla
			$nr = $nr + 1;
			$col = color_columna("#CCCCCC","#FDFDFD",$nr);
			echo '<tr>';
				for ($j=0;$j<$n;$j++){
					echo '<td style="'.$col.'"><div align="center">'.$reg[mysqli_field_name($sql, $j)].'&nbsp;</div></td>';
				}
			echo '</tr>';
		}
	}else{
		if(mysqli_query($con ,$_REQUEST['t4'])){
			//$cad = "select * from ".$_REQUEST['t2']." ".$_REQUEST['t3']. " Limit ".$nr.",".$nr + 10;
		$sql = mysqli_query($con ,$_REQUEST['t4']. " Limit ".$nr.",".$nr2);
		@$n = mysqli_num_fields($sql);
		echo '<tr>';
		for ($j=0;$j<$n;$j++){
			echo '<th>'.mysqli_field_name($sql, $j).'&nbsp;</th>';
		}
		echo '</tr>';
		
		while(@$reg=mysqli_fetch_array($sql)){
			//mandar datos a la tabla
			$nr = $nr + 1;
			$col = color_columna("#CCCCCC","#66CCFF",$nr);
						
			echo '<tr>';
				for ($j=0;$j<$n;$j++){
					echo '<td style="'.$col.'"><div align="center">'.$reg[mysqli_field_name($sql, $j)].'&nbsp;</div></td>';
				}
			echo '</tr>';
		}
			$g = 'Se ejecuto la instruccion';
		}else{
			$g =  'No Se ejecuto la instruccion';
		}
	}
}
echo '</table>';
echo $g . ' ' . $_REQUEST['t4'];




?>
</form>

</body>
</html>
