elseif($mybb->input['action'] == "do_export")
{
$plugins->run_hooks("private_do_export_start");
$lang->private_messages_for = sprintf($lang->private_messages_for, $mybb->user['username']);
$exdate = mydate($mybb->settings['dateformat'], time(), 0, 0);
$extime = mydate($mybb->settings['timeformat'], time(), 0, 0);
$lang->exported_date = sprintf($lang->exported_date, $exdate, $extime);
$foldersexploded = explode("$%%$", $mybb->user['pmfolders']);
if($mybb->input['pmid'])
{
$wsql = "pmid='".intval($mybb->input['pmid'])."' AND uid='".$mybb->user[uid]."'";
}
else
{
if($mybb->input['daycut'] && ($mybb->input['dayway'] != "all"))
{
$datecut = time()-($daycut * 86400);
$wsql = "pm.dateline";
if($mybb->input['dayway'] == "older")
{
$wsql .= "<=";
}
elseif($mybb->input['dayway'] == "newer")
{
$wsql .= ">=";
}
$wsql .= "'$datecut'";
}
else
{
$wsql = "1=1";
}
if(is_array($mybb->input['exportfolders']))
{
reset($mybb->input['exportfolders']);
while(list($key, $val) = each($mybb->input['exportfolders']))
{
$val = addslashes($val);
if($val == "all")
{
$folderlst = "";
break;
}
else
{
if(!$folderlst)
{
$folderlst = " AND pm.folder IN ('$val'";
}
else
{
$folderlst .= ",'$val'";
}
}
}
if($folderlst)
{
$folderlst .= ")";
}
$wsql .= "$folderlst";
}
else
{
error($lang->error_pmnoarchivefolders);
}
if($mybb->input['exportunread'] != "yes")
{
$wsql .= " AND pm.status!='0'";
}
}
if($mybb->input['exporttype'] != "html" && $mybb->input['exporttype'] != "csv")
{
$exporttype = "txt";
}
$query = $db->query("SELECT pm.*, fu.username AS fromusername, tu.username AS tousername FROM ".TABLE_PREFIX."privatemessages pm LEFT JOIN ".TABLE_PREFIX."users fu ON (fu.uid=pm.fromid) LEFT JOIN ".TABLE_PREFIX."users tu ON (tu.uid=pm.toid) WHERE $wsql AND pm.uid='".$mybb->user[uid]."' ORDER BY pm.folder ASC, pm.dateline DESC");
$numpms = $db->num_rows($query);
if(!$numpms)
{
error($lang->error_nopmsarchive);
}
while($message = $db->fetch_array($query))
{
if($message['folder'] == 2 || $message['folder'] == 3)
{ // Sent Items or Drafts Folder Check
if($message['toid'])
{
$tofromuid = $message['toid'];
$tofromusername = "<a href=\"member.php?action=profile&uid=$tofromuid\">$message[tousername]</a>";
}
else
{
$tofromusername = $lang->not_sent;
}
$tofrom = $lang->to;
}
else
{
$tofromuid = $message['fromid'];
$tofromusername = "<a href=\"member.php?action=profile&uid=$tofromuid\">$message[fromusername]</a>";
if($tofromuid == -2)
{
$tofromusername = "MyBB Engine";
}
$tofrom = $lang->from;
}
if($tofromuid == -2)
{
$message['fromusername'] = "MyBB Engine";
}
if(!$message['toid'])
{
$message['tousername'] = $lang->not_sent;
}
$message['subject'] = $message['subject'];
if($message['folder'] != "3")
{
$senddate = mydate($mybb->settings['dateformat'], $message['dateline'], 0, 0);
$sendtime = mydate($mybb->settings['timeformat'], $message['dateline'], 0, 0);
$senddate .= " $lang->at $sendtime";
}
else
{
$senddate = $lang->not_sent;
}
if($mybb->input['exporttype'] == "html")
{
$message['message'] = postify($message['message'], $mybb->settings['pmsallowhtml'], $mybb->settings['pmsallowmycode'], "no", $mybb->settings['pmsallowimgcode']);
// do me code
if($mybb->settings['pmsallowmycode'] != "no")
{
$message['message'] = domecode($message['message'], $message['username']);
}
}
if($mybb->input['exporttype'] == "txt" || $mybb->input['exporttype'] == "csv")
{
$message['message'] = str_replace("\r\n", "\n", $message['message']);
$message['message'] = str_replace("\n", "\r\n", $message['message']);
}
if(!$donefolder[$message['folder']])
{
reset($foldersexploded);
while(list($key, $val) = each($foldersexploded))
{
$folderinfo = explode("**", $val, 2);
if($folderinfo[0] == $message['folder'])
{
$foldername = $folderinfo[1];
if($exporttype != "csv")
{
eval("\$pmsdownload .= \"".$templates->get("private_archive_".$exporttype."_folderhead", 1, 0)."\";");
}
$donefolder[$message['folder']] = 1;
}
}
}
eval("\$pmsdownload .= \"".$templates->get("private_archive_".$exporttype."_message", 1, 0)."\";");
$ids .= ",'$message[pmid]'";
}
$query = $db->query("SELECT css FROM ".TABLE_PREFIX."themes WHERE tid='$theme[tid]'");
$css = $db->result($query, 0);
eval("\$archived = \"".$templates->get("private_archive_".$exporttype, 1, 0)."\";");
if($mybb->input['deletepms'] == "yes")
{ // delete the archived pms
$db->query("DELETE FROM ".TABLE_PREFIX."privatemessages WHERE pmid IN (''$ids)");
}
if($mybb->input['exporttype'] == "html")
{
$filename = "pm-archive.html";
}
elseif($mybb->input['exporttype'] == "csv")
{
$filename = "pm-archive.csv";
}
else
{
$filename = "pm-archive.txt";
}
$archived = ereg_replace("\\\'","'",$archived);
header("Content-disposition: filename=$filename");
header("Content-type: unknown/unknown");
$plugins->run_hooks("private_do_export_end");
if($mybb->input['exporttype'] == "html")
{
outputpage($archived);
}
else
{
echo $archived;
}
}