Location: PHPKode > projects > PSlash > pslash-0.70/html/admin/category.php
<?
###############################################################################
# Copyright (C) 2000  Derek Leung
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# You may modify your copy or copies of this Program or any portion of it,
# but you must cause the modified files to carry prominent notices stating 
# that you changed the files and the date of any change.  And you are required 
# to keep a copy of this License along with this Program.
#
# You are not required to accept this License, since you have not signed it. 
# However, nothing else grants you permission to modify or distribute this 
# Program or its derivative works. These actions are prohibited by law if 
# you do not accept this License. Therefore, by modifying or distributing 
# this Program (or any work based on this Program), you indicate your 
# acceptance of this License to do so, and all its terms and conditions 
# for copying, distributing or modifying this Program or works based on it.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# See the GNU General Public License for more details.
# http://www.opensource.org/licenses/gpl-license.html
###############################################################################

global $config;

// kick out anyone try to access this file directly
if (eregi("admin/", $PHP_SELF)) {
    die ("Access Deny!");
}

#######################
# Category Function
#######################

function manageCategory($action,$cName,$topic,$cid,$listOrder,$mesg) {

// function to add,edit, and remove and category.   
	global $config;

	// check to see if we have right to do this
	$rightArray = getAdminRights();
	if (!in_array("8",$rightArray)) {
		errorPage("Access Deny!",$config[def_theme]);
	}

	switch($action) {
		
		case "createCategory":
			ps_header("");
			?>
			<h3><?echo translate("Create Category");?></h3>
			<small><? echo translate("Create a category for articles");?></small>
			<form action="admin.php" method="post">
				<table>
					<tr>
						<td><b><?echo translate("Category Name");?></b></td><td><input type="text" name="cName"></td>
					</tr>
					<tr>
						<td><b><?echo translate("Topic");?></b></td><td><select name="topic">
							<? $topics = getTopicRights2(); // only topics have their own section can create category
								foreach ($topics as $topic) {
									echo "<option value=\"$topic\">$topic";
								}
							?>
						</td>
					</tr>
					<input type="hidden" name="action" value="createAction">
					<input type="hidden" name="op" value="mod_category">
					<tr>
						<td><input type="submit"></td>
					</tr>
				</table>
			</form>

			<?
			ps_footer("");
			unset($action,$cName,$topic,$cid,$listOrder,$mesg,$rightArray,$topics);
			break;
		
		case "createAction":
			$topics = getTopicRights2(); // only topics have their own section can create category
			if (!in_array($topic,$topics)) {
				errorPage("Access Deny!",$config[def_theme]);
			}

			$cName = check_html(check_words(FixQuotes($cName)));
			mysql_query("insert into ps_category values (NULL,'$cName','$topic',100)");
			$mesg = translate("Category+is+created!");
			header("Location: admin.php?mesg=$mesg&op=mod_category&action=listCategory"); 
			unset($action,$cName,$topic,$cid,$listOrder,$mesg,$rightArray,$topics,$cName);
			break;
		
		case "listCategory":
			global $header;
			$header[js] = "true";
			ps_header($header);
			echo "<h3>" . translate("Edit Category") ;
			if ($mesg) {
				echo " <font color=red><small>(".translate("$mesg").")</small></font>";
			}
			echo "</h3>";
			echo "<table border=1>";
			echo "<tr>";
			echo "<td><b>" . translate("Topic") . "</b></td><td><b>" . translate("Category Name") . "</b></td><td><b>" . translate("List Order") . "</b></td>";
			echo "<td><b>" . translate("Edit") . "</b></td><td><b>" . translate("Delete") . "</b></td>";
			echo "</tr>";
			$result = mysql_query("select * from ps_category order by topic,listOrder");
			$topics =getTopicRights2(); // only topics have their own section can have category
			while (list($cid,$cName,$topic,$listOrder) = mysql_fetch_row($result)) {
				if (in_array($topic,$topics)) {
					echo "<tr>";
					echo "<td>$topic</td><td>$cName</td><td>$listOrder</td>";
					echo "<td><a href=\"admin.php?op=mod_category&action=editCategory&cid=$cid\">".translate("Edit")."</a></td>";
					echo "<td><a href=\"admin.php?op=mod_category&action=delCategory&cid=$cid\" onclick=\"return confirmDelete()\">".translate("Delete")."</a></td>";
					echo "</tr>";
				}
		
			}
			echo "</table><br><br><br>";
			ps_footer("");
			unset($action,$cName,$topic,$cid,$listOrder,$mesg,$rightArray,$topics,$header,$result);
			break;
		
		case "editCategory":

			$result = mysql_query("select cName,topic,listOrder from ps_category where cid=$cid");
			list($cName,$cTopic,$listOrder) = mysql_fetch_row($result);
			
			$topics = getTopicRights2(); // only topics have their own section can edit category
			if (!in_array($cTopic,$topics)) {
				errorPage("Access Deny!",$config[def_theme]);
			}

			ps_header("");
			?>
			<h3><?=translate("Edit Category");?></h3>
			<form name="admin.php" method="post">
				<table>
					<tr>
						<td><b><?=translate("Category Name");?></b></td>
						<td><input type="text" maxlength="20" name="cName" value="<?=htmlspecialchars($cName)?>"></td>
					</tr>
					<tr>
						<td><b><?=translate("List Order");?></b></td>
						<td><input type="text" maxlength="20" name="listOrder" value="<?=$listOrder?>"> <font size=-1>(<?=translate("1 is highest and will be put this category at the top")?>)</font></td>
					</tr>
					<tr>
						<td><b><?=translate("Topic");?></b></td>
						<td>
							<select name="topic">
							<? 
								foreach ($topics as $topic) {
									if ($cTopic == $topic) {
										echo "<option selected>$topic";
									} else {
										echo "<option>$topic";
									}
								}
							?>
							</select>
						</td>
					</tr>
					<tr>
						<td><input type="submit" value="submit"></td>
					</tr>
				</table>
				<input type="hidden" name="op" value="mod_category">
				<input type="hidden" name="action" value="editAction">
				<input type="hidden" name="cid" value="<?=$cid?>">
			</form>
			<?
			ps_footer("");
			unset($action,$cName,$topic,$cid,$listOrder,$mesg,$rightArray,$topics,$result,$cTopic);
			break;

		case "editAction":
			$topics = getTopicRights2();
			if (!in_array($topic,$topics)) {
				errorPage("Access Deny!",$config[def_theme]);
			}
			
			$cName = check_html(check_words(FixQuotes($cName)));
			mysql_query("update ps_category set topic='$topic', cName='$cName', listOrder='$listOrder' where cid=$cid");
			$mesg = translate("Category is updated!");
			header("Location: admin.php?mesg=$mesg&op=mod_category&action=listCategory");
			unset($action,$cName,$topic,$cid,$listOrder,$mesg,$rightArray,$topics);
			break;

		case "delCategory":
			$result = mysql_query("select topic from ps_category where cid=$cid");
			list($cTopic) = mysql_fetch_row($result);
			mysql_free_result($result);
			$topics = getTopicRights2(); // only topics have their own section can delete category
			if (!in_array($cTopic,$topics)) {
				errorPage("Access Deny!",$config[def_theme]);
			}
			mysql_query("delete from ps_category where cid=$cid");
			$mesg = translate("Category is deleted!");
			header("Location: admin.php?mesg=$mesg&op=mod_category&action=listCategory"); 
			unset($action,$cName,$topic,$cid,$listOrder,$mesg,$rightArray,$topics,$result,$cTopic);
			break;

		default:
			ps_header("");
			?>
			<h3><?echo translate("Manage Category")?></h3> 
			<li><a href="admin.php?op=mod_category&action=createCategory"><?=translate("Create Category")?></a>
			<li><a href="admin.php?op=mod_category&action=listCategory"><?=translate("Edit/Delete Category")?></a>
			<br><br><br>
			<?


	}


}

?>
Return current item: PSlash