View file chat spall script/web/inbox.php

File size: 27.56Kb
<?
// -------------------------------------------------------------------------------------
$EnableGZipEncoding = true;
// -------------------------------------------------------------------------------------
// Helper function to detect if GZip is supported by client!
// If not supported the tricks are pointless
function acceptsGZip(){
    $accept = str_replace(" ","",
        strtolower($_SERVER['HTTP_ACCEPT_ENCODING'])
    );
    $accept = explode(",",$accept);
    return in_array("gzip",$accept);
}
// -------------------------------------------------------------------------------------
function playWithHtml($OutputHtml){
    // This will mess up HTML code like my site has done!
    // View the source to understand! All ENTERs are removed.
    // If your site has PREformated code this will break it!
    // Use regexp to find it and save it and place it back ...
    // or just uncomment the next line to keep enters
    // return $OutputHtml;
    return preg_replace("/\s+/"," ",$OutputHtml);
}
// -------------------------------------------------------------------------------------
function obOutputHandler($OutputHtml){
    global $EnableGZipEncoding;
    //-- Play with HTML before output
    $OutputHtml = playWithHtml($OutputHtml);
    //-- If GZIP not supported compression is pointless.
    // If headers were sent we can not signal GZIP encoding as
    // we will mess it all up so better drop it here!
    // If you disable GZip encoding to use plain output buffering we stop here too!
    if(!acceptsGZip() || headers_sent() || !$EnableGZipEncoding) return $OutputHtml;
    //-- We signal GZIP compression and dump encoded data
    header("Content-Encoding: gzip");
    return gzencode($OutputHtml);
}
// This code has to be before any output from your site!
// If output exists uncompressed HTML will be delivered!
ob_start("obOutputHandler");
// -------------------------------------------------------------------------------------
?>
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
//header('Content-type: application/vnd.wap.xhtml+xml'); 
echo "<?xml version=\"1.0\"?>";
echo "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">";
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
include("config.php");
include("core.php");
connectdb();
$action = $_GET["action"];
$sid = $_GET["sid"];
$page = $_GET["page"];
$who = mysql_real_escape_string( $_GET["who"]);
$pmid = mysql_real_escape_string( $_GET["pmid"]);
$sitename = mysql_fetch_array(mysql_query("SELECT value FROM ibwf_settings WHERE name='sitename'"));
$sitename = $sitename[0];
$uid = getuid_sid($sid);
$theme = mysql_fetch_array(mysql_query("SELECT theme FROM ibwf_users WHERE id='".$uid."'"));
$lastloc=$_GET["lstloc"];

if($lastloc=="cht"){
	$rid= $_GET["rid"];
    $rooms = mysql_fetch_array(mysql_query("SELECT id, name FROM ibwf_rooms WHERE id='".$rid."'"));
    $rname = $rooms[1];
}

if(islogged($sid)==false)
{
      echo "<head>";
      echo "<title>Error!!!</title>";
      
      echo "</head>";
      echo "<body>";
      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 "</body>";
      echo "</html>";
      exit();
}
$uid = getuid_sid($sid);
if(isbanned($uid))
    {
      echo "<head>";
      echo "<title>Error!!!</title>";
      echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
      echo "</head>";
      echo "<body>";
      echo "<p align=\"center\">";
      echo "<img src=\"../images/notok.gif\" alt=\"x\"/><br/>";
      echo "<b>You are Banned</b><br/><br/>";
      $banto = mysql_fetch_array(mysql_query("SELECT timeto, pnreas, exid FROM ibwf_penalties WHERE uid='".$uid."' AND penalty='1' OR uid='".$uid."' AND penalty='2'"));
	$banres = mysql_fetch_array(mysql_query("SELECT lastpnreas FROM ibwf_users WHERE id='".$uid."'"));
      $remain = $banto[0]- time();
      $rmsg = gettimemsg($remain);
      echo "<b>Time Left: </b>$rmsg<br/>";
      $nick = getnick_uid($banto[2]);
	echo "<b>By: </b>$nick<br/>";
	echo "<b>Reason: </b>$banto[1]";
      //echo "<a href=\"index.php\">Login</a>";
      echo "</p>";
      echo "</body>";
      echo "</html>";
      exit();
    }

