实现ecshop清除体验数据的方法-插件版
您可以通过此功能将安装系统时所安装的体验数据全部删除,清除的数据包括用户、商品、订单、文章相关数据。
注意:您最新添加的数据也会一起删除,请慎重使用此功能,建议先做好数据备份!
ecshop清除体验数据插件
一、/admin/clear_demo.php
<?php
/**
* ECSHOP 清除体验数据插件
* ----------------------------------------------------------------------------
* http://www.phpally.com
* Jacklee的博客 致力于php技术
* ----------------------------------------------------------------------------
* 作者: Jacklee
* 邮箱: jack349392900#gmail.com
* 创建时间: 2014-05-17
* 最后修改时间: 2014-05-17
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
/*------------------------------------------------------ */
//-- 载入界面
/*------------------------------------------------------ */
if($_REQUEST['act'] == 'start')
{
$smarty->assign('ur_here', $_LANG['clear_demo']);
$smarty->display('clear_demo.htm');
}
/*------------------------------------------------------ */
//-- 清除数据
/*------------------------------------------------------ */
elseif($_REQUEST['act'] == 'clear')
{
$_POST['username'] = isset($_POST['username']) ? trim($_POST['username']) : '';
$_POST['password'] = isset($_POST['password']) ? trim($_POST['password']) : '';
$sql="SELECT `ec_salt` FROM ". $ecs->table('admin_user') ."WHERE user_name = '" . $_POST['username']."'";
$ec_salt =$db->getOne($sql);
if(!empty($ec_salt))
{
/* 检查密码是否正确 */
$sql = "SELECT user_id, user_name, password, last_login, action_list, last_login,suppliers_id,ec_salt".
" FROM " . $ecs->table('admin_user') .
" WHERE user_name = '" . $_POST['username']. "' AND password = '" . md5(md5($_POST['password']).$ec_salt) . "'";
}
else
{
/* 检查密码是否正确 */
$sql = "SELECT user_id, user_name, password, last_login, action_list, last_login,suppliers_id,ec_salt".
" FROM " . $ecs->table('admin_user') .
" WHERE user_name = '" . $_POST['username']. "' AND password = '" . md5($_POST['password']) . "'";
}
$row = $db->getRow($sql);
if($row)
{
$sql="SELECT `action_list` FROM ". $ecs->table('admin_user') ."WHERE user_name = '" . $_POST['username']."'";
$action_list =$db->getOne($sql);
if($action_list == 'all')
{
$tables = array(
'account_log', 'admin_log', 'admin_message', 'article', 'article_cat', 'attribute', 'auction_log',
'back_order', 'bonus_type', 'booking_goods', 'brand',
'card', 'category', 'cat_recommend', 'comment',
'delivery_goods', 'delivery_order',
'exchange_goods',
'favourable_activity', 'feedback', 'friend_link',
'goods', 'goods_activity', 'goods_article', 'goods_attr', 'goods_cat', 'goods_gallery', 'goods_type', 'group_goods',
'keywords',
'link_goods',
'member_price',
'order_action', 'order_goods', 'order_info',
'pack', 'package_goods', 'payment', 'pay_log', 'products',
'shipping', 'shipping_area', 'snatch_log', 'stats', 'suppliers',
'tag', 'topic',
'users', 'user_address', 'user_bonus', 'user_rank',
'virtual_card', 'volume_price', 'vote', 'vote_option',
'wholesale'
);
foreach ($tables AS $table)
{
$sql = "TRUNCATE `{$prefix}$table`";
$db->query($sql);
}
clear_cache_files();
sys_msg($_LANG['clear_success'], 0);
}
else
{
sys_msg($_LANG['not_permitted'], 1);
}
}
else
{
sys_msg($_LANG['password_incorrect'], 1);
}
}
?>
二、/languages/zh_cn/admin/clear_demo.php
<?php
$_LANG['warning'] = '您可以通过此功能将安装系统时所安装的体验数据全部删除,清除的数据包括用户、商品、订单、文章相关数据。
<br/><br/>
注意:您最新添加的数据也会一起删除,请慎重使用此功能,建议先做好数据备份!
';
$_LANG['clear'] = '清除';
$_LANG['username'] = '请输入管理员用户名:';
$_LANG['password'] = '请输入管理员密码:';
$_LANG['clear_success'] = '清理成功!';
$_LANG['not_permitted'] = '您输入的不是超级管理员用户名,没有执行此项操作的权限!';
$_LANG['password_incorrect'] = '用户名密码不匹配!';
$_LANG['js_languages']['username_empty'] = '请输入管理员用户名!';
$_LANG['js_languages']['password_empty'] = '请输入管理员密码!';
?>
三、/admin/templates/clear_demo.htm
{include file="pageheader.htm"}
{insert_scripts files="validator.js"}
<div class="main-div">
<ul id="lilist" style="padding:0; margin: 0; list-style-type:none; color: #CC0000;">
<li class="Start315">
{$lang.warning}
</li>
</ul>
<form method="post" action="clear_demo.php" name='theForm' onsubmit="return validate()">
<table width="100%">
<tr>
<td class="label" style="width:15%;">{$lang.username}</td>
<td>
<input type="text" name="username" size="30" /></td>
</tr>
<tr>
<td class="label" style="width:15%;">{$lang.password}</td>
<td>
<input type="password" name="password" size="30" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="{$lang.clear}" class="button" />
<input type="hidden" name="act" value="clear" />
</td>
</tr>
</table>
</form>
</div>
<script type="text/javascript">
document.forms['theForm'].elements['username'].focus();
/**
* 检查表单输入的数据
*/
function validate()
{
validator = new Validator("theForm");
validator.required("username", username_empty);
validator.required("password", password_empty);
return validator.passed();
}
</script>
{include file="pagefooter.htm"}
四、编辑/admin/includes/inc_menu.php,添加
1
$modules['13_backup']['clear_demo'] = 'clear_demo.php?act=start';
五、编辑/languages/zh_cn/admin/common.php,添加
1
$_LANG['clear_demo'] = '清除体验数据';
尊重劳动成果,转载请注明出处。
下一篇: ECSHOP产品列表增加市场价后台编辑功能 上一篇: 让ecshop商品选择品牌时按拼音排序