JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fixed css so prioritize links don't make a horizontal scroll bar
[contractor-progress.git] / index.php
1 <?php
2
3 #  Copyright (C) 2008  Jason Woofenden
4 #
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.
9 #
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.
14 #
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/>.
17
18 require_once('code/tasks.php');
19
20 function index_main() {
21         if(!logged_in()) {
22                 return 'login';
23         }
24         $ret = _index_main();
25         if($ret) {
26                 return $ret;
27         }
28         tem_show('main_body');
29 }
30
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);
38         if($rows) {
39                 $total = 0.0;
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));
48                         }
49                         tem_show($tem_prefix . '_row');
50                         $total += $price;
51                 }
52
53                 tem_set('task_total', $total);
54
55                 tem_show($tem_prefix);
56         }
57 }
58
59 function _index_main() {
60         $client_id = logged_in();
61
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';
66         }
67
68         if(logged_in_as_contractor()) {
69                 tem_show('su_link');
70                 tem_show('needs_attention_header');
71
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);
74
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_untested', 'where state=%i order by client_id, finished_at desc', TASK_NEEDS_TESTING);
79                 task_summary('finished_paid', 'where state=%i && paid = 1 order by finished_at desc limit 20', TASK_FINISHED);
80                 task_summary('queue', 'where state=%i order by client_id, ord desc', TASK_QUEUED);
81         } else {
82                 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)) {
83                         tem_show('needs_attention_header');
84                         task_summary('needs_approval', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_NEEDS_GO_AHEAD, TASK_NEEDS_TESTING);
85                         task_summary('needs_fixing', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_DRAFT, TASK_NEEDS_CLARIFICATION);
86                 }
87                 task_summary('queue', 'where client_id=%i && state=%i order by ord desc', $client_id, TASK_QUEUED);
88                 task_summary('jason', 'where client_id=%i && (state=%i || state=%i) order by id desc', $client_id, TASK_NEEDS_QUOTE, TASK_BUG);
89                 task_summary('jason_working', 'where client_id=%i && state=%i order by id desc', $client_id, TASK_WORKING);
90                 task_summary('finished_unpaid', 'where client_id=%i && state=%i && paid=0 order by finished_at desc', $client_id, TASK_FINISHED);
91                 task_summary('finished_paid', 'where client_id=%i && state=%i && paid=1 order by finished_at desc', $client_id, TASK_FINISHED);
92         }
93         return;
94 }