<?php
// ======================================================================== //
//   KOOBI - CMS                                                            //
//   SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS                     //
//                                                                          //
//   DREAM4 - AM MICHELSGRUND 7 - 69469 WEINHEIM - GERMANY                  //    
//   TEL. +49(0) 6201 - 980442 / FAX. +49(0) 6201 - 64809                   //
// ======================================================================== //
if(!checkactive('user')) include(dirname(__FILE__)."/lib/notactive.php" );
$sname = simpletitle($lang['useroverview']);
$ok = 1;
$num = 1;

$limit = ($_REQUEST['pp']!='') ? $_REQUEST['pp'] : 10; 

if (!permission("showuserpage")) {
	$EOUT = stderror("nopermission", $lang['nopermission_t'], str_replace("__URL__", "index.php", $lang['redirect']), "index.php", 1);
	$error = 1;
	$NOOUT = 1;
	$ok = 0;
	
	} else {
	
	if (isset($_REQUEST['group']) && $_REQUEST['group'] != "") {
		$z1 = "AND (ugroup='".$_REQUEST['group']."')";
		if ( $_REQUEST['group'] == "all" ) {
			$z1 = "";
		}
	}
	
	if($_REQUEST["ud"] == "ASC") {
		$ascdesc = "ASC";
		$tmpl->assign("ud1", "selected");
		
	} else {
		$_REQUEST["ud"] = "DESC";
		$ascdesc = "DESC";
		$tmpl->assign("ud2", "selected");
	}
	
	if ($_REQUEST["selby"] == "username") {
		$sortby = " ORDER BY uname";
		$tmpl->assign("sel1", "selected");
	} elseif ($_REQUEST["selby"] == "posts") {
		$sortby = " ORDER BY user_posts";
		$tmpl->assign("sel2", "selected");
	} elseif ($_REQUEST["selby"] == "joindate") {
		$sortby = " ORDER BY user_regdate";
		$tmpl->assign("sel3", "selected");
	} else {
		$sortby = " ORDER BY user_regdate";
	}
	
	if (isset($_REQUEST["suname"]) && $_REQUEST["suname"] != "") {
		$seename = " AND (uname like '%".$_REQUEST['suname']."%')";
		$z1 = "";
		$sortby = "";
		$ascdesc = "";
	}
	
	$sql2 =& new dbc("SELECT * FROM ".PREFIX."_user WHERE status='1' $z1 $seename $sortby $ascdesc");
	$num = $sql2->numrows();
	
	$seiten = ceil($num / $limit);
	$a = prepage() * $limit - $limit;
	
	$sql =& new dbc("SELECT * FROM ".PREFIX."_user WHERE status='1' $z1 $sortby $seename $ascdesc  limit  $a,$limit");
	
	
	
	$table_data = array();
	$i = 2;
	while ($row = $sql->fetchrow()) {
		if($row->user_aim!=""){$useraim = '<a href="javascript:popex(\'index.php?p=misc&amp;do=AIM&amp;uid='.$row->uid.'\',\'\',\'450\',\'300\',\'1\',\'1\',\'0\',\'0\');"><img border="0" src="templates/'.$THEME.'/img/user_buttons/aim_small.gif" alt="" /></a>';}
		if($row->user_icq!=""){$usericq = '<a href="javascript:popex(\'index.php?p=misc&amp;do=ICQ&amp;uid='.$row->uid.'\',\'\',\'450\',\'300\',\'1\',\'1\',\'0\',\'0\');"><img border="0" src="templates/'.$THEME.'/img/user_buttons/icq_small.gif" alt="" /></a>';}
		if($row->user_canpn=="yes"){$usercanpn = '<a href="index.php?p=pn&amp;area='.$area.'&amp;action=new&amp;to='.base64_encode($row->uname).'"><img border="0" src="templates/'.$THEME.'/img/user_buttons/pn_small.gif" alt="" /></a>';}
		if($row->user_viewemail=="yes"){$usermail = '<a href="javascript:popex(\'index.php?p=misc&amp;do=EMAIL&amp;uid='.$row->uid.'\',\'\',\'450\',\'300\',\'1\',\'1\',\'0\',\'0\');"><img border="0" src="templates/'.$THEME.'/img/user_buttons/email_small.gif" alt="" /></a>';}
		$usergroup = fetchgroupname($row->ugroup);
		
		$userlink = "index.php?p=user&id=".$row->uid."";
		$entry_array = array(
		'name'	=> $row->uname,
		'usergroup'	=> $usergroup,
		'user_aim' => $useraim,
		'user_icq' => $usericq,
		'userlink' => $userlink,
		'posts' => $row->user_posts,
		'canpn' => $usercanpn,
		'usermail' => $usermail,
		'regtime' => mygmt($row->user_regdate)
		);
		unset($usercanpn,$useraim,$usermail,$usericq,$userlink,$usergroup);
		$i++;
		array_push($table_data, $entry_array);
	}
	$sql->close();
	
	$groupdata = array();
	$sqlg =& new dbc("SELECT * FROM ".PREFIX."_usergroup  WHERE ugroup!='2'");
	
	while ($rowg = $sqlg->fetchrow()) {
		
		if($_REQUEST['group'] == $rowg->ugroup){
			$sel = "selected";
		}
		
		array_push($groupdata, array(
		'groupname_sel' => $rowg->groupname,
		'group_id' => $rowg->ugroup,
		'sel' => $sel
		)
		);
		unset($sel);
	}
	
	for ($i = 10; $i <= 50; $i+=10) {
		unset($isel);
		
		if($_REQUEST['pp']==$i){$isel="selected";}
		$pp_l .= '<option value="'.$i.'" '.$isel.'>'.$i.'</option>';
	}
	
	
	$nav = pagenav($seiten, $lang['aktpos'], " <a class=\"page_navigation\" href=\"?p=userlist&amp;area=$area&amp;group=".$_REQUEST['group']."&amp;ud=".$_REQUEST['ud']."&amp;selby=".$_REQUEST['selby']."&amp;pp=".$limit."&amp;page={s}\">{t}</a> ");
	$tmpl->assign('pagenav', $nav);
	$tmpl->assign('allgroups', $lang['allgroups']);
	$tmpl->assign('pp_l', $pp_l);
	
	$tmpl->assign('table_data', $table_data);
	$tmpl->assign('groupdata', $groupdata);
	
	$tmpl->assign('name_t', $lang['t_name']);
	$tmpl->assign('regtime_t', $lang['regtime_t']);
	$tmpl->assign('usergroup_t', $lang['group_t']);
	$tmpl->assign('posts_t', $lang['posts']);
	$tmpl->assign('posts_t_s', $lang['posts_s']);
	$tmpl->assign('canpn_t', $lang['pnshort_t']);
	$tmpl->assign('user_aim_t', $lang['aimshort_t']);
	$tmpl->assign('usermail_t', $lang['emailshort_t']);
	$tmpl->assign('user_icq_t', $lang['icqshort_t']);
	$tmpl->assign('show', $lang['show']);
	$tmpl->assign('by_t', $lang['by_t']);
	$tmpl->assign('in_t', $lang['in_t']);
	$tmpl->assign('ascs_t', $lang['ascs_t']);
	$tmpl->assign('descs_t', $lang['descs_t']);
	$tmpl->assign('eachpage', $lang['eachpage']);
	$tmpl->assign('showbutt', $lang['showbutt']);
	$tmpl->register_function('getonlinestatus', 'getonlinestatus');
	
	if ($num) {
		$tmpl->assign('found', 1);
	}
	
	
	
	if($ok==1){
		$tmpl->assign("content", parsetrue("container/".container("userlist"), $lang['useroverview'], $tmpl->fetch("user/userlist.tpl")));
	}else{
		$OUT = $EOUT;
	}
	
}
?>