<?php
//=================================================================
// KOOBI R7 - CMS - PORTALSOFTWARE(c) DREAM4(r) 
// HTTP://WWW.DREAM4.DE
//=================================================================
// ACHTUNG!
// DIESER PROGRAMMCODE IST URHERRECHTLICH GESCHUETZT
// DIE URHEBERRECHTE LIEGEN BEI DEN JEWEILIGEN AUTOREN.
// AENDERUNGEN IN DIESER DATEI ERFOLGEN AUF EIGENE GEFAHR!
// ES IST NICHT GESTATTET, DEN COPYRIGHTHINWEIS ZU AENDERN ODER ZU
// ENTFERNEN. NUR WENN SIE EINE COPYRIGHTHINWEIS-ENTFERNUNG BESTELLT
// HABEN, DUERFEN SIE DIESEN ENTFERNEN.
//================================================================
// BEI FRAGEN WENDEN SIE SICH BITTE AN: KONTAKT@DREAM4.DE
//=================================================================
if(!defined('BASE_DIR')) exit;
if(!get_active('members'))
{
	notActive();
}

$sname = $GLOBALS['config_vars']['Forums_useroverview'];
$ok = 1;
$num = 1;
$z1 = '';
	$seename = '';
	
$limit = (isset($_REQUEST['pp']) && $_REQUEST['pp']!='') ? $_REQUEST['pp'] : '15'; 

