YaWK  24.1
Yet another WebKit
message-toggle.php
Go to the documentation of this file.
1 <?php
2 /*
3 if (!isset($_POST['token'])) {
4  die ('no direct access allowed.');
5 }
6 else if ($_POST['token'] != "U3E44ERG0H0M3") {
7  die ('no direct access allowed!');
8 }
9 */
10 include '../../../classes/db.php';
11 include '../../../classes/alert.php';
12 include '../classes/messages.php';
13 
14 /* set database object */
15 if (!isset($db))
16 { // create db object if not exists...
17  $db = new \YAWK\db();
18 }
19 
20 $msg_id = $_POST['msg_id'];
21 
22 // check status before toggle
23 $sql = $db->query("SELECT msg_read FROM {plugin_msg} WHERE msg_id='".$msg_id."'");
24 $res = mysqli_fetch_row($sql);
25 if ($res[0] === '1')
26 { // toggle to unread
27  if ($db->query("UPDATE {plugin_msg} SET msg_read='0' WHERE msg_id='".$msg_id."'"))
28  {
29  echo "message marked as unread";
30  }
31  else
32  {
33  die ("failed to mark as unread");
34  }
35 }
36 else
37 { // toggle to read
38  if ($db->query("UPDATE {plugin_msg} SET msg_read='1' WHERE msg_id='".$msg_id."'"))
39  {
40  echo "message marked as read";
41  }
42  else
43  {
44  die ("failed to mark as read");
45  }
46 }
die
Definition: block-user.php:27
if(!isset($db)) $msg_id