Update of /cvsroot/aimmath/moodle/mod/math_assignment
In directory sc8-pr-cvs1:/tmp/cvs-serv1453/mod/math_assignment
Modified Files:
editgrade.php email.php lib.php pdfgen.php setseed.php
updatepapergrades.php view.php
Log Message:
some minor improvements.
Index: editgrade.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/editgrade.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** editgrade.php 26 Sep 2003 22:23:23 -0000 1.2
--- editgrade.php 10 Nov 2003 12:15:29 -0000 1.3
***************
*** 9,12 ****
--- 9,14 ----
require_variable($id); // quiz id
require_variable($userid); // student user id
+ optional_variable($resetseed, false); // if true the seed for this student is removed from database
+ // so that next time the student accesses the assignment he/she will have to enter a new one.
if (! $site = get_site()) {
***************
*** 31,36 ****
error(get_string("notteacher", "math_assignment"));
}
! if (!$gradeobj = get_record("math_assignment_grades", "assignment", $math_assignment->id, "userid", $userid)) {
$gradeobj->assignment = $math_assignment->id;
$gradeobj->userid = $userid;
--- 33,42 ----
error(get_string("notteacher", "math_assignment"));
}
+
+ if ($resetseed) {
+ delete_records("math_assignment_seed", "student", $userid, "assignment", $math_assignment->id);
+ }
! if (!$gradeobj = get_record("math_assignment_grades", "assignment", $id, "userid", $userid)) {
$gradeobj->assignment = $math_assignment->id;
$gradeobj->userid = $userid;
***************
*** 112,115 ****
--- 118,123 ----
$string->sec = get_string("sec");
$string->secs = get_string("secs");
+ $string->year = get_string("year");
+ $string->route = get_string("route");
$stroldgrade = get_string("oldgrade", "math_assignment");
***************
*** 136,139 ****
--- 144,165 ----
</td>
</tr>
+
+ <?php
+ if ($seedinfo = get_field("math_assignment_seed", "seed", "assignment", $id, "student", $userid)) {
+ ?>
+ <tr valign="top">
+ <td align="right"><p><b><?php echo $strseed; ?>:</b></p></td>
+ <td>
+ <p><?php
+
+ echo "$seedinfo ";
+ echo " <a href=\"editgrade.php?id=$id&userid=$userid&resetseed=true\">Reset seed</a> ";
+ helpbutton ("resetseed", $strresetseed, "math_assignment");
+ ?></p>
+ </td>
+ </tr>
+ <?php
+ }
+ ?>
<tr valign="top">
Index: email.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/email.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** email.php 31 Oct 2003 14:05:59 -0000 1.4
--- email.php 10 Nov 2003 12:15:29 -0000 1.5
***************
*** 11,14 ****
--- 11,16 ----
optional_variable($email, ""); // send email yes or no
optional_variable($message, ""); // message to include in email to student
+
+ global $USER;
if (! $site = get_site()) {
***************
*** 29,32 ****
--- 31,36 ----
require_login($course->id);
+
+ $teacher = $USER;
add_to_log($course->id, "math_assignment", "finalise grades", "view.php?id=$cm->id", "$math_assignment->name");
***************
*** 48,52 ****
foreach ($students as $student) {
// send email to the student
! if (!math_assignment_email_grades($course, $math_assignment, $student, $stremailnotice[$message]))
$failed++;
}
--- 52,56 ----
foreach ($students as $student) {
// send email to the student
! if (!math_assignment_email_grades($course, $math_assignment, $student ,$teacher, $stremailnotice[$message]))
$failed++;
}
Index: lib.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/lib.php,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** lib.php 2 Nov 2003 15:45:30 -0000 1.41
--- lib.php 10 Nov 2003 12:15:29 -0000 1.42
***************
*** 168,173 ****
if ($logs = get_records_select("log", "userid='$user->id' AND module='math_assig'
! AND action='view' AND
! (info='$math_assignment->id' OR info='$math_assignment->name')", "time ASC")) {
$numviews = count($logs);
--- 168,173 ----
if ($logs = get_records_select("log", "userid='$user->id' AND module='math_assig'
! AND action='view' AND
! (info='$math_assignment->id' OR info='$math_assignment->name')", "time ASC")) {
$numviews = count($logs);
***************
*** 188,199 ****
if ($logs = get_records_select("log", "userid='$user->id' AND module='math_assig'
! AND action='view'
! AND (info='$math_assignment->id' OR info='$math_assignment->name')", "time ASC")) {
$numviews = count($logs);
$lastlog = array_pop($logs);
$aimlogs = get_records_select("log", "userid='$user->id' AND module='math_assig'
! AND action='aimpage'
! AND (info='$math_assignment->id' OR info='$math_assignment->name')", "time ASC");
$numaims = count($aimlogs);
--- 188,199 ----
if ($logs = get_records_select("log", "userid='$user->id' AND module='math_assig'
! AND action='view'
! AND (info='$math_assignment->id' OR info='$math_assignment->name')", "time ASC")) {
$numviews = count($logs);
$lastlog = array_pop($logs);
$aimlogs = get_records_select("log", "userid='$user->id' AND module='math_assig'
! AND action='aimpage'
! AND (info='$math_assignment->id' OR info='$math_assignment->name')", "time ASC");
$numaims = count($aimlogs);
***************
*** 559,564 ****
// get max grade for the aim quiz
$max_grade = math_assignment_get_aim_max_grade($math_assignment, $subject, $server);
! if (!$max_grade) // note that this includes the case where $max_grade is zero
! return false;
$math_assignment->aimgrade = $max_grade;
--- 559,565 ----
// get max grade for the aim quiz
$max_grade = math_assignment_get_aim_max_grade($math_assignment, $subject, $server);
! // I have changed this to allow zero AiM grade
! //if (!$max_grade) // note that this includes the case where $max_grade is zero
! // return false;
$math_assignment->aimgrade = $max_grade;
***************
*** 713,719 ****
'$userid = get_field("user", "id", "username", $matches[1]);
$haspicture = get_field("user", "picture", "id", $userid);
! $photo = print_user_picture($userid, 2, $haspicture, true, true);
return "<th align=\"left\">Student photo</th><td>$photo</td></tr><tr>
! <th align=\"left\">Student ID</th>\n<td>$matches[1]</td>";'
), $out
);
--- 714,720 ----
'$userid = get_field("user", "id", "username", $matches[1]);
$haspicture = get_field("user", "picture", "id", $userid);
! $photo = print_user_picture($userid, 1, $haspicture, true, true);
return "<th align=\"left\">Student photo</th><td>$photo</td></tr><tr>
! <th align=\"left\">Student ID</th>\n<td>$matches[1]</td>";'
), $out
);
***************
*** 838,872 ****
if ($students) {
foreach ($students as $key => $student) {
! if ($students[$key] = get_record_sql("SELECT firstname, lastname, email, username, mailformat, picture FROM {$CFG->prefix}user WHERE id = '$key' AND deleted = '0'")) {
! $grade = get_record_sql("SELECT papergrade, aimgrade, aimoverride, aimcomment FROM {$CFG->prefix}math_assignment_grades WHERE assignment = '$math_assignment->id' and userid = '$key'");
! if ($grade) {
! $students[$key]->papergrade = $grade->papergrade;
! $students[$key]->aimgrade = $grade->aimgrade;
! $students[$key]->aimoverride = $grade->aimoverride ;
! $students[$key]->aimcomment = $grade->aimcomment;
! $students[$key]->totalgrade = math_assignment_total_grade($math_assignment, $grade);
! }
! else {
! $students[$key]->papergrade = -1;
! $students[$key]->aimgrade = -1;
! $students[$key]->aimoverride = AIMOVR_OFF ;
! $students[$key]->aimcomment = "";
! $students[$key]->totalgrade = 0;
! }
! }
! else {
! // assume it failed because deleted was not zero
! unset($students[$key]);
! }
}
// sort
if (strcasecmp($sortdir, "desc") == 0)
! $mult = -1;
else
! $mult = 1;
if (strcasecmp($sort, "id") == 0)
! uksort($students, create_function('$a, $b', 'return (($a > $b) ? 1 : -1) * ' . $mult . ';'));
else
! uasort($students, create_function('$a, $b', 'return (($a->' . $sort . ' > $b->' . $sort . ') ? 1 : -1) * ' . $mult . ';'));
}
break;
--- 839,873 ----
if ($students) {
foreach ($students as $key => $student) {
! if ($students[$key] = get_record_sql("SELECT firstname, lastname, email, username, mailformat, picture FROM {$CFG->prefix}user WHERE id = '$key' AND deleted = '0'")) {
! $grade = get_record_sql("SELECT papergrade, aimgrade, aimoverride, aimcomment FROM {$CFG->prefix}math_assignment_grades WHERE assignment = '$math_assignment->id' and userid = '$key'");
! if ($grade) {
! $students[$key]->papergrade = $grade->papergrade;
! $students[$key]->aimgrade = $grade->aimgrade;
! $students[$key]->aimoverride = $grade->aimoverride ;
! $students[$key]->aimcomment = $grade->aimcomment;
! $students[$key]->totalgrade = math_assignment_total_grade($math_assignment, $grade);
! }
! else {
! $students[$key]->papergrade = -1;
! $students[$key]->aimgrade = -1;
! $students[$key]->aimoverride = AIMOVR_OFF ;
! $students[$key]->aimcomment = "";
! $students[$key]->totalgrade = 0;
! }
! }
! else {
! // assume it failed because deleted was not zero
! unset($students[$key]);
! }
}
// sort
if (strcasecmp($sortdir, "desc") == 0)
! $mult = -1;
else
! $mult = 1;
if (strcasecmp($sort, "id") == 0)
! uksort($students, create_function('$a, $b', 'return (($a > $b) ? 1 : -1) * ' . $mult . ';'));
else
! uasort($students, create_function('$a, $b', 'return (($a->' . $sort . ' > $b->' . $sort . ') ? 1 : -1) * ' . $mult . ';'));
}
break;
***************
*** 885,901 ****
}
! function math_assignment_email_grades($course, $math_assignment, $student, $message="") {
/// Function which constructs an email telling the student what their grade is
global $CFG;
- // send from the main teacher
- if (!$teachers = get_records_sql("SELECT u.*,t.role,t.editall FROM {$CFG->prefix}user u, {$CFG->prefix}user_teachers t WHERE t.course = '$course->id' AND t.userid = u.id AND u.deleted = '0' AND t.authority > '0' ORDER BY t.authority ASC"))
- return false;
- $teacher = reset($teachers);
$hasaim = $math_assignment->aimquiz;
$papergrade = min(max((int) $student->papergrade, 0), $math_assignment->papergrade);
! if ($hasaim)
$aimgrade = min(max((int) $student->aimgrade, 0), $math_assignment->aimgrade);
if ($student->mailformat) {
// build html email
--- 886,902 ----
}
! function math_assignment_email_grades($course, $math_assignment, $student, $teacher, $message="") {
/// Function which constructs an email telling the student what their grade is
global $CFG;
$hasaim = $math_assignment->aimquiz;
$papergrade = min(max((int) $student->papergrade, 0), $math_assignment->papergrade);
! if ($hasaim) {
$aimgrade = min(max((int) $student->aimgrade, 0), $math_assignment->aimgrade);
+ }
+ if (!($student->papergrade >=0 or $student->aimgrade >=0)) { // Don't send email if no work was completed
+ return true;
+ }
if ($student->mailformat) {
// build html email
***************
*** 1118,1129 ****
if ($math_assignment->papergrade > 0) {
if (!$math_assignment->papersheetsreturned) {
! $papergrade = get_string("notpublished", "math_assignment");
} else if ($grade->papergrade >= 0) {
! $papergrade = "<b>$grade->papergrade / $math_assignment->papergrade</b>";
} else if ($grade->papergrade = -1) {
! $papergrade = "<b>-- / $math_assignment->papergrade</b>";
}
if ($math_assignment->timedue > time()) {
! $papergrade = $stropen;
}
}
--- 1119,1130 ----
if ($math_assignment->papergrade > 0) {
if (!$math_assignment->papersheetsreturned) {
! $papergrade = get_string("notpublished", "math_assignment");
} else if ($grade->papergrade >= 0) {
! $papergrade = "<b>$grade->papergrade / $math_assignment->papergrade</b>";
} else if ($grade->papergrade = -1) {
! $papergrade = "<b>-- / $math_assignment->papergrade</b>";
}
if ($math_assignment->timedue > time()) {
! $papergrade = $stropen;
}
}
***************
*** 1133,1146 ****
if ($math_assignment->aimgrade > 0) {
if ($grade->aimgrade >= 0) {
! $aimgrade = "<b>$grade->aimgrade / $math_assignment->aimgrade</b>";
} else {
! $aimgrade = "<b>-- / $math_assignment->aimgrade</b>";
}
// show aimgrade in grey if quiz has not closed yet
if ($math_assignment->timedue > time()) {
! $aimgrade = "<span style=\"color: silver \">$aimgrade</span>";
}
if ($grade->aimoverride > AIMOVR_RESET) {
! $aimgrade .= " (" . get_string("gradeoverride", "math_assignment") . ")";
}
}
--- 1134,1147 ----
if ($math_assignment->aimgrade > 0) {
if ($grade->aimgrade >= 0) {
! $aimgrade = "<b>$grade->aimgrade / $math_assignment->aimgrade</b>";
} else {
! $aimgrade = "<b>-- / $math_assignment->aimgrade</b>";
}
// show aimgrade in grey if quiz has not closed yet
if ($math_assignment->timedue > time()) {
! $aimgrade = "<span style=\"color: silver \">$aimgrade</span>";
}
if ($grade->aimoverride > AIMOVR_RESET) {
! $aimgrade .= " (" . get_string("gradeoverride", "math_assignment") . ")";
}
}
***************
*** 1164,1170 ****
if ($solurl) {
if ($timenow > $math_assignment->timedue)
! $solutions = "<a href=\"$solurl\" target=\"solutions\">$strviewsolutions</a>";
else
! $solutions = "";
}
else
--- 1165,1171 ----
if ($solurl) {
if ($timenow > $math_assignment->timedue)
! $solutions = "<a href=\"$solurl\" target=\"solutions\">$strviewsolutions</a>";
else
! $solutions = "";
}
else
***************
*** 1205,1210 ****
}
! function copy_from_url($url, $file) { // emulates copy which works with URLSs only in PHP >= 4.3.0
! if (!$handle = fopen($url, "rb"))
return false;
$contents = "";
--- 1206,1211 ----
}
! function math_assignment_copy($origin, $dest) { // emulates copy which works with URLSs only in PHP >= 4.3.0
! if (!$handle = fopen($origin, "rb"))
return false;
$contents = "";
***************
*** 1217,1223 ****
} while(true);
fclose($handle);
! if (!$handle = fopen($file, "wb"))
return false;
! fwrite($handle, $contents, strlen($contents));
fclose($handle);
return true;
--- 1218,1224 ----
} while(true);
fclose($handle);
! if (!$handle = fopen($dest, "wb"))
return false;
! if (!fwrite($handle, $contents, strlen($contents))) error("copying failed");
fclose($handle);
return true;
Index: pdfgen.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/pdfgen.php,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** pdfgen.php 2 Nov 2003 15:45:30 -0000 1.22
--- pdfgen.php 10 Nov 2003 12:15:29 -0000 1.23
***************
*** 10,14 ****
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.
! // This may be overruled by the student's saved seed.
global $USER;
--- 10,14 ----
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.
! // This may be overruled by the student's saved seed.
global $USER;
***************
*** 33,37 ****
// make sure students don't look at solutions before they should
! if (($type == "solutions") and isstudent($course->id) and $math_assignment->solutiontime > time()){
error("You can not view the solutions yet!");
}
--- 33,37 ----
// make sure students don't look at solutions before they should
! if ($type == "solutions" and isstudent($course->id) and $math_assignment->solutiontime > time()){
error("You can not view the solutions yet!");
}
***************
*** 82,86 ****
$tempfile = substr(md5(microtime()), 0, 6);
}
!
$errlog = "";
--- 82,88 ----
$tempfile = substr(md5(microtime()), 0, 6);
}
! $remote = 'ftp://gustav:bek...@ma.../home/gustav/public_html/moodletex/';
! $textopdf = 'http://manor.york.ac.uk/~gustav/moodletex/index.php';
!
$errlog = "";
***************
*** 98,152 ****
error("Couldn't add $i seed $newseed->seed to database");
}
! math_assignment_generate_pdf($math_assignment, $course, $subject, $server, $type, "$tempfile$i", $newseed->seed);
! // I would now like to send the sheet directly to the printer but that does not work for unknown reasons
! // so for now I am satisfied with having the sheet saved on disk and I will send them all to the printer
! // from the file manager later.
//echo exec("gsview32 -p prmaths1.york.ac.uk $tempfile$i.pdf");
echo "Sheet $i generated<br>";
}
}
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 ($type = "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);
! }
! */
! error("<p>Problem and solution sheets are temporarily unavailable. You can however still view the AiM assignment.</p>
! <p>Unfortunately the machine that was supposed to automatically
! generate these sheets has had a hard disk failure. If you did not receive a copy of the problem sheet during the lectures
! please send an email to <a href=\"mailto:gw...@yo...\">gw...@yo...</a>. I may be able to email you the pdf file. </p>");
}
- @unlink("$tempfile.pdf");
-
! 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
--- 100,126 ----
error("Couldn't add $i seed $newseed->seed to database");
}
! math_assignment_generate_latex($math_assignment, $course, $subject, $server, $type, "$tempfile$i", $newseed->seed);
!
//echo exec("gsview32 -p prmaths1.york.ac.uk $tempfile$i.pdf");
echo "Sheet $i generated<br>";
}
+ redirect("$textopdf?tempfile=$tempfile&printcopies=$printcopies");
}
else {
! math_assignment_generate_latex($math_assignment, $course, $subject, $server, $type, $tempfile, $seed);
! redirect("$textopdf?tempfile=$tempfile");
! die;
}
! function math_assignment_generate_latex($math_assignment, $course, $subject, $server, $type, $tempfile, $seed=0) {
! // This function generates a LaTeX sheet of type $type (problem or solution) for the assignment
// $math_assignment and stores it in $tempfile.pdf
! global $CFG, $remote;
// if there is an aim quiz load it into $data
***************
*** 173,177 ****
// attempt to register them automatically
if (!math_assignment_register_with_aim($server, $subject)) {
! error(get_string("nooutput", "math_assignment"), "view.php?id=$cm->id");
}
// retry
--- 147,151 ----
// attempt to register them automatically
if (!math_assignment_register_with_aim($server, $subject)) {
! error(get_string("nooutput", "math_assignment"), "view.php?id=$cm->id");
}
// retry
***************
*** 185,194 ****
$imageurls = $imagematches[1];
foreach ($imageurls as $key => $imageurl) {
! if (!copy_from_url($imageurl,"$tempfile$key.jpg"))
error("Couldn't copy image file to temp directory");
$data = preg_replace("/<img src=\"([^\"]+jpg)\"/",
"<latex>\n\\begin\{center}\n\\pdfimageresolution=150\n\\pdfximage\{$tempfile$key.jpg}\\pdfrefximage\\pdflastximage\n\\end\{center}\n</latex>",
$data,1
);
}
}
--- 159,174 ----
$imageurls = $imagematches[1];
foreach ($imageurls as $key => $imageurl) {
! if (!math_assignment_copy($imageurl,"$remote$tempfile$key.jpg")) {
error("Couldn't copy image file to temp directory");
+ }
$data = preg_replace("/<img src=\"([^\"]+jpg)\"/",
"<latex>\n\\begin\{center}\n\\pdfimageresolution=150\n\\pdfximage\{$tempfile$key.jpg}\\pdfrefximage\\pdflastximage\n\\end\{center}\n</latex>",
$data,1
);
+ if (!$conn = ftp_connect("manor.york.ac.uk")) echo "couldn't open ftp connection";
+ if (!ftp_login($conn, "gustav", "bekieh++")) echo "couldn't log in";
+ if (!ftp_chdir($conn, "/home/gustav/public_html/moodletex")) echo " couldn't change directory";
+ if (!ftp_site($conn, "chmod 0744 /home/gustav/public_html/moodletex/$tempfile$key.jpg")) echo "couldn't chmod";
+ ftp_close($conn);
}
}
***************
*** 207,211 ****
}
}
! else if ($type == "solutions") {
if ($math_assignment->solutionsisurl) {
$texfile = $math_assignment->solutions;
--- 187,191 ----
}
}
! else if ($type == solutions) {
if ($math_assignment->solutionsisurl) {
$texfile = $math_assignment->solutions;
***************
*** 217,224 ****
if (math_assignment_is_tex_file($texfile)) {
! $latex = implode ('', file($texfile));
! // Make sure that inputs and eps files are taken from the course file directory
! $latex = preg_replace("/\\\input[ ]+(?!amstex)/", "\\\input $CFG->dataroot/$course->id/", $latex);
! $latex = preg_replace("/(?<=[\\W])[\\w]+\\.eps/", "$CFG->dataroot/$course->id/\$1", $latex);
// \aimquestion prints a \spericalangle before the aim question
$latex = str_replace('\aimquestion', '$\sphericalangle$ \aimque', $latex);
--- 197,217 ----
if (math_assignment_is_tex_file($texfile)) {
! $latex = implode ('', file($texfile));
!
! // Copy eps files to moodletex
! if (preg_match_all("/(?<=[\\W])[\\w]+\\.eps/" ,$latex, $imagematches)) {
! $images = $imagematches[1];
! foreach ($images as $image) {
! if (!math_assignment_copy("$CFG->dataroot/$course->id/$image", "$remote$tempfile$image")) {
! error("Couldn't copy graphics file $image");
! }
! $latex = preg_replace("/(?<=[\\W])[\\w]+\\.eps/", "$tempfile$image", $latex, 1);
! if (!$conn = ftp_connect("manor.york.ac.uk")) echo "couldn't open ftp connection";
! if (!ftp_login($conn, "gustav", "bekieh++")) echo "couldn't log in";
! if (!ftp_site($conn, "chmod 0744 /home/gustav/public_html/moodletex/$tempfile$image.eps")) echo "couldn't chmod";
! ftp_close($conn);
! }
! }
!
// \aimquestion prints a \spericalangle before the aim question
$latex = str_replace('\aimquestion', '$\sphericalangle$ \aimque', $latex);
***************
*** 245,293 ****
$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.");
fwrite($fp,$latex);
fclose($fp);
! // decide whether to use latex or tex
! if (strpos($latex, "begin{document}")) {
! $texcommand = "pdflatex.bat";
! }
! else {
! $texcommand = "pdftex";
! }
!
! // for Unix work in temp directory
! if (strpos($_ENV["OS"], "Win") === false) {
! exec("cd ".dirname($tempfile)."; $texcommand $tempfile.tex");
! }
! // for Windows unfortunately the cd doesn't work so we work in the
! // current directory
! else {
! $logp=fopen("$tempfile.mog","wb");
! fwrite($logp,shell_exec("$texcommand $tempfile.tex"));
! fclose($logp);
! }
- if (!file_exists("$tempfile.pdf")) {
- $errlog = htmlentities(implode('', file("$tempfile.log")));
- error("There was a problem while compiling the tex source!<br>
- pdflatex wrote the following log file:<br><br>
- <pre>$errlog</pre>");
- }
-
- // delete temporary files
- @unlink("$tempfile.tex");
- @unlink("$tempfile.aux");
- @unlink("$tempfile.log");
- @unlink("$tempfile.mog");
- if (isset($imageurls)) {
- foreach ($imageurls as $key => $imageurl) {
- @unlink("$tempfile$key.jpg");
- }
- }
- return true;
}
--- 238,255 ----
$latex = str_replace("\begin{document}", "\begin{document}\begin{flushright}Problem sheet ID: $seed\end{flushright}", $latex);
}
!
! // Write $latex to moodletex
! if (!$fp=fopen("$remote$tempfile.tex","wb"))
error("Sorry, I can't produce the pdf output. Failed to open temporary file.");
fwrite($fp,$latex);
fclose($fp);
! if (!$conn = ftp_connect("manor.york.ac.uk")) echo "couldn't open ftp connection";
! if (!ftp_login($conn, "gustav", "bekieh++")) echo "couldn't log in";
! if (!ftp_site($conn, "chmod 0744 /home/gustav/public_html/moodletex/{$tempfile}.tex")) echo "couldn't chmod";
! ftp_close($conn);
!
! return $latex;
}
Index: setseed.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/setseed.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** setseed.php 31 Oct 2003 14:05:59 -0000 1.3
--- setseed.php 10 Nov 2003 12:15:30 -0000 1.4
***************
*** 44,49 ****
"", "", true, update_module_button($cm->id, $course->id, $strmath_assignment), navmenu($course, $cm));
! // generate random seed if sheetid = 0
! if ($sheetid == 0) {
$sheetid = mt_rand (10000000,99999999);
// make sure seed hasn't already been used
--- 44,49 ----
"", "", true, update_module_button($cm->id, $course->id, $strmath_assignment), navmenu($course, $cm));
! // generate random seed if sheetid = -1
! if ($sheetid == -1) {
$sheetid = mt_rand (10000000,99999999);
// make sure seed hasn't already been used
Index: updatepapergrades.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/updatepapergrades.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** updatepapergrades.php 31 Oct 2003 14:05:59 -0000 1.3
--- updatepapergrades.php 10 Nov 2003 12:15:30 -0000 1.4
***************
*** 31,43 ****
/// update database with each grade posted
!
foreach ($_POST as $userid => $grade) {
if (ctype_digit("$userid") && (ctype_digit("$grade") || "$grade" === "")) {
! if ($grade < 0)
$grade = 0;
! if ($grade > $math_assignment->papergrade)
$grade = $math_assignment->papergrade;
! if ($grade === "")
$grade = -1;
// load grade record and update
if (!$gradeobj = get_record("math_assignment_grades", "assignment", $math_assignment->id, "userid", $userid)) {
--- 31,48 ----
/// update database with each grade posted
! $warning = 0;
foreach ($_POST as $userid => $grade) {
if (ctype_digit("$userid") && (ctype_digit("$grade") || "$grade" === "")) {
! if ($grade < 0) {
$grade = 0;
! $warning = 1;
! }
! if ($grade > $math_assignment->papergrade) {
$grade = $math_assignment->papergrade;
! $warning = 2;
! }
! if ($grade === "") {
$grade = -1;
+ }
// load grade record and update
if (!$gradeobj = get_record("math_assignment_grades", "assignment", $math_assignment->id, "userid", $userid)) {
***************
*** 50,59 ****
$gradeobj->aimoverride = AIMOVR_OFF;
$gradeobj->aimcomment = "";
! insert_record("math_assignment_grades", $gradeobj, false);
}
else if ($gradeobj->papergrade != $grade) {
$gradeobj->papergrade = $grade;
$gradeobj->papertimemodified = time();
! math_assignment_update_grades($gradeobj);
}
}
--- 55,68 ----
$gradeobj->aimoverride = AIMOVR_OFF;
$gradeobj->aimcomment = "";
! if (!insert_record("math_assignment_grades", $gradeobj, false)) {
! $warning = 3;
! }
}
else if ($gradeobj->papergrade != $grade) {
$gradeobj->papergrade = $grade;
$gradeobj->papertimemodified = time();
! if (!math_assignment_update_grades($gradeobj)) {
! $warning = 4;
! }
}
}
***************
*** 61,64 ****
print_header();
! redirect("$CFG->wwwroot/mod/math_assignment/view.php?q=$math_assignment->id", get_string("changessaved"), 1);
?>
--- 70,80 ----
print_header();
!
! $strnotice = get_string("changessaved");
! $delay = 3;
! if ($warning) {
! $strnotice .= "<br />There have however been some irregularities (such as grades larger than the allowed maximum or negative grades). Please review the grades.";
! $delay = 15;
! }
! redirect("$CFG->wwwroot/mod/math_assignment/view.php?q=$math_assignment->id", $strnotice, $delay);
?>
Index: view.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/math_assignment/view.php,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** view.php 2 Nov 2003 15:45:30 -0000 1.22
--- view.php 10 Nov 2003 12:15:30 -0000 1.23
***************
*** 276,280 ****
$totalmax = $math_assignment->papergrade + $math_assignment->aimgrade;
! if (!isteacher($course->id)) {
if (!$inbox) {
print_simple_box_start("center");
--- 276,280 ----
$totalmax = $math_assignment->papergrade + $math_assignment->aimgrade;
! if (!isteacher()) {
if (!$inbox) {
print_simple_box_start("center");
***************
*** 449,453 ****
}
}
! if ($isstudent) {
echo math_assignment_get_file_links($math_assignment, "center");
if ($hasaim) {
--- 449,453 ----
}
}
! if ($isstudent or isguest()) {
echo math_assignment_get_file_links($math_assignment, "center");
if ($hasaim) {
|