这是一个很简单插件实例,通过此插件,你可以知道怎么样开发一个插件,它结构是怎么设置的,数据库,后台等。
文件结构:
enroll.php文件在plus文件下
enroll.htm文件在templets/plus文件夹下
adenroll.php文件在dede文件夹下
adenroll.html文件dede/templet文件夹下
sql文件:
CREATETABLEIFNOTEXISTS`dede_enroll`(
`id`int(4)NOTNULLauto_increment,
`name`varchar(20)NOTNULL,
`mail`varchar(30)NOTNULL,
`tag`tinyint(1)NOTNULLdefault'0',
PRIMARYKEY(`id`)
)ENGINE=InnoDBDEFAULTCHARSET=utf8AUTO_INCREMENT=1;
INSERTINTO`dede_plus`(`aid`,`plusname`,`menustring`,`mainurl`,`writer`,`isshow`,`filelist`)VALUES
(30,'网上报名','<m:itemname=''网上报名''link=''adenroll.php''rank=''plus_网上报名''target=''main''/>','','g1000',1,'');
这里说明下为了方便我简单的设置了两个字段姓名和邮箱tag字段是标示是否录取1为录取
第一个insert语句是添加到后台管理
第二个insert语句是添加到前台导航栏
enroll.php
复制代码
<?php
//*******要先包含common.inc.php然后session_start();否则取不到session的值
//*******因为common.inc.php有关于session路径的配置
include_oncedirname(__FILE__).'./../include/common.inc.php';//包含配置文件
session_start();
require_onceDEDEINC."/arc.partview.class.php";//包含partiew类
//*****实例化这个类的作用是得到头部导航栏和尾部信息若不需要可以使用dedetemplate.class.php这个类
$pv=newPartView();
if($_POST){
if(CheckEmail($_POST['mail'])==false){//验证邮箱方法在common.func.php公用函数
ShowMsg('邮箱格式错误','-1');
exit();
}
if($_POST['name']==""){
ShowMsg('用户名不能为空','-1');
exit();
}else{
$name=htmlspecialchars($_POST['name']);
}
if($_SESSION['dd_ckstr']!=strtolower($_POST['validation'])){//验证验证码必须转换成小写
ShowMsg('验证码错误',-1);
exit();
}
$sql="insertinto`cms_enroll`(name,mail)values('$name','$_POST[mail]')";
//********$db可直接使用系统自动实例化了dedesql.class.php
$affected=$db->ExecuteNoneQuery2($sql);//执行一条语句返回影响值
if($affected){
ShowMsg('报名成功',-1);
}
}else{
$pv->SetTemplet(DEDETEMPLATE.'/plus/enroll.htm');//设置模板
$pv->Display();//显示页面
}
?>
enroll.htm
复制代码
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>{dede:global.cfg_webname/}-在线报名</title>
<linkhref="http://{dede:global.cfg_templeturl/}/style/dedecms.css"rel="stylesheet"media="screen"type="text/css"/>
</script>
</head>
<body>
{dede:includefilename="../default/head.htm"/}<!--包含头部-->
<blockquotestyle="margin:50pxauto">
<formmethod="post"action="">
姓名:<inputtype="text"size=30name="name"/><br/><br/>
邮箱:<inputtype="text"size=30name="mail"/><br/><br/>
<!--vdimgck.php是验证码-->
验证码:<inputtype="text"name="validation"/><imgsrc="http://../../include/vdimgck.php"/><br/><br/>
<inputname="encoll"type="submit"value="报名"/><br/>
</form>
</blockquote>
{dede:includefilename="../default/footer.htm"/}<!--包含尾部-->
</body>
</html>
adenroll.php
复制代码
<?php
require_once(dirname(__FILE__).'/config.php');//后台配置文件检查登陆配置信息
require_once(DEDEINC."/datalistcp.class.php");//包含分页类
if($_GET['action']&&$_GET['id']){
if($_GET['action']=='pass'){//各种操作
$db->ExecuteNoneQuery("updatecms_enrollset`tag`=1whereid='$_GET[id]'");
ShowMsg('录取成功','adenroll.php');
}
if($_GET['action']=='nopass'){
$db->ExecuteNoneQuery("updatecms_enrollset`tag`=0whereid='$_GET[id]'");
ShowMsg('取消录取','adenroll.php');
}
if($_GET['action']=='delete'){
$db->ExecuteNoneQuery("deletefromcms_enrollwhereid='$_GET[id]'");
ShowMsg('删除成功','adenroll.php');
}
}else{
$dl=newDataListCP();
$dl->pageSize=10;//每页显示10条
$dl->SetTemplate('./templets/adenroll.htm');//载入模板
$sql="select*fromcms_enroll";
$dl->SetSource($sql);//执行sql不能与$dl->SetTemplate颠倒
$dl->Display();//显示页面
}
?>
adenroll.html
复制代码
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>在线报名管理</title>
<linkhref='http://img/base.css'rel='stylesheet'type='text/css'/>
<styletype="text/css">
th,td{
text-align:center;
border:1px#D1DDAAsolid;
font-size:15px;
}
th{
background:#E6F8B7;
}
table{
margin-top:20px;
}
</style>
</head>
<body>
<tablewidth="90%"border="0"cellpadding="0"cellspacing="0"align="center">
<tr>
<th>姓名</th>
<th>E-mail</th>
<th>状态</th>
<th>操作</th>
</tr>
<!--循环得到结果-->
{dede:datalist}
<tr>
<td>{dede:field.name/}</td>
<td>{dede:field.mail/}</td>
<td>
{dede:iffield.tag==0}
未录取
{else}
<fontcolor="red">已录取</font>
{/dede:if}
</td>
<td><ahref="http://adenroll.php?action=pass&id={dede:field.id/}">[录取]</a>
|
<ahref="http://adenroll.php?action=nopass&id={dede:field.id/}">[不通过]</a>
|
<ahref="http://adenroll.php?action=delete&id={dede:field.id/}">[删除]</a>
</td>
</tr>
{/dede:datalist}
</table>
<!--分页标签-->
<pstyle="text-align:center;font-size:15px;">{dede:pagelistlistitem="info,index,end,pre,next,pageno"listsize="5"/}</p>
</body>
</html>