<?php
/*
IrisBlaze wap forum
by Ra'ed Shabana
*/
include("xhtmlfunctions.php");
header("Content-type: text/html; charset=ISO-8859-1");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
?>

<?php
include("config.php");
include("core.php");
connectdb();
$action = $_GET["action"];
$sid = $_GET["sid"];
$page = $_GET["page"];
$who = $_GET["who"];
$pmid = $_GET["pmid"];
if(islogged($sid)==false)
{
$pstyle = gettheme1("1");
echo xhtmlhead("blingywap",$pstyle);
echo "<p align=\"center\">";
echo "You are not logged in<br/>";
echo "Or Your session has been expired<br/><br/>";
echo "<a href=\"index.php\">Login</a>";
echo "</p>";
echo xhtmlfoot();
exit();
}
$uid = getuid_sid($sid);
if(isbanned($uid))
{
$pstyle = gettheme($sid);
echo xhtmlhead("blingywap",$pstyle);
echo "<p align=\"center\">";
echo "<img src=\"images/notok.gif\" alt=\"x\"/><br/>";
echo "You are <b>Banned</b><br/>";
$banto = mysql_fetch_array(mysql_query("SELECT timeto FROM ibwf_metpenaltiespl WHERE uid='".$uid."' AND penalty='1'"));
$banres = mysql_fetch_array(mysql_query("SELECT lastpnreas FROM ibwf_users WHERE id='".$uid."'"));

$remain = $banto[0]- (time() - $timeadjust) ;
$rmsg = gettimemsg($remain);
echo "Time to finish your penalty: $rmsg<br/><br/>";
echo "Ban Reason: $banres[0]";
//echo "<a href=\"index.php\">Login</a>";
echo "</p>";
echo xhtmlfoot();
exit();
}

