<?php
/*
 * (c) 2007 Prominate Solutions Ltd.
 * http://www.prominate.com
 *
 * THIS FILE IS PRE-ALPHA AND NOT FULLY TESTED
 * THIS FILE IS TO BE RELEASED AS GPL / LGPL
 */

// Make sure we're in the system
if( !defined(IN_SYS) || IN_SYS !== TRUE ) {
	die("Hacking attempt");
}

// If file was included properly check session
$sess->monitorSession($_SESSION);
?>
<h2>Post management</h2>

<script type="text/javascript" src="./cn-js/functions.js"></script>

<h3>Add new post <small>[ <a href="#" onclick="expandNewPostbox();">expand</a> | <a href="#" onclick="collapseNewPostbox();">collapse</a> ]</small></h3>
<div id="newPostBox" style=" visibility: hidden; height: 0px; ">
	<form name="addPost" action="?page=post02" method="post">
		Publish on the following domain(s):<br />
		<?php
			$result	= $sql->query("SELECT id, domain FROM websites");
			
			$domain	= array();
			
			while( $data = $sql->fetch_assoc($result) ) {
				$domain[$data['id']]	= $data['domain'];
				echo "<input type=\"checkbox\" name=\"domainId[]\" id=\"".$data['domain']."\" value=\"".$data['id']."\"> <label for=\"".$data['domain']."\">".$data['domain']."</label>\n ";	
			}
		?>
		<br /><br />
		Title: <input type="text" name="title" maxlength="255" style=" width: 255px; " /><br />
		<br />
		Message:<br />
		<?php
		include("./cn-fckeditor/fckeditor.php");
		$fcke	= new FCKeditor('content');
		$fcke->BasePath	= "./cn-fckeditor/";
		$fcke->Height	= "400px";
		$fcke->Create();
		?>
		<br />
		<input type="submit" name="addPost" value="Save Post" />
	</form>
</div>

<h3>Edit / delete existing posts</h3>

<table width="800" cellpadding="0" cellspacing="1" style=" border: 2px solid #999999; padding: 5px; ">
	<tr>
		<td class="rowBg1" width="40%" style=" text-align: center; ">Title</td>
		<td class="rowBg1" width="40%" style=" text-align: center; ">Published on</td>
		<td class="rowBg1" style=" text-align: center; " width="20%">Options</td>
	</tr>
<?php
$result	= $sql->query("SELECT id, domainId, title FROM posts");

$i = 1;
while( $data = $sql->fetch_assoc($result) ) {
	$ids	= explode(" ", $data['domainId']);
	$domains	= "";
	foreach( $ids as $value ) {
		$domains	.= $domain[$value]." ";
	}
	
	if( $i == 2 ) : $i = 1; else : $i++; endif;
	?>
	<tr>
		<td class="rowBg<?php echo $i; ?>"><?php echo $data['title']; ?></td>
		<td class="rowBg<?php echo $i; ?>" style=" text-align: center; "><?php echo $domains; ?></td>
		<td class="rowBg<?php echo $i; ?>" style=" text-align: center; "><a href="?page=post03&amp;id=<?php echo $data['id']; ?>">Edit</a> | <a href="?page=post04&amp;id=<?php echo $data['id']; ?>">Delete</a></td>
	</tr>		
	<?
}
?>
</table>