php8
[web.mtrack] / admin / watch.php
1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3 include '../../inc/common.php';
4
5 $me = mtrack_canon_username(MTrackAuth::whoami());
6
7 if ($me == 'anonymous' || MTrackAuth::getUserClass() == 'anonymous') {
8   exit;
9 }
10
11 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
12   $object = $_GET['o'];
13   $id = $_GET['i'];
14   $v = $_POST['w'];
15   $value = json_decode($v);
16
17   $db = MTrackDB::get();
18   $db->beginTransaction();
19   MTrackDB::q('delete from watches where otype = ? and oid = ? and userid = ?',
20     $object, $id, $me);
21
22   foreach ($value as $medium => $events) {
23     foreach ($events as $evt => $value) {
24       MTrackDB::q('insert into watches (otype, oid, userid, medium, event, active) values (?, ?, ?, ?, ?, 1)',
25         $object, $id, $me, $medium, $evt);
26     }
27   }
28
29   $db->commit();
30 }
31