forked from howest-wsde/owaes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.owaes.php
270 lines (246 loc) · 7.22 KB
/
get.owaes.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
// get/owaes?help => help
include "inc.default.php"; // should be included in EVERY file
$oSecurity = new security();
$strFormat = $_GET["format"];
$strTemplate = $_GET["file"];
$arInfo = array();
$arInfo["timestamp"] = owaesTime();
$arResult = array();
$arError = array();
if (isset($_GET["help"])) {
$arInfo["help"] = array(
"request" => array(
"get/owaes" => "",
"get/FORMAT/owaes" => "xml / json / txt / html",
"get/FORMAT/owaes/?PARAMETERS" => "zie onder",
"get/owaes/TEMPLATE.HTML" => "use template uit template-folder",
"get/FORMAT/owaes/TEMPLATE.HTML" => "include template uit template-folder",
),
"parameters" => array(
"token" => array(
"format" => "string",
"info" => "token van de gebruiker",
),
"type" => array(
"format" => "string",
"accepted" => "'market' / 'work'",
"info" => "",
),
"author" => array(
"format" => "integer",
"info" => "enkel berichten van deze author (id) worden getoond",
),
"group" => array(
"format" => "integer",
"info" => "enkel berichten van deze groep worden getoond",
),
"status" => array(
"format" => "string / integer",
"accepted" => "recrute / 0 , selected / 1 , finished / 2, open",
"info" => "",
),
"subscribed" => array(
"format" => "string",
"accepted" => "'YES', 'CONFIRMED', 'NOTCONFIRMED'",
"info" => "enkel berichten waar de huidige gebruiker wel/niet voor ingeschreven is. Token verplicht! ",
),
"payed" => array(
"format" => "string",
"accepted" => "'YES', 'NO'",
"info" => "berichten filteren naargelang de creditsoverdracht gebeurd is. (yes = transactie is gebeurd, no = transactie moet nog gebeuren). Token verplicht! ",
),
"rating" => array(
"format" => "string",
"accepted" => "'YES', 'NO'",
"info" => "berichten filteren naargelang de sterren gegeven. Token verplicht! ",
),
"search" => array(
"format" => "string",
"info" => "",
),
"id" => array(
"format" => "integer",
"info" => "toont enkel het bericht met opgegeven ID",
),
),
);
output (array("info" => $arInfo), $strFormat);
}
$oOwaesList = new owaeslist();
if (isset($_GET["type"])) {
switch(strtolower($_GET["type"])) {
case "market":
case "work":
$oOwaesList->filterByType($_GET["type"]);
break;
default:
output (array("error" => "type: invalid value"), $strFormat);
}
}
if (isset($_GET["id"])) {
$oOwaesList->filterByID(intval($_GET["id"]));
}
if (isset($_GET["status"])) {
switch(strtolower($_GET["status"])) {
case "open":
$oOwaesList->filterByState(array(STATE_RECRUTE, STATE_SELECTED));
break;
case "recrute":
case STATE_RECRUTE:
$oOwaesList->filterByState(STATE_RECRUTE);
break;
case "selected":
case STATE_SELECTED:
$oOwaesList->filterByState(STATE_SELECTED);
break;
case "finished":
case STATE_FINISHED:
$oOwaesList->filterByState(STATE_FINISHED);
break;
default:
output (array("error" => "status: invalid value"), $strFormat);
}
}
if (isset($_GET["subscribed"])) {
switch(strtolower($_GET["subscribed"])) {
case "yes":
case "true":
case 1:
$oOwaesList->subscribed(me(), "yes");
break;
case "confirmed":
$oOwaesList->subscribed(me(), "confirmed");
break;
case "notconfirmed":
$oOwaesList->subscribed(me(), "notconfirmed");
break;
case "no":
case "false":
case 0:
$oOwaesList->subscribed(me(), "no");
break;
default:
output (array("error" => "subscribed: invalid value"), $strFormat);
}
}
if (isset($_GET["payed"])) {
switch(strtolower($_GET["payed"])) {
case "yes":
case "true":
case 1:
$oOwaesList->payment(me(), "yes");
break;
case "no":
case "false":
case 0:
$oOwaesList->payment(me(), "no");
break;
default:
output (array("error" => "transaction: invalid value"), $strFormat);
}
}
if (isset($_GET["rating"])) {
switch(strtolower($_GET["rating"])) {
case "yes":
case "true":
case 1:
$oOwaesList->rated(me(), "yes");
break;
case "no":
case "false":
case 0:
$oOwaesList->rated(me(), "no");
break;
default:
output (array("error" => "rating: invalid value"), $strFormat);
}
}
if (isset($_GET["author"])) $oOwaesList->filterByUser(intval($_GET["author"]));
//$oOwaesList->filterByState(STATE_RECRUTE);
foreach ((isset($_POST["show"])?$_POST["show"]:array()) as $iCat) $oOwaesList->hasCategory($iCat);
foreach ((isset($_POST["hide"])?$_POST["hide"]:array()) as $iCat) $oOwaesList->notCategory($iCat);
foreach ((isset($_POST["waarden"])?$_POST["waarden"]:array()) as $strWaarde) $oOwaesList->hasWaarde($strWaarde);
foreach ($oOwaesList->getList() as $oItem) {
$arItem = array(
"id" => $oItem->id(),
"link" => $oItem->url(),
"author" => $oItem->author()->id(),
"group" => $oItem->group() ? $oItem->group()->id() : 0,
"title" => $oItem->title(),
"body" => $oItem->body(),
"location" => array(
"text" => $oItem->location(),
"latitude" => $oItem->latitude(),
"longitude" => $oItem->longitude(),
),
"data" => $oItem->data(),
"timing" => $oItem->timing(),
"indicators" => array(
"mental" => $oItem->mental(),
"emotional" => $oItem->emotional(),
"physical" => $oItem->physical(),
"social" => $oItem->social(),
),
"credits" => $oItem->credits(),
);
if ($strTemplate != "") $arItem["html"] = $oItem->html($strTemplate);
$arResult[] = $arItem;
// echo $oItem->HTML("owaeskort.html");
}
output (array("info" => $arInfo, "result" => $arResult), $strFormat, $strTemplate);
function output($arOutput, $strFormat = "txt", $strTemplate = "") {
switch(strtolower($strFormat)) {
case "json":
echo json_encode($arOutput);
break;
case "xml":
break;
case "txt":
echo (outputTXT($arOutput));
break;
case "":
case "htm":
case "html":
echo (outputHTML($arOutput, $strTemplate));
break;
default:
echo ("ongeldig formaat ('$strFormat'), momenteel enkel 'json', 'xml' of 'html'");
}
exit();
}
function outputTXT($arOutput, $iDepth = 0) {
$strResult = "";
foreach ($arOutput as $strKey=>$strValue) {
$strResult .= str_repeat(" ",$iDepth);
if (is_array($strValue)) {
$strResult .= $strKey . ": \n" . outputTxt($strValue, $iDepth+1);
} else {
$strResult .= $strKey . ": " . $strValue . "\n";
}
}
return $strResult;
}
function outputHTML($arOutput, $strTemplate) {
if (isset($arOutput["result"]) && ($strTemplate != "")) {
$strResult = "";
foreach ($arOutput["result"] as $arItem) {
$strResult .= $arItem["html"];
}
} else {
$strResult = "<dl>";
foreach ($arOutput as $strKey=>$strValue) {
$strResult .= "<dt>" . $strKey . "</dt>";
$strResult .= "<dd>";
if (is_array($strValue)) {
$strResult .= outputHTML($strValue, $strTemplate);
} else {
$strResult .= $strValue;
}
$strResult .= "</dd>";
}
$strResult .= "</dl>";
}
return $strResult;
}
?>