Help on News CMS With Admin P

Posted on Monday 2nd July 2007 at 07:22 PM
dtnet
dtnet's Avatar
It's not working. When I want to add a news nothing appears when I'm pressing on the "New Entry "-button
Posted on Monday 2nd July 2007 at 09:00 PM
SkillMaster
SkillMaster's Avatar
okay post your two codes?
Posted on Monday 2nd July 2007 at 09:19 PM
dtnet
dtnet's Avatar
admin.php
PHP Code
  1. <?php
  2.  
  3. session_start();
  4.  
  5.  
  6. $_username = "****"; //admin username to login
  7. $_password = "******"; //admin password to login
  8.  
  9. print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  10. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en">
  11. <head>
  12. <title>News</title>
  13. <link rel="stylesheet" type="text/css" media="screen" title="Default" href="adminstyle.css" />
  14. </head>
  15. <body>');
  16.  
  17. if (isset($_POST['submit'])) {
  18. //check if the username and password match
  19. if ($_POST['username'] == $_username && $_POST['password'] == $_password) {
  20. //set session variable
  21. $_SESSION['logged_in'] = "true";
  22. $_SESSION['username'] = $_username;
  23. }
  24. }
  25.  
  26. //if not logged in show the login form
  27. if (!isset($_SESSION['logged_in'])) {
  28. print('
  29. <div id="login">
  30. <h1>News Login</h1>
  31. <form method="post" action="admin.php" class="login">
  32. <label for="username">Username:</label> <input type="text" id="username" name="username" /><br/>
  33. <label for="password">Password:</label> <input type="password" id="password" name="password" /><br/>
  34. <input type="hidden" name="login" />
  35. <label for="submit"> </label> <input type="submit" id="submit" name="submit" value="Login" /><br/>
  36. <p style="font-size: 9px; text-align: center;">Created by <a href="https://d-webz.org">DylanM</a>.</p>
  37. </div>
  38. </form>');
  39. //if logout is requested
  40. } elseif (isset($_GET['do']) && $_GET['do'] == "logout") {
  41. session_start();
  42. $_SESSION = array();
  43. session_destroy();
  44. echo '<META HTTP-EQUIV="refresh" content="1"; URL="admin.php">';
  45. } else {
  46. print('<script type="text/javascript">
  47.  
  48. function preview(id1, id2){
  49.  
  50. var NewText = document.getElementById(id1).value;
  51.  
  52. splitText = NewText.split(/n/).join("");
  53.  
  54. var DivElement = document.getElementById(id2);
  55.  
  56. DivElement.innerHTML = splitText;
  57.  
  58. }
  59.  
  60. </script>
  61. ');
  62.  
  63. include '../config.php';
  64.  
  65. print('<div id="container"> <h1>Admin Panel</h1>
  66. <p style="text-align: center;"><a href="?">Admin Home</a> | <a href="?action=new">New Entry</a> | <a href="?action=entries">Edit Entries</a> | <a href="?do=logout">Logout</a></p>');
  67.  
  68. if ($action == "") {
  69. print("<p>Woot. This is your admin panel page. Use the above page to add, edit, and delete news. Created by DylanM (3xS). www.d-webz.org</p>");
  70. }elseif ($action == "entries") {
  71. //get pages from the database
  72. $query = "SELECT * FROM entries ORDER BY id DESC";
  73. $sql = mysql_query($query);
  74.  
  75. print('<form method="post" action="" class="table">
  76. <table width="760">
  77. <tr>
  78. <th>Select</td>
  79. <th>Category</td>
  80. <th>Title</td>
  81. <th>Date</td>
  82. </tr>
  83. ');
  84.  
  85. while($row = mysql_fetch_array($sql)){
  86. $id = $row['id'];
  87. $category = stripslashes($row['category']);
  88. $title = stripslashes($row['title']);
  89. $date = $row['date'];
  90.  
  91.  
  92. // show entries
  93. print('<tr>
  94. <td><input type="checkbox" name="selected[]" value="$id"></td>
  95. <td>$category</td>
  96. <td><a href="?action=edit&id=$id">$title</a></td>
  97. <td>$date</td>
  98. <td><a href="?action=showcomments&id=$id">$comnum</a></td>
  99. </tr>
  100. ');
  101. }
  102. print('
  103. </table>
  104. <br/>
  105. <label for="action">Action:</label>
  106. <select name="action" id="action">
  107. <option value="archive">Archive
  108. <option value="delete">Delete
  109. </select>
  110. <input type="submit" id="submit" name="Submit">
  111. </form>
  112. ');
  113. }elseif($action == "new"){
  114. print('<div class="input">
  115. <form method="post" id="addentry" action="?action=addnewentry">
  116. <label for="title">Title</label><input id="title" name="title" tabindex="1" type="text"><br/>
  117. <label for="category">Category</label><input id="category" name="category" tabindex="2" type="text" value="home"><br/>
  118. <label for="addshort">Short</label><textarea name="addshort" wrap="virtual" id="addshort" tabindex="3"></textarea><br/><br/>
  119. <label for="addfull">Full</label><textarea name="addfull" wrap="virtual" id="addfull" tabindex="4"></textarea><br/>
  120. <label for="submit">Submit</label><input id="submit" name="submit" value="Submit" tabindex="5" type="submit">
  121. </div>
  122. <div class="story">
  123. <h1>Short Preview:</h1>
  124. <div id="addpreview-short"></div><br/>
  125. <h1>Full Preview:</h1>
  126. <div id="addpreview-full"></div>
  127. </div>
  128. ');
  129. }elseif($action == "addnewentry"){
  130. $title = mysql_real_escape_string($_POST['title']);
  131. $category = mysql_real_escape_string($_POST['category']);
  132. $short = mysql_real_escape_string($_POST['addshort']);
  133. $full = mysql_real_escape_string($_POST['addfull']);
  134.  
  135. $query = "INSERT INTO entries (id, category, title, date, short, full)
  136. VALUES (NULL, '$category', '$title', NOW(), '$short', '$full');";
  137. mysql_query($query) or die("Add failed: " . mysql_error());
  138. echo mysql_affected_rows() . ' record added.';
  139. echo '<br/><a href="admin.php">Go back.</a>';
  140. }elseif ($action == "delete"){
  141. $selected = implode(",", $_POST['selected']);
  142. $query = "DELETE FROM entries WHERE id IN ($selected)";
  143. mysql_query($query) or die("Delete failed: " . mysql_error());
  144. echo mysql_affected_rows() . ' record(s) deleted.';
  145. echo '<br/><a href="admin.php">Go back.</a>';
  146. }elseif($action == "archive"){
  147. $selected = implode(",", $_POST['selected']);
  148. $query = "UPDATE entries SET category='archive' WHERE id IN ($selected)";
  149. mysql_query($query) or die("Archive failed: " . mysql_error());
  150. echo mysql_affected_rows() . ' record(s) moved to the archives.';
  151. echo '<br/><a href="admin.php">Go back.</a>';
  152. }elseif($action == "edit"){
  153. $id = mysql_real_escape_string($_GET['id']);
  154. //get page from the database
  155. $query = "SELECT * FROM entries WHERE id = '$id'";
  156. $sql = mysql_query($query);
  157. $row = mysql_fetch_array($sql);
  158.  
  159. $title = stripslashes($row['title']);
  160. $category = stripslashes($row['category']);
  161. $date = stripslashes($row['date']);
  162. $short = stripslashes($row['short']);
  163. $full = stripslashes($row['full']);
  164.  
  165. print('<div class="input">
  166. <form method="post" id="editentry" action="?action=editentry&id=$id">
  167. <label for="title">Title</label><input id="title" name="title" tabindex="1" value="$title" type="text"><br/>
  168. <label for="category">Category</label><input id="category" name="category" value="$category" tabindex="2" type="text"><br/>
  169. <label for="editshort">Short</label><textarea name="editshort" wrap="virtual" id="editshort" tabindex="3">$short</textarea><br/><br/>
  170. <label for="editfull">Full</label><textarea name="editfull" wrap="virtual" id="editfull" tabindex="4">$full</textarea><br/>
  171. <label for="submit">Submit</label><input id="submit" name="submit" value="Submit" tabindex="5" type="submit">
  172. </div>
  173. <div class="story">
  174. <h1>Short Preview:</h1>
  175. <div id="editpreview-short"></div><br/>
  176. <h1>Full Preview:</h1>
  177. <div id="editpreview-full"></div>
  178. </div>
  179. ');
  180. }elseif($action == "editentry"){
  181. $id = mysql_real_escape_string($_GET['id']);
  182. $title = mysql_real_escape_string($_POST['title']);
  183. $title = htmlspecialchars("$title");
  184. $category = "{$_POST['category']}";
  185. $short = mysql_real_escape_string($_POST['editshort']);
  186. $short = htmlspecialchars("$short");
  187. $full = mysql_real_escape_string($_POST['editfull']);
  188. $full = htmlspecialchars("$full");
  189.  
  190. $query = "UPDATE entries SET title = '$title', category = '$category', short = '$short', full = '$full' WHERE id = $id;";
  191. mysql_query($query) or die("Edit failed: " . mysql_error());
  192. echo mysql_affected_rows() . ' record modified.';
  193. echo '<br/><a href="admin.php">Go back.</a>';
  194. }else{
  195. echo "There was an error";
  196. echo '<br/><a href="admin.php">Go back.</a>';
  197. }
  198. print('<p style="font-size: 9px; text-align: center;">Created by <a href="https://d-webz.org">DylanM</a>.</p></div>');
  199. }
  200. ?>
  201. </body>
  202. </html>


news.php
PHP Code
  1. <?php
  2. // Database Connection
  3. include 'config.php';
  4.  
  5. function show(){
  6. global $db;
  7. //get page 1 if no page is requested
  8. if(!isset($_GET['page'])){
  9. $page = "1";
  10. } else {
  11. //get requested page
  12. $page = $_GET['page'];
  13. }
  14.  
  15. if(!isset($_GET['category'])){
  16. $category = "home";
  17. } else {
  18. $category = mysql_real_escape_string($_GET['category']);
  19. }
  20.  
  21. //max entries per page
  22. $max_results = "4";
  23.  
  24. //figure out the result limit
  25. $from = (($page * $max_results) - $max_results);
  26.  
  27. //get pages from the database
  28. $query = "SELECT *, DATE_FORMAT(date, '%W, %M %e, %Y <br/> %r') AS date FROM entries WHERE category = '$category' ORDER BY id DESC LIMIT $from, $max_results";
  29. $sql = mysql_query($query);
  30. while($row = mysql_fetch_array($sql)){
  31. $id = $row['id'];
  32.  
  33. //check for a full story
  34. if( $row['full'] == ""){
  35. $readmore = "";
  36. }else{
  37. $readmore = '| <a href="?id=$id">Read more...</a>';
  38. }
  39. $title = stripslashes($row['title']);
  40. $date = "{$row['date']}";
  41. $short = stripslashes($row['short']);
  42. $short = nl2br($short);
  43. // show emtries
  44. print("<div class='story'>
  45.  
  46. <h1><a href='?id=$id'>$title</a></h1>
  47.  
  48. <h2>$date</h2>
  49.  
  50. <p>$short</p>
  51. <p>$readmore</p>
  52. ");
  53. }
  54.  
  55. //get total number of results
  56. $total_results = mysql_result(mysql_query("SELECT COUNT(*) FROM entries"),0);
  57.  
  58. //round up
  59. $total_pages = ceil($total_results / $max_results);
  60.  
  61. //show previous link
  62. if($page > 1){
  63. $prev = ($page - 1);
  64. echo "<a href="" . $_SERVER['PHP_SELF'] . "?page=" . $prev . "">Previous</a> - |";
  65. }else{
  66. echo "Previous - |";
  67. }
  68.  
  69. for($i = 1; $i <= $total_pages; $i++){
  70. if(($page) == $i){
  71. echo "<strong>$i</strong>";
  72. } else {
  73. echo "<a href="" . $_SERVER['PHP_SELF'] . "?page=$i"> $i </a>";
  74. }
  75. }
  76.  
  77. //show next link
  78. if($page < $total_pages){
  79. $next = ($page + 1);
  80. echo "| - <a href="" . $_SERVER['PHP_SELF'] . "?page=$next">Next</a>";
  81. }else{
  82. echo "| - Next";
  83. }
  84. }
  85.  
  86. function showfull($id){
  87. global $db;
  88.  
  89. //get page from the database
  90. $query = "SELECT *, DATE_FORMAT(date, '%W, %M %e, %Y <br/> %r') AS date FROM entries WHERE id = '$id'";
  91. $sql = mysql_query($query);
  92. $row = mysql_fetch_array($sql);
  93.  
  94. $title = stripslashes($row['title']);
  95. $date = "{$row['date']}";
  96. $short = stripslashes($row['short']);
  97. $short = nl2br($short);
  98. $full = stripslashes($row['full']);
  99. $full = nl2br($full);
  100. if( $full != ""){
  101. $fulltext = "$full";
  102. }else{
  103. $fulltext = "$short";
  104. }
  105.  
  106. // show entry
  107. print('<div class="story">
  108. <h1>$title</h1>
  109. <h2>$date</h2>
  110. <p>$fulltext</p>
  111. </div>
  112. ');
  113. //get entries from the database and sort them by year and month in reverse
  114. $query = "SELECT *, DATE_FORMAT(date, '%Y%m') AS sort, DATE_FORMAT(date, '%M %Y') AS date FROM entries WHERE category = 'archive' GROUP BY sort ORDER BY sort DESC";
  115. $sql = mysql_query($query);
  116. while($row = mysql_fetch_array($sql)){
  117. $date = $row['date'];
  118.  
  119. // show emtries
  120. print('<h1>$date</h1>
  121. ');
  122.  
  123. $query = "SELECT *, DATE_FORMAT(date, '%W, %M %e | %r') AS date FROM entries WHERE category = 'archive' ORDER BY id DESC";
  124. $sql = mysql_query($query);
  125. while($row = mysql_fetch_array($sql)){
  126. $id = $row['id'];
  127. $title = stripslashes($row['title']);
  128. $date = $row['date'];
  129.  
  130. // show emtries
  131. print('<a href="?id=$id">$date - $title</a><br/>');
  132. }
  133.  
  134. }
  135. }
  136.  
  137.  
  138. $id = "{$_GET['id']}";
  139. $archive = "{$_GET['archive']}";
  140.  
  141. if($archive != ""){
  142. showarchive();
  143. }elseif($id != ""){
  144. showfull($id);
  145. }else{
  146. show();
  147. }
  148. ?>
Posted on Monday 2nd July 2007 at 09:27 PM
SkillMaster
SkillMaster's Avatar
i see the only way would be to maybe recode it because its such a big code.
Login or register to respond to this forum topic.