From 0720091ca73b9714aab2b38c3682c15a0cbd4533 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Thu, 2 Jun 2011 17:20:54 -0700 Subject: Added pages --- htdocs/moderate/pages/delete.php | 49 ++++++++++++++++++ htdocs/moderate/pages/editor.php | 100 +++++++++++++++++++++++++++++++++++++ htdocs/moderate/pages/index.php | 52 +++++++++++++++++++ htdocs/moderate/src/header.inc.php | 10 ++++ 4 files changed, 211 insertions(+) create mode 100644 htdocs/moderate/pages/delete.php create mode 100644 htdocs/moderate/pages/editor.php create mode 100644 htdocs/moderate/pages/index.php (limited to 'htdocs/moderate') diff --git a/htdocs/moderate/pages/delete.php b/htdocs/moderate/pages/delete.php new file mode 100644 index 0000000..91ee209 --- /dev/null +++ b/htdocs/moderate/pages/delete.php @@ -0,0 +1,49 @@ + + * + */ + +require_once('../../src/base.inc.php'); + +// Verify User is admin +if (!$_SESSION['currentUser']->isAdmin()) { + header('Location: ' . buildUrl('moderate/')); + exit; +} + +$error = ''; + +$page = false; +if (isset($_GET['id']) and is_numeric($_GET['id'])) { + $page = Page::getById($_GET['id']); + + if ($page !== false and isset($_GET['confirmed'])) { + $page->delete(); + + header('Location: index.php'); + } + +} + +require_once('../src/header.inc.php'); + +echo "

Delete Pages

"; + +if ($page !== false) { + echo "

Are you sure you want to delete " . $page->getTitle() ."?

" + . "

getId() ."&confirmed\">Yes" + . " No

"; + +} else { + echo "

No page to delete.

"; +} + +require_once('../src/footer.inc.php'); + +?> + diff --git a/htdocs/moderate/pages/editor.php b/htdocs/moderate/pages/editor.php new file mode 100644 index 0000000..e2f9d25 --- /dev/null +++ b/htdocs/moderate/pages/editor.php @@ -0,0 +1,100 @@ + + * + */ + +require_once('../../src/base.inc.php'); + +// Verify User is admin +if (!$_SESSION['currentUser']->isAdmin()) { + header('Location: ' . buildUrl('moderate/')); + exit; +} + +$error = ''; + +// Get the current user object. +$page = new Page(); +if (isset($_GET['id']) and is_numeric($_GET['id'])) { + $page = Page::getById($_GET['id']); +} + +// Save changes? +if ($_SERVER['REQUEST_METHOD'] == 'POST') { + // Title + if (isset($_POST['title']) and trim($_POST['title']) != '') { + $page->setTitle($_POST['title']); + + } else { + $error .= '

Title is a required field.

'; + } + + // URL + if (isset($_POST['url']) and trim($_POST['url']) != '') { + $page->setURL($_POST['url']); + + } else { + $error .= '

URL is a required field.

'; + } + + // Content + if (isset($_POST['content']) and trim($_POST['content']) != '') { + $page->setContent($_POST['content']); + + } else { + $error .= '

Content is a required field.

'; + } + + // Save + if ($error == '') { + if ($page->save()) { + // Return to pages list + header("Location: index.php"); + + } else { + $error .= '

An error has occured.

'; + } + } +} + +require_once('../src/header.inc.php'); + +echo "

Edit Page

"; + +if ($error != '') { + echo "
$error
"; +} + +$url = "editor.php"; + +if (isset($_GET['id'])) { + $url .= '?id=' . $_GET['id']; +} + +echo "
"; + +?> + +

+

+

+ +

+ +Cancel +

+ + +
+ + + diff --git a/htdocs/moderate/pages/index.php b/htdocs/moderate/pages/index.php new file mode 100644 index 0000000..d6ffd87 --- /dev/null +++ b/htdocs/moderate/pages/index.php @@ -0,0 +1,52 @@ + + * + */ + +require_once('../../src/base.inc.php'); + +// Verify User is admin +if (!$_SESSION['currentUser']->isAdmin()) { + header('Location: ' . buildUrl('moderate/')); + exit; +} + +$error = ''; + +require_once('../src/header.inc.php'); + +echo "

Pages

"; + +echo "

Create Page

"; + +$pi = new PageIterator(); +$pi->query(); + +if ($pi->valid()) { + echo "
" + . "Title" + . " Actions
"; + + foreach ($pi as $page) { + printf("
" + . "%s" + . " " + . " edit" + . " delete
", + buildUrl('page/' . $page->getURL()), $page->getTitle(), + $page->getId(), $page->getId() + ); + } + +} else { + echo "

There are no pages to edit. Click the button above to create one.

"; +} + +require_once('../src/footer.inc.php'); + +?> diff --git a/htdocs/moderate/src/header.inc.php b/htdocs/moderate/src/header.inc.php index 30910ec..8ad7e0c 100644 --- a/htdocs/moderate/src/header.inc.php +++ b/htdocs/moderate/src/header.inc.php @@ -14,6 +14,16 @@ if (!isset($_SESSION['currentUser'])) { + +