<?php 
#   Copyright by: Manuel
#   Support: www.ilch.de
#   © searchgame.de & .org By Norman, all rights reserved. 

defined ('main') or die ( 'no direct access' );


$title = $allgAr['title'].' | Forum';
$hmenu = $extented_forum_menu.'Forum'.$extented_forum_menu_sufix;
$design = new design ( $title , $hmenu, 1);
$design->header();

if ($menu->get(1) == 'markallasread') {
  user_markallasread ();
}


$tpl = new tpl ( 'forum/showforum' );
$tpl->out (0);

$category_array = array();
$forum_array = array();

$q = "SELECT
  a.id, a.cid, a.name, a.besch,
  a.topics, a.posts, b.name as topic,
  c.id as pid, c.tid, b.rep, c.erst, c.time,
  a.cid, k.name as cname
FROM prefix_forums a
  LEFT JOIN prefix_forumcats k ON k.id = a.cid
  LEFT JOIN prefix_posts c ON a.last_post_id = c.id
  LEFT JOIN prefix_topics b ON c.tid = b.id
	
  LEFT JOIN prefix_groupusers vg ON vg.uid = ".$_SESSION['authid']." AND vg.gid = a.view
  LEFT JOIN prefix_groupusers rg ON rg.uid = ".$_SESSION['authid']." AND rg.gid = a.reply
  LEFT JOIN prefix_groupusers sg ON sg.uid = ".$_SESSION['authid']." AND sg.gid = a.start
	
WHERE ((".$_SESSION['authright']." <= a.view AND a.view < 1) 
   OR (".$_SESSION['authright']." <= a.reply AND a.reply < 1)
   OR (".$_SESSION['authright']." <= a.start AND a.start < 1)
	 OR vg.fid IS NOT NULL
	 OR rg.fid IS NOT NULL
	 OR sg.fid IS NOT NULL
	 OR -9 = ".$_SESSION['authright'].")
	 AND k.cid = 0
ORDER BY k.pos, a.pos";
$erg1 = db_query($q);
$xcid = 0;
while ($r = db_fetch_assoc($erg1) ) {
  
  $r['topicl'] = $r['topic'];
  $r['topic']  = html_enc_substr($r['topic'],0,23);
  $r['ORD']    = forum_get_ordner($r['time'],$r['id']);
  $r['mods']   = getmods($r['id']);
  $r['datum']  = date('d.m.y - H:i', $r['time']);
  $r['page']   = ceil ( ($r['rep']+1)  / $allgAr['Fpanz'] );
  $tpl->set_ar ($r);
  
  if ($r['cid'] <> $xcid) {
    $tpl->out(1);
    //Unterkategorien
    $sql = db_query("SELECT DISTINCT a.name as cname, a.id as cid FROM `prefix_forumcats` a LEFT JOIN `prefix_forums` b ON a.id = b.cid WHERE a.cid = {$r['cid']} AND a.id = b.cid ORDER BY a.pos, a.name");
    while ($ucat = db_fetch_assoc($sql)) {
      $tpl->set_ar_out($ucat,2);
    }
    //Unterkategorien - Ende
    $xcid = $r['cid'];
  }
  $tpl->set_ar_out($r,3);
}
function allianz(){
	$allianz = '';
	$allyErg = db_query("SELECT * FROM `prefix_partners` ORDER BY RAND() LIMIT  0,8");
		while($allyRow = db_fetch_object($allyErg)) {
		      $allianz .= '<a href="'.$allyRow->link.'" target="_blank"><img src="'.$allyRow->banner.'" alt="'.$allyRow->name.'" border="0"></a>&nbsp;';
  }
  return($allianz);
}
function newewstuser(){ 
$lastmember = db_query ("SELECT a.id, a.name, a.regist, a.llogin, b.bez, a.spezrank FROM `prefix_user` a LEFT JOIN prefix_ranks b ON b.id = a.spezrank  WHERE a.llogin > '". $dif."' ORDER BY regist DESC limit 1");
while($mem = db_fetch_assoc($lastmember))
{
$user = 'Unser neuestes Mitglied heißt: <a class="'.$mem['bez'].'" href="index.php?user-details-'.$mem['id'].'">'.$mem['name'].'</a>';
}
return ($user);
}
function user_online_today_liste(){ 
    $OnListe = ''; 
  $dif = mktime(0,0,0,date('m'),date('d'),date('Y'));
    $erg = db_query("SELECT a.id, a.name, a.llogin, b.bez, a.spezrank FROM `prefix_user` a LEFT JOIN prefix_ranks b ON b.id = a.spezrank  WHERE a.llogin > '". $dif."' ORDER BY llogin");
    while($row = db_fetch_object($erg)) {
      if ( $row->spezrank <> 0 ) {
      $OnListe .= '<a class="'.$row->bez.'" title="'.$row->bez.'" href="index.php?user-details-'.$row->id.'">'.$row->name.'</a>, ';
    } else {
      $OnListe .= '<a href="index.php?user-details-'.$row->id.'">'.$row->name.'</a>, ';
      }
  }
    $OnListe = substr($OnListe,0,strlen($OnListe) - 3);
  return ($OnListe);
}
# statistic #
$ges_online_user = ges_online();
$heute = date ('Y-m-d');
$stats_array = array (
  'privmsgpopup' => check_for_pm_popup (),
  'topics' => db_result(db_query("SELECT COUNT(ID) FROM `prefix_topics`"),0),
  'posts' => db_result(db_query("SELECT COUNT(ID) FROM `prefix_posts`"),0),
  'users' => db_result(db_query("SELECT COUNT(ID) FROM `prefix_user`"),0),
  'istsind' => ( $ges_online_user > 1 ? 'sind' : 'ist' ),
  'gesonline' => $ges_online_user,
  'heute' => @db_result(db_query("SELECT count FROM prefix_counter WHERE date = '".$heute."'"),0),
  'gestern' => @db_result(db_query('SELECT count FROM prefix_counter WHERE date < "'.$heute.'" ORDER BY date DESC LIMIT 1'),0),
  'gesamt' =>  db_result(db_query("SELECT SUM(count) FROM prefix_counter"),0),
  'gastonline' => ges_gast_online(),
  'useronline' => ges_user_online(),
  'allianz' => allianz(),
  'userliste' => user_online_liste(),
  'userliste_today' => user_online_today_liste(),
  'newewst_user' => newewstuser(),
);

$tpl->set_ar_out($stats_array,4);

$design->footer();
?>