Advertisement
Guest User

Report_Status.php

a guest
Nov 12th, 2018
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include_once ("../System_Connector.php");
  4. include_once ("Admin_Session_Checker.php");
  5. include_once ("../GeoPlugin.php");
  6. include "../Android_Scripts/Notifications/Push_User_Notification.php";
  7. require "Geocoding.php";
  8. use MyPHPnotes\Geocoding;
  9. $geo = new Geocoding("AIzaSyDWboaopVJ1-AqV9wKp8RMBkFCpO10QKPM");
  10.  
  11. $Latitude_Mean = array();
  12. $Longitude_Mean = array();
  13.  
  14. if(isset($_POST['Approve_Submit'])){
  15. $message = "Your Report has been approved! Please wait for the fire fighters to respond!";
  16. if(!empty($_POST['checked_id'])){
  17. $ID_List = implode(',', $_POST['checked_id']);
  18. //echo "<script type = 'text/javascript'> alert('Error: $ID_List') </script>";
  19. $Fire_Incident_ID = NULL;
  20.  
  21. //RETRIEVES ALL LATITUDE AND LONGITUDES OF ALL SELECTED REPORTS
  22. $Retrieval_Query = "SELECT * FROM Report WHERE Report_ID IN ($ID_List)";
  23. $Retrieval_Location = mysqli_query($Connection, $Retrieval_Query);
  24.  
  25. if(!$Retrieval_Location){
  26. echo "<script type = 'text/javascript'> alert('Error: Could not retrieve data from database because of this error: '".mysqli_error($Connection)."') </script>";
  27. }
  28.  
  29. while ($Report_Row = mysqli_fetch_array($Retrieval_Location, MYSQLI_ASSOC)){
  30. $Report_Latitude = $Report_Row['Report_Latitude'];
  31. $Report_Longitude = $Report_Row['Report_Longitude'];
  32. $Reporter = $Report_Row['User_ID'];
  33.  
  34. array_push($Latitude_Mean, $Report_Latitude);
  35. array_push($Longitude_Mean, $Report_Longitude);
  36.  
  37. $Retrieve_User_Query = "SELECT * FROM User WHERE User_ID = $Reporter";
  38. $Retrieve_User = mysqli_query($Connection, $Retrieve_User_Query);
  39.  
  40. if(!$Retrieve_User){
  41. echo "<script type = 'text/javascript'> alert('Server Error: Could not retrieve data from database of this error: '".mysqli_error($Connection)."') </script>";
  42. }
  43.  
  44. while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
  45. $User_Token[] = $User_Row['User_Token'];
  46. }
  47. $tokens = implode(",", $User_Token);
  48. }
  49. send_notification($tokens, $message);
  50.  
  51. $Mean_Latitude = array_sum($Latitude_Mean) / count($Latitude_Mean);
  52. $Mean_Longitude = array_sum($Longitude_Mean) / count($Longitude_Mean);
  53.  
  54. $Location = $geo->getAddress($Mean_Latitude, $Mean_Longitude);
  55.  
  56. //INSERTS A FIRE INCIDENT
  57. $Insert_Fire_Incident_Query = "INSERT INTO Fire_Incident (Fire_Incident_Latitude_Mean, Fire_Incident_Longitude_Mean, Fire_Incident_Location, Fire_Date, Fire_Time, Fire_Status) VALUES ('$Mean_Latitude', '$Mean_Longitude', '$Location', NOW(), '$Time', 1)";
  58. $Insert_Fire_Incident = mysqli_query($Connection, $Insert_Fire_Incident_Query);
  59.  
  60. if(!$Insert_Fire_Incident){
  61. echo "<script type = 'text/javascript'> alert('Error: Could not insert data into database of this error: '".mysqli_error($Connection)."') </script>";
  62. }
  63.  
  64. $Fire_ID = mysqli_insert_id($Connection);
  65.  
  66. //UPDATES THE REPORT ROW
  67. $Report_Query = "UPDATE Report SET Report_Status = 2, Fire_Incident = '$Fire_ID', Admin_ID = '$SQL_Admin_ID', Date_Checked = '$Date', Time_Checked = '$Time' WHERE Report_ID IN ($ID_List)";
  68. $Report_Update_Query = mysqli_query($Connection, $Report_Query);
  69.  
  70. if(!$Report_Update_Query){
  71. echo "<script type = 'text/javascript'> alert('Server Error: Could not update data from database because of this error: '".mysqli_error($Connection)."') </script>";
  72. }
  73.  
  74. $Admin_Activity = "INSERT INTO Administrator_Activities(Activity_By_Admin,Activity_IP_Address,Activity_Description,Activity_Date,Activity_Time,Activity_Country,Activity_Region,Activity_City) VALUES('$SQL_Admin_ID','$IP', 'Flagged a report as positive. Report ID is - $ID_List', NOW(), '$Time', '$Admin_Country','$Admin_Region','$Admin_City')";
  75. $Activated_Query = mysqli_query($Connection, $Admin_Activity);
  76. if(!$Activated_Query){
  77. echo "<script type = 'text/javascript'> alert('Error: Could not insert activity data from database because of this error: '".mysqli_error($Connection)."') </script>";
  78. }
  79.  
  80. echo "<script type = 'text/javascript'> alert('Successfully approved the selected fire reports.') </script>";
  81. echo "<meta http-equiv='refresh' content='0;url=Report_Management.php'>";
  82.  
  83. }else{
  84. echo "<script type = 'text/javascript'> alert('Error: Select at least one report.') </script>";
  85. }
  86. }
  87.  
  88. elseif(isset($_POST['Disapprove_Submit'])){
  89. $message = "Your Report has been rejected by an admin!";
  90. if(!empty($_POST['checked_id'])){
  91. $ID_List = implode(',', $_POST['checked_id']);
  92. //echo "<script type = 'text/javascript'> alert('Error: $ID_List') </script>";
  93.  
  94. $Report_Query = "UPDATE Report SET Report_Status = 3, Admin_ID = '$SQL_Admin_ID', Date_Checked = '$Date', Time_Checked = '$Time' WHERE Report_ID IN ($ID_List)";
  95. $Report_Update_Query = mysqli_query($Connection, $Report_Query);
  96.  
  97. if(!$Report_Update_Query){
  98. echo "<script type = 'text/javascript'> alert('Server Error: Could not update data from database because of this error: '".mysqli_error($Connection)."') </script>";
  99. }
  100.  
  101. $Admin_Activity = "INSERT INTO Administrator_Activities(Activity_By_Admin,Activity_IP_Address,Activity_Description,Activity_Date,Activity_Time,Activity_Country,Activity_Region,Activity_City) VALUES('$SQL_Admin_ID','$IP', 'Flagged a report as positive. Report ID is - $ID_List', NOW(), '$Time', '$Admin_Country','$Admin_Region','$Admin_City')";
  102. $Activated_Query = mysqli_query($Connection, $Admin_Activity);
  103.  
  104. if(!$Activated_Query){
  105. echo "<script type = 'text/javascript'> alert('Server Error: Could not insert activity data from database because of this error: '".mysqli_error($Connection)."') </script>";
  106. }
  107.  
  108. echo "<script type = 'text/javascript'> alert('Successfully rejected the selected fire reports.') </script>";
  109. echo "<meta http-equiv='refresh' content='0;url=Report_Management.php'>";
  110. }
  111. }
  112. else{
  113. echo "<script type = 'text/javascript'> alert('Error: Select at least one report first.') </script>";
  114. echo "<meta http-equiv='refresh' content='0;url=Report_Management.php'>";
  115. }
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement