<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

if($userID && !isset($_GET['userID']) && !isset($_POST['userID'])) {

eval ("\$title_loginoverview = \"".gettemplate("title_loginoverview")."\";");
echo $title_loginoverview;

$pagebg=PAGEBG;
$border=BORDER;
$bghead=BGHEAD;
$bgcat=BGCAT;

$ds=mysql_fetch_array(safe_query("SELECT registerdate FROM `".PREFIX."user` WHERE userID='$userID'"));
$username='<a href="index.php?site=profile&id='.$userID.'">'.getnickname($userID).'</a>';
$lastlogin = date('d.m.Y, H:i',$_SESSION['ws_lastlogin']);
$registerdate = date('d.m.Y, H:i',$ds[registerdate]);

//messages?
$newmessages = getnewmessages($userID);
if($newmessages==1) $newmessages='There is one new message.';
elseif($newmessages>1) $newmessages='There are '.$newmessages.' new messages.';
else $newmessages='No new messages.';

//boardposts?

$posts=safe_query("SELECT p.topicID, p.date, p.message, t.topic FROM `".PREFIX."forum_posts` AS p, `".PREFIX."forum_topics` AS t WHERE p.date>".$_SESSION['ws_lastlogin']." AND p.topicID = t.topicID AND t.intern<=".isinternboarduser($userID));
$topics=safe_query("SELECT * FROM ".PREFIX."forum_topics WHERE intern<=".isinternboarduser($userID)." AND date>".$_SESSION['ws_lastlogin']);

$new_posts=mysql_num_rows($posts);
$new_topics=mysql_num_rows($topics);

//new topics

if(mysql_num_rows($topics)) {
    $n=1;
	while($db=mysql_fetch_array($topics)) {
		$n%2 ? $bgcolor=BG_1 : $bgcolor=BG_2;
    $posttime=date("d.m.y h:i",$db[date]);

		$topiclist.='<tr bgcolor="'.$bgcolor.'">
                       <td>
					     <table width="100%" cellpadding="1" cellspacing="1">
               <tr>
						     <td colspan="3"><a href="index.php?site=forum_topic&topic='.$db[topicID].'">'.$posttime.'<br><b>'.$db[topic].'</b></a><br><i>'.$db[views].' views - '.$db[replys].' replys</td>
						   </tr>
               </table></td></tr>';
		$n++;
	}
}
else $topiclist='<tr>
                   <td bgcolor="'.BG_1.'">no new topics</td>
                 </tr>';

//new posts

if(mysql_num_rows($posts)) {
    $n=1;
	while($db=mysql_fetch_array($posts)) {
		$n%2 ? $bgcolor1=BG_1 : $bgcolor1=BG_2;
		$n%2 ? $bgcolor2=BG_3 : $bgcolor2=BG_4;
    $posttime=date("d.m.y h:i",$db[date]);
    if(strlen($db['message']) > 100) $message=substr($db['message'],0,90+strpos(substr($db['message'],90,strlen($db['message']))," "))."...";
    else $message = $db['message'];

		$postlist.='<tr bgcolor="'.$bgcolor1.'">
                       <td>
					     <table width="100%" cellpadding="1" cellspacing="1">
               <tr>
						     <td colspan="3"><a href="index.php?site=forum_topic&topic='.$db[topicID].'">'.$posttime.' <br><b>'.$db[topic].'</b></a></td>
						   </tr>
						   <tr></tr>
						   <tr>
                <td width="1%">&nbsp;</td>
                <td bgcolor="'.$bgcolor2.'"><div style="overflow:hidden;">'.clearfromtags($message).'</div></td>
                <td width="1%">&nbsp;</td>

               </tr>
               </table><br></td></tr>';
		$n++;
	}
}
else $postlist='<tr>
                   <td bgcolor="'.BG_1.'" valign="top">no new posts</td>
                 </tr>';

//clanmember/admin/referer

if(isclanmember($userID)) $cashboxpic = '<td><a href="index.php?site=cash_box"><img src="images/icons/cashbox.jpg" border="0"></a></td><td width="10"></td>'; else $cashboxpic = '<td></td><td></td>';
if(isanyadmin($userID)) $admincenterpic = '<td><a href="admin/admincenter.php" target="about:blank"><img src="images/icons/admincenter.jpg" border="0"></a></td><td width="10"></td>'; else $admincenterpic = '<td></td><td></td>';
if(isset($_SESSION['referer'])) { $referer_uri = '<tr><td bgcolor="'.$bgcat.'"><a href="'.$_SESSION['referer'].'"><b>Back to last page</b></a></td></tr>'; unset($_SESSION['referer']); }

//upcoming

if(isclanmember($userID)) {

$clanwars .= '<tr>
     <td colspan="3"><img src="images/icons/upcoming_clanwars.gif" border"0"> <b>Upcoming clanwars</b><br>&nbsp;</td>
    </tr>';

$squads=safe_query("SELECT squadID FROM `".PREFIX."squads_members` WHERE userID='".$userID."'");
while($squad=mysql_fetch_array($squads)) {
	
 if(isgamesquad($squad[squadID])) {

 $dn=mysql_fetch_array(safe_query("SELECT name FROM `".PREFIX."squads` WHERE squadID='".$squad[squadID]."' AND gamesquad='1'"));
 $clanwars .= '<tr><td><i>Squad: '.$dn[name].'</i></td></tr><tr><td align="center">';
 $n = 1;
 $ergebnis=safe_query("SELECT * FROM `".PREFIX."upcoming` WHERE type='c' AND squad='".$squad[squadID]."' AND date>".time()." ORDER by date");
 $anz = mysql_num_rows($ergebnis);
 if($anz) {
  $clanwars .= '<table border="0" width="97%"><tr><td width="20%">Date</td><td width="20%">against</td><td>Announcement</td><td width="10%">announce</td></tr>';
  while($ds=mysql_fetch_array($ergebnis)) {
			if($n%2) {
				$bg1=BG_3;
				$bg2=BG_4;
				$bg3=BG_1;
				$bg4=BG_2;
			}
			else {
				$bg1=BG_2;
				$bg2=BG_3;
				$bg3=BG_4;
				$bg4=BG_1;
			}
			$date=date("d.m.y", $ds[date]);
			
			$anmeldung=safe_query("SELECT * FROM ".PREFIX."upcoming_announce WHERE upID='$ds[upID]' ");
        if(mysql_num_rows($anmeldung)) {
          $i=1;
          unset($players);
					while ($da = mysql_fetch_array($anmeldung)) {
          	if ($da[status] == "y") $fontcolor = $wincolor;
			    	elseif ($da[status] == "n") $fontcolor = $loosecolor;
			    	else $fontcolor = $drawcolor;

	        	if($i>1) $players.=', <a href="index.php?site=profile&id='.$da[userID].'"><font color="'.$fontcolor.'">'.getnickname($da[userID]).'</font></a>';
						else $players.='<a href="index.php?site=profile&id='.$da[userID].'"><font color="'.$fontcolor.'">'.getnickname($da[userID]).'</font></a>';
						$i++;
		    	}
	    	}	else $players='no players announced';
	    	
	    $tag = date("d", $ds[date]);
	    $monat = date("m", $ds[date]);
	    $yahr = date("Y", $ds[date]);

      $clanwars .= '<tr><td bgcolor="'.$bg1.'">'.$date.'</td><td bgcolor="'.$bg2.'"><a href="'.$ds[opphp].'" target="about:blank">'.$ds[opptag].' / '.$ds[opponent].'</a></td><td bgcolor="'.$bg3.'">'.$players.'</td><td bgcolor="'.$bg4.'"><a href="index.php?site=calendar&action=announce&upID='.$ds[upID].'&tag='.$tag.'&month='.$monat.'&year='.$yahr.'">click</a></td></tr>';
      $n++;

		}
   $clanwars .= '</table></td></tr>';
  } else $clanwars .= 'no entries</td></tr>';
 }
 }
 $clanwars.='<tr><td>&nbsp;</td></tr>';
}

unset($events);
$ergebnis=safe_query("SELECT * FROM `".PREFIX."upcoming` WHERE type='d' AND date>".time()." ORDER by date");
$anz = mysql_num_rows($ergebnis);
if($anz) {
  while($ds=mysql_fetch_array($ergebnis)) {
			if($n%2) {
				$bg1=BG_3;
				$bg2=BG_4;
				$bg3=BG_1;
				$bg4=BG_2;
			}
			else {
				$bg1=BG_2;
				$bg2=BG_3;
				$bg3=BG_4;
				$bg4=BG_1;
			}
			
			$events.='<tr><td bgcolor="'.$bg1.'">'.$ds[title].'</td><td bgcolor="'.$bg2.'">'.date('d.m.y, h:i', $ds[date]).'</td><td bgcolor="'.$bg3.'">'.date('d.m.y, h:i', $ds[enddate]).'</td><td bgcolor="'.$bg4.'">'.$ds[location].'</td><td bgcolor="'.$bg1.'"><a href="index.php?site=calendar&tag='.date('d',$ds[date]).'&month='.date('m',$ds[date]).'&year='.date('Y',$ds[date]).'">click</a></td></tr>';
			
	}
} else $events='<tr><td colspan="5" bgcolor="'.$bg1.'"><i>No events</i></td></tr>';




$bg1=BG_1;
$bg2=BG_2;
$bg3=BG_3;
$bg4=BG_4;

 eval ("\$loginoverview = \"".gettemplate("loginoverview")."\";");
 echo $loginoverview;
} else echo'You have to be logged in to view the login overview!<br><br>

			  &#8226; <a href="index.php?site=register">register now</a><br>
			  &#8226; <a href="index.php?site=login">log in</a>';

?>