if($action=="sendpm")
{
$mid = getnick_uid($who);

addonline(getuid_sid($sid),"Sending PM to $mid","");
$pstyle = gettheme($sid);
echo xhtmlhead("Inbox",$pstyle);
echo "<p align=\"center\">";
$whonick = getnick_uid($who);
echo "Send PM to $whonick<br/><br/>";
echo "<form action=\"inbxproc.php?action=sendpm&amp;who=$who&amp;sid=$sid\" method=\"post\">";
echo "<input name=\"pmtext\" maxlength=\"500\"/><br/>";
echo "<input type=\"submit\" value=\"SEND\"/>";
echo "</form>";
echo "<br/>";
$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";
echo xhtmlfoot();

}
else if($action=="sendto")
{ $abc = getnick_uid($who);

addonline(getuid_sid($sid),"Sending PM to $abc","");
$pstyle = gettheme($sid);
echo xhtmlhead("Inbox",$pstyle);

echo "<p align=\"center\">";
$whonick = getnick_uid($who);
echo "Send PM to:<br/><br/>";
echo "<form action=\"inbxproc.php?action=sendto&amp;sid=$sid\" method=\"post\">";
echo "User: <input name=\"who\" format=\"*x\" maxlength=\"15\"/><br/>";
echo "Text: <input name=\"pmtext\" maxlength=\"500\"/><br/>";

echo "<input type=\"submit\" value=\"SEND\"/>";
echo "</form>";

echo "<br/><br/>";
$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";

echo xhtmlfoot();

}
else if($action=="renamefolder")
{
addonline(getuid_sid($sid),"Renaming PM Folder","");
$pstyle = gettheme($sid);
echo xhtmlhead("Renaming PM Folder",$pstyle);

echo "<p align=\"center\">";
$folderid = $_GET["fid"];
$foldername = mysql_fetch_array(mysql_query("SELECT foldername FROM ibwf_private_folders WHERE folderid='".$folderid."'"));
echo "Renaming Folder: $foldername[0]<br/><br/>";
echo "<form action=\"inbox.php?action=rnamefdone&amp;sid=$sid\" method=\"post\">";
echo "New Folder Name: <input name=\"newname\" format=\"*x\" maxlength=\"25\"/><br/>";
echo "<input type=\"hidden\" name=\"fid\" value=\"$folderid\"/>";
echo "<input type=\"submit\" value=\"Rename\"/>";
echo "</form>";

echo "<br/><br/>";
$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"inbox.php?action=main&amp;sid=$sid\">«Back to Inbox</a><br/>";
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";

echo xhtmlfoot();

}
else if($action=="rnamefdone")
{
addonline(getuid_sid($sid),"Renaming PM Folder","");
$pstyle = gettheme($sid);
echo xhtmlhead("Renaming PM Folder",$pstyle);
$folderid = $_POST["fid"];
$newname = $_POST["newname"];

echo "<p align=\"center\">";

$res = mysql_query("UPDATE ibwf_private_folders SET foldername='".$newname."' WHERE folderid='".$folderid."'");

if($res)
{
echo "<img src=\"images/ok.gif\" alt=\"O\"/>Folder Renamed Successfully<br/><br/>";
}else{
echo "<img src=\"images/notok.gif\" alt=\"O\"/>Rename Error!<br/><br/>";
}

echo "<br/><br/>";
$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"inbox.php?action=main&amp;sid=$sid\">«Back to Inbox</a><br/>";
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";

echo xhtmlfoot();

}
else if($action=="delfolder")
{
addonline(getuid_sid($sid),"Deleting PM Folder","");
$pstyle = gettheme($sid);
echo xhtmlhead("Deleting PM Folder",$pstyle);

echo "<p align=\"center\">";

$folderid = $_POST["fid"]; 
$res = mysql_query("DELETE FROM ibwf_private_folders WHERE folderid='".$folderid."'");


$sql = "SELECT folderid FROM ibwf_private WHERE folderid='".$folderid."'";
$items = mysql_query($sql);
echo mysql_error();
if(mysql_num_rows($items)>0)
{
while ($item = mysql_fetch_array($items))
{
$sql = mysql_query("UPDATE ibwf_private SET folderid='0' WHERE folderid='".$folderid."'");
}
}

if($res)
{
echo "<img src=\"images/ok.gif\" alt=\"O\"/>Folder Deleted Successfully<br/><br/>";
}else{
echo "<img src=\"images/notok.gif\" alt=\"O\"/>Delete Error!<br/><br/>";
}

echo "<br/><br/>";
$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"inbox.php?action=main&amp;sid=$sid\">«Back to Inbox</a><br/>";
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";

echo xhtmlfoot();

}

