PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/neaticketwebapp/lib/form3New.php

https://gitlab.com/cesardemora/neaticketwebapphomeEs
PHP | 296 lines | 227 code | 61 blank | 8 comment | 33 complexity | d33dd7881463cf15febac1c7be1de820 MD5 | raw file
  1. <?php
  2. $clase = new connect;
  3. $clase->dbConnects();
  4. /* capturar variable por método GET */
  5. if (isset($_GET['pos']))
  6. $ini=$_GET['pos'];
  7. else
  8. $ini=1;
  9. $url = basename($_SERVER ["PHP_SELF"]);
  10. $limit_end = 15;
  11. $init = ($ini-1) * $limit_end;
  12. if(isset($_POST['AgregarCliente'])){
  13. $email = $_POST['email'];
  14. $nick = $_POST['nick'];
  15. $pass = generaPass();
  16. $sql = "INSERT INTO CLIENTES (mail,nombre,password) values ('$email','$nick','$pass')";
  17. if(! $con->query($sql))
  18. die('Ocurrio un error ejecutando el query [' . $con->error . ']');
  19. else{
  20. $cabecera = "<h1><strong>Cliente</strong> añadido </h1>";
  21. enviar_correo($email, $pass);
  22. }
  23. } else {
  24. $cabecera = "<h1>Buscador de <strong>Clientes</strong></h1>";
  25. }
  26. ?>
  27. <div class="container">
  28. <!-- <h2>Lista de usuarios</h2> -->
  29. <div class="jumbotron">
  30. <?php echo $cabecera; ?>
  31. <!-- Table -->
  32. <div class="table-responsive">
  33. <table class="table">
  34. <?php
  35. $funcion = $campo = $valor = "";
  36. if(isset($_GET['BuscarAlta'])){
  37. $funcion = 'BuscarAlta';
  38. $campo = 'fecha_alta';
  39. $valor = $_GET['fecha_alta'];
  40. $result = mysql_query("SELECT * FROM CLIENTES WHERE fecha_alta LIKE '$valor%' LIMIT $init, $limit_end");
  41. $count = "SELECT COUNT(*) FROM CLIENTES WHERE fecha_alta LIKE '$valor%'";
  42. }
  43. if(isset($_GET['BuscarCliente'])){
  44. $funcion = 'BuscarCliente';
  45. $campo = 'email';
  46. $valor = $_GET['email'];
  47. $result = mysql_query("SELECT * FROM CLIENTES WHERE mail LIKE '%$valor%' LIMIT $init, $limit_end");
  48. $count = "SELECT COUNT(*) FROM CLIENTES WHERE mail LIKE '%$valor%'";
  49. }
  50. if ($row = mysql_fetch_array($result)){
  51. $num = $con->query($count);
  52. $x = $num->fetch_array();
  53. $total = ceil($x[0]/$limit_end);
  54. echo "<thead><tr>
  55. <td><strong>Email</strong></td>
  56. <td><strong>Sexo</strong></td>
  57. <td><strong>Rango Edad</strong></td>
  58. <td><strong>A. Ofertas</strong></td>
  59. <td><strong>A. Correos</strong></td>
  60. <td><strong>A. Devol.</strong></td>
  61. <td><strong>A. Garantías</strong></td>
  62. <td><strong>Fecha Alta</strong></td>
  63. </tr></thead>";
  64. do {
  65. if ($row['recibir_ofertas'] == "1")
  66. $ofertas = "Sí";
  67. else
  68. $ofertas = "No";
  69. if ($row['recibir_correos'] == "1")
  70. $correos = "Sí";
  71. else
  72. $correos = "No";
  73. if ($row['recibir_devoluciones'] == "1")
  74. $devol = "Sí";
  75. else
  76. $devol = "No";
  77. if ($row['recibir_garantias'] == "1")
  78. $garantias = "Sí";
  79. else
  80. $garantias = "No";
  81. $date = date("d/m/Y", strtotime($row['fecha_alta']));
  82. ?>
  83. <td><a href="index_buscarTicketsNew.php?mailCliente=<?php echo $row['mail']; ?>"><?php echo $row['mail']; ?></a></td>
  84. <?php
  85. echo '<td>'.$row['sexo'].'</td>';
  86. echo '<td>'.$row['edad'].'</td>';
  87. echo '<td>'.$ofertas.'</td>';
  88. echo '<td>'.$correos.'</td>';
  89. echo '<td>'.$devol.'</td>';
  90. echo '<td>'.$garantias.'</td>';
  91. echo '<td>'.$date.'</td>';
  92. echo '</tr>';
  93. } while ($row = mysql_fetch_array($result));
  94. } else {
  95. echo "¡ No se ha encontrado ningún registro !";
  96. }
  97. ?>
  98. </table>
  99. <div class="row">
  100. <div class="col-md-8"></div>
  101. <div class="col-md-4">
  102. <?php
  103. if ($total > 1){
  104. /* numeración de registros [importante]*/
  105. echo '<ul class="pagination">';
  106. /****************************************/
  107. if(($ini - 1) == 0){
  108. echo "<li><a href='#'>&laquo;</a></li>";
  109. }else{
  110. echo "<li><a href='$url?pos=".($ini-1)."&$campo=$valor&$funcion'><b>&laquo;</b></a></li>";
  111. }
  112. /****************************************/
  113. $fin = $ini +4;
  114. if($fin >= $total)
  115. $fin = $total;
  116. for($k= $ini; $k <= $fin; $k++){
  117. if($ini == $k){
  118. echo "<li class='active'><a href='#'><b>".$k."</b></a></li>";
  119. }else{
  120. echo "<li><a href='$url?pos=$k&$campo=$valor&$funcion'>".$k."</a></li>";
  121. }
  122. }
  123. /****************************************/
  124. if($ini == $total){
  125. echo "<li><a href='#'>&raquo;</a></li>";
  126. }else{
  127. echo "<li><a href='$url?pos=".($ini+1)."&$campo=$valor&$funcion='><b>&raquo;</b></a></li>";
  128. }
  129. /*******************END*******************/
  130. echo "</ul>";
  131. }
  132. ?>
  133. </div>
  134. </div>
  135. </div>
  136. <div class="form-group"><br>
  137. <a href="index_usersNew.php"><button name="boton2" id="boton2" type="button" class="btn">
  138. <span class="typcn typcn-arrow-left"></span> Volver</button></a>
  139. </div>
  140. </div>
  141. </div>
  142. <?php
  143. function generaPass(){
  144. $str = "1234567890";
  145. $cadena = "";
  146. for($i=0;$i<=5;$i++) {
  147. $cadena .= substr($str,rand(0,10),1);
  148. }
  149. return $cadena;
  150. }
  151. function enviar_correo($para, $pass){
  152. require_once ("lib/class.phpmailer.php");
  153. $mail = new PHPMailer(true);
  154. $name = "NEATICKET"; // También puede ser un campo del formulario como asunto o mensaje.
  155. $password = "147258369";
  156. $SPLangDir = "phpmailer/language/";
  157. $subject = "Nuevo Usuario de Neaticket";
  158. $Mensage = "<html><head>"
  159. . "<title>Neaticket</title>"
  160. . "</head>"
  161. . "<body>"
  162. . "<div style=\"color:#000000; text-align: center;\">"
  163. . "<img src=\"http://www.neaticket.com/assetsNew/img/logo_neatNew2.png\" /><hr>"
  164. . "<h2>Bienvenido a <b>Neaticket!</b></h2></div>"
  165. . "<div style=\"color:#000000;\">"
  166. . "Si recibes esto es porque recientemente has aceptado un ticket electrónico en el comercio asociado a <b>Neaticket:</b><br><br>"
  167. . "</div>"
  168. . "<div style=\"color:#000000;\">"
  169. . "Comercio: <b>".$_SESSION['nombre_empresa']."</b><br>"
  170. . "Telefono:".$_SESSION['telefono'].""
  171. . "</div><br>"
  172. . "<div style=\"color:#000000;\">"
  173. . "Ya puedes entrar en www.neaticket.com y gestionar tus tickets con las siguentes claves:"
  174. . "</div>"
  175. . "<div style=\"color:#000000;\">"
  176. . "<h3>Usuario: ".$para."<br>"
  177. . "Contraseña: <font color=#3366BB>".$pass."</font></h3>"
  178. . "</div>"
  179. . "<div style=\"color:#000000;\">Ten en cuenta que a partir de ahora encontrarás tus tickets electrónicos en www.neaticket.com<br>"
  180. . "Y recuerda que tienes disponible nuestra app gratuita que te ayuda a gestionar las fechas de devolución y garantía, "
  181. . "además de informarte de las ofertas de tus establecimientos favoritos.</div>"
  182. . "<div style=\"color:#000000; text-align: center;\">"
  183. . "<h3>Descarga <b>Neaticket </b>en:</h3>"
  184. . "<a href=\"http://bit.ly/1X8u6Br\" width=\"50%\" height=\"50%\" />"
  185. . "<img src=\"http://quikcu.com/wp-content/themes/responsivo/img/app_google.png\" width=\"140\" /></a>"
  186. . "<a href=\"http://bit.ly/1X8u6Br\" width=\"50%\" height=\"50%\" />"
  187. . "<img src=\"http://quikcu.com/wp-content/themes/responsivo/img/app_ios.png\" width=\"140\" /></a>"
  188. . "</div><br>"
  189. . "<div style=\"color:#000000;\">"
  190. . "Gracias por comprar en <b>".$_SESSION['nombre_empresa'].".</b><br>"
  191. . "</div>"
  192. . "<div style=\"color:#000000;\">"
  193. . "<i>El Equipo Neaticket.</i><hr>"
  194. . "<div>"
  195. . "<div style=\"color:#696969; font-size:11px; text-align: center;\">"
  196. . "<em>Copyright © 2015 www.neaticket.com - All rights reserved</em>"
  197. . "</div>"
  198. . "</body></html>";
  199. $mail->IsSendMail();
  200. $mail->SetLanguage("es", $SPLangDir); // Set mailer to use SMTP
  201. $mail->Host = 'smtp.1and1.es'; // Specify main and backup SMTP servers
  202. $mail->SMTPAuth = true; // Enable SMTP authentication
  203. $mail->Username = "info@neaticket.com"; // SMTP username
  204. $mail->Password = "147258369"; // SMTP password
  205. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  206. $mail->Port = 587;
  207. $mail->SetFrom('info@neaticket.com', 'Neaticket');
  208. $mail->From = "info@neaticket.com";
  209. $mail->FromName = utf8_decode($name);
  210. $mail->AddAddress("$para"); // Esta es la dirección a donde enviamos.
  211. $mail->SMTPDebug = 2;
  212. $mail->MailerDebug = false; // XXXXXXXXXXXXXXXXXXXXXX
  213. $mail->hSubject = $subject; // Este es el titulo del email. Vamos el asunto.
  214. $mail->CharSet = "utf-8";
  215. $mail->IsHTML(true);
  216. $mail->Subject = $subject; // Este es el titulo del email. Vamos el asunto.
  217. $mail->Body = $Mensage; // Mensaje a enviar. Yo aquí uso la plantilla que te comentaba.
  218. $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  219. // Si tenemos que enviar archivos adjuntos.
  220. //$mail->AddAttachment("$archivo_de_salida");
  221. if ($mail->Send()) {
  222. echo "<script language='javascript'>
  223. alert('Se le ha enviado un correo al cliente, muchas gracias.');
  224. </script>";
  225. } else {
  226. error_log($mail->ErrorInfo, 0);
  227. $result .= "<b class='red'>Hubo un inconveniente.</b><br />".$mail->ErrorInfo."Por favor,
  228. inténtalo más tarde.<br /><br />Recuerde que puede ponerse en contacto con nosotros por teléfono
  229. o directamente por correo electrónico.<br />Perdonen por las molestias causadas.";
  230. echo "<script language='javascript'>
  231. alert('.$result.');
  232. </script>";
  233. }
  234. }
  235. ?>