From e121bbebe3ccd990b66a7b04289adf481a4aa2af Mon Sep 17 00:00:00 2001
From: Jesse Morgan
Date: Tue, 30 Aug 2011 12:29:19 -0700
Subject: Working on the moderation schedule iterator
---
htdocs/moderate/schedule/delete.php | 49 ++++++++++++
htdocs/moderate/schedule/editor.php | 144 ++++++++++++++++++++++++++++++++++
htdocs/moderate/schedule/index.php | 52 ++++++++++++
htdocs/src/ModerationSchedule.inc.php | 105 +++++++++++++++++++++++++
4 files changed, 350 insertions(+)
create mode 100644 htdocs/moderate/schedule/delete.php
create mode 100644 htdocs/moderate/schedule/editor.php
create mode 100644 htdocs/moderate/schedule/index.php
create mode 100644 htdocs/src/ModerationSchedule.inc.php
(limited to 'htdocs')
diff --git a/htdocs/moderate/schedule/delete.php b/htdocs/moderate/schedule/delete.php
new file mode 100644
index 0000000..76b8866
--- /dev/null
+++ b/htdocs/moderate/schedule/delete.php
@@ -0,0 +1,49 @@
+
+ *
+ */
+
+require_once('../../src/base.inc.php');
+
+// Verify User is admin
+if (!isset($_SESSION['currentUser']) or !$_SESSION['currentUser']->isAdmin()) {
+ header('Location: ' . buildUrl('moderate/'));
+ exit;
+}
+
+$error = '';
+
+$user = false;
+if (isset($_GET['id']) and is_numeric($_GET['id'])) {
+ $user = User::getById($_GET['id']);
+
+ if ($user !== false and isset($_GET['confirmed'])) {
+ $user->delete();
+
+ header('Location: index.php');
+ }
+
+}
+
+require_once('../src/header.inc.php');
+
+echo "Delete Users
";
+
+if ($user !== false) {
+ echo "Are you sure you want to delete " . $user->getName() ."?
"
+ . "getId() ."&confirmed\">Yes"
+ . " No
";
+
+} else {
+ echo "No user to delete.
";
+}
+
+require_once('../src/footer.inc.php');
+
+?>
+
diff --git a/htdocs/moderate/schedule/editor.php b/htdocs/moderate/schedule/editor.php
new file mode 100644
index 0000000..fe715f7
--- /dev/null
+++ b/htdocs/moderate/schedule/editor.php
@@ -0,0 +1,144 @@
+
+ *
+ */
+
+require_once('../../src/base.inc.php');
+
+// Verify User is admin
+if (!isset($_SESSION['currentUser']) or !$_SESSION['currentUser']->isAdmin()) {
+ header('Location: ' . buildUrl('moderate/'));
+ exit;
+}
+
+$error = '';
+
+// Get the current user object.
+$user = new User();
+if (isset($_GET['id']) and is_numeric($_GET['id'])) {
+ $user = User::getById($_GET['id']);
+}
+
+// Save changes?
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ // Name
+ if (isset($_POST['name']) and trim($_POST['name']) != '') {
+ $user->setName($_POST['name']);
+
+ } else {
+ $error .= 'Name is a required field.
';
+ }
+
+ // Email
+ if (isset($_POST['email']) and trim($_POST['email']) != '') {
+ $user->setEmail($_POST['email']);
+
+ } else {
+ $error .= 'Email is a required field.
';
+ }
+
+ // Source
+ if (isset($_POST['source']) and trim($_POST['source']) != '') {
+ $user->setSource($_POST['source']);
+
+ } else {
+ $error .= 'Source is a required field.
';
+ }
+
+ // Set Admin
+ $admin = isset($_POST['admin']) and $_POST['admin'] == '1';
+ $user->setAdmin($admin);
+
+ // Set Notify
+ $notify = isset($_POST['notify']) and $_POST['notify'] == '1';
+ $user->setNotify($notify);
+
+ // Send new password
+ if (isset($_POST['newpass']) and $_POST['newpass'] == '1') {
+ $user->sendNewPassword();
+ }
+
+ // Save the user
+ if ($error == '') {
+ if ($user->save()) {
+ // Return to users list
+ header("Location: index.php");
+
+ } else {
+ $error .= 'An error has occured.
';
+ }
+ }
+}
+
+require_once('../src/header.inc.php');
+
+echo "Edit User
";
+
+if ($error != '') {
+ echo "$error
";
+}
+
+$url = "editor.php";
+
+if (isset($_GET['id'])) {
+ $url .= '?id=' . $_GET['id'];
+}
+
+echo "
";
+ }
+?>
+
+
+
+Cancel
+
+
+
+
+
+";
+
+ foreach(Source::getSources() as $source) {
+ if ($source->getId() == $select) {
+ echo "";
+
+ } else {
+ echo "";
+ }
+ }
+
+ echo "";
+}
+
+require_once('../src/footer.inc.php');
+
+?>
+
diff --git a/htdocs/moderate/schedule/index.php b/htdocs/moderate/schedule/index.php
new file mode 100644
index 0000000..93dfc3a
--- /dev/null
+++ b/htdocs/moderate/schedule/index.php
@@ -0,0 +1,52 @@
+
+ *
+ */
+
+require_once('../../src/base.inc.php');
+
+
+require_once('../src/header.inc.php');
+
+echo "Moderation Schedule
";
+
+// List out moderators in order with next moderation week
+
+
+echo "Exceptions
";
+echo "New Exception
";
+
+// List out exceptions in order.
+
+$ui = new UserIterator();
+$ui->query();
+
+echo ""
+ . "Name"
+ . " Email"
+ . " Admin"
+ . " Actions
";
+
+foreach ($ui as $user) {
+ printf(""
+ . "
%s"
+ . "
%s"
+ . "
%s"
+ . "
"
+ . " edit"
+ . " delete ",
+ $user->getName(),
+ $user->getEmail(), $user->getEmail(),
+ $user->isAdmin() ? 'Yes' : 'No',
+ $user->getId(), $user->getId()
+ );
+}
+
+require_once('../src/footer.inc.php');
+
+?>
diff --git a/htdocs/src/ModerationSchedule.inc.php b/htdocs/src/ModerationSchedule.inc.php
new file mode 100644
index 0000000..cca6697
--- /dev/null
+++ b/htdocs/src/ModerationSchedule.inc.php
@@ -0,0 +1,105 @@
+
+ *
+ */
+
+require_once "base.inc.php";
+
+class ModerationSchedule implements Iterator {
+ private $moderators;
+ private $exceptions;
+
+ private $year;
+ private $week;
+ private $expos;
+
+ public function __construct() {
+ $this->moderators = array();
+ $this->exceptions = array();
+ }
+
+ public function getNumberOfModerators() {
+ return count($this->moderators);
+ }
+
+
+ // Iterator methods
+
+ public function rewind() {
+ $this->year = date('o');
+ $this->week = date('W') + 0;
+ $this->expos = 0;
+ }
+
+ public function current() {
+ // Get the scheduled mod.
+ $modpos = $this->week % $this->getNumberOfModerators();
+ $moderator = $this->moderators[$modpos]['user_id'];
+
+ // Check for exceptions
+ if (count($this->exceptions) > 0) {
+ // Skip exceptions prior to the current() date.
+ while (
+ // We have exceptions to search
+ $this->expos < count($this->exceptions) and
+ // and the year is less than the current() year
+ ($this->exceptions[$this->expos]['year'] < $this->year or
+ // or if it is the current() year, but less than the week.
+ ($this->exceptions[$this->expos]['year'] == $this->year
+ and $this->exceptions[$this->expos]['week'] < $this->week))
+ ) {
+
+ $this->expos++;
+ }
+
+ // Check if the top exception is for today.
+ if ($this->exceptions[$this->expos]['year'] == $this->year
+ and $this->exceptions[$this->expos]['week'] == $this->week
+ ) {
+ // Yes, return the replacement
+ $moderator = $this->exceptions[$this->expos]['user_id'];
+ }
+ }
+
+ return User::getById($moderator);
+ }
+
+ public function key() {
+ // TODO: Return "key" for "current" moderator (date)
+ }
+
+ public function next() {
+ // TODO: Impl. next
+ }
+
+ public function valid() {
+ // The schedule continues forever.
+ return true;
+ }
+
+ private function query() {
+ $db = getDatabase();
+ $this->rewind();
+
+ // Get the moderators
+ $query = "SELECT * FROM moderation_schedule ORDER BY position";
+ $this->moderators = $db->fetchAssocRows($query);
+
+ // Get the exceptions
+ $year = date('o');
+ $week = date('W');
+
+ $query = "SELECT * FROM moderator_exceptions"
+ . " WHERE year >= $year AND week >= $week"
+ . " ORDER BY year, week";
+ $this->exceptions = $db->fetchAssocRows($query);
+ }
+}
+
+?>
+
--
cgit v1.2.3