- You can now export an entire folder as either CSV or XML :D

git-svn-id: file:///svn/phpbb/trunk@5567 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
David M 2006-02-21 19:49:35 +00:00
parent cddf792dea
commit d6c8a4a1ae
5 changed files with 160 additions and 43 deletions

View file

@ -57,8 +57,6 @@ class acp_language
$this->tpl_name = 'acp_language';
$this->page_title = 'ACP_LANGUAGE_PACKS';
$this->u_action = "{$phpbb_admin_path}index.$phpEx$SID&i=$id&mode=$mode";
if ($action == 'upload_data' && request_var('test_connection', ''))
{
$test_connection = false;

View file

@ -121,10 +121,29 @@ function view_folder($id, $mode, $folder_id, $folder, $type)
$url = "{$phpbb_root_path}ucp.$phpEx$SID";
$data = array();
foreach ($folder_info['pm_list'] as $message_id)
{
$row = &$folder_info['rowset'][$message_id];
if (isset($_REQUEST['submit_export']))
{
$sql = 'SELECT p.message_text
FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
WHERE t.user_id = ' . $user->data['user_id'] . "
AND p.author_id = u.user_id
AND t.folder_id = $folder_id
AND t.msg_id = p.msg_id
AND p.msg_id = $message_id";
$result = $db->sql_query_limit($sql, 1);
$message_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$data[] = array('subject' => censor_text($row['message_subject']), 'from' => $row['username'], 'date' => $user->format_date($row['message_time']), 'to' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? implode(', ', $address_list[$message_id]) : '', 'message' => $message_row['message_text']);
}
else
{
$folder_img = ($row['unread']) ? 'folder_new' : 'folder';
$folder_alt = ($row['unread']) ? 'NEW_MESSAGES' : 'NO_NEW_MESSAGES';
@ -168,9 +187,9 @@ function view_folder($id, $mode, $folder_id, $folder, $type)
'U_REMOVE_PM' => ($row['deleted']) ? $remove_message_url : '',
'RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? implode(', ', $address_list[$message_id]) : '',
'U_MCP_REPORT' => "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}&i=reports&pm=$message_id")
// 'U_MCP_QUEUE' => "mcp.$phpEx?sid={$user->session_id}&i=mod_queue&t=$topic_id")
// 'U_MCP_QUEUE' => "mcp.$phpEx?sid={$user->session_id}&i=mod_queue&t=$topic_id")
);
}
}
unset($folder_info['rowset']);
@ -179,6 +198,78 @@ function view_folder($id, $mode, $folder_id, $folder, $type)
'S_SHOW_COLOUR_LEGEND' => true)
);
}
$type = request_var('export_option', '');
// Ask the user what he wants
if (isset($_REQUEST['submit_export']))
{
if (!isset($_REQUEST['delimiter']) && $type == 'CSV')
{
$template->assign_var('PROMPT', true);
}
else
{
switch ($type)
{
case 'CSV':
case 'CSV_EXCEL':
$mimetype = 'text/csv';
$filetype = 'csv';
if ($type == 'csv_excel')
{
$enclosure = '"';
$delimiter = ',';
$newline = "\r\n";
}
else
{
$enclosure = request_var('enclosure', '"');
$delimiter = request_var('delimiter', ',');
$newline = "\n";
}
$string = '';
foreach ($data as $value)
{
foreach ($value as $text)
{
$cell = str_replace($enclosure, $enclosure . $enclosure, $text);
if (strpos($cell, $enclosure) !== false || strpos($cell, $delimiter) !== FALSE || strpos($cell, $newline) !== FALSE)
{
$string .= $enclosure . $text . $enclosure . $delimiter;
}
else
{
$string .= $cell . $delimiter;
}
}
$string = substr($string, 0, -1) . $newline;
}
break;
case 'XML':
$mimetype = 'text/xml';
$filetype = 'xml';
$string = '<?xml version="1.0"?>' . "\n";
$string .= "<messages>\n";
foreach ($data as $value)
{
$string .= "\t<privmsg>\n";
foreach ($value as $tag => $text)
{
$string .= "\t\t<$tag>$text</$tag>\n";
}
$string .= "\t</privmsg>\n";
}
$string .= '</messages>';
}
header('Pragma: no-cache');
header("Content-Type: $mimetype; name=\"data.$filetype\"");
header("Content-disposition: attachment; filename=data.$filetype");
echo $string;
exit;
}
}
}
/**

View file

@ -104,6 +104,7 @@ $lang = array_merge($lang, array(
'DELETE_COOKIES' => 'Delete all board cookies',
'DELETE_MARKED' => 'Delete Marked',
'DELETE_POST' => 'Delete Post',
'DELIMITER' => 'Delimiter',
'DESCENDING' => 'Descending',
'DISABLED' => 'Disabled',
'DISPLAY' => 'Display',
@ -121,6 +122,7 @@ $lang = array_merge($lang, array(
'EMAIL_ADDRESS' => 'Email address',
'EMPTY_SUBJECT' => 'You must specify a subject when posting a new topic.',
'ENABLED' => 'Enabled',
'ENCLOSURE' => 'Enclosure',
'ERR_CONNECTING_SERVER' => 'Error connecting to the server',
'EXTENSION' => 'Extension',
'EXTENSION_DISABLED_AFTER_POSTING' => 'The extension <b>%s</b> has been deactivated and can no longer be displayed',

View file

@ -137,8 +137,10 @@ $lang = array_merge($lang, array(
'EMPTY_DRAFT_TITLE' => 'You must enter a draft title',
'EXPORT_AS_XML' => 'Export as XML',
'EXPORT_AS_CSV' => 'Export as CSV',
'EXPORT_AS_CSV_EXCEL' => 'Export as CSV (Excel)',
'EXPORT_AS_TXT' => 'Export as TXT',
'EXPORT_AS_MSG' => 'Export as MSG',
'EXPORT_FOLDER' => 'Export Folder',
'FIELD_REQUIRED' => 'The field "%s" must be completed.',
'FIELD_TOO_SHORT' => 'The field "%1$s" is too short, a minimum of %2$d characters is required.',

View file

@ -3,8 +3,9 @@
<!-- $Id$ -->
<div id="pagecontent">
<!-- IF not PROMPT -->
<!-- INCLUDE ucp_pm_message_header.html -->
<!-- ENDIF -->
<div style="padding: 2px;"></div>
<!-- IF S_PM_ICONS and S_UNREAD -->
@ -16,7 +17,24 @@
<!-- ENDIF -->
<form name="viewfolder" method="post" action="{S_PM_ACTION}" style="margin:0px">
<!-- IF PROMPT -->
<table class="tablebg" width="100%" cellspacing="1" cellpadding="0" border="0">
<tr>
<th colspan="2" valign="middle">{L_OPTIONS}</th>
</tr>
<tr>
<td class="row1" width="35%">{L_DELIMITER}: </td>
<td class="row2"><input class="post" type="text" name="delimiter" value="," /></td>
</tr>
<tr>
<td class="row1" width="35%">{L_ENCLOSURE}: </td>
<td class="row2"><input class="post" type="text" name="enclosure" value="&#034;" /></td>
</tr>
<tr>
<td class="cat" colspan="2" align="center"><input type="hidden" name="export_option" value="CSV" /><input class="btnmain" type="submit" name="submit_export" value="{L_EXPORT_FOLDER}" />&nbsp;&nbsp;<input class="btnlite" type="reset" value="Reset" name="reset" /></td>
</tr>
</table>
<!-- ELSE -->
<table class="tablebg" width="100%" cellspacing="1" cellpadding="0" border="0">
<!-- IF NUM_NOT_MOVED -->
<tr>
@ -84,6 +102,12 @@
<div style="padding: 2px;"></div>
<!-- INCLUDE ucp_pm_message_footer.html -->
<!-- IF .messagerow -->
<div style="float:left"><br /><select name="export_option"><option value="CSV">{L_EXPORT_AS_CSV}</option><option value="CSV_EXCEL">{L_EXPORT_AS_CSV_EXCEL}</option><option value="XML">{L_EXPORT_AS_XML}</option></select>&nbsp;<input class="btnlite" type="submit" name="submit_export" value="{L_EXPORT_FOLDER}" /></div>
<!-- ENDIF -->
<!-- ENDIF -->
</form>
<br clear="all" />
</div>