Location: PHPKode > projects > PSlash > pslash-0.70/html/admin/block.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!");
}

/*********************************************************/
/* block functions                                       */
/*********************************************************/

function blocks($topic,$mesg) {

// The main menu for creating blocks
	global $config;

	$topics = getTopicRights2(); // only get the topics that have their own section.

	// No topic input?  we display the menu and exit.
	if ($topic == "") {
		ps_header("");
		echo "<h3>".translate("Choose a Topic");
		if ($mesg) {
			echo " <font color=red><small>(".translate("$mesg").")</small></font>";
		}
		echo "</h3>";
		if (sizeof($topics) > 0) {
			foreach ($topics as $topic) {
				echo "<a href=\"admin.php?op=blocks&topic=$topic\">".sprintf(translate("Manage Topic %s"),$topic)."</a><br>";
			}
		}
		ps_footer("");
		exit;
	}

	// Ok, we got $topic, lets check if the user have right to modify it
	$userArray = getCookie($config[user_cookie_name]);
	$rightArray = getAdminRights();
	if (!in_array("3",$rightArray)) {
		errorPage("Access Deny!",$config[def_theme]);
	}

	// so far so good, lets show the edit box.
	ps_header("");
	$result = mysql_query("select id, title, content, type, listOrder,url,refresh from ps_blocks where topic='$topic'");
	if (mysql_num_rows($result) > 0) {
		while(list($id, $title, $content, $type,$listOrder,$url,$refresh) = mysql_fetch_array($result)) {
			
			?>
			<b><?php echo translate("Modify Block") . " $topic"; ?></b>
			<form action="admin.php" method="post">
				<?php echo translate("Block Title:"); ?>
				<input type="text" name="title" size="30" maxlength="60" value="<?php echo htmlspecialchars($title); ?>"><br><br>
				<?php echo translate("List Order"); ?>:
				<input type="text" name="listOrder" size="3" maxlength="3" value="<?php echo $listOrder; ?>"><br><br>
				<?php echo translate("URL"); ?>:
				<input type="text" name="url" size="20" maxlength="50" value="<?php echo $url; ?>"><font size=-1><br><i><?=translate("(Please leave the Content text box blank and choose dynamic box if you specify a URL or a physical path here.)");?></i></font><br><br>
				<?php echo translate("Refresh time"); ?>:
				<input type="text" name="refresh" size="3" maxlength="3" value="<?php echo $refresh; ?>"><font size=-1><br><i><?=translate("(How often you want to grap the News headline?  Leaving it empty or put a 0 in means no caching.)");?></i></font><br><br>
				<?php echo translate("Content:"); ?>
				<br><textarea wrap="virtual" cols="40" rows="6" name="content"><?php echo htmlspecialchars($content); ?></textarea><br>
				<input type="hidden" name="id" value="<?php echo $id; ?>">

				<select name="type">
					<option VALUE="S" <?php if ($type == "S") echo "SELECTED"; ?>><?php echo translate("Static"); ?></option>
					<option VALUE="D" <?php if ($type == "D") echo "SELECTED"; ?>><?php echo translate("Dynamic"); ?></option>
				</select>

				<select name="op">
					<option VALUE="changeblock" SELECTED><?php echo translate("changeblock"); ?></option>
					<option VALUE="deleteblock"><?php echo translate("deleteblock"); ?></option>
				</select>

				<? $topic = htmlspecialchars($topic); ?>
				<input type="hidden" name="topic" value="<?=$topic?>">
				<input type="submit" VALUE="<?php echo translate("Go!"); ?>">
			</form>
			<hr>
			<?
		}
	} 
	?>
	<b><?php echo translate("Add New Block"); ?></b>
	<form action="admin.php" method="post">
		<?php echo translate("Block Title:"); ?><input type="text" name="title" size=30 maxlength=60><br><br>
		<?php echo translate("List Order"); ?>:<input type="text" name="listOrder" size=3 maxlength=3><br><br>
		<?php echo translate("URL"); ?>:<input type="text" name="url" size=20 maxlength=50><font size=-1><br><i><?=translate("(Please leave the Content text box blank and choose dynamic box if you specify a URL or a physical path here.)");?></i></font><br><br>
		<?php echo translate("Refresh time"); ?>:<input type="text" name="refresh" size=3 maxlength=3><font size=-1><i><br><?=translate("(How often you want to grap the News headline?  Leaving it empty or put a 0 in means no caching.)");?></i></font><br><br>
		<?php echo translate("Content:"); ?><br>
		<textarea wrap=virtual cols=40 rows=6 name=content></textarea><br>

		<select name="type">
			<option VALUE="S" SELECTED><?php echo translate("Static"); ?></option>
			<option VALUE="D"><?php echo translate("Dynamic"); ?></option>
		</select>

		<? $topic = htmlspecialchars($topic); ?>
		<input type="hidden" name="topic" value="<?=$topic?>">
		<input type="hidden" NAME="op" VALUE="makeblock">
		<input type="submit" VALUE="<?php echo translate("makeblock") ?>">
	</form>
	<?

	unset($topics,$topic,$userArray,$rightArray,$result,$id,$title,$content,$type,$url,$refresh);
	ps_footer("");
}


