summaryrefslogtreecommitdiff
path: root/forum/utils/tasks.php
diff options
context:
space:
mode:
Diffstat (limited to 'forum/utils/tasks.php')
-rw-r--r--forum/utils/tasks.php145
1 files changed, 76 insertions, 69 deletions
diff --git a/forum/utils/tasks.php b/forum/utils/tasks.php
index 91f5409..fe66327 100644
--- a/forum/utils/tasks.php
+++ b/forum/utils/tasks.php
@@ -226,79 +226,86 @@ function sendMail($id, $new, $reassigned)
send($email, $subject, $body);
}
-$tasks = tasks_init();
-
-if($action == "tick") {
- $now = time();
-
- $h = (60 * 60);
- $d = ($h * 24);
-
- $mininterval = $d - $h * 4;
- $maxinterval = $d * 7 - $h * 4;
- $overdueinterval = $h * 7;
-
- foreach($tasks->tasks as $task) {
-
- if($task->completed) continue; // no need for reminding
-
- if(($now > $task->deadline) && (($now - $task->lastreminder) > $overdueinterval)) {
- // Deadline is overdue, and it has been more than $overdueinterval since last reminder.
- sendMail($task->id, false, false);
- } elseif((($task->deadline - $now) > $maxinterval) && (($now - $task->lastreminder) > $maxinterval)) {
- // Deadline is a long way off, but it has been $maxinterval since last reminder.
- sendMail($task->id, false, false);
- } elseif((($task->deadline - $now) > $mininterval) && (($now - $task->lastreminder) > $mininterval)) {
- // Deadline is near, and it has been $mininterval since last reminder.
- sendMail($task->id, false, false);
- }
+function tasks()
+{
+ global $action, $GLOBALS;
+
+ $tasks = tasks_init();
+
+ if($action == "tick") {
+ $now = time();
+
+ $h = (60 * 60);
+ $d = ($h * 24);
+
+ $mininterval = $d - $h * 4;
+ $maxinterval = $d * 7 - $h * 4;
+ $overdueinterval = $h * 7;
+
+ foreach($tasks->tasks as $task) {
+
+ if($task->completed) continue; // no need for reminding
+
+ if(($now > $task->deadline) && (($now - $task->lastreminder) > $overdueinterval)) {
+ // Deadline is overdue, and it has been more than $overdueinterval since last reminder.
+ sendMail($task->id, false, false);
+ } elseif((($task->deadline - $now) > $maxinterval) && (($now - $task->lastreminder) > $maxinterval)) {
+ // Deadline is a long way off, but it has been $maxinterval since last reminder.
+ sendMail($task->id, false, false);
+ } elseif((($task->deadline - $now) > $mininterval) && (($now - $task->lastreminder) > $mininterval)) {
+ // Deadline is near, and it has been $mininterval since last reminder.
+ sendMail($task->id, false, false);
+ }
}
-}
+ }
-if($action == "update") {
- $reassigned = false;
- $id = $GLOBALS['id'];
- $task = $tasks->tasks[$id];
- if(isset($GLOBALS['completed'])) $task->completed = $GLOBALS['completed'] == "on";
- if(isset($GLOBALS['userid'])) {
- $reassigned = $task->userid != $GLOBALS['userid'];
- $task->userid = $GLOBALS['userid'];
- }
- $tasks->write();
+ if($action == "update") {
+ $reassigned = false;
+ $id = $GLOBALS['id'];
+ $task = $tasks->tasks[$id];
+ if(isset($GLOBALS['completed'])) $task->completed = $GLOBALS['completed'] == "on";
+ if(isset($GLOBALS['userid'])) {
+ $reassigned = $task->userid != $GLOBALS['userid'];
+ $task->userid = $GLOBALS['userid'];
+ }
+ $tasks->write();
+
+ if($reassigned) sendMail($id, false, true);
+ }
+
+ if($action == "add") {
+
+ $deadline = strtotime($GLOBALS['deadline_year']."-".
+ $GLOBALS['deadline_month']."-".
+ $GLOBALS['deadline_day']);
+
+ $task = new Task($tasks->getNextID(),
+ stripslashes($GLOBALS['title']),
+ $deadline,
+ stripslashes($GLOBALS['description']),
+ 0,
+ $GLOBALS['reassignable'] == "on",
+ $GLOBALS['userid'],
+ false);
+ $tasks->add($task);
+ $tasks->write();
+
+ sendMail($task->id, true, false);
+ }
- if($reassigned) sendMail($id, false, true);
-}
+ $str .= "<form method=\"post\" enctype=\"multipart/form-data\" action=\"?mode=tasks&amp;action=add\">\n";
+ $str .= " Title: <input name=\"title\" value=\"\"> - User: " . userList($current_user->uid) . " -";
+ $str .= " Deadline: D<input placeholder=\"day\" name=\"deadline_day\" style=\"width: 2em\" value=\"\">\n";
+ $str .= " M<input placeholder=\"month\" name=\"deadline_month\" style=\"width: 2em\" value=\"\">\n";
+ $str .= " Y<input placeholder=\"year\" name=\"deadline_year\" style=\"width: 4em\" value=\"\"><br/>\n";
+ $str .= " Reassignable: <input name=\"reassignable\" type=\"checkbox\" checked><br/>\n";
+ $str .= " <textarea name=\"description\" cols=\"80\" rows=\"2\"></textarea><br/>\n";
+ $str .= " <button style=\"width: 120px\" type=\"submit\">Add Task</button>\n";
+ $str .= "</form>\n";
+ $str .= "<hr/>\n";
-if($action == "add") {
-
- $deadline = strtotime($GLOBALS['deadline_year']."-".
- $GLOBALS['deadline_month']."-".
- $GLOBALS['deadline_day']);
-
- $task = new Task($tasks->getNextID(),
- stripslashes($GLOBALS['title']),
- $deadline,
- stripslashes($GLOBALS['description']),
- 0,
- $GLOBALS['reassignable'] == "on",
- $GLOBALS['userid'],
- false);
- $tasks->add($task);
- $tasks->write();
+ $str .= $tasks->show();
- sendMail($task->id, true, false);
+ return $str;
}
-
?>
-<form method="post" enctype="multipart/form-data" action="?mode=tasks&amp;action=add">
- Title: <input name="title" value=""> - User: <?php echo userList($current_user->uid); ?> - Deadline: D<input placeholder="day" name="deadline_day" style="width: 2em" value="">
- M<input placeholder="month" name="deadline_month" style="width: 2em" value="">
- Y<input placeholder="year" name="deadline_year" style="width: 4em" value=""><br/>
- Reassignable: <input name="reassignable" type="checkbox" checked><br/>
- <textarea name="description" cols="80" rows="2"></textarea><br/>
- <button style="width: 120px" type="submit">Add Task</button>
-</form>
-<hr/>
-<?php
-echo $tasks->show();
-?> \ No newline at end of file