<?php
include(BASE_URL.'includes/admin/editors/fckeditor/fckeditor.php');
$id = sanitize_sql_string($_GET['id']);
if($_POST['save']) {
	foreach($_POST as $key => $value) {
		$_POST[$key] = sanitize_sql_string($value);
	}
	$sql = "UPDATE ".DBTABLEPREFIX."content_template SET content = '".$_POST['static-content']."' WHERE id = '".$_POST['id']."'";
	$run = $admin->db_query($sql)or die($output .= $admin->message('error', 'MySQL Error', mysql_error()));
	if(!$run) {
		$output .= $admin->message('error', 'Unknown Error', 'See above.');
	}
	else {
		$output .= $admin->message('success', 'Woohoo! Successfully updated the static content!', 'Congrats! The chanages are applied accross all pages!');
	}
}
elseif($_GET['id']) {
	$id = sanitize_sql_string($_GET['id']);
	$staticContent = $theme->arrayStaticContent();
	foreach($staticContent as $key => $value) {
		$key = explode('|', $key);
		$sid = $key[1];
		$name = $key[0];
		if($sid == $id) {
			$title = $name;
			$content = $value;
		}
	}
			$FCKeditor_content = new FCKeditor('static-content') ;
			$FCKeditor_content->BasePath = THEME_URL.'includes/admin/editors/fckeditor/';
			$FCKeditor_content->Value = stripslashes($content);
			$FCKeditor_content->Width = '100%' ;
			$FCKeditor_content->Height = '350' ;
			$FCKeditor_content_html = $FCKeditor_content->CreateHtml();
		$form = '
							<form action="?page=edit-static-content" method="post">
								<fieldset>
									<h2>Edit Static Content "'.$title.'" </h2>
									<div class="form-row">
										<label class="content" for="content">Static Content</label>
										<span class="content">
											'.$FCKeditor_content_html.'
										</span>
									</div>
									<div class="form-row form-row-last">
										<label for="save">Save</label>
										<span><input type="hidden" name="id" value="'.$id.'" /><input type="submit" name="save" value="Update Static Content" class="submit" /></span>
									</div>
								</fieldset>
							</form>
		';
}
else {
}
	$staticContent = $theme->arrayStaticContent();
	$table .= "\n<table cellspacing='0' border='0' id='static-content' cellpadding='0'>\n\t<thead>\n\t\t<tr>\n\t\t\t<th>Name</th><th>Template</th><th class='td-actions'>Actions</th>\n\t\t</tr>\n\t<tbody>";
	foreach($staticContent as $key => $value) {
		$key = explode('|', $key);
		$id = $key[1];
		$name = $key[0];
		$table .= "\n\t\t<tr title='Edit the {$name}' class='helplink'><td class='static-name'><a style='display:block;' href='?page=edit-static-content&id={$id}'>{$name}</a></td><td class='current-theme'>{$admin->page_info['settings']['Theme']['value']}</td><td class='td-actions'><a href='?page=edit-static-content&id={$id}'><img src='".BASE_URL."includes/admin/images/icons/edit-16x16.png' alt='Edit' /></a></td></tr>";
	}
	$table .= "</tbody></table>";	

$admin->page_info['content']['page_title'] = "Edit Static Content";
$admin->page_info['content']['page_content']	= $output.$table.$form;
//Display page
include(BASE_URL.'includes/admin/admin.php');
?>