Can anyone help me out with this one? I'm currently trying to add a management section to a website for a friend. Neither of us coded it, so I don't really get how this guy who DID code it has done it.
I have never really used drop downs, arrays and PHP together, so I kinda don't know what i'm doing, except I could copy his code.. But then it's wrong!
All I need to do, is make a new drop down, but with management only, just for the admin. No one else. Here's the code he has for the page:
PHP Code:
<?php
require('inc/Predefined.php');
require('inc/Mysql.php');
require('inc/User.php');
require('parts/m_start.php');
require('parts/m_menu.html');
// remove memmbership
if ($_POST['user_id'] && $_POST['activity'])
{
if ($_POST['activity'] === 'active')
{
$sql = "UPDATE s_teams SET
active=0
WHERE user_id=". intval($_POST['user_id']);
$sdb->get_query($sql);
}
elseif ($_POST['activity'] === 'inactive')
{
$sql = "UPDATE s_teams SET
active=1
WHERE user_id=". intval($_POST['user_id']);
$sdb->get_query($sql);
}
}
if ($_POST['user_id'] && isset($_POST['rankID']) && $_POST['gameID'])
{
$sql = "UPDATE s_teams SET
rankID=". (intval($_POST['rankID']) ? intval($_POST['rankID']) : 'NULL') ."
WHERE user_id=". intval($_POST['user_id']) ."
AND gameID=". intval($_POST['gameID']);
$sdb->get_query($sql);
}
?>
<div id="inner_header">Roster: <?php echo $row['name'] ?></div>
<div class="tab_cell">
<table class="stats" cellpadding="0" cellspacing="0">
<thead>
<tr>
<td width="250">Name</td>
<td>Status</td>
<td>Rank</td>
<td>Profile</td>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT gameID,name FROM s_games
ORDER BY name";
$resOut = $sdb->get_query($sql);
while ($rowOut = mysql_fetch_assoc($resOut))
{
echo '<tr><td colspan="4" align="center">- '. $rowOut['name'] ." -</td></tr>\n\n";
// finn all users
$sql = "SELECT st.user_id, st.active, st.rankID, fu.username FROM
s_teams st INNER JOIN forum_users fu USING(user_id)
WHERE st.gameID={$rowOut['gameID']}
ORDER BY fu.username";
$res = $sdb->get_query($sql);
$sql = "SELECT * FROM s_ranks
WHERE gameID=". intval($rowOut['gameID']) ."
ORDER BY name";
$res2 = $sdb->get_query($sql);
$ranks = array(0 => 'no rank');
while ($row = mysql_fetch_assoc($res2))
{
$ranks[intval($row['rankID'])] = $row['name'];
}
while ($row = mysql_fetch_assoc($res))
{
?>
<tr class="tr1" onmouseover="this.className='tr2'" onmouseout="this.className='tr1'">
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" style="display:inline">
<td>
<?php echo $row['username'] ?>
</td>
<input type="hidden" name="user_id" value="<?php echo $row['user_id'] ?>">
<td>
<input type="submit" class="black_box" name="activity" value="<?php echo ($row['active'] ? 'active' : 'inactive') ?>">
</td>
</form>
<td>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" style="display:inline" name="ranks<?php echo $rowOut['gameID'].$row['user_id'] ?>">
<input type="hidden" name="user_id" value="<?php echo $row['user_id'] ?>">
<input type="hidden" name="gameID" value="<?php echo $rowOut['gameID'] ?>">
<select name="rankID" onChange="document.forms['ranks<?php echo $rowOut['gameID'].$row['user_id'] ?>'].submit()">
<?php
foreach (array_keys($ranks) as $key)
{
?><option value="<?php echo $key ?>" <?php if ($row['rankID'] == $key) echo 'selected' ?>><?php echo $ranks[$key] ?></option><?php
}
?>
</select>
</form>
</td>
<td>
<form action="m_user_profile.php" method="post">
<input type="hidden" name="user_id" value="<?php echo $row['user_id'] ?>">
<input type="submit" class="black_box" value="Profile">
</form>
</td>
</tr>
<?php
}
}
?>
<!-- start hack -->
<tr>
<td colspan="4" align="center">
- Management -
<tr class="tr1" onmouseover="this.className='tr2'" onmouseout="this.className='tr1'">
<br /><br />
This section is very hard. Still in development. Too much school work at the moment! :'(
<br /><br />
</td>
</tr>
</tr>
<!-- end hack -->
</tbody>
</table>
</div>
<?php
require('parts/end.php');
?>
Thanks in advance guys.
|