else if($action=="main")
{
addonline(getuid_sid($sid),"User Inbox","");
$pstyle = gettheme($sid);
echo xhtmlhead("Inbox",$pstyle);
echo "<p align=\"center\">";
echo "Inbox";
echo "</p>";

echo "<div class=\"mblock1\">";
echo "<small>";
$uid = getuid_sid($sid);

$umsg = getunreadpm(getuid_sid($sid));
$tmsg = getpmcount(getuid_sid($sid));
$read = $tmsg - $umsg;
$readpmnotinfolder = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE touid='".$uid."' AND unread='0' AND folderid='0'"));
echo "<img src=\"images/star.gif\" alt=\"*\"/><a href=\"inbox.php?action=folderunread&amp;sid=$sid\">New</a>($umsg)<br/>";
echo "<img src=\"images/hot.gif\" alt=\"*\"/><a href=\"inbox.php?action=folderread&amp;sid=$sid\">Old</a>($readpmnotinfolder[0])<br/><br/>";

$sql = "SELECT foldername, folderid FROM ibwf_private_folders WHERE uid='".$uid."' ORDER BY foldername DESC"; 
$items = mysql_query($sql); 
echo mysql_error();
if(mysql_num_rows($items)>0)
{
while ($item = mysql_fetch_array($items))
{
$noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE touid='".$uid."' AND folderid='".$item[1]."'"));
$lnk = "<img src=\"mailbox_folder.gif\" alt=\"*\"/><a href=\"inbox.php?action=folder&amp;folderid=$item[1]&amp;sid=$sid\">$item[0]</a>($noi[0])";
echo "$lnk<br/>";
}
}

echo "<br/>";
echo "<center><a href=\"inbox.php?action=crfolder&amp;sid=$sid\">*Create New Folder*</a></center>";
echo "<center><a href=\"inbox.php?action=sendto&amp;sid=$sid\">*Send PM*</a></center>";
echo "</small>";
echo "</div>";
////// UNTILL HERE >>



echo "<p align=\"center\">";

$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";
echo xhtmlfoot();
}
else if($action=="folderread")
{
addonline(getuid_sid($sid),"User Inbox","");
$pstyle = gettheme($sid);
echo xhtmlhead("Inbox - Read",$pstyle);
echo "<p align=\"center\">";
echo "Read";
echo "</p>";
$view = $_GET["view"];
//////ALL LISTS SCRIPT <<
if($view=="")$view="all";
if($page=="" || $page<=0)$page=1;
$myid = getuid_sid($sid);
$doit=false;
$noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE touid='".$uid."' AND unread='0'"));
$num_items = $noi[0]; //changable
$items_per_page= 7;
$num_pages = ceil($num_items/$items_per_page);
if($page>$num_pages)$page= $num_pages;
$limit_start = ($page-1)*$items_per_page;
if($num_items>0)
{
if($doit)
{
$exp = "&amp;rwho=$myid";
}else
{
$exp = "";
}
//changable sql

$sql = "SELECT
a.name, b.id, b.byuid, b.unread, b.starred FROM ibwf_users a
INNER JOIN ibwf_private b ON a.id = b.byuid
WHERE b.touid='".$myid."' AND b.unread='0'
ORDER BY b.timesent DESC
LIMIT $limit_start, $items_per_page
";
echo "<div class=\"mblock1\">";
echo "<small>";
$items = mysql_query($sql);
echo mysql_error();
while ($item = mysql_fetch_array($items))
{
if($item[3]=="1")
{
$iml = "<img src=\"images/npm.gif\" alt=\"+\"/>";
}else{
if($item[4]=="1")
{
$iml = "<img src=\"images/spm.gif\" alt=\"*\"/>";
}else{

$iml = "<img src=\"images/opm.gif\" alt=\"-\"/>";
}
}

$lnk = "<a href=\"inbox.php?action=readpm&amp;pmid=$item[1]&amp;sid=$sid\">$iml $item[0]</a>";
echo "$lnk<br/>";
}
echo "</small>";
echo "</div>";
echo "<p align=\"center\">";

$npage = $page+1;
echo "<a href=\"inbox.php?action=sendto&amp;sid=$sid\">Send to</a><br/>";
if($page>1)
{
$ppage = $page-1;
echo "<a href=\"inbox.php?action=folderread&amp;page=$ppage&amp;sid=$sid&amp;view=$view$exp\">«Prev</a> ";
}
if($page<$num_pages)
{
$npage = $page+1;
echo "<a href=\"inbox.php?action=folderread&amp;page=$npage&amp;sid=$sid&amp;view=$view$exp\">Next»</a>";
}
echo "<br/>$page/$num_pages<br/>";
if($num_pages>2)
{
$rets = "<form action=\"inbox.php\" method=\"get\">";
$rets .= "Jump to page: <input name=\"page\" format=\"*N\" size=\"3\"/><br/>";
$rets .= "<input type=\"submit\" value=\"GO\"/>";
$rets .= "<input type=\"hidden\" name=\"action\" value=\"$action\"/>";
$rets .= "<input type=\"hidden\" name=\"sid\" value=\"$sid\"/>"; 
$rets .= "<input type=\"hidden\" name=\"view\" value=\"$view\"/>";
$rets .= "</form>";
echo $rets;
}
echo "<br/>";

echo "</p>";
}else{
echo "<p align=\"center\">";
echo "You have no Private Messages<br/>";
echo "</p>";
}
////// UNTILL HERE >>



echo "<p align=\"center\">";

$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"inbox.php?action=main&amp;sid=$sid\">«Back to Inbox</a><br/>";
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";
echo xhtmlfoot();
}


