<?php
if (!defined("ADMIN_FILE") || !is_admin_modul($aid, "News")) die("Illegal File Access");

include("config/config_fields.php");

function NewsNavi() {
	global $admin_file;
	GraphicAdmin();
	OpenTable();
    echo "<center><font class=\"title\">"._ARTICLEADMIN."</font><br><br>"
	."[ <a href=\"".$admin_file.".php?op=AddStory\">"._HOME."</a>"
	." | <a href=\"".$admin_file.".php?op=AddTopics\">"._TOPICS."</a>"
	." | <a href=\"".$admin_file.".php?op=AddCategory\">"._CATEGORIES."</a> ]</center>";
	CloseTable();
}

function AddStory() {
    global $prefix, $db, $admin_file, $multilingual, $stop, $conffi;
    head();
	NewsNavi();
	if ($stop) warning($stop, "", "", 1);
	if (isset($_REQUEST['id'])) {
		$sid = intval($_REQUEST['id']);
		$result = $db->sql_query("SELECT catid, aid, title, time, hometext, bodytext, field, topic, ihome, alanguage, acomm, associated, status FROM ".$prefix."_stories WHERE sid='$sid'");
        list($cat, $postname, $subject, $time, $hometext, $bodytext, $field, $topic, $ihome, $alanguage, $acomm, $associated, $status) = $db->sql_fetchrow($result);
		$associated = explode("-", $associated);
	} else {
		$sid = $_POST['sid'];
		$postname = $_POST['postname'];
		$subject = $_POST['subject'];
		$topic = $_POST['topic'];
		$associated = $_POST['associated'];
		$cat = $_POST['cat'];
		$alanguage = $_POST['alanguage'];
		$hometext = save_text($_POST['hometext']);
		$bodytext = save_text($_POST['bodytext']);
		$field = fields_save($_POST['field']);
		$ihome = $_POST['ihome'];
		$acomm = $_POST['acomm'];
		$status = $_POST['status'];
		if (isset($_POST['year'])) {
			$time = "".$_POST['year']."-".$_POST['mon']."-".$_POST['day']." ".$_POST['hour'].":".$_POST['min'].":00";
		} else {
			$today = getdate();
			$time = "".$today[year]."-".$today[mon]."-".$today[mday]." ".$today[hours].":".$today[minutes].":00";
		}
	}
	$fields = ($conffi['news']) ? fields_out($field, $conffi['news']) : "";
	$fields = ($fields) ? "<br /><br />".$fields."" : "";
	if ($hometext) preview("<b>".$subject."</b><br /><br />".bb_decode($hometext)."<br /><br />".bb_decode($bodytext)."".$fields."");
	OpenTable();
	echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\"><form name=\"post\" action=\"".$admin_file.".php\" method=\"post\">"
	."<tr><td>"._AUTHOR.":</td><td><input type=\"text\" name=\"postname\" value=\"".$postname."\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._TITLE.":</td><td><input type=\"text\" name=\"subject\" value=\"".$subject."\" maxlength=\"80\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._TOPIC.":</td><td><select name=\"topic\" style=\"width:400px\">";
    $result = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics ORDER BY topictext");
    echo "<option value=\"\">"._SELECTTOPIC."</option>\n";
    while (list($topicid, $topictext) = $db->sql_fetchrow($result)) {
		$sel = ($topicid == $topic) ? "selected" : "";
		echo "<option value=\"$topicid\" $sel>$topictext</option>\n";
    }
    echo "</select></td></tr>"
	."<tr><td>"._ASSOTOPIC.":</td><td><table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" style=\"width:400px\"><tr>";
	$result2 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics ORDER BY topictext");
	while (list($topicid, $topictext) = $db->sql_fetchrow($result2)) {
		if ($a == 2) {
			echo "</tr><tr>";
			$a = 0;
		}
		$check = "";
		if ($associated) foreach ($associated as $key => $val) if ($val == $topicid) $check = "checked";
		echo "<td><input type=\"checkbox\" name=\"associated[]\" value=\"$topicid\" $check>$topictext</td>";
		$a++;
    }
    echo "</tr></table></td></tr>";
	$result = $db->sql_query("SELECT catid, title FROM ".$prefix."_stories_cat ORDER BY title");
	if ($db->sql_numrows($result) > 0) {
		echo "<tr><td>"._CATEGORY.":</td><td><select name=\"cat\" style=\"width:400px\">"
		."<option value=\"\">"._SELECTCAT."</option>";
		while (list($catid, $title) = $db->sql_fetchrow($result)) {
			$sel = ($catid == $cat) ? "selected" : "";
			echo "<option value=\"$catid\" $sel>$title</option>";
		}
		echo "</select></td></tr>";
	}
	if ($multilingual == 1) echo "<tr><td>"._LANGUAGE.":</td><td><select name=\"alanguage\" style=\"width:400px\">".language($alanguage)."</select></td></tr>";
	echo "<tr><td>"._TEXT.":</td><td><textarea id=\"area\" name=\"hometext\" cols=\"65\" rows=\"5\" style=\"width:400px\" OnKeyPress=\"TransliteFeld(this, event)\" OnSelect=\"FieldName(this, this.name)\" OnClick=\"FieldName(this, this.name)\" OnKeyUp=\"FieldName(this, this.name)\">".replace_break($hometext)."</textarea>".get_code("area")."</td></tr>"
	."<tr><td>"._ENDTEXT.":</td><td><textarea id=\"area1\" name=\"bodytext\" cols=\"65\" rows=\"15\" style=\"width:400px\" OnKeyPress=\"TransliteFeld(this, event)\" OnSelect=\"FieldName(this, this.name)\" OnClick=\"FieldName(this, this.name)\" OnKeyUp=\"FieldName(this, this.name)\">".replace_break($bodytext)."</textarea>".get_code("area1")."</td></tr>";
	if ($conffi['news']) echo "".fields_in($field, $conffi['news'])."";
	preg_match("/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/", $time, $datetime);
	echo "<tr class=\"bgcolor1\"><td>"._CHNGSTORY.":</td><td>"
	.""._HOURS.": <select name=\"hour\">";
	$hour = 0;
	while ($hour <= 23) {
		$sel = ($hour == $datetime[4]) ? "selected" : "";
		$hour = ($hour < 10) ? "0".$hour."" : $hour;
		echo "<option value=\"$hour\" $sel>$hour</option>";
		$hour++;
	}
	echo "</select>:<select name=\"min\">";
	$min = 0;
	while ($min <= 60) {
		$sel = ($min == $datetime[5]) ? "selected" : "";
		$min = ($min < 10) ? "0".$min."" : $min;
		echo "<option value=\"$min\" $sel>$min</option>";
		$min++;
	}
	echo "</select> "._DAY.": <select name=\"day\">";
	$day = 1;
	while ($day <= 31) {
		$sel = ($day == $datetime[3]) ? "selected" : "";
		echo "<option value=\"$day\" $sel>$day</option>";
		$day++;
	}
	echo "</select> "._UMONTH.": <select name=\"mon\">";
	$mon = 1;
	while ($mon <= 12) {
		$sel = ($mon == $datetime[2]) ? "selected" : "";
		echo "<option value=\"$mon\" $sel>$mon</option>";
		$mon++;
	}
	echo "</select> "._YEAR.": <select name=\"year\">";
	$date = getdate();
	$year = $date[year] + 10;
	$years = $date[year] - 10;
	while ($years <= $year) {
		$sel = ($year == $datetime[1]) ? "selected" : "";
		echo "<option value=\"$year\" $sel>$year</option>";
		$year--;
	}
	echo "</select></td></tr>";
	$sel1 = (!$ihome) ? "checked" : "";
	$sel2 = ($ihome) ? "checked" : "";
	echo "<tr><td>"._PUBHOME."</td><td>"
	."<input type=\"radio\" name=\"ihome\" value=\"0\" $sel1>"._YES." &nbsp;&nbsp; <input type=\"radio\" name=\"ihome\" value=\"1\" $sel2>"._NO."</td></tr>";
	$sel1 = (!$acomm) ? "checked" : "";
	$sel2 = ($acomm) ? "checked" : "";
	echo "<tr><td>"._ACTCOM."</td><td>"
    ."<input type=\"radio\" name=\"acomm\" value=\"0\" $sel1>"._YES." &nbsp;&nbsp; <input type=\"radio\" name=\"acomm\" value=\"1\" $sel2>"._NO."</td></tr>";
	$sel1 = ($status) ? "checked" : "";
	$sel2 = (!$status) ? "checked" : "";
	echo "<tr><td>"._ACTSTORY."</td><td>"
    ."<input type=\"radio\" name=\"status\" value=\"1\" $sel1>"._YES." &nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"0\" $sel2>"._NO."</td></tr>"
	."<tr><td colspan=\"2\" align=\"center\"><br /><select name=\"posttype\">"
	."<option value=\"preview\">"._PREVIEW."</option>"
	."<option value=\"save\">"._SEND."</option></select>"
	." <input type=\"hidden\" name=\"sid\" value=\"$sid\">"
	." <input type=\"hidden\" name=\"op\" value=\"SaveStory\">"
	."<input type=\"submit\" value=\""._OK."\"></td></tr></form></table>";
	CloseTable();
    foot();
}

