<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

if(!ispageadmin($userID) OR substr(basename($_SERVER[REQUEST_URI]),0,15) != "admincenter.php") die('Access denied.');
if($_POST['save']) {

 $file = ("../html/".$_POST['name']);
 $fp = fopen ($file, "w");
 fwrite ($fp, stripslashes($_POST['content']));
 fclose($fp);
 safe_query("INSERT INTO `".PREFIX."static` ( `name`, `accesslevel` ) values( '".$_POST['name']."', '".$_POST['accesslevel']."' ) ");
 echo "Successful. Go <a href='../index.php?site=static&staticID=".mysql_insert_id()."'>here</a>";

}
elseif($_POST['saveedit']) {

//delete old staticfile...

 $ds=mysql_fetch_array(safe_query("SELECT name FROM `".PREFIX."static` WHERE staticID='".$_POST['staticID']."'"));
 unlink('../'.$ds[name]);

//...to write a new, updated one

 $file = ("../html/".$_POST['name']);
 $fp = fopen ($file, "w");
 fwrite ($fp, stripslashes($_POST['content']));
 fclose($fp);
	safe_query("UPDATE `".PREFIX."static` SET name='".$_POST['name']."', accesslevel='".$_POST['accesslevel']."' WHERE staticID='".$_POST['staticID']."'");

}
elseif($_GET['delete']) {
 $ds=mysql_fetch_array(safe_query("SELECT name FROM `".PREFIX."static` WHERE staticID='".$_GET['staticID']."'"));
  @unlink('../html/'.$ds[name]);
	safe_query("DELETE FROM `".PREFIX."static` WHERE staticID='".$_GET['staticID']."'");
}

echo'<h2>Static pages</h2>';
if($_GET['action']=="add") {
    echo'<form method="post" action="admincenter.php?site=static" enctype="post">
	     <table cellpadding="4" cellspacing="0">
		 <tr>
		   <td>Filename</td>
		   <td><input type="text" name="name" class="form_off" onFocus="this.className=\'form_on\'" onBlur="this.className=\'form_off\'" value="new.html"></td>
		 </tr>
		 <tr>
		 <tr>
		   <td>html-content:</td>
		   <td>
        <textarea name="content" cols="80" rows="40" class="form_off" onFocus="this.className=\'form_on\'" onBlur="this.className=\'form_off\'">
<html>
<head>
<title>webSPELL 4</title>
</head>
<body>
		   
</body>
</html></textarea>
       </td>
		 </tr>
		 <tr>
		   <td>&nbsp;</td>
		   <td><input type="submit" name="save" value="add file"></td>
		 </tr>
		 </table>
		 </form>';
}
elseif($_GET['action']=="edit") {

  $staticID = $_GET['staticID'];
  $ergebnis=safe_query("SELECT * FROM `".PREFIX."static` WHERE staticID='$staticID'");
	$ds=mysql_fetch_array($ergebnis);

	echo'<form method="post" action="admincenter.php?site=static" enctype="post">
	     <table cellpadding="4" cellspacing="0">
		 <tr>
		   <td>Filename</td>
		   <td><input type="text" name="name" class="form_off" onFocus="this.className=\'form_on\'" onBlur="this.className=\'form_off\'" value="'.$ds['name'].'"></td>
		 </tr>
		 <tr>
		 <tr>
		   <td>html-content:</td>
		   <td>
        <textarea name="content" cols="80" rows="40" class="form_off" onFocus="this.className=\'form_on\'" onBlur="this.className=\'form_off\'">'.getinput(file_get_contents('../html/'.$ds['name'])).'</textarea>
       </td>
		 </tr>
		 <tr>
		   <td><input type="hidden" name="staticID" value="'.$_GET['staticID'].'"></td>
		   <td><input type="submit" name="saveedit" value="edit file"></td>
		 </tr>
		 </table>
		 </form>';
}
else {
	echo'<input type="button" class="button" onClick="MM_goToURL(\'parent\',\'admincenter.php?site=static&action=add\');return document.MM_returnValue" value="new static page"><br><br>';

	$ergebnis=safe_query("SELECT * FROM ".PREFIX."static ORDER BY name");
	echo'<table width="100%" cellpadding="4" cellspacing="1" bgcolor="#999999">
   		<tr bgcolor="#CCCCCC">
   		<td class="title" align="center">filename:</td>
 		<td class="title" align="center" colspan="2">Actions:</td>
   		</tr>
		<tr bgcolor="#FFFFFF"><td colspan="3"></td></tr>';

	while($ds=mysql_fetch_array($ergebnis)) {
    	echo'<tr bgcolor="#FFFFFF">
	       		<td align="center"><b><a href="../index.php?site=static&staticID='.$ds[staticID].'" target="about:blank">'.$ds[name].'</a></b></td>
		   		<td align="center"><input type="button" class="button" onClick="MM_goToURL(\'parent\',\'admincenter.php?site=static&action=edit&staticID='.$ds[staticID].'\');return document.MM_returnValue" value="edit"></td>
		   		<td align="center"><input type="button" class="button" onClick="MM_confirm(\'really delete this category?\', \'admincenter.php?site=static&delete=true&staticID='.$ds[staticID].'\')" value="delete"></td>
		 	</tr>';
	}
	echo'</table>';
}
?>