else if($action=="folderunread")
{
addonline(getuid_sid($sid),"User Inbox","");
$pstyle = gettheme($sid);
echo xhtmlhead("Inbox - Unread",$pstyle);
echo "<p align=\"center\">";
echo "Unread Mail";
echo "</p>";
$view = $_GET["view"];
//////ALL LISTS SCRIPT <<
if($view=="")$view="all";
if($page=="" || $page<=0)$page=1;
$myid = getuid_sid($sid);
$doit=false;
$noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE touid='".$uid."' AND unread='1'"));
$num_items = $noi[0]; //changable
$items_per_page= 7;
$num_pages = ceil($num_items/$items_per_page);
if($page>$num_pages)$page= $num_pages;
$limit_start = ($page-1)*$items_per_page;
if($num_items>0)
{
if($doit)
{
$exp = "&amp;rwho=$myid";
}else
{
$exp = "";
}
//changable sql

$sql = "SELECT
a.name, b.id, b.byuid, b.unread, b.starred FROM ibwf_users a
INNER JOIN ibwf_private b ON a.id = b.byuid
WHERE b.touid='".$myid."' AND b.unread='1'
ORDER BY b.timesent DESC
LIMIT $limit_start, $items_per_page
";
echo "<div class=\"mblock1\">";
echo "<small>";
$items = mysql_query($sql);
echo mysql_error();
while ($item = mysql_fetch_array($items))
{
if($item[3]=="1")
{
$iml = "<img src=\"images/npm.gif\" alt=\"+\"/>";
}else{
if($item[4]=="1")
{
$iml = "<img src=\"images/spm.gif\" alt=\"*\"/>";
}else{

$iml = "<img src=\"images/opm.gif\" alt=\"-\"/>";
}
}

$lnk = "<a href=\"inbox.php?action=readpm&amp;pmid=$item[1]&amp;sid=$sid\">$iml $item[0]</a>";
echo "$lnk<br/>";
}
echo "</small>";
echo "</div>";
echo "<p align=\"center\">";

$npage = $page+1;
echo "<a href=\"inbox.php?action=sendto&amp;sid=$sid\">Send to</a><br/>";
if($page>1)
{
$ppage = $page-1;
echo "<a href=\"inbox.php?action=folderunread&amp;page=$ppage&amp;sid=$sid&amp;view=$view$exp\">«Prev</a> ";
}
if($page<$num_pages)
{
$npage = $page+1;
echo "<a href=\"inbox.php?action=folderunread&amp;page=$npage&amp;sid=$sid&amp;view=$view$exp\">Next»</a>";
}
echo "<br/>$page/$num_pages<br/>";
if($num_pages>2)
{
$rets = "<form action=\"inbox.php\" method=\"get\">";
$rets .= "Jump to page: <input name=\"page\" format=\"*N\" size=\"3\"/><br/>";
$rets .= "<input type=\"submit\" value=\"GO\"/>";
$rets .= "<input type=\"hidden\" name=\"action\" value=\"$action\"/>";
$rets .= "<input type=\"hidden\" name=\"sid\" value=\"$sid\"/>"; 
$rets .= "<input type=\"hidden\" name=\"view\" value=\"$view\"/>";
$rets .= "</form>";
echo $rets;
}
echo "<br/>";

echo "</p>";
}else{
echo "<p align=\"center\">";
echo "You have no Private Messages<br/>";
echo "<a href=\"inbox.php?action=sendto&amp;sid=$sid\">Send PM</a><br/>";
echo "</p>";
}
////// UNTILL HERE >>



echo "<p align=\"center\">";

$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"inbox.php?action=main&amp;sid=$sid\">«Back to Inbox</a><br/>";
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";
echo xhtmlfoot();
}


