数据库
CREATE TABLE IF NOT EXISTS `ims_tbk_banner` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`weid` int(11) NOT NULL,
`listorder` int(11) NOT NULL,
`title` varchar(20) NOT NULL,
`thumb` varchar(200) NOT NULL,
`links` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
模板
{template 'common/header'}
<ul class="nav nav-tabs">
<li {if $op == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('banner', array('op' => 'post'))}">添加幻灯</a></li>
<li {if $op == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('banner', array('op' => 'display'))}">管理幻灯</a></li>
</ul>
{if $op == 'post'}
<div class="main">
<form action="" method="post" class="form-horizontal form">
<h4>幻灯详细设置</h4>
<table class="tb">
<tr>
<th><label for="">排序</label></th>
<td>
<input type="text" name="listorder" class="span6" value="{$item['listorder']}" />
</td>
</tr>
<tr>
<th><label for="">幻灯名称</label></th>
<td>
<input type="text" name="title" class="span6" value="{$item['title']}" />
</td>
</tr>
<tr>
<th><label for="">幻灯图片</label></th>
<td>
{php echo tpl_form_field_image('thumb', $item['thumb'])}
</td>
</tr>
<tr>
<th><label for="">链接地址</label></th>
<td>
<input type="text" name="links" class="span6" value="{$item['links']}" />
</td>
</tr>
<tr>
<th></th>
<td>
<input name="submit" type="submit" value="提交" class="btn btn-primary span3">
<input type="hidden" name="token" value="{$_W['token']}" />
</td>
</tr>
</table>
</form>
</div>
{elseif $op == 'display'}
<div class="main">
<div class="category">
<form action="" method="post" οnsubmit="return formcheck(this)">
<table class="table table-hover">
<thead>
<tr>
<th style="width:10px;"></th>
<th style="width:60px;">显示顺序</th>
<th style="width:80px;">幻灯名称</th>
<th style="width:200px;">幻灯图片</th>
<th style="width:80px;">操作</th>
</tr>
</thead>
<tbody>
{loop $list $row}
<tr>
<td>{$row['id']}</td>
<td><input type="text" class="span1" name="listorder[{$row['id']}]" value="{$row['listorder']}"></td>
<td>{$row['title']}</td>
<td>{if empty($row['links'])}<img src="{php echo toimage($row['thumb'])}" width="180">{else}
<a href="{$row['links']}" target="_blank"><img src="{php echo toimage($row['thumb'])}" width="180"></a>{/if}</td>
<td><a href="{php echo $this->createWebUrl('banner', array('op' => 'post', 'id' => $row['id']))}">编辑</a> <a href="{php echo $this->createWebUrl('banner', array('op' => 'delete', 'id' => $row['id']))}" οnclick="return confirm('确认删除此幻灯吗?');return false;">删除</a></td>
</tr>
{/loop}
<tr>
<td></td>
<td colspan="4">
<a href="{php echo $this->createWebUrl('banner', array('op' => 'post'))}"><i class="icon-plus-sign-alt"></i> 添加新幻灯</a>
</td>
</tr>
<tr>
<td></td>
<td colspan="4">
<input name="submit" type="submit" class="btn btn-primary" value="提交">
<input type="hidden" name="token" value="{$_W['token']}" />
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
{/if}
{template 'common/footer'}
数据处理
<?php
defined('IN_IA') or exit('Access Denied');
$table='tbk_banner';
$op=empty($_GPC['op'])?'display':$_GPC['op'];
$do=empty($_GPC['do'])?'banner':$_GPC['do'];
if($_GPC['op']=='post'){
$field=array('listorder','title','thumb','links');
$id=intval($_GPC['id']);
if($_W['ispost']){
//保存数据
foreach($field as $v){
$insert[$v]=$_GPC[$v];
}
if($id>0){
$temp=pdo_update($table, $insert, array('id' => $id,'weid'=>$_W['weid']));
}else{
$insert['weid']=$_W['weid'];
$temp=pdo_insert($table,$insert);
}
if($temp===false){
message('抱歉,数据操作失败!','', 'error');
}else{
message('更新数据成功!', $this->createWeburl($do), 'success');
}
}
if($id>0){
$item=pdo_fetch('select * from '.tablename($table).' where weid=:weid AND id=:id',array(':weid'=>$_W['weid'],':id'=>$id));
}
if($item==false){
//初始数值
$item=array(
'listorder'=>0
);
}
}elseif($op=='delete'){
$id=intval($_GPC['id']);
if(empty($id)){
message('参数错误,请确认操作');
}
$temp = pdo_delete($table,array('id'=>$id,'weid'=>$_W['weid']));
if($temp==false){
message('抱歉,刚才修改的数据失败!','', 'error');
}else{
message('删除数据成功!',$this->createWeburl($do), 'success');
}
}elseif($op=='display'){
if($_W['ispost']){
if(!empty($_GPC['listorder'])){
foreach ($_GPC['displayorder'] as $id => $value) {
pdo_update($table, array('listorder' => $value), array('id' => $id));
}
message('分类排序更新成功!', $this->createWebUrl($do, array('op' => 'display')), 'success');
}
}
$where="WHERE weid=".$_W['weid']." ";
$pindex = max(1, intval($_GPC['page']));
$psize = 20;
$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename($table) . $where);
$start = ($pindex - 1) * $psize;
$where .= " order by `listorder` desc LIMIT {$start},{$psize}";
$list = pdo_fetchall("SELECT * FROM ".tablename($table)." ".$where);
$pager = pagination($total, $pindex, $psize);
}
include $this->template($do);