-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrop_scheduling.php
More file actions
174 lines (149 loc) · 4.68 KB
/
crop_scheduling.php
File metadata and controls
174 lines (149 loc) · 4.68 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
<?php
include("includes/init.php");
// open connection to database
$db = open_sqlite_db("secure/crop_scheduling.sqlite");
// An array to deliver messages to the user.
$messages = array();
function print_record($record) {
?>
<tr>
<td><?php echo htmlspecialchars($record["plant"]);?></td>
<td><?php echo htmlspecialchars($record["category"]);?></td>
<td><?php echo htmlspecialchars($record["low_temp"]);?></td>
<td><?php echo htmlspecialchars($record["high_temp"]);?></td>
<td><?php echo htmlspecialchars($record["low_ph"]);?></td>
<td><?php echo htmlspecialchars($record["high_ph"]);?></td>
<td><?php echo htmlspecialchars($record["lighting"]);?></td>
<td><?php echo htmlspecialchars($record["time_harvest"]);?></td>
<td><?php echo htmlspecialchars($record["num_addition"]);?></td>
<td><?php echo htmlspecialchars($record["cost_1000_seed"]);?></td>
<td><?php echo htmlspecialchars($record["market_value"]);?></td>
</tr>
<?php
}
// Search Form
const SEARCH_FIELDS =[
"plant" => "By Plant",
"category" => "By Category",
"low_temp" => "By Low Temperature",
"high_temp" => "By High Temperature",
"low_ph" => "By Low ph",
"high_ph" => "By high ph",
"lighting" => "By Lighting (DLI)",
"time_harvest" => "By Time to Harvest(weeks)",
"num_addition" => "No. Additional Harvest",
"cost_1000_seed" => "cost for 1000 seeds",
"market_value" => "market value per crop"
];
if ( isset($_GET['search']) && isset($_GET['category_1']) ) {
$do_search = TRUE;
$category_1 = filter_input(INPUT_GET, 'category_1', FILTER_SANITIZE_STRING);
// check if the category exists in the SEARCH_FIELDS array
if (in_array($category_1, array_keys(SEARCH_FIELDS))) {
$search_field = $category_1;
} else {
array_push($messages, "Invalid category for search.");
$do_search = FALSE;
}
// Get the search terms
$search = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_STRING);
$search = trim($search);
} else {
// No search provided, so set the product to query to NULL
$do_search = FALSE;
$category_1 = NULL;
$search = NULL;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="styles/all.css"/>
<title>crop scheduling</title>
</head>
<body>
<h1> REAL </h1>
<h2> Crop Scheduling Tool </h2>
<?php
// Write out any messages to the user.
foreach ($messages as $message) {
echo "<p><strong>" . htmlspecialchars($message) . "</strong></p>\n";
}
?>
<form id="searchForm" action="crop_scheduling.php" method="get">
<select name="category_1">
<option value="" selected disabled>Search By</option>
<?php
foreach(SEARCH_FIELDS as $field_name => $label){
?>
<option value="<?php echo $field_name;?>"><?php echo $label;?></option>
<?php
}
?>
</select>
<input type="text" name="search"/>
<button type="submit">Search</button>
</form>
<?php
if ($do_search) {
// We have a specific shoe to query!
?>
<h2>Search Results</h2>
<?php
// Be careful to filter $search_field above. If you're not careful, you can seriously break your database.
// TODO: wildcard search using LIKE.
$sql = "SELECT * FROM crop_scheduling WHERE ".$search_field." LIKE '%' || :search || '%'";
$params = array(
':search' => $search
);
} else {
// No shoe to query, so return everything!
?>
<h2>All Vegetable</h2>
<?php
$sql = "SELECT * FROM crop_scheduling";
$params = array();
}
// Get the shoes to display
$result = exec_sql_query($db, $sql, $params);
if ($result) {
// The query was successful, let's get the records.
$records = $result->fetchAll();
if ( count($records) > 0 ) {
// We have records to display
?>
<table>
<tr>
<th>Plant</th>
<th>Plant Category</th>
<th>Low Temperature</th>
<th>High Temperature</th>
<th>Low pH</th>
<th>High pH</th>
<th>Lighting(DLI)</th>
<th>Time to Harvest(weeks)</th>
<th>No. Additional Weeks</th>
<th>Cost for 1000 Seends</th>
<th>Market Value Per Crop</th>
</tr>
<?php
foreach($records as $record) {
print_record($record);
}
?>
</table>
<?php
} else {
// No results found
echo "<p>No matching vegetables found.</p>";
}
}
?>
<div class="back">
<a href="index.php">BACK</a>
</div>
</div>
</body>
</html>