if (!permission("showuserpage")) 
{
	koobi_message('Global_NoPermission', 'Global_NoPermission_t', HOME_PATH . '/index.php?p=showforums&amp;area=' . AREA);
} else {
	if (isset($_REQUEST['group']) && $_REQUEST['group'] != "") 
	{
		$z1 = "AND (ugroup='".$_REQUEST['group']."')";
		if ( $_REQUEST['group'] == "all" ) 
		{
			$z1 = "";
		}
	}
	
	if(isset($_REQUEST["ud"]) && $_REQUEST["ud"] == "ASC")
	{
		$ascdesc = "ASC";
		$GLOBALS['tmpl']->assign("ud1", "selected");
		
	} else {
		$_REQUEST["ud"] = "DESC";
		$ascdesc = "DESC";
		$GLOBALS['tmpl']->assign("ud2", "selected=\"selected\"");
	}
	
	if (isset($_REQUEST["selby"]) && $_REQUEST["selby"] == "username") 
	{
		$sortby = " ORDER BY Benutzername";
		$GLOBALS['tmpl']->assign("sel1", "selected=\"selected\"");
	} elseif (isset($_REQUEST["selby"]) && $_REQUEST["selby"] == "posts") 
	{
		$sortby = " ORDER BY Beitraege";
		$GLOBALS['tmpl']->assign("sel2", "selected=\"selected\"");
	} elseif (isset($_REQUEST["selby"]) && $_REQUEST["selby"] == "joindate") 
	{
		$sortby = " ORDER BY Regdatum";
		$GLOBALS['tmpl']->assign("sel3", "selected=\"selected\"");
	} else {
		$sortby = " ORDER BY Beitraege";
	}
	
	if (isset($_REQUEST["suname"]) && $_REQUEST["suname"] != "") 
	{
		$seename = " AND (Benutzername like '".$_REQUEST['suname']."%')";
		$z1 = "";
		$sortby = "";
		$ascdesc = "";
	}

	$sql2 = $db->Query("SELECT Id FROM ".PREFIX."_benutzer WHERE Aktiv='1'  AND Gruppe!='2' $z1 $seename $sortby $ascdesc");
	$num = $sql2->numrows();
	$seiten = ceil($num / $limit);
	$a = prepage() * $limit - $limit;
	
	$sql = $db->Query("SELECT *  FROM ".PREFIX."_benutzer WHERE Aktiv='1'  AND Gruppe!='2'  $z1 $sortby $seename $ascdesc  limit  $a,$limit");
	
	$table_data = array();
	$i = 2;
	while ($row = $sql->fetchrow()) 
	{
		// Beitraege aktualisieren
		$beitraege_obj = $GLOBALS['db']->RowQuery("SELECT COUNT(id) AS Beitraege FROM " . PREFIX . "_f_post WHERE uid = '" . $row->Id . "'");
		$GLOBALS['db']->RowQuery("UPDATE " . PREFIX . "_benutzer SET Beitraege = '" . $beitraege_obj->Beitraege . "' WHERE Id = '" . $row->Id . "'");
			
		$userskype = '';
		$useraim = '';
		$usericq  = '';
		$usercanpn = '';
		$usermail = '';
		$usermsn = '';
		
		$row->Icq_User   = ($row->icq != '') ? '<a href="javascript:void(0);" onclick="javascript:open_window(\'index.php?p=misc&amp;do=ICQ&amp;uid=' . $row->Id . '\',\'icq\',\'450\',\'490\',\'1\')"><img border="0" src="theme/'.$GLOBALS['theme'].'/images/forums/icq.png" alt="" /></a>' : "";
		$row->Pn_User   = ($row->Pnempfang == 1 && UGROUP != 2) ? "<a href=\"index.php?p=pn&amp;action=new&amp;to=".base64_encode($row->Benutzername)."\"><img border=\"0\" src=\"theme/".$GLOBALS['theme']."/images/forums/pn.png\" alt=\"\" /></a>" : '';
		$row->Email_User = ($row->Emailempfang == 1 && UGROUP != 2) ? '<a href="javascript:void(0);" onclick="javascript:open_window(\'index.php?p=misc&amp;do=EMAIL&amp;uid=' . $row->Id . '\',\'Email\',\'450\',\'590\',\'1\');"><img border="0" src="theme/'.$GLOBALS['theme'].'/images/forums/mail.png" alt="" /></a>' : '';
		$row->Skype_User = ($row->skype != '') ? '<a href="javascript:void(0);" onclick="javascript:open_window(\'index.php?p=misc&amp;do=SKYPE&amp;uid=' . $row->Id . '\',\'Skype\',\'450\',\'490\',\'1\')"><img border="0" src="theme/'.$GLOBALS['theme'].'/images/forums/skype.png" alt="Call Me!" /></a>' : "";
		$row->Webseite   = (starts_with('www',$row->Webseite)) ? 'http://' . $row->Webseite : $row->Webseite;

		
		$usergroup = fetchgroupname($row->Gruppe);
		
		$userlink = "index.php?p=user&amp;id=".$row->Id."&amp;area=" . AREA;
		$entry_array = array(
		'avatar' => getAvatar($row->Gruppe,$row->Avatar,$row->Avatar_Default),
		'Skype_User'	=> $row->Skype_User,
		'name'	=> $row->Benutzername,
		'usergroup'	=> $usergroup,
		'userlink' => $userlink,
		'user_aim' => $useraim,
		'user_msn' => $row->msn,
		'Icq_User' => $row->Icq_User,
		'posts' => $row->Beitraege,
		'Pn_User' => $row->Pn_User,
		'Email_User' => $row->Email_User,
		'regtime' => $row->Regdatum,
		'gruppe' => $row->Gruppe,
		'team' => $row->Team,
		'teamName' => $GLOBALS['settings']['Seitenname'] . $GLOBALS['config_vars']['WebTeam'],
		'rank' => getRank($row->Beitraege),
		'Webseite' => $row->Webseite,
		'Profil_public' => $row->Profil_public
		);
		unset($userskype,$useraim,$usericq,$usercanpn,$usermail,$userlink,$usergroup);
		$i++;
		array_push($table_data, $entry_array);
	}
	$sql->close();
	
	$groupdata = array();
	$sqlg = $db->Query("SELECT * FROM ".PREFIX."_benutzer_gruppen WHERE Id!='2'");
	
	while ($rowg = $sqlg->fetchrow())
	{
		$sel = (isset($_REQUEST['group']) && $_REQUEST['group'] == $rowg->Id) ? 'selected' : '';
		
		array_push($groupdata, array(
		'groupname_sel' => $rowg->Name,
		'group_id' => $rowg->Id,
		'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>';
	}
	
	$group = (isset($_REQUEST['group']) && $_REQUEST['group'] != '') ? "&amp;group=$_REQUEST[group]" : "";
	$rud = (isset($_REQUEST['ud']) && $_REQUEST['ud'] != '') ? "&amp;ud=$_REQUEST[ud]" : "";
	$selby = (isset($_REQUEST['selby']) && $_REQUEST['selby'] != '') ? "&amp;selby=$_REQUEST[selby]" : "";
	
	$nav = pagenav($seiten, $GLOBALS['config_vars']['aktpos'], " <a class=\"page_navigation\" href=\"index.php?p=members{$group}{$rud}{$selby}&amp;pp=".$limit."&amp;page={s}\">{t}</a> ");
	$GLOBALS['tmpl']->assign('pagenav', $nav);
	$GLOBALS['tmpl']->assign('pp_l', $pp_l);
	$GLOBALS['tmpl']->assign('table_data', $table_data);
	$GLOBALS['tmpl']->assign('groupdata', $groupdata);
	$GLOBALS['tmpl']->assign('posts_t_s', $GLOBALS['config_vars']['Forums_Postings_2']);
	$GLOBALS['tmpl']->assign('show', $GLOBALS['config_vars']['show']);
	$GLOBALS['tmpl']->assign('by_t', $GLOBALS['config_vars']['by_t']);
	$GLOBALS['tmpl']->assign('in_t', $GLOBALS['config_vars']['in_t']);
	$GLOBALS['tmpl']->assign('ascs_t', $GLOBALS['config_vars']['ascs_t']);
	$GLOBALS['tmpl']->assign('descs_t', $GLOBALS['config_vars']['descs_t']);
	$GLOBALS['tmpl']->assign('eachpage', $GLOBALS['config_vars']['eachpage']);
	$GLOBALS['tmpl']->assign('Forums_ShowButton', $GLOBALS['config_vars']['Forums_ShowButton']);
	$GLOBALS['tmpl']->assign('SearchPop', popSearch());
	
	
	if ($num) 
	{
		$GLOBALS['tmpl']->assign('found', 1);
	}
	
	$GLOBALS['tmpl']->assign('pagetitle_html', $GLOBALS['config_vars']['Forums_useroverview']);
	$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/forums/userlist.tpl')); 
}
?>