Guest User

Untitled

a guest
Apr 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.93 KB | None | 0 0
  1. <?php
  2.  
  3. include_once 'model/cliente.php';
  4.  
  5. class clienteController {
  6.  
  7. private $model;
  8. public $mensaje;
  9.  
  10. public function __CONSTRUCT() {
  11. $this->model = new cliente();
  12. }
  13.  
  14. public function Paginar() {
  15. require_once 'view/header.php';
  16. require_once 'view/cliente/cliente.php';
  17. }
  18.  
  19. public function agregar() {
  20. $cliente = new cliente();
  21.  
  22. if (isset($_REQUEST['id'])) {
  23. $cliente = $this->model->Obtener($_REQUEST['id']);
  24. }
  25.  
  26. require_once 'view/header.php';
  27. require_once 'view/cliente/cliente-editar.php';
  28. }
  29.  
  30. public function buscar() {
  31. require_once 'view/header.php';
  32. require_once 'view/cliente/cliente.php';
  33. $cliente = new cliente();
  34.  
  35. if (isset($_POST['Nombre'])) {
  36. $cliente = $this->model->Buscarme($_POST['Nombre']);
  37. }
  38. }
  39.  
  40. public function redireccionar() {
  41. require_once 'view/header.php';
  42. require_once 'view/creditos/Resultado.php';
  43. if (isset($_POST['Nombre'])) {
  44. $cliente = $this->model->Resultador($_POST['Nombre']);
  45. }
  46. }
  47.  
  48. public function listador() {
  49. require_once 'view/header.php';
  50. if ($_REQUEST['Nombre'] == "Ardila") {
  51. require_once 'view/cliente/apellidos/Ardila.php';
  52. }
  53. if ($_REQUEST['Nombre'] == "Mateus") {
  54. require_once 'view/cliente/apellidos/Mateus.php';
  55. }
  56. }
  57.  
  58. public function Guardar() {
  59. require_once 'view/header.php';
  60. $cliente = new cliente();
  61. $tamaño=$_FILES['imagen']['size'];
  62. $tipo=$_FILES['imagen']['type'];
  63. if($tamaño <= 3000000){
  64. if($tipo=="image/jpeg"||$tipo=="image/jpg" || $tipo=="image/png" || $tipo=="image/gif"){
  65. $ruta = "view/cliente/imagenes/";
  66. opendir($ruta);
  67.  
  68. $destino = $ruta . $_FILES['imagen']['name'];
  69. copy($_FILES['imagen']['tmp_name'], $destino);
  70. $cliente->id = $_REQUEST['id'];
  71. $cliente->dni = $_REQUEST['dni'];
  72. $cliente->Nombre = $_REQUEST['Nombre'];
  73. $cliente->Apellido = $_REQUEST['Apellido'];
  74. $cliente->Correo = $_REQUEST['Correo'];
  75. $cliente->telefono = $_REQUEST['telefono'];
  76. $cliente->imagen = $_FILES['imagen']['name'];
  77.  
  78. if ($cliente->id > 0) {
  79. $this->model->Actualizar($cliente);
  80. } else {
  81. $this->model->Registrar($cliente);
  82. }
  83. header('Location: index.php');
  84. }
  85. else{
  86. $this->mensaje="FORMATO NO ADMITIDO";
  87. require_once 'view/cliente/imagenes/error.php';
  88. }
  89. }
  90. else{
  91. $this->mensaje="TAMAÑO EXEDIDO";
  92. require_once 'view/cliente/imagenes/error.php';
  93. }
  94.  
  95. }
  96.  
  97. public function Eliminar() {
  98. $this->model->Eliminar($_REQUEST['id']);
  99. unlink($filename);
  100. header('Location: index.php');
  101. }
  102.  
  103. }
  104.  
  105. <?php
  106. class cliente
  107. {
  108. private $pdo;
  109.  
  110. public $id;
  111. public $res;
  112. public $resultado;
  113. public $busqueda;
  114. public $row;
  115. public $dni;
  116. public $Nombre;
  117. public $Apellido;
  118. public $Correo;
  119. public $Telefono;
  120. public $imagen;
  121.  
  122. public function __CONSTRUCT()
  123. {
  124. try
  125. {
  126. $this->pdo = conectar();
  127. }
  128. catch(Exception $e)
  129. {
  130. die($e->getMessage());
  131. }
  132. }
  133.  
  134. public function Listar()
  135. {
  136. try
  137. {
  138. $result = array();
  139. $stm = $this->pdo->prepare("SELECT * FROM cliente");
  140. $stm->execute();
  141. return $stm->fetchAll(PDO::FETCH_OBJ);
  142. }
  143. catch(Exception $e)
  144. {
  145. die($e->getMessage());
  146. }
  147. }
  148.  
  149. public function Resultador($Nombre)
  150. {
  151. try {
  152. $stm = $this->pdo->prepare("SELECT * FROM cliente WHERE Nombre = '$Nombre'");
  153. $stm->execute();
  154. $pagina=$stm->fetch(PDO::FETCH_ASSOC);
  155. $ruta = "view/cliente/registrados/";
  156. $resultado=$pagina['Nombre'];
  157. $solucion = require_once ($ruta.$resultado);
  158. return $solucion;
  159. } catch (Exception $ex) {
  160. die($e->getMessage());
  161. }
  162. }
  163.  
  164. public function Buscarme($Nombre)
  165. {
  166. try {
  167.  
  168.  
  169. $stm = $this->pdo->prepare("SELECT * FROM cliente WHERE Nombre LIKE '%".$Nombre."%'");
  170.  
  171. $stm -> execute();
  172. $res = $stm->fetchAll(PDO::FETCH_ASSOC);
  173. $this->resultado= array();
  174. $i=0;
  175. foreach($res as $row){
  176. $this->resultado[$i]['id'] = $row['id'];
  177. $this->resultado[$i]['dni'] = $row['dni'];
  178. $this->resultado[$i]['Nombre'] = $row['Nombre'] ;
  179. $this->resultado[$i]['Apellido'] = $row['Apellido'];
  180. $this->resultado[$i]['Correo'] = $row['Correo'] ;
  181. $this->resultado[$i]['Telefono'] = $row['Telefono'] ;
  182. $this->resultado[$i]['Imagen'] = $row['Imagen'] ;
  183. $i++;
  184. }
  185.  
  186. } catch (Exception $ex) {
  187. die($e->getMessage());
  188. }
  189. }
  190.  
  191. public function ListarApellido()
  192. {
  193. try
  194. {
  195. $result = array();
  196. $stm = $this->pdo->prepare("SELECT * FROM cliente WHERE Apellido = 'Ardila'");
  197. $stm->execute();
  198. return $stm->fetchAll(PDO::FETCH_OBJ);
  199. }
  200. catch(Exception $e)
  201. {
  202. die($e->getMessage());
  203. }
  204. }
  205.  
  206. public function ListarApellidoM()
  207. {
  208. try
  209. {
  210. $result = array();
  211. $stm = $this->pdo->prepare("SELECT * FROM cliente WHERE Apellido = 'Mateus'");
  212. $stm->execute();
  213. return $stm->fetchAll(PDO::FETCH_OBJ);
  214. }
  215. catch(Exception $e)
  216. {
  217. die($e->getMessage());
  218. }
  219. }
  220. public function Obtener($id){
  221. try
  222. {
  223. $stm = $this->pdo->prepare("SELECT * FROM cliente WHERE id = ?");
  224. $stm->execute(array($id));
  225. return $stm->fetch(PDO::FETCH_OBJ);
  226. } catch (Exception $e)
  227. {
  228. die($e->getMessage());
  229. }
  230. }
  231.  
  232. public function Eliminar($id) {
  233. try {
  234. $ruta = "view/cliente/imagenes/";
  235. opendir($ruta);
  236. $stm = $this->pdo->prepare("SELECT Imagen FROM cliente WHERE id = ?");
  237. $stm->execute(array($id));
  238. $imgdel=$stm->fetch(PDO::FETCH_ASSOC);
  239. unlink($ruta.$imgdel['Imagen']);
  240. $stm = $this->pdo->prepare("DELETE FROM cliente WHERE id = ?");
  241. $stm->execute(array($id));
  242. } catch (Exception $e) {
  243. die($e->getMessage());
  244. }
  245. }
  246.  
  247. public function Actualizar(cliente $data)
  248. {
  249. try
  250. {
  251. $sql = "UPDATE cliente SET dni = ?, Nombre = ?, Apellido = ?, Correo = ?, Telefono = ?, Imagen = ? WHERE id = ?";
  252. $this->pdo->prepare($sql)->execute(array( $data->dni,
  253. $data->Nombre,$data->Apellido,$data->Correo,$data->telefono, $data->imagen, $data->id));
  254. } catch (Exception $e)
  255. {
  256. die($e->getMessage());
  257. }
  258. }
  259.  
  260. public function Registrar(cliente $data)
  261. {
  262. try
  263. {
  264. $sql = "INSERT INTO cliente (dni,Nombre,Apellido,Correo,telefono,Imagen)
  265. VALUES (?, ?, ?, ?, ?, ?)";
  266. $this->pdo->prepare($sql)->execute(array($data->dni, $data->Nombre,$data->Apellido, $data->Correo, $data->telefono,$data->imagen)
  267. );
  268. } catch (Exception $e)
  269. {
  270. die($e->getMessage());
  271. }
  272. }
  273. }
  274.  
  275. </tr>
  276. <?php endforeach; ?>
  277. </tbody>
  278. </table>
  279. <form action="?c=cliente&a=buscar" method="post" >
  280. <input type="text" name="Nombre" id="Nombre"/>
  281. <input type="submit" name="boton" id="boton"/>
  282. </form>
  283. <?php
  284. $this->model->Buscarme(filter_input(INPUT_POST, "Nombre"));
  285. $resultado = $this->model->resultado;
  286. if ($_POST) {
  287. $dni = $_POST['Nombre'];
  288. try {
  289. foreach ($resultado as $f) {
  290. ?>
  291.  
  292. <?php echo $f['id'] . '</br>'; ?>
  293. <?php echo $f['dni'] . '</br>'; ?>
  294. <?php echo '<a href="?c=cliente' . '&a=redireccionar&Nombre=' . urlencode($f['Nombre']) . '">' . $f['Nombre'] . '</a></br>'; ?>
  295. <?php echo $f['Apellido'] . '</br>'; ?>
  296. <?php echo $f['Correo'] . '</br>'; ?>
  297. <?php echo $f['Telefono'] . '</br>'; ?>
  298. <?php echo "<img class='imagen' src="" . "view/cliente/imagenes/" . $f['Imagen'] . ""/>"; ?>
  299. <?php
  300. }
  301. } catch (PDOExecption $e) {
  302. echo $e->getMessage();
  303. }
  304. }
  305. ?>
  306. </tbody>
  307. </body>
  308. <script src="assets/js/datatable.js">
  309. </script>
  310. </html>
Add Comment
Please, Sign In to add comment