Compare commits

..

10 Commits

9 changed files with 522 additions and 91 deletions

View File

@ -29,7 +29,7 @@ CREATE TABLE `alerts` (
PRIMARY KEY (`alert_id`), PRIMARY KEY (`alert_id`),
KEY `fk_alertsunittype` (`utype_id`), KEY `fk_alertsunittype` (`utype_id`),
CONSTRAINT `fk_alertsunittype` FOREIGN KEY (`utype_id`) REFERENCES `unittypes` (`utype_id`) CONSTRAINT `fk_alertsunittype` FOREIGN KEY (`utype_id`) REFERENCES `unittypes` (`utype_id`)
) ENGINE=InnoDB AUTO_INCREMENT=70 DEFAULT CHARSET=latin1; ) ENGINE=InnoDB AUTO_INCREMENT=84 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -46,6 +46,28 @@ CREATE TABLE `datacenters` (
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `event_updates`
--
DROP TABLE IF EXISTS `event_updates`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `event_updates` (
`update_id` int(11) NOT NULL AUTO_INCREMENT,
`update_desc` text,
`update_date_time` varchar(99) DEFAULT NULL,
`update_is_ongoing` tinyint(1) DEFAULT NULL,
`end_date_time` varchar(99) DEFAULT NULL,
`event_id` int(11) DEFAULT NULL,
`update_user` varchar(99) DEFAULT NULL,
`update_image` varchar(255) NOT NULL,
PRIMARY KEY (`update_id`),
KEY `fk_updatevent` (`event_id`),
CONSTRAINT `fk_updatevent` FOREIGN KEY (`event_id`) REFERENCES `events` (`event_id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
-- --
-- Table structure for table `events` -- Table structure for table `events`
-- --
@ -62,6 +84,7 @@ CREATE TABLE `events` (
`date_time_end` varchar(99) DEFAULT NULL, `date_time_end` varchar(99) DEFAULT NULL,
`user` varchar(99) NOT NULL, `user` varchar(99) NOT NULL,
`alert_id` int(11) DEFAULT NULL, `alert_id` int(11) DEFAULT NULL,
`event_image` varchar(255) NOT NULL,
PRIMARY KEY (`event_id`), PRIMARY KEY (`event_id`),
KEY `user` (`user`), KEY `user` (`user`),
KEY `fk_eventunit` (`unit_id`), KEY `fk_eventunit` (`unit_id`),
@ -70,7 +93,7 @@ CREATE TABLE `events` (
KEY `date_time_end` (`date_time_end`), KEY `date_time_end` (`date_time_end`),
CONSTRAINT `fk_eventalert` FOREIGN KEY (`alert_id`) REFERENCES `alerts` (`alert_id`), CONSTRAINT `fk_eventalert` FOREIGN KEY (`alert_id`) REFERENCES `alerts` (`alert_id`),
CONSTRAINT `fk_eventunit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`unit_id`) CONSTRAINT `fk_eventunit` FOREIGN KEY (`unit_id`) REFERENCES `units` (`unit_id`)
) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=latin1; ) ENGINE=InnoDB AUTO_INCREMENT=69 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -117,4 +140,4 @@ CREATE TABLE `unittypes` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2015-04-05 19:08:30 -- Dump completed on 2015-05-07 23:35:03

View File

