"Week 5 lab", "lab06" => "Week 6 lab", "lab07" => "Week 7 lab", "assign1" => "Assignment 1"); $LINES = array(0 => "None", 1 => "1", 3 => "3", 999 => "All of them"); $MAX_FILE_SIZE = 1024000; // 1MiB $UPLOAD_ERRORS = array (UPLOAD_ERR_INI_SIZE => "The uploaded file exceeded upload_max_filesize dir ective in php.ini", UPLOAD_ERR_FORM_SIZE => "The uploaded file exceeds the MAX_FILE_SIZE direct ive that was specified in the HTML form.", UPLOAD_ERR_PARTIAL => "The uploaded file was only partially uploaded.", UPLOAD_ERR_NO_FILE => "No file was uploaded.", UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder.", UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk.", UPLOAD_ERR_EXTENSION => "A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help."); $sel_task = "assign1"; $sel_lines = "3"; if (isset($_POST['sel_task'])) { $sel_task = $_POST['sel_task']; } if (isset($_POST['sel_lines'])) { $sel_lines = $_POST['sel_lines']; } print_html_header("Style Assessor", "ENGG1811 OpenOffice Basic Style Assessor"); if (isset($_POST['submit'])) { if (isset($_FILES['sel_spreadsheet'])) { if (upload_file($tmpdir, $sel_spreadsheet)) { print_feedback($sel_task, $tmpdir, $sel_spreadsheet, $sel_lines); system("rm -r '$tmpdir'"); } } else { error("You have not uploaded an ods file."); } display_messages(); } else { print_form($sel_task, $sel_lines); } print_html_footer(); function upload_file(&$tmpdir, &$sel_spreadsheet) { global $UPLOAD_ERRORS; $f_name = $_FILES['sel_spreadsheet']['name']; $f_type = $_FILES['sel_spreadsheet']['type']; $f_temp = $_FILES['sel_spreadsheet']['tmp_name']; $f_error = $_FILES['sel_spreadsheet']['error']; $f_size = $_FILES['sel_spreadsheet']['size']; echo "\n"; if ($f_error === UPLOAD_ERR_OK) { $tmpdir = exec("mktemp -d"); if (move_uploaded_file($f_temp, "$tmpdir/$f_name")) { $sel_spreadsheet = "$f_name"; return 1; } else { error("Upload of file $f_name failed.\n"); } } else { error("Upload of file $f_name failed.\nError $f_error. " . $UPLOAD_ERRORS{$f_error}); } return 0; } function print_feedback($sel_task, $tmpdir, $sel_spreadsheet, $sel_lines) { # echo "$sel_task,$tmpdir/$sel_spreadsheet,$sel_lines
\n"; passthru("/bin/sh bin/styleassess.sh -html $sel_task $sel_lines " . escapeshellarg("$tmpdir/$sel_spreadsheet")); ?>

$message

\n"; } function warning($message) { global $warning; $warning .= "

$message

\n"; } function error($message) { global $error; $error .= "

$message

\n"; } function display_messages() { global $information, $warning, $error; if ($information == "" && $warning == "" && $error == "") return; if ($information != "") { echo "
$information
\n"; $information = ""; } if ($warning != "") { echo "
$warning
\n"; $warning = ""; } if ($error != "") { echo "
$error
\n"; $error = ""; } }