Location: PHPKode > projects > Network Traffic Monitor > online/userlist.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 provides a user interface 2 list the available users 
*/
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;
}
$fname = $_GET['name'];
$cid = $_GET['f'];
$gid = $_GET['g'];

$db = dbLogin();

$tpl = new HTML_Template_IT(TEMPLATEDIR);
$tpl->loadTemplatefile("basic.tpl");
$tpl->setVariable("title", "Users");

/*
* The userlist can be used in 2 cases
* either to give a listing of all users
* either to give a listing of the users of a specific company
* the querys are different for those 2 cases
*/

if($cid){
	$sql ="SELECT DISTINCT users.username, users.fullname, users.email, groups.groupname, company.compname, usertype.type, users.uid, users.passwd FROM company
	INNER JOIN users ON users.cid = company.cid
	INNER JOIN groupmember ON groupmember.uid = users.uid
	INNER JOIN groups ON groups.gid = groupmember.gid 
	INNER JOIN usertype ON users.tid = usertype.tid
	WHERE company.cid=$cid ORDER BY users.username";
	$tpl->setVariable("title",$fname);
}//if company ID
else if($gid){
	$sql ="SELECT DISTINCT users.username, users.fullname, users.email, groups.groupname, company.compname, usertype.type, users.uid, users.passwd FROM company
	INNER JOIN users ON users.cid = company.cid
	INNER JOIN groupmember ON groupmember.uid = users.uid
	INNER JOIN groups ON groups.gid = groupmember.gid 
	INNER JOIN usertype ON users.tid = usertype.tid
	WHERE groups.gid=$gid ORDER BY users.username"; 
	$tpl->setVariable("title","Users");
}
else {
	$sql ="SELECT DISTINCT users.username, users.fullname, users.email, groups.groupname, company.compname, usertype.type, users.uid, users.passwd FROM company
	INNER JOIN users ON users.cid = company.cid
	INNER JOIN groupmember ON groupmember.uid = users.uid
	INNER JOIN groups ON groups.gid = groupmember.gid
	INNER JOIN usertype ON users.tid = usertype.tid ORDER BY users.username"; 
	$tpl->setVariable("title","Users");
}//if no company ID

/*
* Start building a dynamic table
* check http://pear.php.net/manual/en/package.html.html-table.php 4 more info
*/

$temp = $db->query($sql);
	$i = 0;
	while ($row = $temp->fetchrow()){
		$manip = "<a href=\"edituser.php?u=$row[6]\">E</a> / <a href=\"delete.php?type=user&i=$row[6]\">D</a> / <a href=\"mailto:$row[2]?subject=ntm user details&body=address: http://$_SERVER[HTTP_HOST]<br>username: $row[0]<br>password: $row[7]\">S</a>";
		$arr = array($row[0],$row[5], $row[3], $row[1],$row[4],$row[2], $manip);
		$data[$i]=$arr;
		$i++;
	}//while fetchrow

	//create table
	$tableAttrs = array("width" => "800");
	$table = new HTML_Table($tableAttrs);
	$table -> setAutoGrow(true);

	for($nr = 0 ; $nr < count($data); $nr++) {
		$table -> setHeaderContents( $nr+1, 0, (string)$nr); 
		for($i = 0; $i < 7; $i++) {  
			if("" != $data[$nr][$i])
			$table -> setCellContents( $nr+1, $i+1, $data[$nr][$i]);
 		}//for
	}//for
	$altRow = array("bgcolor"=>"silver");	
	$table -> altRowAttributes(1, null, $altRow);
	$table -> setHeaderContents(0, 0, " "); 
	$table -> setHeaderContents(0, 1, "User Name");
	$table -> setHeaderContents(0, 2, "User Type");
	$table -> setHeaderContents(0, 3, "Group");
	$table -> setHeaderContents(0, 4, "Full Name");
	$table -> setHeaderContents(0, 5, "Company");
	$table -> setHeaderContents(0, 6, "E-Mail");
	$table -> setHeaderContents(0, 7, "");
	$hrAttrs = array("bgcolor" => "silver");
	$table -> setRowAttributes(0, $hrAttrs, true);
	$table -> setColAttributes(0, $hrAttrs);
	
	$tpl->setVariable("data",$table->toHTML());
	$tpl->setVariable("add","<a href=\"adduser.php\">Add User</a>");



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

dblogout($db);
?>
Return current item: Network Traffic Monitor