Update of /cvsroot/aimmath/moodle/mod/aim_quiz
In directory sc8-pr-cvs1:/tmp/cvs-serv23535/mod/aim_quiz
Modified Files:
aimpage.php lib.php view.php
Log Message:
have started work towards pdf output for the quiz
Index: aimpage.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/aim_quiz/aimpage.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** aimpage.php 30 Aug 2003 15:21:31 -0000 1.3
--- aimpage.php 31 Aug 2003 20:44:57 -0000 1.4
***************
*** 14,17 ****
--- 14,19 ----
optional_variable($q); // quiz ID
optional_variable($aimaction); // action to get AiM to perform
+ optional_variable($pdf); // how to display the page
+ // displaystyle=pdf creates a pdf sheet
if (! $site = get_site()) {
***************
*** 142,150 ****
// For testing purposes only:
! // $urlout = htmlspecialchars($server->address . "?" . $postdata);
! // if (!$_POST)
! // echo "<P>Default page : <A href=\"$urlout\">$urlout</A></P>";
! // else
! // echo "<P>Requested page : <A href=\"$urlout\">$urlout</A></P>";
// load the AiM page and grab the result
--- 144,152 ----
// For testing purposes only:
! $urlout = htmlspecialchars($server->address . "?" . $postdata);
! if (!$_POST)
! echo "<P>Default page : <A href=\"$urlout\">$urlout</A></P>";
! else
! echo "<P>Requested page : <A href=\"$urlout\">$urlout</A></P>";
// load the AiM page and grab the result
***************
*** 164,181 ****
}
- // write out relevant parts of it
- $data = aim_quiz_convert_aim_output($aim_quiz, $subject, $data, $server->address, "aimpage.php?id=$cm->id", $grade, $max_grade);
- if (!$data) {
- error(get_string("nooutput", "aim_quiz"), "view.php?id=$cm->id");
- }
-
if (isteacher($course->id)) {
// write admin links
echo "<div align=right>";
echo "<font size=2>";
- helpbutton("analyze_quiz", get_string("analyze_quiz", "aim_quiz"), "aim_quiz");
- echo "<A href=\"aimpage.php?id=$cm->id\">" . get_string("analyze_quiz", "aim_quiz") . "</A><BR>";
helpbutton("try_quiz", get_string("try_quiz", "aim_quiz"), "aim_quiz");
echo "<A href=\"aimpage.php?id=$cm->id&aimaction=try\">" . get_string("try_quiz", "aim_quiz") . "</A><BR />";
helpbutton("admin_quiz", get_string("admin_quiz", "aim_quiz"), "aim_quiz");
echo "<A href=\"aimpage.php?id=$cm->id&aimaction=edit\">" . get_string("admin_quiz", "aim_quiz") . "</A><BR />";
--- 166,177 ----
}
if (isteacher($course->id)) {
// write admin links
echo "<div align=right>";
echo "<font size=2>";
helpbutton("try_quiz", get_string("try_quiz", "aim_quiz"), "aim_quiz");
echo "<A href=\"aimpage.php?id=$cm->id&aimaction=try\">" . get_string("try_quiz", "aim_quiz") . "</A><BR />";
+ helpbutton("analyze_quiz", get_string("analyze_quiz", "aim_quiz"), "aim_quiz");
+ echo "<A href=\"aimpage.php?id=$cm->id\">" . get_string("analyze_quiz", "aim_quiz") . "</A><BR>";
helpbutton("admin_quiz", get_string("admin_quiz", "aim_quiz"), "aim_quiz");
echo "<A href=\"aimpage.php?id=$cm->id&aimaction=edit\">" . get_string("admin_quiz", "aim_quiz") . "</A><BR />";
***************
*** 184,191 ****
echo "</font></div>";
}
!
! print_simple_box_start("center", "", "$THEME->cellcontent", "20");
! echo $data;
! print_simple_box_end();
// update max grade
--- 180,207 ----
echo "</font></div>";
}
!
! if ($pdf) {
! if (aim_quiz_pdf($aim_quiz, $course, $data)) {
! notice( get_string("pdf_ok", "aim_quiz"));
! } else {
! error( get_string("pdf_error", "aim_quiz"));
! }
! } else {
! echo "<div align=right>";
! echo "<font size=2>";
! helpbutton("try_quiz", get_string("pdf_quiz", "aim_quiz"), "aim_quiz");
! echo "<A href=\"aimpage.php?id=$cm->id&aimaction=try&pdf=true\">" . get_string("pdf_quiz", "aim_quiz") . "</A><BR />";
! echo "</font></div>";
!
! // write out relevant parts of it
! $data = aim_quiz_convert_aim_output($aim_quiz, $subject, $data, $server->address, "aimpage.php?id=$cm->id", $grade, $max_grade);
! if (!$data) {
! error(get_string("nooutput", "aim_quiz"), "view.php?id=$cm->id");
! }
!
! print_simple_box_start("center", "", "$THEME->cellcontent", "20");
! echo $data;
! print_simple_box_end();
! }
// update max grade
Index: lib.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/aim_quiz/lib.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** lib.php 30 Aug 2003 15:21:31 -0000 1.3
--- lib.php 31 Aug 2003 20:44:57 -0000 1.4
***************
*** 474,476 ****
--- 474,506 ----
}
+
+ function aim_quiz_pdf($aim_quiz, $course, $data) {
+ /// Function which extracts the latex from the AiM quiz page and converts it to pdf
+ /// This still has to be written, I am only experimenting at the moment.
+
+ $latex = "\\documentclass[12pt]{article}\n
+ \\begin{document}\n
+ \\begin{center}
+ \\bf ".$course->fullname.": ".$aim_quiz->name."
+ \\end{center}";
+
+ $questions = explode("<div class=\"question\"",$data);
+ array_shift($questions);
+ foreach ($questions as $key => $question) {
+ $latex .= "\n\n{\\bf Question:}\n";
+ $chunks = explode("</latex>",$question);
+ array_pop($chunks);
+ foreach ($chunks as $chunk) {
+ preg_match("|<latex>[\s\S]*$|","$chunk",$piece);
+ $latex .= substr($piece[0],7);
+ }
+ }
+ $latex .= "\n\n\\end{document}";
+ $fp=fopen("temp.tex","w");
+ fwrite($fp,$latex);
+ fclose($fp);
+ // $latexoutput = shell_exec("pdflatex temp.tex");
+ return true;
+ }
+
?>
Index: view.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/aim_quiz/view.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** view.php 30 Aug 2003 15:21:31 -0000 1.3
--- view.php 31 Aug 2003 20:44:57 -0000 1.4
***************
*** 167,174 ****
echo "<div align=right>";
echo "<font size=2>";
- helpbutton("analyze_quiz", get_string("analyze_quiz", "aim_quiz"), "aim_quiz");
- echo "<A href=\"aimpage.php?id=$cm->id\">" . get_string("analyze_quiz", "aim_quiz") . "</A><BR>";
helpbutton("try_quiz", get_string("try_quiz", "aim_quiz"), "aim_quiz");
echo "<A href=\"aimpage.php?id=$cm->id&aimaction=try\">" . get_string("try_quiz", "aim_quiz") . "</A><BR />";
helpbutton("admin_quiz", get_string("admin_quiz", "aim_quiz"), "aim_quiz");
echo "<A href=\"aimpage.php?id=$cm->id&aimaction=edit\">" . get_string("admin_quiz", "aim_quiz") . "</A><BR />";
--- 167,174 ----
echo "<div align=right>";
echo "<font size=2>";
helpbutton("try_quiz", get_string("try_quiz", "aim_quiz"), "aim_quiz");
echo "<A href=\"aimpage.php?id=$cm->id&aimaction=try\">" . get_string("try_quiz", "aim_quiz") . "</A><BR />";
+ helpbutton("analyze_quiz", get_string("analyze_quiz", "aim_quiz"), "aim_quiz");
+ echo "<A href=\"aimpage.php?id=$cm->id\">" . get_string("analyze_quiz", "aim_quiz") . "</A><BR>";
helpbutton("admin_quiz", get_string("admin_quiz", "aim_quiz"), "aim_quiz");
echo "<A href=\"aimpage.php?id=$cm->id&aimaction=edit\">" . get_string("admin_quiz", "aim_quiz") . "</A><BR />";
***************
*** 243,247 ****
}
else
! echo "<P align=\"center\"><A href=\"aimpage.php?id=$cm->id\">" . get_string("attemptquiz", "aim_quiz") . "</A></P>";
echo "</TD></TR></TABLE>";
}
--- 243,247 ----
}
else
! echo "<P align=\"center\"><A href=\"aimpage.php?id=$cm->id\">" . get_string("viewquiz", "aim_quiz") . "</A></P>";
echo "</TD></TR></TABLE>";
}
|