else if($action=="folder")
{
addonline(getuid_sid($sid),"User Inbox","");
$pstyle = gettheme($sid);
echo xhtmlhead("Inbox",$pstyle);
$folderid = $_GET["folderid"];
$foldername = mysql_fetch_array(mysql_query("SELECT foldername FROM ibwf_private_folders WHERE folderid='".$folderid."'"));
echo "<p align=\"center\">";
echo "Folder $foldername[0]";
echo "</p>";
//////ALL LISTS SCRIPT <<
if($view=="")$view="all";
if($page=="" || $page<=0)$page=1;
$myid = getuid_sid($sid);
$doit=false;
$noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE touid='".$uid."' AND folderid='".$folderid."'"));
$num_items = $noi[0]; //changable
$items_per_page= 10;
$num_pages = ceil($num_items/$items_per_page);
if($page>$num_pages)$page= $num_pages;
$limit_start = ($page-1)*$items_per_page;
if($num_items>0)
{
if($doit)
{
$exp = "&amp;rwho=$myid";
}else
{
$exp = "";
}
//changable sql

$sql = "SELECT
a.name, b.id, b.byuid, b.unread, b.starred, folderid FROM ibwf_users a
INNER JOIN ibwf_private b ON a.id = b.byuid
WHERE b.touid='".$myid."' AND folderid='".$folderid."'
ORDER BY b.timesent DESC
LIMIT $limit_start, $items_per_page
";
echo "<div class=\"mblock1\">";
echo "<small>";
$items = mysql_query($sql);
echo mysql_error();
while ($item = mysql_fetch_array($items))
{
if($item[3]=="1")
{
$iml = "<img src=\"images/npm.gif\" alt=\"+\"/>";
}else{
if($item[4]=="1")
{
$iml = "<img src=\"images/spm.gif\" alt=\"*\"/>";
}else{

$iml = "<img src=\"images/opm.gif\" alt=\"-\"/>";
}
}

$lnk = "<a href=\"inbox.php?action=readpm&amp;pmid=$item[1]&amp;sid=$sid\">$iml $item[0]</a>";
echo "$lnk<br/>";
}
echo "<br/>";
echo "</small>";
echo "<center><small><a href=\"inbox.php?action=delfolder&amp;fid=$folderid&amp;sid=$sid\">Delete Folder</a></small></center>";
echo "<center><small><a href=\"inbox.php?action=renamefolder&amp;fid=$folderid&amp;sid=$sid\">Rename Folder</a></small></center>";
echo "</div>";
echo "<p align=\"center\">";

$npage = $page+1;
echo "<a href=\"inbox.php?action=sendto&amp;sid=$sid\">Send to</a><br/>";
if($page>1)
{
$ppage = $page-1;
echo "<a href=\"inbox.php?action=main&amp;page=$ppage&amp;sid=$sid&amp;view=$view$exp\">«Prev</a> ";
}
if($page<$num_pages)
{
$npage = $page+1;
echo "<a href=\"inbox.php?action=main&amp;page=$npage&amp;sid=$sid&amp;view=$view$exp\">Next»</a>";
}
echo "<br/>$page/$num_pages<br/>";
if($num_pages>2)
{
$rets = "<form action=\"inbox.php\" method=\"get\">";
$rets .= "Jump to page: <input name=\"page\" format=\"*N\" size=\"3\"/><br/>";
$rets .= "<input type=\"submit\" value=\"GO\"/>";
$rets .= "<input type=\"hidden\" name=\"action\" value=\"$action\"/>";
$rets .= "<input type=\"hidden\" name=\"sid\" value=\"$sid\"/>"; 
$rets .= "<input type=\"hidden\" name=\"view\" value=\"$view\"/>";
$rets .= "</form>";
echo $rets;
}
echo "<br/>";
echo "</p>";
}else{
echo "<p align=\"center\">";
echo "You have no Private Messages<br/>";
echo "<a href=\"inbox.php?action=sendto&amp;sid=$sid\">Send PM</a><br/>";
echo "</p>";
}
////// UNTILL HERE >>



echo "<p align=\"center\">";

$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"inbox.php?action=main&amp;sid=$sid\">«Back to Inbox</a><br/>";
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";
echo xhtmlfoot();
} 

