Location: PHPKode > scripts > CJ website search > cjwebsitesearchv1/admin.php
<?
session_start();
header("Cache-control: private"); // IE 6 Fix. 
include "config.php";
$filename = "$root/site.dat";
?>
<HTML>
<HEAD>
<link rel="stylesheet" href="css.css" type="text/css">
<title>CJ Website Search Control Panel</title>
</HEAD>
<body topmargin="50" leftmargin="50">
<IMG SRC="top.gif" WIDTH="300" HEIGHT="81" BORDER="0" ALT="CJ Website Search"><p>
<?

if (!session_is_registered('username') && !session_is_registered('password')){
	print "You must be logged in to view the Admin Control Panel<p><p>";
	print "<A HREF=\"login.php\">Log In</A>";
}
if (session_is_registered('username') && session_is_registered('password')){

echo "<h5>CJ Website Search Control Panel</h5><p>";			// Header

	if(!$_GET['action']){

		$date = date("l jS F, Y");

		?>

  <table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr>
      <td width="1%"><img border="0" src="gfx/cp.jpg" width="50" height="50"></td>
      <td width="99%"><font size=2>Hey <? echo $_SESSION['username']; ?><br><? echo $date; ?></font></td>
    </tr>
  </table><p>

  <?
		menuopen();
	}
	else if($_GET['action'] == "edit"){
		edit();
	}
	else if($_GET['action'] == "add"){
		add();
	}
	else if($_GET['action'] == "view"){
		view();
	}
	else if($_GET['action'] == "delete"){
		delete();
	}
	else if($_GET['action'] == "test"){
		test();
	}
	else if($_GET['action'] == "logout"){
		logout();
	}
	else if($_GET['action'] == "change") {
		edit();
		if($_GET['id'] >= 0){

				global $filename;
				$id = $_GET['id'];

				$fp = @fopen($filename, 'r');
				$array = explode("\n", fread($fp, filesize($filename))); 
				for($x=0;$x<sizeof($array);$x++) {									// start loop, each line of file
					$temp = explode("|",$array[$x]);									// explode the line and assign to temp
					$line[$x] = "$temp[0]|$temp[1]|$temp[2]|$temp[3]";
				}

				$mod = explode("|", $line[$id]);

				echo "<p><p>";
				echo "<form method=\"POST\" action=\"admin.php?action=change2\" method=\"post\">";
 				echo "<p><input type=\"text\" value=\"$mod[0]\" name=\"title\" size=\"50\"><br>";
				echo "<textarea rows=\"6\" name=\"description\" cols=\"50\">$mod[1]</textarea><br>";
				echo "<input type=\"text\" value=\"$mod[2]\" name=\"url\" size=\"50\"><br>";
				echo "<input type=\"text\" value=\"$mod[3]\" name=\"keywords\" size=\"50\"><br><br>";
				echo "<input type=\"submit\" value=\"Submit\"> ";
				echo "<input type=\"reset\" value=\"Reset\">";
				echo "<input type=\"hidden\" name=\"id\" value=\"$id\">";
				echo "</form>";

		}

		else{
			print "No ID specified, please <A HREF=\"?action=edit\">select an item</A> to be edited first!";
		}
	}
		else if($_GET['action'] == "viewit") {
		view();
		if($_GET['id'] >= 0){

				global $filename;
				$id = $_GET['id'];

				$fp = @fopen($filename, 'r');
				$array = explode("\n", fread($fp, filesize($filename))); 
				for($x=0;$x<sizeof($array);$x++) {									// start loop, each line of file
					$temp = explode("|",$array[$x]);									// explode the line and assign to temp
					$line[$x] = "$temp[0]|$temp[1]|$temp[2]|$temp[3]";
				}

				$show = explode("|", $line[$id]);

				?>
				<p><p>
				<table border="0" cellpadding="5" cellspacing="0" width="500">
				 <tr>
				    <td width="30%"><b>Title</b></td>
				    <td width="70%"><? echo $show[0]; ?></td>
				  </tr>
				<tr>
				    <td width="30%" valign="top"><b>Description</b></td>
				    <td width="70%"><? echo $show[1]; ?></td>
				  </tr>
				  <tr>
				    <td width="30%"><b>URL</b></td>
				    <td width="70%"><? echo $show[2]; ?></td>
				  </tr>
				  <tr>
				    <td width="30%"><b>Keywords</b></td>
				    <td width="70%"><? echo $show[3]; ?></td>
				  </tr>
					</table>

					<?
		}

		else{
			print "No ID specified, please <A HREF=\"?action=view\">select an item</A> to be edited first!";
		}
	}
	else if($_GET['action'] == "deleteit") {
		delete();
		if($_GET['id'] >= 0){

				global $filename;
				$id = $_GET['id'];

				$fp = @fopen($filename, 'r');
				$array = explode("\n", fread($fp, filesize($filename))); 
				
				unset($array[$id]); // delete it!

				if(count($array) > 0){
					$new = array_values(array_unique($array));
				}
				else $new = $array;

				$fp = fopen ("site.dat", "w");
				
				sort($new);

				fwrite ($fp, $new[0]);

				for($i=1; $i<sizeof($new);$i++){			
				fwrite ($fp, "\n");
				fwrite ($fp, $new[$i]);
				}
				fclose ($fp);
				print "<p><p>Record has been deleted successfully<br><br>";

		}

		else{
			print "No ID specified, please <A HREF=\"?action=view\">select an item</A> to be edited first!";
		}
	}
		else if($_GET['action'] == "change2") {
		menu();
		if($_POST['title'] && $_POST['description'] && $_POST['url'] && $_POST['keywords'] && $_POST['id'] >= 0){

				global $filename;

				$title = strip_tags(stripslashes($_POST['title']));		
				$description = htmlspecialchars(stripslashes($_POST['description']));		
				$description = str_replace("\n", "<br>", $description);
				$url = strip_tags(stripslashes($_POST['url']));		
				$keywords = strip_tags(stripslashes($_POST['keywords']));
				$keywords = trim(str_replace(",", " ", $keywords));		
				$id = $_POST['id'];

				$fp = @fopen($filename, 'r');
				$array = explode("\n", fread($fp, filesize($filename))); 
				for($x=0;$x<sizeof($array);$x++) {									// start loop, each line of file
					$temp = explode("|",$array[$x]);									// explode the line and assign to temp
					$line[$x] = "$temp[0]|$temp[1]|$temp[2]|$temp[3]";
				}

				$line[$id] = "$title|$description|$url|$keywords";

				sort($line);

				$fp = fopen ("$root/site.dat", "w");
				
				fwrite ($fp, $line[0]);

				for($i=1; $i<sizeof($line);$i++){			
				fwrite ($fp, "\n");
				fwrite ($fp, $line[$i]);
				}
				fclose ($fp);
				print "<p><p>Record has been edited successfully<br><br>";
		}
		else{
			print "Please go back and fill in the form properly.  Otherwise please <A HREF=\"?action=edit\">select an item</A> to be edited first!";
		}
	}
	else if($_GET['action'] == "submit") {
		if($_POST['allow'] == "yes"){
		add();
		$fp = fopen ("$root/site.dat", "a+");

		$title = strip_tags(stripslashes($_POST['title']));		
		$description = htmlspecialchars(stripslashes($_POST['description']));		
		$description = str_replace("\n", "<br>", $description);
		$link = strip_tags(stripslashes($_POST['link']));		
		$keywords = strip_tags(stripslashes($_POST['keywords']));
		$keywords = trim(str_replace(",", " ", $keywords));			

		fwrite ($fp, "\n");
		fwrite ($fp, $title);
		fwrite ($fp, "|");
		fwrite ($fp, $description);
		fwrite ($fp, "|");
		fwrite ($fp, $link);
		fwrite ($fp, "|");
		fwrite ($fp, $keywords);
		fwrite ($fp, "|");
		fclose ($fp);
		print "Site has been added successfully<br><br>";
		}
		else{
			print "Only the administrator can add pages.<br><br><A HREF=\"admin.php\">Log In</A>";
		}
	}
	else{
		menu();
	}
}


