<?php
session_start();
require_once('functions.php');
require_once('config.php');
error_reporting(0);
set_time_limit(0);
if ((isset($_GET['action'])) && ($_GET['action'] != "")) {$action = $_GET['action'];} else {$action = 'none';}
if ($action != 'download')
{
include('header.php');
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10%" valign="top">
<?php
if ($boxname[0] != '') {
?>
<h3>Categories</h3>
<blockquote>
<span>
<?php
for($b=0;$b<=count($boxname);$b++){
echo "<a href=\"index.php?action=viewbox&box=$b\">".$boxname[$b]."</a><br />";
}
?>
</span>
</blockquote>
</td>
<td width="10%" valign="top">
</td>
<?php
}
}
switch ($action){
case 'viewbox' : {
if (isset($_GET['box'])) {$boxnr = $_GET['box'];}
if (isset($_GET['fp'])) {$fp=$_GET['fp'];} else {$fp=1;}
if (($fp <= 1)) {$fp=1;}
$tp=$fp+$mails_per_page-1;
//validate box number
if (($boxnr >= 0) && ($boxnr <= count($boxname)) && (isset($boxname[$boxnr])) && ($boxname[$boxnr] != "")) {//validate box number
$overview=fetchBox($boxname[$boxnr],$fp,$tp);
//debug returned info
/*
echo "<textarea name=\"output\" cols=\"100\" rows=\"20\">";
print_r($overview);
echo "</textarea>";
*/
?>
<td width="80%" valign="top">
<h3><a href="index.php?action=viewbox&box=<?php echo $boxnr; ?>"><?php echo $boxname[$boxnr]; ?> (<?php echo count($overview) ?> threads.)</a></h3>
<div align="right"><a href="index.php?action=viewbox&box=<?php echo $boxnr; ?>&fp=<?php echo $fp-$mails_per_page; ?>"><img src="./images/previous.gif" alt="Previous page" border="0" width="<?php echo $pag_img_size; ?>" height="<?php echo $pag_img_size; ?>" /></a><a href="index.php?action=viewbox&box=<?php echo $boxnr; ?>&fp=<?php echo $fp+$mails_per_page; ?>"><img src="./images/next.gif" alt="Next page" border="0" width="<?php echo $pag_img_size; ?>" height="<?php echo $pag_img_size; ?>" /></a></div>
<div>
<?php
foreach (array_reverse($overview) as $m) {
?>
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="60%"><strong><a href="index.php?action=view&box=<?php echo $boxnr; ?>&msgno=<?php echo $m->msgno; ?>"><?php echo $m->subject; ?></a></strong>
</td>
<td width="40%">
<div align="right">
Submitted on<strong> <?php echo $m->date; ?></strong>
</div>
</td>
</tr>
</table>
</div>
<?php
}
?>
</div>
<div align="right"><a href="index.php?action=viewbox&box=<?php echo $boxnr; ?>&fp=<?php echo $fp-$mails_per_page; ?>"><img src="./images/previous.gif" alt="Previous page" border="0" width="<?php echo $pag_img_size; ?>" height="<?php echo $pag_img_size; ?>" /></a><a href="index.php?action=viewbox&box=<?php echo $boxnr; ?>&fp=<?php echo $fp+$mails_per_page; ?>"><img src="./images/next.gif" alt="Next page" border="0" width="<?php echo $pag_img_size; ?>" height="<?php echo $pag_img_size; ?>" /></a></div>
</td>
<?php
}//end validate box
else error('Error : Invalid box specified.');
}break; //end of case viewbox
case 'download' : {
if (isset($_GET['box'])) {$boxnr = $_GET['box'];}
if (isset($_GET['msgno'])) {$msgno = $_GET['msgno'];}
if (isset($_GET['file'])) {$fileno = $_GET['file'];}
if (isset($_GET['filename'])) {$filename = $_GET['filename'];}
if (($boxnr >= 0) && ($boxnr <= count($boxname)) && (isset($boxname[$boxnr])) && ($boxname[$boxnr] != "")) {//validate box number
$mbox = imap_open($hostname.$boxname[$boxnr], $user,$pwd) or error(imap_last_error());
$strFileName = $filename;
$strFileType = strrev(substr(strrev($strFileName),0,4));
$ContentType = "application/octet-stream";
if ($strFileType == ".asf")
$ContentType = "video/x-ms-asf";
if ($strFileType == ".avi")
$ContentType = "video/avi";
if ($strFileType == ".doc")
$ContentType = "application/msword";
if ($strFileType == ".zip")
$ContentType = "application/zip";
if ($strFileType == ".xls")
$ContentType = "application/vnd.ms-excel";
if ($strFileType == ".gif")
$ContentType = "image/gif";
if ($strFileType == ".jpg" || $strFileType == "jpeg")
$ContentType = "image/jpeg";
if ($strFileType == ".wav")
$ContentType = "audio/wav";
if ($strFileType == ".mp3")
$ContentType = "audio/mpeg3";
if ($strFileType == ".mpg" || $strFileType == "mpeg")
$ContentType = "video/mpeg";
if ($strFileType == ".rtf")
$ContentType = "application/rtf";
if ($strFileType == ".htm" || $strFileType == "html")
$ContentType = "text/html";
if ($strFileType == ".xml")
$ContentType = "text/xml";
if ($strFileType == ".xsl")
$ContentType = "text/xsl";
if ($strFileType == ".css")
$ContentType = "text/css";
if ($strFileType == ".php")
$ContentType = "text/php";
if ($strFileType == ".asp")
$ContentType = "text/asp";
if ($strFileType == ".pdf")
$ContentType = "application/pdf";
header ("Content-Type: $ContentType");
header ("Content-Disposition: attachment; filename=$strFileName; size=$fileSize;");
// Updated oktober 29. 2005
if (substr($ContentType,0,4) == "text") {
echo imap_qprint(imap_fetchbody($mbox,$msgno,$fileno+2));
} else {
echo imap_base64(imap_fetchbody($mbox,$msgno,$fileno+2));
}
imap_close($mbox);
/*
//debug returned info
echo "<textarea name=\"output\" cols=\"100\" rows=\"20\">";
print_r($overview);
echo "</textarea>";
*/
}//end validate box
else error('Error : Invalid box specified.');
}break; //end of case download
case 'view' : {
if (isset($_GET['box'])) {$boxnr = $_GET['box'];}
if (isset($_GET['msgno'])) {$msgno = $_GET['msgno'];}
if (($boxnr >= 0) && ($boxnr <= count($boxname)) && (isset($boxname[$boxnr])) && ($boxname[$boxnr] != "")) {//validate box number
$overview=fetchMsg($boxname[$boxnr],$msgno);
?>
<td width="80%" valign="top">
<h3><a href="index.php?action=view&box=<?php echo $boxnr; ?>&msgno=<?php echo $msgno; ?>"><?php echo $overview->subject ?></a></h3>
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="60%"></td>
<td width="40%">
<div align="right">
Submitted on<strong> <?php echo $overview->date; ?></strong>
</div>
<br />
</td>
</tr>
</table>
<?php echo $overview->bodyText; ?>
<br />
<?php
if (sizeof($overview->attachments) > 0) {//has any attachments
echo "<div align=\"left\"><table>";
foreach ($overview->attachments as $att) {
$url="index.php?action=download&box=".$boxnr."&file=".$att->id."&msgno=".$overview->msgno."&filename=".urlencode($att->name);
echo "<tr><td><a href=\"".$url."\"><img src=\"./images/Download.png\" width=\"16\" height=\"16\" alt=\"Download\" border=\"0\" /> ".$att->name."</a></td><td> (".ByteSize($att->size).")</td></tr>";
}
echo "</table></div>";
}//end of has any attactments
?>
</div>
</td>
<?php
}//end of validate box
else error('Error : Invalid box specified.');
}break;//end of case view thread
default :
{
?>
<td width="80%" align="center" valign="middle" >
<h2>
<?php if ($boxname[0] != '')
{echo 'Welcome to my download center.<br /> Please select a category from the left menu.'; }
else
{echo 'There are no categories available, please check your "config.php" file.'; }
?>
</h2>
</td>
<?
}break;
}
if ($action != 'download') {
?>
</tr>
</table>
<br />
<br />
<?php
include('footer.php');
}
?>