<?php
global $id_interfaces;
require('config.php');
mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD);
mysql_select_db(DB_DATABASE);
if ($_GET['id_interfaces']>0) {
$id_interfaces = $_GET['id_interfaces'];
}else{
$id_interfaces = $_POST['id_interfaces'];
}
if ($id_interfaces < 1) {
$query = "SELECT id, name FROM interfaces LIMIT 1";
}else{
$query = "SELECT id, name FROM interfaces WHERE id = ".$id_interfaces." LIMIT 1";
}
$db_query = mysql_query($query);
$resultset = mysql_fetch_array($db_query, MYSQL_ASSOC);
$id_interfaces = $resultset['id'];
$table_name = $resultset['name'];
$query = "SHOW TABLES LIKE '".$table_name."'";
$tables = mysql_query($query);
if (mysql_fetch_array($tables) === false) {
$sql = "CREATE TABLE ". $table_name ." (
id int(11) NOT NULL auto_increment,
name varchar(255) character set utf8 collate utf8_unicode_ci default NULL,
sort_order int(5) NOT NULL,
lft int(11) NOT NULL,
rgt int(11) NOT NULL,
rate varchar(20) character set utf8 collate utf8_unicode_ci default NULL,
ceil varchar(20) character set utf8 collate utf8_unicode_ci default NULL,
burst varchar(20) character set utf8 collate utf8_unicode_ci default NULL,
prio int(1) NOT NULL default '3',
monitor int(1) NOT NULL default '0',
PRIMARY KEY (`id`)
)";
mysql_query($sql);
}
require('lib/tree.class.php');
$tree = new tree($table_name);
switch($_GET['action'])
{
case 'add_new_category':
$name = $_POST['name'];
$rate = $_POST['rate'];
$ceil = $_POST['ceil'];
$burst = $_POST['burst'];
$prio = $_POST['prio'];
$monitor = $_POST['monitor'];
if(strlen($name)>0)
{
$nodelft = $_POST['nodelft'];
$lft = $nodelft+1;
$rgt = $nodelft+2;
if (!defined($burst)) {$burst='2Kbit';}
if (!defined($prio)) {$prio=3;}
if (!defined($monitor)) {$monitor=0;}
$tree->shiftRight($nodelft);
$query = "INSERT INTO ".$table_name." (id , name , sort_order , lft , rgt, rate, ceil, burst, prio, monitor) VALUES (NULL ,'" . $name . "', '0', '" . $lft. "', '" . $rgt . "', '" . $rate . "', '" . $ceil . "', '". $burst ."', '" . $prio . "', '" . $monitor . "')";
mysql_query($query);
$tree->sortTree();
}
$url = "index.php?id_interfaces=".$id_interfaces;
header('Location: '.$url);
break;
case 'update_category':
$name = $_POST['name'];
$id = $_POST['id'];
$rate = $_POST['rate'];
$ceil = $_POST['ceil'];
$burst = $_POST['burst'];
$prio = $_POST['prio'];
$monitor = $_POST['monitor'];
if(strlen($name)>0 && $id>0)
{
$nodelft = $_POST['nodelft'];
$lft = $_POST['lft'];
$rgt = $_POST['rgt'];
$query = "UPDATE ".$table_name." set name='" . $name . "' , lft='" . $lft . "' , rgt = '" . $rgt . "', rate= '" . $rate . "', ceil = '" . $ceil . "', burst = '" . $burst . "', prio = '" . $prio . "', monitor = '" . $monitor . "' WHERE id='" . $id . "'";
mysql_query($query);
if($nodelft!=$_POST['parentLft'])
{
$tree->moveNodes($nodelft, $lft, $rgt);
}
$tree->sortTree();
}
$url = "index.php?id_interfaces=".$id_interfaces;
header('Location: '.$url);
break;
case 'sort_items':
$sortItems = $_POST['order_items'];
foreach($sortItems as $sortOrder=>$id)
{
$query = "UPDATE ".$table_name." set sort_order='" . ($sortOrder+1) . "' WHERE id='" . $id . "'";
mysql_query($query);
}
$tree->sortTree();
exit();
break;
case 'delete_category':
$id = $_GET['id'];
$id_interfaces = $_GET['id_interfaces'];
if($id>0)
{
$query = "SELECT rgt, lft FROM ".$table_name." WHERE id='" . $id . "'";
$db_query = mysql_query($query);
$resultset = mysql_fetch_array($db_query, MYSQL_ASSOC);
$lft = $resultset['lft'];
$rgt = $resultset['rgt'];
$query = "DELETE FROM ".$table_name." WHERE id='" . $id . "'";
mysql_query($query);
$query = "DELETE FROM fillter WHERE id_class='" . $id . "'";
mysql_query($query);
$tree->delete($lft, $rgt);
}
$url = "index.php?id_interfaces=".$id_interfaces;
header('Location: '.$url);
break;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1251">
<title>Traffic Manager</title>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous/scriptaculous.js"></script>
<script type="text/javascript" src="js/livevalidation.js"></script>
<script type="text/javascript" src="js/modalbox/modalbox.js"></script>
<link rel="stylesheet" href="js/modalbox/modalbox.css" type="text/css" />
<link rel="stylesheet" href="css/table.css" type="text/css" />
<link rel="stylesheet" href="css/common.css" type="text/css" />
<style>
ul.sortItemList li {
cursor:move;
}
</style>
</head>
<body>
<table width=100% border=0 cellspasing=0 cellpaddind=0>
<tr class="ewHeaderRow"><td><img src="images/logo6.png"></img></td></tr>
</table>
<table>
<tr>
<td class="phpmaker" valign="top" >
<fieldset title="Manage class" style="background-color:#FFFFFF">
<legend style="background-color:#FC6002; color:#FFFFFF; font-weigth:bold; font-size:10pt">Manage class</legend>
<div style="overflow:auto; width:300px; height:550px">
<div>
<form action="index.php?id_interfaces" method="post">
<fieldset title="Select interfaces">
<legend>Select interfaces</legend>
<table>
<tr>
<td><select name="id_interfaces" onchange="this.form.submit()">
<?php
$query = "SELECT id, name FROM interfaces";
$db_query = mysql_query($query);
while($resultset = mysql_fetch_array($db_query, MYSQL_ASSOC))
{
if ($id_interfaces > 0) {
if ($resultset['id'] == $id_interfaces) {
echo '<option selected value="' . $resultset['id']. '">' . $resultset['name'] . '</option>';
}else{
echo '<option value="' . $resultset['id']. '">' . $resultset['name'] . '</option>';
}
}else{
echo '<option value="' . $resultset['id']. '">' . $resultset['name'] . '</option>';
}
}
?>
</select></td>
<td><input type="button" title="Edit interfaces" onclick="Modalbox.show('_ajax_edit_interfaces.php', {title: this.title, width:350}); return false;" value="Add"></td>
</tr>
</table>
</fieldset>
</form>
</div>
<div >
<form action="index.php?action=add_new_category" method="post">
<fieldset title="Add New class">
<legend>Add New class</legend>
<table>
<tr>
<td><span class="phpmaker">Name:</span></td><td><input type="text" name="name"></td>
</tr>
<tr>
<td><span class="phpmaker">Parent:</span></td><td><?php echo $tree->buildHtmlSelect('name="nodelft"'); ?></td>
</tr>
<tr>
<td>
<input type="submit" value="Add">
<input type="hidden" name="id_interfaces" value="<?php echo $id_interfaces; ?>">
</td>
</tr>
</table>
</fieldset>
</form>
</div>
<div >
<form action="index.php" method="get">
<fieldset title="Sort Order">
<legend>Sort Order</legend>
<span class="phpmaker">Select Class:</span> <?php echo $tree->buildHtmlSelect('name="nodelft" onChange="this.form.submit()"', $_GET['nodelft']); ?>
<ul id="order_items" class="sortItemList">
<?php
$result = $tree->getBranch($_GET['nodelft']);
while($resultset = mysql_fetch_array($result))
{
echo '<li id="order_item_' . $resultset['id'] . '" class="sortable"><span class="phpmaker">' . $resultset['name'] . '</span></li>';
}
?>
</ul>
<script type="text/javascript">
Sortable.create('order_items', {onUpdate:function(){new Ajax.Request('index.php?action=sort_items&id_interfaces=<?php echo $id_interfaces; ?>', {asynchronous:true, evalScripts:false, parameters:Sortable.serialize('order_items')});}, only:'sortable'})
</script>
<input type="submit" value="Update">
<input type="hidden" name=id_interfaces value="<?php echo $id_interfaces; ?>">
</fieldset>
</form>
</div>
</div>
</fieldset>
</td>
<td valign="top" class="phpmaker">
<div >
<fieldset title="Class List">
<legend style="background-color:#FC6002; color:#FFFFFF; font-weigth:bold; font-size:10pt">Class List</legend>
<div style="overflow:auto; width:300px; height:550px">
<table>
<?php
$tree_array = $tree->build(array(),'id');
foreach($tree_array as $key=>$value)
{
echo '<tr><td><span class="phpmaker">' . $value . '</span></td><td><a href="_ajax_edit_class.php?id=' . $key . '&id_interfaces=' . $id_interfaces . '" title="Edit class" onclick="Modalbox.show(this.href, {title: this.title, width:350}); return false;" ><img src="images/b_props.png" alt="Edit class" border=0></img></a></a> <a href="_ajax_edit_filter.php?id_class=' . $key . '&id_interfaces=' . $id_interfaces . '" title="Edit filter" onclick="Modalbox.show(this.href, {title: this.title, width: 550}); return false;"><img src="images/b_browse.png" alt="Filter tables" border=0></img></a> <a href="index.php?action=delete_category&id=' . $key . '&id_interfaces='.$id_interfaces.'" onClick="return confirm(\'Are you sure?\')"><img src="images/b_drop.png" alt="Delete class" border=0></img></a></td></tr>';
}
?>
</table>
</div>
</fieldset>
</div>
</td>
<td valign="top" class="phpmaker">
<div >
<fieldset title="Graph List">
<legend style="background-color:#FC6002; color:#FFFFFF; font-weigth:bold; font-size:10pt">Graph List</legend>
<div style="overflow:auto; width:450px; height:550px">
<table width="100%" border=0>
<?php
//$GRAPHDIR='graph/';
$handle=opendir(GRAPHDIR);
while ( ($file = readdir($handle))!==false) {
if (stristr($file, $table_name)) {
$image_file = GRAPHDIR.$file;
echo '<tr><td class="phpmaker"><a href="_ajax_graph_class.php?name='.$image_file.'" border=0 title="Show graph" onclick="Modalbox.show(this.href, {title: this.title, width:950}); return false;"><img src='.$image_file.' width=420 height=120></a></td></tr>';
}
}
closedir($handle);
?>
</table>
</div>
</fieldset>
</div>
</td>
</tr>
</table>
</body>
</html>