Location: PHPKode > projects > Akasha > mailbox.php
<?

	include ("includes/global.inc"); 	// Global Variables
	include ("includes/functions.inc"); 	// Global Functions

if ($akashaID == $ID) {
	$mailbox = $mbox_id;

	if ($mbox_id != 'inbox') {
		$auth_user = 1000;
		$auth_user = getUserIDMbox( $mbox_id );
		$user_id = findUserByHash($ID);
		if ($user_id != $auth_user) {
			Header("Location: main.php?error_code=1");		
		}
	}

	include ("includes/head.inc"); 					// Standard Headers
	include ("stylesheets/homestyle.inc"); 			// Stylesheets

function mychop($thistring,$length) {
	$result="";
	$mystring=trim($thistring);
	if (strlen($mystring)>$length) {
  	$result=substr($mystring,0,$length);
		$result = "$result...";
  }else {
  	$result=$mystring;
  }
	return($result);
}

function listinbox($username,$password) 
{
   	global $seperator,$ID,$top,$mbox_id;
   	global $domain;

   	$mbox = imap_open("{".$domain."/pop3:110}INBOX", "$username", "$password");

	if ($mbox) {
		$mboxstatus=imap_check($mbox);
		$num_messages=$mboxstatus->Nmsgs;
		$headers = array();
		$headers=imap_headers($mbox);
		if ($num_messages == 0) {
			echo "          <tr>\n";
	    	echo "            <td colspan='5' align='center'>\n";
			echo "							&nbsp;<br><b><font color='#304167'>no messages</font></b>\n";
     		echo "            </td>\n";
     		echo "          </tr>\n";
		}
		if ($top >= $num_messages) {
			$top = $num_messages;
			$bottom = $num_messages - $seperator +1;
		}
		if ($top <= 0) {
			$top = $num_messages;
			$bottom = $num_messages - $seperator +1;
		} else {
			$bottom = $top - $seperator +1;
		}
		if ($bottom <= 0) {
			$bottom = 1;
		}

		for ($i = $top; $i>=$bottom;$i = $i -1) {
			$size=$headers[$i-1];
  	 		$size=ereg_replace(".*\(","",$size);
  	 		$size=ereg_replace(" .*$"," ",$size);
  	 		$htmlsize=ceil($size/1024). "K";
			$msg_header=imap_header($mbox,$i);
		 	$date=ereg_replace(" ","&nbsp;", date("Y M d - H:i",$msg_header->udate));
    		$htmlfrom1	=htmlspecialchars(decode_mime_string($msg_header->fromaddress));
			$htmlfrom = mychop($htmlfrom1,25);
    		$mysubject	= decode_mime_string($msg_header->subject);
    		$mysubject	= htmlspecialchars($mysubject);
    		$mysubject	=mychop($mysubject,28);
    		if ( strlen($mysubject) <= 0 ) {
    			$mysubject="No Subject";
    		}
    		$messageno=trim($msg_header->Msgno);
			$urlfrom = rawurlencode($htmlfrom1);
			$urlto = rawurlencode($htmlto);
  	  		echo "          <tr>\n";
	    	echo "            <td width='3%' bgcolor='#E3E7E8'>\n";
    		echo "              <font color='#000000'>\n";
     		echo "              <input type='checkbox' name='chk[]' value='$messageno'>\n";
     		echo "            </font></td>\n";
     		echo "            <td width='18%' bgcolor='#E3E7E8' nowrap><a href='new_message.php?ID=$ID&message_id$messageno&mbox_id=inbox&to=$urlfrom'>$htmlfrom</a>&nbsp;&nbsp;</td>\n";
   			echo "            <td width='56%' bgcolor='#E3E7E8' nowrap><a href='message_view.php?ID=$ID&message_id=$messageno&mbox_id=inbox'>$mysubject</a>&nbsp;&nbsp;</td>\n";
     		echo "            <td width='16%' bgcolor='#E3E7E8' nowrap>$date</td>\n";
     		echo "            <td width='7%' bgcolor='#E3E7E8' nowrap align='center'>$htmlsize</td>\n";
     		echo "          </tr>\n";
		}
  	
		echo "        </table>\n";
  		echo "        <div align='right'><b><font color='#304167'>Total Message Count : $num_messages</font></b></div>\n";
  		echo "      </form>\n";
  		echo "      <p>&nbsp;\n";
  		echo "      </p>\n";
  		echo "      </td>\n";
  		echo "    <td valign='top' width='10'>&nbsp;</td>\n";
  		echo "  </tr>\n";
  		echo "</table>\n";


		$how_many = calculateHowManyPages($num_messages);

		if ($how_many !=1) {
  			echo "<div align='center'>\n";
  			$tmptop = $num_messages;
  			for ($j=$how_many ; $j>0 ; $j = $j-1) {
  				$tmpbottom = $tmptop - $seperator +1;
  				if ($tmpbottom <= 0) {
  					$tmpbottom = 1;
  				}
  				if ($tmptop != $tmpbottom) {
  					echo "[ <a href='mailbox.php?ID=$ID&mbox_id=$mbox_id&top=$tmptop' class='stil9boldlink'>$tmptop-$tmpbottom</a> ] ";
  				} else {
  					echo "[ <a href='mailbox.php?ID=$ID&mbox_id=$mbox_id&top=$tmptop' class='stil9boldlink'>$tmptop</a> ]";
  				}
  				$tmptop = $tmpbottom -1;
  			}
  			echo "</div>\n";
		}
	} else {
		Header("Location: main.php?error_code=2");		
		die;
	}		
	imap_close($mbox);
	return $top;
}

function listmbox($username,$password,$mbox_id) 
{
	global $seperator,$ID,$top,$dbname;

	$user_id = findUserByHash($ID);
   	$query = "select count(*) as cnt from tblMessages where mbox_id = $mbox_id and user_id = $user_id";
   	$result = mysql_db_query("$dbname",$query);
   	if($result) {
      	$num_messages = @mysql_result( $result, 0, "cnt" );
	}
   	$headers = array();
   	$query = "select message_id from tblMessages where mbox_id = $mbox_id and user_id=$user_id order by message_id asc";
   	$result = mysql_db_query("$dbname",$query);
   	while( list( $message_id ) = mysql_fetch_row( $result ) ) {
	   	$headers[] = $message_id;
	}
	if ($num_messages == 0) {
      	echo "          <tr>\n";
	   	echo "            <td colspan='5' align='center'>\n";
		echo "							&nbsp;<br><b><font color='#304167'>no messages</font></b>\n";
   		echo "            </td>\n";
   		echo "          </tr>\n";
	}
	if ($top >= $num_messages) {
		$top = $num_messages;
		$bottom = $num_messages - $seperator +1;
	}
	if ($top <= 0) {
		$top = $num_messages;
		$bottom = $num_messages - $seperator +1;
	} else {
		$bottom = $top - $seperator +1;
	}
	if ($bottom <= 0) {
		$bottom = 1;
	}
   	$query = "select mbox_tip from tblMailBoxes where mbox_id = $mbox_id and user_id = $user_id";
   	$result = mysql_db_query("$dbname",$query);
   	if( $result ) {
      	$mbox_tip = @mysql_result( $result, 0, "mbox_tip" );
   }
	for( $i = $top; $i>=$bottom; $i-- ) {
		$messageno = $headers[$i-1];
      	$query = "select * from tblMessages where mbox_id = $mbox_id and user_id = $user_id and message_id=$messageno";
  	   	$result = mysql_db_query("$dbname",$query);
	   	while ($r = @mysql_fetch_array($result)) {
		   	$message_id = $r["message_id"];
			$htmlfrom1 = $r["header_from"];
			$htmlto1 = $r["header_to"];
			$mysubject = $r["header_subject"];
    	   	if ( strlen($mysubject) <= 0 ) {
    		   	$mysubject="No Subject";
    	   	}
		   	$mysubject	=mychop($mysubject,28);
		   	$htmlfrom	=mychop($htmlfrom1,28);
		   	$htmlto		=mychop($htmlto1,28);
			$date = $r["header_date"];
			$htmlsize = "";
         	$urlfrom = rawurlencode(stripslashes($htmlfrom1));
         	$urlto = rawurlencode($htmlto1);
         	if ($mbox_tip == 1) {
 	         	echo "          <tr>\n";
  	         	echo "            <td width='3%' bgcolor='#E3E7E8'>\n";
            	echo "              <font color='#000000'>\n";
            	echo "              <input type='checkbox' name='chk[]' value='$messageno'>\n";
    	      	echo "            </font></td>\n";
       	   		echo "            <td width='18%' bgcolor='#E3E7E8' nowrap><a href='new_message.php?ID=$ID&message_id$messageno&mbox_id=$mbox_id&to=$urlto'>$htmlto</a>&nbsp;&nbsp;</td>\n";
     	      	echo "            <td width='56%' bgcolor='#E3E7E8' nowrap><a href='message_viewDB.php?ID=$ID&message_id=$messageno&mbox_id=$mbox_id'>$mysubject</a>&nbsp;&nbsp;</td>\n";
            	echo "            <td width='16%' bgcolor='#E3E7E8' nowrap>$date</td>\n";
            	echo "          </tr>\n";
         	} else {
    	      	echo "          <tr>\n";
  	         	echo "            <td width='3%' bgcolor='#E3E7E8'>\n";
          		echo "              <font color='#000000'>\n";
          		echo "              <input type='checkbox' name='chk[]' value='$messageno'>\n";
          		echo "            </font></td>\n";
    	      	echo "            <td width='18%' bgcolor='#E3E7E8' nowrap><a href='new_message.php?ID=$ID&message_id$messageno&mbox_id=$mbox_id&to=$urlfrom'>$htmlfrom</a>&nbsp;&nbsp;</td>\n";
  		      	echo "            <td width='56%' bgcolor='#E3E7E8' nowrap><a href='message_viewDB.php?ID=$ID&message_id=$messageno&mbox_id=$mbox_id'>$mysubject</a>&nbsp;&nbsp;</td>\n";
       	   		echo "            <td width='16%' bgcolor='#E3E7E8' nowrap>$date</td>\n";
            	echo "          </tr>\n";
         	}
		}
	}
 	echo "        </table>\n";
 	echo "        <div align='right'><b><font color='#304167'>Total Message Count : $num_messages</font></b></div>\n";
 	echo "      </form>\n";
 	echo "      </td>\n";
 	echo "    <td valign='top' width='10'>&nbsp;</td>\n";
 	echo "  </tr>\n";
 	echo "</table>\n";
	$how_many = calculateHowManyPages($num_messages);
	if ($how_many !=1) {
  		echo "<div align='center'>\n";
  		$tmptop = $num_messages;
  		for ($j=$how_many ; $j>0 ; $j = $j-1) {
  			$tmpbottom = $tmptop - $seperator +1;
  			if ($tmpbottom <= 0) {
  				$tmpbottom = 1;
  			}
  			if ($tmptop != $tmpbottom) {
  				echo "[ <a href='mailbox.php?ID=$ID&mbox_id=$mbox_id&top=$tmptop' class='stil9boldlink'>$tmptop-$tmpbottom</a> ] ";
  			} else {
  				echo "[ <a href='mailbox.php?ID=$ID&mbox_id=$mbox_id&top=$tmptop' class='stil9boldlink'>$tmptop</a> ]";
  			}
  			$tmptop = $tmpbottom -1;
  		}
  		echo "</div>\n";
	}
	return $top;
}


if ($giris != 1) {
	$giris = 0;
}
?>

<script language="JavaScript">
<!--
function submitonce(theform){
	if (document.all||document.getElementById){
		for (i=0;i<theform.length;i++){
			var tempobj=theform.elements[i]
			if(tempobj.type.toLowerCase()=="submit") {
				tempobj.disabled=true
			}
		}
	}
}
//-->
</script>

<script language="JavaScript">
<!--
function loadframes() {
	parent.side.location = "navbar.php?ID="+loadframes.arguments[0];
	parent.upper.location = "top2.php?ID="+loadframes.arguments[0];
}
//-->
</script>

<script language="JavaScript">
<!--
function ToggleAll(checked) {
  len = document.mesajlar.elements.length;
  var i=0;
  for(i=0; i < len; i++) {
    document.mesajlar.elements[i].checked=checked;
  }
}
//-->
</script>

<? echo "<meta http-equiv='refresh' content='180; url=mailbox.php?ID=$ID&mbox_id=$mbox_id&top=$top'>\n"; ?>
</head>
<body onLoad="loadframes('<? echo $ID ?>','<? echo $giris ?>');" bgcolor='#FFFFFF' text='#000000' link='#3457A9' vlink='#3457A9' alink='#009966'>
<?
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' height='200'>\n";
echo "  <tr>\n";
echo "    <td valign='top' align='left'>\n";

	$mailadress = getUserMailAdress($ID);	
	$username =  getUsername($ID);
	$password = getPassword($ID);


$user_id = findUserByHash($ID);

if ($mbox_id == "inbox") {
	$mboxtip = 0;
	$postakutusu_adi = "Inbox";
} else {
	$postakutusu_adi = getMboxName($mbox_id);
	$mboxtip = getMboxTip($mbox_id);
}

echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>\n";
echo "        <tr bgcolor='#2B3D61'>\n";
echo "          <td><b><font color='#DCD7CB'><i>$postakutusu_adi</i></font></b></td>\n";
if ($mboxtip == 2) {
	echo "				<td align='right'><a href='empty_trash.php?ID=$ID&mbox_id=$mbox_id'><font color='#DCD7CB'><b><i>Empty Trash</i></b></font></a></td>\n";
}
echo "        </tr>\n";
echo "</table>\n";
echo "      <form method='post' action='message_process.php' name='mesajlar' onSubmit='submitonce(this)'>\n";
echo "				<input type='hidden' name='ID' value='$ID'>\n";
echo "				<input type='hidden' name='mbox_id' value='$mbox_id'>\n";
if ($giris !=1) {
	if ($giris !=0) {	
		echo "				<input type='hidden' name='top' value='$top'>\n";
	}
}
echo "        <table width='100%' border='0' cellspacing='2' cellpadding='0' class='stil9'>\n";
echo "          <tr align='right'>\n";
echo "            <td colspan='5'>\n";
echo "              <table width='100%' border='0' cellspacing='0' cellpadding='0'>\n";
echo "                <tr>\n";
echo "                  <td valign='bottom'><a href='javascript:ToggleAll(true)' class='stil8'>select all</a> | <a href='javascript:ToggleAll(false)' class='stil8'>deselect all</a></td>\n";
echo "                  <td align='right'>Move Selected Messages to \n";
echo "                    <select name='slcmbox'>\n";

$query = "select mbox_id,mbox_tip,mboxname from tblMailBoxes where user_id = $user_id";
$res = mysql_db_query("$dbname",$query);

while( list( $mbox_idX, $mbox_tip, $mboxname ) = @mysql_fetch_row( $res ) ) {
   if( $mbox_idX != $mbox_id && $mbox_tip != 1 ) {
  	   if ($mbox_tip == 2) {
    	   echo " 	            <option value='$mbox_idX' selected>$mboxname</option>\n";
   		} else {
      		echo " 	            <option value='$mbox_idX'>$mboxname</option>\n";
   		}
	}
}

echo "                    </select>\n";
echo "                    </td><td  width='5%' valign='middle'>\n";
echo "                    <input type='image' src='images/ok.gif' width='25' height='25' align='middle'>\n";
echo "                  </td>\n";
echo "                </tr>\n";
echo "              </table>\n";
echo "            </td>\n";
echo "          </tr>\n";
echo "          <tr>\n";

$query = "select mbox_tip from tblMailBoxes where mbox_id = $mbox_id and user_id = $user_id";
$result = mysql_db_query("$dbname",$query);
if($result) {	
	$mbox_tip = @mysql_result( $result, 0, "mbox_tip" );
}

if ($mbox_tip ==1) {
	echo "            <td width='18%' bgcolor='#DCD7CB'><font color='#2B3D61'><b>&nbsp</b></font></td>\n";
	echo "            <td width='18%' bgcolor='#DCD7CB'><font color='#2B3D61'><b>To</b></font></td>\n";
} else {
	echo "            <td width='18%' bgcolor='#DCD7CB'><font color='#2B3D61'><b>&nbsp</b></font></td>\n";
	echo "            <td width='18%' bgcolor='#DCD7CB'><font color='#2B3D61'><b>From</b></font></td>\n";
}
echo "            <td width='56%' bgcolor='#DCD7CB'><font color='#2B3D61'><b>Subject</b></font></td>\n";
echo "            <td width='16%' bgcolor='#DCD7CB'><font color='#2B3D61'><b>Date</b></font></td>\n";

if ($mailbox == "inbox") {
	echo "            <td width='7%' bgcolor='#DCD7CB'><font color='#2B3D61'><b>Size</b></font></td>\n";
	echo "          </tr>\n";

	$top = listinbox($username,$password);
} else {
	$auth_user = getUserIDMbox($mailbox);
	if ($auth_user == $user_id) {
		$top = listmbox($username,$password,$mailbox);		
	} else {
		Header("Location: main.php?error_code=1");
	}
}

echo "</body>\n";
echo "</html>\n";

} else {
		Header("Location: main.php?error_code=1");
}

?>
Return current item: Akasha