This repository has been archived by the owner on May 8, 2023. It is now read-only.
/
getstatus_agent.php
135 lines (122 loc) · 4.4 KB
/
getstatus_agent.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php // UTF-8 marker äöüÄÖÜ߀
/**
* @category File
* @package Bestelldienst
* @author Noah Kottenhahn, <noah.kottenhahn@stud.h-da.de>
* @author Max Klosterhalfen, <max.klosterhalfen@stud.h-da.de>
* @license http://www.h-da.de none
*/
require_once './Page.php';
/**
* This is a template for top level classes, which represent
* a complete web page and which are called directly by the user.
* Usually there will only be a single instance of such a class.
* The name of the template is supposed
* to be replaced by the name of the specific HTML page e.g. baker.
* The order of methods might correspond to the order of thinking
* during implementation.
*
* Angepasst für Bestelldienst
*
* @author Noah Kottenhahn, <noah.kottenhahn@stud.h-da.de>
* @author Bernhard Kreling, <b.kreling@fbi.h-da.de>
* @author Ralf Hahn, <ralf.hahn@h-da.de>
*/
class StatusHelperAgent extends Page
{
/**
* Gibt den Wert des status-Attributs der genocheckorder-Datenbank für den User mit der
* angegebenen Email-Adresse aus
* @param String $userid id des Nutzers
* @return Int Bestellungsstatus (0=bestätigt, 1=gesendet, 2=im Labor, 3=fertig)
*/
protected function getUserOrderStatus($userid)
{
if (!$this->checkUserExists($userid)) {
return null;
}
$query = "SELECT status FROM genocheckorder WHERE userid='" . $userid . "'";
$result = $this->_database->query($query);
if ($row = $result->fetch_assoc()) {
return $row["status"];
} else {
return null;
}
}
/**
* Prüft, ob der Nutzer mit der angegebenen Email-Adresse einen Eintrag
* in der User-Datenbank hat
* @param String $userid ID des zu prüfenden Nutzers
* @return Boolean Ob der User in der Datenbank besteht
*/
protected function checkUserExists($userid) {
$query = "SELECT userid FROM user WHERE userid='".$userid."'";
$result = $this->_database->query($query);
return !$result->fetch_assoc() == null;
}
/**
* First the necessary data is fetched and then the HTML is
* assembled for output. i.e. the header is generated, the content
* of the page ("view") is inserted and -if avaialable- the content of
* all views contained is generated.
* Finally the footer is added.
*
* @return void
*/
protected function getStatus()
{
if (!isset($_GET["userid"])) {
die ("userid-GET-Parameter muss gesetzt sein!");
}
$status = $this->getUserOrderStatus($_GET["userid"]);
echo json_encode($status);
}
/**
* Processes the data that comes via GET or POST i.e. CGI.
* If this page is supposed to do something with submitted
* data do it here.
* If the page contains blocks, delegate processing of the
* respective subsets of data to them.
*
* Führt Parameter-Prüfungen durch, erstellt Nutzer und einen passenden GenoCheck-Auftrag
*
* @return void
*/
protected function processReceivedData()
{
}
/**
* This main-function has the only purpose to create an instance
* of the class and to get all the things going.
* I.e. the operations of the class are called to produce
* the output of the HTML-file.
* The name "main" is no keyword for php. It is just used to
* indicate that function as the central starting point.
* To make it simpler this is a static function. That is you can simply
* call it without first creating an instance of the class.
*
* @return void
*/
public static function main()
{
session_start();
header("Content-Type: application/json; charset=UTF-8");
try {
$page = new StatusHelperAgent();
$page->processReceivedData();
$page->getStatus();
} catch (Exception $e) {
header("Content-type: text/plain; charset=UTF-8");
echo $e->getMessage();
}
}
}
// This call is starting the creation of the page.
// That is input is processed and output is created.
StatusHelperAgent::main();
// Zend standard does not like closing php-tag!
// PHP doesn't require the closing tag (it is assumed when the file ends).
// Not specifying the closing ? > helps to prevent accidents
// like additional whitespace which will cause session
// initialization to fail ("headers already sent").
//? >