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

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

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

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

if( !isReady($params, array( "name", "desc", "header_bg_color", "header_font_color", "footer_bg_color", "footer_font_color" ) ) ){
    dj($output);
}

if($settings['room_creation'] == 2 && $user['mem_level'] != 2 && $user['mem_level'] != 3){
    dj($output);
}

$title                      =   secure($params['name']);
$desc                       =   secure($params['desc']);
$avatar                     =   secure($params['showAvatar']) ? 1 : 2;
$hbg                        =   secure($params['header_bg_color']);
$hfc                        =   secure($params['header_font_color']);
$fbg                        =   secure($params['footer_bg_color']);
$ffc                        =   secure($params['footer_font_color']);
$hasImages                  =   intval($params['images']);
$fontFamily                 =   intval($params['fontFamily']);
$fontSize                   =   intval($params['fontSize']);
$fontColor                  =   intval($params['fontColor']);
$bold                       =   intval($params['bold']);
$italic                     =   intval($params['italic']);
$emotes                     =   intval($params['emotes']);
$links                      =   intval($params['links']);
$youtube                    =   intval($params['youtube']);
$files                      =   intval($params['files']);
$polls                      =   intval($params['polls']);
$bad_words                  =   secure($params['bad_words']);
$password                   =   secure($params['password']);

$insertChatQuery    =   $db->prepare("INSERT INTO chats(title,chat_desc,show_avatar,header_bg,header_font,
                                                        footer_bg,footer_font, images_enabled, font_enabled,size_enabled,color_enabled,
                                                        bold_enabled,italic_enabled,emotes_enabled,links_enabled,youtube_enabled,
                                                        files_enabled,polls_enabled,bad_words,password,owner)
                                      VALUES( :t, :cd, :sa, :hbg, :hfc,
                                              :fbg, :ffc, :img, :fe, :se,
                                              :ce, :be, :ie, :ee, :le,
                                              :ye, :files_e, :poe, :bad, :pass, :o
                                               )");
$insertChatQuery->execute(array(
    ":t"        =>  $title,
    ":cd"       =>  $desc,
    ":sa"       =>  $avatar,
    ":hbg"      =>  $hbg,
    ":hfc"      =>  $hfc,

    ":fbg"      =>  $fbg,
    ":ffc"      =>  $ffc,
    ":img"      =>  $hasImages,
    ":fe"       =>  $fontFamily,
    ":se"       =>  $fontSize,

    ":ce"       =>  $fontColor,
    ":be"       =>  $bold,
    ":ie"       =>  $italic,
    ":ee"       =>  $emotes,
    ":le"       =>  $links,

    ":ye"       =>  $youtube,
    ":files_e"  =>  $files,
    ":poe"      =>  $polls,
    ":bad"      =>  $bad_words,
    ":pass"     =>  $password,

    ":o"        =>  $_SESSION['username']
));

$output['status'] =   2;
$output['cid']    =   $db->lastInsertId();
dj($output);