-
Notifications
You must be signed in to change notification settings - Fork 0
/
beleg.php
112 lines (84 loc) · 2.68 KB
/
beleg.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
<?php
ob_start();
session_start();
require('head.php');
use src\ProjectBrood\business\BelegBusiness;
use src\ProjectBrood\business\BroodBusiness;
use Doctrine\Common\ClassLoader;
/**
* Check if 'id' is not emoty.
* If not, load Twig etc..
* Else redirect to index.php
*/
/**
* todo: controle van broodje ID toevoegen, zodat bij een verkeerde ID naar index.php verwezen wordt.
*/
if (!empty($_GET['id']))
{
/**
* Connect with Doctrine.
* Load ClassLoader to autoload classes.
*/
require_once'Doctrine/Common/ClassLoader.php';
$classLoader = new ClassLoader("src");
$classLoader->register();
/**
* Create 'Beleg' object from BelegBusiness class.
* Get all 'Beleg' records from database.
*/
$obj = new BelegBusiness();
$belegen = $obj->overzichtBeleg();
$objBrood = new BroodBusiness();
$broden = $objBrood->overzichtBroodById($_GET['id']);
/**
* Connect to Twig.
* Load beleg.twig file.
* Send array $belegen and $_GET variable to beleg.twig.
*/
require_once("lib/Twig/Autoloader.php");
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem("src/ProjectBrood/presentation");
$twig = new Twig_Environment($loader);
$view = $twig->render("beleg.twig", array("self" => $_SERVER['REQUEST_URI'], "belegen" => $belegen, "brood_id" => $_GET['id'], "authorized" => $_SESSION['user']['authorized'], "brood_prijs" => $broden->getPrijs(), "totaalBestellingPrijs" => $_SESSION['totaalBestellingPrijs']));
print($view);
}
else
{
header("Location: index.php");
}
/**
* Check if 'Verder' button has been pressed.
* If true, go to product overview.
*/
if ((isset($_POST['sendButton'])) && (!empty($_POST['broodSoort'])))
{
if (empty($_SESSION['bestelling']))
{
$_SESSION['productCounter'] = 0;
$_SESSION['bestelling'][0]['aantal'] = 1;
}
$_SESSION['keyExists'] = false;
foreach ($_SESSION['bestelling'] as $bestKey => $bestRow)
{
if (array_key_exists($_POST['broodSoort'], $_SESSION['bestelling'][$bestKey]))
{
if ($_SESSION['bestelling'][$bestKey][$_POST['broodSoort']] == $_POST)
{
$_SESSION['keyExists'] = true;
$_SESSION['broodNr'] = $bestKey;
}
}
}
if ($_SESSION['keyExists'] == true)
{
$_SESSION['bestelling'][$_SESSION['broodNr']]['aantal']++;
}
else
{
$_SESSION['bestelling'][$_SESSION['productCounter']][$_POST['broodSoort']] = $_POST;
$_SESSION['bestelling'][$_SESSION['productCounter']]['aantal'] = 1;
$_SESSION['productCounter']++;
}
header("Location: overzicht.php");
}
ob_flush();