blob: 1dae14665d85749d00477b2e3200af6a90022e11 (
plain) (
blame)
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
|
<?php
/**
* BusinessAdmin: administrative software for small companies
* Copyright (C) 2015 Camil Staps (ViviSoft)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once(__DIR__ . '/../index.php');
require_once(__DIR__ . '/../login.php');
require('./header.php');
?>
<div id="wrapper">
<?php require('./nav.php'); ?>
<div id="page-wrapper">
<div class="row">
<?php
//------------------------------------------------------------------------------
// Check for GET variables
//
// ?id=<id> View information of the discount with id <id>
// ?delete=<id> Delete the discount with id <id>
//------------------------------------------------------------------------------
// The header of the page
$header = 'Discounts';
// Whether or not to show an individual discount in the end (false if not, or the id if yes)
$show_individual = false;
// View discount
if (isset($_GET['id'])) {
$id = (int) $_GET['id'];
try {
$discount = new Discount($_pdo, $id);
$header = "<a href='".Constants::url_external."discounts'>Discounts</a> / {$discount->title}";
$show_individual = $id;
} catch (PDOException $e) {
$alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The discount with id $id</i> could not be found.</div>";
} catch (Exception $e) {
$alert = "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The discount with id $id</i> could not be found.</div>";
}
}
// Show the header
echo "<div class='col-lg-12'><h1 class='page-header'>$header</h1></div>";
if (isset($alert)) echo "<div class='col-lg-12'>$alert</div>";
// Delete discount
if (isset($_GET['delete'])) {
echo "<div class='col-lg-12'>";
$id = (int) $_GET['delete'];
try {
$discount = new Discount($_pdo, $id);
if ($discount->delete()) {
echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The discount with title <i>{$discount->title}</i> has been removed.</div>";
} else {
echo "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The discount with title <i>{$discount->title}</i> could not be removed. Perhaps it's already removed?</div>";
}
} catch (PDOException $e) {
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The discount could not be removed due to a PDO error.</div>";
} catch (Exception $e) {
echo "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The discount with id {$id} could not be found.</div>";
}
echo "</div>";
}
if ($show_individual !== false) {
$_id = $show_individual;
require('discounts-view.php');
} else {
require('discounts-overview.php');
}
?>
</div>
<!-- /.row -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<?php
require('./footer.php');
?>
|