X-Git-Url: https://jasonwoof.com/gitweb/?p=contractor-progress.git;a=blobdiff_plain;f=tasks.php;h=6351ca6e5ebd3b18a40eacc9dae9b98b39eb00dc;hp=04438896e2c9f2d9ed5b16272cc083c048a95f16;hb=1bcde3c6ba88a93deaa0848df4de0b0857d9bf49;hpb=5cc6274a058be9a9cf9d7d3e1d169870cad90353 diff --git a/tasks.php b/tasks.php index 0443889..6351ca6 100644 --- 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,20 +42,72 @@ 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']); @@ -55,29 +119,28 @@ function _tasks_main() { 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']; @@ -99,8 +162,7 @@ function _tasks_main() { } } if($error !== true) { - tem_show('thankyou'); - return; + return './'; } } # otherwise, we display the form again. tasks_get_fields() has @@ -119,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'); } ?>