添加多级栏目分类的功能
This commit is contained in:
parent
5e03872d38
commit
790e212a57
|
@ -80,15 +80,17 @@ class Admin_NewsController extends Zend_Controller_Action
|
|||
|
||||
if($add)
|
||||
{
|
||||
if(empty($submit))
|
||||
if(empty($submit)){
|
||||
$this->view->categories = $this->getAllcategory();
|
||||
$this->_helper->viewRenderer('category-add');
|
||||
else{
|
||||
}else{
|
||||
$title = $this->_request->getParam('ctitle');
|
||||
$url = $this->_request->getParam('url');
|
||||
$keyword = $this->_request->getParam('keyword');
|
||||
$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)
|
||||
{
|
||||
$this->messenger->addMessage('提示信息:栏目添加成功!');
|
||||
|
@ -108,28 +110,49 @@ class Admin_NewsController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
}//栏目删除
|
||||
|
||||
if($edit>0)
|
||||
{
|
||||
$title = $this->_request->getParam('ctitle');
|
||||
$url = $this->_request->getParam('url');
|
||||
$keyword = $this->_request->getParam('keyword');
|
||||
$description = $this->_request->getParam('description');
|
||||
$displayorder = $this->_request->getParam('displayorder');
|
||||
|
||||
$sql="update news_category set title='$title',keywords='$keyword',description='$description',displayorder='$displayorder',url='$url' where id='$edit'";
|
||||
if($this->db->exec($sql)>0)
|
||||
$submit = $this->_getParam('submit');
|
||||
if(empty($submit))
|
||||
{
|
||||
$this->messenger->addMessage('提示信息:栏目编辑成功!');
|
||||
$this->_redirect('/admin/news/catlog');
|
||||
$this->_helper->viewRenderer('category-edit');
|
||||
|
||||
$this->view->info = $this->getCategory($edit);
|
||||
$this->view->categories = $this->getAllcategory($edit);
|
||||
|
||||
}else{
|
||||
|
||||
$title = $this->_request->getParam('ctitle');
|
||||
$url = $this->_request->getParam('url');
|
||||
$keyword = $this->_request->getParam('keyword');
|
||||
$description = $this->_request->getParam('description');
|
||||
$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',fid=$fid where id=$edit";
|
||||
if($this->db->exec($sql)>0)
|
||||
{
|
||||
$this->messenger->addMessage('提示信息:栏目编辑成功!');
|
||||
$this->_redirect('/admin/news/catlog');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}//栏目编辑
|
||||
|
||||
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);
|
||||
$catlogs=$re->fetchAll();
|
||||
|
||||
foreach($catlogs as $k=>$v)
|
||||
{
|
||||
$catlogs[$k]['sub'] = $this->getSubCategory($v['id']);
|
||||
}
|
||||
|
||||
$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()
|
||||
{
|
||||
|
|
|
@ -32,6 +32,18 @@
|
|||
<input type="text" id="ctitle" class="half" value="" name="ctitle"/>
|
||||
</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>
|
||||
<label class="required" for="ctitle">栏目URL:</label><br/>
|
||||
<input type="text" id="url" class="half" value="" name="url"/>(仅小写英文字母与数字)
|
||||
|
|
|
@ -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>
|
|
@ -42,82 +42,91 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
<?php
|
||||
if(is_array($this->catlogs))
|
||||
{
|
||||
foreach($this->catlogs as $k=>$v)
|
||||
{
|
||||
foreach($this->catlogs as $k=>$v)
|
||||
{
|
||||
echo '
|
||||
<tr>
|
||||
<td>
|
||||
<div id="paddiv'.$v['id'].'">
|
||||
<a id="titlebtn'.$v['id'].'" class="title"><b>'.$v['title'].'</b></a>
|
||||
<div class="listingDetails">
|
||||
<div class="pad">
|
||||
<b>编辑栏目</b> <a href="javascript:;" class="closepad" style="float:right">关闭</a>
|
||||
<form id="editform'.$v['id'].'" method="post" action="#">
|
||||
<fieldset>
|
||||
<legend>栏目信息</legend>
|
||||
|
||||
<p>
|
||||
<label class="required" for="ctitle">栏目标题:</label><br/>
|
||||
<input type="text" id="ctitle" class="half" value="'.$v['title'].'" name="ctitle"/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label class="required" for="ctitle">栏目URL:</label><br/>
|
||||
<input type="text" id="url" class="half" value="'.$v['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="'.$v['keywords'].'" name="keyword"/>
|
||||
<small>e.g. 高程,气象,地理</small>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label class="required" for="description">描述:</label><br/>
|
||||
<textarea id="description" class="small half" name="description">'.$v['description'].'</textarea>
|
||||
<small>80个汉字以内,不能使用折行</small>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label class="required" for="displayorder">排序:</label><br/>
|
||||
<input type="text" id="roders" class="half" value="'.$v['displayorder'].'" name="displayorder"/>
|
||||
<small>e.g. 数字越大排序越靠前</small>
|
||||
</p>
|
||||
|
||||
<input type="hidden" name="edit" value="'.$v['id'].'" />
|
||||
|
||||
<p class="box"><input type="submit" class="btn btn-green big" value="提交"/> or <input type="reset" class="btn" value="重置"/></p>
|
||||
|
||||
</fieldset>
|
||||
|
||||
</form>
|
||||
</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>
|
||||
';
|
||||
}
|
||||
?>
|
||||
|
||||
<td>
|
||||
<div id="paddiv'.$v['id'].'">
|
||||
<a id="titlebtn'.$v['id'].'" class="title"><b>'.$v['title'].'</b></a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="/news/'.$v['url'].'" target="_blank">浏览</a>
|
||||
<a href="/admin/news/newslist/type/'.$v['id'].'">文档</a>
|
||||
<a href="/admin/news/catlog/edit/'.$v['id'].'"><b>编辑</b></a>
|
||||
<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>
|
||||
<label class="required" for="ctitle">栏目标题:</label><br/>
|
||||
<input type="text" id="ctitle" class="half" value="" name="ctitle"/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label class="required" for="ctitle">栏目URL:</label><br/>
|
||||
<input type="text" id="url" class="half" value="" 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="" name="keyword"/>
|
||||
<small>e.g. 高程,气象,地理</small>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label class="required" for="description">描述:</label><br/>
|
||||
<textarea id="description" class="small half" name="description"></textarea>
|
||||
<small>80个汉字以内,不能使用折行</small>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label class="required" for="displayorder">排序:</label><br/>
|
||||
<input type="text" id="roders" class="half" value="" name="displayorder"/>
|
||||
<small>e.g. 数字越大排序越靠前</small>
|
||||
</p>
|
||||
|
||||
<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="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;"> </p>
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
|
@ -128,5 +137,4 @@ $(document).ready(function(){
|
|||
function showpad(id){
|
||||
$('#titlebtn'+id).click();
|
||||
}
|
||||
|
||||
</script>
|
Loading…
Reference in New Issue