<?php 
require("common_begin.php");

$lst = Listopia::getInstance();

$result = array();

if ($lst->isLoggedIn() && isset($_POST['id']) && isset($_POST['op']))
{
  // ensure this message belongs to this user
  $query = $lst->Database()->select(array(
                'fields' => 'mess_to',
                'table' => 'messages',
                'condition' => 'mess_id = '.$_POST['id']
                ));
                
  if (!empty($query[0]))
  {
    if ($query[0]['messages']['mess_to'] == Session::getInstance()->gl_userid)
    {
      $result['result'] = $lst->modifyMessage($_POST['id'], $_POST['op']);
      $result['success'] = true;
    }
    else
    {
      $result['result'] = "That message doesn't belong to you, shitbird";
    }
  }
  else
  {
    $result['result'] = "This message doesn't exist or something";
  }
}
else
{
  $result['result'] = "Not logged in";
}

echo json_encode($result);

require("common_end.php");

