-
Notifications
You must be signed in to change notification settings - Fork 28
/
admin_modification_requests.php
370 lines (337 loc) · 11.5 KB
/
admin_modification_requests.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
require_once("bootstrap.inc.php");
require_once("include_pouet/box-modalmessage.php");
require_once("include_pouet/box-party-submit.php");
if ($currentUser && !$currentUser->CanEditItems())
{
redirect("index.php");
exit();
}
class PouetBoxAdminModificationRequests extends PouetBox
{
public $requests;
function __construct( )
{
parent::__construct();
$this->uniqueID = "pouetbox_adminreq";
$this->title = "process the following requests";
}
use PouetForm;
function Commit($data)
{
global $currentUser;
$req = SQLLib::SelectRow(sprintf_esc("select itemID,requestType,requestBlob,approved from modification_requests where id = %d",$data["requestID"]));
if ($req->approved !== NULL)
return array("this request was already processed");
if (@$data["requestDeny"])
{
$a = array();
$a["gloperatorID"] = $currentUser->id;
$a["approved"] = 0;
$a["comment"] = $data["comment"];
$a["approveDate"] = date("Y-m-d H:i:s");
SQLLib::UpdateRow("modification_requests",$a,"id=".(int)$data["requestID"]);
return array();
}
$reqData = unserialize($req->requestBlob);
global $REQUESTTYPES;
if ($REQUESTTYPES[$req->requestType])
{
$errors = null;
try
{
$errors = $REQUESTTYPES[$req->requestType]::Process($req->itemID,$reqData);
}
catch(Exception $e)
{
$errors = array((string)$e);
}
if ($errors) return $errors;
gloperator_log( $REQUESTTYPES[$req->requestType]::GetItemType(), $req->itemID, $req->requestType, $reqData );
}
else
{
return array("no such request type!");
}
$a = array();
$a["gloperatorID"] = $currentUser->id;
$a["approved"] = 1;
$a["approveDate"] = date("Y-m-d H:i:s");
SQLLib::UpdateRow("modification_requests",$a,"id=".(int)$data["requestID"]);
return array();
}
function LoadFromDB()
{
$s = new BM_Query();
$s->AddTable("modification_requests");
$s->AddField("modification_requests.id");
$s->AddField("modification_requests.requestType");
$s->AddField("modification_requests.itemID");
$s->AddField("modification_requests.itemType");
$s->AddField("modification_requests.requestBlob");
$s->AddField("modification_requests.requestDate");
$s->Attach(array("modification_requests"=>"userID"),array("users as user"=>"id"));
$s->Attach(array("modification_requests"=>"itemID"),array("prods as prod"=>"id") ,"modification_requests.itemType = 'prod'");
$s->Attach(array("modification_requests"=>"itemID"),array("groups as group"=>"id"),"modification_requests.itemType = 'group'");
$s->AddWhere("approved is null");
$s->AddOrder("requestDate desc");
$this->requests = $s->perform();
}
function Render()
{
global $REQUESTTYPES;
echo "<table id='".$this->uniqueID."' class='boxtable'>\n";
echo " <tr>\n";
echo " <th colspan='6'>".$this->title."</th>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <th>date</th>\n";
echo " <th>user</th>\n";
echo " <th>item</th>\n";
echo " <th>request</th>\n";
echo " <th>details</th>\n";
echo " <th> </th>\n";
echo " </tr>\n";
foreach($this->requests as $r)
{
echo " <tr>\n";
echo " <td>".$r->requestDate."</td>\n";
echo " <td>".$r->user->PrintLinkedAvatar()." ".$r->user->PrintLinkedName()."</td>\n";
echo " <td>".$r->itemType.": ";
switch ($r->itemType)
{
case "prod" : if ($r->prod ) echo $r->prod->RenderSingleRowShort(); break;
case "group": if ($r->group) echo $r->group->RenderLong(); break;
}
echo "</td>\n";
echo " <td>".$REQUESTTYPES[$r->requestType]::Describe()."</td>\n";
echo " <td>";
$data = unserialize($r->requestBlob);
global $REQUESTTYPES;
if ($REQUESTTYPES[$r->requestType])
echo $REQUESTTYPES[$r->requestType]::Display($r->itemID,$data);
echo "</td>\n";
echo "<td>";
printf("<form action='%s' method='post' enctype='multipart/form-data'>\n",_html(selfPath()));
$csrf = new CSRFProtect();
$csrf->PrintToken();
printf(" <input type='hidden' name='requestID' value='%d'/>",$r->id);
printf(" <input type='submit' name='requestAccept' value='accept !'/>");
printf(" <input type='submit' name='requestDeny' value='deny !'/>");
printf(" <span class='result'></span>");
printf(" <input type='hidden' name='%s' value='%s'/>\n",PouetFormProcessor::fieldName,"adminModReq");
printf("</form>\n\n\n");
echo "</td>\n";
echo " </tr>\n";
}
echo "</table>\n";
?>
<script>
<!--
document.observe("dom:loaded",function(){
<?php
if (defined("YOUTUBE_FRONTEND_KEY")) {
?>
function Youtubify( parentElement, detailed )
{
var videoIDs = {};
var playlistIDs = {};
var ytAPIKey = "<?=YOUTUBE_FRONTEND_KEY?>";
parentElement.select("a[rel='external']").each(function(element){
var videoID = element.href.match(/youtu(\.be\/|.*v=)([a-zA-Z0-9_\-]{11})/);
if (videoID)
{
videoIDs[videoID[2]] = element;
return;
}
var playlistID = element.href.match(/youtube\.com\/playlist\?.*list=([a-zA-Z0-9_\-]{34})/);
if (playlistID)
{
playlistIDs[playlistID[1]] = element;
return;
}
var pouetID = element.href.match(/pouet\.net\/prod\.php.*which=([0-9]+)/);
if (pouetID)
{
new Ajax.JSONRequest("https://api.pouet.net/v1/prod/?id="+pouetID[1],{
method: "get",
onSuccess: function(transport) {
if (transport.responseJSON.success)
{
var s = transport.responseJSON.prod.name;
item.update( s.escapeHTML() );
item.addClassName("pouet");
}
},
});
return;
}
var demozooProdID = element.href.match(/demozoo\.org\/productions\/([0-9]+)/);
if (demozooProdID)
{
new Ajax.JSONRequest("https://demozoo.org/api/v1/productions/"+demozooProdID[1]+"/?format=jsonp",{
method: "get",
onSuccess: function(transport) {
if (transport.responseJSON)
{
var s = transport.responseJSON.title;
item.update( s.escapeHTML() );
item.addClassName("demozoo");
}
},
});
return;
}
});
if (Object.keys(videoIDs).length)
{
new Ajax.JSONRequest("https://www.googleapis.com/youtube/v3/videos?id=" + Object.keys(videoIDs).join(",") + "&key=" + ytAPIKey + "&part=snippet",{
method: "get",
onException: function(r, ex) { throw ex; },
onSuccess: function(transport) {
if (transport.responseJSON.items)
{
for(var i=0; i<transport.responseJSON.items.length; i++)
{
var item = transport.responseJSON.items[i];
var element = videoIDs[item.id];
var s = item.snippet.title.escapeHTML();
if (detailed)
{
s += " <small>("+item.snippet.channelTitle.escapeHTML()+")</small>";
}
element.update( s );
element.addClassName("youtube");
}
}
},
});
}
if (Object.keys(playlistIDs).length)
{
new Ajax.JSONRequest("https://www.googleapis.com/youtube/v3/playlists?id=" + Object.keys(playlistIDs).join(",") + "&key=" + ytAPIKey + "&part=snippet",{
method: "get",
onException: function(r, ex) { throw ex; },
onSuccess: function(transport) {
if (transport.responseJSON.items)
{
for(var i=0; i<transport.responseJSON.items.length; i++)
{
var item = transport.responseJSON.items[i];
var element = playlistIDs[item.id];
var s = item.snippet.title.escapeHTML();
if (detailed)
{
s += " <small>("+item.snippet.channelTitle.escapeHTML()+")</small>";
}
element.update( s );
element.addClassName("youtube");
}
}
},
});
}
}
$$("#pouetbox_adminreq th[colspan]").first().insert( " [" );
$$("#pouetbox_adminreq th[colspan]").first().insert( new Element("a",{"href":"#"}).update("resolve youtube links").observe("click",function(){
Youtubify( $("pouetbox_adminreq").down('tbody'), true );
}) );
$$("#pouetbox_adminreq th[colspan]").first().insert( "]" );
<?php
}
?>
function fireError( e, msg )
{
console.error( "[pouet] There's been an error:\n--------------\n" + msg );
fireErrorOverlay( "There's been an error:<br/>" + msg );
e.element().select("input[type='submit']").invoke("removeAttribute","disabled");
var result = e.element().select(".result").first();
result.update("⚠");
result.setAttribute("title","There's been an internal error; check console for details.");
}
$$("#pouetbox_adminreq input[type='submit']").invoke("observe","click",function(e){ e.element().setAttribute("clicked","true"); });
$$("#pouetbox_adminreq form").invoke("observe","submit",function(e){
e.stop();
var reqAction = e.element().select("input[type='submit'][clicked='true']").first().name;
var reason = null;
if (reqAction == "requestDeny")
{
reason = prompt("Enter the reason why you want to deny this request");
if (reason == null || !reason.length)
return;
}
e.element().select("input[type='submit']").invoke("setAttribute","disabled",true);
var opt = Form.serializeElements( e.element().select("input[type='hidden']"), {hash:true} );
opt["partial"] = true;
opt["comment"] = reason;
opt[ reqAction ] = true;
new Ajax.Request( e.element().action, {
method: e.element().method,
parameters: opt,
onException: function(r, ex) { fireError( e, ex ); throw ex; },
onSuccess: function(transport)
{
if (!transport.responseJSON || !transport.responseJSON.success)
{
var msg = (transport.responseJSON && transport.responseJSON.errors) ? transport.responseJSON.errors.join("<br/>") : transport.responseText;
fireError( e, msg );
return;
}
e.element().up("tr").remove();
fireSuccessOverlay( transport.responseJSON.success == "accepted" ? "request accepted !" : "request denied !");
}
});
});
});
//-->
</script>
<?php
}
}
$form = new PouetFormProcessor();
$form->renderForm = false;
$box = new PouetBoxAdminModificationRequests( );
$form->Add( "adminModReq", $box );
if ($currentUser && $currentUser->CanEditItems())
{
if (@$_POST["partial"])
{
$form->SetSuccessURL( "", false );
$form->Process();
$response = array();
if ($form->GetErrors())
{
$response["errors"] = $form->GetErrors();
}
else
{
$response["success"] = @$_POST["requestAccept"] ? "accepted" : "denied";
}
header("Content-type: application/json; charset=utf-8");
echo json_encode($response);
exit();
}
else
{
$form->SetSuccessURL( "admin_modification_requests.php", true );
$form->Process();
}
}
$TITLE = "process modification requests";
require_once("include_pouet/header.php");
require("include_pouet/menu.inc.php");
echo "<div id='content'>\n";
if (get_login_id())
{
$form->Display();
}
else
{
require_once("include_pouet/box-login.php");
$box = new PouetBoxLogin();
$box->Render();
}
echo "</div>\n";
require("include_pouet/menu.inc.php");
require_once("include_pouet/footer.php");
?>