From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:59:44
|
Log Message: ----------- New CVS directory structure Added Files: ----------- wwmoodle/wwquestion/bin: setup.pl wwmoodle/wwquestion/moodle/lang/en_utf8: qtype_webwork.php wwmoodle/wwquestion/moodle/lang/en_utf8/help/quiz: webwork.html wwmoodle/wwquestion/moodle/lang/en_utf8/help/webwork: code.html codecheck.html codeheader.html fileheader.html seed.html trials.html webwork.html wwmoodle/wwquestion/moodle/question/type/webwork: config.php display.html edit_webwork_form.php file.php files.php icon.gif locallib.php questiontype.php version.php wwmoodle/wwquestion/moodle/question/type/webwork/db: install.xml wwmoodle/wwquestion/moodle/question/type/webwork/simpletest: sampleProblem.pg testquestiontype.php Revision Data ------------- --- /dev/null +++ wwquestion/moodle/lang/en_utf8/qtype_webwork.php @@ -0,0 +1,33 @@ +<?php // $Id: qtype_webwork.php,v 1.1 2007/09/11 22:52:59 mleventi Exp $ +/** + * The language strings for the QTYPENAME question type. + * + * @copyright © 2006 YOURNAME + * @author YOUREMAILADDRESS + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package YOURPACKAGENAME + *//** */ + +$string['editingwebwork'] = 'Editing WeBWorK'; +$string['webwork'] = 'WeBWorK'; + +$string['error_client_construction'] = 'Error constructing client to Problem Server. Perhaps your WSDL Path is wrong?'; +$string['error_client_call'] = 'Error in communication with the Problem Server.'; + +$string['edit_codeheader'] = 'WeBWorK Code'; +$string['edit_fileheader'] = 'WeBWorK Files'; +$string['edit_optionheader'] = 'WeBWorK Options'; +$string['edit_codecheck'] = 'Code Checking'; + $string['edit_codecheck0'] = 'Turn Off (unadvised)'; + $string['edit_codecheck1'] = 'Reject Problem Seeds w/ Errors (silent)'; + $string['edit_codecheck2'] = 'Reject Question if any Errors exist (strict)'; + $string['edit_codecheck3'] = 'Reject Problem Seeds w/ Errors or Warnings (silent)'; + $string['edit_codecheck4'] = 'Reject Question if any Errors or Warnings exist (strict)'; +$string['edit_codefile'] = 'Question File'; +$string['edit_addcodefiles'] = 'Add More Question Files'; +$string['edit_code'] = 'Code'; +$string['edit_seed'] = 'Seed'; +$string['edit_trials'] = 'Trials'; +// TODO add any other requred strings. + +?> \ No newline at end of file --- /dev/null +++ wwquestion/moodle/lang/en_utf8/help/webwork/webwork.html @@ -0,0 +1,4 @@ +<p align="center"><b>WeBWorK</b></p> + +<p>TODO describe your question type and how to edit it here. This help file is +linked to from the top of the question editing form for you question type.</p> --- /dev/null +++ wwquestion/moodle/question/type/webwork/files.php @@ -0,0 +1,839 @@ +<?php // $Id: files.php,v 1.1 2007/09/11 22:53:00 mleventi Exp $ + +// Manage all uploaded files in a course file area + +// All the Moodle-specific stuff is in this top section +// Configuration and access control occurs here. +// Must define: USER, basedir, baseweb, html_header and html_footer +// USER is a persistent variable using sessions + + require('../../../config.php'); + require($CFG->libdir.'/filelib.php'); + require($CFG->libdir.'/adminlib.php'); + require($CFG->dirroot.'/question/type/webwork/locallib.php'); + + $id = required_param('id', PARAM_INT); + $qid = required_param('qid',PARAM_INT); + $file = optional_param('file', '', PARAM_PATH); + $wdir = optional_param('wdir', '', PARAM_PATH); + $action = optional_param('action', '', PARAM_ACTION); + $name = optional_param('name', '', PARAM_FILE); + $oldname = optional_param('oldname', '', PARAM_FILE); + $choose = optional_param('choose', '', PARAM_FILE); //in fact it is always 'formname.inputname' + $userfile= optional_param('userfile','',PARAM_FILE); + $save = optional_param('save', 0, PARAM_BOOL); + $text = optional_param('text', '', PARAM_RAW); + $confirm = optional_param('confirm', 0, PARAM_BOOL); + + if ($choose) { + if (count(explode('.', $choose)) > 2) { + print_error('Incorrect format for choose parameter'); + } + } + + if (! $course = get_record("course", "id", $id) ) { + print_error("That's an invalid course id"); + } + + //access is needed + require_login($course); + require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id)); + + + $baseweb = $CFG->wwwroot; + $basedir = $CFG->dataroot; + $userid = $USER->id; + + if($qid == -1) { + $searcher = webwork_get_tmp_path(); + } else { + $searcher = webwork_get_wwquestion_path($qid); + } + $wdir = str_replace($searcher,'',$wdir); + + if ($wdir == '') { + $wdir = "/"; + } + + if ($wdir{0} != '/') { + $wdir = "/".$wdir; + } + + //prefix the filepath + if($qid == -1) { + webwork_make_tmp_dir(); + $wdir = webwork_get_tmp_path() . $wdir; + } else { + if(!$question = get_record('question_webwork','id',$qid)) { + print_error("That's an invalid question id."); + } + $wdir = webwork_get_wwquestion_path($qid) . $wdir; + } + + if (!is_dir($basedir.$wdir)) { + //html_header($course, $wdir); + print_error("Requested directory does not exist."); + } + print_header(); + switch ($action) { + + case "upload": + //html_header($course, $wdir); + require_once($CFG->dirroot.'/lib/uploadlib.php'); + + if ($save and confirm_sesskey()) { + $course->maxbytes = 0; // We are ignoring course limits + $um = new upload_manager('userfile',false,false,$course,false,0); + $dir = "$basedir$wdir"; + if ($um->process_file_uploads($dir)) { + notify(get_string('uploadedfile')); + } + // um will take care of error reporting. + displaydir($wdir); + } else { + $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes); + $filesize = display_size($upload_max_filesize); + + $struploadafile = get_string("uploadafile"); + $struploadthisfile = get_string("uploadthisfile"); + $strmaxsize = get_string("maxsize", "", $filesize); + $strcancel = get_string("cancel"); + + echo "<p>$struploadafile ($strmaxsize) --> <b>$wdir</b></p>"; + echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"files.php\">"; + echo "<div>"; + echo "<table><tr><td colspan=\"2\">"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false); + echo " </td></tr></table>"; + echo " <input type=\"submit\" name=\"save\" value=\"$struploadthisfile\" />"; + echo "</div>"; + echo "</form>"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"$strcancel\" />"; + echo "</div>"; + echo "</form>"; + } + //html_footer(); + break; + + case "delete": + if ($confirm and confirm_sesskey()) { + //html_header($course, $wdir); + if (!empty($USER->filelist)) { + foreach ($USER->filelist as $file) { + $fullfile = $basedir.'/'.$file; + if (! fulldelete($fullfile)) { + echo "<br />Error: Could not delete: $fullfile"; + } + } + } + clearfilelist(); + displaydir($wdir); + //html_footer(); + + } else { + //html_header($course, $wdir); + + if (setfilelist($_POST)) { + notify(get_string('deletecheckwarning').':'); + print_simple_box_start("center"); + printfilelist($USER->filelist); + print_simple_box_end(); + echo "<br />"; + + require_once($CFG->dirroot.'/mod/resource/lib.php'); + $block = resource_delete_warning($course, $USER->filelist); + + if (empty($CFG->resource_blockdeletingfile) or $block == '') { + $optionsyes = array('id'=>$id, 'qid'=>$qid, 'wdir'=>$wdir, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'choose'=>$choose); + $optionsno = array('id'=>$id, 'qid'=>$qid, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose); + notice_yesno (get_string('deletecheckfiles'), 'files.php', 'files.php', $optionsyes, $optionsno, 'post', 'get'); + } else { + + notify(get_string('warningblockingdelete', 'resource')); + $options = array('id'=>$id, 'qid'=>$qid, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose); + print_continue("files.php?id=$id&qid=$qid&wdir=$wdir&action=cancel&choose=$choose"); + } + } else { + displaydir($wdir); + } + //html_footer(); + } + break; + + case "move": + //html_header($course, $wdir); + if (($count = setfilelist($_POST)) and confirm_sesskey()) { + $USER->fileop = $action; + $USER->filesource = $wdir; + echo "<p class=\"centerpara\">"; + print_string("selectednowmove", "moodle", $count); + echo "</p>"; + } + displaydir($wdir); + //html_footer(); + break; + + case "paste": + //html_header($course, $wdir); + if (isset($USER->fileop) and ($USER->fileop == "move") and confirm_sesskey()) { + foreach ($USER->filelist as $file) { + $shortfile = basename($file); + $oldfile = $basedir.'/'.$file; + $newfile = $basedir.$wdir."/".$shortfile; + if (!rename($oldfile, $newfile)) { + echo "<p>Error: $shortfile not moved</p>"; + } + } + } + clearfilelist(); + displaydir($wdir); + //html_footer(); + break; + + case "rename": + if (($name != '') and confirm_sesskey()) { + //html_header($course, $wdir); + $name = clean_filename($name); + if (file_exists($basedir.$wdir."/".$name)) { + echo "<center>Error: $name already exists!</center>"; + } else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) { + echo "<p align=\"center\">Error: could not rename $oldname to $name</p>"; + } else { + //file was renamed now update resources if needed + require_once($CFG->dirroot.'/mod/resource/lib.php'); + resource_renamefiles($course, $wdir, $oldname, $name); + } + displaydir($wdir); + + } else { + $strrename = get_string("rename"); + $strcancel = get_string("cancel"); + $strrenamefileto = get_string("renamefileto", "moodle", $file); + //html_header($course, $wdir, "form.name"); + echo "<p>$strrenamefileto:</p>"; + echo "<table><tr><td>"; + echo "<form action=\"files.php\" method=\"post\">"; + echo "<fieldset class=\"invisiblefieldset\">"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"rename\" />"; + echo " <input type=\"hidden\" name=\"oldname\" value=\"$file\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"$file\" />"; + echo " <input type=\"submit\" value=\"$strrename\" />"; + echo "</fieldset>"; + echo "</form>"; + echo "</td><td>"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"$strcancel\" />"; + echo "</div>"; + echo "</form>"; + echo "</td></tr></table>"; + } + //html_footer(); + break; + + case "makedir": + if (($name != '') and confirm_sesskey()) { + //html_header($course, $wdir); + $name = clean_filename($name); + if (file_exists("$basedir$wdir/$name")) { + echo "Error: $name already exists!"; + } else if (! make_upload_directory("$wdir/$name")) { + echo "Error: could not create $name"; + } + displaydir($wdir); + + } else { + $strcreate = get_string("create"); + $strcancel = get_string("cancel"); + $strcreatefolder = get_string("createfolder", "moodle", $wdir); + //html_header($course, $wdir, "form.name"); + echo "<p>$strcreatefolder:</p>"; + echo "<table><tr><td>"; + echo "<form action=\"files.php\" method=\"post\">"; + echo "<fieldset class=\"invisiblefieldset\">"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />"; + echo " <input type=\"text\" name=\"name\" size=\"35\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + echo " <input type=\"submit\" value=\"$strcreate\" />"; + echo "</fieldset>"; + echo "</form>"; + echo "</td><td>"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"$strcancel\" />"; + echo "</div>"; + echo "</form>"; + echo "</td></tr></table>"; + } + //html_footer(); + break; + + case "edit": + //html_header($course, $wdir); + if (($text != '') and confirm_sesskey()) { + $fileptr = fopen($basedir.'/'.$file,"w"); + $text = preg_replace('/\x0D/', '', $text); // http://moodle.org/mod/forum/discuss.php?d=38860 + fputs($fileptr, stripslashes($text)); + fclose($fileptr); + displaydir($wdir); + + } else { + $streditfile = get_string("edit", "", "<b>$file</b>"); + $fileptr = fopen($basedir.'/'.$file, "r"); + $contents = fread($fileptr, filesize($basedir.'/'.$file)); + fclose($fileptr); + + if (mimeinfo("type", $file) == "text/html") { + $usehtmleditor = can_use_html_editor(); + } else { + $usehtmleditor = false; + } + $usehtmleditor = false; // Always keep it off for now + + print_heading("$streditfile"); + + echo "<table><tr><td colspan=\"2\">"; + echo "<form action=\"files.php\" method=\"post\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"file\" value=\"$file\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"edit\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + print_textarea($usehtmleditor, 25, 80, 680, 400, "text", $contents); + echo "</td></tr><tr><td>"; + echo " <input type=\"submit\" value=\"".get_string("savechanges")."\" />"; + echo "</div>"; + echo "</form>"; + echo "</td><td>"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />"; + echo "</div>"; + echo "</form>"; + echo "</td></tr></table>"; + + if ($usehtmleditor) { + use_html_editor(); + } + + + } + //html_footer(); + break; + + case "zip": + if (($name != '') and confirm_sesskey()) { + //html_header($course, $wdir); + $name = clean_filename($name); + + $files = array(); + foreach ($USER->filelist as $file) { + $files[] = "$basedir/$file"; + } + + if (!zip_files($files,"$basedir$wdir/$name")) { + error(get_string("zipfileserror","error")); + } + + clearfilelist(); + displaydir($wdir); + + } else { + //html_header($course, $wdir, "form.name"); + + if (setfilelist($_POST)) { + echo "<p align=\"center\">".get_string("youareabouttocreatezip").":</p>"; + print_simple_box_start("center"); + printfilelist($USER->filelist); + print_simple_box_end(); + echo "<br />"; + echo "<p align=\"center\">".get_string("whattocallzip")."</p>"; + echo "<table><tr><td>"; + echo "<form action=\"files.php\" method=\"post\">"; + echo "<fieldset class=\"invisiblefieldset\">"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"zip\" />"; + echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"new.zip\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + echo " <input type=\"submit\" value=\"".get_string("createziparchive")."\" />"; + echo "<fieldset>"; + echo "</form>"; + echo "</td><td>"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />"; + echo "</div>"; + echo "</form>"; + echo "</td></tr></table>"; + } else { + displaydir($wdir); + clearfilelist(); + } + } + //html_footer(); + break; + + case "unzip": + //html_header($course, $wdir); + if (($file != '') and confirm_sesskey()) { + $strok = get_string("ok"); + $strunpacking = get_string("unpacking", "", $file); + + echo "<p align=\"center\">$strunpacking:</p>"; + + $file = basename($file); + + if (!unzip_file("$basedir$wdir/$file")) { + error(get_string("unzipfileserror","error")); + } + + echo "<div style=\"text-align:center\"><form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"$strok\" />"; + echo "</div>"; + echo "</form>"; + echo "</div>"; + } else { + displaydir($wdir); + } + //html_footer(); + break; + + case "listzip": + //html_header($course, $wdir); + if (($file != '') and confirm_sesskey()) { + $strname = get_string("name"); + $strsize = get_string("size"); + $strmodified = get_string("modified"); + $strok = get_string("ok"); + $strlistfiles = get_string("listfiles", "", $file); + + echo "<p align=\"center\">$strlistfiles:</p>"; + $file = basename($file); + + include_once("$CFG->libdir/pclzip/pclzip.lib.php"); + $archive = new PclZip(cleardoubleslashes("$basedir$wdir/$file")); + if (!$list = $archive->listContent(cleardoubleslashes("$basedir$wdir"))) { + notify($archive->errorInfo(true)); + + } else { + echo "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=\"640\" class=\"files\">"; + echo "<tr class=\"file\"><th align=\"left\" class=\"header name\" scope=\"col\">$strname</th><th align=\"right\" class=\"header size\" scope=\"col\">$strsize</th><th align=\"right\" class=\"header date\" scope=\"col\">$strmodified</th></tr>"; + foreach ($list as $item) { + echo "<tr>"; + print_cell("left", s($item['filename']), 'name'); + if (! $item['folder']) { + print_cell("right", display_size($item['size']), 'size'); + } else { + echo "<td> </td>"; + } + $filedate = userdate($item['mtime'], get_string("strftimedatetime")); + print_cell("right", $filedate, 'date'); + echo "</tr>"; + } + echo "</table>"; + } + echo "<br /><center><form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"$strok\" />"; + echo "</div>"; + echo "</form>"; + echo "</center>"; + } else { + displaydir($wdir); + } + //html_footer(); + break; + + case "restore": + //html_header($course, $wdir); + if (($file != '') and confirm_sesskey()) { + echo "<p align=\"center\">".get_string("youaregoingtorestorefrom").":</p>"; + print_simple_box_start("center"); + echo $file; + print_simple_box_end(); + echo "<br />"; + echo "<p align=\"center\">".get_string("areyousuretorestorethisinfo")."</p>"; + $restore_path = "$CFG->wwwroot/backup/restore.php"; + notice_yesno (get_string("areyousuretorestorethis"), + $restore_path."?id=".$id."&qid=".$qid."&file=".cleardoubleslashes($id.$wdir."/".$file)."&method=manual", + "files.php?id=$id&qid=$qid&wdir=$wdir&action=cancel"); + } else { + displaydir($wdir); + } + //html_footer(); + break; + + case "cancel": + clearfilelist(); + + default: + //html_header($course, $wdir); + displaydir($wdir); + //html_footer(); + break; +} + + +/// FILE FUNCTIONS /////////////////////////////////////////////////////////// + + +function setfilelist($VARS) { + global $USER; + + $USER->filelist = array (); + $USER->fileop = ""; + + $count = 0; + foreach ($VARS as $key => $val) { + if (substr($key,0,4) == "file") { + $count++; + $val = rawurldecode($val); + $USER->filelist[] = clean_param($val, PARAM_PATH); + } + } + return $count; +} + +function clearfilelist() { + global $USER; + + $USER->filelist = array (); + $USER->fileop = ""; +} + + +function printfilelist($filelist) { + global $CFG, $basedir; + + $strfolder = get_string("folder"); + $strfile = get_string("file"); + + foreach ($filelist as $file) { + if (is_dir($basedir.'/'.$file)) { + echo "<img src=\"$CFG->pixpath/f/folder.gif\" class=\"icon\" alt=\"$strfolder\" /> $file<br />"; + $subfilelist = array(); + $currdir = opendir($basedir.'/'.$file); + while (false !== ($subfile = readdir($currdir))) { + if ($subfile <> ".." && $subfile <> ".") { + $subfilelist[] = $file."/".$subfile; + } + } + printfilelist($subfilelist); + + } else { + $icon = mimeinfo("icon", $file); + echo "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" /> $file<br />"; + } + } +} + + +function print_cell($alignment='center', $text=' ', $class='') { + if ($class) { + $class = ' class="'.$class.'"'; + } + echo '<td align="'.$alignment.'" style="white-space:nowrap "'.$class.'>'.$text.'</td>'; +} + +function displaydir ($wdir) { +// $wdir == / or /a or /a/b/c/d etc + + global $basedir; + global $id; + global $qid; + global $USER, $CFG; + global $choose; + + $fullpath = $basedir.$wdir; + $dirlist = array(); + + $directory = opendir($fullpath); // Find all files + while (false !== ($file = readdir($directory))) { + if ($file == "." || $file == "..") { + continue; + } + + if (is_dir($fullpath."/".$file)) { + $dirlist[] = $file; + } else { + $filelist[] = $file; + } + } + closedir($directory); + + $strname = get_string("name"); + $strsize = get_string("size"); + $strmodified = get_string("modified"); + $straction = get_string("action"); + $strmakeafolder = get_string("makeafolder"); + $struploadafile = get_string("uploadafile"); + $strselectall = get_string("selectall"); + $strselectnone = get_string("deselectall"); + $strwithchosenfiles = get_string("withchosenfiles"); + $strmovetoanotherfolder = get_string("movetoanotherfolder"); + $strmovefilestohere = get_string("movefilestohere"); + $strdeletecompletely = get_string("deletecompletely"); + $strcreateziparchive = get_string("createziparchive"); + $strrename = get_string("rename"); + $stredit = get_string("edit"); + $strunzip = get_string("unzip"); + $strlist = get_string("list"); + $strrestore= get_string("restore"); + $strchoose = get_string("choose"); + $strfolder = get_string("folder"); + $strfile = get_string("file"); + + + echo "<form action=\"files.php\" method=\"post\" id=\"dirform\">"; + echo "<div>"; + echo '<input type="hidden" name="choose" value="'.$choose.'" />'; + // echo "<hr align=\"center\" noshade=\"noshade\" size=\"1\" />"; + echo "<hr/>"; + echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\" class=\"files\">"; + echo "<tr>"; + echo "<th scope=\"col\"></th>"; + echo "<th class=\"header name\" scope=\"col\">$strname</th>"; + echo "<th class=\"header size\" scope=\"col\">$strsize</th>"; + echo "<th class=\"header date\" scope=\"col\">$strmodified</th>"; + echo "<th class=\"header commands\" scope=\"col\">$straction</th>"; + echo "</tr>\n"; + + if ($wdir != "/") { + $dirlist[] = '..'; + } + + $count = 0; + + if (!empty($dirlist)) { + asort($dirlist); + foreach ($dirlist as $dir) { + echo "<tr class=\"folder\">"; + + if ($dir == '..') { + //only display parent if we are not in root of question + if($qid == -1) { + $tempstr = webwork_get_tmp_path() . '/'; + } else { + $tempstr = WWQUESTION_ROOTDIR . '/' . $qid . '/'; + } + if($tempstr != $wdir) { + $fileurl = rawurlencode(dirname($wdir)); + print_cell(); + // alt attribute intentionally empty to prevent repetition in screen reader + print_cell('left', '<a href="files.php?id='.$id.'&qid='.$qid.'&wdir='.$fileurl.'&choose='.$choose.'"><img src="'.$CFG->pixpath.'/f/parent.gif" class="icon" alt="" /> '.get_string('parentfolder').'</a>', 'name'); + print_cell(); + print_cell(); + print_cell(); + } + + } else { + $count++; + $filename = $fullpath."/".$dir; + $fileurl = rawurlencode($wdir."/".$dir); + $filesafe = rawurlencode($dir); + $filesize = display_size(get_directory_size("$fullpath/$dir")); + $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); + print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox'); + print_cell("left", "<a href=\"files.php?id=$id&qid=$qid&wdir=$fileurl&choose=$choose\"><img src=\"$CFG->pixpath/f/folder.gif\" class=\"icon\" alt=\"$strfolder\" /> ".htmlspecialchars($dir)."</a>", 'name'); + print_cell("right", $filesize, 'size'); + print_cell("right", $filedate, 'date'); + print_cell("right", "<a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands'); + } + + echo "</tr>"; + } + } + + + if (!empty($filelist)) { + asort($filelist); + foreach ($filelist as $file) { + + $icon = mimeinfo("icon", $file); + + $count++; + $filename = $fullpath."/".$file; + $fileurl = trim($wdir, "/")."/$file"; + $filesafe = rawurlencode($file); + $fileurlsafe = rawurlencode($fileurl); + $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); + + $selectfile = trim($fileurl, "/"); + + echo "<tr class=\"file\">"; + + print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox'); + echo "<td align=\"left\" style=\"white-space:nowrap\" class=\"name\">"; + if ($CFG->slasharguments) { + $ffurl = str_replace('//', '/', "/file.php/$fileurl"); + } else { + $ffurl = str_replace('//', '/', "/file.php?file=/$fileurl"); + } + link_to_popup_window ($ffurl, "display", + "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" /> ".htmlspecialchars($file), + 480, 640); + echo "</td>"; + + $file_size = filesize($filename); + print_cell("right", display_size($file_size), 'size'); + print_cell("right", $filedate, 'date'); + + if ($choose) { + $edittext = "<strong><a onclick=\"return set_value('$selectfile')\" href=\"#\">$strchoose</a></strong> "; + } else { + $edittext = ''; + } + + + if ($icon == "text.gif" || $icon == "html.gif") { + $edittext .= "<a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$fileurl&action=edit&choose=$choose\">$stredit</a>"; + } else if ($icon == "zip.gif") { + $edittext .= "<a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$fileurl&action=unzip&sesskey=$USER->sesskey&choose=$choose\">$strunzip</a> "; + $edittext .= "<a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$fileurl&action=listzip&sesskey=$USER->sesskey&choose=$choose\">$strlist</a> "; + if (!empty($CFG->backup_version) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { + $edittext .= "<a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$filesafe&action=restore&sesskey=$USER->sesskey&choose=$choose\">$strrestore</a> "; + } + } + + print_cell("right", "$edittext <a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands'); + + echo "</tr>"; + } + } + echo "</table>"; + echo "<hr />"; + //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; + + echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">"; + echo "<tr><td>"; + echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo '<input type="hidden" name="choose" value="'.$choose.'" />'; + echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" /> "; + echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + $options = array ( + "move" => "$strmovetoanotherfolder", + "delete" => "$strdeletecompletely", + "zip" => "$strcreateziparchive" + ); + if (!empty($count)) { + choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:getElementById('dirform').submit()"); + } + echo "</td></tr></table>"; + echo "</div>"; + echo "</form>"; + echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>"; + echo "<td align=\"center\">"; + if (!empty($USER->fileop) and ($USER->fileop == "move") and ($USER->filesource <> $wdir)) { + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + echo " <input type=\"submit\" value=\"$strmovefilestohere\" />"; + echo "</div>"; + echo "</form>"; + } + echo "</td>"; + echo "<td align=\"right\">"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />"; + echo " <input type=\"submit\" value=\"$strmakeafolder\" />"; + echo "</div>"; + echo "</form>"; + echo "</td>"; + echo "<td align=\"right\">"; + echo "<form action=\"files.php\" method=\"get\">"; //dummy form - alignment only + echo "<fieldset class=\"invisiblefieldset\">"; + echo " <input type=\"button\" value=\"$strselectall\" onclick=\"checkall();\" />"; + echo " <input type=\"button\" value=\"$strselectnone\" onclick=\"uncheckall();\" />"; + echo "</fieldset>"; + echo "</form>"; + echo "</td>"; + echo "<td align=\"right\">"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />"; + echo " <input type=\"submit\" value=\"$struploadafile\" />"; + echo "</div>"; + echo "</form>"; + echo "</td></tr>"; + echo "</table>"; + echo "<hr/>"; + //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; + +} + +?> + --- /dev/null +++ wwquestion/moodle/question/type/webwork/version.php @@ -0,0 +1,5 @@ +<?PHP // $Id: version.php,v 1.1 2007/09/11 22:53:00 mleventi Exp $ + +$plugin->version = 2007090700; +$plugin->requires = 2006032200; +?> \ No newline at end of file --- /dev/null +++ wwquestion/moodle/question/type/webwork/config.php @@ -0,0 +1,13 @@ +<?php + +//Path to the WSDL file on the Webwork Server +define('WWQUESTION_WSDL','ENTER YOUR WSDL PATH HERE','WSDL Path Test'); + +//Leave the rest alone +define('WWQUESTION_PREFIX','/wwquestions'); +define('WWQUESTION_ROOTDIR','/' . SITEID . WWQUESTION_PREFIX); + +define('WWQUESTION_RESPONSE_TIMEOUT',120); + + +?> --- /dev/null +++ wwquestion/moodle/question/type/webwork/questiontype.php @@ -0,0 +1,688 @@ +<?php + +require_once("$CFG->dirroot/question/type/webwork/config.php"); +require_once("$CFG->dirroot/question/type/webwork/locallib.php"); +require_once("$CFG->dirroot/question/type/questiontype.php"); +require_once("$CFG->dirroot/backup/lib.php"); + +/** + * The question type class for the webwork question type. + * + * @copyright © 2007 Matthew Leventi + * @author mle...@gm... + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package webwork_qtype +**/ + +/** + * The webwork question class + * + * Allows webwork questions to be used in Moodle through a new question type. + */ +class webwork_qtype extends default_questiontype { + + ////////////////////////////////////////////////////////////////// + // Functions overriding default_questiontype functions + ////////////////////////////////////////////////////////////////// + + /** + * @desc Required function that names the question type. + * @return string webwork. + */ + function name() { + return 'webwork'; + } + + /** + * @desc Gives the label in the Create Question dropdown. + * @return string WeBWorK + */ + function menu_name() { + return 'WeBWorK'; + } + + /** + * @desc Retrieves information out of question_webwork table and puts it into question object. + * @return boolean to indicate success of failure. + */ + function get_question_options(&$question) { + if (!$record = get_record('question_webwork', 'question', $question->id)) { + notify('Error: Missing question options!'); + return false; + } + $question->trials = $record->trials; + $question->seed = $record->seed; + $question->code = base64_decode($record->code); + $question->codecheck = $record->codecheck; + $question->grading = $record->grading; + //hold onto the ID of the question_webwork record + $question->webworkid = $record->id; + return true; + } + + /** + * @desc Saves the webwork question code and default seed setting into question_webwork. Will recreate all corresponding derived questions. + * @param $question object The question object holding new data. + * @return boolean to indicate success of failure. + */ + function save_question_options($question) { + //determing update or insert + $oldrecord = get_record('question_webwork','question',$question->id); + if(!$oldrecord) { + $isupdate = false; + } else { + $isupdate = true; + } + //set new variables for DB entry + $record = new stdClass; + $record->question = $question->id; + $record->codecheck = $question->codecheck; + $record->code = base64_encode(stripslashes($question->code)); + $record->seed = $question->seed; + $record->trials = $question->trials; + + $results = webwork_qtype::_derivations(); + if(count($results) > 0) { + $record->grading = $results[0]['grading']; + } + + //insert or update question in DB + if($isupdate) { + //update + $record->id = $oldrecord->id; + $errresult = update_record("question_webwork", $record); + if (!$errresult) { + $errresult->error = "Could not update question_webwork record! (id=$record->id)"; + return $errresult; + } + } else { + //insert + $errresult = insert_record("question_webwork", $record); + if (!$errresult) { + $errresult->error = "Could not insert question_webwork record!"; + return $errresult; + } + //set the new record id + $record->id = $errresult; + } + $wwquestionid = $record->id; + //copy the tmp directory to the question one + if($isupdate == false) { + rename(webwork_get_tmp_path_full(),webwork_get_wwquestion_path_full($wwquestionid)); + } + + + //update the derivations + $this->_update_derivations($wwquestionid); + return true; + } + + /** + * @desc Creates an empty response before a student answers a question. This contains the possibly randomized seed for that particular student. Sticky seeds are created here. + * @param $question object The question object. + * @param $state object The state object. + * @param $cmoptions object The cmoptions containing the course ID + * @param $attempt id The attempt ID. + * @return bool true. + */ + function create_session_and_responses(&$question, &$state, $cmoptions, $attempt) { + global $CFG,$USER; + //here we get the derived results for this question + $derivations = get_records("question_webwork_derived","question_webwork",$question->webworkid,'','id'); + if(!$derivations) { + print_error(get_string('error_db_webwork_derived','qtype_webwork')); + return false; + } + + //make sure its not 0 + if(count($derivations) == 0) { + print_error(get_string('error_no_webwork_derived','qtype_webwork')); + return false; + } + + //pick a random question based on time + srand(time()); + $random = rand(0,count($derivations)-1); + $values = array_values($derivations); + $derivationid = $values[$random]->id; + + //get the actual data + $derivation = get_record('question_webwork_derived','id',$derivationid); + //build state + $state->responses['seed'] = $derivation->seed; + $state->responses['derivationid'] = $derivation->id; + return true; + } + + /** + * @desc Deletes question from the question_webwork table + * @param integer $questionid The question being deleted + * @return boolean to indicate success of failure. + */ + function delete_question($questionid) { + //Get wwquestion from DB + $record = get_record('question_webwork','question',$questionid); + $wwquestionid = $record->id; + + //delete DB and Files + webwork_delete_wwquestion_dir($wwquestionid); + delete_records('question_webwork', 'id' , $wwquestionid); + + //delete derivations + webwork_delete_derivations_db($wwquestionid); + return true; + } + + /** + * @desc Decodes and unserializes a students response into the response array carried by state + * @param $question object The question object. + * @param $state object The state that needs to be restored. + * @return bool true. + */ + function restore_session_and_responses(&$question, &$state) { + $serializedresponse = $state->responses['']; + $serializedresponse = base64_decode($serializedresponse); + $responses = unserialize($serializedresponse); + $state->responses = $responses; + return true; + } + + /** + * @desc Serialize, encodes and inserts a students response into the question_states table. + * @param $question object The question object for the session. + * @param $state object The state to save. + * @return true, or error on db change. + */ + function save_session_and_responses(&$question, &$state) { + $responses = $state->responses; + $serialized = serialize($responses); + $serialized = base64_encode($serialized); + return set_field('question_states', 'answer', $serialized, 'id', $state->id); + } + + /** + * @desc Prints the question. Calls question_webwork_derived, and prints out the html associated with derivedid. + * @param $question object The question object to print. + * @param $state object The state of the responses for the question. + * @param $cmoptions object Options containing course ID. + * @param $options object + */ + function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { + global $CFG,$USER; + $readonly = empty($options->readonly) ? '' : 'disabled="disabled"'; + //Formulate question image and text + $questiontext = $this->format_text($question->questiontext, + $question->questiontextformat, $cmoptions); + $image = get_question_image($question, $cmoptions->course); + + $derivationid = $state->responses['derivationid']; + $derivation = get_record('question_webwork_derived','id',$derivationid); + + $unparsedhtml = base64_decode($derivation->html); + + //partial answers + $showPartiallyCorrectAnswers = $question->grading; + + //new array keyed by field + $fieldhash = $state->responses['answers']; + $answerfields = array(); + $parser = new HtmlParser($unparsedhtml); + $currentselect = ""; + while($parser->parse()) { + //change some attributes of html tags for moodle compliance + if ($parser->iNodeType == NODE_TYPE_ELEMENT) { + $nodename = $parser->iNodeName; + $name = $parser->iNodeAttributes['name']; + //handle generic change of node's attribute name + if(($nodename == "INPUT") || ($nodename == "SELECT") || ($nodename == "TEXTAREA")) { + $parser->iNodeAttributes['name'] = 'resp' . $question->id . '_' . $name; + if(($state->event == QUESTION_EVENTGRADE) && (isset($fieldhash[$name]))) { + if($showPartiallyCorrectAnswers) { + $parser->iNodeAttributes['class'] = $parser->iNodeAttributes['class'] . ' ' . question_get_feedback_class($fieldhash[$name]['score']); + } + } + if(!strstr($name,'previous')) { + $answerfields[$name] = $fieldhash[$name]; + } + } + //handle specific change + if($nodename == "INPUT") { + //put submitted value into field + if(isset($fieldhash[$name])) { + $parser->iNodeAttributes['value'] = $fieldhash[$name]['answer']; + } + } else if($nodename == "SELECT") { + $currentselect = $name; + } else if($nodename == "OPTION") { + if($parser->iNodeAttributes['value'] == $fieldhash[$currentselect]['answer']) + $parser->iNodeAttributes['selected'] = '1'; + } else if($nodename == "TEXTAREA") { + } + } + $problemhtml .= $parser->printTag(); + } + + //for the seed form field + $qid = $question->id; + $seed = $state->responses['seed']; + + + + //if the student has answered + include("$CFG->dirroot/question/type/webwork/display.html"); + } + + /** + * @desc Assigns a grade for a student response. Currently a percentage right/total questions. Calls the Webwork Server to evaluate answers. + * @param $question object The question to grade. + * @param $state object The response to the question. + * @param $cmoptions object ... + * @return boolean true. + */ + function grade_responses(&$question, &$state, $cmoptions) { + global $CFG,$USER; + + //get code and seed of the students problem + $code = base64_encode($question->code); + $seed = $state->responses['seed']; + $derivationid = $state->responses['derivationid']; + $wwquestionid = $question->webworkid; + + //get answers & build answer request + $answerarray = array(); + foreach($state->responses as $key => $value) { + array_push($answerarray, array('field' => $key, 'answer'=> $value)); + } + + //build problem request + $problem = array(); + $problem['code'] = $code; + $problem['seed'] = $seed; + $problem['files']= array(); + + //SOAP request + $params = array(); + $params['request'] = $problem; + $params['answers'] = $answerarray; + + //SOAP Call + $client = new webwork_client(); + $response = $client->handler('checkAnswers',$params); + + //process output from soap & calculate score + $answers = $response; + $state->raw_grade = 0; + $total = 0; + $num = 0; + foreach($answers as $answer) { + $total += $answer['score']; + $num++; + } + if($num != 0) { + $state->raw_grade = $total / $num; + } + + //create the directory for this user + webwork_make_derivation_user_dir($wwquestionid,$derivationid,$USER->id); + + // Apply the penalty for this attempt + $state->penalty = $question->penalty * $question->maxgrade; + + // mark the state as graded + $state->event = ($state->event == QUESTION_EVENTCLOSE) ? QUESTION_EVENTCLOSEANDGRADE : QUESTION_EVENTGRADE; + + //put the responses into the state to remember + $state->responses['answers'] = array(); + + foreach ($answers as $answer) { + $html = base64_decode($answer['preview']); + $copyto = webwork_get_derivation_user_path_full($wwquestionid,$derivationid,$USER->id); + $replacer = webwork_get_derivation_user_url($wwquestionid,$derivationid,$USER->id); + $html = webwork_parse_change_ans($html,$replacer,$copyto); + $answer['preview'] = $html; + $state->responses['answers'][$answer['field']] = $answer; + } + return true; + } + + /** + * @desc Comparison of two student responses for the same question. Checks based on seed equality, and response equality. + * Perhaps we could add check on evaluated answer (depends on whether the server is called before this function) + * @param $question object The question object to compare. + * @param $state object The first response. + * @param $teststate object The second response. + * @return boolean, Returns true if the state are equal | false if not. + */ + function compare_responses($question, $state, $teststate) { + if(sizeof($state->responses) != sizeof($teststate->responses)) { + return false; + } + //check values are equal + foreach($state->responses as $key => $value) { + if($value != $teststate->responses[$key]) { + return false; + } + } + return true; + } + + /** + * @desc Gets the correct answers from the SOAP server for the seed in state. Places them into the state->responses array. + * @param $question object The question object. + * @param $state object The state object. + * @return object Object containing the seed,derivedid, and answers. + */ + function get_correct_responses(&$question, &$state) { + //get code and seed of response + $code = base64_encode($question->code); + $seed = $state->responses['seed']; + $derivationid = $state->responses['derivationid']; + + //get empty answers & build answer request + $answerarray = array(); + foreach($state->responses as $key => $value) { + array_push($answerarray, array('field' => $key, 'answer'=> $value)); + } + + //build problem request + $problem = array(); + $problem['code'] = $code; + $problem['seed'] = $seed; + + //SOAP request + $params = array(); + $params['request'] = $problem; + $params['answers'] = $answerarray; + + //SOAP Call + $client = new webwork_client(); + $response = $client->handler('checkAnswers',$params); + + //make the state perfect graded + $state->raw_grade = 1; + $state->event = ($state->event == QUESTION_EVENTCLOSE) ? QUESTION_EVENTCLOSEANDGRADE : QUESTION_EVENTGRADE; + $state->penalty = 0; + + //process correct answers into fields + $answers = $response; + $ret = array(); + $ret['answers'] = array(); + + foreach ($answers as $answer) { + $ret['answers'][$answer['field']] = $answer; + $ret['answers'][$answer['field']]['answer'] = $answer['correct']; + $ret['answers'][$answer['field']]['score'] = 1; + $ret['answers'][$answer['field']]['evaluated'] = ""; + $ret['answers'][$answer['field']]['preview'] = ""; + } + + //push the seed onto the answer array, keep track of what seed these are for. + $ret['seed'] = $seed; + $ret['derivationid'] = $derivationid; + return $ret; + } + + /** + * @desc Enumerates the pictures for a response. + * @param $question object The question object. + * @param $state object The state object. + * @return array HTML code with <img> tag for each picture. + */ + function get_actual_response($question, $state) { + $temp = ''; + $i = 1; + foreach($state->responses['answers'] as $key => $value) { + $responses[] = "$i) " . $value['preview']; + $i++; + } + return $responses; + } + + /** + * @desc Prints a summary of a response. + * @param $question object The question object. + * @param $state object The state object. + * @return string HTML. + */ + function response_summary($question, $state, $length=80) { + // This should almost certainly be overridden + $responses = $this->get_actual_response($question, $state); + if (empty($responses) || !is_array($responses)) { + $responses = array(); + } + if (is_array($responses)) { + $responses = implode('<br/><br/>', $responses); + } + return $responses;//substr($responses, 0, $length); + } + + /** + * Changes all states for the given attempts over to a new question + * + * This is used by the versioning code if the teacher requests that a question + * gets replaced by the new version. In order for the attempts to be regraded + * properly all data in the states referring to the old question need to be + * changed to refer to the new version instead. In particular for question types + * that use the ... [truncated message content] |