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,paid');
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, $paid) = $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');
50 if(!$paid && isset($GLOBALS['unpaid_totals'])) {
51 if(!isset($GLOBALS['unpaid_totals'][$client_id])) {
52 $GLOBALS['unpaid_totals'][$client_id] = array();
54 if(!isset($GLOBALS['unpaid_totals'][$client_id][$tem_prefix])) {
55 $GLOBALS['unpaid_totals'][$client_id][$tem_prefix] = 0;
57 $GLOBALS['unpaid_totals'][$client_id][$tem_prefix] += $price;
62 tem_set('task_total', $total);
64 tem_show($tem_prefix);
68 # pass multi-dimensional hash arr[client_id][status].
69 # status strings: 'finished_untested', 'finished_unpaid', 'queue'
70 function totals_summary($arr) {
72 $total_finished_untested = 0;
73 $total_finished_unpaid = 0;
76 foreach($arr as $client_id => $t) {
77 $finished_untested = 0;
81 if(isset($t['finished_untested'])) {
82 $finished_untested = $t['finished_untested'];
84 if(isset($t['finished_unpaid'])) {
85 $finished_unpaid = $t['finished_unpaid'];
87 if(isset($t['queue'])) {
90 if(isset($t['needs_approval'])) { # administrator page re-uses this for TASK_WORKING
91 $working = $t['needs_approval'];
93 tem_set('tested_total', $finished_unpaid);
94 tem_set('done_total', $finished_unpaid + $finished_untested);
95 tem_set('not_tested_total', $finished_untested);
96 tem_set('queued_total', $queue + $working);
97 tem_set('client', db_get_value('people', 'username', 'where id=%i', $client_id));
98 tem_show('unpaid_totals_row');
99 $total_finished_untested += $finished_untested;
100 $total_finished_unpaid += $finished_unpaid;
101 $total_queue += $queue;
102 $total_working += $working;
105 tem_set('tested_total', $total_finished_unpaid);
106 tem_set('done_total', $total_finished_unpaid + $total_finished_untested);
107 tem_set('not_tested_total', $total_finished_untested);
108 tem_set('queued_total', $total_queue + $total_working);
109 tem_set('client', 'all');
110 tem_show('unpaid_totals_row');
112 tem_show('unpaid_totals');
116 function _index_main() {
117 $client_id = logged_in();
119 # make sure they've filled out the tiny user agreement
120 $tiny_agreement = db_get_value('people', 'tiny_agreement', 'where id=%i', $client_id);
121 if($tiny_agreement < 30 || $tiny_agreement > 999) {
122 return './tiny_agreement';
125 if(ever_was_contractor()) {
129 if(logged_in_as_contractor()) {
130 tem_show('contractor_links');
131 tem_show('needs_attention_header');
133 $GLOBALS['unpaid_totals'] = array();
134 # things with a view link:
135 task_summary('needs_approval', 'where state=%i order by id desc', TASK_WORKING); # this affects queued_total
137 # things with an edit link:
138 task_summary('needs_fixing', 'where state=%i || state=%i order by id desc', TASK_NEEDS_QUOTE, TASK_BUG);
139 task_summary('finished_untested', 'where state=%i order by client_id, finished_at desc', TASK_NEEDS_TESTING);
140 task_summary('finished_unpaid', 'where state=%i && paid=0 order by finished_at desc', TASK_FINISHED);
141 task_summary('queue', 'where state=%i order by client_id, ord desc', TASK_QUEUED);
142 totals_summary($GLOBALS['unpaid_totals']);
143 task_summary('finished_paid', 'where state=%i && paid = 1 order by finished_at desc limit 20', TASK_FINISHED);
145 tem_show('not_contractor_links');
146 if(db_count('tasks', 'where client_id=%i && (state=%i || state=%i || state=%i || state=%i || state=%i)', $client_id, TASK_DRAFT, TASK_NEEDS_CLARIFICATION, TASK_ON_HOLD, TASK_NEEDS_GO_AHEAD, TASK_NEEDS_TESTING)) {
147 tem_show('needs_attention_header');
148 task_summary('needs_approval', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_NEEDS_GO_AHEAD, TASK_NEEDS_TESTING);
149 task_summary('needs_fixing', 'where client_id=%i && (state=%i || state=%i || state=%i) order by id', $client_id, TASK_ON_HOLD, TASK_DRAFT, TASK_NEEDS_CLARIFICATION);
151 task_summary('queue', 'where client_id=%i && state=%i order by ord desc', $client_id, TASK_QUEUED);
152 task_summary('jason', 'where client_id=%i && (state=%i || state=%i) order by id desc', $client_id, TASK_NEEDS_QUOTE, TASK_BUG);
153 task_summary('jason_working', 'where client_id=%i && state=%i order by id desc', $client_id, TASK_WORKING);
154 task_summary('finished_unpaid', 'where client_id=%i && state=%i && paid=0 order by finished_at desc', $client_id, TASK_FINISHED);
155 task_summary('finished_paid', 'where client_id=%i && state=%i && paid=1 order by finished_at desc', $client_id, TASK_FINISHED);