<?php
/**
 * Created by PhpStorm.
 * User: jaskokoyn
 * Date: 2/16/2015
 * Time: 9:33 PM
 */

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

if(!isset($_SESSION['loggedin']) || $user['mem_level'] != 2){
    die("AYYYYYY");
}

if( !isReady($_POST, array( "cid", "title", "desc", "headerBG", "headerColor", "footerBG", "footerColor" ) ) ){
    die( "EMPTY" );
}

$cid    =   intval($_POST['cid']);
$title  =   secure($_POST['title']);
$desc   =   secure($_POST['desc']);
$avatar =   (secure($_POST['showAvatar']) == "true") ? 1 : 2;
$hbg    =   secure($_POST['headerBG']);
$hfc    =   secure($_POST['headerColor']);
$fbg    =   secure($_POST['footerBG']);
$ffc    =   secure($_POST['footerColor']);

$updateChatQuery    =   $db->prepare("UPDATE chats SET title = :t,
                                                       chat_desc = :cd,
                                                         show_avatar = :sa,
                                                         header_bg = :hbg,
                                                         header_font = :hfc,
                                                         footer_bg = :fbg,
                                                         footer_font = :ffc
                                                         WHERE id = :id");
$updateChatQuery->execute(array(
    ":t"        =>  $title,
    ":cd"       =>  $desc,
    ":sa"       =>  $avatar,
    ":hbg"      =>  $hbg,
    ":hfc"      =>  $hfc,
    ":fbg"      =>  $fbg,
    ":ffc"      =>  $ffc,
    ":id"       =>  $cid
));

die("SUCCESS");