<?php

session_start();
include_once "config.php";
include_once "support.php";
$jobid = san_jobid($_GET['j']);
if ($jobid == "" || !is_dir("{$RESULT_DIR}/{$jobid}") || !is_file("{$RESULT_DIR}/{$jobid}/{$PARAM_FILE}")) {
    $_SESSION['msg'] = "Failed to generate your barcoded files.  Please try again and if that fails contact the system admin.";
    header("location: barcoder.php");
    exit;
}
// load job details from file
$params = array_map("trim", file("{$RESULT_DIR}/{$jobid}/{$PARAM_FILE}"));
$c = array_slice($params, 0, 8);
$bc = array_slice($params, 8, 8);
if (count($c) != 8 || count($bc) != 8) {
    $_SESSION['msg'] = "Failed to generate your barcoded files.  Please try again and if that fails contact the system admin.";
    header("location: barcoder.php");
    exit;
}
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Barcoder results - <?php 
echo $APP_TITLE_SHORT;
?>
</title>
	<link rel="stylesheet" href="css/styles.css">
	<link rel="shortcut icon" href="http://www.latrobe.edu.au/favicon.ico" />
<?php

// This page processes reconstructer requests and redirects to reconstructer_results.php
session_start();
include_once "config.php";
include_once "support.php";
$jobid = san_jobid($_POST['j']);
if ($jobid == "" || !is_dir("{$RESULT_DIR}/{$jobid}") || !is_file("{$RESULT_DIR}/{$jobid}/{$BARCODE_FILE}")) {
    $_SESSION['msg'] = "Failed to find your job details.  Please try again and if that fails contact the system admin.";
    header("location: reconstructer_jobid.php");
    exit;
}
// load job details from file
// $bc = array_map("trim", file("$RESULT_DIR/$jobid/$BARCODE_FILE"));
//
// if (count($bc) == 0)
// {
// $_SESSION['msg'] = "Failed to find your job details.  Please try again and if that fails contact the system admin.";
//
// header("location: reconstructer_jobid.php");
// exit();
// }
// sanitise input parameters
$seq = san_seq($_POST['seq']);
if (strlen($seq) < 4) {
    $_SESSION['msg'] = "Sequence size is too small.  Please enter at least 1 sequence";
    saveVars($_SESSION, $c, $bc, $seq);
    header("location: reconstructer.php?j={$jobid}");
    exit;
}
if (strlen($seq) > $MAX_SEQ_SIZE) {