中转文件
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
include("./conn.php");
include("./init.inc.php");
include("./FCKeditor/fckeditor.php");
session_start();
//从PHP文件分配标量模板变量
$page_title="新闻管理系统";
$tpl->assign("page_title",$page_title);
//从PHP文件分配数组到模板
$sql="select * from news";
$result = $mysqli->query($sql);
$news=array();
while($row = $result->fetch_assoc()){
$news[]=$row;
}
$tpl->assign("news",$news);
//来自配置文件的变量(作业)
//局部缓存关闭
//$tpl->register_block("nocache","fun1",false);
// function fun1(){
// }
//采取第二种办法
//到plugins目录下新建文件
//$tpl->assign("username",$_SESSION['username']);
//fckeditor的使用
function editor($name,$value){
global $tpl;
$editor = new FCKeditor($name);
//指定在线编辑器的路径
$editor->BasePath="./FCKeditor/" ;
$editor->Toolbarset="Default";
$editor->Height=500;
$editor->Width="100%";
$editor->Value=$value;
$editor->Confit['AutoDetectLanguage']=true;
$editor->Confit['DefalutLanguage']='en';
$fck = $editor->CreateHtml();
$tpl->assign("editor",$fck);
}
//根据地址栏的参数判断使用的模板
$action=$_REQUEST['action'];//分配的变量是一样的
$id=$_REQUEST['id'];
switch($action){
case "addnewsview":
$tpl->assign("page_title","添加新闻");
$tpl->assign("actionvalue","addnews");
$tpl->assign("content_title","添加新闻管理");
editor("content","");
$tpl->display("addnews.html");
break;
case "addnews":
$title = $_REQUEST['title'];
$content = $_REQUEST['content'];
//$db=new mysql();
$button=$_REQUEST['Submit'];
if(empty($title) || empty($content)){
echo "请填写完成!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?action=addnewsview\">";
}else{
$sql="insert into news values(id,'admin','$title','$content',NOW())";
$db->query_exec($sql);
echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
}
break;
case "delnews":
$result = $mysqli->query("select * from news where id={$_REQUEST['id']}");
//$row = $result->num_rows();
for($i=0;$i<=count($result);$i++){
$sql = "delete from news where id={$_REQUEST['id']}";
}
break;
//分配模板变量
//指定模板文件
default:
$tpl->assign("page_title","新闻管理");
$tpl->assign("cotent_title","新闻管理");
$tpl->assign("actionvalue","delnews");
$mysqli->query($sql);
$sql1="select * from news";
$result=$mysqli->query($sql1);
while($row = $result->fetch_assoc()){
$news[]=$row;
}
$tpl->assign("news",$news);
$tpl->display("index.html");
}
?>
<?php
include("./conn.php");
include("./init.inc.php");
include("./FCKeditor/fckeditor.php");
session_start();
//从PHP文件分配标量模板变量
$page_title="新闻管理系统";
$tpl->assign("page_title",$page_title);
//从PHP文件分配数组到模板
$sql="select * from news";
$result = $mysqli->query($sql);
$news=array();
while($row = $result->fetch_assoc()){
$news[]=$row;
}
$tpl->assign("news",$news);
//来自配置文件的变量(作业)
//局部缓存关闭
//$tpl->register_block("nocache","fun1",false);
// function fun1(){
// }
//采取第二种办法
//到plugins目录下新建文件
//$tpl->assign("username",$_SESSION['username']);
//fckeditor的使用
function editor($name,$value){
global $tpl;
$editor = new FCKeditor($name);
//指定在线编辑器的路径
$editor->BasePath="./FCKeditor/" ;
$editor->Toolbarset="Default";
$editor->Height=500;
$editor->Width="100%";
$editor->Value=$value;
$editor->Confit['AutoDetectLanguage']=true;
$editor->Confit['DefalutLanguage']='en';
$fck = $editor->CreateHtml();
$tpl->assign("editor",$fck);
}
//根据地址栏的参数判断使用的模板
$action=$_REQUEST['action'];//分配的变量是一样的
$id=$_REQUEST['id'];
switch($action){
case "addnewsview":
$tpl->assign("page_title","添加新闻");
$tpl->assign("actionvalue","addnews");
$tpl->assign("content_title","添加新闻管理");
editor("content","");
$tpl->display("addnews.html");
break;
case "addnews":
$title = $_REQUEST['title'];
$content = $_REQUEST['content'];
//$db=new mysql();
$button=$_REQUEST['Submit'];
if(empty($title) || empty($content)){
echo "请填写完成!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?action=addnewsview\">";
}else{
$sql="insert into news values(id,'admin','$title','$content',NOW())";
$db->query_exec($sql);
echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
}
break;
case "delnews":
$result = $mysqli->query("select * from news where id={$_REQUEST['id']}");
//$row = $result->num_rows();
for($i=0;$i<=count($result);$i++){
$sql = "delete from news where id={$_REQUEST['id']}";
}
break;
//分配模板变量
//指定模板文件
default:
$tpl->assign("page_title","新闻管理");
$tpl->assign("cotent_title","新闻管理");
$tpl->assign("actionvalue","delnews");
$mysqli->query($sql);
$sql1="select * from news";
$result=$mysqli->query($sql1);
while($row = $result->fetch_assoc()){
$news[]=$row;
}
$tpl->assign("news",$news);
$tpl->display("index.html");
}
?>