<?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                                                   #
#                                                                        #
 ########################################################################
*/

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

if($_GET['action']=="show") {
if($_GET['squadID']) {
 $getsquad = 'WHERE squadID="'.$_GET['squadID'].'"';
}

$ergebnis=safe_query("SELECT * FROM ".PREFIX."squads ".$getsquad." ORDER BY sort");
while($ds=mysql_fetch_array($ergebnis)) {

  $anzmembers=mysql_num_rows(safe_query("SELECT sqmID FROM ".PREFIX."squads_members WHERE squadID='".$ds[squadID]."'"));
  $name='&not; <b>'.$ds[name].'</b></a>';
  $squadID=$ds[squadID];
  $backlink='&raquo; <a href="index.php?site=squads"><b>back to squad overview</b></a>';
  $results='';
  $awards='';
	$challenge='';
  
  $border=BORDER;

	if($ds[gamesquad]) {
	  $results='[ <a href="index.php?site=clanwars&action=showonly&id='.$squadID.'&sort=date&only=squad">results</a> | ';
    $awards='<a href="index.php?site=awards&action=showsquad&squadID='.$squadID.'&page=1">awards</a> | ';
		$challenge='<a href="index.php?site=challenge">challenge</a> ]';
	}
  
	$member=safe_query("SELECT * FROM ".PREFIX."squads_members s, ".PREFIX."user u WHERE s.squadID='$ds[squadID]' AND s.userID = u.userID ORDER BY sort");
    eval ("\$squads_head = \"".gettemplate("squads_head")."\";");
    echo $squads_head;

	$i=1;
 	while($dm=mysql_fetch_array($member)) {
	  
	  if($i%2) {
			$bg1=BG_1;
			$bg2=BG_2;
		}
		else {
			$bg1=BG_3;
			$bg2=BG_4;
		}
		
		$country = '[flag]'.$dm[country].'[/flag]';
		$country = flags($country);
		$nickname = '<a href="index.php?site=profile&id='.$dm[userID].'"><b>'.$dm[nickname].'</b></a>';
		$nicknamee = $dm[nickname];
		$profilid = $dm[userID];
    
    if($dm[userdescription]) $userdescription=$dm[userdescription];
    else $userdescription='no description available';
		
		if ($dm['userpic']!="" AND file_exists("images/userpics/".$dm['userpic']))
		   {
		   $userpic = $dm['userpic'];
		   $pic_info = $dm[nickname]." userpicture";
		   }
		else
		   {
		   $userpic = "nouserpic.gif";
		   $pic_info = "no userpic available!";
		   }
		   
		$icq = $dm[icq];
		$email = '<a href="mailto:'.$dm[email].'"><img src="images/icons/email.gif" border="0" width="15" height="11" alt="email"></a>';
		$emaill = $dm[email];
			
		$pm = '';
		$buddy = '';
		if ($loggedin && $dm[userID] != $userID)
			{
			$pm='<a href="index.php?site=messenger&action=touser&touser='.$dm[userID].'"><img src="images/icons/pm.gif" border="0" width="12" height="13" alt="messenger"></a>';
			
			if (isignored($userID, $dm[userID])) $buddy='<a href="buddys.php?action=readd&id='.$dm[userID].'&userID='.$userID.'"><img src="images/icons/buddy_readd.gif" width="16" height="16" border="0" alt="back to buddy-list"></a>';
			elseif(isbuddy($userID, $dm[userID])) $buddy='<a href="buddys.php?action=ignore&id='.$dm[userID].'&userID='.$userID.'"><img src="images/icons/buddy_ignore.gif" width="16" height="16" border="0" alt="ignore user"></a>';
			elseif($userID==$dm[userID]) $buddy="";
			else $buddy='<a href="buddys.php?action=add&id='.$dm[userID].'&userID='.$userID.'"><img src="images/icons/buddy_add.gif" width="16" height="16" border="0" alt="add to buddylist"></a>';
			}
			
		if (isonline($dm[userID])=="offline") $statuspic='<img src="images/icons/offline.gif" width="7" height="7" alt="offline">';
		else $statuspic='<img src="images/icons/online.gif" width="7" height="7" alt="online">'; 
		
		$position=$dm[position];
		$firstname=$dm[firstname];
		$lastname=$dm[lastname];
		$town=$dm[town];
		if($dm[activity]) $activity='<font color="'.$wincolor.'">active</font>';
		else $activity='<font color="'.$loosecolor.'">inactive</font>';
				
		eval ("\$squads_content = \"".gettemplate("squads_content")."\";");
        echo $squads_content; 
		$i++;
    }
	eval ("\$squads_foot = \"".gettemplate("squads_foot")."\";");
    echo $squads_foot;    
    }
}

else {
if($_GET['squadID']) {
 $getsquad = 'WHERE squadID="'.$_GET['squadID'].'"';
}

$ergebnis=safe_query("SELECT * FROM ".PREFIX."squads ".$getsquad." ORDER BY sort");
while($ds=mysql_fetch_array($ergebnis)) {
    $anzmembers=mysql_num_rows(safe_query("SELECT sqmID FROM ".PREFIX."squads_members WHERE squadID='".$ds[squadID]."'"));
    $name='&not; <a href="index.php?site=squads&action=show&squadID='.$ds[squadID].'"><b>'.$ds[name].'</b></a>';
	if($ds[icon]) $icon='<a href="index.php?site=squads&action=show&squadID='.$ds[squadID].'"><img src="images/squadicons/'.$ds[icon].'" border="0"></a>';
	else $icon='';
	$info=$ds[info];
  $details='&raquo; <a href="index.php?site=squads&action=show&squadID='.$ds[squadID].'"><b>show details</b></a>';
	$squadID=$ds[squadID];
	$results='';
  $awards='';
	$challenge='';
		
	if($ds[gamesquad]) {
	  $results='[ <a href="index.php?site=clanwars&action=showonly&id='.$squadID.'&sort=date&only=squad">results</a> | ';
    $awards='<a href="index.php?site=awards&action=showsquad&squadID='.$squadID.'&page=1">awards</a> | ';
		$challenge='<a href="index.php?site=challenge">challenge</a> ]';
	}
			
	$bgcat=BGCAT;
	eval ("\$squads = \"".gettemplate("squads")."\";");
   	echo $squads;
  }
}
?>