function SaveStory() {
	global $prefix, $db, $multilingual, $admin_file, $stop;
	$sid = intval($_POST['sid']);
	$postname = $_POST['postname'];
	$subject = $_POST['subject'];
	$topic = $_POST['topic'];
	$associated_mas = $_POST['associated'];
	if (isset($associated_mas)) {
		$associated = "";
		while (list($key,$val) = each($associated_mas)) $associated .= "{$val}-";
	}
	$cat = $_POST['cat'];
	$alanguage = ($multilingual == 1) ? $_POST['alanguage'] : "";
	$hometext = save_text($_POST['hometext']);
	$bodytext = save_text($_POST['bodytext']);
	$field = fields_save($_POST['field']);
	$ihome = $_POST['ihome'];
	$acomm = $_POST['acomm'];
	$status = $_POST['status'];
	if (isset($_POST['year'])) {
		$time = "".$_POST['year']."-".$_POST['mon']."-".$_POST['day']." ".$_POST['hour'].":".$_POST['min'].":00";
	} else {
		$today = getdate();
		$time = "".$today[year]."-".$today[mon]."-".$today[mday]." ".$today[hours].":".$today[minutes].":00";
	}
	if (!$hometext) $stop = ""._CERROR1."";
	if (!$postname) $stop = ""._CERROR3."";
	if (!$stop && $_POST['posttype'] == "save") {
		if ($sid) {
			$db->sql_query("UPDATE ".$prefix."_stories SET catid='$cat', aid='$postname', title='$subject', time='$time', hometext='$hometext', bodytext='$bodytext', field='$field', topic='$topic', ihome='$ihome', alanguage='$alanguage', acomm='$acomm', associated='$associated', status='$status' WHERE sid='$sid'");
		} else {
			$db->sql_query("INSERT INTO ".$prefix."_stories VALUES (NULL, '$cat', '$postname', '$subject', '$time', '$hometext', '$bodytext', '$field', '0', '0', '$topic', '$ihome', '$alanguage', '$acomm', '0', '0', '$associated', '$status')");
		}
		Header("Location: ".$admin_file.".php");
	} else {
		AddStory();
	}
}

