Location: PHPKode > projects > Network Traffic Monitor > online/export.php
<?php

#Network Traffic Monitor is an application to monitor the network traffic on all SNMP managable devices.
#
#Copyright (c) 2004, Daimler Trust nv <hide@address.com> - Jan Van Hees <hide@address.com>
# 
#This file is part of Network Traffic Monitor.
#
#    Network Traffic Monitor 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.
#
#    Network Traffic Monitor 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.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Network Traffic Monitor; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
/*
* This script export data to a textfile and delete is selected 
*/
require_once("../auth.php");
require_once ("../config.php");
require_once ("HTML/Template/IT.php");
require_once "HTML/Table.php";
if($_POST['port']){
	header("Location: error.php");
	exit;
}
$tpl = new HTML_Template_IT(TEMPLATEDIR);
$tpl->loadTemplatefile("exdel.tpl");
$tpl->setVariable("title","Export & Delete Data");

$db = dbLogin();

$type = $_POST['timespan'];
$exp  = $_POST['export'];
$del  = $_POST['delete'];

if($type=="older"){
	$year  = $_POST['year'];
	$month = $_POST['month'];
	$day   = $_POST['day'];
	$date = "$year-$month-$day 00:%";
	$select ="SELECT pid, times, incoming, outgoing FROM porttraffic WHERE times<'$date' ORDER BY times";
	if($del=="on"){
		$delete="DELETE FROM porttraffic WHERE times<'$date'";
		$delete2="DELETE FROM hourtraffic WHERE times<'$date'";
	}# if del on
}#if older
if($type=="between"){
	$fyear  = $_POST['fyear'];
	$fmonth = $_POST['fmonth'];
	$fday   = $_POST['fday'];
	$lyear  = $_POST['lyear'];
	$lmonth = $_POST['lmonth'];
	$lday	= $_POST['lday'];
	$fdate  = "$fyear-$fmonth-$fday 00:%";
	$ldate  = "$lyear-$lmonth-$lday 00:%";
	$select ="SELECT pid, times, incoming, outgoing FROM porttraffic WHERE times BETWEEN '$fdate' AND '$ldate' ORDER BY times";
	if($del=="on"){
		$delete="DELETE FROM porttraffic WHERE times BETWEEN '$fdate' AND '$ldate'";
		$delete2="DELETE FROM hourtraffic WHERE times BETWEEN '$fdate' AND '$ldate'";
	}# if del on
}#if between
if($exp=="export"){
	header ("Content-Type: text/plain");
	$result = $db->query($select);
	echo"pid, times, incoming, outgoing\n";
	while($row = $result->fetchrow()){
		echo" $row[0],  $row[1],  $row[2],  $row[3]\n";
	}
	if($del!="on")exit();
}//if export
if($del=="on"){
	$db->query($delete);
	$db->query($delete2);
	exit();
}

$content = $tpl->get();
fillFrame($db, $content);

dblogout($db);

?>
Return current item: Network Traffic Monitor