function edit(){

		menu();

		global $filename;

		$fp = @fopen($filename, 'r');
	
		if ($filename) {  
			$array = explode("\n", fread($fp, filesize($filename))); 

			$listed = count($array);

			?>

				<table border="0" cellpadding="2" cellspacing="0" width="100%">
				<tr>
				<td width="1%"><img border="0" src="gfx/edit.jpg" width="50" height="50"></td>
				<td width="99%"><font size="3">Edit</font></td>
				</tr>
				</table>
				<br>

				<?

				echo "Select item to edit :: Viewing all ($listed) listed by URL<P><P>";

				for($x=0;$x<$listed;$x++) {									// start loop, each line of file
					$temp = explode("|",$array[$x]);									// explode the line and assign to temp
				
				
				echo "<li>[<A HREF=\"?action=change&id=$x\">edit</A>] - <b>$temp[2]</b></li>";				
	
			}
		}
	}

function delete(){

		menu();

		global $filename;

		$fp = @fopen($filename, 'r');
	
		if ($filename) {  
			$array = explode("\n", fread($fp, filesize($filename))); 

			$listed = count($array);

				?>

			  <table border="0" cellpadding="2" cellspacing="0" width="100%">
				<tr>
				<td width="1%"><img border="0" src="gfx/delete.jpg" width="50" height="50"></td>
				<td width="99%"><font size="3">Delete</font></td>
				</tr>
				</table>
				<br>

				  <?

				echo "Select item to delete :: Viewing all ($listed) listed by URL<P><P>";

				for($x=0;$x<$listed;$x++) {									// start loop, each line of file
					$temp = explode("|",$array[$x]);									// explode the line and assign to temp
				
				
				echo "<li>[<A HREF=\"?action=deleteit&id=$x\">delete</A>] - <b>$temp[2]</b></li>";				
	
			}
		}
	}