else if($action=="readpm")
{$pminfo = mysql_fetch_array(mysql_query("SELECT text, byuid, timesent,touid, reported FROM ibwf_private WHERE id='".$pmid."'"));

$ab = getnick_uid($pminfo[1]);

addonline(getuid_sid($sid),"Reading PM from $ab","");
$pstyle = gettheme($sid);
echo xhtmlhead("Read PM",$pstyle);
echo "<p>";

$pminfo = mysql_fetch_array(mysql_query("SELECT text, byuid, timesent,touid, reported FROM ibwf_private WHERE id='".$pmid."'"));
if(getuid_sid($sid)==$pminfo[3])
{
$chread = mysql_query("UPDATE ibwf_private SET unread='0' WHERE id='".$pmid."'");
}

if(($pminfo[3]==getuid_sid($sid))||($pminfo[1]==getuid_sid($sid)))
{

if(getuid_sid($sid)==$pminfo[3])
{
if(isonline($pminfo[1]))
{
$iml = "<img src=\"images/onl.gif\" alt=\"+\"/>";
}else{
$iml = "<img src=\"images/ofl.gif\" alt=\"-\"/>";
}
$ptxt = "PM By: ";

$bylnk = "<a href=\"index.php?action=viewuser&amp;who=$pminfo[1]&amp;sid=$sid\">$iml".getnick_uid($pminfo[1])."</a>";

}else{
if(isonline($pminfo[3]))
{
$iml = "<img src=\"images/onl.gif\" alt=\"+\"/>";
}else{
$iml = "<img src=\"images/ofl.gif\" alt=\"-\"/>";
}
$ptxt = "PM To: ";

$bylnk = "<a href=\"index.php?action=viewuser&amp;who=$pminfo[3]&amp;sid=$sid\">$iml".getnick_uid($pminfo[3])."</a>";

}

echo "$ptxt $bylnk<br/>";
$tmstamp = $pminfo[2];
$tmdt = date("d/m/Y - H:i:s", $tmstamp);
echo "$tmdt<br/>";
$pmtext = parsepm($pminfo[0], $sid);
$pmtext = str_replace("/faq","<a href=\"lists.php?action=faqs&amp;sid=$sid\">Users Questions</a>", $pmtext);
$pmtext = str_replace("/help","<a href=\"help.php?sid=$sid\">Our help menu</a>", $pmtext);
$pmtext = str_replace("/reader",getnick_uid($pminfo[3]), $pmtext);
if(isspam($pmtext))
{
if(($pminfo[4]=="0") && ($pminfo[1]!=1))
{
mysql_query("UPDATE ibwf_private SET reported='1' WHERE id='".$pmid."'");
}
}
echo $pmtext;
echo "</p>";
echo "<p align=\"center\"><br/><br/>";

echo "<form action=\"inbxproc.php?action=proc&amp;sid=$sid\" method=\"post\">";
echo "Action: <select name=\"pmact\">";
echo "<option value=\"rep-$pmid\">Reply</option>";
echo "<option value=\"del-$pmid\">Delete</option>";
if(isstarred($pmid))
{
echo "<option value=\"ust-$pmid\">Unstar</option>";
}else{
echo "<option value=\"str-$pmid\">Star</option>";
}
echo "<option value=\"rpt-$pmid\">Report</option>";

echo "</select>";
echo "<input type=\"submit\" value=\"GO\"/>";
echo "</form><br/>";

echo "<form action=\"inbox.php?action=movetofolder&amp;sid=$sid\" method=\"post\">";
$uid = getuid_sid($sid);

echo "Move To: <select name=\"movetof\">";
$foldername = mysql_query("SELECT folderid, foldername FROM ibwf_private_folders WHERE uid='".$uid."'");
while ($items = mysql_fetch_array($foldername))
{
echo "<option value=\"$items[0]\">".htmlspecialchars($items[1])."</option>";
}
echo "</select>"; 
echo "<input type=\"hidden\" name=\"pmid\" value=\"$pmid\"/>";
echo "<input type=\"submit\" value=\"Move\"/>";
echo "</form>";

echo "</p>";
echo "<p align=\"center\">";
echo "<br/><br/><a href=\"inbox.php?action=dialog&amp;sid=$sid&amp;who=$pminfo[1]\">Dialog</a>";

}else{
echo "<img src=\"images/notok.gif\" alt=\"X\"/>This PM ain't yours";
}
echo "<br/><br/><a href=\"inbox.php?action=main&amp;sid=$sid\">Back to inbox</a><br/>";

$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>"; 
echo "Home</a>";
echo "</p>";

echo xhtmlfoot();

}