@ -17,9 +17,17 @@ if( $_SESSION['access'] != 1 ) {
<script src="includes/js/dtp/jquery.datetimepicker.js"></script> <script src="includes/js/dtp/jquery.datetimepicker.js"></script>
<title>Add BMS Event</title> <title>Add BMS Event</title>
<script> <script>
$(function() { $(document).ready(function() {
$('#start_date_time').datetimepicker(); $('#start_date_time').datetimepicker();
$('#end_date_time').datetimepicker(); $('#end_date_time').datetimepicker();
$('#select_form').submit(function(event) {
if (!$("#is_ongoing").prop("checked") && $("#end_date_time").val() === "") {
alert('You must enter a value for Currently Ongoing or End Date and Time');
event.preventDefault();
return false;
}
});
}); });
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
@ -106,7 +114,7 @@ if( $_SESSION['access'] != 1 ) {
</div> </div>
<?php include "includes/classes/select.class.php";?> <?php include "includes/classes/select.class.php";?>
<br /> <br />
<form id="select_form" required method="post" action="includes/insert_event1.php"> <form id="select_form" required method="post" action="includes/insert_event.php" enctype="multipart/form-data">
<table align="center"> <table align="center">
<tr> <tr>
<td> <td>
@ -161,6 +169,7 @@ if( $_SESSION['access'] != 1 ) {
Issue Description: Issue Description:
</td> </td>
<td> <td>
<!-- <input type="text" name="description" id="description" required /> --!>
<textarea name="description" id="description" cols="40" rows="5" required></textarea> <textarea name="description" id="description" cols="40" rows="5" required></textarea>
</td> </td>
</tr> </tr>
@ -180,6 +189,14 @@ if( $_SESSION['access'] != 1 ) {
<input type="text" name="end_date_time" id="end_date_time" /> <input type="text" name="end_date_time" id="end_date_time" />
</td> </td>
</tr> </tr>
<tr>
<td>
Attach an Image:
</td>
<td>
<input type="file" name="fileToUpload" id="fileToUpload" />
</td>
</tr>
<tr> <tr>
<td colspan="2" class="ui-helper-center"> <td colspan="2" class="ui-helper-center">
<input type="submit" value="Add Event" /> <input type="submit" value="Add Event" />

View File

@ -18,9 +18,17 @@ if( $_SESSION['access'] != 1 ) {
<script src="includes/js/dtp/jquery.datetimepicker.js"></script> <script src="includes/js/dtp/jquery.datetimepicker.js"></script>
<title>Edit BMS Event</title> <title>Edit BMS Event</title>
<script> <script>
$(function() { $(document).ready(function() {
$('#start_date_time').datetimepicker(); $('#start_date_time').datetimepicker();
$('#end_date_time').datetimepicker(); $('#end_date_time').datetimepicker();
$('#select_form').submit(function(event) {
if (!$("#is_ongoing").prop("checked") && $("#end_date_time").val() === "") {
alert('You must enter a value for Currently Ongoing or End Date and Time');
event.preventDefault();
return false;
}
});
}); });
</script> </script>
</head> </head>
@ -63,7 +71,7 @@ if( $_SESSION['access'] != 1 ) {
} }
include "includes/classes/select2.class.php"; ?> include "includes/classes/select2.class.php"; ?>
<br /> <br />
<form id="select_form" required method="post" action="includes/update_event1.php"> <form id="select_form" required method="post" action="includes/update_event.php" enctype="multipart/form-data">
<table align=center> <table align=center>
<tr> <tr>
<td> <td>
@ -127,7 +135,15 @@ if( $_SESSION['access'] != 1 ) {
Issue Description: Issue Description:
</td> </td>
<td> <td>
<textarea name="description" id="description" cols="40" rows="5" required><?=$desc?></textarea> <?=nl2br($desc)?>
</td>
</tr>
<tr>
<td>
Update:
</td>
<td>
<textarea name="description" id="description" cols="40" rows="5" required></textarea>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -150,6 +166,14 @@ if( $_SESSION['access'] != 1 ) {
<input type="text" name="end_date_time" id="end_date_time" value="<?=$endtimedate;?>" /> <input type="text" name="end_date_time" id="end_date_time" value="<?=$endtimedate;?>" />
</td> </td>
</tr> </tr>
<tr>
<td>
Attach an image:
</td>
<td>
<input type="file" name="fileToUpload" id="fileToUpload" />
</td>
</tr>
<tr> <tr>
<td colspan=2 class="ui-helper-center"> <td colspan=2 class="ui-helper-center">
<input type="submit" value="Submit"/> <input type="submit" value="Submit"/>

1
images/README Normal file
View File

@ -0,0 +1 @@
This directory is for the storage of images uploaded via the web interface. This file can and should be removed when this is put into production.

View File

@ -2,18 +2,73 @@
include "db_config.php"; include "db_config.php";
$conn = mysqli_connect($servername, $username, $password, $db); $conn = mysqli_connect($servername, $username, $password, $db);
//Allow Image Upload
$target_dir = "../images/";
if(empty($_FILES["fileToUpload"]["name"])) {
$target_file_name = "";
$target_file = "";
$image_link = "";
} else {
$target_file_name = preg_replace('/[^a-zA-Z0-9s.]/', '_', basename($_FILES["fileToUpload"]["name"]));
$target_file = $target_dir . $target_file_name;
$image_link = mysqli_real_escape_string($conn, "https://DOMAIN.com/bms/images/$target_file_name");
}
$target_file = $target_dir . $target_file_name;
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
//Set variables for MySQL Insert
$unit = mysqli_real_escape_string($conn, $_POST['unit']); $unit = mysqli_real_escape_string($conn, $_POST['unit']);
$start_date_time = mysqli_real_escape_string($conn, $_POST['start_date_time']); $start_date_time = mysqli_real_escape_string($conn, $_POST['start_date_time']);
$description = $_POST['description']; $description = mysqli_real_escape_string($conn, $_POST['description']);
$is_ongoing = mysqli_real_escape_string($conn, $_POST['is_ongoing']); $is_ongoing = mysqli_real_escape_string($conn, $_POST['is_ongoing']);
$end_date_time = mysqli_real_escape_string($conn, $_POST['end_date_time']); $end_date_time = mysqli_real_escape_string($conn, $_POST['end_date_time']);
$alert = mysqli_real_escape_string($conn, $_POST['alert']); $alert = mysqli_real_escape_string($conn, $_POST['alert']);
$user = mysqli_real_escape_string($conn, $_POST['user']); $user = mysqli_real_escape_string($conn, $_POST['user']);
//Insert event to events table //Insert event to events table
$event = "INSERT INTO events (unit_id, date_time_start, description, is_ongoing, date_time_end, alert_id, user) VALUES ('$unit','$start_date_time', '$description', '$is_ongoing', '$end_date_time', '$alert', '$user')"; $event = "INSERT INTO events (unit_id, date_time_start, description, is_ongoing, date_time_end, alert_id, user, event_image) VALUES ('$unit','$start_date_time', '$description', '$is_ongoing', '$end_date_time', '$alert', '$user', '$image_link')";
//MySQL queries to get Unit Name and Alert Name for the Email //Set variables for email
//MySQL queries to get Unit Name and Alert
$unitname_query = "SELECT unit_name FROM units WHERE unit_id=".$_POST['unit'].""; $unitname_query = "SELECT unit_name FROM units WHERE unit_id=".$_POST['unit']."";
$unitname_query_run = mysqli_query($conn, $unitname_query); $unitname_query_run = mysqli_query($conn, $unitname_query);
$unitname_array = mysqli_fetch_assoc($unitname_query_run); $unitname_array = mysqli_fetch_assoc($unitname_query_run);
@ -22,6 +77,7 @@ $alertname_query = "SELECT alert_name FROM alerts WHERE alert_id=".$_POST['alert
$alertname_query_run = mysqli_query($conn, $alertname_query); $alertname_query_run = mysqli_query($conn, $alertname_query);
$alertname_array = mysqli_fetch_assoc($alertname_query_run); $alertname_array = mysqli_fetch_assoc($alertname_query_run);
$alertname = $alertname_array['alert_name']; $alertname = $alertname_array['alert_name'];
$description_for_email = nl2br($_POST['description']);
//If successful, redirect back to index.php and send email, else tell user that it failed. //If successful, redirect back to index.php and send email, else tell user that it failed.
$result = mysqli_query($conn, $event); $result = mysqli_query($conn, $event);
@ -31,11 +87,33 @@ if($result){
header('Location: ../index.php'); header('Location: ../index.php');
//Get inserted Event ID //Get inserted Event ID
$event_id = $conn->insert_id; $event_id = $conn->insert_id;
//Set Email Info $to = "TOEMAIL@DOMAIN>COM";
$to = "TO-EMAIL@DOMAIN.COM";
$subject = "New BMS Alert: ".$unitname." ".$alertname.""; $subject = "New BMS Alert: ".$unitname." ".$alertname."";
$headers = "From: FROM-EMAIL@DOMAIN.COM"; $headers = "MIME-Version: 1.0" . "\r\n";
$message = "BMS Unit: ".$unitname." \n Type of Alert: ".$alertname." \n Start Date / Time: ".$start_date_time." \n End Date / Time: ".$end_date_time." \n Description: ".$description." \n Created by: ".$user." \n Event Link: https://DOMAIN.com/bms/viewevent.php?eventid=$event_id \n \n This message generated by https://DOMAIN.com/bms"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: FROMEMAIL@.com";
$message = "
<html>
<body>
BMS Unit: ".$unitname."
<br />
Type of Alert: ".$alertname."
<br />
Start Date / Time: ".$start_date_time."
<br />
End Date / Time: ".$end_date_time."
<br />
Description: ".$description_for_email."
<br />
Created by: ".$user."
<br />
Image: ".$image_link."
<br />
Event Link: https://DOMAIN.com/bms/viewevent.php?eventid=$event_id
<br /><br />
This message generated by https://DOMAIN.com/bms
</body>
</html>";
//WordWrap the message //WordWrap the message
$message_wrapped = wordwrap($message, 70, "\n", true); $message_wrapped = wordwrap($message, 70, "\n", true);
//Send the email //Send the email

View File

@ -2,14 +2,74 @@
include "db_config.php"; include "db_config.php";
$conn = mysqli_connect($servername, $username, $password, $db); $conn = mysqli_connect($servername, $username, $password, $db);
//Allow Image Upload
$target_dir = "../images/";
if(empty($_FILES["fileToUpload"]["name"])) {
$target_file_name = "";
$target_file = "";
$image_link = "";
} else {
$target_file_name = preg_replace('/[^a-zA-Z0-9s.]/', '_', basename($_FILES["fileToUpload"]["name"]));
$target_file = $target_dir . $target_file_name;
$image_link = mysqli_real_escape_string($conn, "https://DOMAIN.com/bms/images/$target_file_name");
}
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
//Set Variables
$event_id = mysqli_real_escape_string($conn, $_POST['event']); $event_id = mysqli_real_escape_string($conn, $_POST['event']);
$description = $_POST['description']; $description = mysqli_real_escape_string($conn, $_POST['description']);
$is_ongoing = mysqli_real_escape_string($conn, $_POST['is_ongoing']); $is_ongoing = mysqli_real_escape_string($conn, $_POST['is_ongoing']);
$end_date_time = mysqli_real_escape_string($conn, $_POST['end_date_time']); $end_date_time = mysqli_real_escape_string($conn, $_POST['end_date_time']);
$user = mysqli_real_escape_string($conn, $_POST['user']); $user = mysqli_real_escape_string($conn, $_POST['user']);
//Insert event to events table //Get timestamp
$event = "UPDATE events SET description='$description', is_ongoing='$is_ongoing', date_time_end='$end_date_time', user='$user' WHERE event_id='$event_id'"; $timestamp = new DateTime();
$update_date_time = date_format($timestamp, 'Y/m/d H:i');
//Insert event update into event updates table
$update_query = "INSERT INTO event_updates (update_desc, update_date_time, update_is_ongoing, end_date_time, event_id, update_user, update_image) VALUES ('$description', '$update_date_time', '$is_ongoing', '$end_date_time', '$event_id', '$user', '$image_link')";
//Update value of is_ongoing in main events table
$is_ongoing_endtime_query = "UPDATE events SET is_ongoing='$is_ongoing', date_time_end='$end_date_time' WHERE event_id='$event_id'";
//Set variables for email //Set variables for email
//MySQL queries to get Unit Name and Alert //MySQL queries to get Unit Name and Alert
@ -27,17 +87,43 @@ $start_date_time_query = "SELECT date_time_start FROM events WHERE event_id=".$_
$start_date_time_query_run = mysqli_query($conn, $start_date_time_query); $start_date_time_query_run = mysqli_query($conn, $start_date_time_query);
$start_date_time_array = mysqli_fetch_assoc($start_date_time_query_run); $start_date_time_array = mysqli_fetch_assoc($start_date_time_query_run);
$start_date_time = $start_date_time_array['date_time_start']; $start_date_time = $start_date_time_array['date_time_start'];
$description_for_email = nl2br($_POST['description']);
//If successful, redirect back to index.php and send email, else tell user that it failed. //If successful, redirect back to index.php and send email, else tell user that it failed.
$result = mysqli_query($conn, $event); $event_update = mysqli_query($conn, $is_ongoing_endtime_query);
$result = mysqli_query($conn, $update_query);
if($result){ if($result){
echo("Event added, redirecting..."); echo("Event added, redirecting...");
sleep (2); sleep (2);
header('Location: ../index.php'); header('Location: ../index.php');
//Set Email Info //Set Email Info
$to = "TO-EMAIL@DOMAIN.COM"; $to = "TOEMAIL@DOMAIN.com";
$subject = "Updated BMS Alert: ".$unitname." ".$alertname.""; $subject = "Updated BMS Alert: ".$unitname." ".$alertname."";
$headers = "From: FROM-EMAIL@DOMAIN.COM"; $headers = "MIME-Version: 1.0" . "\r\n";
$message = "BMS Unit: ".$unitname." \n Type of Alert: ".$alertname." \n Start Date / Time: ".$start_date_time." \n End Date / Time: ".$end_date_time." \n Description: ".$description." \n Updated by: ".$user." \n Event Link: https://DOMAIN.com/bms/viewevent.php?eventid=$event_id \n \n This message generated by https://DOMAIN.com/bms"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: FROMEMAIL@DOMAIN.com";
$message = "
<html>
<body>
BMS Unit: ".$unitname."
<br />
Type of Alert: ".$alertname."
<br />
Start Date / Time: ".$start_date_time."
<br />
End Date / Time: ".$end_date_time."
<br />
Description: ".$description_for_email."
<br />
Updated by: ".$user."
<br />
Image Link (if any): ".$image_link."
<br />
Event Link: https://DOMAIN.com/bms/viewevent.php?eventid=$event_id
<br /><br />
This message generated by https://DOMAIN.com/bms
</body>
</html>";
//WordWrap the message //WordWrap the message
$message_wrapped = wordwrap($message, 70, "\n", true); $message_wrapped = wordwrap($message, 70, "\n", true);
//Send the email //Send the email

132
index.php
View File

@ -31,28 +31,134 @@ if( $_SESSION['access'] != 1 ) {
if ($conn1->connect_error) { if ($conn1->connect_error) {
die("Connection Failed: " . $conn1->connect_error); die("Connection Failed: " . $conn1->connect_error);
} }
$sql1 = "SELECT * FROM events AS events INNER JOIN units AS units ON events.unit_id=units.unit_id INNER JOIN alerts as alerts ON events.alert_id=alerts.alert_id where is_ongoing=1;"; $currently_ongoing_query = "SELECT * FROM events AS events INNER JOIN units AS units ON events.unit_id=units.unit_id INNER JOIN alerts as alerts ON events.alert_id=alerts.alert_id where is_ongoing=1;";
$result1 = $conn1->query($sql1); $currently_ongoing_result = $conn1->query($currently_ongoing_query);
if ($result1->num_rows >0){ if ($currently_ongoing_result->num_rows >0){
echo "<table align='center'><tr><th>Event ID</th><th>Unit</th><th>Alert</th><th>Start Date and Time</th><th>Description</th><th>End Date and Time</th><th>User</th><th>Edit</th></tr>"; echo "<table align='center'><tr><th>Event ID</th><th>Unit</th><th>Alert</th><th>Start Date and Time</th><th>Description</th><th>End Date and Time</th><th>User</th><th>Updates</th><th>Attachments</th><th>Edit</th></tr>";
while ($row1 = $result1->fetch_assoc()) { while ($currently_ongoing_row = $currently_ongoing_result->fetch_assoc()) {
echo "<tr><td><a href=https://DOMAIN.com/bms/viewevent.php?eventid=".$row1["event_id"]." target=_blank>".$row1["event_id"]."</a></td><td>".$row1["unit_name"]."</td><td>".$row1["alert_name"]."</td><td>".$row1["date_time_start"]."</td><td>".$row1["description"]."</td><td>".$row1["date_time_end"]."</td><td>".$row1["user"]."</td><td><a href=http://DOMAIN.com/bms/editevent.php?event_id=".$row1["event_id"]." target=blank>Edit</a></td></tr> "; echo "<tr><td>";
echo "<a href=viewevent.php?eventid=".$currently_ongoing_row["event_id"]." target=_blank>".$currently_ongoing_row["event_id"]."</a>";
echo "</td><td>";
print_r($currently_ongoing_row["unit_name"]);
echo "</td><td>";
print_r($currently_ongoing_row["alert_name"]);
echo "</td><td>";
print_r($currently_ongoing_row["date_time_start"]);
echo "</td><td>";
echo nl2br($currently_ongoing_row["description"]);
echo "</td><td>";
print_r($currently_ongoing_row["date_time_end"]);
echo "</td><td>";
print_r($currently_ongoing_row["user"]);
echo "</td><td>";
$update_query = "SELECT update_desc, update_date_time, update_user, update_image FROM event_updates WHERE event_updates.event_id=".$currently_ongoing_row["event_id"].";";
$update_result = $conn1->query($update_query);
if ($update_result->num_rows >0){
while ($update_row = $update_result->fetch_assoc()) {
echo "<table align='center'><tr><td>";
echo "Info: ";
echo "</td><td>";
echo nl2br($update_row['update_desc']);
echo "</td></tr><tr><td>";
echo "User: ";
echo "</td><td>";
print_r($update_row['update_user']);
echo "</td></tr><tr><td>";
echo "Time: ";
echo "</td><td>";
print_r($update_row['update_date_time']);
echo "</td></tr>";
if(empty($update_row['update_image'])) {
echo "</table>";
} else {
echo "<tr><td>";
echo "Image: ";
echo "</td><td>";
echo "<a href=".$update_row['update_image']." target=blank>Attachment</a>";
echo "</td></tr></table>";
}
}
} else {
echo "No updates to this event";
}
echo "</td><td>";
if(empty($currently_ongoing_row["event_image"])) {
echo "";
} else{
echo "<a href=".$currently_ongoing_row["event_image"]." target=blank>Attachment</a>";
}
echo "</td><td>";
echo "<a href=editevent.php?event_id=".$currently_ongoing_row["event_id"]." target=blank>Edit</a></td></tr> ";
} }
echo "</table>"; echo "</table>";
} else { } else {
echo "<h5>No Ongoing Events at This Time</h5>"; echo "<h5>No Ongoing Events at This Time</h5>";
} }
if ($conn1->connect_error) { if ($conn1->connect_error) {
die("Connection Failed: " . $conn2->connect_error); die("Connection Failed: " . $conn1->connect_error);
} }
$sql2 = "SELECT * FROM events AS events INNER JOIN units AS units ON events.unit_id=units.unit_id INNER JOIN alerts as alerts ON events.alert_id=alerts.alert_id where is_ongoing=0 ORDER BY date_time_end DESC LIMIT 10;"; $past_event_query = "SELECT * FROM events AS events INNER JOIN units AS units ON events.unit_id=units.unit_id INNER JOIN alerts as alerts ON events.alert_id=alerts.alert_id where is_ongoing=0 ORDER BY date_time_end DESC LIMIT 10;";
$result2 = $conn1->query($sql2); $past_event_result = $conn1->query($past_event_query);
if ($result2->num_rows >0){ if ($past_event_result->num_rows >0){
echo "<h3>Previous 10 Events</h3>"; echo "<h3>Previous 10 Events</h3>";
echo "This does not include ongoing events."; echo "This does not include ongoing events.";
echo "<table align='center'><tr><th>Event ID</th><th>Unit</th><th>Alert</th><th>Start Date and Time</th><th>Description</th><th>End Date and Time</th><th>User</th><th>Edit</th></tr>"; echo "<table align='center'><tr><th>Event ID</th><th>Unit</th><th>Alert</th><th>Start Date and Time</th><th>Description</th><th>End Date and Time</th><th>User</th><th>Updates</th><th>Attachments</th><th>Edit</th></tr>";
while ($row2 = $result2->fetch_assoc()) { while ($past_event_row = $past_event_result->fetch_assoc()) {
echo "<tr><td><a href=https://DOMAIN.com/bms/viewevent.php?eventid=".$row2["event_id"]." target=_blank>".$row2["event_id"]."</a></td><td>".$row2["unit_name"]."</td><td>".$row2["alert_name"]."</td><td>".$row2["date_time_start"]."</td><td>".$row2["description"]."</td><td>".$row2["date_time_end"]."</td><td>".$row2["user"]."</td><td><a href=http://DOMAIN.com/bms/editevent.php?event_id=".$row2["event_id"]." target=blank>Edit</a></td></tr> "; echo "<tr><td>";
echo "<a href=viewevent.php?eventid=".$past_event_row["event_id"]." target=_blank>".$past_event_row["event_id"]."</a>";
echo "</td><td>";
print_r($past_event_row["unit_name"]);
echo "</td><td>";
print_r($past_event_row["alert_name"]);
echo "</td><td>";
print_r($past_event_row["date_time_start"]);
echo "</td><td>";
echo nl2br($past_event_row["description"]);
echo "</td><td>";
print_r($past_event_row["date_time_end"]);
echo "</td><td>";
print_r($past_event_row["user"]);
echo "</td><td>";
$update_query = "SELECT update_desc, update_date_time, update_user, update_image FROM event_updates WHERE event_updates.event_id=".$past_event_row["event_id"].";";
$update_result = $conn1->query($update_query);
if ($update_result->num_rows >0){
while ($update_row = $update_result->fetch_assoc()) {
echo "<table align='center'><tr><td>";
echo "Info: ";
echo "</td><td>";
echo nl2br($update_row['update_desc']);
echo "</td></tr><tr><td>";
echo "User: ";
echo "</td><td>";
print_r($update_row['update_user']);
echo "</td></tr><tr><td>";
echo "Time: ";
echo "</td><td>";
print_r($update_row['update_date_time']);
echo "</td></tr>";
if(empty($update_row['update_image'])) {
echo "</table>";
} else {
echo "<tr><td>";
echo "Image: ";
echo "</td><td>";
echo "<a href=".$update_row['update_image']." target=blank>Attachment</a>";
echo "</td></tr></table>";
}
}
} else {
echo "No updates to this event";
}
echo "</td><td>";
if(empty($past_event_row["event_image"])) {
echo "";
} else {
echo "<a href=".$past_event_row["event_image"]." target=blank>Attachment</a>";
}
echo "</td><td>";
echo "<a href=editevent.php?event_id=".$past_event_row["event_id"]." target=blank>Edit</a>";
echo "</td></tr>";
} }
echo "</table>"; echo "</table>";
} else { } else {

View File

@ -56,13 +56,67 @@ if($result->num_rows >0){
<br /> <br />
<?php <?php
if ($result->num_rows >0){ if ($result->num_rows >0){
echo "<table align='center'><tr><th>Event ID</th><th>Unit</th><th>Alert</th><th>Start Date and Time</th><th>Description</th><th>End Date and Time</th><th>User</th><th>Edit</th></tr>"; echo "<table align='center'><tr><th>Event ID</th><th>Unit</th><th>Alert</th><th>Start Date and Time</th><th>Description</th><th>End Date and Time</th><th>User</th><th>Updates</th><th>Attachments</th><th>Edit</th></tr>";
while ($row1 = $result->fetch_assoc()) { while ($row1 = $result->fetch_assoc()) {
echo "<tr><td><a href=https://DOMAIN.com/bms/viewevent.php?eventid=".$row1["event_id"]." target=_blank>".$row1["event_id"]."</a></td><td>".$row1["unit_name"]."</td><td>".$row1["alert_name"]."</td><td>".$row1["date_time_start"]."</td><td>".$row1["description"]."</td><td>".$row1["date_time_end"]."</td><td>".$row1["user"]."</td><td><a href=http://DOMAIN.com/bms/editevent.php?event_id=".$row1["event_id"]." target=blank>Edit</a></td></tr> "; echo "<tr><td>";
echo "<a href=viewevent.php?eventid=".$row1["event_id"]." target=_blank>".$row1["event_id"]."</a>";
echo "</td><td>";
print_r($row1["unit_name"]);
echo "</td><td>";
print_r($row1["alert_name"]);
echo "</td><td>";
print_r($row1["date_time_start"]);
echo "</td><td>";
echo nl2br($row1["description"]);
echo "</td><td>";
print_r($row1["date_time_end"]);
echo "</td><td>";
print_r($row1["user"]);
echo "</td><td>";
$update_query = "SELECT update_desc, update_date_time, update_user, update_image FROM event_updates WHERE event_updates.event_id=".$row1["event_id"].";";
$update_result = $conn->query($update_query);
if ($update_result->num_rows >0){
while ($update_row = $update_result->fetch_assoc()) {
echo "<table align='center'><tr><td>";
echo "Info: ";
echo "</td><td>";
echo nl2br($update_row['update_desc']);
echo "</td></tr><tr><td>";
echo "User: ";
echo "</td><td>";
print_r($update_row['update_user']);
echo "</td></tr><tr><td>";
echo "Time: ";
echo "</td><td>";
print_r($update_row['update_date_time']);
echo "</td></tr>";
if(empty($update_row['update_image'])) {
echo "</table>";
} else {
echo "<tr><td>";
echo "Image: ";
echo "</td><td>";
echo "<a href=".$update_row['update_image']." target=blank>Attachment</a>";
echo "</td></tr></table>";
}
}
} else {
echo "No updates to this event";
}
echo "</td><td>";
if(empty($row1["event_image"])) {
echo "";
} else {
echo "<a href=".$row1["event_image"]." target=blank>Attachment</a>";
}
echo "</td><td>";
echo "<a href=editevent.php?event_id=".$row1["event_id"]." target=blank>Edit</a>";
echo "</td></tr>";
} }
echo "</table>"; echo "</table>";
} }
} else{ } else{
echo('No Results Found! Please <a href="javascript:history.back()">Go back</a> and try again'); echo('No Results Found! Please <a href="javascript:history.back()">Go back</a> and try again');
} }

View File

@ -65,9 +65,51 @@ $eventid=$_GET['eventid'];
echo "</td><td>"; echo "</td><td>";
print_r($row1['date_time_end']); print_r($row1['date_time_end']);
echo "</td></tr>"; echo "</td></tr>";
echo "<tr><td>";
echo "Event Updates:";
echo "</td><td>";
$update_query = "SELECT update_desc, update_date_time, update_user FROM event_updates WHERE event_updates.event_id=".$eventid.";";
$update_result = $conn1->query($update_query);
if ($update_result->num_rows >0){
while ($update_row = $update_result->fetch_assoc()) {
echo "<table align='center'><tr><td>";
echo "Update Desc: ";
echo "</td><td>";
echo nl2br($update_row['update_desc']);
echo "</td></tr><tr><td>";
echo "Update User: ";
echo "</td><td>";
print_r($update_row['update_user']);
echo "</td></tr><tr><td>";
echo "Update Date and Time: ";
echo "</td><td>";
print_r($update_row['update_date_time']);
if(empty($update_row['update_image'])) {
echo "</td></tr></table>";
} else {
echo "<tr><td>";
echo "Image: ";
echo "</td><td>";
echo "<a href=".$update_row['update_image']." target=blank>Attachment</a>";
}
}
} else {
echo "No updates to this event";
}
echo "</td></tr>";
if(empty($row1['event_image'])) {
echo "<tr><td colspan='2' class='ui-helper-center'>"; echo "<tr><td colspan='2' class='ui-helper-center'>";
echo "<a href=editevent.php?event_id=".$row1['event_id'].">Edit Event</a>"; echo "<a href=editevent.php?event_id=".$row1['event_id'].">Edit Event</a>";
echo "</td></tr></table>"; echo "</td></tr></table>";
} else {
echo "<tr><td>";
echo "Attachments:";
echo "</td><td>";
echo "<a href=".$row1['event_image']." target=blank>Attachment</a>";
echo "<tr><td colspan='2' class='ui-helper-center'>";
echo "<a href=editevent.php?event_id=".$row1['event_id'].">Edit Event</a>";
echo "</td></tr></table>";
}
} }
} else { } else {
echo "<h4>ERROR Event ID Not Found</h4>"; echo "<h4>ERROR Event ID Not Found</h4>";