Change how event updates are handled
This commit is contained in:
parent
f3c866481c
commit
adf296588d
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
include "db_config.php";
|
include "db_config.php";
|
||||||
$conn = mysqli_connect($servername, $username, $password, $db);
|
$conn = mysqli_connect($servername, $username, $password, $db);
|
||||||
|
|
||||||
$event_id = mysqli_real_escape_string($conn, $_POST['event']);
|
$event_id = mysqli_real_escape_string($conn, $_POST['event']);
|
||||||
@ -9,8 +9,16 @@ $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']);
|
||||||
|
|
||||||
$description_for_email = nl2br($_POST['description']);
|
$description_for_email = nl2br($_POST['description']);
|
||||||
//Insert event to events table
|
|
||||||
$event = "UPDATE events SET description='$description', is_ongoing='$is_ongoing', date_time_end='$end_date_time', user='$user' WHERE event_id='$event_id'";
|
//Get timestamp
|
||||||
|
$timestamp = new DateTime();
|
||||||
|
$update_date_time = date_format($timestamp, 'Y/m/d H:i');
|
||||||
|
|
||||||
|
//Insert event update into event updates table
|
||||||
|
$update = "INSERT INTO event_updates (update_desc, update_date_time, update_is_ongoing, end_date_time, event_id, user) VALUES ('$description', '$update_date_time', '$is_ongoing', '$end_date_time', '$event_id', '$user')";
|
||||||
|
|
||||||
|
//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
|
||||||
@ -29,40 +37,41 @@ $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'];
|
||||||
//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);
|
||||||
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 = "TO.ADDRES@DOMAIN.com";
|
||||||
$subject = "Updated BMS Alert: ".$unitname." ".$alertname."";
|
$subject = "TEST Updated BMS Alert: ".$unitname." ".$alertname."";
|
||||||
$headers = "MIME-Version: 1.0" . "\r\n";
|
$headers = "MIME-Version: 1.0" . "\r\n";
|
||||||
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
|
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
|
||||||
$headers .= "From: FROM-EMAIL@DOMAIN.COM";
|
$headers .= "From: FROM.ADDRESS@DOMAIN.com";
|
||||||
$message = "
|
$message = "
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
BMS Unit: ".$unitname."
|
BMS Unit: ".$unitname."
|
||||||
<br />
|
<br />
|
||||||
Type of Alert: ".$alertname."
|
Type of Alert: ".$alertname."
|
||||||
<br />
|
<br />
|
||||||
Start Date / Time: ".$start_date_time."
|
Start Date / Time: ".$start_date_time."
|
||||||
<br />
|
<br />
|
||||||
End Date / Time: ".$end_date_time."
|
End Date / Time: ".$end_date_time."
|
||||||
<br />
|
<br />
|
||||||
Description: ".$description_for_email."
|
Description: ".$description_for_email."
|
||||||
<br />
|
<br />
|
||||||
Updated by: ".$user."
|
Updated by: ".$user."
|
||||||
<br />
|
<br />
|
||||||
Event Link: https://DOMAIN.com/bms/viewevent.php?eventid=$event_id
|
Event Link: https://DOMAIN.com/bms/viewevent.php?eventid=$event_id
|
||||||
<br /><br />
|
<br /><br />
|
||||||
This message generated by https://DOMAIN.com/bms
|
This message generated by https://DOMAIN.com/bms
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</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
|
||||||
mail($to,$subject,$message_wrapped,$headers);
|
mail($to,$subject,$message_wrapped,$headers);
|
||||||
} else{
|
} else{
|
||||||
echo('Error! Please <a href="javascript:history.back()">go back</a> and try again');
|
echo('Error! Please <a href="javascript:history.back()">go back</a> and try again');
|
||||||
|
@ -21,8 +21,8 @@ if( $_SESSION['access'] != 1 ) {
|
|||||||
echo "Hello, ";
|
echo "Hello, ";
|
||||||
print_r($_SESSION['uname']);
|
print_r($_SESSION['uname']);
|
||||||
}
|
}
|
||||||
echo "<h2>View Event</h2>";
|
echo "<h2>View Event</h2>";
|
||||||
include("includes/menu.php"); ?>
|
include("includes/menu.php"); ?>
|
||||||
</div>
|
</div>
|
||||||
<div class=content>
|
<div class=content>
|
||||||
<?php include "includes/db_config.php";
|
<?php include "includes/db_config.php";
|
||||||
@ -35,41 +35,66 @@ $eventid=$_GET['eventid'];
|
|||||||
$result1 = $conn1->query($sql1);
|
$result1 = $conn1->query($sql1);
|
||||||
if ($result1->num_rows >0){
|
if ($result1->num_rows >0){
|
||||||
while ($row1 = $result1->fetch_assoc()) {
|
while ($row1 = $result1->fetch_assoc()) {
|
||||||
echo "<br />";
|
echo "<br />";
|
||||||
echo "<table align='center'><tr><td>";
|
echo "<table align='center'><tr><td>";
|
||||||
echo "Unit: ";
|
echo "Unit: ";
|
||||||
echo "</td><td>";
|
echo "</td><td>";
|
||||||
print_r($row1['unit_name']);
|
print_r($row1['unit_name']);
|
||||||
echo "</td></tr><tr><td>";
|
echo "</td></tr><tr><td>";
|
||||||
echo "Alert: ";
|
echo "Alert: ";
|
||||||
echo "</td><td>";
|
echo "</td><td>";
|
||||||
print_r($row1['alert_name']);
|
print_r($row1['alert_name']);
|
||||||
|
echo "</td></tr><tr><td>";
|
||||||
|
echo "Description: ";
|
||||||
|
echo "</td><td>";
|
||||||
|
echo nl2br($row1['description']);
|
||||||
|
echo "</td></tr><tr><td>";
|
||||||
|
echo "Start Date and Time: ";
|
||||||
|
echo "</td><td>";
|
||||||
|
print_r($row1['date_time_start']);
|
||||||
echo "</td></tr><tr><td>";
|
echo "</td></tr><tr><td>";
|
||||||
echo "Description: ";
|
echo "Currently Ongoing? ";
|
||||||
echo "</td><td>";
|
echo "</td><td>";
|
||||||
echo nl2br($row1['description']);
|
if($row1['is_ongoing'] ==1) {
|
||||||
|
echo "Yes";
|
||||||
|
} else {
|
||||||
|
echo "No";
|
||||||
|
}
|
||||||
echo "</td></tr><tr><td>";
|
echo "</td></tr><tr><td>";
|
||||||
echo "Start Date and Time: ";
|
echo "End Date and Time: ";
|
||||||
echo "</td><td>";
|
echo "</td><td>";
|
||||||
print_r($row1['date_time_start']);
|
print_r($row1['date_time_end']);
|
||||||
echo "</td></tr><tr><td>";
|
echo "</td></tr>";
|
||||||
echo "Currently Ongoing? ";
|
echo "<tr><td>";
|
||||||
echo "</td><td>";
|
echo "Event Updates";
|
||||||
if($row1['is_ongoing'] ==1) {
|
echo "</td><td>";
|
||||||
echo "Yes";
|
$update_query = "SELECT update_desc, update_date_time, update_user FROM event_updates WHERE event_updates.event_id=".$eventid.";";
|
||||||
} else {
|
$update_result = $conn1->query($update_query);
|
||||||
echo "No";
|
if ($update_result->num_rows >0){
|
||||||
}
|
while ($update_row = $update_result->fetch_assoc()) {
|
||||||
echo "</td></tr><tr><td>";
|
echo "<table align='center'><tr><td>";
|
||||||
echo "End Date and Time: ";
|
echo "Update Desc: ";
|
||||||
echo "</td><td>";
|
echo "</td><td>";
|
||||||
print_r($row1['date_time_end']);
|
echo nl2br($update_row['update_desc']);
|
||||||
echo "</td></tr>";
|
echo "</td></tr><tr><td>";
|
||||||
echo "<tr><td colspan='2' class='ui-helper-center'>";
|
echo "Update User: ";
|
||||||
echo "<a href=editevent.php?event_id=".$row1['event_id'].">Edit Event</a>";
|
echo "</td><td>";
|
||||||
echo "</td></tr></table>";
|
print_r($update_row['update_user']);
|
||||||
}
|
echo "</td></tr><tr><td>";
|
||||||
} else {
|
echo "Update Date and Time: ";
|
||||||
|
echo "</td><td>";
|
||||||
|
print_r($update_row['update_date_time']);
|
||||||
|
echo "</td></tr></table>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "No updates to this event";
|
||||||
|
}
|
||||||
|
echo "</td></tr>";
|
||||||
|
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 {
|
||||||
echo "<h4>ERROR Event ID Not Found</h4>";
|
echo "<h4>ERROR Event ID Not Found</h4>";
|
||||||
}
|
}
|
||||||
if ($conn1->connect_error) {
|
if ($conn1->connect_error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user