Revize 1861
Přidáno uživatelem Ondřej Fibich před více než 11 roky(ů)
freenetis/branches/1.1/application/models/email_queue.php | ||
---|---|---|
}
|
||
|
||
/**
|
||
* Returns all sent e-mails for export
|
||
*
|
||
* @param string $filter_sql
|
||
* @return Mysql_Result
|
||
*/
|
||
public function get_all_sent_emails_for_export($filter_sql = '')
|
||
{
|
||
// filter
|
||
$where = '';
|
||
if (!empty($filter_sql))
|
||
$where = "WHERE $filter_sql";
|
||
|
||
return $this->db->query("
|
||
SELECT eq.id,
|
||
CONCAT(eq.from, ' (', IFNULL(CONCAT(from_user_id, ' - ', from_user_name),'-'), ')') AS sender,
|
||
CONCAT(eq.to, ' (', IFNULL(CONCAT(to_user_id, ' - ', to_user_name),'-'), ')') AS receiver,
|
||
eq.access_time AS sended,
|
||
eq.subject,
|
||
eq.body AS message
|
||
FROM
|
||
(
|
||
SELECT eq.*, fuc.user_id AS from_user_id,
|
||
CONCAT(fu.name,' ',fu.surname) AS from_user_name,
|
||
tuc.user_id AS to_user_id,
|
||
CONCAT(tu.name,' ',tu.surname) AS to_user_name
|
||
FROM email_queues eq
|
||
LEFT JOIN contacts fc ON eq.from = fc.value AND fc.type = ?
|
||
LEFT JOIN users_contacts fuc ON fc.id = fuc.contact_id
|
||
LEFT JOIN users fu ON fuc.user_id = fu.id
|
||
LEFT JOIN contacts tc ON eq.to = tc.value AND tc.type = ?
|
||
LEFT JOIN users_contacts tuc ON tc.id = tuc.contact_id
|
||
LEFT JOIN users tu ON tuc.user_id = tu.id
|
||
WHERE eq.state = ?
|
||
) eq
|
||
$where
|
||
GROUP BY eq.id
|
||
", Contact_Model::TYPE_EMAIL, Contact_Model::TYPE_EMAIL, self::STATE_OK);
|
||
}
|
||
|
||
/**
|
||
* Returns all unsent e-mails
|
||
*
|
||
* @author Michal Kliment
|
freenetis/branches/1.1/application/controllers/email_queues.php | ||
---|---|---|
);
|
||
|
||
$grid->add_new_button(
|
||
'email_queues/delete_unsended', __('Delete all unsended e-mails')
|
||
'export/csv/email_queue_sent' . server::query_string(),
|
||
'Export to CSV', array
|
||
(
|
||
'title' => __('Export to CSV'),
|
||
'class' => 'popup_link'
|
||
)
|
||
);
|
||
|
||
// database columns
|
freenetis/branches/1.1/application/controllers/export.php | ||
---|---|---|
|
||
break;
|
||
|
||
// export emails
|
||
case 'email_queue_sent':
|
||
|
||
if (!$this->acl_check_view('Settings_Controller', 'system'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
$filter_form = new Filter_form('eq');
|
||
$filter_form->autoload();
|
||
|
||
$email_queue = new Email_queue_Model();
|
||
|
||
try
|
||
{
|
||
$items = $email_queue->get_all_sent_emails_for_export($filter_form->as_sql());
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$items = array();
|
||
}
|
||
|
||
$filename = __('E-mails') . '.csv';
|
||
|
||
break;
|
||
|
||
// export for items of subnet
|
||
case 'subnets':
|
||
|
||
... | ... | |
{
|
||
$items[] = $one->as_array();
|
||
}
|
||
|
||
|
||
unset($all);
|
||
}
|
||
catch (Exception $e)
|
||
... | ... | |
else
|
||
{
|
||
/* Generate file */
|
||
|
||
|
||
// set content header
|
||
header('Content-type: application/csv');
|
||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||
|
||
$is_utf = $encoding == 'utf-8';
|
||
|
||
// get headers
|
||
foreach ($items[0] as $key => $value)
|
||
... | ... | |
$field = __('Number');
|
||
}
|
||
// character encoding
|
||
if ($encoding != 'utf-8')
|
||
if (!$is_utf)
|
||
{
|
||
$field = iconv('utf-8', $encoding, $value);
|
||
}
|
||
... | ... | |
}
|
||
|
||
echo "\n";
|
||
|
||
|
||
// for each data row
|
||
foreach ($items as $line)
|
||
{
|
||
... | ... | |
foreach ($line as $key => $value)
|
||
{
|
||
// character encoding
|
||
if ($encoding != 'utf-8')
|
||
if (!$is_utf)
|
||
{
|
||
$field = iconv('utf-8', $encoding, $value);
|
||
}
|
||
// emails body
|
||
if ($content == 'email_queue_sent' && $key == 'message')
|
||
{
|
||
$value = str_replace('"', '\'', strip_tags($value));
|
||
}
|
||
// output
|
||
echo '"' . $value . '";';
|
||
echo '"';
|
||
echo $value;
|
||
echo '";';
|
||
}
|
||
echo "\n";
|
||
}
|
Také k dispozici: Unified diff
Novinky:
- #461: export emailu