if (!$found) {
         throw ns_exception("The sample you modified no longer exists in the database!");
     }
     $sample_id = 0;
 }
 /*******************************
    Load Mask information for samples
   ********************************/
 $query = "SELECT image_masks.id, images.id, images.filename FROM image_masks, images WHERE image_masks.processed = 0 AND image_masks.image_id = images.id ORDER BY images.filename ";
 $sql->get_row($query, $masks);
 $masks[sizeof($masks)] = array(0, 0, "(none)");
 /**********************************
    Load Experiment-wide Jobs
   **********************************/
 $job = new ns_processing_job();
 $query = $job->provide_query_stub();
 $query .= "FROM processing_jobs WHERE processing_jobs.experiment_id = {$experiment_id} AND sample_id = 0 AND region_id = 0";
 $sql->get_row($query, $ejobs);
 $experiment_jobs = array();
 for ($i = 0; $i < sizeof($ejobs); $i++) {
     $experiment_jobs[$i] = new ns_processing_job();
     $experiment_jobs[$i]->load_from_result($ejobs[$i]);
 }
 /*****************************
    Load Sample Jobs
   ****************************/
 $sample_jobs = array();
 if ($show_sample_jobs) {
     for ($i = 0; $i < sizeof($experiment->samples); $i++) {
         $query = $job->provide_query_stub();
         $query .= "FROM processing_jobs WHERE experiment_id = {$experiment_id} AND sample_id = '" . $experiment->samples[$i]->id() . "' AND region_id = 0 AND image_id = 0";
 $specified_all_experiments = @$query_string['experiment_id'] === "all";
 $specified_hidden_experiments = @$query_string['hidden'] == "1";
 $specified_experiment_list = isset($query_string['experiment_list']);
 $specified_all_samples = @$query_string['sample_id'] === "all";
 $specified_all_regions = @$query_string['region_id'] === "all";
 $all_new = @$query_string['all_new'] == '1';
 $include_censored = @(int) $query_string['include_censored'];
 $live_dangerously = @$query_string['live_dangerously'] === "1";
 $experiment_list = @$query_string['experiment_list'];
 $clear_region = @$_POST["clear_region"];
 $delete_sample_images = @$_POST["delete_sample_images"];
 $job_specified = false;
 if ($job_id != 0) {
     $job_specified = true;
     $specified_job = new ns_processing_job();
     $query = $specified_job->provide_query_stub();
     $query .= " FROM processing_jobs WHERE processing_jobs.id = " . $job_id;
     $sql->get_row($query, $result);
     if (sizeof($result) == 0) {
         throw new ns_exception("Could not load job id " . $job_id . " from database");
     }
     $specified_job->load_from_result($result[0]);
     $experiment_id = (int) $specified_job->experiment_id;
     $sample_id = $specified_job->sample_id;
     $region_id = $specified_job->region_id;
     $image_id = $specified_job->image_id;
     $all_samples = FALSE;
     $all_regions = FALSE;
 } else {
     $experiment_id = $specified_experiment_id;
     $sample_id = $specified_sample_id;