<?
###############################################################################
# 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!");
}
#######################
# Topic Function
#######################
function displayTopics($mesg) {
// dispaly all the topics for editing
global $config;
// check if he has right to user this function
$rightArray = getAdminRights();
if (!in_array("5",$rightArray)) {
errorPage("Access Deny!",$config[def_theme]);
}
ps_header("");
echo "<h3>".translate("Edit Topics");
if ($mesg) {
echo " <font color=red><small>(".translate("$mesg").")</small></font>";
}
echo "</h3>";
# Display topic list
$result = mysql_query("select tid, topic, icon_url, alt from ps_topics order by tid");
$topics = '';
if($result > 0) {
echo "<table border=0>";
while(list($tid, $topic, $icon_url, $alt) = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td><li> $tid</td><td><a href=\"admin.php?op=modifyTopic&chng_tid=$tid\">$topic</a></td>\n";
echo "<td><a href=\"admin.php?op=modifyTopic&chng_tid=$tid\">";
echo "<img border=\"1\" src=\"$icon_url\" alt=\"$alt\">";
echo "</a></td>\n";
echo "</tr>";
}
echo "</table>";
}
echo "<form method=post action=\"admin.php\">";
echo "<b>".translate("Num").": </b> <input type=text name=\"chng_tid\" size=3>\n";
echo "<select name=\"op\">";
echo "<option value=\"modifyTopic\">".translate("Modify Topic")."</option>\n";
echo "<option value=\"delTopic\">".translate("Delete Topic")."</option></select>\n";
echo "<input type=\"submit\" value=\"".translate("Go!")."\"></form>";
?>
<h3>
<?
// display the input box for adding new topic
echo translate("New topic"); ?></h3>
<form action="admin.php?op=addTopic" method="post">
<table border=0>
<tr>
<td><?PHP echo translate("Name"); ?></td>
<td><input type="text" name="add_topic"></td>
</tr>
<tr>
<td><input type="submit" value="<?PHP echo translate("New topic") ?>"></form></td>
</tr>
</table>
</form>
<?
unset($mesg,$rightArray,$result,$topics,$col,$tid, $topic, $icon_url, $alt);
ps_footer("");
}
function modifyTopic($chng_tid) {
// display modify topic form
global $config;
// check if he has right to user this function
$rightArray = getAdminRights();
if (!in_array("5",$rightArray)) {
errorPage("Access Deny!",$config[def_theme]);
}
ps_header("");
$result = mysql_query("select tid, topic, icon_url, alt, required, moderate, displayTopic from ps_topics where tid='$chng_tid'");
if(mysql_num_rows($result) > 0) {
while(list($chng_tid, $chng_topic, $chng_icon_url, $chng_alt, $chng_required,$moderate,$displayTopic) = mysql_fetch_row($result)) {
$titlebar = "<h3>".translate("Update Topic").": $chng_topic</h3>";
echo $titlebar;
?>
<form action="admin.php" enctype="multipart/form-data" method="post">
<table border=0>
<tr>
<td><b><?PHP echo translate("Topic ID");?></b></td>
<td><?PHP echo $chng_tid ?></td>
</tr>
<tr>
<td><b><?PHP echo translate("Name");?>*</b></td>
<td><input type="text" name="chng_topic" value="<?PHP echo $chng_topic ?>"></td>
</tr>
<tr valign="top">
<td><b><?PHP echo translate("Icon");?></b></td>
<td valign="top"><img border="1" src="topic-icon.php?topic=<?=$chng_topic ?>"><br>
<td> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td><b><?PHP echo translate("Icon URL");?></b></td>
<td><input type="text" name="chng_icon_url" value="<?PHP echo $chng_icon_url ?>"></td>
</tr>
<tr>
<td><b><?PHP echo translate("Ballon topic name");?></b></td>
<td><input type="text" name="chng_alt" value="<?PHP echo $chng_alt ?>"></td>
</tr>
<tr>
<td colspan="2"><font size=-1><?PHP echo translate("(Appears if you move your mouse pointer over the icon, or if your browser doesn't support graphics)");?></font></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><b><?PHP echo translate("Topic can be disabled");?></b></td>
<td><input type="checkbox" name="chng_required" value="N" <?PHP if ($chng_required=='N') echo "checked" ?>></td>
</tr>
<tr>
<td><b><?PHP echo translate("Topic link display on main page");?></b></td>
<td><input type="checkbox" name="displayTopic" value="true" <?PHP if ($displayTopic=='true') echo "checked" ?>> <small><?=translate(sprintf("Make sure you make a subdirectory call \"%s\" in %s dir.",$chng_topic,$config[theme_path]));?><br> <?=translate(sprintf("see the README in %s for help",$config[theme_path]));?></small></td>
</tr>
<tr>
<td><b><?PHP echo translate("Moderate Level");?></b></td>
<td><input type="radio" name="moderate" value="1" <?PHP if ($moderate==1) echo "checked" ?>><?=translate("Everyone post directly")?></td>
</tr>
<tr>
<td> </td><td><input type="radio" name="moderate" value="2" <?PHP if ($moderate==2) echo "checked" ?>><?= translate("Admin/Moderator post directly, member put into queue");?></td>
</tr>
<tr>
<td> </td><Td><input type="radio" name="moderate" value="3" <?PHP if ($moderate==3) echo "checked" ?>><?= translate("Only Admin can post")?></td>
</tr>
<tr>
<td colspan="2"><small><?PHP echo translate("May the user disable articles posted with this topic");?> ?</small></td>
</tr>
<input type="hidden" name="chng_tid" value="<?php echo $chng_tid; ?>">
<input type="hidden" name="op" value="updateTopic">
<tr>
<td colspan=2><input type="submit" value="<?PHP echo translate("Update Topic");?>"></td>
</tr>
</table>
</form>
<font color=red><?PHP echo translate("* indicates REQUIRED fields"); ?></font><?
}
} else {
echo errorMsg("No info");
}
ps_footer("");
unset($chng_tid,$rightArray,$result, $chng_topic, $chng_icon_url, $chng_alt, $chng_required,$moderate,$displayTopic);
}
function updateTopic($chng_tid, $chng_topic, $chng_icon_type, $chng_icon_size, $chng_icon_name, $chng_icon_url, $chng_alt, $chng_required,$moderate,$displayTopic) {
// update the topic
global $config;
// check if he has right to user this function
$rightArray = getAdminRights();
if (!in_array("5",$rightArray)) {
errorPage("Access Deny!",$config[def_theme]);
}
if (!($chng_topic || $chng_icon)) {
$mesg = translate("Something+is+wrong!");
Header("Location: admin.php?mesg=$mesg");
}
$chng_topic = fixquotes($chng_topic);
$sql = "update ps_topics set topic='$chng_topic' ";
if ($chng_required == '') {
$chng_required="Y";
}
if ($displayTopic == "") {
$displayTopic = "false";
}
if ($chng_alt == '') {
$chng_alt=$chng_topic;
}
$sql .= ", required='$chng_required' ";
$sql .= ", icon_url='$chng_icon_url' ";
$sql .= ", alt='$chng_alt' ";
$sql .= ", moderate=$moderate ";
$sql .= ", displayTopic='$displayTopic' ";
$sql .= " where tid='$chng_tid'";
if(mysql_query($sql)) {
$mesg = translate("Operation+Successful!");
unset($chng_tid, $chng_topic, $chng_icon_type, $chng_icon_size, $chng_icon_name, $chng_icon_url, $chng_alt, $chng_required,$moderate,$displayTopic,$rightArray,$sql);
header("Location: admin.php?mesg=$mesg&op=mod_topics");
} else {
unset($chng_tid, $chng_topic, $chng_icon_type, $chng_icon_size, $chng_icon_name, $chng_icon_url, $chng_alt, $chng_required,$moderate,$displayTopic,$rightArray,$sql);
errorPage("DateBase Error!",$config[def_theme]);
}
}
function delTopic($chng_tid) {
// delete a topic
global $config;
// check if he has right to user this function
$rightArray = getAdminRights();
if (!in_array("5",$rightArray)) {
errorPage("Access Deny!",$config[def_theme]);
}
$query = "select topic from ps_topics where tid=$chng_tid";
list($topic) = mysql_fetch_row(mysql_query($query));
$topic = fixquotes($topic);
$sql = "delete from ps_topics where tid=$chng_tid";
$query = "select sid from ps_stories where topic='$topic'";
$result = mysql_query($query);
while (list($sid) = mysql_fetch_row($result)) {
mysql_query("delete from ps_comments where sid=$sid");
}
$sql2 = "delete from ps_stories where topic='$topic'";
$sql3 = "delete from ps_queue where topic='$topic'";
if(mysql_query($sql) && mysql_query($sql2) && mysql_query($sql3) ) {
$mesg = translate("Operation+Successful!");
unset($chng_tid,$rightArray,$query,$topic,$sql,$result,$sql2,$sql3);
header("Location: admin.php?mesg=$mesg&op=mod_topics");
} else {
echo mysql_errno(). ": ".mysql_error(). "<br>";
unset($chng_tid,$rightArray,$query,$topic,$sql,$result,$sql2,$sql3);
return;
}
}
function addTopic($add_topic) {
// add a topic
global $config;
// check if he has right to user this function
$rightArray = getAdminRights();
if (!in_array("5",$rightArray)) {
errorPage("Access Deny!",$config[def_theme]);
}
if (!($add_topic)) {
errorPage("Missing Field!",$config[def_theme]);
}
$add_topic = check_html(check_words(FixQuotes($add_topic)));
$sql = "insert into ps_topics ";
$sql .= "(topic) ";
$sql .= "values ('$add_topic')";
$result = mysql_query("select topic from ps_topics where topic='$add_topic'");
if (mysql_num_rows($result) >0) {
errorPage("You have another topic in the database with the same name!",$config[def_theme]);
}
$result = mysql_query($sql);
if (!$result) {
echo mysql_errno(). ": ".mysql_error(). "<br>"; return;
}
$result = mysql_query("SELECT tid FROM ps_topics WHERE topic='$add_topic' ORDER BY tid DESC");
if (!$result) {
echo mysql_errno(). ": ".mysql_error(). "<br>"; return;
}
list ($tid) = mysql_fetch_row($result);
unset($add_topic,$rightArray,$sql,$result);
Header("Location: admin.php?op=modifyTopic&chng_tid=$tid");
}
?>