. require_once('code/tasks.php'); function index_main() { if(!logged_in()) { return 'login'; } $ret = _index_main(); if($ret) { return $ret; } tem_show('main_body'); } # pass multiple argumens for where-clause and printf-args just like db_get_rows() function task_summary($tem_prefix, $where_clause/*, ... */) { $args = func_get_args(); $args = array_slice($args, 1); array_unshift($args, 'tasks', 'id,price,title,state,client_id'); $rows = call_user_func_array('db_get_rows', $args); #$rows = db_get_rows('tasks', 'id,price,title,state,client_id', $where_clause); if($rows) { $total = 0.0; foreach($rows as $row) { list($id, $price, $title, $state, $client_id) = $row; tem_set('task_id', $id); tem_set('task_title', $title); tem_set('task_price', $price); tem_set('task_state', task_state_pretty($state)); if(logged_in_as_contractor()) { tem_set('client', db_get_value('people', 'username', 'where id=%i', $client_id)); } tem_show($tem_prefix . '_row'); $total += $price; } tem_set('task_total', $total); tem_show($tem_prefix); } } function _index_main() { $client_id = logged_in(); # make sure they've filled out the tiny user agreement $tiny_agreement = db_get_value('people', 'tiny_agreement', 'where id=%i', $client_id); if($tiny_agreement < 30) { return './tiny_agreement'; } if(logged_in_as_contractor()) { tem_show('su_link'); tem_show('needs_attention_header'); # things with a view link: 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); # things with an edit link: 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); task_summary('finished_unpaid', 'where state=%i && paid=0 order by finished_at desc', TASK_FINISHED); task_summary('finished_untested', 'where state=%i order by client_id, finished_at desc', TASK_NEEDS_TESTING); task_summary('finished_paid', 'where state=%i && paid = 1 order by finished_at desc limit 20', TASK_FINISHED); task_summary('queue', 'where state=%i order by client_id, ord desc', TASK_QUEUED); } else { 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)) { tem_show('needs_attention_header'); task_summary('needs_approval', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_NEEDS_GO_AHEAD, TASK_NEEDS_TESTING); task_summary('needs_fixing', 'where client_id=%i && (state=%i || state=%i) order by id', $client_id, TASK_DRAFT, TASK_NEEDS_CLARIFICATION); } task_summary('queue', 'where client_id=%i && state=%i order by ord desc', $client_id, TASK_QUEUED); task_summary('jason', 'where client_id=%i && (state=%i || state=%i) order by id desc', $client_id, TASK_NEEDS_QUOTE, TASK_BUG); task_summary('jason_working', 'where client_id=%i && state=%i order by id desc', $client_id, TASK_WORKING); task_summary('finished_unpaid', 'where client_id=%i && state=%i && paid=0 order by finished_at desc', $client_id, TASK_FINISHED); task_summary('finished_paid', 'where client_id=%i && state=%i && paid=1 order by finished_at desc', $client_id, TASK_FINISHED); } return; }