Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include_once ("../System_Connector.php");
- include_once ("Admin_Session_Checker.php");
- include_once ("../GeoPlugin.php");
- include "../Android_Scripts/Notifications/Push_User_Notification.php";
- require "Geocoding.php";
- use MyPHPnotes\Geocoding;
- $geo = new Geocoding("AIzaSyDWboaopVJ1-AqV9wKp8RMBkFCpO10QKPM");
- $Latitude_Mean = array();
- $Longitude_Mean = array();
- if(isset($_POST['Approve_Submit'])){
- $message = "Your Report has been approved! Please wait for the fire fighters to respond!";
- if(!empty($_POST['checked_id'])){
- $ID_List = implode(',', $_POST['checked_id']);
- //echo "<script type = 'text/javascript'> alert('Error: $ID_List') </script>";
- $Fire_Incident_ID = NULL;
- //RETRIEVES ALL LATITUDE AND LONGITUDES OF ALL SELECTED REPORTS
- $Retrieval_Query = "SELECT * FROM Report WHERE Report_ID IN ($ID_List)";
- $Retrieval_Location = mysqli_query($Connection, $Retrieval_Query);
- if(!$Retrieval_Location){
- echo "<script type = 'text/javascript'> alert('Error: Could not retrieve data from database because of this error: '".mysqli_error($Connection)."') </script>";
- }
- while ($Report_Row = mysqli_fetch_array($Retrieval_Location, MYSQLI_ASSOC)){
- $Report_Latitude = $Report_Row['Report_Latitude'];
- $Report_Longitude = $Report_Row['Report_Longitude'];
- $Reporter = $Report_Row['User_ID'];
- array_push($Latitude_Mean, $Report_Latitude);
- array_push($Longitude_Mean, $Report_Longitude);
- $Retrieve_User_Query = "SELECT * FROM User WHERE User_ID = $Reporter";
- $Retrieve_User = mysqli_query($Connection, $Retrieve_User_Query);
- if(!$Retrieve_User){
- echo "<script type = 'text/javascript'> alert('Server Error: Could not retrieve data from database of this error: '".mysqli_error($Connection)."') </script>";
- }
- while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
- $User_Token[] = $User_Row['User_Token'];
- }
- $tokens = implode(",", $User_Token);
- }
- send_notification($tokens, $message);
- $Mean_Latitude = array_sum($Latitude_Mean) / count($Latitude_Mean);
- $Mean_Longitude = array_sum($Longitude_Mean) / count($Longitude_Mean);
- $Location = $geo->getAddress($Mean_Latitude, $Mean_Longitude);
- //INSERTS A FIRE INCIDENT
- $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)";
- $Insert_Fire_Incident = mysqli_query($Connection, $Insert_Fire_Incident_Query);
- if(!$Insert_Fire_Incident){
- echo "<script type = 'text/javascript'> alert('Error: Could not insert data into database of this error: '".mysqli_error($Connection)."') </script>";
- }
- $Fire_ID = mysqli_insert_id($Connection);
- //UPDATES THE REPORT ROW
- $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)";
- $Report_Update_Query = mysqli_query($Connection, $Report_Query);
- if(!$Report_Update_Query){
- echo "<script type = 'text/javascript'> alert('Server Error: Could not update data from database because of this error: '".mysqli_error($Connection)."') </script>";
- }
- $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')";
- $Activated_Query = mysqli_query($Connection, $Admin_Activity);
- if(!$Activated_Query){
- echo "<script type = 'text/javascript'> alert('Error: Could not insert activity data from database because of this error: '".mysqli_error($Connection)."') </script>";
- }
- echo "<script type = 'text/javascript'> alert('Successfully approved the selected fire reports.') </script>";
- echo "<meta http-equiv='refresh' content='0;url=Report_Management.php'>";
- }else{
- echo "<script type = 'text/javascript'> alert('Error: Select at least one report.') </script>";
- }
- }
- elseif(isset($_POST['Disapprove_Submit'])){
- $message = "Your Report has been rejected by an admin!";
- if(!empty($_POST['checked_id'])){
- $ID_List = implode(',', $_POST['checked_id']);
- //echo "<script type = 'text/javascript'> alert('Error: $ID_List') </script>";
- $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)";
- $Report_Update_Query = mysqli_query($Connection, $Report_Query);
- if(!$Report_Update_Query){
- echo "<script type = 'text/javascript'> alert('Server Error: Could not update data from database because of this error: '".mysqli_error($Connection)."') </script>";
- }
- $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')";
- $Activated_Query = mysqli_query($Connection, $Admin_Activity);
- if(!$Activated_Query){
- echo "<script type = 'text/javascript'> alert('Server Error: Could not insert activity data from database because of this error: '".mysqli_error($Connection)."') </script>";
- }
- echo "<script type = 'text/javascript'> alert('Successfully rejected the selected fire reports.') </script>";
- echo "<meta http-equiv='refresh' content='0;url=Report_Management.php'>";
- }
- }
- else{
- echo "<script type = 'text/javascript'> alert('Error: Select at least one report first.') </script>";
- echo "<meta http-equiv='refresh' content='0;url=Report_Management.php'>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement