I am not really sure how to word this so if you need more clarification I can try my best to explain.
Here is the code
$file = "shout.txt";
$filed = file_get_contents($file);
preg_match_all('|<div class=\'date\'>(?P<date>.*?) .*<a.*>(?P<user>.*)</a>|i', $filed, $matches);
$shoutlines = file($shout_file);
$aTemp = array();
foreach($matches['user'] as $user) {
$aTemp[] = "'" . mysql_real_escape_string($user) . "'";
}
$user = implode(",", $aTemp);
$getlevel = $db->query("SELECT * FROM accounts WHERE username IN ( ".$user." )");
$isadmin = $db->query("SELECT * FROM accounts WHERE username = '".$_SESSION['username']."'");
$admin = $isadmin->fetch_assoc();
while($status = $getlevel->fetch_assoc()){
//output the html
for($i = 0; $i < (1000); $i++)
{
if(isset($shoutlines[$i]))
{
if ($admin['admin'] == 1 && $status['sblevel'] != Admin && $status['sblevel'] != Banned){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='javascript: ban({$status['id']});' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>";
}
if ($admin['admin'] == 1 && $status['sblevel'] != Admin && $status['sblevel'] == Banned){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='?index=shout&unban&user=".$shout['username']."' class='ban' onclick=\"return confirm('Are you sure you want to unban this user?');\">ø</a>";
}
if ($admin['admin'] == 1 && $status['sblevel'] == Admin){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a>";
}
if ($admin['sblevel'] == Moderator && $status['sblevel'] != Admin && $status['sblevel'] != Moderator){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='?index=shout&ban&user=".$shout['username']."' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>";
}
if ($status['sblevel'] == Moderator && $status['sblevel'] != Admin){
$delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a>";
}
$shoutline = preg_replace('/<\/div>\n/', ' ', $shoutlines[$i], 1);
echo showSmileys($shoutline) . $delete . "</div>";
}
}
}
The problem is that it duplicates all of the posts for every user that posted.. I am assuming this is because it is in a while loop, but I don’t know how else to go about doing it because I need to check if a user is an admin/mod and if they are put a delete/ban button next to the posts to allow them to delete. As it stands now it puts an delete button next to all posts and then duplicates them all with a delete and ban button next to them.
Here’s the simplest modification to avoid repeating messages. You have to supply a function
author()that takes a line from the shout_file and returns the author ID.This probably isn’t the best way to do it, since it repeats the “Ban this user” for each messages from the author. It would be better to put the ban/unban options once at the beginning of each user, then “delete” on each line.