3 function tasks_pagesetup() {
10 if (defined("context") && context
== "tasks" && page_owner() == $_SESSION['userid']) {
11 $PAGE->menu
[] = array( 'name' => 'tasks',
12 'html' => '<li><a href="'.$CFG->wwwroot
.'mod/tasks/" class="selected">'.gettext("Your Tasks").'</a></li>');
14 $PAGE->menu
[] = array( 'name' => 'tasks',
15 'html' => '<li><a href="'.$CFG->wwwroot
.'mod/tasks/">'.gettext("Your Tasks").'</a></li>');
20 function tasks_init() {
26 $function['init'][] = $CFG->dirroot
. "mod/tasks/init.php";
27 $function['display:sidebar'][] = $CFG->dirroot
. "mod/tasks/sidebarlink.php";
29 $tables = $db->Metatables();
30 if (!in_array($CFG->prefix
. "tasks",$tables)) {
31 modify_database($CFG->dirroot
. "mod/tasks/table.sql");
32 print_continue("index.php");
38 function tasks_permissions_check ($object) {
41 if ($object === "tasks" && (page_owner() == $_SESSION['userid'] ||
user_flag_get("admin", $_SESSION['userid']))) {
47 function tasks_display ($tasklist_id, $owner_id, $title, $assigned_to = false, $keyword = null) {
52 $where = run("users:access_level_sql_where",$_SESSION['userid']);
53 if ($tasklist_id > 0) {
54 $tasklist_where = " and tasklist = $tasklist_id ";
55 } else if ($tasklist_id < 0) {
56 $tasklist_where = " and tasklist != " . (0 - $tasklist_id);
61 if ($keyword == null) {
62 if ($owner_id != -1) {
63 $sql = "select * from ".$CFG->prefix
."tasks where ($where) and owner = ".$owner_id." $tasklist_where order by deadline asc";
65 $sql = "select * from ".$CFG->prefix
."tasks where ($where) and owner != ".$_SESSION['userid']." $tasklist_where order by deadline asc";
68 $where = str_replace("owner","ts.owner",$where);
69 $where = str_replace("access","ts.access",$where);
70 $keyword = mysql_real_escape_string($keyword);
71 if ($owner_id != -1) {
72 $sql = "select ts.* from ".$CFG->prefix
."tags tg left join ".$CFG->prefix
."tasks ts on ts.ident = tg.ref where ($where) and tg.tag = '$keyword' and ts.owner = ".$owner_id." $tasklist_where order by deadline asc";
74 $sql = "select ts.* from ".$CFG->prefix
."tags tg left join ".$CFG->prefix
."tasks ts on ts.ident = tg.ref where ($where) and tg.tag = '$keyword' and ts.owner != ".$_SESSION['userid']." $tasklist_where order by deadline asc";
78 $tasks = get_records_sql($sql);
80 if ($tasklist_id < 0) {
81 $tasklist_id = 0 - $tasklist_id;
84 if (is_array($tasks) && !empty($tasks)) {
86 $return = "<h2>" . $title . "</h2>";
87 foreach($tasks as $task) {
88 if (run("users:access_level_check", $task->access
)) {
90 $return .= "<table width=\"100%\" border=\"0\" class=\"task\">";
94 if ($task->deadline
< time() && $task->deadline
> 0) {
96 } else if ($task->deadline
< (time() +
86400) && $task->deadline
> 0) {
97 $class = "task_expiring";
99 $class = "task_normal";
101 $return .= "<tr class=\"$class\"><td class=\"task_title\">";
103 if ($task->tasklist
!= page_owner()) {
104 $return .= "<a href=\"".$CFG->wwwroot
."mod/tasks/?owner=".$task->tasklist
."\">";
107 $return .= $task->title
;
109 if ($task->tasklist
!= page_owner()) {
110 $return .= " @ " . user_info("name",$task->tasklist
) . "</a>";
113 if ($task->deadline
> 0) {
115 $return .= "</td><td class=\"task_deadline\">" . gettext("Due: ") . strftime("%B %d, %Y %H:%M",$task->deadline
);
118 if ($task->owner
== $_SESSION['userid'] ||
run("permissions:check", "profile")) {
120 $return .= "<td class=\"task_buttons\">Edit | <a href=\"".$CFG->wwwroot
."mod/tasks/?owner=".$task->tasklist
."&action=task:delete&task_id=".$task->ident
."\">Delete</a></td>";
123 $return .= "<tr class=\"$class\"><td colspan=\"$cells\" class=\"task_assigned\">";
124 $return .= gettext("Assigned to: ");
126 if (run("permissions:check", "weblog") && logged_on
) {
128 $sql = "select u.ident, u.name from ".$CFG->prefix
."friends f join ".$CFG->prefix
."users u on u.ident = f.owner where f.friend = ".$task->tasklist
;
129 $users = get_records_sql($sql);
131 $return .= "<form action=\"\" method=\"post\">";
133 if (is_array($users) && !empty($users)) {
135 $return .= "<select name=\"task_assigned\">";
137 foreach($users as $user) {
138 if ($user->ident
== $task->owner
) {
139 $selected = "selected = \"selected\"";
144 $return .= "<option value=\"".$user->ident
."\" $selected>" . $user->name
. "</option>";
147 $user = get_record_sql("select * from ".$CFG->prefix
."users where ident = ".$task->owner
);
148 $return .= "<option value=\"".$user->ident
."\" selected=\"selected\">" . $user->name
. "</option>";
150 $return .= "</select> ";
151 $return .= "<input type=\"hidden\" name=\"action\" value=\"task:reassign\" />";
152 $return .= "<input type=\"hidden\" name=\"task_id\" value=\"".$task->ident
."\" />";
153 $return .= "<input type=\"submit\" value=\">\" />";
157 $return .= "</form>";
160 $return .= user_info("name",$task->owner
);
163 $return .= "</td></tr>";
165 $return .= "<tr><td colspan=\"$cells\" class=\"task_description\">" . nl2br($task->description
) . "</td></tr>";
168 $db_tags = get_records_sql("select * from ".$CFG->prefix
."tags where tagtype = 'task' and ref = ".$task->ident
);
170 if (is_array($db_tags) && !empty($db_tags)) {
172 foreach($db_tags as $tag) {
173 $tags .= "<a href=\"" . $CFG->wwwroot
. "mod/tasks/search.php?tag=".urlencode($tag->tag
)."&tasklist=$tasklist_id\">";
176 if ($i < sizeof($db_tags) - 1) {
183 $return .= "<tr><td colspan=\"$cells\" class=\"task_tags\">" . gettext("Tags:") . " " . $tags . "</td>";
184 $return .= "</tr>\n";
186 $return .= "</table>";
197 function tasks_form($tasklist_id) {
201 if (run("permissions:check", "weblog") && logged_on
) {
203 if (user_type($tasklist_id) == "person") {
204 $access = "user" . $tasklist_id;
205 } else if (user_type($tasklist_id) == "community") {
206 $access = "community" . $tasklist_id;
211 $return .= "<h2>" . gettext("Add new task") . "</h2>";
212 $return .= "<form action=\"\" method=\"post\">";
213 $return .= "<p>" . gettext("Task title") . "<br /><input type=\"text\" name=\"task_title\" value=\"\" /></p>";
214 $return .= "<p>" . gettext("Task description") . "<br /><textarea name=\"task_description\" ></textarea></p>";
215 $return .= "<p>" . gettext("Task tags") . "<br /><input type=\"text\" name=\"task_tags\" value=\"\" /></p>";
216 $return .= "<p>" . gettext("Task expiry time if any<br />(eg, 'next thursday 15:00', 'december 1st 2007', '+1 week', etc)") . "<br /><input type=\"text\" name=\"task_deadline\" value=\"\"></textarea></p>";
217 $return .= "<p>" . gettext("Task access restriction") . "<br />". run("display:access_level_select",array("task_access",$access)) ."</p>";
218 $return .= "<p><input type=\"hidden\" name=\"action\" value=\"task:add\" /><input type=\"hidden\" name=\"tasklist_id\" value=\"$tasklist_id\" /><input type=\"submit\" value=\"" . gettext("Add new task") . "\" /></p>";
219 $return .= "</form>";
227 function tasks_actions() {
234 $action = optional_param('action', "");
236 if (logged_on
&& run("permissions:check", "weblog") && !empty($action)) {
241 $task = new stdClass
;
243 $task->title
= optional_param('task_title',"");
244 $task->description
= optional_param('task_description',"");
245 $task->access
= optional_param('task_access',"");
246 $task->tasklist
= optional_param('tasklist_id',page_owner(),PARAM_INT
);
247 $task->owner
= $_SESSION['userid'];
248 $task->posted
= time();
250 $deadline = optional_param('task_deadline',"");
251 if (empty($deadline)) {
254 $task->deadline
= strtotime($deadline);
257 $insert_id = insert_record('tasks',$task);
259 $tags = optional_param('task_tags',"");
260 insert_tags_from_string (trim($tags), 'task', $insert_id, $task->access
, $task->owner
);
262 $messages[] = gettext("Task '". $task->title
."' was added to the tasklist.");
268 $task_id = optional_param('task_id',-1,PARAM_INT
);
269 if ($task_id != -1) {
270 $task = get_record_sql("select * from ".$CFG->prefix
."tasks where ident = $task_id");
271 if ($task->owner
== $_SESSION['userid'] ||
run("permissions:check", "weblog")) {
273 delete_records('tasks','ident',$task_id);
274 delete_records('tags','tagtype','task','ref',$task_id);
275 $messages[] = gettext("Task '".$task->title
."' was deleted.");
282 case "task:reassign":
284 $task_id = optional_param('task_id',-1,PARAM_INT
);
285 $task_owner = optional_param('task_assigned',-1,PARAM_INT
);
286 if ($task_id != -1 && $task_owner != -1) {
287 $task = get_record_sql("select * from ".$CFG->prefix
."tasks where ident = $task_id");
288 if ($task->owner
== $_SESSION['userid'] ||
run("permissions:check", "weblog")) {
290 $task->owner
= $task_owner;
291 update_record('tasks',$task);
292 $messages[] = gettext("Task '".$task->title
."' was reassigned.");
302 define('redirect_url',$CFG->wwwroot
. "mod/tasks/?owner=" . $task->tasklist
);
303 $_SESSION['messages'] = $messages;
304 header("Location: " . redirect_url
);