if($action=="sendpm")
{
$whonick = getnick_uid($who);
  addonline(getuid_sid($sid),"Sending Inbox to $whonick","inbox.php?action=main");
      echo "<head>";
      echo "<title>Inbox</title>";
      
      echo "</head>";
      echo "<body>";
  echo "<p align=\"center\">";
  $whonick = getnick_uid($who);
  echo "Send Inbox 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\" name=\"send\" value=\"Send\"></form>";
  echo "<br/><br/>";
  echo "<br/><a accesskey=\"6\" href=\"inbox.php?action=main&amp;sid=$sid\">Inbox</a><br/>";
  echo "<a accesskey=\"7\" href=\"lists.php?action=buds&amp;sid=$sid\">BuddyList</a><br/>";
  echo "<a accesskey=\"8\" href=\"index.php?action=chat&amp;sid=$sid\">Chat</a><br/>";
  
  echo "<a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
  echo "</p>";
    echo "</body>";

}
else if($action=="sendpopup")
{
$whonick = getnick_uid($who);
  addonline(getuid_sid($sid),"Sending Popup $whonick","lists.php?action=buds");
      echo "<head>";
      echo "<title>Send Popup</title>";
      echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
      echo "</head>";
      echo "<body>";
  echo "<p align=\"center\">";
  if (!arebuds($uid, $who))
 {
    echo "$whonick is not in ur buddy list<br/><br/>";
    echo "<a accesskey=\"9\" href=\"lists.php?action=buds&amp;sid=$sid\">BuddyList</a><br/>";
    echo "<a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
    echo "</p></body></html>";
    exit;
  }else{
  $whonick = getnick_uid($who);
  echo "Send Popup to $whonick<br/><br/>";
  echo "<form action=\"inbxproc.php?action=sendpopup&amp;who=$who&amp;sid=$sid\" method=\"post\">";
  echo "<input name=\"pmtext\" maxlength=\"500\"/><br/>";
  echo "<input type=\"Submit\" name=\"send\" value=\"Send\"></form>";
  echo "<a accesskey=\"6\" href=\"inbox.php?action=main&amp;sid=$sid\">Inbox</a><br/>";
  echo "<a accesskey=\"7\" href=\"lists.php?action=buds&amp;sid=$sid\">BuddyList</a><br/>";
  echo "<a accesskey=\"8\" href=\"index.php?action=chat&amp;sid=$sid\">Chat</a><br/>";
  
  echo "<a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
  echo "</p>";
    echo "</body>";
}
}
else if($action=="sendto")
{
  addonline(getuid_sid($sid),"Sending Inbox","inbox.php?action=$action");
  echo "<head>";
  echo "<title>Send Inbox</title>";
  echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
  echo "</head>";
  echo "<body>";
  echo "<p align=\"center\">";
  $whonick = getnick_uid($who);
  echo "Send Inbox 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\" name=\"send\" value=\"Send\"></form>";
  echo "<br/><br/>";
  echo "<br/><a accesskey=\"6\" href=\"inbox.php?action=main&amp;sid=$sid\">Inbox</a><br/>";
  echo "<a accesskey=\"7\" href=\"lists.php?action=buds&amp;sid=$sid\">BuddyList</a><br/>";
  echo "<a accesskey=\"8\" href=\"index.php?action=chat&amp;sid=$sid\">Chat</a><br/>";
  
  echo "<a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
  echo "</p>";
    echo "</body>";

}
else if($action=="popupto")
{
  addonline(getuid_sid($sid),"Sending Popup","inbox.php?action=$action");
  echo "<head>";
  echo "<title>Send PPopup</title>";
  echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
  echo "</head>";
  echo "<body>";
  echo "<p align=\"center\">";
  $whonick = getnick_uid($who);
  echo "Send Popup To:<br/>";
  echo "<form action=\"inbxproc.php?action=sendpopup&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\" name=\"send\" value=\"Send\"></form>";
  echo "<a accesskey=\"6\" href=\"inbox.php?action=main&amp;sid=$sid\">Inbox</a><br/>";
  echo "<a accesskey=\"7\" href=\"lists.php?action=buds&amp;sid=$sid\">BuddyList</a><br/>";
  echo "<a accesskey=\"8\" href=\"index.php?action=chat&amp;sid=$sid\">Chat</a><br/>";
  
  echo "<a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
  echo "</p>";
  echo "</body>";
}
else if($action=="popdialog")
{
    addonline(getuid_sid($sid),"Viewing Popups","inbox.php?action=$action");
  echo "<head>";
  echo "<title>Popup Dialog</title>";
  echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
  echo "</head>";
  echo "<body>";
  $uid = getuid_sid($sid);
  if($page=="" || $page<=0)$page=1;
    $myid = getuid_sid($sid);
    $pms = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_popups WHERE touid=$uid ORDER BY timesent"));
    echo mysql_error();
    $num_items = $pms[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)
    {
      echo "<p>";
      $pms = mysql_query("SELECT byuid, text, timesent FROM ibwf_popups WHERE touid=$uid ORDER BY timesent DESC 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=popdialog&amp;page=$ppage&amp;sid=$sid\">&#171;Prev</a> ";
    }
    if($page<$num_pages)
    {
      $npage = $page+1;
      echo "<a href=\"inbox.php?action=popdialog&amp;page=$npage&amp;sid=$sid\">Next&#187;</a>";
    }
    echo "<br/>$page/$num_pages<br/>";
    if($num_pages>2)
    {
	$rets = "<form action=\"inbox.php\" method=\"get\">";
      $rets .= "<input name=\"page\" style=\"-wap-input-format: '*N'\" size=\"2\"/>";
      $rets .= "<input type=\"hidden\" name=\"action\" value=\"$action\">";
      $rets .= "<input type=\"hidden\" name=\"sid\" value=\"$sid\">";
      $rets .= "<input type=\"Submit\" name=\"Submit\" Value=\"Go To Page\"></form>";
      echo $rets;
      }
      }else{
        echo "<p align=\"center\">";
        echo "NO DATA";
      }
  
  
  echo "<a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
  echo "</p></body>";
  }
