-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
67 lines (59 loc) · 2.53 KB
/
edit.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
<?php
session_start();
// Include necessary classes for user and delivery data
require_once('Models/UserDataSet.php');
require_once('Models/DeliveryPointDataSet.php');
// Create a view for the edit parcel entry page
$view = new stdClass();
$view->pageTitle = 'Edit parcel entry';
$view->message = '';
$id = $recipient = $address1 = $address2 = $postcode = $lat = $long = $deliverer = $status = '';
$userData = new UserDataSet();
$view->userDataSet = $userData->getAllDeliverers();
$deliveryPointData = new DeliveryPointDataSet();
$view->statusOptions = $deliveryPointData->getDeliveryStatus();
// Check if the 'id' parameter is set in the URL
if (isset($_GET['id'])) {
// Validate and retrieve the 'id' parameter from the URL
$id = filter_input(INPUT_GET, 'id');
// Fetch the current data values for the specified delivery point
$deliveryPointInfo = $deliveryPointData->getSingleDeliveryPoint($id);
if ($deliveryPointInfo) {
$deliveryPointInfo = $deliveryPointData->getSingleDeliveryPoint($id);
if ($deliveryPointInfo) {
$recipient = $deliveryPointInfo->getName();
$address1 = $deliveryPointInfo->getAddress1();
$address2 = $deliveryPointInfo->getAddress2();
$postcode = $deliveryPointInfo->getPostcode();
$lat = $deliveryPointInfo->getLat();
$long = $deliveryPointInfo->getLong();
$deliverer = $deliveryPointInfo->getDeliverer();
$status = $deliveryPointInfo->getStatus();
}
}
}
// Check if the form is submitted
if (isset($_POST['submit'])) {
// Retrieve form data
$id = $_GET['id'];
$recipient = $_POST['recipient'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$postcode = $_POST['postcode'];
$lat = $_POST['lat'];
$long = $_POST['long'];
$deliverer = $_POST['deliverer'];
$status = $_POST['status'];
// Instance of DeliveryPointDataSet class
$deliveryData = new DeliveryPointDataSet();
// Update the delivery point using the provided data
$updateDeliveryPoint = $deliveryData->updateDeliveryPoint($recipient, $address1, $address2, $postcode, $deliverer, $lat, $long, $status, $id);
// Check if any rows were affected
if ($updateDeliveryPoint > 0) {
$view->message = '<p class="text-success">' . 'Delivery point updated successfully' . '</p>';
} else {
$view->message = '<p class="text-danger">' . 'No rows affected' . '</p>';
}
}
// Include the HTML view file for the edit parcel entry page
require_once('Views/edit.phtml');