-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate.php
More file actions
55 lines (51 loc) · 1.82 KB
/
Copy pathupdate.php
File metadata and controls
55 lines (51 loc) · 1.82 KB
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
<?php
require_once "../config.php";
use \Tsugi\Core\LTIX;
use \Tsugi\Util\U;
use \Tsugi\UI\Output;
// Sanity checks
$LAUNCH = LTIX::requireData();
Output::headerJson();
$p = $CFG->dbprefix;
$lat = U::get($_POST, 'lat');
$lng = U::get($_POST, 'lng');
if ( $lat !== null && $lng !== null ) {
$lat = $lat+0;
$lng = $lng+0;
if ( abs($lat) > 85 || abs($lng) > 180 || ($lat == 0 && $lng == 0) ) {
echo(json_encode(array('status'=> 'failure', 'lat' => $lat, 'lng' => $lng)));
return;
}
$sql = "INSERT INTO {$p}context_map
(context_id, user_id, lat, lng, updated_at)
VALUES ( :CID, :UID, :LAT, :LNG, NOW() )
ON DUPLICATE KEY
UPDATE lat = :LAT, lng = :LNG, updated_at = NOW()";
$PDOX->queryDie($sql, array(
':CID' => $CONTEXT->id,
':UID' => $USER->id,
':LAT' => $lat,
':LNG' => $lng));
echo(json_encode(array('status'=> 'success', 'lat' => $lat, 'lng' => $lng)));
return;
}
$allow_name = U::get($_POST, 'allow_name');
$allow_email = U::get($_POST, 'allow_email');
$allow_first = U::get($_POST, 'allow_first');
if ( $allow_name !== null && $allow_email !== null && $allow_first !== null ) {
$sql = "INSERT INTO {$p}context_map
(context_id, user_id, name, email, first, updated_at)
VALUES ( :CID, :UID, :NAME, :EMAIL, :FIRST, NOW() )
ON DUPLICATE KEY
UPDATE name = :NAME, email = :EMAIL, first = :FIRST, updated_at = NOW()";
$PDOX->queryDie($sql, array(
':CID' => $CONTEXT->id,
':UID' => $USER->id,
':NAME' => $allow_name+0,
':FIRST' => $allow_first+0,
':EMAIL' => $allow_email+0));
echo(json_encode(array('status'=> 'success', 'email' => $allow_email,
'name' => $allow_name, 'first' => $allow_first)));
return;
}
echo(json_encode(array('status'=> 'failure')));