function DeleteStory() {
    global $prefix, $db, $admin_file;
	$sid = intval($_REQUEST['id']);
	$ok = intval($_GET['ok']);

###########################

$del = (isset($_POST['id'])) ? implode(",", $_POST['id']) : "";
$del = explode(",",$del);
foreach ($del as $val) {
$db->sql_query("DELETE FROM ".$prefix."_stories WHERE sid='".$val."'");
$db->sql_query("DELETE FROM ".$prefix."_comment WHERE cid='".$val."' AND modul='News'");

Header("Location: ".$admin_file.".php");
}




    if ($sid && $ok == 1) {
		$db->sql_query("DELETE FROM ".$prefix."_stories WHERE sid='$sid'");
		$db->sql_query("DELETE FROM ".$prefix."_comment WHERE cid='$sid' AND modul='News'");
		Header("Location: ".$admin_file.".php");
	} else {
		list($title) = $db->sql_fetchrow($db->sql_query("SELECT title FROM ".$prefix."_stories WHERE sid='$sid'"));
		head();
        NewsNavi();
		OpenTable();
		echo "<center>"._DELETE." \"$title\"?<br /><br />[ <a href=\"".$admin_file.".php?op=DeleteStory&id=$sid&ok=1\">"._YES."</a> | <a href=\"".$admin_file.".php\">"._NO."</a> ]</center>";
		CloseTable();
		foot();
	}
}

