Location: PHPKode > scripts > LinkExchange > linkexchange/LinkExchange_Admin.php
<?php
require ("LinkExchange.class.php");
$links = new LinkExchange_class;

$form_result = '';

if (isset ($_POST['create_tables'])) {
	$links->setupTables();
	$form_result = 'Tables created';
}



if (isset ($_POST['add_category'])) {
	$links->addCategory(addslashes($_POST['add_category_name']));
	$form_result = 'Category added';
}



if (isset ($_POST['add_link'])) {
	$links->addLink (addslashes ($_POST['add_link_source']), addslashes ($_POST['add_link_backlink']), (int) $_POST['add_link_category']);
	$form_result = 'Link added';
}

if (isset ($_POST['remove_link'])) {
	$links->removeLink( (int) $_POST['remove_link_id']);
	$form_result = 'Link removed';
}


if (isset ($_GET['remove_link_id'])) {
	$links->removeLink( (int) $_GET['remove_link_id']);
	$form_result = 'Link removed';
}


if (isset ($_POST['update_link'])) {
	$links->updateLink ((int)$_POST['remove_link_id'], addslashes( $_POST['edit_link_source'] ), addslashes ($_POST['edit_backlink']), (int) $_POST['edit_category']);
	$form_result = 'Link updated';
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Links Administration</title>
</head>

<body>
<h1 style="color:#FF0000"><?=$form_result ?></h1>
<table border="1" align="center">
<tr><td>Create tables</td><td><form action="LinkExchange_Admin.php" method="post"><input type="submit" name="create_tables" value="Create tables" /></form></td></tr>
<tr>
  <td>Add category </td>
  <td><form action="LinkExchange_Admin.php" method="post"><input type="text" name="add_category_name" /><br /><input type="submit" name="add_category" /></form></td>
</tr>
<tr>
  <td>Add link </td>
  <td><form action="LinkExchange_Admin.php" method="post">
    <label>Links source: <textarea name="add_link_source" cols="60" rows="3"></textarea></label><br />
	Category: <select name="add_link_category"><?php $categories = $links->getCategoriesList(); for ($i = 0; $i < $links->counter; $i++) echo '<option value="'.$categories[$i]['category_id'].'">'.$categories[$i]['category_id'].'. '.stripslashes ($categories[$i]['name']).'</option>'; ?></select><br />
	Backlink address <input type="text" name="add_link_backlink" size="60" /><br />
	<input type="submit" name="add_link" />
  </form></td>
</tr>
<tr>
  <td>Check links</td>
  <td><form action="LinkExchange_Admin.php" method="post" target="_blank">
  All <input type="radio" name="check_type" value="all" checked="checked" /> &nbsp; Only confirmed <input type="radio" name="check_type" value="confirmed" /> &nbsp; Only not confirmed <input type="radio" name="check_type" value="not_confirmed" /><br />
  <input type="submit" name="check_links" value="Check links" /></form></td>
</tr>
<tr>
  <td>Remove link </td>
  <td><form action="LinkExchange_Admin.php" method="post"> Enter Link No: <input type="text" name="remove_link_id" value="" /><input type="submit" name="remove_link" value="Remove" /></form></td>
</tr>

<tr><td>Show all links</td><td><form action="LinkExchange_Admin.php" method="post">
<select name="category_id"><option value="0">All categories</option><?php $categories = $links->getCategoriesList(); for ($i = 0; $i < $links->counter; $i++) echo '<option value="'.$categories[$i]['category_id'].'">'.$categories[$i]['category_id'].'. '.stripslashes ($categories[$i]['name']).'</option>'; ?></select>
<input type="submit" name="show_all" value="Show" /></form></td></tr>
</table>

<p>&nbsp;</p>
<hr />
<p>&nbsp;</p>
<?php
set_time_limit(300);
if (isset ($_POST['check_links'])) {
	echo '<h2>Checking links</h2>';
	echo '<form><table border=1><tr><th>ID</th><th>Link</th><th>Backlink address</th><th>Status</th></tr>';
	$links->checkLinks ( $_POST['check_type']);
	echo '</table></form>';
}


if (isset ($_POST['show_all'])) {
	echo '<table align="center">';
	$categories = $links->getCategoriesList(); 
	$cat_counter = $links->counter;
	$links_array = $links->makeCheckReport((int) $_POST['category_id']);
	for ($i = 0; $i < $links->counter; $i++) {
		echo '<tr><td>';
		echo '<form action="LinkExchange_Admin.php" method="post"><table border="1"><tr><td>ID</td><td>'.$links_array[$i]['link_id'].'</td></tr><tr><td>Link source</td><td><textarea name="edit_link_source" cols="60" rows="3">'. stripslashes ($links_array[$i]['link_source']) .'</textarea></td></tr><tr><td>Backlink address</td><td><input type="text" name="edit_backlink" value="'.stripslashes ($links_array[$i]['backlink_address']).'" size="60" /></td></tr><tr><td>Category</td><td><select name="edit_category">';
		for ($j = 0; $j < $cat_counter; $j++) {
			if ($categories[$j]['category_id'] == $links_array[$i]['category_id']) $selected = ' selected="selected"'; else $selected = '';
			echo '<option value="'.$categories[$j]['category_id'].'"'.$selected.'>'.$categories[$j]['category_id'].'. '.stripslashes ($categories[$j]['name']).'</option>';
		}
		echo '</select></td></tr><tr><td>Date added</td><td></td></tr><tr><td>Date checked</td><td></td></tr><tr><td>Action</td><td><input type="submit" name="remove_link" value="Remove" /> &nbsp; <input type="submit" name="update_link" value="Update" /><input type="hidden" name="remove_link_id" value="'.$links_array[$i]['link_id'].'" /></td></tr></table></form>';
		
		echo '</td></tr>';
	}
	echo '</table>';
}
?>
</body>
</html>
Return current item: LinkExchange