添加多级栏目分类的功能

This commit is contained in:
Li Jianxuan 2012-08-23 08:01:19 +00:00
parent 5e03872d38
commit 790e212a57
4 changed files with 252 additions and 88 deletions

View File

@ -80,15 +80,17 @@ class Admin_NewsController extends Zend_Controller_Action
if($add) if($add)
{ {
if(empty($submit)) if(empty($submit)){
$this->view->categories = $this->getAllcategory();
$this->_helper->viewRenderer('category-add'); $this->_helper->viewRenderer('category-add');
else{ }else{
$title = $this->_request->getParam('ctitle'); $title = $this->_request->getParam('ctitle');
$url = $this->_request->getParam('url'); $url = $this->_request->getParam('url');
$keyword = $this->_request->getParam('keyword'); $keyword = $this->_request->getParam('keyword');
$description = $this->_request->getParam('description'); $description = $this->_request->getParam('description');
$fid = $this->_request->getParam('fid');
$sql="insert into news_category (title,keywords,description,url) values ('$title','$keyword','$description','$url')"; $sql="insert into news_category (title,keywords,description,url,fid) values ('$title','$keyword','$description','$url','$fid')";
if($this->db->exec($sql) > 0) if($this->db->exec($sql) > 0)
{ {
$this->messenger->addMessage('提示信息:栏目添加成功!'); $this->messenger->addMessage('提示信息:栏目添加成功!');
@ -108,28 +110,49 @@ class Admin_NewsController extends Zend_Controller_Action
} }
}//栏目删除 }//栏目删除
if($edit>0) if($edit>0)
{ {
$submit = $this->_getParam('submit');
if(empty($submit))
{
$this->_helper->viewRenderer('category-edit');
$this->view->info = $this->getCategory($edit);
$this->view->categories = $this->getAllcategory($edit);
}else{
$title = $this->_request->getParam('ctitle'); $title = $this->_request->getParam('ctitle');
$url = $this->_request->getParam('url'); $url = $this->_request->getParam('url');
$keyword = $this->_request->getParam('keyword'); $keyword = $this->_request->getParam('keyword');
$description = $this->_request->getParam('description'); $description = $this->_request->getParam('description');
$displayorder = $this->_request->getParam('displayorder'); $displayorder = $this->_request->getParam('displayorder');
$fid = $this->_request->getParam('fid');
$sql="update news_category set title='$title',keywords='$keyword',description='$description',displayorder='$displayorder',url='$url' where id='$edit'"; $sql="update news_category set title='$title',keywords='$keyword',description='$description',displayorder='$displayorder',url='$url',fid=$fid where id=$edit";
if($this->db->exec($sql)>0) if($this->db->exec($sql)>0)
{ {
$this->messenger->addMessage('提示信息:栏目编辑成功!'); $this->messenger->addMessage('提示信息:栏目编辑成功!');
$this->_redirect('/admin/news/catlog'); $this->_redirect('/admin/news/catlog');
} }
}
}//栏目编辑 }//栏目编辑
else else
{ {
$sql="select * from news_category order by displayorder asc"; $sql="select * from news_category WHERE fid=0 order by displayorder asc";
$re=$this->db->query($sql); $re=$this->db->query($sql);
$catlogs=$re->fetchAll(); $catlogs=$re->fetchAll();
foreach($catlogs as $k=>$v)
{
$catlogs[$k]['sub'] = $this->getSubCategory($v['id']);
}
$this->view->catlogs=$catlogs; $this->view->catlogs=$catlogs;
}//栏目列表 }//栏目列表
@ -137,6 +160,42 @@ class Admin_NewsController extends Zend_Controller_Action
}//栏目管理 }//栏目管理
function getSubCategory($fid)
{
$sql = "SELECT * FROM news_category WHERE fid=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($fid));
$rows = $sth->fetchAll();
if(empty($rows) || count($rows)<1)
{
return 0;
}else{
return $rows;
}
}
function getCategory($id)
{
$sql = "SELECT * FROM news_category WHERE id=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($id));
$rows = $sth->fetch();
return $rows;
}
function getAllcategory($id=0)
{
$_addon = '';
if(!empty($id))
{
$_addon = "WHERE id not in ($id)";
}
$sql = "SELECT * FROM news_category $_addon ORDER BY id DESC";
$sth = $this->db->prepare($sql);
$sth->execute();
return $sth->fetchAll();
}
function newsaddAction() function newsaddAction()
{ {

View File

@ -32,6 +32,18 @@
<input type="text" id="ctitle" class="half" value="" name="ctitle"/> <input type="text" id="ctitle" class="half" value="" name="ctitle"/>
</p> </p>
<p>
<label>父级栏目</label><br />
<select name="fid">
<option value="0"></option>
<?php if(!empty($this->categories)) :?>
<?php foreach($this->categories as $v) : ?>
<option value="<?= $v['id'];?>"><?= $v['title'];?></option>
<?php endforeach;?>
<?php endif; ?>
</select>
</p>
<p> <p>
<label class="required" for="ctitle">栏目URL:</label><br/> <label class="required" for="ctitle">栏目URL:</label><br/>
<input type="text" id="url" class="half" value="" name="url"/>(仅小写英文字母与数字) <input type="text" id="url" class="half" value="" name="url"/>(仅小写英文字母与数字)

View File

@ -0,0 +1,85 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('<a href="/admin/news">新闻中心</a>');
$this->breadcrumb('栏目管理');
?>
<div id="leftPanel">
<?= $this->partial('news/left.phtml'); ?>
</div>
<div id="rightPanel">
<?php if ($this->msg or $this->messages) :?>
<div id="message">
<?php if ($this->msg) : ?>
<p><?php echo $this->msg; ?></p>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
<p><?php echo $msg; ?></p>
<?php endforeach;endif; ?>
</div>
<?php endif; ?>
<form id="sampleform" method="post" action="#">
<fieldset>
<legend>栏目添加</legend>
<p>
<label class="required" for="ctitle">栏目标题:</label><br/>
<input type="text" id="ctitle" class="half" value="<?= $this->info['title']?>" name="ctitle"/>
</p>
<p>
<label>父级栏目</label><br />
<select name="fid" style="width:300px">
<option value="0"></option>
<?php if(!empty($this->categories)) :?>
<?php foreach($this->categories as $v) : ?>
<?php if($v['id'] == $this->info['fid']) :?>
<option value="<?= $v['id'];?>" selected="selected"><?= $v['title'];?></option>
<?php else: ?>
<option value="<?= $v['id'];?>"><?= $v['title'];?></option>
<?php endif;?>
<?php endforeach;?>
<?php endif; ?>
</select>
</p>
<p>
<label class="required" for="ctitle">栏目URL:</label><br/>
<input type="text" id="url" class="half" value="<?= $this->info['url']?>" name="url"/>(仅小写英文字母与数字)
<small>如填写: technology 则前台访问地址为: http://westdc.westgis.ac.cn/news/technology </small>
</p>
<p>
<label class="required" for="keyword">关键字:</label><br/>
<input type="text" id="keyword" class="half" value="<?= $this->info['keywords']?>" name="keyword"/>
<small>e.g. 高程,气象,地理</small>
</p>
<p>
<label class="required" for="displayorder">显示顺序:</label><br/>
<input type="text" id="displayorder" class="half" value="" name="displayorder"/>
<small>e.g. 高程,气象,地理</small>
</p>
<p>
<label class="required" for="discript">描述:</label><br/>
<textarea id="discript" class="medium half" name="description"><?= $this->info['description']?></textarea>
<small>80个汉字以内不能使用折行</small>
</p>
<input type="hidden" name="submit" value="1" />
<input type="hidden" name="edit" value="<?= $this->info['id']?>"? />
<p class="box"><input type="submit" class="btn btn-green big" value="提交"/> or <input type="reset" class="btn" value="重置"/></p>
</fieldset>
</form>
</div>

View File

@ -52,73 +52,82 @@
<td> <td>
<div id="paddiv'.$v['id'].'"> <div id="paddiv'.$v['id'].'">
<a id="titlebtn'.$v['id'].'" class="title"><b>'.$v['title'].'</b></a> <a id="titlebtn'.$v['id'].'" class="title"><b>'.$v['title'].'</b></a>
<div class="listingDetails"> </td>
<div class="pad"> <td>
<b>编辑栏目</b> <a href="javascript:;" class="closepad" style="float:right">关闭</a> <a href="/news/'.$v['url'].'" target="_blank">浏览</a>
<form id="editform'.$v['id'].'" method="post" action="#"> <a href="/admin/news/newslist/type/'.$v['id'].'">文档</a>
<fieldset> <a href="/admin/news/catlog/edit/'.$v['id'].'"><b>编辑</b></a>
<legend>栏目信息</legend> <a href="/admin/news/catlog/delete/'.$v['id'].'" onclick="return confirm(\'是否确定删除该栏目\')">删除</a></td>
</tr>';
if(!empty($v['sub']))
{
foreach($v['sub'] as $vv)
{
echo '
<tr>
<td>
<div id="paddiv'.$vv['id'].'">
 - <a id="titlebtn'.$vv['id'].'" class="title"><b>'.$vv['title'].'</b></a>
</td>
<td>
<a href="/news/'.$vv['url'].'" target="_blank">浏览</a>
<a href="/admin/news/newslist/type/'.$vv['id'].'">文档</a>
<a href="/admin/news/catlog/edit/'.$vv['id'].'"><b>编辑</b></a>
<a href="/admin/news/catlog/delete/'.$vv['id'].'" onclick="return confirm(\'是否确定删除该栏目\')">删除</a></td>
</tr>';
}
}
}
}else{
echo '<tr><td>暂无数据</td><td></td></tr>';
}
?>
</tbody>
</table>
</div>
<div style="width:500px;display:none;" id="categoryForm">
<form id="category" style="width:500px;">
<p> <p>
<label class="required" for="ctitle">栏目标题:</label><br/> <label class="required" for="ctitle">栏目标题:</label><br/>
<input type="text" id="ctitle" class="half" value="'.$v['title'].'" name="ctitle"/> <input type="text" id="ctitle" class="half" value="" name="ctitle"/>
</p> </p>
<p> <p>
<label class="required" for="ctitle">栏目URL:</label><br/> <label class="required" for="ctitle">栏目URL:</label><br/>
<input type="text" id="url" class="half" value="'.$v['url'].'" name="url"/>(仅小写英文字母与数字) <input type="text" id="url" class="half" value="" name="url"/>(仅小写英文字母与数字)
<small>如填写: technology 则前台访问地址为: http://westdc.westgis.ac.cn/news/technology </small> <small>如填写: technology 则前台访问地址为: http://westdc.westgis.ac.cn/news/technology </small>
</p> </p>
<p> <p>
<label class="required" for="keyword">关键字:</label><br/> <label class="required" for="keyword">关键字:</label><br/>
<input type="text" id="keyword" class="half" value="'.$v['keywords'].'" name="keyword"/> <input type="text" id="keyword" class="half" value="" name="keyword"/>
<small>e.g. 高程,气象,地理</small> <small>e.g. 高程,气象,地理</small>
</p> </p>
<p> <p>
<label class="required" for="description">描述:</label><br/> <label class="required" for="description">描述:</label><br/>
<textarea id="description" class="small half" name="description">'.$v['description'].'</textarea> <textarea id="description" class="small half" name="description"></textarea>
<small>80个汉字以内不能使用折行</small> <small>80个汉字以内不能使用折行</small>
</p> </p>
<p> <p>
<label class="required" for="displayorder">排序:</label><br/> <label class="required" for="displayorder">排序:</label><br/>
<input type="text" id="roders" class="half" value="'.$v['displayorder'].'" name="displayorder"/> <input type="text" id="roders" class="half" value="" name="displayorder"/>
<small>e.g. 数字越大排序越靠前</small> <small>e.g. 数字越大排序越靠前</small>
</p> </p>
<input type="hidden" name="edit" value="'.$v['id'].'" /> <input type="hidden" name="edit" value="" />
<p class="box"><input type="submit" class="btn btn-green big" value="提交"/> or <input type="reset" class="btn" value="重置"/></p> <p class="box"><input type="submit" class="btn btn-green big" value="提交"/> or <input type="reset" class="btn" value="重置"/></p>
</fieldset> <p class="box">
<input type="hidden" name="id" id="categoryID" value="" />
<input type="button" onclick="" id="submit" class="btn btn-green big" value="提交"/> or <input type="reset" class="btn" id="resetForm" value="重置"/>
</p>
<p id="formStatus" style="display:block;">&nbsp;</p>
</form> </form>
</div> </div>
</div></div>
</td>
<td>
<a href="/news/'.$v['url'].'" target="_blank">浏览</a>
<a href="/admin/news/newslist/type/'.$v['id'].'">文档</a>
<a href="javascript:showpad('.$v['id'].');"><b>编辑</b></a>
<a href="/admin/news/catlog/delete/'.$v['id'].'" onclick="return confirm(\'是否确定删除该栏目\')">删除</a></td>
</tr>
';
}
}
else
{
echo '
<tr><td>暂无数据</td><td></td></tr>
';
}
?>
</tbody>
</table>
</div>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(document).ready(function(){
$('.title').bind('click', function() { $('.title').bind('click', function() {
@ -128,5 +137,4 @@ $(document).ready(function(){
function showpad(id){ function showpad(id){
$('#titlebtn'+id).click(); $('#titlebtn'+id).click();
} }
</script> </script>