function AddTopics() {
    global $prefix, $db, $admin_file;
    head();
	NewsNavi();
    OpenTable();
    echo "<center><font class=\"option\"><b>"._CURRENTTOPICS."</b></font></center><br>"
	."<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">";
    $count = 0;
    $result = $db->sql_query("SELECT topicid, topicname, topicimage, topictext FROM ".$prefix."_topics ORDER BY topicname");
    while (list($topicid, $topicname, $topicimage, $topictext) = $db->sql_fetchrow($result)) {
		$topicid = intval($topicid);
		echo "<td align=\"center\"><a href=\"".$admin_file.".php?op=EditTopics&topicid=$topicid\"><img src=\"images/topics/$topicimage\" border=\"0\" alt=\""._CLICK2EDIT."\"></a><br><b>$topicname</td>";
		$count++;
		if ($count == 5) {
			echo "</tr><tr>";
			$count = 0;
		}
    }
    echo "</table>";
    CloseTable();
    OpenTable();
    echo "<center><font class=\"option\"><b>"._ADDATOPIC."</b></font></center><br>"
	."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
	."<form action=\"".$admin_file.".php\" method=\"post\">"
	."<tr><td>"._TOPICNAME.":</td><td><input type=\"text\" name=\"topicname\" maxlength=\"20\" value=\"$topicname\" size=\"45\" style=\"width:300px\"></td></tr>"
	."<tr><td>"._TOPICTEXT.":</td><td><input type=\"text\" name=\"topictext\" maxlength=\"40\" value=\"$topictext\" size=\"45\" style=\"width:300px\"></td></tr>"
	."<tr><td>"._TOPICIMAGE.":</td><td><select name=\"topicimage\" style=\"width:300px\">";
	$dir = opendir("images/topics");
	while ($entry = readdir($dir)) {
		if (preg_match("/(\.gif|\.png|\.jpg|\.jpeg)$/is", $entry) && $entry != "." && $entry != ".." && $entry != "AllTopics.gif") {
			$entryname = str_replace("_", " ", preg_replace("/^(.*)\..*$/", "\\1", $entry));
			echo "<option value=\"$entry\">$entryname</option>";
		}
	}
	closedir($dir);
	echo "</select></td></tr></table><br>"
	."<center><input type=\"hidden\" name=\"op\" value=\"MakeTopics\">"
	."<input type=\"submit\" value=\""._ADD."\"></center></form>";
    CloseTable();
    foot();
}

function EditTopics($topicid) {
    global $prefix, $db, $admin_file;
    head();
	NewsNavi();
    OpenTable();
    $topicid = intval($topicid);
    list($topicid, $topicname, $topicimage, $topictext) = $db->sql_fetchrow($db->sql_query("SELECT topicid, topicname, topicimage, topictext FROM ".$prefix."_topics WHERE topicid='$topicid'"));
	$topicid = intval($topicid);
    echo "<center><font class=\"option\"><b>"._EDIT.": $topictext</b></font></center><br>"
	."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
	."<form action=\"".$admin_file.".php\" method=\"post\">"
	."<tr><td>"._TOPICNAME.":</td><td><input type=\"text\" name=\"topicname\" maxlength=\"20\" value=\"$topicname\" size=\"45\" style=\"width:300px\"></td></tr>"
	."<tr><td>"._TOPICTEXT.":</td><td><input type=\"text\" name=\"topictext\" maxlength=\"40\" value=\"$topictext\" size=\"45\" style=\"width:300px\"></td></tr>"
	."<tr><td>"._TOPICIMAGE.":</td><td><select name=\"topicimage\" style=\"width:300px\">";
	$dir = opendir("images/topics");
	while ($entry = readdir($dir)) {
		if (preg_match("/(\.gif|\.png|\.jpg|\.jpeg)$/is", $entry) && $entry != "." && $entry != ".." && $entry != "AllTopics.gif") {
			$entryname = str_replace("_", " ", preg_replace("/^(.*)\..*$/", "\\1", $entry));
			$sel = ($topicimage == $entry) ? "selected" : "";
			echo "<option value=\"$entry\" $sel>$entryname</option>";
		}
	}
	closedir($dir);
	echo "</select></td></tr>"
	."<tr><td align=\"center\" colspan=\"2\"><table><tr><td><input type=\"hidden\" name=\"topicid\" value=\"$topicid\">"
	."<input type=\"hidden\" name=\"op\" value=\"ChangeTopics\"><input type=\"submit\" value=\""._SAVECHANGES."\"></td></form></form><form action=\"".$admin_file.".php\" method=\"post\"><td><input type=\"hidden\" name=\"topicid\" value=\"$topicid\"><input type=\"hidden\" name=\"title\" value=\"$topicname\"><input type=\"hidden\" name=\"op\" value=\"DeleteTopics\"><input type=\"submit\" value=\""._DELETE."\"></td></tr></form></table></tr></td></table>";
    CloseTable();
    foot();
}