//////////////////////////////////////////////////////////////////////////////////////
else if($action=="main")
{
  addonline(getuid_sid($sid),"User Inbox","inbox.php?action=$action");
  echo "<head>";
  echo "<title>Inbox</title>";
  echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
  echo "</head>";
  echo "<body>";
  echo "<p align=\"center\">";
  echo "<b></b><a accesskey=\"1\" href=\"inbox.php?action=sendto&amp;sid=$sid\">[Send New Msg]</a>";
  echo "</p>";
  echo "<p align=\"left\">";

    $view = $_GET["view"];
     //////ALL LISTS SCRIPT <<
    if($view=="")$view="all";
    if($page=="" || $page<=0)$page=1;
    $myid = getuid_sid($sid);
    $doit=false;
    $num_items = getpmcount($myid,$view); //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
    if($view=="all")
  {
    $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.starred='0'
            ORDER BY b.timesent DESC
            LIMIT $limit_start, $items_per_page
    ";
  }else if($view=="snt")
  {
    $sql = "SELECT
            a.name, b.id, b.touid, b.unread, b.starred FROM ibwf_users a
            INNER JOIN ibwf_private b ON a.id = b.touid
            WHERE b.byuid='".$myid."'
            ORDER BY b.timesent DESC
            LIMIT $limit_start, $items_per_page
    ";
  }else if($view=="str")
  {
    $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.starred='1'
            ORDER BY b.timesent DESC
            LIMIT $limit_start, $items_per_page
    ";
  }else if($view=="urd")
  {
    $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
    ";
  }
    
    $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=\"-\"/>";
        }
      }
      if($lastloc=="cht"){
      $lnk = "<a href=\"inbox.php?action=readpm&amp;pmid=$item[1]&amp;sid=$sid&amp;lstloc=cht&amp;rid=$rid\">$iml $item[0]</a>";
	}else{
	      $lnk = "<a href=\"inbox.php?action=readpm&amp;pmid=$item[1]&amp;sid=$sid\">$iml $item[0]</a>";
	}
      echo "$lnk<br/>";
    }
    echo "</p>";
    
    echo "<p align=\"center\">";
    
      $npage = $page+1;

    if($page>1)
    {
      $ppage = $page-1;
      if($lastloc=="cht"){
echo "<a href=\"inbox.php?action=main&amp;page=$ppage&amp;sid=$sid&amp;view=$view$exp&amp;lstloc=cht&amp;rid=$rid\">&#171;Prev</a> ";
	}else{
echo "<a href=\"inbox.php?action=main&amp;page=$ppage&amp;sid=$sid&amp;view=$view$exp\">&#171;Prev</a> ";
	}
      
    }
    if($page<$num_pages)
    {
      $npage = $page+1;
      if($lastloc=="cht"){
      echo "<a href=\"inbox.php?action=main&amp;page=$npage&amp;sid=$sid&amp;view=$view$exp&amp;lstloc=cht&amp;rid=$rid\">Next&#187;</a>";
	}else{
	echo "<a href=\"inbox.php?action=main&amp;page=$npage&amp;sid=$sid&amp;view=$view$exp\">Next&#187;</a>";
	}
    }
    echo "</p>";
    echo "<p align=\"center\">";
    echo "$page/$num_pages";
    echo "</p>";
    echo "<p align=\"center\">";
    if($num_pages>2)
    {
      if($lastloc=="cht"){
	    $rets = "<form action=\"inbox.php&amp;lstloc=cht&amp;rid=$rid\" method=\"get\">";
	}else{
	    $rets = "<form action=\"inbox.php\" method=\"get\">";
	}
	$rets .= "<input name=\"page\" style=\"-wap-input-format: '*N'\" size=\"3\"/>";
	$rets .= "<input type=\"hidden\" name=\"sid\" value=\"$sid\"/>";
	$rets .= "<input type=\"hidden\" name=\"action\" value=\"$action\"/>";
	$rets .= "<input type=\"hidden\" name=\"view\" value=\"$view\"/>";
	$rets .= "<input type=\"Submit\" value=\"Go To Page\" Name=\"Submit\"/></form>";

        echo $rets;
    }
    
     echo "</p>";
