3 # Copyright (C) 2008 Jason Woofenden
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 require_once('code/tasks.php');
20 function index_main() {
28 tem_show('main_body');
31 # pass multiple argumens for where-clause and printf-args just like db_get_rows()
32 function task_summary($tem_prefix, $where_clause/*, ... */) {
33 $args = func_get_args();
34 $args = array_slice($args, 1);
35 array_unshift($args, 'tasks', 'id,price,title,state,client_id');
36 $rows = call_user_func_array('db_get_rows', $args);
37 #$rows = db_get_rows('tasks', 'id,price,title,state,client_id', $where_clause);
40 foreach($rows as $row) {
41 list($id, $price, $title, $state, $client_id) = $row;
42 tem_set('task_id', $id);
43 tem_set('task_title', $title);
44 tem_set('task_price', $price);
45 tem_set('task_state', task_state_pretty($state));
46 if(logged_in_as_contractor()) {
47 tem_set('client', db_get_value('people', 'username', 'where id=%i', $client_id));
49 tem_show($tem_prefix . '_row');
53 tem_set('task_total', $total);
55 tem_show($tem_prefix);
59 function _index_main() {
60 $client_id = logged_in();
62 # make sure they've filled out the tiny user agreement
63 $tiny_agreement = db_get_value('people', 'tiny_agreement', 'where id=%i', $client_id);
64 if($tiny_agreement < 30) {
65 return './tiny_agreement';
68 if(logged_in_as_contractor()) {
70 tem_show('needs_attention_header');
72 # things with a view link:
73 task_summary('needs_approval', 'where state=%i || (client_id=%i && (state=%i || state=%i || state=%i)) order by id desc', TASK_WORKING, $client_id, TASK_NEEDS_TESTING, TASK_NEEDS_GO_AHEAD, TASK_BUG);
75 # things with an edit link:
76 task_summary('needs_fixing', 'where (state=%i || state=%i) || (client_id=%i && (state<%i || state=%i)) order by id desc', TASK_NEEDS_QUOTE, TASK_BUG, $client_id, TASK_DRAFT, TASK_NEEDS_CLARIFICATION);
77 task_summary('finished_unpaid', 'where state=%i && paid = 0 order by finished_at desc', TASK_FINISHED);
78 task_summary('finished_paid', 'where state=%i && paid = 1 order by finished_at desc limit 20', TASK_FINISHED);
79 task_summary('queue', 'where state=%i order by client_id, ord desc', TASK_QUEUED);
81 if(db_count('tasks', 'where client_id=%i && (state=%i || state=%i || state=%i || state=%i)', $client_id, TASK_DRAFT, TASK_NEEDS_CLARIFICATION, TASK_NEEDS_GO_AHEAD, TASK_NEEDS_TESTING)) {
82 tem_show('needs_attention_header');
83 task_summary('needs_approval', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_NEEDS_GO_AHEAD, TASK_NEEDS_TESTING);
84 task_summary('needs_fixing', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_DRAFT, TASK_NEEDS_CLARIFICATION);
86 task_summary('queue', 'where client_id=%i && state=%i order by ord desc', $client_id, TASK_QUEUED);
87 task_summary('jason', 'where client_id=%i && (state=%i || state=%i) order by id desc', $client_id, TASK_NEEDS_QUOTE, TASK_BUG);
88 task_summary('jason_working', 'where client_id=%i && state=%i order by id desc', $client_id, TASK_WORKING);
89 task_summary('finished_unpaid', 'where client_id=%i && state=%i && paid=0 order by finished_at desc', $client_id, TASK_FINISHED);
90 task_summary('finished_paid', 'where client_id=%i && state=%i && paid=1 order by finished_at desc', $client_id, TASK_FINISHED);