Advertisement
Guest User

Untitled

a guest
May 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.45 KB | None | 0 0
  1. <?php
  2.     include("../include/database.php");
  3.     $webQuery = $_GET['query'];
  4.     if($webQuery != null)
  5.     {
  6.         global $database, $session;
  7.        
  8.         if($webQuery == "news")    
  9.         {
  10.             $result = $database->getNews();
  11.             $json = "";
  12.             echo "{ \"news\": [";
  13.             while($row = mysql_fetch_array($result))
  14.             {
  15.                 $json .= "{";
  16.                 $json .= "\"date\": \"".$row[0]."\",";
  17.                 $json .= "\"title\": \"".$row[1]."\",";
  18.                 $json .="\"content\": \"".$row[2]."\",";
  19.                 $json .="\"username\": \"".$row[3]."\",";
  20.                 $json .="\"email\": \"".$row[4]."\"";
  21.                 $json .="},";
  22.             }
  23.             $json = substr_replace($json,"",-1);
  24.             echo $json;
  25.             echo "]}";
  26.         }
  27.         else if($webQuery == "adduser")
  28.         {
  29.             $username = $_GET['username'];
  30.             $password = $_GET['password'];
  31.             $email = $_GET['email'];
  32.             $contactemail = $_GET['contactemail'];
  33.            
  34.             $result = $database->addUser($username, $password, $email, $contactemail);
  35.            
  36.             echo "{ \"status\" : \"".$result."\" }";
  37.         }
  38.         else if($webQuery == "login")
  39.         {
  40.             $username = $_GET['username'];
  41.             $password = $_GET['password'];
  42.            
  43.             $result = $database->login($username, $password);
  44.            
  45.             echo "{ \"status\" : \"".$result."\" }";
  46.         }
  47.         else if($webQuery == "addLocation")
  48.         {
  49.             $username = $_GET['username'];
  50.             $password = $_GET['password'];
  51.             $lat = $_GET['lat'];
  52.             $lng = $_GET['lng'];
  53.            
  54.             $result = $database->addLocation($username, $password, $lat, $lng);
  55.            
  56.             echo "{ \"status\" : \"".$result."\" }";
  57.         }
  58.         else if($webQuery == "addtimer")
  59.         {
  60.             $username = $_GET['username'];
  61.             $password = $_GET['password'];
  62.             $interval = $_GET['interval'];
  63.            
  64.             $result = $database->addTimer($username, $password, $interval);
  65.            
  66.             echo "{ \"status\" : \"".$result."\" }";
  67.         }
  68.         else if($webQuery == "removetimer")
  69.         {
  70.             $username = $_GET['username'];
  71.             $password = $_GET['password'];
  72.            
  73.             $result = $database->removeTimer($username, $password);
  74.            
  75.             echo "{ \"status\" : \"".$result."\" }";
  76.         }
  77.         else if($webQuery == "users")
  78.         {
  79.             $input = $_GET['input'];
  80.  
  81.             if($input != null)
  82.             {
  83.                 $results = $database->getUsers($input);
  84.                
  85.                 echo "{\"results\": [";
  86.                 $arr = array();
  87.                 while($row = mysql_fetch_array($results))
  88.                 {
  89.                      $arr[] = "{\"id\": \"" .$row['Id'] . "\", \"value\": \"" . $row['username'] . "\", \"info\": \"\"}";
  90.                 }
  91.                 echo implode(", ", $arr);
  92.                 echo "]}";
  93.             }
  94.         }
  95.         else if($webQuery == "announcements")
  96.         {
  97.             $input = $_GET['input'];
  98.  
  99.             if($input != null)
  100.             {
  101.                 $results = $database->query("SELECT News.Id, News.Title, News.Content FROM News WHERE News.Title LIKE '$input%' LIMIT 10");
  102.                
  103.                 echo "{\"results\": [";
  104.                 $arr = array();
  105.                 while($row = mysql_fetch_array($results))
  106.                 {
  107.                      $arr[] = "{\"id\": \"" .$row['Id'] . "\", \"value\": \"" . $row['Title'] . "\", \"info\": \"" . $row['Content'] . "\"}";
  108.                 }
  109.                 echo implode(", ", $arr);
  110.                 echo "]}";
  111.             }
  112.         }
  113.         else if($webQuery = "sexoffender")
  114.         {
  115.             $url = $_GET['url'];
  116.             $url = urldecode($url);
  117.             $url = str_replace(" ", "%20", $url);
  118.  
  119.             $r = new HttpRequest($url, HttpRequest::METH_GET);
  120.             try {
  121.                 $r->send();
  122.                 if ($r->getResponseCode() == 200)
  123.                 {
  124.                     $json = json_decode($r->getResponseBody(), true);
  125.                     $arr = array();
  126.                     print("{identifier:'registrant',label:'registrant',items:[");
  127.                     for($i=0; $i<sizeof($json["records"]); $i++)
  128.                     {
  129.                         $arr[] = "{registrant:\"" . $json["records"][$i]["registrant"] .
  130.                         "\",oci:\"" . $json["records"][$i]["oci"] .
  131.                         "\",last_name:\"" . $json["records"][$i]["last_name"] .
  132.                         "\",first_name:\"" . $json["records"][$i]["first_name"] .
  133.                         "\",middle_name:\"" . $json["records"][$i]["middle_name"] .
  134.                         "\",gender:\"" . $json["records"][$i]["gender"] .
  135.                         "\",tier:\"" . $json["records"][$i]["tier"] .
  136.                         "\",county:\"" . $json["records"][$i]["county"] .
  137.                         "\",race:\"" . $json["records"][$i]["race"] .
  138.                         "\",hair_color:\"" . $json["records"][$i]["hair_color"] .
  139.                         "\",height_inches:\"" . $json["records"][$i]["height_inches"] .
  140.                         "\",weight_pounds:\"" . $json["records"][$i]["weight_pounds"] .
  141.                         "\",eye_color:\"" . $json["records"][$i]["eye_color"] .
  142.                         "\",skin_tone:\"" . $json["records"][$i]["skin_tone"] .
  143.                         "\",last_changed:\"" . $json["records"][$i]["last_changed"] .
  144.                         "\",address:\"" . $json["records"][$i]["address"] .
  145.                         "\",birthdate:\"" . $json["records"][$i]["birthdate"] .
  146.                         "\",lat:\"" . $json["records"][$i]["lat"] .
  147.                         "\",lon:\"" . $json["records"][$i]["lon"] .
  148.                         "\",victim_minors:\"" . $json["records"][$i]["victim_minors"] .
  149.                         "\",victim_adults:\"" . $json["records"][$i]["victim_adults"] .
  150.                         "\",victim_uknown:\"" . $json["records"][$i]["victim_uknown"] .
  151.                         "\",registrant_cluster:\"" . $json["records"][$i]["registrant_cluster"] .
  152.                         "\",photo:\"" . $json["records"][$i]["photo"] .
  153.                         "\",distance:\"" . $json["records"][$i]["distance"] .
  154.                         "\"}";
  155.                     }
  156.  
  157.                     print(implode(",", $arr));
  158.                     print("]}");
  159.                 }
  160.             } catch (HttpException $ex) {
  161.                 print($ex);
  162.             }
  163.             session_write_close();
  164.         }
  165.         else if($webQuery = "passthrough")
  166.         {
  167.             $url = $_GET['url'];
  168.             $url = urldecode($url);
  169.             $url = str_replace(" ", "%20", $url);
  170.  
  171.             $r = new HttpRequest($url, HttpRequest::METH_GET);
  172.             try {
  173.                 $r->send();
  174.                 if ($r->getResponseCode() == 200) {
  175.                     print($r->getResponseBody());
  176.                 }
  177.             } catch (HttpException $ex) {
  178.                 print($ex);
  179.             }
  180.             session_write_close();
  181.         }
  182.     }
  183. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement