-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCultivations.php
179 lines (129 loc) · 5.51 KB
/
Cultivations.php
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
<?php require_once('includes/connection.php'); ?>
<?php
session_start();
$officerID = $_SESSION['userID'];
$query = "SELECT OfficerID, CenterID, FName, LName FROM AGRICULTURAL_OFFICER WHERE OfficerID = '{$officerID}' LIMIT 1";
$result = mysqli_query($conn, $query);
if ($recordRow = mysqli_fetch_assoc($result)) {
$userOfficerID = $recordRow['OfficerID'];
$userCenterID = $recordRow['CenterID'];
$userFName = $recordRow['FName'];
$userLName = $recordRow['LName'];
$msgViewUser = "Login as {$userOfficerID} - {$userFName} {$userLName} under Center - {$userCenterID}";
}
if(isset($_POST["btnSearchID"])){
if(isset($_POST["txtLandID"])){
$landID = $_POST["txtLandID"];
$query = "SELECT * FROM CULTIVATION WHERE LandID = '{$landID}' AND OfficerID = '{$officerID}'";
$resultRow = mysqli_query($conn, $query);
if ($record = mysqli_fetch_assoc($resultRow)) {
$FarmerId = $record['FarmerID'];
$Area = $record['LandArea'];
$CropName = $record['CropName'];
$Month = $record['Month'];
} else {
$msg1 = "No such LandID exists";
}
}
}
if(isset($_POST["btnAddNew"]))
{
$query = "SELECT * FROM CULTIVATION";
$result_set = mysqli_query($conn, $query);
$landID = '';
while ($record = mysqli_fetch_assoc($result_set)) {
$landID = $record['LandID'];
}
$landID = "L" . str_pad(((int)(substr($landID, 1)) + 1), 3, '0', STR_PAD_LEFT);
}
if(isset($_POST['btn_update']))
{
$landID = $_POST['txtLandID'];
$FarmerId = $_POST['txtFarmerId'];
$CropName = $_POST['txtCropName'];
$Month = $_POST['txtMonth'];
$query = "SELECT LandArea FROM CULTIVATION WHERE LandID = '{$landID}'";
$result_set = mysqli_query($conn, $query);
if($result = mysqli_fetch_assoc($result_set))
{
$Area = $result['LandArea'];
$query = "UPDATE CULTIVATION SET FarmerID = '{$FarmerId}', CropName = '{$CropName}', Month ='{$Month}' WHERE LandID = '{$landID}'";
$result = mysqli_query($conn, $query);
if ($result) {
$msg2 = "Record updated successfully";
} else {
$msg2 = "Failed updating the record";
}
}
else {
$msg2 = "Failed updating the record";
}
}
if(isset($_POST['btn_save']))
{
$landID = $_POST['txtLandID'];
$FarmerId = $_POST['txtFarmerId'];
$CropName = $_POST['txtCropName'];
$Month = $_POST['txtMonth'];
$Area = $_POST['txtArea'];
$query = "SELECT LandArea FROM CULTIVATION WHERE LandID = '{$landID}'";
$result_set = mysqli_query($conn, $query);
if($result = mysqli_fetch_assoc($result_set))
{
$msg2 = "This land is already in data base.";
}
else {
$Area = number_format($Area,2);
$query = "INSERT INTO CULTIVATION VALUES ('{$landID}', '{$FarmerId}', '{$officerID}', '{$CropName}', {$Area}, '{$Month}')";
$result = mysqli_query($conn, $query);
if ($result) {
$msg2 = "New land added successfully";
} else {
$msg2 = "Failed adding new record";
}
}
}
?>
<?php include('includes/header.php'); ?>
<form action="Cultivations.php" method = "post">
<h1>View Cultivation Info</h1>
<h4><?php echo $msgViewUser ?></h4><hr>
<table>
<tr>
<td>Land ID : </td>
<td>
<input type="text" name = "txtLandID" value = "<?php echo (isset($landID)) ? $landID : ''; ?>"></input>
<button name="btnSearchID" type="submit" value="HTML">SEARCH</button>
<button name="btnAddNew" type="submit" value="HTML">ADD NEW</button>
<label for="lblMsg1"><b><?php echo (isset($msg1)) ? $msg1 : ''; ?></b></label>
</td>
</tr>
<tr>
<td>Farmer ID : </td>
<td><input type="text" name="txtFarmerId" value = "<?php echo (isset($FarmerId)) ? $FarmerId : ''; ?>"></input></td>
</tr>
<tr>
<td>Area (Ha) : </td>
<td><input type="text" name = "txtArea" value = "<?php echo (isset($Area)) ? $Area : ''; ?>"></input></td>
</tr>
<tr>
<td>Crop Name : </td>
<td><input type="text" name = "txtCropName" value = "<?php echo (isset($CropName)) ? $CropName : ''; ?>"></input></td>
</tr>
<tr>
<td>Month : </td>
<td><input type="text" name = "txtMonth" value = "<?php echo (isset($Month)) ? $Month : ''; ?>"></input></td>
</tr>
<tr>
<td>
</td>
<td>
<button name="btn_update" type="submit" value="HTML">UPDATE</button>
<button name="btn_save" type="submit" value="HTML">SAVE NEW</button>
<label for="lblMsg2"><b><?php echo (isset($msg2)) ? $msg2 : ''; ?></b></label>
</td>
</tr>
</table>
</form>
<?php include('includes/footer.php'); ?>
<?php mysqli_close($conn) ?>