赵荣涛's Archivers

From admin on 2013-03-20 11:20:04

ECSHOP邮件发送记录插件【转】

ECSHOP邮件队列中的邮件发送完毕后,将从数据库中删除,保存记录(发件箱)将方便各位站长做运维,所以开发了此插件。本插件高内聚低耦合,发送成功则记录,不成功则不记录,可按发送时间、主题、邮箱关键字搜索历史记录,导出记录,如需二次开发可联系我。为方便各位站长,本插件制作成了傻瓜式安装程序,不懂代码也可一键按完成安装。

<img title="20120828211631" src="http://www.phpally.com/wp-content/uploads/2012/08/20120828211631.png" alt="" width="554" height="76" />

安装指南

第一步:将安装文件覆盖到网站根目录。

第二步:输入”站点路径/db_patch.php”,如”http://ecshop.phpally.com/db_patch.php”一键完成安装,安装完成后,请立即删除db_patch.php。

按主题、邮箱关键字、发送时间等多条件搜索

<img title="20120828205454" src="http://www.phpally.com/wp-content/uploads/2012/08/20120828205454.png" alt="" width="554" height="201" />

导出发送记录为EXCEL文件

<img title="20120828141206" src="http://www.phpally.com/wp-content/uploads/2012/08/20120828141206.png" alt="" width="554" height="288" />

开发指南

一、/db_patch.php
<?php

/**
* ECSHOP 邮件发送记录插件 数据库补丁
* ----------------------------------------------------------------------------
* Jacklee的博客 致力于php技术
* http://www.phpally.com
* ----------------------------------------------------------------------------
* @author: Jacklee
* @email: jack349392900#gmail.com
* @date: 2012-08-28
*/

define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');

$sql = "
DROP TABLE IF EXISTS {$prefix}email_send_history;
";
$db->query($sql);
$sql = "
CREATE TABLE IF NOT EXISTS {$prefix}email_send_history (
id mediumint(8) NOT NULL AUTO_INCREMENT,
email varchar(100) NOT NULL,
email_subject varchar(200) NOT NULL,
email_type int(10) NOT NULL,
send_time int(10) NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
";
$db->query($sql);
echo '数据库补丁程序执行成功,请立即删除此补丁文件(db_patch.php)。';
?>
 

二、/admin/view_sendlist.php发送成功语句后添加

 
//写入发送记录
$time = gmtime();
$sql = "INSERT INTO " .$ecs->table('email_send_history'). " (id, email, email_subject, email_type, send_time)".
" VALUES (NULL, '$row[email]', '$rt[template_subject]', 1, $time)";
$db->query($sql);
 

三、/admin/includes/inc_menu.php添加菜单项
$modules['16_email_manage']['email_send_history'] = 'email_send_history.php?act=list';
 

四、/languages/zh_cn/admin/common.php添加菜单语言项
$_LANG['email_send_history'] = '邮件发送记录';
 

 

 

 

五、新建文件/admin/email_send_history.php

 
<?php

/**
* ECSHOP 邮件发送记录插件
* ----------------------------------------------------------------------------
* Jacklee的博客 致力于php技术
* http://www.phpally.com
* ----------------------------------------------------------------------------
* @author: Jacklee
* @email: jack349392900#gmail.com
* @date: 2012-08-28
*/

define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');

/* act操作项的初始化 */
if (empty($_REQUEST['act']))
{
$_REQUEST['act'] = 'list';
}
else
{
$_REQUEST['act'] = trim($_REQUEST['act']);
}

/*------------------------------------------------------ */
//-- 获取所有发送记录
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'list')
{
$id = !empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
$email = !empty($_REQUEST['email']) ? $_REQUEST['email'] : '';
$email_subject = !empty($_REQUEST['email_subject']) ? $_REQUEST['email_subject'] : '';
$email_type = !empty($_REQUEST['email_type']) ? $_REQUEST['email_type'] : '';
$send_time = !empty($_REQUEST['send_time']) ? $_REQUEST['send_time'] : '';

/* 查询主题列表 */
$subject_list = array();
$res = $db->query("SELECT DISTINCT email_subject FROM " .$ecs->table('email_send_history'));
while ($row = $db->FetchRow($res))
{
$subject_list[$row['email_subject']] = $row['email_subject'];
}

$smarty->assign('ur_here', $_LANG['email_send_history']);
$smarty->assign('subject_list', $subject_list);
$smarty->assign('full_page', 1);

$history_list = get_history();

$smarty->assign('history_list', $history_list['list']);
$smarty->assign('filter', $history_list['filter']);
$smarty->assign('record_count', $history_list['record_count']);
$smarty->assign('page_count', $history_list['page_count']);
$sort_flag = sort_flag($history_list['filter']);
$smarty->assign($sort_flag['tag'], $sort_flag['img']);
$smarty->assign('action_link', array('text' => $_LANG['export'],'href'=>'email_send_history.php?act=export'));

assign_query_info();
$smarty->display('email_send_history.htm');
}

/*------------------------------------------------------ */
//-- 排序、分页、查询
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'query')
{
$history_list = get_history();

$smarty->assign('history_list', $history_list['list']);
$smarty->assign('filter', $history_list['filter']);
$smarty->assign('record_count', $history_list['record_count']);
$smarty->assign('page_count', $history_list['page_count']);

$sort_flag = sort_flag($history_list['filter']);
$smarty->assign($sort_flag['tag'], $sort_flag['img']);

make_json_result($smarty->fetch('email_send_history.htm'), '',
array('filter' => $history_list['filter'], 'page_count' => $history_list['page_count']));
}

