comparador.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. require 'shared/extraeInfo.php';
  3. $accesoPortal = new AccesoPortal();
  4. error_reporting(0);
  5. if (isset($_POST['compare'])) {
  6. $arrComparador = json_decode($_POST['compare'],true);
  7. $arrJson = $_POST['compare'];
  8. if (!empty($arrComparador)) {
  9. foreach ($arrComparador as $key => $datos) {
  10. foreach ($datos as $key => $detalles) {
  11. $idx = $detalles['Id'];
  12. $model = $detalles['Model'];
  13. $serie = $detalles['codSerie'];
  14. $categoria = $detalles['catId'];
  15. $imagen = $accesoPortal->compara($model,$idx,$serie,$categoria);
  16. }
  17. }
  18. ?>
  19. <div class="row">
  20. <div id="compare" class="section">
  21. <div class="container title-only">
  22. <div class="row">
  23. <div class="col-md-12 section-title">
  24. <h2 id="compare-fans-header">Comparar ventiladores</h2>
  25. <hr>
  26. </div>
  27. </div>
  28. <div class="saved-container">
  29. <div class="row">
  30. <div class="col-md-5">
  31. <div class="saved-chart-container" style="margin-bottom:30px">
  32. <?php if(!empty($imagen)) echo $imagen; ?>
  33. </div>
  34. </div>
  35. <div class="col-md-7">
  36. <div class="saved-grid-container">
  37. <table id="saved-grid" style="width:100%;" class="table table-hover table-striped dt-responsive no-wrap">
  38. </table>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. <script>
  47. if (compareEnabled) {
  48. $j("#saved-grid").DataTable({
  49. language: {
  50. url: 'js/0.js'
  51. },
  52. searching: false,
  53. lengthChange: false,
  54. data: [],
  55. responsive: {
  56. details: {
  57. type: 'column'
  58. },
  59. },
  60. rowId: 'RowId',
  61. columns: [
  62. {
  63. title: "", data: "Id", orderable: false, render: function (data, type, full, meta) {
  64. return "<a class=\"delete-saved\" style=\"cursor: pointer;\" onclick=\"removeFan(" + data + ")\" data-val=\"" + data + "\"><i class=\"fa fa-times\" aria-hidden=\"true\"></i></a>";
  65. }
  66. },
  67. { data: "Model", title: ColumnCode, visible: true },
  68. { data: "Description", title: ColumnDescription, visible: true }
  69. /*{
  70. title: "", data: "Id", orderable: false, render: function (data, type, full, meta) {
  71. return "<a style=\"cursor: pointer;\" class='tree quickview btn btn-primary btn-xs' data-val=\"" + data + "\"><i class=\"fa fa-search\" aria-hidden=\"true\"></i> " + ViewStr + "</a>";
  72. // return ;
  73. }
  74. }*/
  75. ]
  76. });
  77. var $grid = $j('#saved-grid').DataTable();
  78. $grid.clear();
  79. //pasamos el array de php a Js
  80. var datos = '<?php echo $arrJson ?>';
  81. //le damos formato tipo json
  82. var res = datos.split('"').join("'");
  83. var json = JSON.stringify(eval("(" + res + ")"));
  84. arrToJson = JSON.parse(json);
  85. //los agregamos a la tabla
  86. for (var i = 0; i < arrToJson.datos.length; i++) {
  87. $grid.row.add(arrToJson.datos[i]).draw();
  88. }
  89. //desaparecer comparador si no tenemos datos
  90. if (Object.keys(arrToJson.datos).length === 0) {
  91. $j("#comparador").hide();
  92. }
  93. }
  94. </script>
  95. <?php
  96. }
  97. }
  98. // Imprimimos el modelo en 3D
  99. if (isset($_POST['url'])) {
  100. $url = trim($_POST['url']);
  101. // Mandamos a llamar el método getTablas
  102. $accesoPortal->buscarInfo($url);
  103. }
  104. // Extraer la tabla de modelos
  105. if (isset($_POST['table'])) {
  106. $url = $_POST['table'];
  107. extraerTabla($url);
  108. }
  109. function extraerTabla($url){
  110. require_once 'shared/conexionBD.php';
  111. //hacemos una consulta para obtener los modelos de hábitat
  112. mysqli_query($conexion, "SET NAMES utf8");
  113. $idProducto = $_POST['id'];
  114. $queryConsulta = "SELECT IDPROD, DATATABLE, FECHAMOD FROM ITT_ASW_EASYVENT WHERE IDPROD = '" . trim($idProducto) . "'";
  115. $resultado = mysqli_query($conexion, $queryConsulta) or die("Algo ha ido mal en la consulta a la base de datos");
  116. $arrTabla = array();
  117. while ($columna = mysqli_fetch_assoc($resultado)) {
  118. $arrTabla[] = $columna;
  119. }
  120. if(!empty($arrTabla)){
  121. echo $arrTabla[0]['DATATABLE'];
  122. }/* else{
  123. $exito = false;
  124. $errorDescripcion = '';
  125. // Los servidores se obtuvieron de la página https://www.proxyscan.io/ ** Todos son de México
  126. $arrProxies = array(); // Lista de Proxies para realizar las peticiones
  127. //$arrProxies[0]['proxyAndPuerto'] = '187.188.168.57:9991'; // No funciona (puede servir para realizar pruebas del ciclo)
  128. //$arrProxies[0]['tipoProxy'] = CURLPROXY_SOCKS4;
  129. // $arrProxies[0]['proxyAndPuerto'] = '190.9.54.24:5678';
  130. // $arrProxies[0]['tipoProxy'] = CURLPROXY_SOCKS4;
  131. // $arrProxies[1]['proxyAndPuerto'] = '187.216.90.46:5678';
  132. // $arrProxies[1]['tipoProxy'] = CURLPROXY_SOCKS4;
  133. // $arrProxies[2]['proxyAndPuerto'] = '201.148.28.17:5678';
  134. // $arrProxies[2]['tipoProxy'] = CURLPROXY_SOCKS4;
  135. // $arrProxies[3]['proxyAndPuerto'] = '187.189.81.246:4153';
  136. // $arrProxies[3]['tipoProxy'] = CURLPROXY_SOCKS4;
  137. // $arrProxies[4]['proxyAndPuerto'] = '187.217.39.66:5678';
  138. // $arrProxies[4]['tipoProxy'] = CURLPROXY_SOCKS4;
  139. // $arrProxies[5]['proxyAndPuerto'] = '177.242.150.6:5678';
  140. // $arrProxies[5]['tipoProxy'] = CURLPROXY_SOCKS4;
  141. // Proxy No Disponible
  142. // $arrProxies[0]['proxyAndPuerto'] = '169.57.64.4:3128';
  143. // $arrProxies[0]['tipoProxy'] = CURLPROXY_HTTP;
  144. // Los servidores se obtuvieron de la página http://proxydb.net/?country=MX ** Todos son de México
  145. $arrProxies[0]['proxyAndPuerto'] = '201.159.22.164:46809';
  146. $arrProxies[0]['tipoProxy'] = CURLPROXY_SOCKS4;
  147. $arrProxies[1]['proxyAndPuerto'] = '201.144.20.231:5678';
  148. $arrProxies[1]['tipoProxy'] = CURLPROXY_SOCKS4;
  149. $arrProxies[2]['proxyAndPuerto'] = '45.167.253.129:999';
  150. $arrProxies[2]['tipoProxy'] = CURLPROXY_HTTPS;
  151. $totalProxies = count($arrProxies) - 1;
  152. for ($i = 0; $i <= $totalProxies; $i++) {
  153. //echo $arrProxies[$i]['proxyAndPuerto'].'<br>';
  154. $ch = curl_init();
  155. curl_setopt($ch, CURLOPT_URL, $url); // Dirección URL a capturar
  156. curl_setopt($ch, CURLOPT_PROXY, $arrProxies[$i]['proxyAndPuerto']); // El proxy HTTP para enviar peticiones a través de tunel.
  157. curl_setopt($ch, CURLOPT_PROXYTYPE, $arrProxies[$i]['tipoProxy']); // Puede ser CURLPROXY_HTTP (por defecto), CURLPROXY_SOCKS4, CURLPROXY_SOCKS5, CURLPROXY_SOCKS4A o CURLPROXY_SOCKS5_HOSTNAME
  158. curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Número máximo de segundos permitido para ejectuar funciones cURL
  159. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); // Número de segundos a esperar cuando se está intentado conectar. Use 0 para esperar indefinidamente
  160. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // "true" para seguir cualquier encabezado "Location: " que el servidor envíe como parte del encabezado HTTP (observe la recursividad, PHP seguirá tantos header "Location: " como se envíen, a no ser que la opción CURLOPT_MAXREDIRS esté establecida)
  161. //curl_setopt($ch, CURLOPT_MAXREDIRS, 10); // Número máximo de redirecciones HTTP a seguir. Use esta opción con CURLOPT_FOLLOWLOCATION
  162. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // "true" para devolver el resultado de la transferencia como string del valor de curl_exec() en lugar de mostrarlo directamente
  163. $data = curl_exec($ch); // Ejecuta la sesión cURL que se le pasa como parámetro
  164. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Obtener información sobre una transferencia específica -> El último código de respuesta. A partir de PHP 5.5.0 y cURL 7.10.8, este es un alias heredado de CURLINFO_RESPONSE_CODE
  165. curl_close($ch); // Cierra la sesión cURL
  166. if (($httpcode >= 200) && ($httpcode < 300)) {
  167. $contenido = $data;
  168. if ($contenido) {
  169. $tablaHTML = "<div class='section section-grey'>";
  170. $seccionGris = strstr($contenido, "section section-grey");
  171. $removeFooter = strstr($seccionGris, "section cookie-warning", true);
  172. $tablaHTML .= ("<div class=\" " . $removeFooter . "\" >");
  173. $tablaHTML .= "</div>";
  174. $tablaHTML = str_replace("'", '"', $tablaHTML);
  175. $exito = true;
  176. $idProducto = $_POST['id'];
  177. $fechaMod = date("Y-m-d H:i:s");
  178. // $queryUpdate = "UPDATE ITT_ASW_EASYVENT SET DATATABLE = '" . trim($tablaHTML) . "', FECHAMOD = '" . trim($fechaMod) . "' WHERE (IDPROD = '" . trim($idProducto) . "');";
  179. $queryInsert = "INSERT INTO ITT_ASW_EASYVENT (IDPROD, DATATABLE, FECHAMOD) VALUES ('" . trim($idProducto) . "', '" . trim($tablaHTML) . "', '" . trim($fechaMod) . "');";
  180. if (mysqli_query($conexion, $queryInsert)) {
  181. var_dump('TEST REGISTRO');
  182. }
  183. echo $queryInsert;
  184. } else {
  185. $exito = false;
  186. }
  187. goto fin_extraerTabla;
  188. }else{
  189. $exito = false;
  190. }
  191. } // Fin del ciclo
  192. fin_extraerTabla :
  193. if($exito == false){
  194. if(empty($errorDescripcion)){
  195. echo "<p style='text-align: center;'>Los servidores proxy dejarón de funcionar. Por favor contacte con al administrador del sistema si el problema continua.</p>";
  196. }else{
  197. echo $errorDescripcion;
  198. }
  199. }
  200. } */
  201. }
  202. ?>