function DeleteTopics() {
    global $prefix, $db, $admin_file;
	$topicid = intval($_REQUEST['topicid']);
	$ok = intval($_GET['ok']);
    if ($topicid && $ok == 1) {
		$db->sql_query("DELETE FROM ".$prefix."_topics WHERE topicid='$topicid'");
		$result = $db->sql_query("SELECT sid FROM ".$prefix."_stories WHERE topic='$topicid'");
		while(list($sid) = $db->sql_fetchrow($result)) {
			$sid = intval($sid);
			$db->sql_query("DELETE FROM ".$prefix."_stories WHERE topic='$topicid'");
			$db->sql_query("DELETE FROM ".$prefix."_comment WHERE cid='$sid' AND modul='News'");
		}
		Header("Location: ".$admin_file.".php?op=AddTopics");
	} else {
		head();
        NewsNavi();
        OpenTable();
		echo "<center><font class=\"option\">"._DELTOPIC.": ".$_POST['title']."</font><br /><br />"
		.""._DELTOPNOTE."<br /><br />[ <a href=\"".$admin_file.".php?op=DeleteTopics&topicid=$topicid&ok=1\">"._YES."</a> | <a href=\"".$admin_file.".php?op=AddTopics\">"._NO."</a> ]</center>";
		CloseTable();
		foot();
	}
}

function AddCategory() {
	global $db, $prefix, $admin_file;
    head();
    NewsNavi();
	OpenTable();
	echo "<center><font class=\"option\">"._CATEGORIES."</font></center><br />";
	echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"100%\" class=\"bgcolor4\"><tr><th>"._ID."</th><th width=\"80%\">"._CATEGORY."</th><th>"._FUNCTIONS."</th></tr>";
	$result = $db->sql_query("SELECT catid, title FROM ".$prefix."_stories_cat");
	while(list($catid, $title) = $db->sql_fetchrow($result)) {
		echo "<tr class=\"bgcolor1\"><td align=\"center\">$catid</td><td>$title</td><td align=\"center\" class=\"bgcolor1\"><a href=\"".$admin_file.".php?op=EditCategory&catid=$catid\" title=\""._EDIT."\"><img src=images/edit.gif border=\"0\" alt=\""._EDIT."\"></a> <a href=\"".$admin_file.".php?op=DelCategory&catid=$catid&title=$title\" title=\""._DELETE."\"><img src=images/delete.gif border=\"0\" alt=\""._DELETE."\"></a></td></td></tr>";
	}
	echo "</table>";
	CloseTable();
	OpenTable();
    echo "<center><font class=\"option\">"._ADDCATEGORY."</font><br />"
	."<form action=\"".$admin_file.".php\" method=\"post\">"
	."<input type=\"text\" name=\"title\" maxlength=\"20\" size=\"65\" style=\"width:400px\">"
	." <input type=\"hidden\" name=\"op\" value=\"SaveCategory\">"
	."<input type=\"submit\" value=\""._SAVE."\"></form></center>";
    CloseTable();
    foot();
}