echo "<form action=\"inbxproc.php?action=proall&amp;sid=$sid\" method=\"post\">";
      echo "Delete: <select name=\"pmact\">";
  echo "<option value=\"ust\">Unstarred</option>";
  echo "<option value=\"red\">Read</option>";
  echo "<option value=\"all\">All</option>";
  echo "</select>";
echo "<input type=\"submit\" value=\"GO\"/>";
echo "</form>";
     echo "<p align=\"center\">";
    }else{
      echo "<p align=\"center\">";
      echo "You have no Private Messages<br/><br/>";
      
    }
  ////// UNTILL HERE >>

  if($lastloc=="cht")
  {
  echo "<a accesskey=\"1\" href=\"chat.php?sid=$sid&amp;rid=$rid\">Back to $rname</a><br/>";
  }
  echo "<a accesskey=\"2\" href=\"inbox.php?action=main&amp;time=date('dmHis')&amp;sid=$sid\">Refresh</a><br/>";
  echo "<a href=\"index.php?action=online&amp;sid=$sid\">[Onl users(".getnumonline().")]</a><br/>";
  if($view=="all"){
  $count = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_users a INNER JOIN ibwf_private b ON a.id = b.touid WHERE b.byuid='".$myid."'"));
  if($lastloc=="cht"){
  echo "<a accesskey=\"4\" href=\"inbox.php?action=$action&amp;sid=$sid&amp;view=snt&amp;lstloc=cht&amp;rid=$rid\">Outbox($count[0])</a><br/>";
  }else{
  echo "<a accesskey=\"4\" href=\"inbox.php?action=$action&amp;sid=$sid&amp;view=snt\">Outbox($count[0])</a><br/>";
  }
  }
  if($view=="all"){
  $count = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_users a INNER JOIN ibwf_private b ON a.id = b.byuid WHERE b.touid='".$myid."' AND b.starred='1'"));
  if($lastloc=="cht"){
  echo "<a accesskey=\"5\" href=\"inbox.php?action=$action&amp;sid=$sid&amp;view=str&amp;lstloc=cht&amp;rid=$rid\">Starred($count[0])</a><br/>";
  }else{
  echo "<a accesskey=\"5\" href=\"inbox.php?action=$action&amp;sid=$sid&amp;view=str\">Starred($count[0])</a><br/>";
  echo "<a accesskey=\"4\" href=\"inbox.php?action=popdialog&amp;sid=$sid\">Popup Dialog</a><br/>";
  
  }
  }else{
  if($lastloc=="cht"){
  echo "<a accesskey=\"6\" href=\"inbox.php?action=main&amp;sid=$sid&amp;lstloc=cht&amp;rid=$rid\">Inbox</a><br/>";
  }else{
  echo "<a accesskey=\"6\" href=\"inbox.php?action=main&amp;sid=$sid\">Inbox</a>|";
  }
  }
    
  echo "<a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a><br/>";
