<?php
	$cpanel_cabeza=mysql_query("select * from    tabla_menu where eliminar=0 and abreviacion='$control_menu'",$link);
	$ver_cpanel_cabeza=mysql_fetch_array($cpanel_cabeza);
		$control_id_menu=$ver_cpanel_cabeza['id'];
		$cpanel_sub_menu=mysql_query("select * from  tabla_menu_sub where eliminar=0 and abreviacion='$menu' and cod_menu='$control_id_menu'",$link);
		$ver_cpanel_sub_menu=mysql_fetch_array($cpanel_sub_menu);
		$tabla_control=$ver_cpanel_sub_menu['nombre_tabla_sql'];


?>
                    <div class="pageheader">
                        <div class="media">
                            <div class="pageicon pull-left">
                                <i class="fa <?php echo $ver_cpanel_cabeza['figura']; ?>"></i>
                            </div>
                            <div class="media-body">
                                <ul class="breadcrumb">
                                    <li><a href="#"><i class="glyphicon glyphicon-cog"></i></a></li>
                                    <li><?php echo $ver_cpanel_cabeza['nombre_menu']; ?></li>
                                </ul>
                                <h4><?php echo $ver_cpanel_sub_menu['nombre_menu']; ?> | 
									<?php if($ver_usuarios['privilegios']=='1'){ echo 'Administrador';} ?>
									<?php if($ver_usuarios['privilegios']=='2'){ echo 'Gerente';} ?>
									<?php if($ver_usuarios['privilegios']=='3'){ echo 'Cajero';} ?>
								</h4>
                            </div>
                        </div>
                    </div>
<!-- PANEL ADMINISTRATIVO -->					
<div class="contentpanel">
 <?php 
 		include 'mensajes.php';
		if (isset($_POST['submit'])){
			foreach($_POST as $campo => $value)
			 {
				$limpiar_variable=strip_tags($value);
				//echo $campo.$limpiar_variable;
				if (empty($limpiar_variable)){
						echo'
							<div class="alert alert-danger fade in">
								<i class="fa-fw fa fa-times"></i>
								<strong>Error!</strong> Llamar al administrador del sistema <b>ERROR: 10</b>
							</div>
						';
					break;
				}
			}
			if($_GET['insert']=="true")	{
				$contar_registro = mysql_query("SELECT * FROM $tabla_control");
				$cont_registro=mysql_num_rows($contar_registro);
				$contruc_table = mysql_query("SHOW COLUMNS FROM $tabla_control");
				$cont=mysql_num_rows($contruc_table);
					if ( $cont> 0) {
						 $campos.="(";
						while ($fila = mysql_fetch_assoc($contruc_table)) {
							$i++;
							if($i>1){
								$tipo_campo=$fila['Field'];
								$campos.="".$tipo_campo;
							}
							if($i<$cont and $i>1 ){
								$campos.=",";
							}
						}
					}
				$campos.=") values (";
				$conta=count($_POST);
				$i=0;
				foreach($_POST as $campo => $value) {
					$i++;
					$campos_tabla.="'".$value."'";
					if($i<$conta){
						$campos_tabla.=",";
					}
				 }
				 $campos_tabla=$campos_tabla.");";
				 $sql="INSERT INTO $tabla_control ". $campos.$campos_tabla;
				 mysql_query("$sql",$link);
				$contar_registro_insert = mysql_query("SELECT * FROM $tabla_control");
				$cont_registro_insert=mysql_num_rows($contar_registro_insert);
				if($cont_registro==$cont_registro_insert){
					echo'
                        <div class="alert alert-warning fade in">
                            <i class="fa-fw fa fa-warning"></i>
                                <strong>Advertencia !</strong> Datos ya registrados en la base de datos.
                        </div>
					';
				} else {
					echo'
                        <div class="alert alert-success fade in">
                            <i class="fa-fw fa fa-check"></i>
                               <strong>Exelente !</strong> Muchas gracias datos registrados.
                        </div>

					';					
				}
			}
		}
 
 ?>
	<div class="row row-stat">
		<div class="col-md-12">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <div class="panel-btns">
                                            <a href="#" class="panel-minimize tooltips" data-toggle="tooltip" title="Minimize Panel"><i class="fa fa-minus"></i></a>
                                            <a href="#" class="panel-close tooltips" data-toggle="tooltip" title="Close Panel"><i class="fa fa-times"></i></a>
                                        </div><!-- panel-btns -->
                                        <h4 class="panel-title"><?php echo $ver_cpanel_sub_menu['titulo']; ?></h4>
                                        <p><?php echo $ver_cpanel_sub_menu['descripcion']; ?>.</p>
                                    </div><!-- panel-heading -->
                                    <div class="panel-body nopadding">
                                        <form action="<?php echo $url_global; ?>&insert=true" method="post" class=" form-bordered">
										<div class="form-group">
											<?php
												$resultado = mysql_query("SHOW COLUMNS FROM $tabla_control");
													if (mysql_num_rows($resultado) > 0) {
													while ($fila = mysql_fetch_assoc($resultado)) {
													$tipo_campo=$fila['Type'];
											?>
											<!-- TIPO TEXTO -->
												<?php if($tipo_campo=='varchar(50)'){ ?>	
                                                <div class="col-sm-4">
													<input type='text' name='<?php echo $fila['Field']; ?>' placeholder='<?php echo $fila['Default']; ?>' class='form-control' autocomplete="off"  autofocus required="required"  /></br>
							                    </div>
												<?php } ?>
												<?php if($tipo_campo=='varchar(150)'){ ?>	
                                                <div class="col-sm-6">
													<input type='text' name='<?php echo $fila['Field']; ?>' placeholder='<?php echo $fila['Default']; ?>' class='form-control' autocomplete="off"  autofocus required="required"  /></br>
							                    </div>
												<?php } ?>	
												<?php if($tipo_campo=='varchar(200)'){ ?>	
                                                <div class="col-sm-8">
													<input type='text' name='<?php echo $fila['Field']; ?>' placeholder='<?php echo $fila['Default']; ?>' class='form-control' autocomplete="off"  autofocus required="required" /></br>
							                    </div>
												<?php } ?>	
												<?php if($tipo_campo=='varchar(250)'){ ?>	
                                                <div class="col-sm-12">
													<input type='text' name='<?php echo $fila['Field']; ?>' placeholder='<?php echo $fila['Default']; ?>' class='form-control' autocomplete="off"  autofocus required="required"  /></br>
							                    </div>
												<?php } ?>
											<!-- TIPO TEXTO -->
	
												<?php } ?>
												<?php } ?>
										<div class="pull-right">
												<button type="submit" name="submit" value='Guardar' class="btn btn-default">GUARDAR <i class="fa fa-floppy-o ml5"></i></button>
										</div>
                                            </div>

										</form>  
								
                                    </div>     
                                </div>
        </div>
	</div>
</div>