+function tasks_display_main() {
+ $task_id = format_int($_REQUEST['tasks_id']);;
+ $client_id = logged_in();
+ if(logged_in_as_contractor()) {
+ $row = db_get_row('tasks', 'title,url,description,state,price,client_id', 'where id=%i', $task_id);
+ } else {
+ $row = db_get_row('tasks', 'title,url,description,state,price,client_id', 'where id=%i && client_id=%i', $task_id, $client_id);
+ }
+ if($row) {
+ list($title, $url, $description, $state, $price, $owner_id) = $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));
+ tem_set('price', $price);
+ if($state == TASK_BUG) {
+ tem_show('bug_title');
+ } else {
+ tem_show('normal_title');
+ }
+ if(logged_in_as_contractor()) {
+ switch($state) {
+ case TASK_DRAFT:
+ case TASK_NEEDS_CLARIFICATION:
+ case TASK_NEEDS_QUOTE:
+ case TASK_BUG:
+ tem_show('normal_edit_link');
+ break;
+ case TASK_NEEDS_GO_AHEAD:
+ tem_show('approve_price_link');
+ tem_show('normal_edit_link');
+ tem_show('price_row');
+ break;
+ case TASK_QUEUED:
+ tem_show('normal_edit_link');
+ tem_show('working_link');
+ tem_show('price_row');
+ break;
+ case TASK_WORKING:
+ tem_show('price_row');
+ tem_show('needs_testing_link');
+ break;
+ case TASK_NEEDS_TESTING:
+ if($owner_id == logged_in()) {
+ tem_show('finished_link');
+ }
+ # FALL THROUGH
+ case TASK_FINISHED:
+ tem_show('price_row');
+ tem_show('mark_paid_link'); # FIXME
+ break;
+ }
+ } else {
+ switch($state) {
+ case TASK_DRAFT:
+ case TASK_NEEDS_CLARIFICATION:
+ case TASK_NEEDS_QUOTE:
+ case TASK_BUG:
+ tem_show('normal_edit_link');
+ break;
+ case TASK_NEEDS_GO_AHEAD:
+ tem_show('price_row');
+ tem_show('approve_price_link');
+ tem_show('normal_edit_link');
+ break;
+ case TASK_QUEUED:
+ tem_show('price_row');
+ tem_show('warning_edit_link');
+ break;
+ case TASK_WORKING:
+ tem_show('price_row');
+ break;
+ case TASK_NEEDS_TESTING:
+ tem_show('price_row');
+ tem_show('finished_link');
+ break;
+ case TASK_FINISHED:
+ tem_show('price_row');
+ break;
+ }
+ }
+ } else {
+ message("Task #$task_id not found");
+ return './';
+ }
+}
+
+function tasks_edit_main() {
+ $state = TASK_DRAFT; # will be overwritten
+ $client_id = logged_in(); # fixed shortly if we're contractor