Permalink
Browse files

Added the CMS

  • Loading branch information...
1 parent f4627e2 commit 47f8184d7902c1ff35750b183c63a7d3e4994607 @sikevux committed Jan 1, 2012
Showing with 1,025 additions and 79 deletions.
  1. 0 .keep_www-servers_lighttpd-0
  2. +1 −3 README.org
  3. +40 −0 admin.php
  4. +79 −0 cmstables.php
  5. +35 −0 comment.php
  6. +63 −0 compose.php
  7. +89 −0 cpanel.php
  8. +0 −23 db.pl
  9. +4 −0 footer.php
  10. +22 −0 forgotpass.php
  11. +58 −0 header.php
  12. +10 −0 http.php
  13. +21 −0 index.php
  14. +28 −0 login.php
  15. +112 −0 outputfunctions.php
  16. +42 −0 pending.php
  17. +52 −0 reviewarticle.php
  18. +29 −0 search.php
  19. +123 −0 transact-article.php
  20. +119 −0 transact-user.php
  21. +0 −53 uppgift2.py
  22. +87 −0 useraccount.php
  23. +11 −0 viewarticle.php
No changes.
View
@@ -5,6 +5,4 @@ Databashantering course that I'm going to take 2011/2012. It's
mandatory for the ones taking Naturalsciences with the Math and data
focus.
-
-Basically it's about learning SQL, or rather Microsoft Access 2010,
-that's why I use python(or perl(or php)) + sqlite(or MySQL)
+Basically it's my final assignment, it's a very simple CMS.
View
@@ -0,0 +1,40 @@
+<?php
+
+require_once 'conn.php';
+require_once 'header.php';
+
+$a_users = array(1 => "Users","Moderators","Admins");
+
+function echoUserList($level) {
+ global $a_users;
+ $sql = "SELECT user_id, name, mail FROM cms_users " .
+ "WHERE access_level = $level ORDER BY name";
+
+ $result = mysql_query($sql) or die(mysql_error());
+
+ if (mysql_num_rows($result) == 0) {
+ echo "<em>No " . $a_users[$level] . " created.</em>";
+ } else {
+ while ($row = mysql_fetch_array($result)) {
+ if ($row['user_id'] == $_SESSION['user_id']) {
+ echo htmlspecialchars($row['name']) . "<br />\n";
+ } else {
+ echo '<a href="useraccount.php?userid=' . $row['user_id'] .
+ '" title="' . htmlspecialchars($row['mail']) . '">' .
+ htmlspecialchars($row['name']) . "</a><br />\n";
+ }
+ }
+ }
+}
+?>
+<h2>User Administration</h2>
+<?php
+ for($i=1;$i<=3;$i++) {
+ echo "<h3>". $a_users[$i] . "</h3>\n" .
+ "<div class='scroller'>\n";
+ echoUserList($i);
+ echo "\n</div>\n";
+ }
+?>
+<br />
+<?php require_once 'footer.php'; ?>
View
@@ -0,0 +1,79 @@
+<?php
+require_once 'conn.php';
+
+$sql = <<<EOS
+CREATE TABLE IF NOT EXISTS cms_access_levels (
+ access_level tinyint(4) NOT NULL auto_increment,
+ access_name varchar(50) NOT NULL default '',
+ PRIMARY KEY (access_level)
+)
+EOS;
+$result = mysql_query($sql) or die(mysql_error());
+
+$sql = "INSERT IGNORE INTO cms_access_levels
+ VALUES (1,'User')";
+$result = mysql_query($sql) or die(mysql_error());
+$sql = "INSERT IGNORE INTO cms_access_levels
+ VALUES (2,'Moderator')";
+$result = mysql_query($sql) or die(mysql_error());
+$sql = "INSERT IGNORE INTO cms_access_levels
+ VALUES (3,'Administrator')";
+$result = mysql_query($sql) or die(mysql_error());
+
+$sql = <<<EOS
+CREATE TABLE IF NOT EXISTS cms_articles (
+ article_id int(11) NOT NULL auto_increment,
+ author_id int(11) NOT NULL default '0',
+ is_published tinyint(1) NOT NULL default '0',
+ date_submitted datetime NOT NULL default '0000-00-00 00:00:00',
+ date_published datetime NOT NULL default '0000-00-00 00:00:00',
+ title varchar(255) NOT NULL default '',
+ body mediumtext NOT NULL,
+ PRIMARY KEY (article_id),
+ KEY IdxArticle (author_id,date_submitted),
+ FULLTEXT KEY IdxText (title,body)
+)
+EOS;
+$result = mysql_query($sql) or die(mysql_error());
+
+$sql = <<<EOS
+CREATE TABLE IF NOT EXISTS cms_comments (
+ comment_id int(11) NOT NULL auto_increment,
+ article_id int(11) NOT NULL default '0',
+ comment_date datetime NOT NULL default '0000-00-00 00:00:00',
+ comment_user int(11) NOT NULL default '0',
+ comment text NOT NULL,
+ PRIMARY KEY (comment_id),
+ KEY IdxComment (article_id)
+)
+EOS;
+$result = mysql_query($sql) or die(mysql_error());
+
+$sql = <<<EOS
+CREATE TABLE IF NOT EXISTS cms_users (
+ user_id int(11) NOT NULL auto_increment,
+ mail varchar(255) NOT NULL default '',
+ password varchar(50) NOT NULL default '',
+ name varchar(100) NOT NULL default '',
+ access_level tinyint(4) NOT NULL default '1',
+ PRIMARY KEY (user_id),
+ UNIQUE KEY uniq_mail (mail)
+)
+EOS;
+$result = mysql_query($sql) or die(mysql_error());
+
+$adminmail = "sikevux@sikevux.se";
+$adminpass = "admin";
+$adminname = "Admin";
+
+$sql = "INSERT IGNORE INTO cms_users VALUES (NULL,
+ '$adminmail', '". hash_password($adminpass, $adminmail). "', '$adminname', 3)";
+$result = mysql_query($sql) or die(mysql_error());
+
+echo "<html><head><title>CMS Tables Created</title></head><body>";
+echo "CMS Tables created. Here is your initial login information:\n";
+echo "<ul><li><strong>login</strong>: " . $adminmail . "</li>\n";
+echo "<li><strong>password</strong>: " . $adminpass . "</li></ul>\n";
+echo "<a href='login.php'>Login</a> to the site now.";
+echo "</body></html>"
+?>
View
@@ -0,0 +1,35 @@
+<?php
+
+require_once 'conn.php';
+require_once 'outputfunctions.php';
+require_once 'header.php';
+
+outputStory($_GET['article']);
+
+?>
+
+<h1>Add a comment</h1>
+
+<form method="post" action="transact-article.php">
+
+<p>
+ Comment:<br />
+ <textarea id="comment" name="comment" rows="10" cols="60"></textarea>
+</p>
+
+<p>
+ <input type="submit" class="submit" name="action"
+ value="Submit Comment" />
+ <input type="hidden" name="article"
+ value="<?php echo $_GET['article']; ?>" />
+</p>
+
+</form>
+
+<?php
+
+showComments($_GET['article'],FALSE);
+
+require_once 'footer.php';
+
+?>
View
@@ -0,0 +1,63 @@
+<?php
+
+require_once 'conn.php';
+
+$title = '';
+$body = '';
+$article = '';
+$authorid = '';
+if (isset($_GET['a'])
+ and $_GET['a'] == 'edit'
+ and isset($_GET['article'])
+ and $_GET['article']) {
+ $sql = "SELECT title,body,author_id FROM cms_articles WHERE article_id=" .
+ $_GET['article'];
+ $result = mysql_query($sql,$conn)
+ or die('Could not retrieve article data; ' . mysql_error());
+
+ $row = mysql_fetch_array($result);
+
+ $title = $row['title'];
+ $body = $row['body'];
+ $article = $_GET['article'];
+ $authorid = $row['author_id'];
+}
+require_once 'header.php';
+?>
+
+<form method="post" action="transact-article.php">
+
+<h2>Compose Article</h2>
+
+<p>
+ Title:<br />
+ <input type="text" class="title" name="title" maxlength="255"
+ value="<?php echo htmlspecialchars($title); ?>" />
+</p>
+<p>
+ Body:<br />
+ <textarea class="body" name="body" rows="10" cols="60"><?php
+ echo htmlspecialchars($body); ?></textarea>
+</p>
+<p>
+<?php
+echo '<input type="hidden" name="article" value="' .
+ $article . "\" />\n";
+
+if ($_SESSION['access_level'] < 2) {
+ echo '<input type="hidden" name="authorid" value="' .
+ $authorid . "\" />\n";
+}
+
+if ($article) {
+ echo '<input type="submit" class="submit" name="action" ' .
+ "value=\"Save Changes\" />\n";
+} else {
+ echo '<input type="submit" class="submit" name="action" ' .
+ "value=\"Submit New Article\" />\n";
+}
+?>
+</p>
+</form>
+
+<?php require_once 'footer.php'; ?>
View
@@ -0,0 +1,89 @@
+<?php
+require_once 'conn.php';
+require_once 'header.php';
+
+$sql = "SELECT name,mail " .
+ "FROM cms_users " .
+ "WHERE user_id=" . $_SESSION['user_id'];
+$result = mysql_query($sql,$conn)
+ or die('Could not look up user data; ' . mysql_error());
+
+$user = mysql_fetch_array($result);
+?>
+<form method="post" action="transact-user.php">
+
+<p>Name:<br />
+ <input type="text" id="name" name="name"
+ value="<?php echo htmlspecialchars($user['name']); ?>" /></p>
+
+<p>E-mail:<br />
+ <input type="text" id="mail" name="mail"
+ value="<?php echo htmlspecialchars($user['mail']); ?>" /></p>
+
+<p><input type="submit" class="submit" name="action"
+ value="Change my info" /></p>
+
+</form>
+
+<h2>Pending Articles</h2>
+<div class="scroller">
+ <table>
+<?php
+
+$sql = "SELECT article_id, title, date_submitted " .
+ "FROM cms_articles " .
+ "WHERE is_published=0 " .
+ "AND author_id=" . $_SESSION['user_id'] . " " .
+ "ORDER BY date_submitted";
+$result = mysql_query($sql,$conn)
+ or die('Could not get list of pending articles; ' . mysql_error());
+
+if (mysql_num_rows($result) == 0) {
+ echo " <em>No pending articles available</em>";
+} else {
+ while ($row = mysql_fetch_array($result)) {
+ echo "<tr>\n";
+ echo '<td><a href="reviewarticle.php?article=' .
+ $row['article_id'] . '">' . htmlspecialchars($row['title']) .
+ "</a> (submitted " .
+ date("F j, Y",strtotime($row['date_submitted'])) .
+ ")</td>\n";
+ echo "</tr>\n";
+ }
+}
+?>
+ </table>
+</div>
+<br />
+
+<h2>Published Articles</h2>
+<div class="scroller">
+ <table>
+<?php
+
+$sql = "SELECT article_id, title,date_published " .
+ "FROM cms_articles " .
+ "WHERE is_published=1 " .
+ "AND author_id=" . $_SESSION['user_id'] . " " .
+ "ORDER BY date_submitted";
+$result = mysql_query($sql,$conn)
+ or die('Could not get list of pending articles; ' . mysql_error());
+
+if (mysql_num_rows($result) == 0) {
+ echo " <em>No published articles available</em>";
+} else {
+ while ($row = mysql_fetch_array($result)) {
+ echo "<tr>\n";
+ echo '<td><a href="viewarticle.php?article=' .
+ $row['article_id'] . '">' . htmlspecialchars($row['title']) .
+ "</a> (published " .
+ date("F j, Y",strtotime($row['date_published'])) .
+ ")</td>\n";
+ echo "</tr>\n";
+ }
+}
+?>
+ </table>
+</div>
+<br />
+<?php require_once 'footer.php'; ?>
View
23 db.pl
@@ -1,23 +0,0 @@
-#!/usr/bin/env perl
-use strict;
-use warnings;
-use DBI;
-my $dbh;
-my $i;
-my $sth;
-my $ref;
-my $fortune = `/usr/games/fortune`;
-$dbh = DBI->connect("DBI:mysql:database=junk;host=localhost", "root", "l0l", {'RaiseError' => 1});
-$dbh->do("CREATE DATABASE IF NOT EXISTS junk");
-$dbh->do("CREATE TABLE IF NOT EXISTS M00 (id MEDIUMINT NOT NULL AUTO_INCREMENT, quote VARCHAR(9001) NOT NULL, PRIMARY KEY (id))");
-for($i=0; $i<3; $i++) {
- $dbh->do("INSERT INTO M00 (quote) VALUES(" . $dbh->quote($fortune) . ")");
-$fortune = `/usr/games/fortune`;
-}
-$sth = $dbh->prepare("SELECT * FROM M00");
-$sth->execute();
-while($ref = $sth->fetchrow_hashref()) {
- print "Quote number $ref->{'id'}: $ref->{'quote'}\n";
-}
-$sth->finish();
-$dbh->disconnect();
View
@@ -0,0 +1,4 @@
+ </div>
+</div>
+</body>
+</html>
View
@@ -0,0 +1,22 @@
+<?php require_once 'header.php'; ?>
+
+<form method="post" action="transact-user.php">
+
+<h1>E-mail Password Reminder</h1>
+
+<p>
+ Forgot your password? Just enter your mail address, and we'll mail
+ your password to you!
+</p>
+
+<p>
+ E-mail Address:<br />
+ <input type="text" id="mail" name="mail" />
+</p>
+
+<p>
+ <input type="submit" class="submit" name="action" value="Send my reminder!" />
+</p>
+</form>
+
+<?php require_once 'footer.php'; ?>
Oops, something went wrong.

0 comments on commit 47f8184

Please sign in to comment.