Update of /cvsroot/aimmath/moodle/mod/math_assignment
In directory sc8-pr-cvs1:/tmp/cvs-serv9801
Modified Files:
pdfgen.php view.php
Added Files:
setseed.php
Log Message:
further work towards randomized problem sheets
--- NEW FILE: setseed.php ---
<?php // $Id: setseed.php,v 1.1 2003/10/08 19:49:41 gustav_delius Exp $
/// This page uses the form submitted from view.php to set the
/// student's seed
require_once("../../config.php");
require_variable($sheetid);
require_variable($assignment);
require_variable($student);
if (! $math_assignment = get_record("math_assignment", "id", $assignment)) {
error("Course module is incorrect");
}
if (! $course = get_record("course", "id", $math_assignment->course)) {
error("Course is misconfigured");
}
require_login();
if ($course->category) {
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
}
else
$navigation = "";
if (!isstudent($course->id)) {
error("Sorry, you shouldn't be on this page!");
}
if ($seed = get_record("math_assignment_seed", "assignment", $assignment, "student", $student)) {
error("You already entered an ID for this assignment.");
}
print_header("$course->shortname: $math_assignment->name", "$course->fullname",
"$navigation <a href=\"index.php?id=$course->id\">$strmath_assignments</a> -> $math_assignment->name",
"", "", true, update_module_button($cm->id, $course->id, $strmath_assignment), navmenu($course, $cm));
if (!$seed = get_record("math_assignment_seed", "assignment", $assignment, "seed", $sheetid)) {
// The ID number does not exist
notice(get_string("idinvalid", "math_assignment"));
}
// ID number is valid
if (isset($seed->student)) {
// but this ID number was already entered by a
// different student
notice(get_string("idtaken", "math_assignment"));
}
// Everything is o.k., so assign seed to student
set_field($math_assignment_seed, "student", $student, "assignment", $assignment, "seed", $sheetid);
redirect($_SERVER["HTTP_REFERER"]);
?>
Index: pdfgen.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/pdfgen.php,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** pdfgen.php 6 Oct 2003 00:11:07 -0000 1.17
--- pdfgen.php 8 Oct 2003 19:49:41 -0000 1.18
***************
*** 9,12 ****
--- 9,13 ----
optional_variable($type, "problems"); // "problems" or "solutions"
optional_variable($printcopies); // number of randomized copies to send to printer
+ optional_variable($seed, 0); // seed to be passed to AiM. 0 means no seed set.
if (! $site = get_site()) {
***************
*** 30,35 ****
add_to_log($course->id, "math_assignment", "pdfgen", "pdfgen.php?id=$math_assignment->id", $type);
! // check that the request is valid
!
if ($solutions) {
if (time() < $math_assignment->solutiontime and !isteacher($course->id)) {
--- 31,35 ----
add_to_log($course->id, "math_assignment", "pdfgen", "pdfgen.php?id=$math_assignment->id", $type);
! // check that the request is valid
if ($solutions) {
if (time() < $math_assignment->solutiontime and !isteacher($course->id)) {
***************
*** 38,42 ****
}
! // Create temp file names
if (strpos($_ENV["OS"], "Win") === false) {
if (!$tempfile = tempnam("/tmp","pdf")) {
--- 38,52 ----
}
! if ($math_assignment->aimquiz) {
!
! if (!$subject = get_record("math_assignment_subject", "course", $course->id)) {
! error(get_string("noaccess", "math_assignment"));
! }
! if (!$server = get_record("math_assignment_server", "id", $subject->server)) {
! error(get_string("noaccess", "math_assignment"));
! }
! }
!
! // Create temp file names
if (strpos($_ENV["OS"], "Win") === false) {
if (!$tempfile = tempnam("/tmp","pdf")) {
***************
*** 47,61 ****
$tempfile = substr(md5(microtime()), 0, 6);
}
! // if there is an aim quiz load it into $data
! $data = "";
! if ($math_assignment->aimquiz) {
! if (!$subject = get_record("math_assignment_subject", "course", $course->id)) {
! error(get_string("noaccess", "math_assignment"));
}
! if (!$server = get_record("math_assignment_server", "id", $subject->server)) {
! error(get_string("noaccess", "math_assignment"));
}
$postdata = "";
--- 57,137 ----
$tempfile = substr(md5(microtime()), 0, 6);
}
+
+ $errlog = "";
+
! if ($printcopies > 0) {
! $newseed->assignment = $math_assignment->id;
! $newseed->student = NULL;
! for ($i = 1; $i <= $printcopies; $i++) {
! $newseed->seed = mt_rand (10000000,99999999);
! // make sure seed hasn't already been used
! while (get_record("math_assignment_seed", "assignment", $newseed->assignment, "seed", $newseed->seed)) {
! $newseed->seed = mt_rand (10000000,99999999);
! }
! if (!insert_record("math_assignment_seed", $newseed, $returnid=false)) {
! error("Couldn't add $i seed $newseed->seed to database");
! }
! math_assignment_generate_pdf($math_assignment, $course, $subject, $server, $type, $tempfile, $newseed->seed);
! exec("\"c:\\Program Files\\ghostgum\\gsview\\gsview32.exe\" $tempfile.pdf");
! }
! }
! else {
! math_assignment_generate_pdf($math_assignment, $course, $subject, $server, $type, $tempfile, $seed);
! // output of pdf
!
! /* I have just noticed the following in the php documentation on this issue of using Content-disposition headers:
! Note: There is a bug in Microsoft Internet Explorer 4.01 that prevents this from working. There is no workaround.
! There is also a bug in Microsoft Internet Explorer 5.5 that interferes with this, which can be resolved by upgrading
! to Service Pack 2 or later.
! Darn MS!
! One possible way round this might be to use slash arguments with the last arguent 'problems.pdf' when a
! problem sheet is required and 'solutions.pdf' when solutions are required. With luck this might fool IE which seems to
! go by the extension when it ignores the headers. This would need testing in a broken version of IE. */
!
! if ($file = @fopen("$tempfile.pdf", "rb")) { // the 'b' is for compatibility with Windoze
!
! // tell the browser that it is pdf
! header("Content-type: application/pdf");
! if ($solutions)
! header("Content-disposition: inline; filename=solutions.pdf");
! else
! header("Content-disposition: inline; filename=problems.pdf");
! header('Cache-Control: public');
! @fpassthru($file); // chuck all the data direct to the browser and close the handle
! @fclose($file);
}
! else {
! $errlog = htmlentities(implode('', file("$tempfile.log")));
}
+ }
+
+ @unlink("$tempfile.pdf");
+ @unlink("$tempfile.tex");
+ @unlink("$tempfile.aux");
+ @unlink("$tempfile.log");
+ if (isset($imageurls)) {
+ foreach ($imageurls as $key => $imageurl) {
+ @unlink("$tempfile$key.jpg");
+ }
+ }
+
+ if (strlen($errlog) > 0) {
+ error("There was a problem while compiling the tex source!<br>
+ pdflatex wrote the following log file:<br><br>
+ <pre>$errlog</pre>"); // error message
+ }
+
+
+ function math_assignment_generate_pdf($math_assignment, $course, $subject, $server, $type, $tempfile, $seed=0) {
+ // This function generates a sheet of type $type (problem or solution) for the assignment
+ // $math_assignment and stores it in $tempfile.pdf
+
+ global $CFG;
+
+ // if there is an aim quiz load it into $data
+ $data = "";
+ if ($math_assignment->aimquiz) {
$postdata = "";
***************
*** 65,68 ****
--- 141,147 ----
$postdata = math_assignment_add_arg_to_url_data($postdata, "QuizName", $math_assignment->aimquiz);
$postdata = math_assignment_add_arg_to_url_data($postdata, "Password", $subject->password);
+ if ($seed > 0) {
+ $postdata = math_assignment_add_arg_to_url_data($postdata, "QuizSeed", $seed);
+ }
// load the AiM page and grab the result
***************
*** 83,88 ****
}
! // convert images
!
if (preg_match_all("/<img src=\"([^\"]+jpg)\"/",$data,$imagematches)) {
$imageurls = $imagematches[1];
--- 162,166 ----
}
! // convert images
if (preg_match_all("/<img src=\"([^\"]+jpg)\"/",$data,$imagematches)) {
$imageurls = $imagematches[1];
***************
*** 97,108 ****
}
! // split into individual questions
!
$questions = preg_split("/id=\"question(\d+)\"/",$data);
array_shift($questions);
!
! // Add questions to lecturer's tex file or to dummy
!
if ($type == "problems") {
if ($math_assignment->problemsisurl) {
--- 175,183 ----
}
! // split into individual questions
$questions = preg_split("/id=\"question(\d+)\"/",$data);
array_shift($questions);
! // Add questions to lecturer's tex file or to dummy
if ($type == "problems") {
if ($math_assignment->problemsisurl) {
***************
*** 142,151 ****
}
! // Insert course and assignment name if required
$latex = str_replace("\coursename","$course->fullname",$latex);
$latex = str_replace("\assignmentname","$math_assignment->name",$latex);
! // generate pdf file from $latex
!
if (!$fp=fopen("$tempfile.tex","wb"))
error("Sorry, I can't produce the pdf output. Failed to open temporary file.");
--- 217,231 ----
}
! // Insert course and assignment name and sheet id if required
$latex = str_replace("\coursename","$course->fullname",$latex);
$latex = str_replace("\assignmentname","$math_assignment->name",$latex);
+ $latex = str_replace("\aimid","$seed",$latex);
+
+ // Insert problem sheet id
+ if ($type == "problems" and $seed > 0) {
+ $latex = str_replace("\begin{document}", "\begin{document}\begin{flushright}Problem sheet ID: $seed\end{flushright}", $latex);
+ }
! // generate pdf file from $latex
if (!$fp=fopen("$tempfile.tex","wb"))
error("Sorry, I can't produce the pdf output. Failed to open temporary file.");
***************
*** 170,223 ****
exec("$texcommand $tempfile.tex");
}
- // output of pdf
-
- /* We need to remove the temporary file so we had better output it to the browser directly rather than redirecting.
- If we redirect we have no idea when the file is no longer needed. */
- //redirect("$tempfile.pdf");
-
- /* I have just noticed the following in the php documentation on this issue of using Content-disposition headers:
- Note: There is a bug in Microsoft Internet Explorer 4.01 that prevents this from working. There is no workaround.
- There is also a bug in Microsoft Internet Explorer 5.5 that interferes with this, which can be resolved by upgrading
- to Service Pack 2 or later.
- Darn MS!
- One possible way round this might be to use slash arguments with the last arguent 'problems.pdf' when a
- problem sheet is required and 'solutions.pdf' when solutions are required. With luck this might fool IE which seems to
- go by the extension when it ignores the headers. This would need testing in a broken version of IE. */
-
- $errlog = "";
- if ($file = @fopen("$tempfile.pdf", "rb")) { // the 'b' is for compatibility with Windoze
-
- // tell the browser that it is pdf
- header("Content-type: application/pdf");
- if ($solutions)
- header("Content-disposition: inline; filename=solutions.pdf");
- else
- header("Content-disposition: inline; filename=problems.pdf");
- header('Cache-Control: public');
- @fpassthru($file); // chuck all the data direct to the browser and close the handle
- @fclose($file);
- }
- else {
- $errlog = htmlentities(implode('', file("$tempfile.log")));
- }
-
- @unlink("$tempfile.pdf");
- @unlink("$tempfile.tex");
- @unlink("$tempfile.aux");
- @unlink("$tempfile.log");
- if (isset($imageurls)) {
- foreach ($imageurls as $key => $imageurl) {
- @unlink("$tempfile$key.jpg");
- }
- }
-
- if (strlen($errlog) > 0) {
- error("There was a problem while compiling the tex source!<br>
- pdflatex wrote the following log file:<br><br>
- <pre>$errlog</pre>"); // error message
- }
-
-
function math_assignment_aim_to_latex($data,$type) {
--- 250,256 ----
exec("$texcommand $tempfile.tex");
}
+ return true;
+ }
function math_assignment_aim_to_latex($data,$type) {
Index: view.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/view.php,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** view.php 26 Sep 2003 22:23:23 -0000 1.18
--- view.php 8 Oct 2003 19:49:41 -0000 1.19
***************
*** 13,16 ****
--- 13,18 ----
optional_variable($sort, "lastname"); // column to sort
optional_variable($sortdir, "asc"); // direction to sort
+
+ global $USER;
if (! $site = get_site()) {
***************
*** 83,87 ****
if (strcasecmp($sort, "firstname") != 0) { // to improve speed
if (strcasecmp($sort, "totalgrade") != 0)
! $sort = "lastname"; // not valid so use default instead
}
}
--- 85,89 ----
if (strcasecmp($sort, "firstname") != 0) { // to improve speed
if (strcasecmp($sort, "totalgrade") != 0)
! $sort = "lastname"; // not valid so use default instead
}
}
***************
*** 149,159 ****
if ($hasboth) {
if ($student->papergrade >= 0)
! $myxls->InsertNumber($student->papergrade);
else
! $myxls->InsertText("");
if ($student->aimgrade >= 0)
! $myxls->InsertNumber($student->aimgrade);
else
! $myxls->InsertText("");
}
$myxls->InsertNumber($student->totalgrade);
--- 151,161 ----
if ($hasboth) {
if ($student->papergrade >= 0)
! $myxls->InsertNumber($student->papergrade);
else
! $myxls->InsertText("");
if ($student->aimgrade >= 0)
! $myxls->InsertNumber($student->aimgrade);
else
! $myxls->InsertText("");
}
$myxls->InsertNumber($student->totalgrade);
***************
*** 185,192 ****
if ($hasboth) {
if ($student->papergrade >= 0)
! echo "$student->papergrade";
echo "\t";
if ($student->aimgrade >= 0)
! echo "$student->aimgrade";
echo "\t";
}
--- 187,194 ----
if ($hasboth) {
if ($student->papergrade >= 0)
! echo "$student->papergrade";
echo "\t";
if ($student->aimgrade >= 0)
! echo "$student->aimgrade";
echo "\t";
}
***************
*** 227,235 ****
echo "<td>";
if ($student->aimgrade >= 0)
! echo $student->aimgrade;
else echo " ";
echo "</td><td>";
if ($student->papergrade >= 0)
! echo $student->papergrade;
else echo " ";
echo "</td>";
--- 229,237 ----
echo "<td>";
if ($student->aimgrade >= 0)
! echo $student->aimgrade;
else echo " ";
echo "</td><td>";
if ($student->papergrade >= 0)
! echo $student->papergrade;
else echo " ";
echo "</td>";
***************
*** 238,242 ****
echo "<td>";
if ($student->totalgrade > 0)
! echo $student->totalgrade;
else echo " ";
echo "</td>";
--- 240,244 ----
echo "<td>";
if ($student->totalgrade > 0)
! echo $student->totalgrade;
else echo " ";
echo "</td>";
***************
*** 279,285 ****
echo "<b>$strpaper $strgrade :</b> ";
if ($grade->papergrade >= 0)
! echo "$grade->papergrade / $math_assignment->papergrade";
else
! print_string("notmarked", "math_assignment");
echo "<br />";
}
--- 281,287 ----
echo "<b>$strpaper $strgrade :</b> ";
if ($grade->papergrade >= 0)
! echo "$grade->papergrade / $math_assignment->papergrade";
else
! print_string("notmarked", "math_assignment");
echo "<br />";
}
***************
*** 287,302 ****
echo "<b>$strcomputer $strgrade :</b> ";
if ($grade->aimgrade >= 0)
! echo "$grade->aimgrade / $math_assignment->aimgrade";
else
! print_string("notattempted", "math_assignment");
if ($grade->aimoverride > AIMOVR_RESET) {
! echo " (";
! print_string("gradeoverride", "math_assignment");
! echo ")";
}
echo "<br />";
if ($grade->aimcomment)
! echo "<b>" . $course->teacher . " " . get_string("comment", "math_assignment") .
! ":</b> " . nl2br(htmlspecialchars($grade->aimcomment)) . "<br />";
}
if ($hasboth) {
--- 289,304 ----
echo "<b>$strcomputer $strgrade :</b> ";
if ($grade->aimgrade >= 0)
! echo "$grade->aimgrade / $math_assignment->aimgrade";
else
! print_string("notattempted", "math_assignment");
if ($grade->aimoverride > AIMOVR_RESET) {
! echo " (";
! print_string("gradeoverride", "math_assignment");
! echo ")";
}
echo "<br />";
if ($grade->aimcomment)
! echo "<b>" . $course->teacher . " " . get_string("comment", "math_assignment") .
! ":</b> " . nl2br(htmlspecialchars($grade->aimcomment)) . "<br />";
}
if ($hasboth) {
***************
*** 304,310 ****
echo "<b>$strtotal $strgrade :</b> ";
if ($totalgrade >= 0)
! echo " $totalgrade / $totalmax";
else
! print_string("notmarked", "math_assignment");
}
}
--- 306,312 ----
echo "<b>$strtotal $strgrade :</b> ";
if ($totalgrade >= 0)
! echo " $totalgrade / $totalmax";
else
! print_string("notmarked", "math_assignment");
}
}
***************
*** 316,320 ****
if ($subject = get_record("math_assignment_subject", "course", $course->id)) {
if ($server = get_record("math_assignment_server", "id", $subject->server))
! $zonelink = $server->password;
}
echo math_assignment_get_admin_links($cm, $math_assignment, $zonelink, "right");
--- 318,322 ----
if ($subject = get_record("math_assignment_subject", "course", $course->id)) {
if ($server = get_record("math_assignment_server", "id", $subject->server))
! $zonelink = $server->password;
}
echo math_assignment_get_admin_links($cm, $math_assignment, $zonelink, "right");
***************
*** 342,388 ****
$picture = print_user_picture($student->userid, $course->id, $student->picture, false, true);
if ($student->papergrade >= 0)
! $papergrade = $student->papergrade;
else
! $papergrade = "";
$papergrade = "<input type=\"text\" name=\"$student->userid\" size=\"10\" maxlength=\"10\" value=\"$papergrade\" tabindex=\"$i\" />";
if ($student->aimgrade >= 0)
! $aimgrade = $student->aimgrade;
else
! $aimgrade = "";
if ($student->aimoverride > AIMOVR_RESET) {
! $edited = "$stredited (";
! $editedclose = ")";
}
else if ($student->aimcomment) {
! $edited = "$strcommented (";
! $editedclose = ")";
}
else {
! $edited = "";
! $editedclose = "";
}
$email = "<a href=\"mailto:$student->email\">";
if ($CFG->math_assignment_default_email_host) {
! if (preg_match("/^(.*)@(.*)$/", $student->email, $matches)) {
! if (strcmp($matches[2], $CFG->math_assignment_default_email_host) == 0)
! $email .= "$matches[1]</a>";
! else
! $email .= "$student->email</a>";
! }
! else
! $email .= "$student->email</a>";
}
else
! $email .= "$student->email</a>";
if ($hasboth)
! $table->data[] = array($picture, $student->firstname, $student->lastname, $email, $papergrade,
! "$aimgrade $edited<a href=\"editgrade.php?id=$math_assignment->id&userid=$student->userid\">$stredit</a>$editedclose", $student->totalgrade);
else if ($haspaper)
! $table->data[] = array($picture, $student->firstname, $student->lastname, $email, $papergrade);
else if ($hasaim)
! $table->data[] = array($picture, $student->firstname, $student->lastname, $email,
! "$aimgrade $edited<a href=\"editgrade.php?id=$math_assignment->id&userid=$student->userid\">$stredit</a>$editedclose");
$i++;
--- 344,390 ----
$picture = print_user_picture($student->userid, $course->id, $student->picture, false, true);
if ($student->papergrade >= 0)
! $papergrade = $student->papergrade;
else
! $papergrade = "";
$papergrade = "<input type=\"text\" name=\"$student->userid\" size=\"10\" maxlength=\"10\" value=\"$papergrade\" tabindex=\"$i\" />";
if ($student->aimgrade >= 0)
! $aimgrade = $student->aimgrade;
else
! $aimgrade = "";
if ($student->aimoverride > AIMOVR_RESET) {
! $edited = "$stredited (";
! $editedclose = ")";
}
else if ($student->aimcomment) {
! $edited = "$strcommented (";
! $editedclose = ")";
}
else {
! $edited = "";
! $editedclose = "";
}
$email = "<a href=\"mailto:$student->email\">";
if ($CFG->math_assignment_default_email_host) {
! if (preg_match("/^(.*)@(.*)$/", $student->email, $matches)) {
! if (strcmp($matches[2], $CFG->math_assignment_default_email_host) == 0)
! $email .= "$matches[1]</a>";
! else
! $email .= "$student->email</a>";
! }
! else
! $email .= "$student->email</a>";
}
else
! $email .= "$student->email</a>";
if ($hasboth)
! $table->data[] = array($picture, $student->firstname, $student->lastname, $email, $papergrade,
! "$aimgrade $edited<a href=\"editgrade.php?id=$math_assignment->id&userid=$student->userid\">$stredit</a>$editedclose", $student->totalgrade);
else if ($haspaper)
! $table->data[] = array($picture, $student->firstname, $student->lastname, $email, $papergrade);
else if ($hasaim)
! $table->data[] = array($picture, $student->firstname, $student->lastname, $email,
! "$aimgrade $edited<a href=\"editgrade.php?id=$math_assignment->id&userid=$student->userid\">$stredit</a>$editedclose");
$i++;
***************
*** 405,412 ****
echo "</td></tr></table></form>\n";
if (!$math_assignment->papersheetsreturned) {
! echo "<table border=\"0\" align=\"center\"><tr><td>";
! $options = array("id"=>$cm->id);
! print_single_button("email.php", $options, get_string("emailstudents", "math_assignment"));
! echo "</td></tr></table>\n";
}
}
--- 407,414 ----
echo "</td></tr></table></form>\n";
if (!$math_assignment->papersheetsreturned) {
! echo "<table border=\"0\" align=\"center\"><tr><td>";
! $options = array("id"=>$cm->id);
! print_single_button("email.php", $options, get_string("emailstudents", "math_assignment"));
! echo "</td></tr></table>\n";
}
}
***************
*** 434,446 ****
}
}
! else {
! echo math_assignment_get_file_links($math_assignment, "center");
! if ($hasaim) {
! if ($grade->aimoverride > AIMOVR_RESET) {
! echo "<p align=\"center\">";
! print_string("gradeoverridemsg", "math_assignment");
! echo "</p>";
}
- echo "<p align=\"center\"><a href=\"aimpage.php?id=$cm->id\">" . get_string("viewquiz", "math_assignment") . "</a></p>";
}
}
--- 436,460 ----
}
}
! else { // This is for the student
! // First get seed
! if (!$seed = get_record("math_assignment_seed", "assignment", $math_assignment->id, "student", $USER->id)) {
! // No seed set yet, so ask the student
! echo "<form action=\"setseed.php\" method=\"GET\">\n";
! echo get_string("enterid", "math_assignment");
! echo "<input type=\"text\" name=\"sheetid\" size=\"8\" maxlength=\"8\" />\n";
! echo "<input type=\"hidden\" name=\"assignment\" value=\"$math_assignment->id\" />\n";
! echo "<input type=\"hidden\" name=\"student\" value=\"$USER->id\" />\n";
! echo "<input type=\"submit\" value=\"Submit\"><br />";
! }
! else {
! echo math_assignment_get_file_links($math_assignment, "center");
! if ($hasaim) {
! if ($grade->aimoverride > AIMOVR_RESET) {
! echo "<p align=\"center\">";
! print_string("gradeoverridemsg", "math_assignment");
! echo "</p>";
! }
! echo "<p align=\"center\"><a href=\"aimpage.php?id=$cm->id\">" . get_string("viewquiz", "math_assignment") . "</a></p>";
}
}
}
|