function EditCategory($catid) {
    global $prefix, $db, $admin_file;
    head();
    NewsNavi();
	OpenTable();
    echo "<center><font class=\"option\">"._EDITCATEGORY."</font><br />";
	$catid = intval($catid);
    $result = $db->sql_query("SELECT title FROM ".$prefix."_stories_cat WHERE catid='$catid'");
    list($title) = $db->sql_fetchrow($result);
	echo "<form action=\"".$admin_file.".php\" method=\"post\">"
	."<input type=\"text\" name=\"title\" maxlength=\"20\" value=\"$title\" size=\"65\" style=\"width:400px\">"
	." <input type=\"hidden\" name=\"catid\" value=\"$catid\">"
	."<input type=\"hidden\" name=\"op\" value=\"SaveCategory\">"
	."<input type=\"submit\" value=\""._SAVECHANGES."\"></form></center>";
    CloseTable();
    foot();
}

function DelCategory() {
    global $prefix, $db, $admin_file;
	$catid = intval($_REQUEST['catid']);
	$ok = intval($_GET['ok']);
    if ($catid && $ok == 1) {
		$db->sql_query("DELETE FROM ".$prefix."_stories_cat WHERE catid='$catid'");
		$result = $db->sql_query("SELECT sid FROM ".$prefix."_stories WHERE catid='$catid'");
		while(list($sid) = $db->sql_fetchrow($result)) {
			$sid = intval($sid);
			$db->sql_query("DELETE FROM ".$prefix."_stories WHERE catid='$catid'");
			$db->sql_query("DELETE FROM ".$prefix."_comment WHERE cid='$sid' AND modul='News'");
		}
		Header("Location: ".$admin_file.".php?op=AddCategory");
	} else {
        head();
        NewsNavi();
        OpenTable();
		echo "<center><font class=\"option\">"._DELCATEGORY.": ".$_GET['title']."</font><br /><br />"
		.""._DELCATNOTE."<br /><br />[ <a href=\"".$admin_file.".php?op=DelCategory&catid=$catid&ok=1\">"._YES."</a> | <a href=\"".$admin_file.".php?op=AddCategory\">"._NO."</a> ]</center>";
		CloseTable();
		foot();
    }
}

switch($op) {
	case "AddStory":
    AddStory($sid);
    break;
	
	case "SaveStory":
	SaveStory();
	break;
	
	case "ActiveStory":
	$id = intval($_GET['id']);
	$act = intval($_GET['act']);
	$pagenum = (!intval($_GET['pagenum'])) ? "" : "?pagenum=".intval($_GET['pagenum'])."";
	$db->sql_query("UPDATE ".$prefix."_stories SET status='$act' WHERE sid='$id'");
    Header("Location: ".$admin_file.".php".$pagenum."");
	break;

	case "DeleteStory":
	DeleteStory();
	break;
	
	case "AddTopics":
    AddTopics();
    break;

    case "EditTopics":
    EditTopics($topicid);
    break;

    case "MakeTopics":
	$db->sql_query("INSERT INTO ".$prefix."_topics VALUES (NULL, '$topicname', '$topicimage', '$topictext')");
    Header("Location: ".$admin_file.".php?op=AddTopics");
    break;

    case "DeleteTopics":
    DeleteTopics();
    break;

    case "ChangeTopics":
	$topicid = intval($topicid);
    $db->sql_query("UPDATE ".$prefix."_topics SET topicname='$topicname', topicimage='$topicimage', topictext='$topictext' WHERE topicid='$topicid'");
    Header("Location: ".$admin_file.".php?op=AddTopics");
    break;
	
	case "AddCategory":
    AddCategory();
    break;

	case "EditCategory":
    EditCategory($catid);
    break;
	
	case "DelCategory":
    DelCategory();
    break;
	
	case "SaveCategory":
	$title = $_POST['title'];
	$catid = intval($_POST['catid']);
	if ($catid) {
		$db->sql_query("UPDATE ".$prefix."_stories_cat SET title='$title' WHERE catid='$catid'");
	} else {
		$db->sql_query("INSERT INTO ".$prefix."_stories_cat VALUES (NULL, '$title')");
	}
	Header("Location: ".$admin_file.".php?op=AddCategory");
    break;
}
?>