require_once('code/wfpl/email.php');
require_once('code/db_connect.php');
+# replace every character in $str with " "
+function tonbsp($matches) {
+ return str_repeat(' ', strlen($matches[0]) * 2);
+}
+
+# encode as html, make it display newlines and leading spaces
+function enc_htmlbrtab($str) {
+ $str = enc_htmlbr($str);
+ $str = preg_replace_callback("|^ *|m", tonbsp, $str);
+ return $str;
+}
+
function tasks_get_fields() {
$title = format_oneline($_REQUEST['title']);
$url = format_oneline($_REQUEST['url']);
}
function tasks_main() {
- $ret = _tasks_main();
- if($ret) {
- return $ret;
+ if(!logged_in()) {
+ $GLOBALS['url'] = this_url();
+ return 'login';
+ }
+
+ if(isset($_REQUEST['tasks_id'])) {
+ $ret = tasks_display_main();
+ if($ret) {
+ return $ret;
+ }
+ tem_show('display_body');
+ } else {
+ $ret = tasks_edit_main();
+ if($ret) {
+ return $ret;
+ }
+ tem_show('edit_body');
}
+
tem_show('main_body');
}
-function _tasks_main() {
+function tasks_display_main() {
+ $task_id = format_int($_REQUEST['tasks_id']);;
+ $row = db_get_row('tasks', 'title,url,description,state', 'where id=%i', $task_id);
+ if($row) {
+ list($title, $url, $description, $state) = $row;
+ tem_set('task_id', $task_id);
+ tem_set('title', $title);
+ tem_set('url', $url);
+ tem_set('description', $description);
+ tem_set('state', task_state_pretty($state));
+ if($state == TASK_BUG) {
+ tem_show('bug_title');
+ } else {
+ tem_show('normal_title');
+ }
+ } else {
+ message("Task #$task_id not found");
+ return './';
+ }
+}
+
+function tasks_edit_main() {
+ $state = TASK_DRAFT; # will be overwritten
$edit_id = format_int($_REQUEST['tasks_edit_id']);
unset($_REQUEST['tasks_edit_id']);
if($edit_id) {
# add hidden field for database id of row we're editing
tem_set('tasks_edit_id', $edit_id);
tem_show('editing');
+
+ $state = db_get_value('tasks', 'state', 'where id=%i', $edit_id);
+ }
+
+ if(isset($_REQUEST['tasks_new_bug'])) {
+ tem_show('bug_submit');
+ $state = TASK_BUG;
+ } else {
+ tem_show('normal_submits');
+ }
+
+ if($state == TASK_BUG) {
+ tem_show('bug_instructions');
+ } else {
+ tem_show('normal_instructions');
}
$delete_id = format_int($_REQUEST['tasks_delete_id']);
return './tasks.html';
}
- if(!$edit_id) {
- tem_show('new_msg');
- }
-
if(isset($_REQUEST['title'])) {
list($title, $url, $description) = tasks_get_fields();
+ # FIXME
+ if(isset($_REQUEST['save_draft'])) {
+ $state = TASK_DRAFT;
+ } elseif(isset($_REQUEST['save_bug'])) {
+ $state = TASK_BUG;
+ } else {
+ $state = TASK_NEEDS_QUOTE;
+ }
+
if("you're happy with the POSTed values") {
if($edit_id) {
- db_update('tasks', 'title,url,description,state', $title, $url, $description, $state, $paid = 0, 'where id=%i', $edit_id);
+ db_update('tasks', 'title,url,description,state', $title, $url, $description, $state, 'where id=%i', $edit_id);
message('Task updated.');
} else {
# new task
$paid = 0;
- if(isset($_REQUEST['save_draft'])) {
- $state = TASK_DRAFT;
- } else {
- $state = TASK_NEEDS_QUOTE;
- }
$client_id = 4; # FIXME
db_insert('tasks', 'client_id,title,url,description,state,paid', $client_id, $title, $url, $description, $state, $paid);
message('Task saved.');
- return './';
}
if($GLOBALS['tasks_form_recipient'] != "fixme@example.com") {
$to = $GLOBALS['tasks_form_recipient'];
}
}
if($error !== true) {
- tem_show('thankyou');
- return;
+ return './';
}
}
# otherwise, we display the form again. tasks_get_fields() has
# this has to be later in the file because it requres that client_id be set already
if($edit_id) {
tem_show('edit_msg');
+ } elseif($state == TASK_BUG) {
+ tem_show('bug_msg');
+ } else {
+ tem_show('new_msg');
}
-
- tem_show('form');
}
?>