插件的管理中心不需要cpheader()等输出头部尾部,直接输出需要的内容即可,也可加载模板,同样模板也不需要HTML头部尾部,因为以.inc.php的文件都是被嵌入的.
一个例子:
程序文件放在source/plugin/xxx/下
<?php
//echo "欢迎来到管理中心!相关程序正在开发中......";
/******************判断是否被正常引入**********************/
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
exit('Access Denied');
}
/*******创建二维数组$cardcategory,保存充值卡类别信息,下标是卡品ID********/
$result= DB::query("SELECT * FROM ".DB::table('xxjob_cardcategory'));
$cardcategory=array();
while($arr=DB::fetch($result)){
$arr['date']= dgmdate($arr['date'],'u');//将时间戳转换为距当前时长
$i=$arr['id'];
$cardcategory[$i]=$arr;
}
/****************当收到自动生成请求时********************/
if($_POST['type']=="autocreate"){
//判断数量是否小于10000
if(intval($_POST['num'])>=10000||intval($_POST['num'])<=0){
echo "<div style='color:red;'>创建失败!必须大于0小于10000条数据!</div>";
exit();
}
//准备要插入的数据
$card_id=$_POST['card_id'];
$card_name=$cardcategory[$card_id]['name'];//卡品名称
$card_money=$cardcategory[$card_id]['money'];//卡品面值
$num=intval($_POST['num']);//生成数量
$timestamp=TIMESTAMP;//时间戳
//echo $card_id." ".$card_name." ".$card_money." ".$num." ".$timestamp;//debug
$data="";//存储SQL语句中的插入数据部分
$cards="";//存储账号密码,以便在前台显示
for($i=1;$i<=$num;$i++){
//创建账号,时间戳加序号,一共14位
if($i<10) $str="000".$i;
if($i>=10&&$i<100) $str="00".$i;
if($i>=100&&$i<1000) $str="0".$i;
if($i>=1000&&$i<10000) $str=$i;
$account=$timestamp.$str;//echo $account."<br/>";//debug
//创建密码,全部随机数,一共16位
$password=rand(0,9).rand(0.9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
//创建SQL语句中的数据部分
if($i==1){
$data="('{$account}','{$password}','{$card_id}','{$card_name}','{$card_money}','1','{$timestamp}')";
}elseif($i>1){
$data.=",('{$account}','{$password}','{$card_id}','{$card_name}','{$card_money}','1','{$timestamp}')";
}
//创建充值卡明细
$card_list.=$card_name.":".$account.":".$password."<br/>";
}//for循环结束
$sql="INSERT INTO ".DB::table('xxjob_card')." (account,password,card_id,card_name,card_money,status,date) VALUES ".$data;
$create_status=DB::query($sql);
}//if语句结束
/*****************完成自动生成请求******************/
//加载模板文件
include template("chongzhi:admin");
?>
模板文件如下 ,模板文件放在source/plugin/xxx/template/下
<style type="text/css">
.recharge_box{
margging:20px;
}
.recharge_box table{
width:300px;
margin:20px;
}
.recharge_box table,.recharge_box tr,.recharge_box td{
border:3px solid black;
}
.recharge_box td{
padding:10px;
text-align: center;
}
.recharge_box textarea{
width:360px;
height:400px;
}
</style>
<div class="recharge_box">
<form action="admin.php?action=plugins&identifier=chongzhi&pmod=admin" method="post">
<table border="1" cellspacing="0">
<thead>
<tr><td>说明</td><td>操作</td></tr>
</thead>
<tbody>
<tr>
<td>选择充值卡种类</td>
<td>
<select id="select" name="card_id">
<!--{loop $cardcategory $val}-->
<option value="{$val['id']}">{$val['name']}</option>
<!--{/loop}-->
</select>
</td>
</tr>
<tr><td>生成数量(小于10000条)</td><td><input type="text" name="num" /><input type="hidden" name="type" value="autocreate" /></td></tr>
<tr><td>确认生成</td><td><input type="submit" value="生成" /></td></tr>
</tbody>
</table>
</form>
<!--{if $card_list}-->
<!--{if $create_status}-->
<div style="color:green;">成功创建充值卡,明细如下:</div>
<div style="margin:10px;height:360px;overflow: scroll;">{$card_list}</div>
<!--{else}-->
<div style="color:red;">充值卡创建失败,请重试!</div>
<!--{/if}-->
<!--{/if}-->
</div>