function view(){

		menu();

		global $filename;

		$fp = @fopen($filename, 'r');
	
		if ($filename) {  
			$array = explode("\n", fread($fp, filesize($filename))); 

			$listed = count($array);

			?>

			   <table border="0" cellpadding="2" cellspacing="0" width="100%">
				<tr>
				<td width="1%"><img border="0" src="gfx/view.jpg" width="50" height="50"></td>
				<td width="99%"><font size="3">View</font></td>
				</tr>
				</table>
				<br>

			<?

				echo "Select item to view :: Viewing all ($listed) listed by URL<P><P>";

				for($x=0;$x<$listed;$x++) {									// start loop, each line of file
					$temp = explode("|",$array[$x]);									// explode the line and assign to temp
				
				
				echo "<li>[<A HREF=\"?action=viewit&id=$x\">view</A>] - <b>$temp[2]</b></li>";				
	
			}
		}
	}

function menuopen(){

	?>

		<B><h4><p>Options</B></h4><P><P>
		<li><A HREF="?action=add">Add a website</A><br>
		<li><A HREF="?action=edit">Edit a website's details</A><br>
		<li><A HREF="?action=delete">Delete a website</A><br>
		<li><A HREF="?action=view">View a website's details</A><br>
		<li><A HREF="?action=test">Stats/Test the search engine</A><br>
		<li><A HREF="?action=logout"><font color=red>Logout!</font></A><br>
		<br><br>

	<?
				
}	

function menu(){

	?>

		<B><h4><p>Menu</B></h4><P><P>
		<li><A HREF="?action=add">Add</A><br>
		<li><A HREF="?action=edit">Edit</A><br>
		<li><A HREF="?action=delete">Delete</A><br>
		<li><A HREF="?action=view">View</A><br>
		<li><A HREF="?action=test">Stats/Test!</A><br>
		<li><A HREF="?action=logout"><font color=red>Logout</font></A><br>
		<br><br><hr>

	<?
				
}	
	
