function download($probid, $rank, $file) { global $DB; if ($file == 'image') { $ext = $DB->q('MAYBEVALUE SELECT image_type FROM testcase WHERE probid = %i AND rank = %i', $probid, $rank); $type = 'image/' . $ext; } else { $ext = substr($file, 0, -3); $type = 'text/plain'; } $filename = filebase($prob['probid'], $rank) . $ext; $size = $DB->q("MAYBEVALUE SELECT OCTET_LENGTH({$file})\n\t FROM testcase WHERE probid = %i AND rank = %i", $probid, $rank); // sanity check before we start to output headers if ($size === NULL || !is_numeric($size)) { error("Problem while fetching testcase"); } header("Content-Type: {$type}; name=\"{$filename}\""); header("Content-Disposition: inline; filename=\"{$filename}\""); header("Content-Length: {$size}"); // This may not be good enough for large testsets, but streaming them // directly from the database query result seems overkill to implement. echo $DB->q("VALUE SELECT SQL_NO_CACHE {$file} FROM testcase\n\t WHERE probid = %i AND rank = %i", $probid, $rank); }
echo "<td>" . addFileField("update_" . $inout . "[{$rank}]") . "</td>"; } if ($inout == 'input') { if (IS_ADMIN) { echo "<td rowspan=\"2\"\tclass=\"testsample\" onclick=\"editTcSample({$rank})\">" . addSelect("sample[{$rank}]", array("no", "yes"), $row['sample'], true) . "</td>"; // hide sample dropdown field if javascript is enabled echo "<script type=\"text/javascript\" language=\"JavaScript\">" . "hideTcSample({$rank}, '" . printyn($row['sample']) . "');</script>"; echo "<td class=\"testdesc\" onclick=\"editTcDesc({$rank})\">" . "<textarea id=\"tcdesc_{$rank}\" name=\"description[{$rank}]\" cols=\"50\" rows=\"1\">" . htmlspecialchars($row['description']) . "</textarea></td>" . "<td rowspan=\"2\" class=\"editdel\">" . "<a href=\"delete.php?table=testcase&testcaseid={$row['testcaseid']}&referrer=" . urlencode('testcase.php?probid=' . $probid) . "\">" . "<img src=\"../images/delete.png\" alt=\"delete\"" . " title=\"delete this testcase\" class=\"picto\" /></a></td>"; } else { echo "<td rowspan=\"2\" align=\"testsample\">" . printyn($row['issample']) . "</td>"; echo "<td class=\"testdesc\">" . htmlspecialchars($row['description']) . "</td>"; } } else { echo '<td class="testimage filename">'; if ($row['size_image']) { echo "<a href=\"./testcase.php?probid=" . urlencode($probid) . "&rank={$rank}&fetch=image\">" . filebase($probid, $rank) . $row['image_type'] . "</a>"; } else { echo '<span class="nodata">No image.</span>'; } if (IS_ADMIN) { echo ' ' . addFileField("update_image[{$rank}]"); } echo "</td>"; } echo "</tr>\n"; } } if (count($data) != 0) { echo "</tbody>\n</table>\n"; } if (IS_ADMIN) {