-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer.php
More file actions
103 lines (75 loc) · 2.87 KB
/
customer.php
File metadata and controls
103 lines (75 loc) · 2.87 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
<?php
/**
* Created by PhpStorm.
* User: Elli
* Date: 9/26/2016
* Time: 1:52 PM
*/
require_once('includes/bootstrap.inc.php');
// check if user is logged in
User::checkLogin();
$content = "<h2>Kunden</h2>";
// Set the Step var
if(isset($_GET['id']))
$id = $_GET['id'];
else
$id = '';
if($id == '1')
{
// Update customer Form
$customer = CustomerMapper::findById(intval($_GET['customerid']));
$content .= Customer::getForm($customer);
} else if($id == '2') {
// Process the customer post data by calling the formMapper
$customer = Customer::formMapper($_POST);
if ($customer instanceof Customer) {
// If the Mapper passed correctly, the data will be given to database
if ($_POST['action'] == 'update') {
CustomerMapper::update($customer);
$content .= "<div class='alert alert-success'> <a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a><p>Kunde erfolgreich geändert.</p></div>";
} else {
CustomerMapper::add($customer);
$content .= "<div class=\'alert alert-success'><a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a><p>Kunde erfolgreich eingefügt.</p></div>";
}
$content .= Customer::getTable(CustomerMapper::getAllCustomers());
}
else {
// The formMapper failed
$content .= $customer;
}
} else if($id == '3') {
// The add new customer form is called
$content .= "<h3>Neuer Kunde</h3>";
$content .= Customer::getForm();
} else if($id == '4')
{
// Delete customer is called
if(empty($_GET['sure']))
{
// ask the customer if he is sure
$content .= "<div class=\"alert alert-warning\"><p>Wirklich löschen?</p>
<p><button class='btn update' onclick=\"window.location.href='?id=4&customerid=" . $_GET['customerid'] . "&sure=true'\">Ja</button>
<button class='btn delete' onclick=\"window.location.href='?'\">Nein</button></p>
</div>";
$content .= Customer::getTable(CustomerMapper::getAllCustomers());
} else {
// If the user is sure, delete the customer in database
$customer = new Customer();
$customer->setId(intval($_GET['customerid']));
CustomerMapper::delete($customer);
$content .= "<div class=\"alert alert-success\">
<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>
Datensatz erfolgreich gelöscht.
</div>";
$content .= Customer::getTable(CustomerMapper::getAllCustomers());
}
} else {
// show the customers table
$content .= Customer::getTable(CustomerMapper::getAllCustomers());
}
// Initialize Page
$page = new Page();
$page->setTitle("tinyERP - Customer");
$page->setRightArea($page->getMasterDataNav());
$page->setContent($content);
$page->run();