SHARE
TWEET

Lefitel

a guest Jul 20th, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*
  4. Just edit everything below to set everything up for your server. Else, don't touch the script
  5. unless you know what you're doing.
  6. */
  7.  
  8. define('MYSQL_BOTH',MYSQLI_BOTH);
  9. define('MYSQL_NUM',MYSQLI_NUM);
  10. define('MYSQL_ASSOC',MYSQLI_ASSOC);
  11. header('Content-type:application/json;charset=utf-8');
  12.  
  13. $host = "localhost"; //The host of your SQL server. Usually localhost
  14. $user = "admin_info"; //The user of your SQL server.
  15. $password = "Carloselpeor1"; //The password to the user of your SQL server.
  16. $database = "admin_info"; //Your GunBound database name
  17. /* Parametros */
  18. /* estatico */
  19. $opt = $_GET['opt'];
  20.  
  21. $link = new mysqli($host,$user,$password,$database); //mysql_connect($host,$user,$password);
  22. $link->set_charset("utf8");
  23. if(!$link){ mysql_error(); die();}
  24.  
  25. /* Se realizan todas las consultas aqui*/
  26. $regid = $link->real_escape_string(stripslashes($_GET['login']));
  27. $regpass = $link->real_escape_string(stripslashes($_GET['password']));
  28. /* 1 = updateLocation(); -- 99 = updateLogin(); -- 90 = disconcect() */
  29. if ($opt == 9){
  30.     //mb_internal_encoding('UTF-8');
  31.     $login = $link->real_escape_string(stripslashes($_GET['login']));
  32.     $password = $link->real_escape_string(stripslashes($_GET['password']));
  33.     $login = mb_strtolower($login, 'UTF-8');
  34.     $result = "SELECT count(id) as existe FROM empleado WHERE login = '$login' AND PASSWORD = '$password'";
  35.     $runsql = $link->query($result);//$mysql_query($sql);
  36.     $infosql = mysqli_fetch_array($runsql, MYSQL_ASSOC);
  37.     //die(implode("|",$infosql));
  38.     $count = $infosql['existe'];
  39.     if($count>0){
  40.         $getID = "SELECT id FROM empleado WHERE login = '$login' AND PASSWORD = '$password'";
  41.         $runsql = $link->query($getID);//$mysql_query($sql);
  42.         $infosql = mysqli_fetch_array($runsql, MYSQL_ASSOC);
  43.         $checkid = $infosql['id'];
  44.         $consulta = "UPDATE `admin_info`.`empleado` SET `estado`='1' WHERE  `id`='$checkid'";
  45.         $runsql = $link->query($consulta);
  46.         $response = array(
  47.         'id' => $checkid,
  48.         'message' => 'ok'
  49.         );
  50.         die(json_encode($response));
  51.         //die(implode("|",$checkid));
  52.     } else {
  53.         $response = array(
  54.         'id' => 0,
  55.         'message' => 'Datos incorrectos'
  56.         );
  57.         die(json_encode($response));
  58.     }
  59.    
  60. }
  61. if ($opt == 1){//Se actualiza la ubicacion del empleado
  62.     $id = $link->real_escape_string(stripslashes($_GET['id']));
  63.     $latitud = $link->real_escape_string(stripslashes($_GET['latitud']));
  64.     $longitud = $link->real_escape_string(stripslashes($_GET['longitud']));
  65.     $consulta = "UPDATE `admin_info`.`movil` SET `latitud`='$latitud', `longitud`='$longitud' WHERE  `idTaxista`='$id'";
  66.     $runsql = $link->query($consulta);//$mysql_query($sql);
  67.     //$infosql = mysqli_fetch_array($runsql, MYSQL_ASSOC);
  68.     $response = array(
  69.         'estado' => 'ok'
  70.         );
  71.         die(json_encode($response));
  72. }
  73. if ($opt == 90){// El empleado ha apagado el aparato
  74.     $id = $link->real_escape_string(stripslashes($_GET['id']));
  75.     $consulta = "UPDATE `admin_info`.`empleado` SET `estado`='0' WHERE  `id`='$id'";
  76.     $runsql = $link->query($consulta);//$mysql_query($sql);
  77.     //$infosql = mysqli_fetch_array($runsql, MYSQL_ASSOC);
  78.     $response = array(
  79.         'estado' => 'off'
  80.         );
  81.         die(json_encode($response));
  82. }
  83. if ($opt == 5) {//Guardar Viaje
  84.     $id = $link->real_escape_string(stripslashes($_GET['id']));
  85.     $latitudInicio = $link->real_escape_string(stripslashes($_GET['latitudInicio']));
  86.     $longitudInicio = $link->real_escape_string(stripslashes($_GET['longitudInicio']));
  87.     $latitudFin = $link->real_escape_string(stripslashes($_GET['latitudFin']));
  88.     $longitudFin = $link->real_escape_string(stripslashes($_GET['longitudFin']));
  89.     $consulta = "INSERT INTO `admin_info`.`bitacora` (`id`, `latitudInicio`, `longitudInicio`, `latitudFin`, `longitudFin`) VALUES ('$id', '$latitudInicio', '$longitudInicio', '$latitudFin', '$longitudFin')";
  90.     $runsql = $link->query($consulta);//$mysql_query($sql);
  91.     //$infosql = mysqli_fetch_array($runsql, MYSQL_ASSOC);
  92.     $response = array(
  93.         'estado' => 'ok'
  94.         );
  95.         die(json_encode($response));
  96. }
  97. if ($opt == 3) {//Corregir reconexion
  98.     $id = $link->real_escape_string(stripslashes($_GET['id']));
  99.     $estado = $link->real_escape_string(stripslashes($_GET['estado']));
  100.     $consulta = "UPDATE `admin_info`.`empleado` SET `estado`='$estado' WHERE  `id`='$id'";
  101.     $runsql = $link->query($consulta);//$mysql_query($sql);
  102.     //$infosql = mysqli_fetch_array($runsql, MYSQL_ASSOC);
  103.     $response = array(
  104.         'estado' => 'ok'
  105.         );
  106.         die(json_encode($response));
  107. }
  108. if ($opt == 2){//Se pide auxilio
  109.     $id = $link->real_escape_string(stripslashes($_GET['id']));
  110.     $latitud = $link->real_escape_string(stripslashes($_GET['latitud']));
  111.     $longitud = $link->real_escape_string(stripslashes($_GET['longitud']));
  112.     $consulta = "INSERT INTO `admin_info`.`auxilio` (`id`, `latitud`, `longitud`) VALUES ('$id', '$latitud', '$longitud')";
  113.     $runsql = $link->query($consulta);//$mysql_query($sql);
  114.     $consulta = "UPDATE `admin_info`.`empleado` SET `icono`='https://i.imgur.com/IdaKTDs.png?1' WHERE  `id`='$id'";
  115.     $runsql = $link->query($consulta);//$mysql_query($sql);
  116.     //$infosql = mysqli_fetch_array($runsql, MYSQL_ASSOC);
  117.     /*
  118.     Lista de Iconos
  119.     Normal: https://i.imgur.com/3O18sMg.png?1
  120.     Auxilio: https://i.imgur.com/IdaKTDs.png?1
  121.     */
  122.     /*                 WhatsApp API                       */
  123.     $INSTANCE_ID = '18';  // TODO: Replace it with your gateway instance ID here
  124.     $CLIENT_ID = "underbolivia@gmail.com";  // TODO: Replace it with your Forever Green client ID here
  125.     $CLIENT_SECRET = "145a581793ee447298bb4ed8760588bf";
  126.     $headers = array(
  127.     'Content-Type: application/json',
  128.     'X-WM-CLIENT-ID: '.$CLIENT_ID,
  129.     'X-WM-CLIENT-SECRET: '.$CLIENT_SECRET
  130.   );
  131.     $url = 'http://api.whatsmate.net/v3/whatsapp/single/image/message/' . $INSTANCE_ID;
  132.   $ch = curl_init($url);
  133.   curl_setopt($ch, CURLOPT_POST, 1);
  134.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  135.   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  136.  
  137.     $getIcon = "SELECT img, nombres, apellidos, telefono from empleado WHERE id = '$id'";
  138.     $rsql = $link->query($getIcon);//$mysql_query($sql);
  139.     $isql = mysqli_fetch_array($rsql, MYSQL_ASSOC);
  140.     $icono = $isql['img'];
  141.     $myNombres = $isql['nombres'].' '.$isql['apellidos'];
  142.     $myTelefono = $isql['telefono'];
  143.     //echo $icono;
  144.     //echo $myNombres;
  145.     $pathToImage = "https://lefitel.site/img/empleado/".$icono;
  146.     //echo $pathToImage;
  147.     $imageData = file_get_contents($pathToImage);
  148.     $base64Image = base64_encode($imageData);
  149.     //echo $base64Image;
  150.     /* Send Data*/
  151.     $consulta = "SELECT telefono FROM empleado WHERE estado = '1'";
  152.     $resultado = $link->query($consulta);
  153.     while ($row = $resultado->fetch_assoc()) {
  154.         $postData = array(
  155.               'number' => '+591'.$row["telefono"],  // TODO: Specify the recipient's number here. NOT the gateway number
  156.               'image' => $base64Image,
  157.               'caption' => '¬°¬°Necesito tu ayuda!!, abajo esta mi ubicacion. Mi numero de telefono es: '.$myTelefono.' Mi nombre es: '.$myNombres.' Mi ubicacion: http://www.google.com/maps/place/'.$latitud.','.$longitud
  158.               /*'message' => 'http://www.google.com/maps/place/'.$latitud.','.$longitud*/
  159.             );
  160.             curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
  161.             $response = curl_exec($ch);
  162.             /*echo "Response: ".$response." Se envio al numero: ".$row["telefono"];*/
  163.     }
  164.     //$link->close();
  165.     //echo "Response: ".$response;
  166.     curl_close($ch);
  167.    
  168.     $response = array(
  169.         'estado' => 'ok'
  170.         );
  171.         die(json_encode($response));
  172. }
  173. if ($opt == 8){//Se actualiza icono
  174.     $id = $link->real_escape_string(stripslashes($_GET['id']));
  175.     $consulta = "UPDATE `admin_info`.`empleado` SET `icono`='https://i.imgur.com/3O18sMg.png?1' WHERE  `id`='$id'";
  176.     $runsql = $link->query($consulta);
  177.     $response = array(
  178.         'estado' => 'ok'
  179.         );
  180.         die(json_encode($response));
  181. }
  182. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top