function makeblock($title, $content, $type,$topic, $listOrder,$url,$refresh) {

// function to create a new block for a specific topic
	global $config;
	
	// check if he has right to use this function
	$rightArray = getAdminRights();
	if (!in_array("3",$rightArray)) {
		errorPage("Access Deny!",$config[def_theme]);
	}

	// check if he has the right to modify this topic
	$topics = getTopicRights2();
	if (!in_array($topic,$topics)) {
		errorPage("Access Deny!",$config[def_theme]);
	}

	$title = FixQuotes($title);
	$content = FixQuotes($content);
	$topic = FixQuotes($topic);
	$url = FixQuotes($url);
	mysql_query("INSERT INTO ps_blocks VALUES (NULL,'$aid','$title','$content','$type','$topic',$listOrder,'$url',$refresh,now())");
	if (mysql_error()) {
		$mesg = "Error! ". mysql_error();
	} else {
		$mesg = translate("The+block+is+added!");
	}
	

	unset($rightArray,$topics,$title,$content,$type,$topic,$listOrder,$url,$refresh);
	Header("Location: admin.php?mesg=$mesg&op=blocks");
}


function changeblock($id, $title, $content, $type, $topic, $listOrder, $url, $refresh) {

// change an existing block info
	global $config;
	
	// check if he has right to use this function
	$rightArray = getAdminRights();
	if (!in_array("3",$rightArray)) {
		errorPage("Access Deny!",$config[def_theme]);
	}

	// check if he has right to edit this topic
	$topics = getTopicRights2();
	if (!in_array($topic,$topics)) {
		errorPage("Access Deny!",$config[def_theme]);
	}
	$title = FixQuotes($title);
	$content = FixQuotes($content);
	$url = FixQuotes($url);
	
	mysql_query("update ps_blocks set author='$aid',title='$title',content='$content',type='$type', listOrder=$listOrder, url='$url', refresh=$refresh, ts=NOW() where id=$id");
	if (mysql_error()) {
		$mesg = "Error! ". mysql_error();
	} else {
		$mesg = translate("The+block+is+updated!");
	}

	unset($id,$title,$content,$type,$topic);
	Header("Location: admin.php?mesg=$mesg&op=blocks");
	
}

function deleteblock($id,$topic) {

// function to delete an existing block
	global $config;

	// check if he has right to use this function
	$rightArray = getAdminRights();
	if (!in_array("3",$rightArray)) {
		errorPage("Access Deny!",$config[def_theme]);
	}

	// check if he has right to edit this topic
	$topics = getTopicRights2();
	if (!in_array($topic,$topics)) {
		errorPage("Access Deny!",$config[def_theme]);
	}
	mysql_query("delete from ps_blocks where id='$id'");
	if (mysql_error()) {
		$mesg = "Error! ". mysql_error();
	} else {
		$mesg = translate("The+block+is+deleted!");
	}
	

	unset($id,$topic,$rightArray,$topics);
	Header("Location: admin.php?mesg=$mesg&op=blocks");
	
}


# Don't add empty spaces at the end of this file....
# If you don't want to see cookies errors.
?>
Return current item: PSlash