else if($action=="crfolder")
{
addonline(getuid_sid($sid),"Creating Folder","");
$pstyle = gettheme($sid);
echo xhtmlhead("Create Folder",$pstyle);
echo "<p align=\"center\">"; 

echo "<form method=\"post\" action=\"inbox.php?action=crfolderdone&amp;sid=$sid\">"; 
echo "Folder Name: <input name=\"fname\" maxlength=\"25\"/><br/>"; 
echo "<input type=\"submit\" name=\"Submit\" value=\"Create\"/>";
echo "</form><br/>";


$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"inbox.php?action=main&amp;sid=$sid\">«Back to Inbox</a><br/>";
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";
echo xhtmlfoot();

}

else if($action=="crfolderdone")
{
addonline(getuid_sid($sid),"Creating Folder","");
$pstyle = gettheme($sid);
echo xhtmlhead("Create Folder",$pstyle);
echo "<p align=\"center\">";

$fname = $_POST["fname"];
$uid = getuid_sid($sid);


$reg = mysql_query("INSERT INTO ibwf_private_folders SET uid='".$uid."', foldername='".$fname."'");

if($reg)
{
echo "<img src=\"images/ok.gif\" alt=\"O\"/>Folder Created Successfully<br/><br/>";
}else{
echo "<img src=\"images/notok.gif\" alt=\"X\"/>Error Creating Folder<br/><br/>";
}



$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"inbox.php?action=main&amp;sid=$sid\">«Back to Inbox</a><br/>";
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";
echo xhtmlfoot();

}

else if($action=="movetofolder")
{
addonline(getuid_sid($sid),"Moving PM to Folder","");
$pstyle = gettheme($sid);
echo xhtmlhead("Moving PM",$pstyle);
echo "<p align=\"center\">";

$movetof = $_POST["movetof"];
$pmid = $_POST["pmid"];

$uid = getuid_sid($sid);


$str = mysql_query("UPDATE ibwf_private SET folderid='".$movetof."' WHERE id='".$pmid."' ");
if($str)
{
echo "<img src=\"images/ok.gif\" alt=\"O\"/>PM moved successfully<br/><br/>";
}else{
echo "<img src=\"images/notok.gif\" alt=\"X\"/>Can't move PM at the moment<br/><br/>";
} 



$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"inbox.php?action=main&amp;sid=$sid\">«Back to Inbox</a><br/>";
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";
echo xhtmlfoot();

}


