<?php include('casa/setup.casa.php');
$titulo = 'PHP Generar';
include('inc_head.php');
$TABLA = 'siesar_presupuestos';
?>
<style>
th{
	color:white;
	text-align:center;
	text-transform:uppercase;}	
.txt{
	font-size:12px;
	font-family:'Courier New';
	background:#ccc;
}
</style>
</head>
<body>
	<div class="wrapper">
	
	<?php include('inc_menu.php');?>
		<div class="main-panel">
			<div class="content">
				
			<div class="page-inner">
					
					<div class="row">						
						<div class="col-md-12">
							<div class="card">
								<div class="card-header">
									<div class="d-flex align-items-center">
										<h3 class="card-title"><?php echo $titulo;?></h3>																																									
									</div>
								</div>
								
								<div class="card-body">																					
									<div class="table-responsive">
										<?php 
$db=new DB();
										

$sql = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '$TABLA';";
$db->dbSQL($sql);
$datos='';
$tabla = '';
$i=0;
while($db->next()){
$i++;													 
	$columna = $db->dbField('COLUMN_NAME');																																										
	$datos.='$'.$columna.' = $db->dbField("'.$columna.'");<br>';
	
}


                                        $db=new DB();
										
										$sql = "SELECT *
										FROM INFORMATION_SCHEMA.COLUMNS
										WHERE TABLE_NAME = '$TABLA';";
                                        $db->dbSQL($sql);
                                        $codigo ='<textarea cols="10" rows="7" class="txt form-control">';
										$tabla = '<textarea cols="10" rows="7" class="txt form-control">';
										$titulos = '<textarea cols="10" rows="7" class="txt form-control">';
										$form = '<textarea cols="10" rows="7" class="txt form-control">';
										$post = '<textarea cols="10" rows="7" class="txt form-control">';
										$validar = '<textarea cols="10" rows="7" class="txt form-control">';
										$update = '<textarea cols="10" rows="7" class="txt form-control">UPDATE '.$TABLA.' SET ';										
										$insert = '<textarea cols="10" rows="7" class="txt form-control">INSERT INTO '.$TABLA.'(';
										$insert2='';
										$i=0;
                                        while($db->next()){
										$i++;													 
									    
										$columnas = $db->dbField('COLUMN_NAME');							
										
                                            $codigo.='<div class="input-group mb-2">'."\n".
											'    <div class="input-group-prepend"><span class="input-group-text bg-dark">'.$columnas.':</span></div>'."\n".
											'        <input id="'.$columnas.'" value="<?php echo &#36;'.$columnas.'; ?>" type="text" class="form-control" required>'."\n".
											'</div>'."\n"; 
											$form.= "&#39;".$columnas."&#39;: &#36;(&#39;#".$columnas."&#39;).val(),"."\n";     
											$post.= "&#36;".$columnas." = DataForms::POST(&#39;".$columnas."&#39;);"."\n";  
											$validar.= "if(trim(&#36;".$columnas.")==''){\n  MostrarMensaje('Debe Ingresar ".$columnas."!!!');\n  exit();\n}"."\n";       
											$update.= $columnas." = '&#36;".$columnas."',"."\n";
											$insert.= $columnas.","."\n";
											$insert2.= "&#39;&#36;".$columnas."&#39;,"."\n";
											$tabla.= " &#36;html.='<td align=center>&#39;.&#36;".$columnas.".&#39;</td>';"."\n";                                            
											$titulos.= "<th>".$columnas."</th>"."\n"; 
                                        }
										$codigo.='</textarea>';    
										$tabla.='</textarea>';     
										$titulos.='</textarea>';     
										$form.='</textarea>';          
										$post.='</textarea>';          
										$validar.='</textarea>';       
										$insert.=')VALUES('.$insert2.');</textarea>';         
										$update.='WHERE codigo = &#39;&#36;codigo&#39;;</textarea>';                          
                                        ?>   	

<div class="card-body">
		<div class="row">										
			<div class="col-md-6">														
				<div class=" txt form-group">
					<?php echo $datos; ?>
				</div>
			</div>
			<div class="col-md-6">														
				<div class="form-group">
					<?php echo $codigo; ?> <br>
					<?php echo $tabla; ?><br>
					<?php echo $titulos; ?><br>
					<?php echo $form; ?><br>
					<?php echo $post; ?><br>
					<?php echo $validar; ?><br>
					<?php echo $update; ?><br>
					<?php echo $insert; ?>
				</div>
			</div>
		</div>
	</div>

                                    <table id="registros" class="table table-striped table-bordered">
                                        <thead>
                                            <tr class="bg-dark">	
                                            </tr>
                                        </thead>
                                        <tbody>    
                                        <?php 
                                        $db=new DB();
										

										$sql = "SELECT *
										FROM INFORMATION_SCHEMA.COLUMNS
										WHERE TABLE_NAME = '$TABLA';";
                                        $db->dbSQL($sql);
                                        $html='';
										$i=0;
                                        while($db->next()){
										$i++;													 
									    
										$columnas = $db->dbField('COLUMN_NAME');							
	
                                            $html.='<tr>'; 
											$html.='<td>'.$i.'</td>';																																							
											$html.='<td>'.$columnas.'</td>';										                                    
                                            
                                            $html.='</tr>';
                                            
                                        }
                                        echo $html;                                        
                                        ?>                                                                                    
                                        </tbody>                                        
                                    </table>
                                </div>
								</div>
							</div>
						</div>
					</div>
				</div>
				
			</div>
			<?php include('inc_pie.php');?>
		</div>
				
	</div>
</body>
</html>