<?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(!isuseradmin($userID) OR substr(basename($_SERVER[REQUEST_URI]),0,15) != "admincenter.php") die('Sie haben keine Zugangsberechtigung zum Admincenter.');
// Sortierung

if($_POST['sortieren']) {
	$sort = $_POST['sort'];
	if(is_array($sort)) {
		foreach($sort as $sortstring) {
	    	$sorter=explode("-", $sortstring);
			safe_query("UPDATE ".PREFIX."squads_members SET sort='$sorter[1]' WHERE sqmID='$sorter[0]' ");
		}
	}
}
	
// Member löschen
if($_GET['delete']) {
	$id = $_GET['id'];
	$squadID = $_GET['squadID'];
	$squads=mysql_num_rows(safe_query("SELECT userID FROM ".PREFIX."squads_members WHERE userID='$id'"));
	if($squads<2 AND !issuperadmin($id)) safe_query("DELETE FROM ".PREFIX."user_groups WHERE userID='$id'");
	
	safe_query("DELETE FROM ".PREFIX."squads_members WHERE userID='$id' AND squadID='$squadID'");
}

if($_POST['saveedit']) {
  $id = $_POST['id'];
  $newsadmin = $_POST['newsadmin'];
  $pollsadmin = $_POST['pollsadmin'];
  $feedbackadmin = $_POST['feedbackadmin'];
  $useradmin = $_POST['useradmin'];
  $cwadmin = $_POST['cwadmin'];
  $boardadmin = $_POST['boardadmin'];
  $moderator = $_POST['moderator'];
  $intern = $_POST['intern'];
  $pageadmin = $_POST['pageadmin'];
  $fileadmin = $_POST['fileadmin'];
  $cashadmin = $_POST['cashadmin'];
  $position = $_POST['position'];
  $userdescription = $_POST['userdescription'];
  $activity = $_POST['activity'];
  $join = $_POST['join'];
  $war = $_POST['war'];
  $gallery = $_POST['galleryadmin'];
  
  if($userID != $id OR issuperadmin($userID)) {

		$ergebnis=safe_query("SELECT * FROM ".PREFIX."user_groups WHERE userID='$id'");
		if(!mysql_num_rows($ergebnis)) safe_query("INSERT INTO ".PREFIX."user_groups (userID) values ('$id')");
		safe_query("UPDATE ".PREFIX."user_groups SET news='$newsadmin', 
												  polls='$pollsadmin',
												  feedback='$feedbackadmin',
												  user='$useradmin', 
												  clanwars='$cwadmin',
												  forum='$boardadmin',
												  moderator='$moderator',
												  internboards='$intern',
												  page='$pageadmin',
												  gallery='$gallery',
												  files='$fileadmin', cash='$cashadmin' WHERE userID='$id'");
                          
    $userdescriptione=safe_query("SELECT * FROM ".PREFIX."user WHERE userID='$id'");
		if(!mysql_num_rows($userdescriptione)) safe_query("INSERT INTO ".PREFIX."user (userID) values ('$id')");
		safe_query("UPDATE ".PREFIX."user SET userdescription='$userdescription' WHERE userID='$id'");

		foreach($position as $sqmID=>$pos) {
			safe_query("UPDATE ".PREFIX."squads_members SET position='$pos' WHERE sqmID='$sqmID'");
		}
		foreach($activity as $sqmID=>$act) {
			safe_query("UPDATE ".PREFIX."squads_members SET activity='$act' WHERE sqmID='$sqmID'");
		}
		foreach($join as $sqmID=>$joi) {
			safe_query("UPDATE ".PREFIX."squads_members SET joinmember='$joi' WHERE sqmID='$sqmID'");
		}
		foreach($war as $sqmID=>$wara) {
			safe_query("UPDATE ".PREFIX."squads_members SET warmember='$wara' WHERE sqmID='$sqmID'");
		}
		if(issuperadmin($userID)) safe_query("UPDATE ".PREFIX."user_groups SET super='".$_POST['superadmin']."' WHERE userID='$id'");
	} else redirect('admincenter.php?site=members','Can not change own rights.');
}

echo'<h2>members</h2>';
	
if($_GET['action']=="edit") {
  $id = $_GET['id'];
	$ergebnis=safe_query("SELECT * FROM ".PREFIX."squads_members WHERE userID='$id' GROUP BY squadID");
    $anz=mysql_num_rows($ergebnis);
    if($anz) {
        while($ds=mysql_fetch_array($ergebnis)) {
		    if($ds[activity]) $activity=' <select name="activity['.$ds[sqmID].']"><option value="1" selected>active</option><option value="0">inactive</option></select>';
			  else $activity=' <select name="activity['.$ds[sqmID].']"><option value="1">active</option><option value="0" selected>inactive</option></select>';
      	if($ds[joinmember]) $join='<select name="join['.$ds[sqmID].']"><option value="1" selected>yes</option><option value="0">no</option></select>';
        else $join='<select name="join['.$ds[sqmID].']"><option value="1">yes</option><option value="0" selected>no</option></select>';
      	if($ds[warmember]) $fight='<select name="war['.$ds[sqmID].']"><option value="1" selected>yes</option><option value="0">no</option></select>';
        else $fight='<select name="war['.$ds[sqmID].']"><option value="1">yes</option><option value="0" selected>no</option></select>';


			$squads.='<tr><td colspan="2"><table border="0" cellpadding="1" cellspacing="0" width="100%"><tr><td colspan="2" height="1" bgcolor="#CCCCCC"></td></tr></table></td></tr>
      <tr>
			  <td>Squad:</td><td><b>'.getsquadname($ds[squadID]).'</b></td></tr>
        <tr><td>Position:</td><td><input type="text" name="position['.$ds[sqmID].']" value="'.$ds[position].'" size="60" class="form_off" onFocus="this.className=\'form_on\'" onBlur="this.className=\'form_off\'">'.$activity.'</td>						   
					 </tr>
           <tr>
            <td></td><td>Joinus-Admin: '.$join.' Fightus-Admin: '.$fight.'</td>
           </tr>';
	    }
    }
	if(isnewsadmin($id)) $news='<input type="checkbox" class="input" name="newsadmin" value="1" checked>';
	else $news='<input type="checkbox" class="input" name="newsadmin" value="1">';
		
	if(ispollsadmin($id)) $polls='<input type="checkbox" class="input" name="pollsadmin" value="1" checked>';
	else $polls='<input type="checkbox" class="input" name="pollsadmin" value="1">';
		
	if(isfeedbackadmin($id)) $feedback='<input type="checkbox" class="input" name="feedbackadmin" value="1" checked>';
	else $feedback='<input type="checkbox" class="input" name="feedbackadmin" value="1">';
		
	if(isuseradmin($id)) $useradmin='<input type="checkbox" class="input" name="useradmin" value="1" checked>';
	else $useradmin='<input type="checkbox" class="input" name="useradmin" value="1">';
	
	if(isclanwaradmin($id)) $cwadmin='<input type="checkbox" class="input" name="cwadmin" value="1" checked>';
	else $cwadmin='<input type="checkbox" class="input" name="cwadmin" value="1">';
		
	if(isforumadmin($id)) $board='<input type="checkbox" class="input" name="boardadmin" value="1" checked>';
	else $board='<input type="checkbox" class="input" name="boardadmin" value="1">';
		
	if(isanymoderator($id)) $mod='<input type="checkbox" class="input" name="moderator" value="1" checked>';
	else $mod='<input type="checkbox" class="input" name="moderator" value="1">';
		
	if(isinternboarduser($id)) $intern='<input type="checkbox" class="input" name="intern" value="1" checked>';
	else $intern='<input type="checkbox" class="input" name="intern" value="1">';
		
	if(ispageadmin($id)) $page='<input type="checkbox" class="input" name="pageadmin" value="1" checked>';
	else $page='<input type="checkbox" class="input" name="pageadmin" value="1">';
		
	if(isfileadmin($id)) $file='<input type="checkbox" class="input" name="fileadmin" value="1" checked>';
	else $file='<input type="checkbox" class="input" name="fileadmin" value="1">';
	
	if(iscashadmin($id)) $cash='<input type="checkbox" class="input" name="cashadmin" value="1" checked>';
	else $cash='<input type="checkbox" class="input" name="cashadmin" value="1">';

	if(isgalleryadmin($id)) $gallery='<input type="checkbox" class="input" name="galleryadmin" value="1" checked>';
	else $gallery='<input type="checkbox" class="input" name="galleryadmin" value="1">';

	if(issuperadmin($id)) $super='<input type="checkbox" class="input" name="superadmin" value="1" checked>';
	else $super='<input type="checkbox" class="input" name="superadmin" value="1">';
  
  if(isclanmember($id)) $userdes='<tr>
        <td>User description:</td>
        <td><textarea cols="60" rows="5" name="userdescription" class="form_off" onFocus="this.className=\'form_on\'" onBlur="this.className=\'form_off\'">'.getuserdescription($id).'</textarea></td>
       </tr>';
	else $userdes='';
  
	echo'<form method="post" action="admincenter.php?site=members">
	       <table cellpadding="4" cellspacing="0">
		   <tr>
		     <td>Nickname:</td><td><b>'.getnickname($id).'</b></td>
		   </tr>
		   '.$squads.'
       '.$userdes.'
       <tr><td colspan="2"><table border="0" cellpadding="1" cellspacing="0" width="100%"><tr><td colspan="2" height="1" bgcolor="#CCCCCC"></td></tr></table></td></tr>		   <tr><td>'.$news.' News-Admin</td><td>'.$board.' Messageboard-Admin</td></tr>
		   <tr><td>'.$cwadmin.' Clanwar-Admin</td><td>'.$mod.' Messageboard-Moderator</td></tr>
		   <tr><td>'.$polls.' Polls-Admin</td><td>'.$intern.' Access to intern Boards</td></tr>
		   <tr><td>'.$feedback.' Feedback-Admin</td><td>'.$page.' Page-Admin</td></tr>
		   <tr><td>'.$file.' File-Admin</td><td>'.$useradmin.' User-Admin</td></tr>
		   <tr><td>'.$cash.' Cash-Admin</td><td>'.$gallery.' Gallery-Admin</td><td>&nbsp;</td></tr>';
	if(issuperadmin($userID)) echo '<tr><td>'.$super.' <b>Super-Admin</b></td><td>&nbsp;</td></tr>';
	echo '<tr><td><input type="hidden" name="id" value="'.$id.'"><input type="submit" name="saveedit" value="update member"></td><td></td></tr>
		 </table>
		 </form>';
	unset($squads);	 
}
else {
	$squads=safe_query("SELECT * FROM ".PREFIX."squads ORDER BY sort");
	echo'<form method="post" action="admincenter.php?site=members">';
	while($ds=mysql_fetch_array($squads)) {
	    echo'<table width="100%" cellpadding="2" cellspacing="1" bgcolor="#999999">
		       <tr bgcolor="#CCCCCC">
			     <td colspan="6" class="category_big">'.$ds[name].'</td>
			   </tr>
			   <tr bgcolor="#FFFFFF"><td colspan="6"></td></tr>';
			
		$members=safe_query("SELECT * FROM ".PREFIX."squads_members WHERE squadID='$ds[squadID]' ORDER BY sort");	 
	    $anzmembers=safe_query("SELECT count(squadID) FROM ".PREFIX."squads_members WHERE squadID='$ds[squadID]'");
		$anzmembers=mysql_result($anzmembers, 0);
		
		echo'<tr bgcolor="#CCCCCC">
		     <td class="title" width="30%">Country / Nickname:</td>
			 <td class="title" width="40%">Position:</td>
			 <td class="title" width="10%">Activity:</td>
			 <td class="title" width="5%">Sort:</td>
			 <td class="title" width="15%" colspan="2">Actions:</td>
			 </tr>';
			
		while($dm=mysql_fetch_array($members)) {
		    $country = '[flag]'.getcountry($dm[userID]).'[/flag]';
		    $country=flags($country);
			$country=str_replace("images/", "../images/", $country);
		    $nickname='<a href="../index.php?site=profile&id='.$dm[userID].'"><b>'.getnickname($dm[userID]).'</b></a>';
			if($dm[activity]) $activity='<b>activ</b>';
			else $activity='inactive';
			echo'<tr bgcolor="#FFFFFF">
			       <td>'.$country.' '.$nickname.'</td>
				   <td>'.$dm[position].'</td>
				   <td>'.$activity.'</td>
				   <td><select name="sort[]">';
	        for($j=1; $j<=$anzmembers; $j++) {
	        	if($dm[sort] == $j) echo'<option value="'.$dm[sqmID].'-'.$j.'" selected>'.$j.'</option>';
		    	else echo'<option value="'.$dm[sqmID].'-'.$j.'">'.$j.'</option>';
	        }		
	        echo'  </select></td>
				   <td><input type="button" class="button" onClick="MM_goToURL(\'parent\',\'admincenter.php?site=members&action=edit&id='.$dm[userID].'\');return document.MM_returnValue" value="edit"></td>
				   <td><input type="button" class="button" onClick="MM_confirm(\'really delete this member?\', \'admincenter.php?site=members&delete=true&id='.$dm[userID].'&squadID='.$dm[squadID].'\')" value="delete"></td>
				 </tr>';
		}
		echo'</table><br>';
	}
	echo'<div align="right"><input type="submit" name="sortieren" value="sort members"></div></form>';
}
?>