include("admob.php");
  echo "</p>";
  echo "</body>";
}
/////////////////////////////////////////////////////////////////////////
else if($action=="readpm")
{
$pminfo = mysql_fetch_array(mysql_query("SELECT byuid FROM ibwf_private
WHERE id='".$pmid."'"));
 addonline(getuid_sid($sid),"Reading PM from
".getnick_uid($pminfo[0])."","");
  
  echo "<head>";
  echo "<title>Inbox</title>";
  echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
  echo "</head>";
  echo "<body>";
echo "<p align=\"center\">";
   
  echo ("Read PM");
  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];
  $tremain = time()-$tmstamp;
  //$tmdt = date("d m Y - H:i:s", $tmstamp);
  $tmdt = gettimemsg($tremain)." ago"; ////////////////////this is the time thing
  echo "<i>$tmdt</i><br/><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("/credits","<a href=\"index.php?action=viewtpc&amp;sid=$sid&amp;tid=2040\">How to Earn Much Credits??</a>", $pmtext);
$pmtext = str_replace("/features","<a href=\"index.php?action=viewfrm&amp;sid=$sid&amp;fid=189\">New Features!</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 "<br/>";
   $pminfo = mysql_fetch_array(mysql_query("SELECT text, byuid, touid, reported FROM ibwf_private WHERE id='".$pmid."'"));
	echo "<form action=\"inbxproc.php?action=sendpm&amp;who=$pminfo[1]&amp;sid=$sid\" method=\"post\">";
  echo "<input name=\"pmtext\" maxlength=\"500\"/><br/>";
  echo "<input type=\"submit\" value=\"Fast Reply &#187;\"/>";
echo "</form>";
  echo "</p>";
  echo "<p align=\"center\"><br/><br/>";
  
   if($page=="" || $page<=0)$page=1;
    $myid = getuid_sid($sid);
    $doit=false;
    $num_items = getpmcount($myid); //changable
    $items_per_page= 1
;
    $num_pages = ceil($num_items/$items_per_page);
    if($page>$num_pages)$page= $num_pages;
    $limit_start = ($page-1)*$items_per_page;
 
   
$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 
            LIMIT $limit_start, $items_per_page
    ";

     $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=\"../mages/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 "<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/><a href=\"index.php?action=chat&amp;sid=$sid\">Back to Chat</a><br/>";
    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/home.gif\" alt=\"*\"/>"; 
    echo "Home</a>";
    echo "</p>";
    
    




}else if($action=="dialog")
{
    addonline(getuid_sid($sid),"Viewing Inbox Dialog","inbox.php?action=$action");
  echo "<head>";
  echo "<title>Inbox Dialog</title>";
  echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
  echo "</head>";
  echo "<body>";
  $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\">&#171;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&#187;</a>";
    }
    echo "<br/>$page/$num_pages<br/>";
    if($num_pages>2)
    {
	$rets = "<form action=\"inbox.php\" method=\"get\">";
      $rets .= "<input name=\"page\" style=\"-wap-input-format: '*N'\" size=\"2\"/>";
      $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 .= "<input type=\"Submit\" name=\"Submit\" Value=\"Go To Page\"></form>";
      echo $rets;
      }
      }else{
        echo "<p align=\"center\">";
        echo "NO DATA";
      }
      echo "<br/><br/><b>4 </b><a accesskey=\"4\" href=\"rwdpm.php?action=dlg&amp;sid=$sid&amp;who=$who\">Download</a><br/>only first 50 messages<br/>";
           if($lastloc=="cht"){
	        echo "<br/><b>5 </b><a accesskey=\"5\" href=\"chat.php?sid=$sid&amp;rid=$rid\">Back to $rname</a><br/>";
  echo "<a accesskey=\"6\" href=\"inbox.php?action=main&amp;sid=$sid\">Inbox</a><br/>";
  echo "<a accesskey=\"7\" href=\"lists.php?action=buds&amp;sid=$sid\">BuddyList</a><br/>";
  echo "<a accesskey=\"8\" href=\"index.php?action=chat&amp;sid=$sid\">Chat</a><br/>";
 
  echo "<a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
  echo "</p></body>";
}else{
  
  
  echo "<a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
  echo "</p></body>";
}
  }
    else{
      addonline(getuid_sid($sid),"Lost in inbox lol","");
  echo "<head>";
  echo "<title>Error!!!</title>";
  echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
  echo "</head>";
  echo "<body>";
  echo "<p align=\"center\">";
  echo "I don't know how did you get into here, but there's nothing to show<br/>";
  echo "<a accesskey=\"0\" href=\"index.php?action=main&amp;sid=$sid\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
  echo "</p></body>";
}
?>
</html>