/*------------------------------------------------------ */
//-- 批量删除发送记录
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'batch_drop')
{
/* 按ID删除 */
$count = 0;
foreach ($_POST['checkboxes'] AS $key => $id)
{
$sql = "DELETE FROM " .$ecs->table('email_send_history'). " WHERE id = '$id'";
$result = $db->query($sql);

$count++;
}
if ($result)
{
//admin_log('', 'remove', 'email_send_history'); //记录操作日志
$link[] = array('text' => $_LANG['back_list'], 'href' => 'email_send_history.php?act=list');
sys_msg(sprintf($_LANG['batch_drop_success'], $count), 0, $link);
}
}

/* 导出全部记录 */
if ($_REQUEST['act'] == 'export')
{
$sql = 'SELECT * FROM ' .$GLOBALS['ecs']->table('email_send_history');
$res = $GLOBALS['db']->query($sql);

$file_name = $_SERVER['SERVER_NAME'] . '_email_send_history';
header("Content-type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=$file_name.xls");

/* 编号,操作者,操作时间,IP,操作记录 */
echo ecs_iconv(EC_CHARSET, 'UTF-8', $_LANG['id']) . "\t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $_LANG['email']) . "\t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $_LANG['email_subject']) . "\t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $_LANG['email_type']) . "\t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $_LANG['send_time']) . "\t\n";

while ($row = $GLOBALS['db']->fetchRow($res))
{
if($row['email_type'] == 1)
{
$row['email_type'] = $_LANG['email_magazine'];
}
$row['send_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['send_time']);
echo ecs_iconv(EC_CHARSET, 'UTF-8', $row['id']) . "\t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $row['email']) . "\t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $row['email_subject']) . "\t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $row['email_type']) . "\t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $row['send_time']) . "\t";
echo "\n";
}
//admin_log('', 'export', 'email_send_history'); //记录操作日志
exit;
}

/* 获取发送记录 */
function get_history()
{
$id = !empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
$email_subject = !empty($_REQUEST['email_subject']) ? $_REQUEST['email_subject'] : '';
$keywords = !empty($_REQUEST['keywords']) ? trim($_REQUEST['keywords']) : '';
$start_time = empty($_REQUEST['start_time']) ? '' : (strpos($_REQUEST['start_time'], '-') > 0 ? local_strtotime($_REQUEST['start_time']) : $_REQUEST['start_time']);
$end_time = empty($_REQUEST['end_time']) ? '' : (strpos($_REQUEST['end_time'], '-') > 0 ? local_strtotime($_REQUEST['end_time']) : $_REQUEST['end_time']);


$filter = array();
$filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'id' : trim($_REQUEST['sort_by']);
$filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);

//查询条件
$where = " WHERE 1 ";
if (!empty($id))
{
$where .= " AND id = '$id' ";
}
elseif (!empty($email_subject))
{
$where .= " AND email_subject = '$email_subject' ";
}
if (!empty($keywords))
{
$where .= " AND email like '%$keywords%' ";
}
if (!empty($start_time))
{
$where .= " AND send_time >= '$start_time'";
}
if (!empty($end_time))
{
$where .= " AND send_time <= '$end_time'";
}

/* 获得总记录数据 */
$sql = 'SELECT COUNT(*) FROM ' .$GLOBALS['ecs']->table('email_send_history'). $where;
$filter['record_count'] = $GLOBALS['db']->getOne($sql);

$filter = page_and_size($filter);


/* 获取发送记录 */
$list = array();
$sql = 'SELECT * FROM ' .$GLOBALS['ecs']->table('email_send_history').
$where .' ORDER by '.$filter['sort_by'].' '.$filter['sort_order'];
$res = $GLOBALS['db']->selectLimit($sql, $filter['page_size'], $filter['start']);

while ($rows = $GLOBALS['db']->fetchRow($res))
{
$rows['send_time'] = local_date($GLOBALS['_CFG']['time_format'], $rows['send_time']);
$list[] = $rows;
}

return array('list' => $list, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
}

?>
 

 

六、新建文件/languages/zh_cn/admin/email_send_history.php
<?php

/**
* ECSHOP 邮件发送记录插件 语言文件
* ----------------------------------------------------------------------------
* Jacklee的博客 致力于php技术
* http://www.phpally.com
* ----------------------------------------------------------------------------
* @author: Jacklee
* @email: jack349392900#gmail.com
* @date: 2012-08-28
*/

/* 字段信息 */
$_LANG['id'] = '编号';
$_LANG['email'] = '邮箱';
$_LANG['email_subject'] = '邮件主题';
$_LANG['email_type'] = '邮件类型';
$_LANG['email_magazine'] = '杂志订阅';
$_LANG['send_time'] = '发送时间';
$_LANG['drop_records'] = '删除记录';
$_LANG['select_subject'] = '选择主题...';
$_LANG['search'] = '搜索';
$_LANG['export'] = '导出全部记录';
$_LANG['back_list'] = '返回记录列表';

/* 提示信息 */
$_LANG['batch_drop_success'] = '成功删除了 %d 个历史记录';

?>
 

 

 

 

查看完整版本: ECSHOP邮件发送记录插件【转】

Tags: