bmspage/editevent.php

181 lines
4.9 KiB
PHP
Raw Normal View History

2015-03-30 23:45:30 -04:00
<?php
session_start();
if( $_SESSION['access'] != 1 ) {
require( 'login.php' );
} else {
$uname=$_SESSION['uname'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/sestyle.css">
<link rel="shortcut icon" href="favicon.ico" />
<script type="text/javascript" src="includes/jquery-2.1.3.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="includes/js/dtp/jquery.datetimepicker.css"/ >
<script src="includes/js/dtp/jquery.js"></script>
<script src="includes/js/dtp/jquery.datetimepicker.js"></script>
<title>Edit BMS Event</title>
<script>
$(function() {
$('#start_date_time').datetimepicker();
$('#end_date_time').datetimepicker();
});
2015-04-07 18:54:26 -04:00
$('#select_form').submit(function(event) {
alert('test');
if ($.trim($("#is_ongoing").val()) === "" && $.trim($("#end_date_time").val()) === "") {
alert('You must enter a value for Currently Ongoing or End Date and Time');
event.preventDefault();
return false;
}
});
2015-03-30 23:45:30 -04:00
</script>
</head>
<body>
<div class=header>
2015-03-30 23:53:01 -04:00
<h1>BMS Events</h1>
2015-03-30 23:45:30 -04:00
<?php
if(isset($_SESSION['uname'])) {
echo "Hello, ";
print_r($_SESSION['uname']);
}
echo "<h2>Edit Event</h2>";
include("includes/menu.php"); ?>
</div>
<div class=body>
<?php include "includes/db_config.php";
//Get Event ID from URL
if(isset($_GET['event_id']) && is_numeric($_GET['event_id'])) {
$varEvent = $_GET['event_id'];
} else {
$varEvent = 0;
}
$conn1 = new mysqli($servername, $username, $password, $db);
if ($conn1->connect_error) {
die ("Connection Failed: " . $conn1->connect_error);
}
$sql1 = "SELECT * FROM events WHERE event_id='".$varEvent."'";
$result1 = $conn1->query($sql1);
if ($result1->num_rows >=1) {
while($row1 = $result1->fetch_assoc()) {
$unitid=$row1['unit_id'];
$starttimedate=$row1['date_time_start'];
$desc=$row1['description'];
$ongoing=$row1['is_ongoing'];
$endtimedate=$row1['date_time_end'];
$alertid=$row1['alert_id'];
$eventid=$row1['event_id'];
}
include "includes/classes/select2.class.php"; ?>
<br />
<form id="select_form" required method="post" action="includes/update_event1.php">
2015-03-30 23:45:30 -04:00
<table align=center>
<tr>
<td>
Affected unit:
</td>
<td>
<?php
if ($conn1->connect_error) {
die ("Connection Failed: " . $conn1->connect_error);
}
$sql2 = "SELECT unit_name FROM units WHERE unit_id='".$unitid."'";
$result2 = $conn1->query($sql2);
if ($result2->num_rows >0) {
while($row2 = $result2->fetch_assoc()) {
$unitname=$row2['unit_name'];
}
} else {
echo "Database Error";
2015-03-30 23:53:01 -04:00
}
2015-03-30 23:45:30 -04:00
echo $unitname;
?>
</td>
</tr>
<tr>
<td>
Alert:
</td>
<td>
<?php
if ($conn1->connect_error) {
die ("Connection Failed: " . $conn1->connect_error);
}
$sql3 = "SELECT alert_name FROM alerts WHERE alert_id='".$alertid."'";
$result3 = $conn1->query($sql3);
if ($result3->num_rows >0) {
while($row3 = $result3->fetch_assoc()) {
$alertname=$row3['alert_name'];
}
} else {
echo "Database Error";
}
echo $alertname;
$conn1->close();
?>
</td>
</tr>
<tr>
<td>
Start date and time:
</td>
<td>
<?php
echo $starttimedate;
?>
</td>
</tr>
<tr>
<td>
Issue Description:
</td>
2015-03-30 23:53:01 -04:00
<td>
<textarea name="description" id="description" cols="40" rows="5" required><?=$desc?></textarea>
2015-03-30 23:45:30 -04:00
</td>
</tr>
<tr>
<td>
Currently Ongoing?
</td>
<td>
<?php
if ($ongoing == 1) $checked= ' checked="true"';
2015-03-30 23:53:01 -04:00
2015-03-30 23:45:30 -04:00
echo '<input type="checkbox" name="is_ongoing" id="is_ongoing" value="1"' . $checked .' />';
?>
</td>
</tr>
<tr>
<td>
End date and time:
</td>
<td>
<input type="text" name="end_date_time" id="end_date_time" value="<?=$endtimedate;?>" />
</td>
</tr>
<tr>
<td colspan=2 class="ui-helper-center">
2015-04-07 18:54:26 -04:00
<input type="submit" value="Submit"/>
2015-03-30 23:45:30 -04:00
</td>
</tr>
</table>
2015-03-30 23:53:01 -04:00
You must press "Submit" to record the update!
2015-03-30 23:45:30 -04:00
<input type="hidden" name="event" id="event" value="<?=$eventid;?>"/>
<input type="hidden" name="user" id="user" value="<?=$uname;?>"/>
</form>
<?php
}else{
echo 'No entry found. <a href="javascript:history.back()">Go back</a>';
}
?>
</div>
<div id="result"></div>
</body>
</html>
<?php } ?>