Location: PHPKode > projects > @1 File Store > control/users/index.php
<?
require_once("const.php");
require_once(LIBPATH."multipage.php");

$pager=new multipage("page");
$pager->setpagesize(20);

$smarty->assign("datasheet", "user_list");
$ulev = $CurUser->getlevel();

	$user_list=array();
	$SQL="SELECT * FROM `".DB_PREFIX."users`";
	if($ulev>=0) {
		$SQL.=" WHERE `level`<>0 AND `level`<>-1";
	}
	$SQL.=" ORDER BY `level` ASC, `real_name` ASC";
	if(!$mysql->query($SQL)) {
		exit($mysql->error);
	}
	$pager->setrec($mysql->num);
	$SQL.=$pager->limit();

	if(!$mysql->query($SQL)) {
		exit($mysql->error);
	}
	$smarty->assign("PAGES", $pager->smarty());

	while(!$mysql->EOF) {
		$user_list[]=$mysql->arr;
		$mysql->movenext();
	}

	$raw = $user_list;

	foreach ($user_list as $kuser_list => $vuser_list) {
		$userid = $vuser_list['level'];
		if ($userid == '99999') {
			$user_list[$kuser_list]['grp_name']='-';
		} else {
			$SQL2="SELECT group_name FROM `".DB_PREFIX."user_groups` WHERE id='".$userid."'";
			if(!$mysql->query($SQL2)) { exit($mysql->error); }
			if ($mysql->field('group_name') == '') {
				$user_list[$kuser_list]['grp_name']='admins';
			} else {
				$user_list[$kuser_list]['grp_name']=$mysql->field('group_name');
			}
		}
	}
$flist = $user_list;
$smarty->assign("listdata", $flist);

// -- start -- STATISTICS DISPLAY
	$smarty->assign("extra_info", "1");
	
	function getStatistic($SQL_total,$SQL_subscribe,&$total,&$subscribed){
		if(!($rs=mysql_query($SQL_total))) {
			exit(mysql_error());
		}
		
		$total=0;
		if($row=mysql_fetch_array($rs)) {
			$total=$row[0];
		}
		
		if(!($rs=mysql_query($SQL_subscribe))) {
			exit(mysql_error());
		}
		
		$subscribed=0;
		if($row=mysql_fetch_array($rs)) {
			$subscribed=$row[0];
		}
	}
	
	// # admin statistic #
	$SQL_total="SELECT count( `".DB_PREFIX."users`.login )
		  FROM `".DB_PREFIX."users`
		  WHERE `".DB_PREFIX."users`.level = -1";	
	
	$SQL_subscribe="SELECT count( `".DB_PREFIX."users`.login )
		  FROM `".DB_PREFIX."users`
		  WHERE `".DB_PREFIX."users`.level = -1
		  AND `".DB_PREFIX."users`.subscription = 'Y'";	
	getStatistic($SQL_total,$SQL_subscribe,$total,$subscribed);
	
	$smarty->assign("x_admin", $total);
	$smarty->assign("y_admin", $subscribed);
	
	// # subadmin statistic #
	$SQL_total="SELECT count( `".DB_PREFIX."users`.login )
		  FROM `".DB_PREFIX."users`
		  WHERE `".DB_PREFIX."users`.level = 0";	
	$SQL_subscribe="SELECT count( `".DB_PREFIX."users`.login )
		  FROM `".DB_PREFIX."users`
		  WHERE `".DB_PREFIX."users`.level = 0
		  AND `".DB_PREFIX."users`.subscription = 'Y'";
	getStatistic($SQL_total,$SQL_subscribe,$total,$subscribed);	
	
	$smarty->assign("x_subadmin", $total);
	$smarty->assign("y_subadmin", $subscribed);
	
	// # total user for each group #
	// --grab groups
	$SQL="SELECT `".DB_PREFIX."user_groups`.id,`".DB_PREFIX."user_groups`.group_name 
	      FROM `".DB_PREFIX."user_groups` ORDER BY `".DB_PREFIX."user_groups`.group_name ASC";		  
	if(!$mysql->query($SQL)) { exit($mysql->error); }
	$group_list=array();
	while(!$mysql->EOF) {
		$group_list[]=$mysql->arr;
		$mysql->movenext();
	}
	
	if(count($group_list)){
		$user_groups=array();
		foreach($group_list as $group){		
			$SQL_total="SELECT count( `".DB_PREFIX."users`.login )
				  FROM `".DB_PREFIX."users`
				  WHERE `".DB_PREFIX."users`.level = ".$group["id"];	
			$SQL_subscribe="SELECT count( `".DB_PREFIX."users`.login )
				  FROM `".DB_PREFIX."users`
				  WHERE `".DB_PREFIX."users`.level = ".$group["id"]." 
				  AND `".DB_PREFIX."users`.subscription = 'Y'";
			getStatistic($SQL_total,$SQL_subscribe,$total,$subscribed);
			$user_groups[]=array("group_name"=>$group["group_name"],"total"=>$total,"subscribed"=>$subscribed);
		}
		
		$smarty->assign("user_groups", $user_groups);
	}
	
	// # total user excluded admin/subadmin statistic #
	$SQL_total="SELECT count( `".DB_PREFIX."users`.login )
		  FROM `".DB_PREFIX."users`
		  WHERE `".DB_PREFIX."users`.level > 0";	
	$SQL_subscribe="SELECT count( `".DB_PREFIX."users`.login )
		  FROM `".DB_PREFIX."users`
		  WHERE `".DB_PREFIX."users`.level > 0
		  AND `".DB_PREFIX."users`.subscription = 'Y'";
	getStatistic($SQL_total,$SQL_subscribe,$total,$subscribed);		
	
	$smarty->assign("x_exadmin", $total);
	$smarty->assign("y_exadmin", $subscribed);
	
	// # total user included admin/subadmin statistic #
	$SQL_total="SELECT count( `".DB_PREFIX."users`.login )
		  FROM `".DB_PREFIX."users`";
	$SQL_subscribe="SELECT count( `".DB_PREFIX."users`.login )
		  FROM `".DB_PREFIX."users`
		  WHERE `".DB_PREFIX."users`.subscription = 'Y'";
	getStatistic($SQL_total,$SQL_subscribe,$total,$subscribed);	
	
	$smarty->assign("x_inadmin", $total);
	$smarty->assign("y_inadmin", $subscribed);
//  -- end --  STATISTICS DISPLAY

$smarty->display("control/index.tpl");
?>
Return current item: @1 File Store