-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave.php
46 lines (41 loc) · 981 Bytes
/
save.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
<?php
ob_start();
session_start();
require 'vendor/autoload.php';
require 'src/Customer.php';
// init flag
$action = 'add';
$isSuccess = false;
// get data from POST param
$customerId = isset($_POST['customerId']) ? $_POST['customerId'] : '';
$customerName = $_POST['customerName'];
if (empty($customerName)) {
$_SESSION['require_customername'] = true;
header('Location: add.php');
exit;
}
// save logic
if ($customerId != '') {
// edit customer
$action = 'edit';
// need to impliment edit customer code here
} else {
// create customer
$result = Customer::createCustomer($customerName);
if ($result['success']) {
$isSuccess = true;
$_SESSION['insert_customer_id'] = $result['id'];
} else {
$_SESSION['insert_customer_fail'] = true;
}
}
// redirect handling
if ($isSuccess) {
header('Location: list.php');
} else {
if ($action == 'add') {
header('Location: add.php');
} else {
header('Location: edit.php?id'.$customerId);
}
}