<?php

/*
// +--------------------------------------------------------------------------+
// | Teams anzeigen und verwalten                                             |
// | by truenoir                                                              |
// +--------------------------------------------------------------------------+
// | Obige Zeilen dürfen nicht entfernt werden!    Do not remove above lines! |
// +--------------------------------------------------------------------------+
*/

require "include/bittorrent.php";
dbconn();
loggedinorreturn();

$act=$_GET["act"];
$admin=get_user_class()>=UC_ADMINISTRATOR;
$mod=get_user_class()>=UC_MODERATOR;
$types=array("support","crew");
$res=mysql_query("select * from teams order by teams.sort");
$teams=mysql_num_rows($res);
$_a=0;
$dt = time() - 180;
$dt = sqlesc(get_date_time($dt)); 
stdhead("Tracker Groups");
?>


<table cellpadding="4" cellspacing="1" border="0" style="width:600px" class="tableinborder">
<tr class="tabletitle" width="100%">
<td colspan="10" width="100%"><span class="smallfont"><center>
<b>.:Tracker Groups:.<b>
</center></span></td></tr><tr><td width="100%" class="tablea">


<?php
while($r=mysql_fetch_assoc($res))
{
  $leaderid=0;
  if($_a++>0)
    echo "<br><br>\n";
  echo "<table width='450'  border='0' cellspacing='1' cellpadding='3' align='center' class='tableinborder'>\n";
  $head="<tr align=center><td colspan=3 class=tablecat>".($admin?"<a href=\"taketeams.php?act=delete&team=$r[id]\"><img src=\"" . $GLOBALS["PIC_BASE_URL"] . "editdelete.png\" border=0 alt=\"Team l&ouml;schen\" title=\"Team l&ouml;schen\"></a>&nbsp;":"").($r[typ]=="crew"?"<a href=\"browse.php?team=$r[id]\">":"")."<b>$r[name]-".ucfirst($r[typ])."</b>".($r[typ]=="crew"?"</a>":"")." ".($_a>1&&$admin?"<a href=\"taketeams.php?act=moveup&team=$r[id]&sort=$r[sort]\"><img src=\"" . $GLOBALS["PIC_BASE_URL"] . "up.gif\" border=0 alt=\"Team nach oben schieben\" title=\"Team nach oben schieben\"></a>":"")." ".($_a<$teams&&$admin?"<a href=\"taketeams.php?act=movedown&team=$r[id]&sort=$r[sort]\"><img src=\"" . $GLOBALS["PIC_BASE_URL"] . "down.gif\" border=0 alt=\"Team nach unten schieben\" title=\"Team nach unten schieben\"></a>":"")." ".($admin?"<a href=\"teams.php?act=edit&team=$r[id]\"><img src=\"" . $GLOBALS["PIC_BASE_URL"] . "edit.png\" border=0 alt=\"Team bearbeiten\" title=\"Team bearbeiten\"></a>":"")."</td></tr>\n";
  if($r[banner])
    $head.="<tr align=center><td colspan=3 class=tableb><div align=\"center\"><img src=\"$r[banner]\" border=0 /></div></td></tr>\n";
  $res2=mysql_query("select users.*, teammembers.leader from users,teammembers where teammembers.userid=users.id and teammembers.teamid=$r[id] order by teammembers.leader desc, users.username");
  if(mysql_num_rows($res2)>0)
  {
    ?>
    <colgroup>
     <col width="125">
     <col width="25">
     <col width="35">
    </colgroup>
    <?
    echo $head;
    while($r2=mysql_fetch_assoc($res2))
    {
      echo "<tr><td class=tableb><a href=\"userdetails.php?id=$r2[id]\"><span class=".get_class_color($r2['class']).">$r2[username]</span></a> ";
      if($r2["leader"]=="yes") 
      {
        echo "(Leader)";
        $leaderid=$r2["id"];
      }
      else
        if($mod||$leaderid==$CURUSER["id"])
        {
          echo "<a href=\"taketeams.php?act=leader&team=$r[id]&user=$r2[id]\">[Neuer Leader]</a>";
        }
      if($mod||($leaderid==$CURUSER["id"]&&$r2["leader"]!="yes")) 
        echo " <a href=\"taketeams.php?act=delmember&team=$r[id]&user=$r2[id]\"><img src=\"" . $GLOBALS["PIC_BASE_URL"] . "editdelete.png\" border=0 alt=\"Member l&ouml;schen\" title=\"Member l&ouml;schen\"></a>";
      echo "</td><td class=tableb>".("'" . $r2['last_access'] . "'" > $dt?"<img src=\"" . $GLOBALS["PIC_BASE_URL"] . "button_online2.gif\" border=0 alt=\"online\">":"<img src=\"" . $GLOBALS["PIC_BASE_URL"] . "button_offline2.gif\" border=0 alt=\"offline\">") . "</td><td class=\"tablea\"><a href=\"messages.php?action=send&amp;receiver=$r2[id]\"><img src=\"" . $GLOBALS["PIC_BASE_URL"] . "button_pm2.gif\" border=0></a></td></tr>\n";
    }
  }
  else
    echo "$head\n<tr><td colspan=3 class=tableb>Keine Mitglieder vorhanden</td></tr>\n";
  echo "</table>";
}
?>
<?php
if (get_user_class()>=UC_MODERATOR) {
  if($act=="edit")
  {
    $team=0+$_GET["team"];
    $data=mysql_fetch_assoc(mysql_query("select * from teams where id=$team"));
  }
?>
<br><br>
<form action="taketeams.php" method="post">
<input type=hidden name=act value=<?=($act=="edit"?"edit":"neu")?> />
<input type=hidden name="id" value=<?=$team?> />
<table width="450"  border="0" cellspacing="1" cellpadding="3" align="center" class="tableinborder">
<tr align="center"><td colspan="2" class=tablecat><b>Group <?=($act=="edit"?"bearbeiten":"erstellen")?></b></td></tr>
<tr><td class=tableb>Name:</td><td class=tablea><input type=text name=teamname value="<?=$data["name"]?>" /></td></tr>
<tr><td class=tableb>Banner:</td><td class=tablea><input type=text name=banner value="<?=$data["banner"]?>" /></td></tr>
<tr><td class=tableb>Typ:</td><td class=tablea><select name=typ><?php
for($i=0;$i<count($types);$i++) echo "<option value=\"$types[$i]\"".($data[typ]==$types[$i]?" selected":"").">".ucfirst($types[$i])."</option>";
?></select></td></tr>
<tr><td class=tableb>Suffix (Crew):</td><td class=tablea><input type=text name=suffix value="<?=$data["suffix"]?>" /></td></tr>
<tr><td colspan=2 class=tableb><div align="center"><input type=submit class=btn style="height:25px" value=<?=($act=="edit"?"&Auml;nden":"Anlegen")?> /></div></td></tr>
</table>
</td></tr></table>
</form>
<?php
}

stdfoot();
?>