basepath = '../fckeditor/'; // 设置fckeditor目录地址
/*action操作初始化*/
if(emptyempty($_request['action'])){
$_request['action']='list';
}else {
$_request['action']=trim($_request['action']);
}
if($_request['action']=='add'){
$ofckeditor = new fckeditor(content) ; // 创建fckeditor实例,可创建多个实例
$ofckeditor->basepath = '../fckeditor/'; // 设置fckeditor目录地址
$tpl->assign('fck',$ofckeditor->create());
$tpl->assign('tmess','添加文章');
$tpl->assign('act','insert');
$tpl->assign('submitbutton','添加');
$tpl->display('admin/addarticle.tpl');
}
/*添加文章*/
elseif ($_request['action']=='insert'){
$title=$_post['title'];
$zhaiyao=$_post['zhaiyao'];
$author=$_post['author'];
$laiyuan=$_post['laiyuan'];
$keyword=$_post['keyword'];
$is_tuijian=$_post['is_tuijian'];
$content=$_post['content'];
$sql=insert into article (title,zhaiyao,author,laiyuan,keyword,is_tuijian,content,addtime) values
('$title','$zhaiyao','$author','$laiyuan','$keyword','$is_tuijian','$content',now());
$rs=$db->query($sql);
if($rs){
echo header(location:/admin/article.php?action=list);
}else {
echo 失败!;
}
}
/*文章列表*/
elseif ($_request['action']=='list'){
$total=getallarticle();
$curpage=isset($_get['page'])?$_get['page']:1;
$pageobj=new page($total,$curpage);
$pageinfo=$pageobj->getpageinfo();
$arts=getarticlepage($pageinfo['row_offset'],$pageinfo['row_num']);
$tpl->assign(tmess,文章列表);
$tpl->assign(arts,$arts);
$tpl->assign(pageinfo,$pageinfo);
$tpl->display(admin/editarticle.tpl);
}
/*修改文章*/
elseif ($_request['action']=='edit'){
$id=$_get['id'];
$post=editarticle($id);
$tpl->assign(tmess,修改文章);
$tpl->assign('post',$post);
$ofckeditor->value=$post[content]; //编辑时显示文章内容
if($post['is_tuijian']==1||$_post[recommend]==1){ //判断是否推荐
$tpl->assign('recommend','checked');
}else {
$tpl->assign('no_recommend','checked');
}
$tpl->assign('fck',$ofckeditor->create());
$tpl->assign(act,update);
$tpl->assign('submitbutton','修改');
$tpl->display('admin/addarticle.tpl');
}elseif ($_request['action']=='update'){
$id=$_post['id'];
$title=$_post['title'];
$zhaiyao=$_post['zhaiyao'];
$author=$_post['author'];
$laiyuan=$_post['laiyuan'];
$keyword=$_post['keyword'];
$is_tuijian=$_post['is_tuijian'];
$content=$_post['content'];
$sql=update article set title='$title',zhaiyao='$zhaiyao',author='$author',laiyuan='$laiyuan',keyword='$keyword',is_tuijian='$is_tuijian',
content='$content' where id ='$id';
$rs=$db->query($sql);
if($rs){
echo header(location:/admin/article.php?action=list);
}else {
echo 修改失败!;
}
}
/*删除*/
elseif ($_request['action']=='del'){
$id=$_get['id'];
del($id);
}
/*审核文章*/
elseif ($_request['action']=='shenhe'){
$id=$_get['id'];
shenhe($id);
}
/*锁定文章*/
elseif ($_request['action']=='lock'){
$id=$_get['id'];
lock($id);
}
/*批量删除*/
/*批量审核*/
elseif (isset($_request['shenhe_x'])||isset($_request['shenhe_y'])){
$del=$_post['del'];
shenhe($del);
}
/*批量锁定*/
elseif (isset($_request['lock_x'])||isset($_request['lock_y'])){
$del=$_post['del'];
lock($del);
}
/*=======文章模块相关函数==========*/
/**
* 获取所有的文章进行分页用
* */
function getallarticle(){
global $db;
$sql=select * from article;
$rs=$db->query($sql);
$total=$db->num_rows($rs);
return $total;
}
/*文章分页相关函数*/
function getarticlepage($offset,$num){
global $db;
$sql=select*from article order by id desc limit $offset,$num;
$rs=$db->query($sql);
while ($row=$db->fetch_array($rs)){
$data[]=$row;
}
return $data;
}
/*文章修改*/
function editarticle($id){
global $db;
$sql=select * from article where id = '$id';
$rs=$db->query($sql);
return $row=$db->fetch_array($rs,mysql_assoc);
}
/*删除文章*/
function del($id){
global $db;
$sql=delete from article where id;
if(is_array($id)){
$sql.=in (.implode(,,$id).);
}else {
$sql.==$id;
}
$rs=$db->query($sql);
if($rs){
echo header(location:/admin/article.php?action=list);
}else {
echo 删除失败!;
}
}
function shenhe($id){
global $db;
$sql=update article set status='1' where id;
if(is_array($id)){
$sql.=in (.join(,,$id).); //如果$id是一个数组,用join函数把$id分割成用,连接的字符串 join是implode的别名
}else {
$sql.==$id;
}
$rs=$db->query($sql);
if($rs){
echo header(location:/admin/article.php?action=list);
}else {
echo 审核失败!;
}
}
function lock($id){
global $db;
$sql=update article set status='0' where id ;
if(is_array($id)){
$sql.=in (.implode(,,$id).);
}else {
$sql.==$id;
}
$rs=$db->query($sql);
if($rs){
echo header(location:/admin/article.php?action=list);
}else {
echo 锁定失败!;
}
}
?>
basepath = '../fckeditor/'; // 设置fckeditor目录地址
/*action操作初始化*/
if(empty($_request['action'])){
$_request['action']='list';
}else {
$_request['action']=trim($_request['action']);
}
if($_request['action']=='add'){
$ofckeditor = new fckeditor(content) ; // 创建fckeditor实例,可创建多个实例
$ofckeditor->basepath = '../fckeditor/'; // 设置fckeditor目录地址
$tpl->assign('fck',$ofckeditor->create());
$tpl->assign('tmess','添加文章');
$tpl->assign('act','insert');
$tpl->assign('submitbutton','添加');
$tpl->display('admin/addarticle.tpl');
}
/*添加文章*/
elseif ($_request['action']=='insert'){
$title=$_post['title'];
$zhaiyao=$_post['zhaiyao'];
$author=$_post['author'];
$laiyuan=$_post['laiyuan'];
$keyword=$_post['keyword'];
$is_tuijian=$_post['is_tuijian'];
$content=$_post['content'];
$sql=insert into article (title,zhaiyao,author,laiyuan,keyword,is_tuijian,content,addtime) values
('$title','$zhaiyao','$author','$laiyuan','$keyword','$is_tuijian','$content',now());
$rs=$db->query($sql);
if($rs){
echo header(location:/admin/article.php?action=list);
}else {
echo 失败!;
}
}
/*文章列表*/
elseif ($_request['action']=='list'){
$total=getallarticle();
$curpage=isset($_get['page'])?$_get['page']:1;
$pageobj=new page($total,$curpage);
$pageinfo=$pageobj->getpageinfo();
$arts=getarticlepage($pageinfo['row_offset'],$pageinfo['row_num']);
$tpl->assign(tmess,文章列表);
$tpl->assign(arts,$arts);
$tpl->assign(pageinfo,$pageinfo);
$tpl->display(admin/editarticle.tpl);
}
/*修改文章*/
elseif ($_request['action']=='edit'){
$id=$_get['id'];
$post=editarticle($id);
$tpl->assign(tmess,修改文章);
$tpl->assign('post',$post);
$ofckeditor->value=$post[content]; //编辑时显示文章内容
if($post['is_tuijian']==1||$_post[recommend]==1){ //判断是否推荐
$tpl->assign('recommend','checked');
}else {
$tpl->assign('no_recommend','checked');
}
$tpl->assign('fck',$ofckeditor->create());
$tpl->assign(act,update);
$tpl->assign('submitbutton','修改');
$tpl->display('admin/addarticle.tpl');
}elseif ($_request['action']=='update'){
$id=$_post['id'];
$title=$_post['title'];
$zhaiyao=$_post['zhaiyao'];
$author=$_post['author'];
$laiyuan=$_post['laiyuan'];
$keyword=$_post['keyword'];
$is_tuijian=$_post['is_tuijian'];
$content=$_post['content'];
$sql=update article set title='$title',zhaiyao='$zhaiyao',author='$author',laiyuan='$laiyuan',keyword='$keyword',is_tuijian='$is_tuijian',
content='$content' where id ='$id';
$rs=$db->query($sql);
if($rs){
echo header(location:/admin/article.php?action=list);
}else {
echo 修改失败!;
}
}
/*删除*/
elseif ($_request['action']=='del'){
$id=$_get['id'];
del($id);
}
/*审核文章*/
elseif ($_request['action']=='shenhe'){
$id=$_get['id'];
shenhe($id);
}
/*锁定文章*/
elseif ($_request['action']=='lock'){
$id=$_get['id'];
lock($id);
}
/*批量删除*/
/*批量审核*/
elseif (isset($_request['shenhe_x'])||isset($_request['shenhe_y'])){
$del=$_post['del'];
shenhe($del);
}
/*批量锁定*/
elseif (isset($_request['lock_x'])||isset($_request['lock_y'])){
$del=$_post['del'];
lock($del);
}
/*=======文章模块相关函数==========*/
/**
* 获取所有的文章进行分页用
* */
function getallarticle(){
global $db;
$sql=select * from article;
$rs=$db->query($sql);
$total=$db->num_rows($rs);
return $total;
}
/*文章分页相关函数*/
function getarticlepage($offset,$num){
global $db;
$sql=select*from article order by id desc limit $offset,$num;
$rs=$db->query($sql);
while ($row=$db->fetch_array($rs)){
$data[]=$row;
}
return $data;
}
/*文章修改*/
function editarticle($id){
global $db;
$sql=select * from article where id = '$id';
$rs=$db->query($sql);
return $row=$db->fetch_array($rs,mysql_assoc);
}
/*删除文章*/
function del($id){
global $db;
$sql=delete from article where id;
if(is_array($id)){
$sql.=in (.implode(,,$id).);
}else {
$sql.==$id;
}
$rs=$db->query($sql);
if($rs){
echo header(location:/admin/article.php?action=list);
}else {
echo 删除失败!;
}
}
function shenhe($id){
global $db;
$sql=update article set status='1' where id;
if(is_array($id)){
$sql.=in (.join(,,$id).); //如果$id是一个数组,用join函数把$id分割成用,连接的字符串 join是implode的别名
}else {
$sql.==$id;
}
$rs=$db->query($sql);
if($rs){
echo header(location:/admin/article.php?action=list);
}else {
echo 审核失败!;
}
}
function lock($id){
global $db;
$sql=update article set status='0' where id ;
if(is_array($id)){
$sql.=in (.implode(,,$id).);
}else {
$sql.==$id;
}
$rs=$db->query($sql);
if($rs){
echo header(location:/admin/article.php?action=list);
}else {
echo 锁定失败!;
}
}
?>
摘自 chaojie2009的专栏
http://www.bkjia.com/phpjc/478371.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/478371.htmltecharticle?php /** * 文章 * 2011/9/21 * kcj * */ include islogin.php; include ../conn/config.inc.php; include_once(../fckeditor/fckeditor.php); $ofckeditor = new fckeditor(content) ; // 创建...