else if($action=="dialog")
{
addonline(getuid_sid($sid),"Viewing PM Dialog","");
$pstyle = gettheme($sid);
echo xhtmlhead("PM Dialog",$pstyle);
$uid = getuid_sid($sid);
if($page=="" || $page<=0)$page=1;
$myid = getuid_sid($sid);
$pms = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE (byuid=$uid AND touid=$who) OR (byuid=$who AND touid=$uid) ORDER BY timesent"));
echo mysql_error();
$num_items = $pms[0]; //changable
$items_per_page= 7;
$num_pages = ceil($num_items/$items_per_page);
if($page>$num_pages)$page= $num_pages;
$limit_start = ($page-1)*$items_per_page;
if($num_items>0)
{
echo "<p>";
$pms = mysql_query("SELECT byuid, text, timesent FROM ibwf_private WHERE (byuid=$uid AND touid=$who) OR (byuid=$who AND touid=$uid) ORDER BY timesent LIMIT $limit_start, $items_per_page");
while($pm=mysql_fetch_array($pms))
{
if(isonline($pm[0]))
{
$iml = "<img src=\"images/onl.gif\" alt=\"+\"/>";
}else{
$iml = "<img src=\"images/ofl.gif\" alt=\"-\"/>";
}
$bylnk = "<a href=\"index.php?action=viewuser&amp;who=$pm[0]&amp;sid=$sid\">$iml".getnick_uid($pm[0])."</a>";
echo $bylnk;
$tmopm = date("d m y - h:i:s",$pm[2]);
echo " <small>$tmopm<br/>";

echo parsepm($pm[1], $sid);


echo "</small>";
echo "<br/>--------------<br/>";
}
echo "</p><p align=\"center\">";
if($page>1)
{
$ppage = $page-1;
echo "<a href=\"inbox.php?action=dialog&amp;page=$ppage&amp;sid=$sid&amp;who=$who\">«PREV</a> ";
}
if($page<$num_pages)
{
$npage = $page+1;
echo "<a href=\"inbox.php?action=dialog&amp;page=$npage&amp;sid=$sid&amp;who=$who\">Next»</a>";
}
echo "<br/>$page/$num_pages<br/>";
if($num_pages>2)
{
$rets = "<form action=\"inbox.php\" method=\"get\">";
$rets .= "Jump to page: <input name=\"page\" format=\"*N\" size=\"3\"/><br/>";
$rets .= "<input type=\"submit\" value=\"GO\"/>";
$rets .= "<input type=\"hidden\" name=\"action\" value=\"$action\"/>";
$rets .= "<input type=\"hidden\" name=\"sid\" value=\"$sid\"/>";
$rets .= "<input type=\"hidden\" name=\"who\" value=\"$who\"/>";
$rets .= "</form>";
echo $rets;
}
}else{
echo "<p align=\"center\">";
echo "NO DATA";
}
echo "<br/><br/><a href=\"rwdpm.php?action=dlg&amp;sid=$sid&amp;who=$who\">Download</a><br/><small>only first 50 messages</small><br/>";
echo "<a href=\"inbox.php?action=main&amp;sid=$sid\">Back to inbox</a><br/>";
$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";
echo xhtmlfoot();
}
else{
addonline(getuid_sid($sid),"Lost in inbox lol","");
$pstyle = gettheme($sid);
echo xhtmlhead("Inbox",$pstyle);
echo "<p align=\"center\">";
echo "I don't know how did you get into here, but there's nothing to show<br/><br/>";
$thid = mysql_fetch_array(mysql_query("SELECT themeid FROM ibwf_users WHERE id='".$uid."'"));
$themeimageset = mysql_fetch_array(mysql_query("SELECT themedir FROM ibwf_iconset WHERE id='".$thid[0]."'")); 
echo "<a href=\"index.php?action=main&amp;sid=$sid\"><img src=\"images/themes/$themeimageset[0]/home.gif\" alt=\"*\"/>";
echo "Home</a>";
echo "</p>";
echo xhtmlfoot();
}

?>