<?php
/**
 * Created by PhpStorm.
 * User: jaskokoyn
 * Date: 4/28/2015
 * Time: 9:08 PM
 */

include('../../inc/db.php');
include('../../inc/functions.php');

$params                     =   getParams();
$output                     =   array('status' => 1);

if(!isset($_SESSION['loggedin'])){
    dj($output);
}

// Check if owner
$chatQuery                      =   $db->prepare("SELECT `owner` FROM chats WHERE id = :cid");
$chatQuery->execute(array( ":cid" => $cid ));
$chatRow                        =   $chatQuery->fetch();

// Check if chat mod
$checkModQuery                  =   $db->prepare("SELECT * FROM chat_mods WHERE username = :u AND cid = :cid");
$checkModQuery->execute(array(
    ":u"                        =>  $_SESSION['username'],
    ":cid"                      =>  $cid
));

if($user['mem_level'] != 2 && $user['mem_level'] == 3 && $checkModQuery->rowCount() === 0 && $chatRow['owner'] != $_SESSION['username']){
    dj($output);
}

$mid                        =   intval($params['mid']);
$deleteQuery                =   $db->prepare("DELETE FROM messages WHERE id = :id");
$deleteQuery->execute(array(
    ":id"                   =>  $mid
));
$output['status']           =   2;
dj($output);