<?php
define('FA_SYSTEM', true);

require("./core.fpd");
$filename = "admin.fpd";

//Make sure that the admin.fpd file exists to ensure user is an admin...
if($adminstatus == true) {
	require("./file_functions.fpd");
	
	//For posting news from the index.fpd file...
	if($_REQUEST['action'] == "postnews") {
		$sql->query("INSERT INTO iworks_news (date,user,comments,username,strlower,subject,message)
				VALUES
				('".time()."','$user_info[userid]','0','$user_info[username]','$user_info[strlower]','".addslashes($_REQUEST[title])."','".addslashes($_REQUEST[message])."')");
		header("LOCATION: $_REQUEST[returnlink]");
		exit();
	}
	
	//Deletion of announcements
	if($_REQUEST['action'] == "deleteannouncement") {
		$rowid = $sql->query_first("SELECT rowid FROM iworks_news WHERE date='$_REQUEST[a]'");
		$sql->query("DELETE FROM iworks_news WHERE rowid='$rowid[rowid]'");
		$sql->query("DELETE FROM iworks_news_comments WHERE article='$rowid[rowid]'");
		header("LOCATION: index.fpd");
		exit();
	}
	
	//This will lock out the system entirely...
	if($_REQUEST['action'] == "setlock") {
		$modestatus = setread($mode);
		header("LOCATION: $_REQUEST[returnlink]");
		exit();
	} 
	
	//For putting the system into a read-only status...
	if($_REQUEST['action'] == "setmode") {
		$modestatus = setmode($mode);
		header("LOCATION: $_REQUEST[returnlink]");
		exit();
	} else {
		echo "Please select an option:<BR>
			<a href='admin.fpd?action=setmode&mode=readonly&returnlink=admin.fpd'>Put system into read-only mode</a><BR>
			<a href='admin.fpd?action=setmode&mode=normal&returnlink=admin.fpd'>Take system out of read-only mode</a>";
		exit();
	}
} else {
	echo "Authorization failed!";
	exit();
}
?>
