[Aimmath-commit] moodle/mod/math_assignment/moodletex index.php,NONE,1.1
Brought to you by:
gustav_delius,
npstrick
|
From: <gus...@us...> - 2003-11-16 18:39:08
|
Update of /cvsroot/aimmath/moodle/mod/math_assignment/moodletex
In directory sc8-pr-cvs1:/tmp/cvs-serv7888/mod/math_assignment/moodletex
Added Files:
index.php
Log Message:
--- NEW FILE: index.php ---
<?PHP
// Generate pdf file from latex
// required parameter tempfile should be the name of the latex file
// optional parameter printcopies should be present only if problem sheets should be
// sent to the printer and is then set to the number of copies required.
if (!$tempfile = $_GET['tempfile']) {
echo "Filename is missing";
die;
}
$texcommand = 'pdflatex';
if (isset($_GET['printcopies'])) {
$printcopies = $_GET['printcopies'];
if ($printcopies < 1 or $printcopies > 200) {
error("You can not print $printcopies copies");
}
for ($i = 1; $i <= $printcopies; $i++) {
// reset time limit for each sheet
set_time_limit(10);
// $errlog = shell_exec("cd /home/gustav/public_html/moodletex; $texcommand $tempfile$i");
$errlog = shell_exec("$texcommand $tempfile$i");
if (!file_exists("$tempfile$i.pdf")) {
echo "There was a problem while compiling the tex source!<br>
pdflatex wrote the following log:<br><br>
<pre>$errlog</pre>";
die;
}
// Now we should send the pdf file through ghostview and on to the printer
@unlink("$tempfile$i.tex");
@unlink("$tempfile$i.aux");
@unlink("$tempfile$i.log");
}
echo "$printcopies pdf sheets have been produced";
die;
}
if (!file_exists("$tempfile.tex")) {
echo "Sorry, I can't produce the pdf output. The specified file does not exist.";
die;
}
/// Now run the tex file through pdflatex
// $errlog = shell_exec("cd /home/gustav/public_html/moodletex; $texcommand $tempfile");
$errlog = shell_exec("$texcommand $tempfile");
if (!file_exists("$tempfile.pdf")) {
echo "There was a problem while compiling the tex source!<br>
pdflatex wrote the following log:<br><br>
<pre>$errlog</pre>";
die;
}
// delete temporary files
@unlink("$tempfile.tex");
@unlink("$tempfile.aux");
@unlink("$tempfile.log");
@unlink("$tempfile.mog");
if (isset($images)) {
$i = 1;
while ($i <= $images) {
@unlink("$tempfile$i.jpg");
$i++;
}
}
// Now redirect browser to the new pdf file.
if ($texmachine == "remote") {
$url = "http://manor.york.ac.uk/~gustav/moodletex/$tempfile.pdf";
} else {
$url = "$tempfile.pdf";
}
echo "<meta http-equiv=\"refresh\" content=\"0; url=$url\" />";
?>
|