<?php
if (!defined('FLUX_ROOT')) exit;
$this->loginRequired();


$charsql = $server->connection->getStatement("SELECT * FROM {$server->charMapDatabase}.char WHERE account_id = ?");
$charsql->execute(array($session->account->account_id));
$charlist = $charsql->fetchAll();
$charselect=NULL;
if(!$charlist){
	$charselect='<option value="-1">No Chars Available</option>';
} else {
	foreach($charlist as $char){$charselect.='<option value="'. $char->char_id .'">'. $char->name .'</option>';}
}

$catsql = $server->connection->getStatement("SELECT * FROM {$server->loginDatabase}.cp_changelogscat WHERE `display` = 1");
$catsql->execute();
$catlist = $catsql->fetchAll();

if(isset($_POST['account_id'])){
	$char_id	= $_POST['char_id'];
	$category	= $_POST['category'];
	$subject	= $_POST['subject'];
	$text		= $_POST['text'];
	if($_POST['sslink']	== NULL || $_POST['sslink']	==''){$_POST['sslink'] = '0';}		else{$_POST['sslink'] 		= $_POST['sslink'];}
	if($_POST['chatlink']	== NULL || $_POST['chatlink']	==''){$_POST['chatlink'] = '0';}	else{$_POST['chatlink'] 	= $_POST['chatlink'];}
	if($_POST['videolink']	== NULL || $_POST['videolink']	==''){$_POST['videolink'] = '0';}	else{$_POST['videolink'] 	= $_POST['videolink'];}

	$sql = "INSERT INTO {$server->loginDatabase}.cp_changelogs (char_id, category, subject, text, sslink, chatlink, videolink, timestamp)";
	$sql .= "VALUES (?, ?, ?, ?, ?, ?, ?, NOW())";
	$sth = $server->connection->getStatement($sql);
	$sth->execute(array($char_id, $category, $subject, $text, $_POST['sslink'], $_POST['chatlink'], $_POST['videolink'])); 

	$this->redirect($this->url('changelog','create'));
}
?>