/
closeSession.php
executable file
·54 lines (45 loc) · 1.44 KB
/
closeSession.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
<?php
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
require_once('../../../lib/parapara.inc');
require_once('api.inc');
require_once('walls.inc');
header('Content-Type: text/plain; charset=UTF-8');
// Check we are logged in
session_name(WALLMAKER_SESSION_NAME);
session_start();
if (!isset($_SESSION['email'])) {
bailWithError('logged-out');
}
// Parse input
$handle = fopen('php://input','r');
$jsonString = fgets($handle);
$json = json_decode($jsonString,true);
fclose($handle);
// Prepare parameters
$wallId = toIntOrNull($json['wallId']);
$sessionId = toIntOrNull($json['sessionId']);
if (!isset($wallId) || !isset($sessionId)) {
bailWithError('bad-request');
}
// Get wall
$wall = Walls::getById($wallId, $_SESSION['email']);
if ($wall === null)
bailWithError('not-found');
// End session
$currentdatetime = gmdate("Y-m-d H:i:s");
$madeChange = $wall->endSession($sessionId, $currentdatetime);
// Return the result
// - If we made a change then return the latest session.
// - Otherwise return a parallel-change notification with the latest session in
// the detail.
$latestSession = $wall->latestSession;
if ($madeChange) {
print json_encode($latestSession);
} else {
$result['error_key'] = 'parallel-change';
$result['error_detail'] = $latestSession;
print json_encode($result);
}
?>