Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once 'model/cliente.php';
- class clienteController {
- private $model;
- public $mensaje;
- public function __CONSTRUCT() {
- $this->model = new cliente();
- }
- public function Paginar() {
- require_once 'view/header.php';
- require_once 'view/cliente/cliente.php';
- }
- public function agregar() {
- $cliente = new cliente();
- if (isset($_REQUEST['id'])) {
- $cliente = $this->model->Obtener($_REQUEST['id']);
- }
- require_once 'view/header.php';
- require_once 'view/cliente/cliente-editar.php';
- }
- public function buscar() {
- require_once 'view/header.php';
- require_once 'view/cliente/cliente.php';
- $cliente = new cliente();
- if (isset($_POST['Nombre'])) {
- $cliente = $this->model->Buscarme($_POST['Nombre']);
- }
- }
- public function redireccionar() {
- require_once 'view/header.php';
- require_once 'view/creditos/Resultado.php';
- if (isset($_POST['Nombre'])) {
- $cliente = $this->model->Resultador($_POST['Nombre']);
- }
- }
- public function listador() {
- require_once 'view/header.php';
- if ($_REQUEST['Nombre'] == "Ardila") {
- require_once 'view/cliente/apellidos/Ardila.php';
- }
- if ($_REQUEST['Nombre'] == "Mateus") {
- require_once 'view/cliente/apellidos/Mateus.php';
- }
- }
- public function Guardar() {
- require_once 'view/header.php';
- $cliente = new cliente();
- $tamaño=$_FILES['imagen']['size'];
- $tipo=$_FILES['imagen']['type'];
- if($tamaño <= 3000000){
- if($tipo=="image/jpeg"||$tipo=="image/jpg" || $tipo=="image/png" || $tipo=="image/gif"){
- $ruta = "view/cliente/imagenes/";
- opendir($ruta);
- $destino = $ruta . $_FILES['imagen']['name'];
- copy($_FILES['imagen']['tmp_name'], $destino);
- $cliente->id = $_REQUEST['id'];
- $cliente->dni = $_REQUEST['dni'];
- $cliente->Nombre = $_REQUEST['Nombre'];
- $cliente->Apellido = $_REQUEST['Apellido'];
- $cliente->Correo = $_REQUEST['Correo'];
- $cliente->telefono = $_REQUEST['telefono'];
- $cliente->imagen = $_FILES['imagen']['name'];
- if ($cliente->id > 0) {
- $this->model->Actualizar($cliente);
- } else {
- $this->model->Registrar($cliente);
- }
- header('Location: index.php');
- }
- else{
- $this->mensaje="FORMATO NO ADMITIDO";
- require_once 'view/cliente/imagenes/error.php';
- }
- }
- else{
- $this->mensaje="TAMAÑO EXEDIDO";
- require_once 'view/cliente/imagenes/error.php';
- }
- }
- public function Eliminar() {
- $this->model->Eliminar($_REQUEST['id']);
- unlink($filename);
- header('Location: index.php');
- }
- }
- <?php
- class cliente
- {
- private $pdo;
- public $id;
- public $res;
- public $resultado;
- public $busqueda;
- public $row;
- public $dni;
- public $Nombre;
- public $Apellido;
- public $Correo;
- public $Telefono;
- public $imagen;
- public function __CONSTRUCT()
- {
- try
- {
- $this->pdo = conectar();
- }
- catch(Exception $e)
- {
- die($e->getMessage());
- }
- }
- public function Listar()
- {
- try
- {
- $result = array();
- $stm = $this->pdo->prepare("SELECT * FROM cliente");
- $stm->execute();
- return $stm->fetchAll(PDO::FETCH_OBJ);
- }
- catch(Exception $e)
- {
- die($e->getMessage());
- }
- }
- public function Resultador($Nombre)
- {
- try {
- $stm = $this->pdo->prepare("SELECT * FROM cliente WHERE Nombre = '$Nombre'");
- $stm->execute();
- $pagina=$stm->fetch(PDO::FETCH_ASSOC);
- $ruta = "view/cliente/registrados/";
- $resultado=$pagina['Nombre'];
- $solucion = require_once ($ruta.$resultado);
- return $solucion;
- } catch (Exception $ex) {
- die($e->getMessage());
- }
- }
- public function Buscarme($Nombre)
- {
- try {
- $stm = $this->pdo->prepare("SELECT * FROM cliente WHERE Nombre LIKE '%".$Nombre."%'");
- $stm -> execute();
- $res = $stm->fetchAll(PDO::FETCH_ASSOC);
- $this->resultado= array();
- $i=0;
- foreach($res as $row){
- $this->resultado[$i]['id'] = $row['id'];
- $this->resultado[$i]['dni'] = $row['dni'];
- $this->resultado[$i]['Nombre'] = $row['Nombre'] ;
- $this->resultado[$i]['Apellido'] = $row['Apellido'];
- $this->resultado[$i]['Correo'] = $row['Correo'] ;
- $this->resultado[$i]['Telefono'] = $row['Telefono'] ;
- $this->resultado[$i]['Imagen'] = $row['Imagen'] ;
- $i++;
- }
- } catch (Exception $ex) {
- die($e->getMessage());
- }
- }
- public function ListarApellido()
- {
- try
- {
- $result = array();
- $stm = $this->pdo->prepare("SELECT * FROM cliente WHERE Apellido = 'Ardila'");
- $stm->execute();
- return $stm->fetchAll(PDO::FETCH_OBJ);
- }
- catch(Exception $e)
- {
- die($e->getMessage());
- }
- }
- public function ListarApellidoM()
- {
- try
- {
- $result = array();
- $stm = $this->pdo->prepare("SELECT * FROM cliente WHERE Apellido = 'Mateus'");
- $stm->execute();
- return $stm->fetchAll(PDO::FETCH_OBJ);
- }
- catch(Exception $e)
- {
- die($e->getMessage());
- }
- }
- public function Obtener($id){
- try
- {
- $stm = $this->pdo->prepare("SELECT * FROM cliente WHERE id = ?");
- $stm->execute(array($id));
- return $stm->fetch(PDO::FETCH_OBJ);
- } catch (Exception $e)
- {
- die($e->getMessage());
- }
- }
- public function Eliminar($id) {
- try {
- $ruta = "view/cliente/imagenes/";
- opendir($ruta);
- $stm = $this->pdo->prepare("SELECT Imagen FROM cliente WHERE id = ?");
- $stm->execute(array($id));
- $imgdel=$stm->fetch(PDO::FETCH_ASSOC);
- unlink($ruta.$imgdel['Imagen']);
- $stm = $this->pdo->prepare("DELETE FROM cliente WHERE id = ?");
- $stm->execute(array($id));
- } catch (Exception $e) {
- die($e->getMessage());
- }
- }
- public function Actualizar(cliente $data)
- {
- try
- {
- $sql = "UPDATE cliente SET dni = ?, Nombre = ?, Apellido = ?, Correo = ?, Telefono = ?, Imagen = ? WHERE id = ?";
- $this->pdo->prepare($sql)->execute(array( $data->dni,
- $data->Nombre,$data->Apellido,$data->Correo,$data->telefono, $data->imagen, $data->id));
- } catch (Exception $e)
- {
- die($e->getMessage());
- }
- }
- public function Registrar(cliente $data)
- {
- try
- {
- $sql = "INSERT INTO cliente (dni,Nombre,Apellido,Correo,telefono,Imagen)
- VALUES (?, ?, ?, ?, ?, ?)";
- $this->pdo->prepare($sql)->execute(array($data->dni, $data->Nombre,$data->Apellido, $data->Correo, $data->telefono,$data->imagen)
- );
- } catch (Exception $e)
- {
- die($e->getMessage());
- }
- }
- }
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <form action="?c=cliente&a=buscar" method="post" >
- <input type="text" name="Nombre" id="Nombre"/>
- <input type="submit" name="boton" id="boton"/>
- </form>
- <?php
- $this->model->Buscarme(filter_input(INPUT_POST, "Nombre"));
- $resultado = $this->model->resultado;
- if ($_POST) {
- $dni = $_POST['Nombre'];
- try {
- foreach ($resultado as $f) {
- ?>
- <?php echo $f['id'] . '</br>'; ?>
- <?php echo $f['dni'] . '</br>'; ?>
- <?php echo '<a href="?c=cliente' . '&a=redireccionar&Nombre=' . urlencode($f['Nombre']) . '">' . $f['Nombre'] . '</a></br>'; ?>
- <?php echo $f['Apellido'] . '</br>'; ?>
- <?php echo $f['Correo'] . '</br>'; ?>
- <?php echo $f['Telefono'] . '</br>'; ?>
- <?php echo "<img class='imagen' src="" . "view/cliente/imagenes/" . $f['Imagen'] . ""/>"; ?>
- <?php
- }
- } catch (PDOExecption $e) {
- echo $e->getMessage();
- }
- }
- ?>
- </tbody>
- </body>
- <script src="assets/js/datatable.js">
- </script>
- </html>
Add Comment
Please, Sign In to add comment