JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
311addfefa38c6fa46c3a83309450329dfa33ab0
[contractor-progress.git] / index.php
1 <?php
2
3 require_once('code/tasks.php');
4
5 function index_main() {
6         if(!logged_in()) {
7                 return 'login';
8         }
9         $ret = _index_main();
10         if($ret) {
11                 return $ret;
12         }
13         tem_show('main_body');
14 }
15
16 # pass multiple argumens for where-clause and printf-args just like db_get_rows()
17 function task_summary($tem_prefix, $where_clause/*, ... */) {
18         $args = func_get_args();
19         $args = array_slice($args, 1);
20         array_unshift($args, 'tasks', 'id,price,title,state,client_id');
21         $rows = call_user_func_array('db_get_rows', $args);
22         #$rows = db_get_rows('tasks', 'id,price,title,state,client_id', $where_clause);
23         if($rows) {
24                 $total = 0.0;
25                 foreach($rows as $row) {
26                         list($id, $price, $title, $state, $client_id) = $row;
27                         tem_set('task_id', $id);
28                         tem_set('task_title', $title);
29                         tem_set('task_price', $price);
30                         tem_set('task_state', task_state_pretty($state));
31                         if(logged_in_as_contractor()) {
32                                 tem_set('client', db_get_value('people', 'username', 'where id=%i', $client_id));
33                         }
34                         tem_show($tem_prefix . '_row');
35                         $total += $price;
36                 }
37
38                 tem_set('task_total', $total);
39
40                 tem_show($tem_prefix);
41         }
42 }
43
44 function _index_main() {
45         $client_id = logged_in();
46
47         # make sure they've filled out the tiny user agreement
48         $tiny_agreement = db_get_value('people', 'tiny_agreement', 'where id=%i', $client_id);
49         if($tiny_agreement < 30) {
50                 return './tiny_agreement';
51         }
52
53         if(logged_in_as_contractor()) {
54                 tem_show('su_link');
55                 tem_show('needs_attention_header');
56                 task_summary('needs_approval', 'where state=%i order by id desc', TASK_WORKING);
57                 task_summary('needs_fixing', 'where (state=%i || state=%i) || (client_id=1 && state<%i) order by id desc', TASK_NEEDS_QUOTE, TASK_BUG, TASK_QUEUED);
58                 task_summary('finished_unpaid', 'where state=%i && paid = 0 order by id desc', TASK_FINISHED);
59                 task_summary('finished_paid', 'where state=%i && paid = 1 order by id desc', TASK_FINISHED);
60                 task_summary('queue', 'where state=%i order by client_id, ord', TASK_QUEUED);
61         } else {
62                 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)) {
63                         tem_show('needs_attention_header');
64                         task_summary('needs_approval', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_NEEDS_GO_AHEAD, TASK_NEEDS_TESTING);
65                         task_summary('needs_fixing', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_DRAFT, TASK_NEEDS_CLARIFICATION);
66                 }
67                 task_summary('queue', 'where client_id=%i && state=%i order by ord', $client_id, TASK_QUEUED);
68                 task_summary('jason', 'where client_id=%i && (state=%i || state=%i) order by id desc', $client_id, TASK_NEEDS_QUOTE, TASK_BUG);
69                 task_summary('jason_working', 'where client_id=%i && state=%i order by id desc', $client_id, TASK_WORKING);
70                 task_summary('finished_unpaid', 'where client_id=%i && state=%i && paid=0 order by id desc', $client_id, TASK_FINISHED);
71                 task_summary('finished_paid', 'where client_id=%i && state=%i && paid=1 order by id desc', $client_id, TASK_FINISHED);
72         }
73         return;
74 }