The content of index. php In the main file is as follows:
Copy codeThe Code is as follows: <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<? Php
Require ('./global. php ');
Require ('./smarty/libs/Smarty. class. php ');
Require ('./mysql. php ');
Require ('./FCKeditor/fckeditor. php ');
$ Action = $ _ REQUEST ['action'];
// Define a function to call FCK
Function editor ($ input_name, $ input_value)
{
Global $ smarty;
$ Editor = new FCKeditor ($ input_name );
$ Editor-> BasePath = "./FCKeditor/"; // specify the editor path
$ Editor-> ToolbarSet = "Default"; // The editor Toolbar contains Basic (Basic tools) and Default (all tools). Select
$ Editor-& gt; Width = "100% ";
$ Editor-& gt; Height = "320 ";
$ Editor-> Value = $ input_value;
$ Editor-> Config ['autodetectlanguage'] = true;
$ Editor-> Config ['defaultlanguage'] = 'en'; // Language
$ FCKeditor = $ editor-> CreateHtml ();
$ Smarty-> assign ("editor", $ FCKeditor); // specify a region
}
Switch ($ action ){
Case 'addnewview ':
$ Smarty = new Smarty ();
$ Smarty-> template_dir = './template ';
$ Smarty-> compile_dir = './smarty/templates_c ';
$ Smarty-> assign ('page _ title', 'create new ');
$ Smarty-> assign ('actionvalue', 'addnew ');
Editor ('content', ''); // call the editor and define the text domain name as content (corresponding to $ _ REQUEST ['content'] In addnews below)
$ Smarty-> display('addnews.htm ');
Break;
Case 'addnew ':
$ Title = $ _ REQUEST ['title'];
$ Content = $ _ REQUEST ['content'];
$ Db = new mysql ();
$ Button = $ _ REQUEST ['submit '];
If (empty ($ title) | empty ($ content )){
Echo "complete! <MetaHTTP-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 "operation successful! <META HTTP-EQUIV = \ "Refresh \" CONTENT = \ "1; URL =./index. php \"> ";
}
Break;
Case 'editnewview ':
$ Smarty = new Smarty ();
$ Smarty-> template_dir = './template ';
$ Smarty-> compile_dir = './smarty/templates_c ';
$ Smarty-> assign ('page _ title', 'modify News ');
$ Smarty-> assign ('actionvalue', 'addnew ');
$ Id = $ _ REQUEST ['id'];
$ Query = "select * from news where id = $ id ";
$ Db = new mysql ();
$ Result = $ db-> query_exec ($ query );
$ Rs = $ result-> fetch_assoc ();
$ Smarty-> assign ('title', $ rs ['title']);
// $ Smarty-> assign ('content', $ rs ['content']);
$ Smarty-> assign ('actionvalue', 'editnews ');
$ Smarty-> assign ('id', $ rs ['id']);
Editor ('content', $ rs ['content']);
$ Smarty-> display('addnews.htm ');
Break;
Case 'editnews ':
$ Title = $ _ REQUEST ['title'];
$ Content = $ _ REQUEST ['content'];
$ Id = $ _ REQUEST ['id'];
$ Button = $ _ REQUEST ['submit '];
$ Db = new mysql ();
If ($ button = 'Submit '){
$ SQL = "update news set title = '$ title', content =' $ content', date = NOW () where id = $ id ";
$ Db-> query_exec ($ SQL );
Echo "operation successful! <META HTTP-EQUIV = \ "Refresh \" CONTENT = \ "1; URL =./index. php \"> ";
}
Break;
Case 'delnews ':
$ Db = new mysql ();
If ($ checkbox! = "" Or count ($ checkbox )! = 0 ){
For ($ I = 0; $ I <count ($ checkbox); $ I ++ ){
$ Db-> query_exec ("delete from news where id = '$ checkbox [$ I]'");
}
}
Echo "operation successful! <META HTTP-EQUIV = \ "Refresh \" CONTENT = \ "1; URL =./index. php \"> ";
Break;
Default:
$ Smarty = new Smarty ();
$ Smarty-> template_dir = './template ';
$ Smarty-> compile_dir = './smarty/templates_c ';
$ Smarty-> assign ('page _ title', 'news management ');
$ Smarty-> assign ('actionvalue', 'delnews ');
$ Query = "select * from news ";
$ Db = new mysql ();
$ Result = $ db-> query_exec ($ query );
While ($ rs = $ result-> fetch_assoc ()){
$ Array [] = array ("id" => $ rs ['id'], "title" => $ rs ['title'], "date" => $ rs ['date']);
$ Smarty-> assign ('News', $ array );
}
$ Smarty-> display('index.htm ');
}
?>
Below is the content of the template file index.htm
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"
Http://www.w3.org/TR/html4/loose.dtd>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title >{$ page_title} </title>
</Head>
<Body>
<P class = "style1"> News management </p>
<Hr>
<Table width = "771" height = "115" border = "0">
<Tr>
<Td height = "62"> <div align = "center"> system management </div> </td>
<Td width = "666" rowspan = "2"> <form name = "form1" method = "post" action = "">
<Table width = "543" border = "0">
<Tr>
<Td width = "253"> title </td>
<Td width = "230"> date </td>
<Td width = "46"> select </td>
</Tr>
{Section name = news loop = $ news}
<Tr>
<Td> <a href = "./index. php? Action = editnewsview & id = {$ news [news]. id} ">{$ news [news]. title} </a> </td>
<Td >{$ news [news]. date} </td>
<Td> <input name = "checkbox []" type = "checkbox" id = "checkbox []" value = "{$ news [news]. id} "> </td>
</Tr>
{/Section}
</Table>
<P>
<Input type = "submit" name = "Submit" value = "delete">
<Input name = "action" type = "hidden" id = "action" value = "{$ actionvalue}">
</P>
</Form> </td>
</Tr>
<Tr>
<Td width = "95" height = "47"> <div align = "center"> <a href = "./index. php? Action = addnewsview "> Add news </a> </div> </td>
</Tr>
</Table>
<P class = "style1"> </p>
</Body>
</Html>
Addnews.htm
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"
Http://www.w3.org/TR/html4/loose.dtd>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Link href = "./css/a.css" rel = "stylesheet" type = "text/css">
<Title >{$ page_title} </title>
</Head>
<Body>
<P class = "style1"> News management logon </p>
<Hr>
<Table width = "771" height = "501" border = "0">
<Tr>
<Td height = "62"> <div align = "center"> system management </div> </td>
<Td width = "666" rowspan = "2"> <form name = "form1" method = "post" action = "index. php">
<P> title
<Input name = "title" type = "text" id = "title" value = "{$ title}">
</P>
<P> content: </p>
<P> {$ editor} </p>
<P>
<Input type = "submit" name = "Submit" value = "submit">
<Input type = "hidden" name = 'action' value = {$ actionvalue}>
<Input name = "id" type = "hidden" value = "{$ id}">
</P>
</Form>
</Td>
</Tr>
<Tr>
<Td width = "95" height = "433"> <div align = "center"> Add news </div> </td>
</Tr>
</Table>
</Body>
</Html>
Note: The database is already in the attachment. First, create a new database named new, and then import the table.
System User name: admin Password: admin
Package download
Download this file