ECShop二次开发的时候我会使用到一些自己编写的函数,通常我都将这些函数放在 includes/lib_common.php 文件末尾。
这次的例子中使用到两个函数 data_insert和data_update,他们的做用是插入和更新数据库记录
打开:includes/lib_common.php 文件,在默认添加下列代码
/**
* 添加数据
* @param string $tablename 数据表名称(不带前缀)
* @param array $info 要添加到数据表中的字段和值,格式:array('字段名称'=>'字段值')
*
* return int $insertid 当前记录ID
*/
function data_insert($tablename,$info=array())
{
$sp1 = $sp2 = '';
if (is_array($info))
{
foreach ($info as $key=>$value)
{
$sp1 .= "`$key`, ";
$sp2 .= "'$value', ";
}
$sp1 = substr($sp1,0,-2);
$sp2 = substr($sp2,0,-2);
}
$GLOBALS['db']->query("insert into ".$GLOBALS['ecs']->table($tablename)." ($sp1) values ($sp2)");
$insertid = $GLOBALS['db']->insert_id();
return $insertid;
}
/**
* 编辑数据
* @param string $tablename 数据表名称(不带前缀)
* @param array $info 数据表中的字段和值,格式:array('字段名称'=>'字段值')
* @param int $id 当前操作记录ID
* @param string $idname 当前数据表中主键名称
*
* return
*/
function data_update($tablename,$info=array(),$id,$idname='id')
{
$sp = '';
if (is_array($info))
{
foreach ($info as $key=>$value)
{
$sp .= "`$key` = '$value', ";
}
$sp = substr($sp,0,-2);
}
$GLOBALS['db']->query("update ".$GLOBALS['ecs']->table($tablename)." set $sp where $idname = '$id'");
}
步骤一:添加建立数据库
CREATE TABLE IF NOT EXISTS `ecs_court` ( `court_id` mediumint(8) NOT NULL auto_increment, `title` varchar(250) NOT NULL, `company` varchar(250) NOT NULL, `types` varchar(100) NOT NULL, `province` varchar(250) NOT NULL, `citys` varchar(100) NOT NULL, `areas` varchar(100) NOT NULL, `charge` varchar(250) NOT NULL, `opens` varchar(250) NOT NULL, `address` varchar(250) NOT NULL, `tel` varchar(250) NOT NULL, `add_time` int(10) NOT NULL default '0', `user_id` mediumint(8) NOT NULL default '0', `is_check` tinyint(1) NOT NULL default '1', PRIMARY KEY (`court_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=115 ;
步骤二:修改user.php文件
修改一:给user.php文件中的$ui_arr数组中添加两个值:’court_list’, ‘court_add’
修改二:user.php文件中添加处理代码:添加,编辑,列表
//列表,这里为简单起见,不添加分页功能
elseif ($action == 'court_list')
{
$items = $db->GetAll("SELECT * FROM ecs_court WHERE user_id = $user_id");
$smarty->assign('items', $items);
$smarty->display('user_court_list.dwt');
}
//添加
elseif ($action == 'court_add')
{
if ($_POST['do'] == 'save')
{
$info = $_POST['info'];
$info['user_id'] = $user_id;
$info['is_check'] = 0;
$info['add_time'] = gmtime();
data_insert('court', $info);
show_message('操作成功', '返回列表', 'user.php?act=court_list');
}
else
{
$smarty->display('user_court_add.dwt');
}
}
//编辑
elseif ($action == 'court_edit')
{
if ($_POST['do'] == 'save')
{
$info = $_POST['info'];
$info['user_id'] = $user_id;
$info['is_check'] = 0;
$info['add_time'] = gmtime();
data_update('court', $info, $_POST['id'], 'court_id');
show_message('操作成功', '返回列表', 'user.php?act=court_list');
}
else
{
$article = $db->GetRow("SELECT * FROM ecs_court WHERE court_id = $_GET[id]");
$smarty->assign('article', $article);
$smarty->display('user_court_edit.dwt');
}
}
步骤三:在themes\default目录下添加三个模板文件,注意下面三个模板的样式可能与默认模板不同,请自行修改。
文件一:user_court_add.dwt
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{$keywords}" />
<meta name="Description" content="{$description}" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>{$page_title}</title>
<!-- TemplateEndEditable --><!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link href="{$ecs_css_path}" rel="stylesheet" type="text/css" />
{* 包含脚本文件 *}
{insert_scripts files='transport.js,common.js,user.js'}
<script>
function getbyid(id) {return document.getElementById(id);}
function check_court()
{
if (getbyid("title").value == '')
{
alert("请输入场馆名称!");
getbyid("title").focus();
return false;
}
if (getbyid("types").value == '')
{
alert("请输入场馆类型!");
getbyid("types").focus();
return false;
}
if (getbyid("citys").value == '')
{
alert("请输入所在城市!");
getbyid("citys").focus();
return false;
}
if (getbyid("areas").value == '')
{
alert("请输入场地数量!");
getbyid("areas").focus();
return false;
}
if (getbyid("charge").value == '')
{
alert("请输入收费标准!");
getbyid("charge").focus();
return false;
}
if (getbyid("opens").value == '')
{
alert("请输入开放时间!");
getbyid("opens").focus();
return false;
}
if (getbyid("address").value == '')
{
alert("请输入地址!");
getbyid("address").focus();
return false;
}
if (getbyid("tel").value == '')
{
alert("请输入电话!");
getbyid("tel").focus();
return false;
}
}
</script>
</head>
<body>
<!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->
<div class="user_here"><!-- #BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem --></div>
<div class="clearfix">
<div class="AreaL"><!-- #BeginLibraryItem "/library/user_menu.lbi" --><!-- #EndLibraryItem --></div>
<div class="AreaR">
<div class="box"><div class="box_1"><div class="userCenterBox boxCenterList clearfix" style="_height:1%;">
<h5><span>添加场馆</span></h5>
<form action="user.php?act=court_add" method="post" enctype="multipart/form-data" onsubmit="return check_court()">
<input type="hidden" name="do" value="save" />
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_info">
<tr>
<th>场馆名称</th>
<td><input type="text" name="info[title]" id="title" size="60" value="{$article.title|escape}" /> (必填)</td>
</tr>
<tr>
<th>场馆类型</th>
<td><input type="text" name="info[types]" id="types" size="60" value="{$article.types|escape}" /> (必填)</td>
</tr>
<tr>
<th>所在城市</th>
<td><input type="text" name="info[citys]" id="citys" size="60" value="{$article.citys|escape}" /> (必填)</td>
</tr>
<tr>
<th>场地数量</th>
<td><textarea name="info[areas]" id="areas" cols="50" rows="3">{$article.areas|escape}</textarea> (必填)</td>
</tr>
<tr>
<th>收费标准</th>
<td><textarea name="info[charge]" id="charge" cols="50" rows="3">{$article.charge|escape}</textarea> (必填)</td>
</tr>
<tr>
<th>开放时间</th>
<td><input type="text" name="info[opens]" id="opens" size="60" value="{$article.opens|escape}" /> (必填)</td>
</tr>
<tr>
<th>地址</th>
<td><input type="text" name="info[address]" id="address" size="60" value="{$article.address|escape}" /> (必填)</td>
</tr>
<tr>
<th>电话</th>
<td><input type="text" name="info[tel]" id="tel" size="60" value="{$article.tel|escape}" /> (必填)</td>
</tr>
<tr>
<th></th>
<td height="50"><input type="submit" name="Submit" class="bnt_blue_1" style="border:none;" value=" 提交 " /></td>
</tr>
</table>
</form>
</div></div></div>
</div>
</div>
<!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->
</body>
</html>
文件二:user_court_edit.dwt
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{$keywords}" />
<meta name="Description" content="{$description}" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>{$page_title}</title>
<!-- TemplateEndEditable --><!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link href="{$ecs_css_path}" rel="stylesheet" type="text/css" />
{* 包含脚本文件 *}
{insert_scripts files='transport.js,common.js,user.js'}
<script>
function getbyid(id) {return document.getElementById(id);}
function check_court()
{
if (getbyid("title").value == '')
{
alert("请输入场馆名称!");
getbyid("title").focus();
return false;
}
if (getbyid("types").value == '')
{
alert("请输入场馆类型!");
getbyid("types").focus();
return false;
}
if (getbyid("citys").value == '')
{
alert("请输入所在城市!");
getbyid("citys").focus();
return false;
}
if (getbyid("areas").value == '')
{
alert("请输入场地数量!");
getbyid("areas").focus();
return false;
}
if (getbyid("charge").value == '')
{
alert("请输入收费标准!");
getbyid("charge").focus();
return false;
}
if (getbyid("opens").value == '')
{
alert("请输入开放时间!");
getbyid("opens").focus();
return false;
}
if (getbyid("address").value == '')
{
alert("请输入地址!");
getbyid("address").focus();
return false;
}
if (getbyid("tel").value == '')
{
alert("请输入电话!");
getbyid("tel").focus();
return false;
}
}
</script>
</head>
<body>
<!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->
<div class="user_here"><!-- #BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem --></div>
<div class="clearfix">
<div class="AreaL"><!-- #BeginLibraryItem "/library/user_menu.lbi" --><!-- #EndLibraryItem --></div>
<div class="AreaR">
<div class="box"><div class="box_1"><div class="userCenterBox boxCenterList clearfix" style="_height:1%;">
<h5><span>编辑场馆</span></h5>
<form action="user.php?act=court_edit" method="post" enctype="multipart/form-data" onsubmit="return check_court()">
<input type="hidden" name="do" value="save" />
<input type="hidden" name="id" value="{$article.court_id}" />
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_info">
<tr>
<th>场馆名称</th>
<td><input type="text" name="info[title]" id="title" size="60" value="{$article.title|escape}" /> (必填)</td>
</tr>
<tr>
<th>场馆类型</th>
<td><input type="text" name="info[types]" id="types" size="60" value="{$article.types|escape}" /> (必填)</td>
</tr>
<tr>
<th>所在城市</th>
<td><input type="text" name="info[citys]" id="citys" size="60" value="{$article.citys|escape}" /> (必填)</td>
</tr>
<tr>
<th>场地数量</th>
<td><textarea name="info[areas]" id="areas" cols="50" rows="3">{$article.areas|escape}</textarea> (必填)</td>
</tr>
<tr>
<th>收费标准</th>
<td><textarea name="info[charge]" id="charge" cols="50" rows="3">{$article.charge|escape}</textarea> (必填)</td>
</tr>
<tr>
<th>开放时间</th>
<td><input type="text" name="info[opens]" id="opens" size="60" value="{$article.opens|escape}" /> (必填)</td>
</tr>
<tr>
<th>地址</th>
<td><input type="text" name="info[address]" id="address" size="60" value="{$article.address|escape}" /> (必填)</td>
</tr>
<tr>
<th>电话</th>
<td><input type="text" name="info[tel]" id="tel" size="60" value="{$article.tel|escape}" /> (必填)</td>
</tr>
<tr>
<th></th>
<td height="50"><input type="submit" name="Submit" class="bnt_blue_1" style="border:none;" value=" 提交 " /></td>
</tr>
</table>
</form>
</div></div></div>
</div>
</div>
<!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->
</body>
</html>
文件三:user_court_list.dwt
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{$keywords}" />
<meta name="Description" content="{$description}" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>{$page_title}</title>
<!-- TemplateEndEditable --><!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link href="{$ecs_css_path}" rel="stylesheet" type="text/css" />
{* 包含脚本文件 *}
{insert_scripts files='transport.js,common.js,user.js'}
</head>
<body>
<!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->
<div class="user_here"><!-- #BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem --></div>
<div class="clearfix">
<div class="AreaL"><!-- #BeginLibraryItem "/library/user_menu.lbi" --><!-- #EndLibraryItem --></div>
<div class="AreaR">
<div class="box"><div class="box_1"><div class="userCenterBox boxCenterList clearfix" style="_height:1%;">
<h5><span>我的场馆</span></h5>
<table width="100%" border="0" cellspacing="1" cellpadding="0" class="table_list">
<tr>
<th>场馆名称</th>
<th width="70" align="center">状态</th>
<th width="50" align="center">编辑</th>
</tr>
<!--{foreach from=$items item=value}-->
<tr>
<td>{$value.title}</td>
<td align="center">{if $value.is_check eq 1}审核通过{else}<span style="color:#f00">等待审核</span>{/if}</td>
<td align="center"><a href="user.php?act=court_edit&id={$value.court_id}">编辑</a></td>
</tr>
<!--{/foreach}-->
</table>
</div></div></div>
</div>
</div>
<!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->
</body>
</html>
步骤四:在themes/default/library/user_menu.lbi文件中添加下面的链接地址,default是当前模板目录
<a href="user.php?act=court_add"{if $action eq 'court_add'}class="curs"{/if}>添加场馆</a>
<a href="user.php?act=court_list"{if $action eq 'court_list' || $action eq 'court_edit'}class="curs"{/if}>我的场馆</a>
步骤五:打开admin/includes/inc_menu.php文件,添加后台管理导航链接。在末尾添加一行代码:
$modules['17_diymodule']['new_court'] = 'new_court.php?act=list';
步骤六:打开languages/zh_cn/admin/common.php文件,在末尾添加语言选项。
/* 自定义模块 */ $_LANG['17_diymodule'] = '自定义模块'; $_LANG['01_new_court'] = '场馆管理';
完成步骤五和步骤六以后进入后台,你会在左侧导航的最下面发现新增加的“自定义模块”。
步骤七:在admin目录下添加文件:new_court.php
<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
/*初始化数据交换对象 */
$exc = new exchange($ecs->table("court"), $db, 'court_id', 'title');
/*------------------------------------------------------ */
//-- 场馆列表
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'list')
{
/* 取得过滤条件 */
$filter = array();
$smarty->assign('ur_here', $_LANG['new_court']);
$smarty->assign('action_link', array('text' => '添加新场馆', 'href' => 'new_court.php?act=add'));
$smarty->assign('full_page', 1);
$smarty->assign('filter', $filter);
$article_list = get_articleslist();
$smarty->assign('article_list', $article_list['arr']);
$smarty->assign('filter', $article_list['filter']);
$smarty->assign('record_count', $article_list['record_count']);
$smarty->assign('page_count', $article_list['page_count']);
$sort_flag = sort_flag($article_list['filter']);
$smarty->assign($sort_flag['tag'], $sort_flag['img']);
assign_query_info();
$smarty->display('new_court_list.htm');
}
/*------------------------------------------------------ */
//-- 翻页,排序
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'query')
{
check_authz_json('article_manage');
$article_list = get_articleslist();
$smarty->assign('article_list', $article_list['arr']);
$smarty->assign('filter', $article_list['filter']);
$smarty->assign('record_count', $article_list['record_count']);
$smarty->assign('page_count', $article_list['page_count']);
$sort_flag = sort_flag($article_list['filter']);
$smarty->assign($sort_flag['tag'], $sort_flag['img']);
make_json_result($smarty->fetch('new_court_list.htm'), '',
array('filter' => $article_list['filter'], 'page_count' => $article_list['page_count']));
}
/*------------------------------------------------------ */
//-- 添加场馆
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'add')
{
/*初始化*/
$article = array();
if (isset($_GET['id']))
{
$smarty->assign('cur_id', $_GET['id']);
}
$smarty->assign('article', $article);
$smarty->assign('ur_here', '添加新场馆');
$smarty->assign('action_link', array('text' => '场馆列表', 'href' => 'new_court.php?act=list'));
$smarty->assign('form_action', 'insert');
assign_query_info();
$smarty->display('new_court_info.htm');
}
/*------------------------------------------------------ */
//-- 添加场馆
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'insert')
{
/*插入数据*/
$add_time = gmtime();
$sql = "INSERT INTO ".$ecs->table('court')."(title, types, citys, areas, charge, ".
"opens, address, tel, add_time) ".
"VALUES ('$_POST[title]', '$_POST[types]', '$_POST[citys]', '$_POST[areas]', ".
"'$_POST[charge]', '$_POST[opens]', '$_POST[address]', '$_POST[tel]', ".
"'$add_time')";
$db->query($sql);
$court_id = $db->insert_id();
$link[0]['text'] = '继续添加场馆';
$link[0]['href'] = 'new_court.php?act=add';
$link[1]['text'] = '返回场馆列表';
$link[1]['href'] = 'new_court.php?act=list';
admin_log($_POST['title'],'add','场馆');
clear_cache_files(); // 清除相关的缓存文件
sys_msg('添加成功',0, $link);
}
/*------------------------------------------------------ */
//-- 编辑
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'edit')
{
/* 取场馆数据 */
$article = $db->GetRow("SELECT * FROM " .$ecs->table('court'). " WHERE court_id='$_REQUEST[id]'");
$smarty->assign('article', $article);
$smarty->assign('ur_here', '编辑场馆');
$smarty->assign('action_link', array('text' => '场馆列表', 'href' => 'new_court.php?act=list&' . list_link_postfix()));
$smarty->assign('form_action', 'update');
assign_query_info();
$smarty->display('new_court_info.htm');
}
if ($_REQUEST['act'] =='update')
{
if ($exc->edit("title='$_POST[title]', types='$_POST[types]', citys='$_POST[citys]', areas='$_POST[areas]', charge='$_POST[charge]', opens='$_POST[opens]', address ='$_POST[address]', tel ='$_POST[tel]', is_check='$_POST[is_check]'", $_POST['id']))
{
$link[0]['text'] = '返回列表';
$link[0]['href'] = 'new_court.php?act=list&' . list_link_postfix();
$link[1]['text'] = '继续编辑';
$link[1]['href'] = 'new_court.php?act=edit&id=' . $_POST['id'];
$note = sprintf('场馆编辑成功', stripslashes($_POST['title']));
admin_log($_POST['title'], 'edit', 'article');
clear_cache_files();
sys_msg($note, 0, $link);
}
else
{
die($db->error());
}
}
/*------------------------------------------------------ */
//-- 编辑场馆名称
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_title')
{
$id = intval($_POST['id']);
$title = json_str_iconv(trim($_POST['val']));
if ($exc->edit("title = '$title'", $id))
{
clear_cache_files();
admin_log($title, 'edit', 'article');
make_json_result(stripslashes($title));
}
else
{
make_json_error($db->error());
}
}
/*------------------------------------------------------ */
//-- 删除场馆
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'remove')
{
$id = intval($_GET['id']);
$db->query("DELETE FROM " . $ecs->table('court') . " WHERE " . "court_id = $id");
$url = 'new_court.php?act=query&' . str_replace('act=remove', '', $_SERVER['QUERY_STRING']);
ecs_header("Location: $url\n");
exit;
}
/*------------------------------------------------------ */
//-- 批量操作
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'batch')
{
/* 批量删除 */
if (isset($_POST['type']))
{
if ($_POST['type'] == 'button_remove')
{
if (!isset($_POST['checkboxes']) || !is_array($_POST['checkboxes']))
{
sys_msg($_LANG['no_select_article'], 1);
}
foreach ($_POST['checkboxes'] AS $key => $id)
{
$db->query("DELETE FROM " . $ecs->table('court') . " WHERE " . "court_id = $id");
}
}
}
/* 清除缓存 */
clear_cache_files();
$lnk[] = array('text' => '返回列表', 'href' => 'new_court.php?act=list');
sys_msg($_LANG['batch_handle_ok'], 0, $lnk);
}
/* 获得场馆列表 */
function get_articleslist()
{
$result = get_filter();
if ($result === false)
{
$filter = array();
$filter['keyword'] = empty($_REQUEST['keyword']) ? '' : trim($_REQUEST['keyword']);
if (isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax'] == 1)
{
$filter['keyword'] = json_str_iconv($filter['keyword']);
}
$filter['cat_id'] = empty($_REQUEST['cat_id']) ? 0 : intval($_REQUEST['cat_id']);
$filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'a.court_id' : trim($_REQUEST['sort_by']);
$filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
$where = '';
if (!empty($filter['keyword']))
{
$where = " AND a.title LIKE '%" . mysql_like_quote($filter['keyword']) . "%'";
}
/* 场馆总数 */
$sql = 'SELECT COUNT(*) FROM ' .$GLOBALS['ecs']->table('court'). ' AS a '.
'WHERE 1 ' .$where;
$filter['record_count'] = $GLOBALS['db']->getOne($sql);
$filter = page_and_size($filter);
/* 获取场馆数据 */
$sql = 'SELECT a.* '.
'FROM ' .$GLOBALS['ecs']->table('court'). ' AS a '.
'WHERE 1 ' .$where. ' ORDER by '.$filter['sort_by'].' '.$filter['sort_order'];
$filter['keyword'] = stripslashes($filter['keyword']);
set_filter($filter, $sql);
}
else
{
$sql = $result['sql'];
$filter = $result['filter'];
}
$arr = array();
$res = $GLOBALS['db']->selectLimit($sql, $filter['page_size'], $filter['start']);
while ($rows = $GLOBALS['db']->fetchRow($res))
{
$rows['date'] = local_date("Y-m-d", $rows['add_time']);
$arr[] = $rows;
}
return array('arr' => $arr, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
}
?>
步骤八:在admin/templates目录下添加两个文件: new_court_list.htm 和 new_court_info.htm
new_court_list.htm
<!-- $Id: article_list.htm 16783 2009-11-09 09:59:06Z liuhui $ -->
{if $full_page}
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js"}
<div class="form-div">
<form action="javascript:searchArticle()" name="searchForm" >
<img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
名称:
{$lang.title} <input type="text" name="keyword" id="keyword" />
<input type="submit" value="{$lang.button_search}" class="button" />
</form>
</div>
<form method="POST" action="new_court.php?act=batch_remove" name="listForm">
<!-- start cat list -->
<div class="list-div" id="listDiv">
{/if}
<table cellspacing='1' cellpadding='3' id='list-table'>
<tr>
<th align="left"><input onclick='listTable.selectAll(this, "checkboxes")' type="checkbox">
<a href="javascript:listTable.sort('court_id'); ">编号</a>{$sort_court_id}</th>
<th><a href="javascript:listTable.sort('title'); ">场馆名称</a>{$sort_title}</th>
<th><a href="javascript:listTable.sort('types'); ">场馆类型</a>{$sort_types}</th>
<th><a href="javascript:listTable.sort('citys'); ">所在城市</a>{$sort_citys}</th>
<th><a href="javascript:listTable.sort('is_check'); ">审核状态</a>{$sort_is_check}</th>
<th><a href="javascript:listTable.sort('add_time'); ">添加时间</a>{$sort_add_time}</th>
<th>{$lang.handler}</th>
</tr>
{foreach from=$article_list item=list}
<tr>
<td><span><input name="checkboxes[]" type="checkbox" value="{$list.court_id}"/>{$list.court_id}</span></td>
<td class="first-cell">
<span onclick="javascript:listTable.edit(this, 'edit_title', {$list.court_id})">{$list.title|escape:html}</span></td>
<td align="center">{$list.types}</td>
<td align="center">{$list.citys}</td>
<td align="center">{if $list.is_check eq 1}审核通过{else}<span style="color:#F00">等待审核</span>{/if}</td>
<td align="center"><span>{$list.date}</span></td>
<td align="center" nowrap="true"><span>
<a href="new_court.php?act=edit&id={$list.court_id}" title="{$lang.edit}"><img src="images/icon_edit.gif" border="0" height="16" width="16" /></a>
<a href="javascript:;" onclick="listTable.remove({$list.court_id}, '{$lang.drop_confirm}')" title="{$lang.remove}"><img src="images/icon_drop.gif" border="0" height="16" width="16"></a></span>
</td>
</tr>
{foreachelse}
<tr><td class="no-records" colspan="10">{$lang.no_article}</td></tr>
{/foreach}
<tr>
<td align="right" nowrap="true" colspan="8">{include file="page.htm"}</td>
</tr>
</table>
{if $full_page}
</div>
<div>
<input type="hidden" name="act" value="batch" />
<select name="type" id="selAction" onchange="changeAction()">
<option value="">{$lang.select_please}</option>
<option value="button_remove">批量删除</option>
</select>
<select name="target_cat" style="display:none">
<option value="0">{$lang.select_please}</option>
{$cat_select}
</select>
<input type="submit" value="{$lang.button_submit}" id="btnSubmit" name="btnSubmit" class="button" disabled="true" />
</div>
</form>
<!-- end cat list -->
<script type="text/javascript" language="JavaScript">
listTable.recordCount = {$record_count};
listTable.pageCount = {$page_count};
{foreach from=$filter item=item key=key}
listTable.filter.{$key} = '{$item}';
{/foreach}
{literal}
onload = function()
{
// 开始检查订单
startCheckOrder();
}
/**
* @param: bool ext 其他条件:用于转移分类
*/
function confirmSubmit(frm, ext)
{
if (frm.elements['type'].value == 'button_remove')
{
return confirm(drop_confirm);
}
else if (frm.elements['type'].value == 'not_on_sale')
{
return confirm(batch_no_on_sale);
}
else if (frm.elements['type'].value == 'move_to')
{
ext = (ext == undefined) ? true : ext;
return ext && frm.elements['target_cat'].value != 0;
}
else if (frm.elements['type'].value == '')
{
return false;
}
else
{
return true;
}
}
function changeAction()
{
var frm = document.forms['listForm'];
// 切换分类列表的显示
frm.elements['target_cat'].style.display = frm.elements['type'].value == 'move_to' ? '' : 'none';
if (!document.getElementById('btnSubmit').disabled &&
confirmSubmit(frm, false))
{
frm.submit();
}
}
/* 搜索文章 */
function searchArticle()
{
listTable.filter.keyword = Utils.trim(document.forms['searchForm'].elements['keyword'].value);
listTable.filter.page = 1;
listTable.loadList();
}
{/literal}
</script>
{include file="pagefooter.htm"}
{/if}
new_court_info.htm
<!-- $Id: article_info.htm 16780 2009-11-09 09:28:30Z sxc_shop $ -->
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,selectzone.js,validator.js"}
<!-- start goods form -->
<div class="tab-div">
<div id="tabbody-div">
<form action="new_court.php" method="post" enctype="multipart/form-data" name="theForm" onsubmit="return validate();">
<table width="90%" id="general-table">
<tr>
<td class="narrow-label">场馆名称</td>
<td><input type="text" name="title" size ="40" maxlength="60" value="{$article.title|escape}" />{$lang.require_field}</td>
</tr>
<tr>
<td class="narrow-label">场馆类型</td>
<td><input type="text" name="types" value="{$article.types|escape}" /></td>
</tr>
<tr>
<td class="narrow-label">所在城市</td>
<td><input type="text" name="citys" value="{$article.citys|escape}" /></td>
</tr>
<tr>
<td class="narrow-label">场地数量</td>
<td><input type="text" name="areas" value="{$article.areas|escape}" /></td>
</tr>
<tr>
<td class="narrow-label">收费标准</td>
<td><textarea name="charge" id="charge" cols="40" rows="5">{$article.charge|escape}</textarea></td>
</tr>
<tr>
<td class="narrow-label">开放时间</td>
<td><input type="text" name="opens" value="{$article.opens|escape}" /></td>
</tr>
<tr>
<td class="narrow-label">地址</td>
<td><input type="text" name="address" value="{$article.address|escape}" /></td>
</tr>
<tr>
<td class="narrow-label">电话</td>
<td><input type="text" name="tel" value="{$article.tel|escape}" /></td>
</tr>
<tr>
<td class="narrow-label">状态</td>
<td>
<input type="radio" name="is_check" value="1" {if $article.is_check eq 1}checked="checked"{/if} />审核通过
<input type="radio" name="is_check" value="0" {if $article.is_check eq 0}checked="checked"{/if} />等待审核
</td>
</tr>
</table>
<div class="button-div">
<input type="hidden" name="act" value="{$form_action}" />
<input type="hidden" name="old_title" value="{$article.title}"/>
<input type="hidden" name="id" value="{$article.court_id}" />
<input type="submit" value="{$lang.button_submit}" class="button" />
<input type="reset" value="{$lang.button_reset}" class="button" />
</div>
</form>
</div>
</div>
<!-- end goods form -->
<script language="JavaScript">
var articleId = {$article.article_id|default:0};
var elements = document.forms['theForm'].elements;
var sz = new SelectZone(1, elements['source_select'], elements['target_select'], '');
{literal}
onload = function()
{
// 开始检查订单
startCheckOrder();
}
function validate()
{
var validator = new Validator('theForm');
validator.required('title', no_title);
{/literal}
{if $article.cat_id >= 0}
validator.isNullOption('article_cat',no_cat);
{/if}
{literal}
return validator.passed();
}
function showNotice(objId)
{
var obj = document.getElementById(objId);
if (obj)
{
if (obj.style.display != "block")
{
obj.style.display = "block";
}
else
{
obj.style.display = "none";
}
}
}
function searchGoods()
{
var elements = document.forms['theForm'].elements;
var filters = new Object;
filters.cat_id = elements['cat_id'].value;
filters.brand_id = elements['brand_id'].value;
filters.keyword = Utils.trim(elements['keyword'].value);
sz.loadOptions('get_goods_list', filters);
}
{/literal}
</script>
{include file="pagefooter.htm"}
到这里我们添加的自定义模块已经基本可以使用了,这个例子比较简单,只包含会员录入数据,管理员编辑审核的功能,可以更具这个例子修改为你想要的功能和样式。
本例子还有可以升级的地方,比如上传图片生成缩略图,调用FCK编辑器,会员后台列表分页功能,删除数据功能等等,这些暂时不添加。
