-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditbatch.php
More file actions
214 lines (182 loc) · 8.26 KB
/
editbatch.php
File metadata and controls
214 lines (182 loc) · 8.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php ob_start(); ?>
<html>
<head>
<title>Edit Batch</title>
<?php
//ini_set('display_errors', 1);
include "includes/base.php";
?>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="/bower_components/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/bower_components/moment/min/moment.min.js"></script>
<script type="text/javascript" src="/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="/bower_components/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css" />
</head>
<body>
<?php include("includes/header.php");?>
<?php //include("includes/nav.php");?>
<div id='section'>
<?php
if($_POST['updatetable']!=''){
$_SESSION['table'] = htmlspecialchars($_POST['updatetable']);
}
if($_POST['updateid']!=''){
$_SESSION['id'] = htmlspecialchars($_POST['updateid']);
}
$sql = "SELECT * FROM " . $_SESSION['table'] . " WHERE batch_id = ?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt,'s',htmlspecialchars($_SESSION['id']));
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_array($result);
$batch_id = $row[0];
$beer_name = $row[1];
$sched_start = $row[2];
$sched_end = $row[3];
$username = $row[4];
mysqli_stmt_close($stmt);
}
echo "<div class='container'>";
echo "<br>";
echo "<form class='form-horizontal' action='' method='POST'>";
echo "<fieldset>";
echo "<legend>Update Batch</legend>";
if (isset($_SESSION['error']) || isset($_SESSION['success'])) {
if ($_SESSION['error']) {
echo "<div class='btn btn-danger col-md-4 form-control'>". $_SESSION['error']. "</div>";
echo "<br><br>";
$_SESSION['error'] = '';
}
else if($_SESSION['success']) {
print "<div class='btn btn-success form-control'>". $_SESSION['success']. "</div>";
echo "<br><br>";
$_SESSION['success'] = '';
}
}
echo "<div class='form-group'>";
echo "<label class='col-md-4 control-label'>Batch ID:</label>";
echo "<div class='col-md-4'>";
echo "<input class='form-control input-md' type='text' name='batch_id' value='".$batch_id."' readonly>";
echo "</div>";
echo "</div>";
echo "<div class='form-group'>";
echo "<label class='col-md-4 control-label'>Beer Name:</label>";
echo "<div class='col-md-4'>";
$query = "SELECT name FROM beer ORDER BY name";
if($stmt = mysqli_prepare($link, $query)){
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
//$field = mysqli_fetch_fields($result);
echo "<select class='form-control input-md' name='beer_name' id='sel1'>";
while($row = mysqli_fetch_assoc($result)){
foreach($row as $key => $value){
if($value == $beer_name) {
echo "<option value='" . $value . "' selected>" . $value . "</option>";
}
else {
echo "<option value='" . $value . "'>" . $value . "</option>";
}
}
}
echo "</select>";
mysqli_stmt_close($stmt);
}
echo "</div>";
echo "</div>";
echo "<div class='form-group'>";
echo "<label class='col-md-4 control-label'>Batch Start Date:</label>";
echo "<div class='input-group date col-md-4' id='datetimepicker3'>";
echo "<input class='form-control' type='text' name='start_date' value='" . $sched_start . "' />";
echo "<span class='input-group-addon'>";
echo "<span class='glyphicon glyphicon-calendar'></span>";
echo "</span>";
echo "</div>";
echo '<script type="text/javascript">';
echo '$(function () {';
echo '$("#datetimepicker3").datetimepicker({';
echo 'format: "YYYY-MM-DD HH:mm:ss",';
echo 'sideBySide: true,';
echo '});';
echo '});';
echo '</script>';
echo "</div>";
echo "<div class='form-group'>";
echo "<label class='col-md-4 control-label'>Batch End Date:</label>";
echo "<div class='input-group date col-md-4' id='datetimepicker4'>";
echo "<input class='form-control' type='text' name='end_date' value='" . $sched_end . "' />";
echo "<span class='input-group-addon'>";
echo "<span class='glyphicon glyphicon-calendar'></span>";
echo "</span>";
echo "</div>";
echo '<script type="text/javascript">';
echo '$(function () {';
echo '$("#datetimepicker4").datetimepicker({';
echo 'format: "YYYY-MM-DD HH:mm:ss",';
echo 'sideBySide: true,';
echo '});';
echo '});';
echo '</script>';
echo "</div>";
echo "<div class='form-group'>";
echo "<label class='col-md-4 control-label'>Username:</label>";
echo "<div class='col-md-4'>";
echo "<input class='form-control input-md' type='text' name='username' value='".$username."' readonly>";
echo "</div>";
echo "</div>";
echo "<div class='form-group'>";
echo "<label class='col-md-4 control-label'></label>";
echo "<div class='col-md-4'>";
echo "<input class='btn btn-info form-control' type='submit' name='submit_batch' value='Save'>";
echo "</div>";
echo "</div>";
echo "<div class='form-group'>";
echo "<input type='hidden' name='updatetable' value='".$table."'>";
echo "<input type='hidden' name='updateid' value='".$id."'>";
echo "</div>";
echo "</fieldset>";
echo "</form>";
echo "</div>";
?>
<div class="container">
<br><a href="schedule.php">Back to Batch Schedule</a><br>
</div>
</div>
<?php// include("includes/footer.php");?>
</body>
</html>
<?php
if(isset($_POST['submit_batch'])){
$batch_id = htmlspecialchars($_POST['batch_id']);
$beer_name = htmlspecialchars($_POST['beer_name']);
$start_date = htmlspecialchars($_POST['start_date']);
$end_date = htmlspecialchars($_POST['end_date']);
$username = htmlspecialchars($_POST['username']);
if($beer_name == '' || $start_date == '') {
$_SESSION['error'] = "Error: All fields must be filled.";
header('Refresh:0');
exit();
}
$sql = "UPDATE " . $_SESSION['table'] . " SET beer_name=?,sched_start=?,sched_end=? WHERE batch_id=?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt,'ssss',$beer_name,$start_date,$end_date,$batch_id);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
$_SESSION['success'] = "Success: Batch with ID " . $batch_id . " has been updated.";
$_SESSION['table'] = '';
$_SESSION['id'] = '';
header('Location:schedule.php');
exit();
}
else {
$_SESSION['error'] = "Error: Batch not successfully updated.";
header('Refresh:0');
exit();
}
}
?>
<?php
ob_end_flush();
mysqli_close($link);
?>