<?php

include "config2.php";
$page = isset($_GET['p'])?$_GET['p']:'';


if($page=='login'){
	$rut_usuario = $_POST['rut'];
	$contrasena = $_POST['contrasena'];
	$resp="";
	$stmt = $dbh->prepare("select rut from usuario where rut=? and contrasena=? ");
	$stmt->bindParam(1,$rut_usuario);
	$stmt->bindParam(2,$contrasena);
	$stmt->execute();
	while($row = $stmt->fetch()){
		$resp = $row['rut'];
	}
	if($resp===$rut_usuario){
		echo "1";
	}else{
		echo "error";
	}
}elseif($page=='mostrar_usuario'){
	$consulta ="select * from usuario";
	$stmt = $dbh->prepare($consulta);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
		<tr>
	        <td><?php echo 	$row['rut'];   
	        				$row['id']=$row['rut'];  
	        				$row['id']= str_replace('.', '', $row['id']);
	        				$row['id']= str_replace('-', '', $row['id']);?>			
         	</td>
	        <td><?php echo $row['contrasena']; ?></td>
	        <td><?php echo $row['perfil']; ?></td>
	        <td><?php echo $row['estado']; ?></td>
	        <td>
				<button  class="btn btn-warning" data-toggle="modal" data-target="#edit-<?php echo $row['id'] ?>">Editar</button>
				<!-- Modal -->
				<div class="modal fade" id="edit-<?php echo $row['id'] ?>" tabindex="-1" role="dialog" aria-labelledby="editLabel-<?php echo $row['id'] ?>">
				  <div class="modal-dialog" role="document">
				    <div class="modal-content">
    			      <div class="modal-header">
				        <h4 class="modal-title" id="editLabel-<?php echo $row['id'] ?>">Editar datos</h4>
				      </div>
				      <form>
				      <div  class="modal-body">
                           <input type="hidden"  id="<?php echo $row['id'] ?>" value="<?php echo $row['id'] ?>">
                       	<div class="form-group">
                            <label for="rut">Rut</label>
                            <input type="text" disabled="disabled" class="form-control" id="rut-<?php echo $row['id'] ?>" value="<?php echo $row['rut'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Contrasña</label>
                            <input type="text" class="form-control" id="contrasena-<?php echo $row['id'] ?>" value="<?php echo $row['contrasena'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="estado">Estado</label>
                             <select class="form-control" id="estado-<?php echo $row['id'] ?>" value="<?php echo $row['estado'] ?>">
                              <option>Activo</option>
                              <option>Bloqueado</option>
                            </select>
                          </div>         
				      </div>
				      <div class="modal-footer">
				        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
				        <button type="submit" onclick="actualizar(<?php echo $row['id'] ?>)" class="btn btn-primary">Actualizar</button>
				      </div>
				      </form>
				    </div>
				  </div>
				</div>
			</td>
			<td>
				<button class="btn btn-primary" <?php echo 'onclick="eliminar(\''.$row['rut'].'\');"';?>>eliminar</button>
			</td>
	    </tr>
		<?php
	}
}elseif($page=='eliminar_usuario'){
	$rut = $_POST['rut'];
	$consulta ="delete from usuario where rut=?";
	$stmt = $dbh->prepare($consulta);
	$stmt->bindParam(1,$rut);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
    	<tr>
	        <td><?php echo $row['rut'];?></td>
	        <td><?php echo $row['contrasena']; ?></td>
	        <td><?php echo $row['perfil']; ?></td>
            <td><?php echo $row['estado']; ?></td>
            <td>
				<button class="btn btn-primary"  <?php echo 'onclick="editar(\''.$row['rut'].'\');"';?>>editar</button>
			</td>
			<td>
				<button class="btn btn-primary" <?php echo 'onclick="eliminar(\''.$row['rut'].'\');"';?>>eliminar</button>
			</td>
	    </tr>
		<?php
	}
}elseif($page=='agregar_usuario'){
	$dato1 = $_POST['rut'];
	$dato2 = $_POST['contrasena'];
	$dato3 = $_POST['perfil'];
	$dato4 = $_POST['estado'];
	$stmt = $dbh->prepare("insert into usuario (rut,contrasena,perfil,estado) values(?,?,?,?)");
	$stmt->bindParam(1,$dato1);
	$stmt->bindParam(2,$dato2);
	$stmt->bindParam(3,$dato3);
	$stmt->bindParam(4,$dato4);
	if($stmt->execute()){
		echo "Usuario Agregado";
	}else{
		echo "no se agrego";
	}

}elseif($page=='actualizar_usuario'){
	$rut = $_POST['rut'];
	$contrasena = $_POST['contrasena'];
	$estado= $_POST['estado'];
	$stmt = $dbh->prepare("update usuario set  contrasena=?, estado=? where rut=?");
	$stmt->bindParam(1, $contrasena);
	$stmt->bindParam(2, $estado);
	$stmt->bindParam(3, $rut);
	if($stmt->execute()){
		echo "Usuario actualizado";
	}else{
		echo "no se actualizo";
	}
}elseif($page=='mostrar_noticia'){
	$consulta ="select * from noticias";
	$stmt = $dbh->prepare($consulta);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
		<tr>
	        <td><?php echo $row['id_noticia']; ?></td>
	        <td><?php echo $row['titulo']; ?></td>
	        <td><?php echo $row['contenido']; ?></td>
	        <td><?php echo $row['link']; ?></td>
	        <td><?php echo $row['fecha']; ?></td>
	        <td><?php echo $row['imagen']; ?> <br/> <img src="<?php echo $row['imagen']?>" width="300" height="300" > </td>
	        <td>
				<button  class="btn btn-warning" data-toggle="modal" data-target="#edit-<?php echo $row['id_noticia'] ?>">Editar</button>
				<!-- Modal -->
				<div class="modal fade" id="edit-<?php echo $row['id_noticia'] ?>" tabindex="-1" role="dialog" aria-labelledby="editLabel-<?php echo $row['id_noticia'] ?>">
				  <div class="modal-dialog" role="document">
				    <div class="modal-content">
    			      <div class="modal-header">
				        <h4 class="modal-title" id="editLabel-<?php echo $row['id_noticia'] ?>">Editar datos</h4>
				      </div>
				      <form>
				      <div  class="modal-body">
                           <input type="hidden"  id="<?php echo $row['id_noticia'] ?>" value="<?php echo $row['id_noticia'] ?>">
                       	<div class="form-group">
                            <label for="id_noticia"></label>
                            <input type="text" disabled="disabled" class="form-control" id="id_noticia-<?php echo $row['id_noticia'] ?>" value="<?php echo $row['id_noticia'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Titulo</label>
                            <input type="text" class="form-control" id="titulo-<?php echo $row['id_noticia'] ?>" value="<?php echo $row['titulo'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Contenido</label>
                            <input type="text" class="form-control" id="contenido-<?php echo $row['id_noticia'] ?>" value="<?php echo $row['contenido'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Link</label>
                            <input type="text" class="form-control" id="link-<?php echo $row['id_noticia'] ?>" value="<?php echo $row['link'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Imagen</label>
                            <input type="text" class="form-control" id="imagen-<?php echo $row['id_noticia'] ?>" value="<?php echo $row['imagen'] ?>">
                            
                          </div>
                               
				      </div>
				      <div class="modal-footer">
				        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
				        <button type="submit" onclick="actualizar(<?php echo $row['id_noticia'] ?>)" class="btn btn-primary">Actualizar</button>
				      </div>
				      </form>
				    </div>
				  </div>
				</div>
			</td>
			<td>
				<button class="btn btn-primary" <?php echo 'onclick="eliminar(\''.$row['id_noticia'].'\');"';?>>eliminar</button>
			</td>
	    </tr>
		<?php
	}
}elseif($page=='eliminar_noticia'){
	$id_noticia = $_POST['id_noticia'];
	$consulta ="delete from noticias where id_noticia=?";
	$stmt = $dbh->prepare($consulta);
	$stmt->bindParam(1,$id_noticia);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
    	<tr>
	        <td><?php echo $row['id_noticia'];?></td>
	        <td><?php echo $row['titulo']; ?></td>
	        <td><?php echo $row['contenido']; ?></td>
            <td><?php echo $row['link']; ?></td>
            <td><?php echo $row['imagen']; ?></td>
            <td>
				<button class="btn btn-primary"  <?php echo 'onclick="editar(\''.$row['id_noticia'].'\');"';?>>editar</button>
			</td>
			<td>
				<button class="btn btn-primary" <?php echo 'onclick="eliminar(\''.$row['id_noticia'].'\');"';?>>eliminar</button>
			</td>
	    </tr>
		<?php
	}
}elseif($page=='agregar_noticia'){
	$dato1 = $_POST['titulo'];
	$dato2 = $_POST['contenido'];
	$dato3 = $_POST['link'];
	$dato4 = $_POST['imagen'];

	//buscamos solo el nombre del archivo image
	$stmt = $dbh->prepare("insert into noticias (titulo,contenido,link,fecha,imagen) values(?,?,?,NOW(),?)");
	$stmt->bindParam(1,$dato1);
	$stmt->bindParam(2,$dato2);
	$stmt->bindParam(3,$dato3);
	$stmt->bindParam(4,$dato4);
	if($stmt->execute()){
		echo "Noticia Agregada";
	}else{
		echo "no se agrego";
	}

}elseif($page=='actualizar_noticia'){
	$id_noticia = $_POST['id_noticia'];
	$titulo = $_POST['titulo'];
	$contenido= $_POST['contenido'];
	$link= $_POST['link'];
	$imagen= $_POST['imagen'];
	$stmt = $dbh->prepare("update noticias set  titulo=?, contenido=? , link=?, imagen=? where id_noticia=?");
	$stmt->bindParam(1, $titulo);
	$stmt->bindParam(2, $contenido);
	$stmt->bindParam(3, $link);
	$stmt->bindParam(4, $imagen);
	$stmt->bindParam(5, $id_noticia);
	if($stmt->execute()){
		echo "Noticia actualizada";
	}else{
		echo "no se actualizo";
	}
}elseif($page=='mostrar_pregunta_frecuente'){
	$consulta ="select * from preguntas_frecuentes";
	$stmt = $dbh->prepare($consulta);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
		<tr>
	        <td><?php echo $row['id_pregunta_frecuente']; ?></td>
	        <td><?php echo $row['titulo']; ?></td>
	        <td><?php echo $row['area']; ?></td>
	        <td><?php echo $row['respuesta']; ?></td>
	        <td>
				<button  class="btn btn-warning" data-toggle="modal" data-target="#edit-<?php echo $row['id_pregunta_frecuente'] ?>">Editar</button>
				<!-- Modal -->
				<div class="modal fade" id="edit-<?php echo $row['id_pregunta_frecuente'] ?>" tabindex="-1" role="dialog" aria-labelledby="editLabel-<?php echo $row['id_pregunta_frecuente'] ?>">
				  <div class="modal-dialog" role="document">
				    <div class="modal-content">
    			      <div class="modal-header">
				        <h4 class="modal-title" id="editLabel-<?php echo $row['id_pregunta_frecuente'] ?>">Editar datos</h4>
				      </div>
				      <form>
				      <div  class="modal-body">
                           <input type="hidden"  id="<?php echo $row['id_pregunta_frecuente'] ?>" value="<?php echo $row['id_pregunta_frecuente'] ?>">
                       	<div class="form-group">
                            <label for="id_pregunta_frecuente"></label>
                            <input type="text" disabled="disabled" class="form-control" id="id_pregunta_frecuente-<?php echo $row['id_pregunta_frecuente-'] ?>" value="<?php echo $row['id_pregunta_frecuente'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Pregunta</label>
                            <input type="text" class="form-control" id="titulo-<?php echo $row['id_pregunta_frecuente'] ?>" value="<?php echo $row['titulo'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Area</label>
                            <input type="text" class="form-control" id="area-<?php echo $row['id_pregunta_frecuente'] ?>" value="<?php echo $row['area'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Respuesta</label>
                            <input type="text" class="form-control" id="respuesta-<?php echo $row['id_pregunta_frecuente'] ?>" value="<?php echo $row['respuesta'] ?>">
                          </div>
                               
				      </div>
				      <div class="modal-footer">
				        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
				        <button type="submit" onclick="actualizar(<?php echo $row['id_pregunta_frecuente'] ?>)" class="btn btn-primary">Actualizar</button>
				      </div>
				      </form>
				    </div>
				  </div>
				</div>
			</td>
			<td>
				<button class="btn btn-primary" <?php echo 'onclick="eliminar(\''.$row['id_pregunta_frecuente'].'\');"';?>>eliminar</button>
			</td>
	    </tr>
		<?php
	}
}elseif($page=='eliminar_pregunta_frecuente'){
	$id_pregunta_frecuente = $_POST['id_pregunta_frecuente'];
	$consulta ="delete from preguntas_frecuentes where id_pregunta_frecuente=?";
	$stmt = $dbh->prepare($consulta);
	$stmt->bindParam(1,$id_pregunta_frecuente);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
    	<tr>
	        <td><?php echo $row['id_pregunta_frecuente'];?></td>
	        <td><?php echo $row['titulo']; ?></td>
	        <td><?php echo $row['area']; ?></td>
            <td><?php echo $row['respuesta']; ?></td>
            <td>
				<button class="btn btn-primary"  <?php echo 'onclick="editar(\''.$row['id_pregunta_frecuente'].'\');"';?>>editar</button>
			</td>
			<td>
				<button class="btn btn-primary" <?php echo 'onclick="eliminar(\''.$row['id_pregunta_frecuente'].'\');"';?>>eliminar</button>
			</td>
	    </tr>
		<?php
	}
}elseif($page=='agregar_pregunta_frecuente'){
	$dato1 = $_POST['titulo'];
	$dato2 = $_POST['area'];
	$dato3 = $_POST['respuesta'];
	$stmt = $dbh->prepare("insert into preguntas_frecuentes (titulo,area,respuesta) values(?,?,?)");
	$stmt->bindParam(1,$dato1);
	$stmt->bindParam(2,$dato2);
	$stmt->bindParam(3,$dato3);
	if($stmt->execute()){
		echo "Pregunta Agregada";
	}else{
		echo "no se agrego";
	}

}elseif($page=='actualizar_pregunta_frecuente'){
	$id_pregunta_frecuente = $_POST['id_pregunta_frecuente'];
	$titulo = $_POST['titulo'];
	$area= $_POST['area'];
	$respuesta= $_POST['respuesta'];
	$stmt = $dbh->prepare("update preguntas_frecuentes set  titulo=?, area=? , respuesta=? where id_pregunta_frecuente=?");
	$stmt->bindParam(1, $titulo);
	$stmt->bindParam(2, $area);
	$stmt->bindParam(3, $respuesta);
	$stmt->bindParam(4, $id_pregunta_frecuente);
	if($stmt->execute()){
		echo "Pregunta frecuente actualizada";
	}else{
		echo "no se actualizo";
	}
}elseif($page=='mostrar_responder_preguntas'){
	$consulta ="select * from contactenos ORDER BY id_contactenos desc";
	$stmt = $dbh->prepare($consulta);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
		<tr>
	        <td><?php echo $row['id_contactenos']; ?></td>
	        <td><?php echo $row['rut']; ?></td>
	        <td><?php echo $row['pregunta']; ?></td>
	        <td><?php echo $row['correo']; ?></td>
	        <td><?php echo $row['tipo_pregunta']; ?></td>
	        <td><?php echo $row['Respuesta']; ?></td>
	        <td><?php echo $row['fecha']; ?></td>
	        <td>
				<button  class="btn btn-warning" data-toggle="modal" data-target="#edit-<?php echo $row['id_contactenos'] ?>">Editar</button>
				<!-- Modal -->
				<div class="modal fade" id="edit-<?php echo $row['id_contactenos'] ?>" tabindex="-1" role="dialog" aria-labelledby="editLabel-<?php echo $row['id_contactenos'] ?>">
				  <div class="modal-dialog" role="document">
				    <div class="modal-content">
    			      <div class="modal-header">
				        <h4 class="modal-title" id="editLabel-<?php echo $row['id_contactenos'] ?>">Editar datos</h4>
				      </div>
				      <form>
				      <div  class="modal-body">
                           <input type="hidden"  id="<?php echo $row['id_contactenos'] ?>" value="<?php echo $row['id_contactenos'] ?>">
                       	<div class="form-group">
                            <label for="contrasena"></label>
                            <input type="text" disabled="disabled" class="form-control" id="id_contactenos-<?php echo $row['id_contactenos'] ?>" value="<?php echo $row['id_contactenos'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Rut</label>
                            <input type="text" disabled="disabled" class="form-control" id="rut-<?php echo $row['id_contactenos'] ?>" value="<?php echo $row['rut'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Pregunta</label>
                            <input type="text" disabled="disabled" class="form-control" id="pregunta-<?php echo $row['id_contactenos'] ?>" value="<?php echo $row['pregunta'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Correo</label>
                            <input type="text" disabled="disabled" class="form-control" id="correo-<?php echo $row['id_contactenos'] ?>" value="<?php echo $row['correo'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Tipo Pregunta</label>
                            <input type="text" disabled="disabled" class="form-control" id="tipo_pregunta-<?php echo $row['id_contactenos'] ?>" value="<?php echo $row['tipo_pregunta'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Respuesta</label>
                            <input type="text" class="form-control" id="respuesta-<?php echo $row['id_contactenos'] ?>" value="<?php echo $row['Respuesta'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Fecha</label>
                            <input type="text" disabled="disabled" class="form-control" id="fecha-<?php echo $row['id_contactenos'] ?>" value="<?php echo $row['fecha'] ?>">
                          </div>
                               
				      </div>
				      <div class="modal-footer">
				        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
				        <button type="submit" onclick="actualizar(<?php echo $row['id_contactenos'] ?>)" class="btn btn-primary">Actualizar</button>
				      </div>
				      </form>
				    </div>
				  </div>
				</div>
			</td>
	    </tr>
		<?php
	}
}elseif($page=='actualizar_contactenos'){
	$id_contactenos = $_POST['id_contactenos'];
	$respuesta = $_POST['respuesta'];
	
	$stmt = $dbh->prepare("update contactenos set  Respuesta=? where id_contactenos=?");
	$stmt->bindParam(1, $respuesta);
	$stmt->bindParam(2, $id_contactenos);
	if($stmt->execute()){
		echo "Respuesta actualizada";
	}else{
		echo "no se actualizo";
	}
}elseif($page=='mostrar_oecl'){
	$consulta ="select * from oecl";
	$stmt = $dbh->prepare($consulta);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
		<tr>
	        <td><?php echo $row['id_oecl']; ?></td>
	        <td><?php echo $row['oecl']; ?></td>
	        <td><?php echo $row['direccion']; ?></td>
	        <td><?php echo $row['comuna']; ?></td>
	        <td><?php echo $row['telefono']; ?></td>
	        <td><?php echo $row['celular']; ?></td>
	        <td><?php echo $row['contacto1']; ?></td>
	        <td><?php echo $row['contacto2']; ?></td>
	        <td><?php echo $row['contacto3']; ?></td>
	        <td><?php echo $row['correo1']; ?></td>
	        <td><?php echo $row['correo2']; ?></td>
	        <td><?php echo $row['correo3']; ?></td>

	        <td>
				<button  class="btn btn-warning" data-toggle="modal" data-target="#edit-<?php echo $row['id_oecl'] ?>">Editar</button>
				<!-- Modal -->
				<div class="modal fade" id="edit-<?php echo $row['id_oecl'] ?>" tabindex="-1" role="dialog" aria-labelledby="editLabel-<?php echo $row['id_oecl'] ?>">
				  <div class="modal-dialog" role="document">
				    <div class="modal-content">
    			      <div class="modal-header">
				        <h4 class="modal-title" id="editLabel-<?php echo $row['id_oecl'] ?>">Editar datos</h4>
				      </div>
				      <form>
				      <div  class="modal-body">
                           <input type="hidden"  id="<?php echo $row['id_oecl'] ?>" value="<?php echo $row['id_oecl'] ?>">
                       	<div class="form-group">
                            <label for="id_oecl"></label>
                            <input type="text" disabled="disabled" class="form-control" id="id_oecl-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['id_oecl'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">OECL</label>
                            <input type="text" class="form-control" id="oecl-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['oecl'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Direccion</label>
                            <input type="text" class="form-control" id="direccion-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['direccion'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Comuna</label>
                            <input type="text" class="form-control" id="comuna-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['comuna'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Telefono</label>
                            <input type="text" class="form-control" id="telefono-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['telefono'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Celular</label>
                            <input type="text" class="form-control" id="celular-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['celular'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Contacto1</label>
                            <input type="text" class="form-control" id="contacto1-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['contacto1'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Contacto2</label>
                            <input type="text" class="form-control" id="contacto2-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['contacto2'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Contacto3</label>
                            <input type="text" class="form-control" id="contacto3-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['contacto3'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Correo1</label>
                            <input type="text" class="form-control" id="correo1-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['correo1'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Correo2</label>
                            <input type="text" class="form-control" id="correo2-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['correo2'] ?>">
                          </div>
                          <div class="form-group">
                            <label for="contrasena">Correo3</label>
                            <input type="text" class="form-control" id="correo3-<?php echo $row['id_oecl'] ?>" value="<?php echo $row['correo3'] ?>">
                          </div>
                               
				      </div>
				      <div class="modal-footer">
				        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
				        <button type="submit" onclick="actualizar(<?php echo $row['id_oecl'] ?>)" class="btn btn-primary">Actualizar</button>
				      </div>
				      </form>
				    </div>
				  </div>
				</div>
			</td>
			<td>
				<button class="btn btn-primary" <?php echo 'onclick="eliminar(\''.$row['id_oecl'].'\');"';?>>eliminar</button>
			</td>
	    </tr>
		<?php
	}
}elseif($page=='eliminar_oecl'){
	$id_oecl = $_POST['id_oecl'];
	$consulta ="delete from oecl where id_oecl=?";
	$stmt = $dbh->prepare($consulta);
	$stmt->bindParam(1,$id_oecl);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
    	<tr>
	        <td><?php echo $row['id_oecl'];?></td>
	        <td><?php echo $row['oecl']; ?></td>
	        <td><?php echo $row['direccion']; ?></td>
            <td><?php echo $row['comuna']; ?></td>
            <td><?php echo $row['telefono']; ?></td>
            <td><?php echo $row['celular']; ?></td>
            <td><?php echo $row['contacto1']; ?></td>
            <td><?php echo $row['contacto2']; ?></td>
            <td><?php echo $row['contacto3']; ?></td>
            <td><?php echo $row['correo1']; ?></td>
            <td><?php echo $row['correo2']; ?></td>
            <td><?php echo $row['correo3']; ?></td>
            <td>
				<button class="btn btn-primary"  <?php echo 'onclick="editar(\''.$row['id_oecl'].'\');"';?>>editar</button>
			</td>
			<td>
				<button class="btn btn-primary" <?php echo 'onclick="eliminar(\''.$row['id_oecl'].'\');"';?>>eliminar</button>
			</td>
	    </tr>
		<?php
	}
}elseif($page=='agregar_oecl'){
	$dato1 = $_POST['oecl'];
	$dato2 = $_POST['direccion'];
	$dato3 = $_POST['comuna'];
	$dato4 = $_POST['telefono'];
	$dato5 = $_POST['celular'];
	$dato6 = $_POST['contacto1'];
	$dato7 = $_POST['contacto2'];
	$dato8 = $_POST['contacto3'];
	$dato9 = $_POST['correo1'];
	$dato10 = $_POST['correo2'];
	$dato11 = $_POST['correo3'];
	$stmt = $dbh->prepare("insert into oecl (oecl,direccion,comuna,telefono,celular,contacto1,contacto2,contacto3,correo1,correo2,correo3) values(?,?,?,?,?,?,?,?,?,?,?)");
	$stmt->bindParam(1,$dato1);
	$stmt->bindParam(2,$dato2);
	$stmt->bindParam(3,$dato3);
	$stmt->bindParam(4,$dato4);
	$stmt->bindParam(5,$dato5);
	$stmt->bindParam(6,$dato6);
	$stmt->bindParam(7,$dato7);
	$stmt->bindParam(8,$dato8);
	$stmt->bindParam(9,$dato9);
	$stmt->bindParam(10,$dato10);
	$stmt->bindParam(11,$dato11);

	if($stmt->execute()){
		echo "Oecl Agregada";
	}else{
		echo "no se agrego";
	}

}elseif($page=='actualizar_oecl'){
	$id_oecl = $_POST['id_oecl'];
	$oecl = $_POST['oecl'];
	$direccion = $_POST['direccion'];
	$comuna= $_POST['comuna'];
	$telefono= $_POST['telefono'];
	$celular= $_POST['celular'];
	$contacto1= $_POST['contacto1'];
	$contacto2= $_POST['contacto2'];
	$contacto3= $_POST['contacto3'];
	$correo1= $_POST['correo1'];
	$correo2= $_POST['correo2'];
	$correo3= $_POST['correo3'];
	$stmt = $dbh->prepare("update oecl set  oecl=?, direccion=? , comuna=? , telefono=? , celular=?, contacto1=? , contacto2=? , contacto3=? , correo1=? , correo2=? , correo3=? where id_oecl=?");
	$stmt->bindParam(1, $oecl);
	$stmt->bindParam(2, $direccion);
	$stmt->bindParam(3, $comuna);
	$stmt->bindParam(4, $telefono);
	$stmt->bindParam(5, $celular);
	$stmt->bindParam(6, $contacto1);
	$stmt->bindParam(7, $contacto2);
	$stmt->bindParam(8, $contacto3);
	$stmt->bindParam(9, $correo1);
	$stmt->bindParam(10, $correo2);
	$stmt->bindParam(11, $correo3);
	$stmt->bindParam(12, $id_oecl);
	if($stmt->execute()){
		echo "OECL actualizada";
	}else{
		echo "no se actualizo";
	}
}elseif($page=='mostrar_instalados'){
	$consulta ="select * from registro_instalacion ORDER BY registro_instalacion.id_registro DESC";
	$stmt = $dbh->prepare($consulta);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
		<tr>
	        <td><?php echo $row['id_registro']; ?></td>
	        <td><?php echo $row['rut']; ?></td>
	        <td><?php echo $row['credencial']; ?></td>
	        <td><?php echo $row['numero_telefono']; ?></td>
	        <td><?php echo $row['fecha_instalacion']; ?></td>
	    </tr>
		<?php
	}
}elseif($page=='mostrar_visitas'){
	$consulta ="select * from visita";
	$stmt = $dbh->prepare($consulta);
	$stmt->execute();
	while($row = $stmt->fetch()){
		?>
		<tr>
	        <td><?php echo $row['id']; ?></td>
	        <td><?php echo $row['rut']; ?></td>
	        <td><?php echo $row['fecha']; ?></td>
	    </tr>
		<?php
	}
}







?>