. require_once("../inc/submit_db.inc"); require_once("../inc/util.inc"); require_once("../inc/result.inc"); require_once("../inc/submit_util.inc"); require_once("../project/project.inc"); error_reporting(E_ALL); ini_set('display_errors', true); ini_set('display_startup_errors', true); define("PAGE_SIZE", 20); function state_count($batches, $state) { $n = 0; foreach ($batches as $batch) { if ($batch->state == $state) $n++; } return $n; } function show_all_link($batches, $state, $limit, $user, $app) { $n = state_count($batches, $state); if ($n > $limit) { if ($user) $userid = $user->id; else $userid = 0; if ($app) $appid = $app->id; else $appid = 0; echo "Showing the most recent $limit of $n batches. Show all $n
"; } } function show_in_progress($batches, $limit, $user, $app) { $first = true; $n = 0; foreach ($batches as $batch) { if ($batch->state != BATCH_STATE_IN_PROGRESS) continue; if ($limit && $n == $limit) break; $n++; if ($first) { $first = false; echo "
No in-progress batches.\n"; } else { end_table(); } } function show_complete($batches, $limit, $user, $app) { $first = true; $n = 0; foreach ($batches as $batch) { if ($batch->state != BATCH_STATE_COMPLETE) continue; if ($limit && $n == $limit) break; $n++; if ($first) { $first = false; echo "
No completed batches.\n"; } else { end_table(); } } function show_aborted($batches, $limit, $user, $app) { $first = true; $n = 0; foreach ($batches as $batch) { if ($batch->state != BATCH_STATE_ABORTED) continue; if ($limit && $n == $limit) break; $n++; if ($first) { $first = false; echo "
Return to job control page\n"; page_tail(); } // show the details of a job, including links to see the output files // function handle_query_job($user) { $wuid = get_int('wuid'); $wu = BoincWorkunit::lookup_id($wuid); if (!$wu) error_page("no such job"); page_head("Job $wuid"); echo " Workunit details · batch>Batch $wu->batch "; // show input files // echo "
Return to job control page\n"; page_tail(); } function handle_abort_batch_confirm() { $batch_id = get_int('batch_id'); page_head("Confirm abort batch"); echo " Aborting a batch will cancel all unstarted jobs. Are you sure you want to do this?
"; show_button( "submit.php?action=abort_batch&batch_id=$batch_id", "Yes - abort batch" ); echo "
Return to job control page\n"; page_tail(); } function check_access($user, $batch) { if ($user->id == $batch->user_id) return; $user_submit = BoincUserSubmit::lookup_userid($user->id); if ($user_submit->manage_all) return; $usa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$batch->app_id"); if ($usa->manage) return; error_page("no access"); } function handle_abort_batch($user) { $batch_id = get_int('batch_id'); $batch = BoincBatch::lookup_id($batch_id); if (!$batch) error_page("no such batch"); check_access($user, $batch); abort_batch($batch); page_head("Batch aborted"); echo "
Return to job control page\n"; page_tail(); } function handle_retire_batch_confirm() { $batch_id = get_int('batch_id'); page_head("Confirm retire batch"); echo " Retiring a batch will remove all of its output files. Are you sure you want to do this?
"; show_button( "submit.php?action=retire_batch&batch_id=$batch_id", "Yes - retire batch" ); echo "
Return to job control page\n"; page_tail(); } function handle_retire_batch($user) { $batch_id = get_int('batch_id'); $batch = BoincBatch::lookup_id($batch_id); if (!$batch) error_page("no such batch"); check_access($user, $batch); retire_batch($batch); page_head("Batch retired"); echo "
Return to job control page\n"; page_tail(); } function show_batches_in_state($batches, $state) { switch ($state) { case BATCH_STATE_IN_PROGRESS: page_head("Batches in progress"); show_in_progress($batches, 0, null, null); break; case BATCH_STATE_COMPLETE: page_head("Completed batches"); show_complete($batches, 0, null, null); break; case BATCH_STATE_ABORTED: page_head("Aborted batches"); show_aborted($batches, 0, null, null); break; } page_tail(); } function handle_show_all($user) { $userid = get_int("userid"); $appid = get_int("appid"); $state = get_int("state"); if ($userid) { // user looking at their own batches // if ($userid != $user->id) error_page("wrong user"); $batches = BoincBatch::enum("user_id = $user->id and state=$state order by id desc"); fill_in_app_and_user_names($batches); show_batches_in_state($batches, $state); } else { // admin looking at batches // check_admin_access($user, $appid); if ($appid) { $app = BoincApp::lookup_id($appid); if (!$app) error_page("no such app"); $batches = BoincBatch::enum("app_id = $appid and state=$state order by id desc"); } else { $batches = BoincBatch::enum("state=$state order by id desc"); } fill_in_app_and_user_names($batches); show_batches_in_state($batches, $state); } } $user = get_logged_in_user(); $action = get_str('action', true); switch ($action) { case '': handle_main($user); break; case 'abort_batch': handle_abort_batch($user); break; case 'abort_batch_confirm': handle_abort_batch_confirm(); break; case 'admin': handle_admin($user); break; case 'query_batch': handle_query_batch($user); break; case 'query_job': handle_query_job($user); break; case 'retire_batch': handle_retire_batch($user); break; case 'retire_batch_confirm': handle_retire_batch_confirm(); break; case 'show_all': handle_show_all($user); break; default: error_page("no such action $action"); } ?>