<?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_members = \"".gettemplate("title_members")."\";");
echo $title_members;

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='<b>'.$ds[name].'</b></a>';
  if($ds[icon]) $icon='<img src="images/squadicons/'.$ds[icon].'" border="0">';
	else $icon='';
	$info=$ds[info];
  $squadID=$ds[squadID];
  $backlink='&raquo; <a href="index.php?site=members"><b>back to member 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 ("\$members_head_head = \"".gettemplate("members_head_head")."\";");
    echo $members_head_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 (file_exists("images/userpics/".$profilid.".jpg"))
		   {
		   $userpic = $profilid.".jpg";
		   $pic_info = $dm[nickname]." userpicture";
		   }
		elseif (file_exists("images/userpics/".$profilid.".gif"))
		   {
		   $userpic = $profilid.".gif";
		   $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 ("\$membes_details_content = \"".gettemplate("membes_details_content")."\";");
        echo $membes_details_content;
		$i++;
    }
	eval ("\$membes_details_foot = \"".gettemplate("membes_details_foot")."\";");
    echo $membes_details_foot;
    }
}

else {
if($_POST['squadID']) {
 $onesquadonly = 'WHERE squadID="'.$_POST['squadID'].'"';
 $visible="block";
} elseif($_GET['squadID']) {
 $onesquadonly = 'WHERE squadID="'.$_GET['squadID'].'"';
 $visible="block";
} else $visible="none";

$ergebnis=safe_query("SELECT * FROM ".PREFIX."squads ".$onesquadonly." 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='<a href="index.php?site=members&action=show&squadID='.$ds[squadID].'"><b>'.$ds[name].'</b></a>';
	if($ds[icon]) $icon='<img src="images/squadicons/'.$ds[icon].'" border="0">';
	else $icon='';
	  $info=$ds[info];
	  $squadID=$ds[squadID];
    $details='&raquo; <a href="index.php?site=members&action=show&squadID='.$ds[squadID].'"><b>show details</b></a>';
	  $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 ("\$members_head_head = \"".gettemplate("members_head_head")."\";");
   	echo $members_head_head;


	$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 ("\$members_head = \"".gettemplate("members_head")."\";");
    echo $members_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 (file_exists("images/userpics/".$profilid.".jpg"))
		   {
		   $userpic = $profilid.".jpg";
		   $pic_info = $dm[nickname]." userpicture";
		   }
		elseif (file_exists("images/userpics/".$profilid.".gif"))
		   {
		   $userpic = $profilid.".gif";
		   $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 ("\$members_content = \"".gettemplate("members_content")."\";");
        echo $members_content;
		$i++;

	}

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

}
  $ergebnis=safe_query("SELECT squadID, name FROM ".PREFIX."squads ORDER BY sort");
  unset($squadlist);
  $squadlist = '<form name="members" action="index.php?site=members" method="post">Show only:  <select name="squadID">';
  while($ds=mysql_fetch_array($ergebnis)) {
   $squadlist .= '<option value="'.$ds[squadID].'">'.$ds[name].'</option>';
  }
  $squadlist .= '</select> <input type="submit" value="show"></form>';

echo '<table border="0" width="100%">
       <tr>
        <td align="right" width="100%">'.$squadlist.'</td>
       </tr>
      </table>';
}
?>