JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added real logins, login administration, task viewer page, contractor main page
[contractor-progress.git] / index.php
1 <?php
2
3 require_once('code/tasks.php');
4
5 function enc_money($float) {
6         return format_money($float, $cents = true);
7 }
8
9 function index_main() {
10         if(!logged_in()) {
11                 return 'login';
12         }
13         $ret = _index_main();
14         if($ret) {
15                 return $ret;
16         }
17         tem_show('main_body');
18 }
19
20 # pass multiple argumens for where-clause and printf-args just like db_get_rows()
21 function task_summary($tem_prefix, $where_clause/*, ... */) {
22         $args = func_get_args();
23         $args = array_slice($args, 1);
24         array_unshift($args, 'tasks', 'id,price,title,state,client_id');
25         print_r($args);
26         $rows = call_user_func_array('db_get_rows', $args);
27         #$rows = db_get_rows('tasks', 'id,price,title,state,client_id', $where_clause);
28         if($rows) {
29                 $total = 0.0;
30                 foreach($rows as $row) {
31                         list($id, $price, $title, $state, $client_id) = $row;
32                         tem_set('task_id', $id);
33                         tem_set('task_title', $title);
34                         tem_set('task_price', $price);
35                         tem_set('task_state', task_state_pretty($state));
36                         if(logged_in_as_contractor()) {
37                                 tem_set('client', db_get_value('people', 'name', 'where id=%i', $client_id));
38                         }
39                         tem_show($tem_prefix . '_row');
40                         $total += $price;
41                 }
42
43                 tem_set('task_total', $total);
44
45                 tem_show($tem_prefix);
46         }
47 }
48
49 function _index_main() {
50         $client_id = logged_in();
51         if(logged_in_as_contractor()) {
52                 task_summary('needs_attention', 'where state=%i || state=%i || state=%i order by id desc', TASK_NEEDS_QUOTE, TASK_WORKING, TASK_BUG);
53                 task_summary('finished_unpaid', 'where state=%i && paid = 0 order by id desc', TASK_FINISHED);
54                 task_summary('finished_paid', 'where state=%i && paid = 1 order by id desc', TASK_FINISHED);
55         } else {
56                 task_summary('needs_attention', 'where state=' . TASK_DRAFT . ' || state=' . TASK_NEEDS_CLARIFICATION . ' || state=' . TASK_NEEDS_GO_AHEAD . ' || state=' . TASK_NEEDS_TESTING . ' order by id');
57                 task_summary('queue', 'where state=' . TASK_QUEUED . " && client_id=$client_id order by ord");
58                 task_summary('jason', 'where state=' . TASK_NEEDS_QUOTE . ' || state=' . TASK_WORKING . ' || state=' . TASK_BUG . ' order by id desc');
59                 #task_summary('jason_pricing', 'where state=' . TASK_NEEDS_QUOTE . ' order by id desc');
60                 #task_summary('jason_working', 'where state=' . TASK_WORKING . ' order by id desc');
61                 task_summary('finished_unpaid', 'where state=' . TASK_FINISHED . ' && paid = 0 order by id desc');
62                 task_summary('finished_paid', 'where state=' . TASK_FINISHED . ' && paid = 1 order by id desc');
63         }
64         return;
65 }