function formatsize($file_size){
	if($file_size >= 1073741824)
		{$file_size = round($file_size / 1073741824 * 100) / 100 . " Gigabytes!";}
    elseif($file_size >= 1048576)
    	{$file_size = round($file_size / 1048576 * 100) / 100 . " Megabytes!";}
    elseif($file_size >= 1024)
    	{$file_size = round($file_size / 1024 * 100) / 100 . " Kilobytes";}
    else{$file_size = $file_size . " Bytes";}
return $file_size;
}


function test(){

			menu();

			global $filename;

			$fp = @fopen($filename, 'r');
			$array = explode("\n", fread($fp, filesize($filename))); 
			$count = count($array);

			if(is_writable($filename)){
				$state = "<font color=blue>OK</font>";
			}
			else{
					$state = "<font color=red>Not Writable, <A HREF=\"http://www.perlservices.net/en/faq/cute_ftp.shtml\" TARGET=\"_blank\">CHMOD</A> \"site.dat\"!</font>";
			}
	?>

			   <table border="0" cellpadding="2" cellspacing="0" width="100%">
				<tr>
				<td width="1%"><img border="0" src="gfx/test.jpg" width="50" height="50"></td>
				<td width="99%"><font size="3">Stats/Test Database</font></td>
				</tr>
				</table>
				<br>
				<li> Database State = <b><? echo $state; ?></b>
				<li> Database Size = <b><? echo $dbsize = formatsize(filesize($filename)); ?></b>
				<li> Website Count = <b><? echo $count; ?></b><br>
			 <form action="search.php" method="post" target="_blank">
				Search:
			<input type="text" name="keyword" size="20" maxlength="100">
			<input type="submit" name="submit" value="Search">
			<input type ="hidden" name="action" value ="search">
				</form>

	<?
				
}	

function logout(){

  session_destroy();

?>

			   <table border="0" cellpadding="2" cellspacing="0" width="100%">
				<tr>
				<td width="1%"><img border="0" src="gfx/logout.jpg" width="50" height="50"></td>
				<td width="99%"><font size="2">Logged out successfully</font></td>
				</tr>
				</table>
				<br>
				<br>
				<li><A HREF="login.php">Log In</A>
				<li><A HREF="<? echo $yourwebsite; ?>">Return to Website</A>
   
<?

}
	
function add(){

		menu();

?>

  <table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr>
      <td width="1%"><img border="0" src="gfx/add.jpg" width="50" height="50"></td>
      <td width="99%"><font size="3">Add</font></td>
    </tr>
  </table>
  <br><form method="post" action="admin.php?action=submit">
<table border="0" cellpadding="5" cellspacing="0" width="400">
  <tr>
    <td width="50%"><b>Page Title</b></td>
    <td width="50%"> <input type=text name=title size="50"></td>
  </tr>
  <tr>
    <td width="50%"><b>Description</b></td>
    <td width="50%"><textarea rows="5" name="description" cols="50"></textarea></td>
  </tr>
  <tr>
    <td width="50%"><b>URL</b></td>
    <td width="50%"> <input type=text name=link value=http:// size="50"></td>
  </tr>
  <tr>
    <td width="50%"><b>Keywords</b></td>
    <td width="50%"><font size="1" color="red">Note:&nbsp; Separate keywords by spaces <font color="blue">(word1 word2 word3)</font><br>
 <input type=text name=keywords size="50"></td>
  </tr>
  <tr>
	<td width="50%"></td>
    <td width="50%">
		<input type ="hidden" name="allow" value ="yes">
	  <input type=submit value=Submit> <input type="reset" value="Reset" name="Reset"></td>
  </tr>
</table>
</form>

<?
}

// If you like this script then vote for it at Hotscripts or PHPResource or wherever you got it from!
// I would appreciate it if all copyright could remain to abide with the Data Protection act.
// If you would however like to remove it then a kind donation should be sent via paypal to hide@address.com
// Please do not manipulate this code to pass it off as your own
?>
<p><p>
<hr>
CJ Website Search © 2003 <a href="http://www.cj-design.com">CJ Website
Design</a> | <A HREF="http://www.cj-design.com/?id=forum">Script Support</A> | <A HREF="http://www.cj-design.com/?id=donate">Donate</A>
</BODY>
</HTML>
Return current item: CJ website search