JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added real logins, login administration, task viewer page, contractor main page
[contractor-progress.git] / tasks.php
index e923b21..6351ca6 100644 (file)
--- a/tasks.php
+++ b/tasks.php
@@ -13,6 +13,18 @@ require_once('code/wfpl/messages.php');
 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']);
@@ -30,28 +42,74 @@ function tasks_tem_sets($title, $url, $description) {
 }
 
 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']);
        unset($_REQUEST['tasks_delete_id']);
        if($delete_id) {
@@ -61,10 +119,6 @@ function _tasks_main() {
                return './tasks.html';
        }
 
-       if(!$edit_id) {
-               tem_show('new_msg');
-       }
-
        if(isset($_REQUEST['title'])) {
                list($title, $url, $description) = tasks_get_fields();
 
@@ -127,9 +181,11 @@ function _tasks_main() {
        # 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');
 }
 
 ?>