From: Matt L. v. a. <we...@ma...> - 2007-09-09 02:59:46
|
Log Message: ----------- Modified Files: -------------- wwmoodle/wwquestion: README.txt display.html edit_webwork_form.php file.php questiontype.php version.php wwmoodle/wwquestion/db: install.xml wwmoodle/wwquestion/lang/en_utf8: qtype_webwork.php Added Files: ----------- wwmoodle/wwquestion: files.php locallib.php version.txt Revision Data ------------- Index: display.html =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/display.html,v retrieving revision 1.6 retrieving revision 1.7 diff -Lwwquestion/display.html -Lwwquestion/display.html -u -r1.6 -r1.7 --- wwquestion/display.html +++ wwquestion/display.html @@ -4,7 +4,7 @@ <div class="qtext"> <?php echo $problemhtml; ?> <input id="resp<?php echo $qid; ?>_seed" name="resp<?php echo $qid; ?>_seed" type="hidden" value="<?php echo $seed; ?>" /> - <input id="resp<?php echo $qid; ?>_derivedid" name="resp<?php echo $qid; ?>_derivedid" type="hidden" value="<?php echo $derivedid; ?>" /> + <input id="resp<?php echo $qid; ?>_derivationid" name="resp<?php echo $qid; ?>_derivationid" type="hidden" value="<?php echo $derivationid; ?>" /> </div> <?php if ($image) { ?> @@ -12,6 +12,8 @@ <?php } ?> <div class="ablock clearfix"> + <?php $this->print_question_submit_buttons($question, $state, $cmoptions, $options); ?> + <br> <?php if($state->event == QUESTION_EVENTGRADE) { ?> <table class="answer"> <tr class="header"> @@ -59,5 +61,5 @@ </div> <?php } ?> - <?php $this->print_question_submit_buttons($question, $state, $cmoptions, $options); ?> + </div> \ No newline at end of file --- /dev/null +++ wwquestion/version.txt @@ -0,0 +1,10 @@ +Old versions: + +Version .2 (August 2007) +* DB consistency issues fixed (thanks to Jean-Marc) +* New code checking, makes sure PG code is correct +* Images are now copied locally for faster problem loading +* Minor bug Fixes + +Version .1 (July 2007) +* Initial Release \ No newline at end of file --- /dev/null +++ wwquestion/files.php @@ -0,0 +1,839 @@ +<?php // $Id: files.php,v 1.1 2007/09/09 02:53:16 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\" />"; + +} + +?> + Index: README.txt =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/README.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -Lwwquestion/README.txt -Lwwquestion/README.txt -u -r1.4 -r1.5 --- wwquestion/README.txt +++ wwquestion/README.txt @@ -1,21 +1,25 @@ Webwork Question Type ---------------------- -Version: 0.2 (stable) +Version: 0.3 (stable) Released 9/9/2007 Maintainer: Matthew Leventi <mle...@gm...> CVS: cvs.webwork.rochester.edu:/webwork/cvs/system wwmoodle/wwquestion -**If your using this send me an email.** +This is a moodle questiontype module that will allow webwork questions to be asked in Moodle Quizzes and Lessons. Currently it supports many of the features found in the webwork2 system. -Whats coming soon (sept 1): -* Question Importer (alpha at CVS: cvs.webwork.rochester.edu:/webwork/cvs/system wwmoodle/wwquestion_importer) -* Applet & External Dep. support for PG files. - -Whats New: -* DB consistency issues fixed (thanks to Jean-Marc) -* New code checking, makes sure PG code is correct -* Images are now copied locally for faster problem loading -* Minor bug Fixes +* If you are using this send me an email. Feedback is appreciated. * +Current Release: +* Derivation mismatch bugs fixed. +* New Test file +* External File support! (applet,images,graphs,etc) +* Code Refactoring +* New levels of Code Checking including warnings + +PG Language: What is supported? +Simple and complex pg problems including those which use applets, images, graph generation problems, etc. + +PG Language: What is not supported? +Currently the only PG files that don't fully work are those with custom graders. Hence problems will reveal which answers the student has correct despite the showCorrectAnswer flag being off. Upgrading (from 0.1): A database column was added called codecheck. If you have data that you don't want to lose your going to have to add the new column manually to the db @@ -23,15 +27,17 @@ Then you can delete the webwork directory and recreate it from the CVS ** I am not really sure if this is backward compatible to 0.1. If you are having problems with questions edit them and submit to regenerate derived copies. + Setup: 1) Make a new folder named 'webwork' in the question/type directory. 2) Copy all the files from this directory into . 3) Point your browser to http://yourmoodle/admin to setup the question_webwork database table. Configuration: -1) Change the WSDL path variable in the webwork/questiontype.php file to point to your Webwork Problem Server's WSDL file. +1) Change the WSDL path variable in the webwork/config.php file to point to your Webwork Problem Server's WSDL file. Use: +Go into the question bank and create a new WeBWorK question. A webwork question only has three special fields. -code: Paste the perl code that renders the webwork question here. -seed: The starting seed to use to generate random problems @@ -43,7 +49,7 @@ Note: Previewing the question will use random seeds. -ex problem) +Example Problem: ##DESCRIPTION Index: version.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/version.php,v retrieving revision 1.3 retrieving revision 1.4 diff -Lwwquestion/version.php -Lwwquestion/version.php -u -r1.3 -r1.4 --- wwquestion/version.php +++ wwquestion/version.php @@ -1,5 +1,5 @@ <?PHP // $Id$ -$plugin->version = 2007082900; // TODO. +$plugin->version = 2007090700; $plugin->requires = 2006032200; ?> \ No newline at end of file Index: questiontype.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/questiontype.php,v retrieving revision 1.11 retrieving revision 1.12 diff -Lwwquestion/questiontype.php -Lwwquestion/questiontype.php -u -r1.11 -r1.12 --- wwquestion/questiontype.php +++ wwquestion/questiontype.php @@ -1,12 +1,9 @@ <?php -require_once("$CFG->libdir/soap/nusoap.php"); - -require_once("htmlparser.php"); - -//Path to the WSDL file on the Webwork Server -define('PROBLEMSERVER_WSDL','YOUR WSDL PATH HERE'); - +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. @@ -15,7 +12,6 @@ * @author mle...@gm... * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package webwork_qtype - * **/ /** @@ -24,27 +20,32 @@ * 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'; } - function _derivedquestions($derivedquestions = null) { - static $temp = null; - if($derivedquestions == null) { - return $temp; - } - $temp = $derivedquestions; - return true; + /** + * @desc Gives the label in the Create Question dropdown. + * @return string WeBWorK + */ + function menu_name() { + return 'WeBWorK'; } - + /** - * @desc Retrieves the seed and decoded code out of the question_webwork table. + * @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) { - // TODO code to retrieve the extra data you stored in the database into - // $question->options. if (!$record = get_record('question_webwork', 'question', $question->id)) { notify('Error: Missing question options!'); return false; @@ -53,251 +54,123 @@ $question->seed = $record->seed; $question->code = base64_decode($record->code); $question->codecheck = $record->codecheck; + //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) { - - //UPDATE OR INSERTION - if ($record = get_record("question_webwork", "question", $question->id)) { - $isupdate = true; - } else { + //determing update or insert + $oldrecord = get_record('question_webwork','question',$question->id); + if(!$oldrecord) { $isupdate = false; - unset($record); + } else { + $isupdate = true; } - //set new variables for update or insert + //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; - - //create the derived questions and check for errors - //$results = $question->derivedquestions; - - //do the database action on question_webwork + //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 quiz webwork options! (id=$record->id)"; + $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 quiz webwork options!"; + $errresult->error = "Could not insert question_webwork record!"; return $errresult; } + //set the new record id $record->id = $errresult; } - - //delete the derived questions - $this->delete_derived_questions($record->id); - - //do the database action on question_webwork_derived - $err = $this->insert_derived_questions($record->id,$this->_derivedquestions()); - if($err != 0) { - return $err; + $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)); } - return true; - } - - /** - * @desc Deletes all derived questions that are children of the ID passed in. - * @param $webworkquestionid integer The ID of the parent question - */ - function delete_derived_questions($webworkquestionid) { - delete_records("question_webwork_derived", "question_webwork", $webworkquestionid); - return true; - } - - /** - * @desc Gets derived questions from a webworkquestion record object by calling the SOAP object. - * @param $webworkquestion The record to create from - * - */ - function get_derived_questions($webworkquestion) { - //parameters needed from the webworkquestion object - $code = $webworkquestion->code; - $seed = $webworkquestion->seed; - $trials = $webworkquestion->trials; - //problem to be generated - $problem = array(); - $problem['code'] = $code; - $problem['seed'] = $seed; - - //requested # times for generation - $request = array(); - $request['trials'] = $trials; - $request['problem'] = $problem; - - //SOAP CALL - $params = array($request); - $client = new problemserver_client(); - $response = $client->handler('generateProblem',$params); - return $response; - } - - - /** - * @desc Inserts the derived questions into the DB. - * @param $parentid The parent ID of the derived questions. - * @param $derivedrecordset The recordset to create from. - */ - function insert_derived_questions($parentid,$derivedrecordset) { - - foreach($derivedrecordset as $problem) { - unset($record); - //set the parent id for the derived questions - $record->question_webwork = $parentid; - $record->html = $problem['output']; - $record->seed = $problem['seed']; - //initial insert - $result = insert_record("question_webwork_derived",$record); - if (!$result) { - $result->error = "Could not insert quiz webwork derived options!"; - return $result; - } - $record->id = $result; - - //brings image files to local drive - //THIS SHOULD ALSO DO APPLETS SOON - $err = $this->copy_derived_question_data($record); - if($err != 0) { - return $err; - } - - $result = update_record("question_webwork_derived",$record); - if(!$result) { - $result->error = "Could not update quiz webwork derived options! (id=$record->id)"; - return $result; - } - - } - return false; - } - - function copy_derived_question_data(&$derivedrecord) { - global $CFG; - //make the base directory if needed - $dir = $CFG->dataroot . '/wwquestions'; - mkdir($dir); - //make the directory for this question - $dir = $CFG->dataroot . '/wwquestions/'.$derivedrecord->id; - mkdir($dir); - - //first we need to find the image paths - $imagestocopy = array(); - $problemhtml = ""; - $unparsedhtml = base64_decode($derivedrecord->html); - $parser = new HtmlParser($unparsedhtml); - while($parser->parse()) { - if ($parser->iNodeType == NODE_TYPE_ELEMENT) { - $nodename = $parser->iNodeName; - //rewrite the images - if(($nodename == "IMG") || ($nodename == "img")) { - //found one - $srcpath = $parser->iNodeAttributes['src']; - $srcfilename = strrchr($srcpath,'/'); - $parser->iNodeAttributes['src'] = $CFG->wwwroot . "/question/type/webwork/file.php/wwquestions/" . $derivedrecord->id . '/' . $srcfilename; - //NOTE explore the possibility of having an existence check here, filenames hashed? - //copy it - $err = copy($srcpath,$CFG->dataroot.'/wwquestions/'.$derivedrecord->id.$srcfilename); - if($err == false) { - $err->error = 'Copy Failed for: '.$srcpath; - return $err; - } - - - } - } - $problemhtml .= $parser->printTag(); - } - $html = base64_encode($problemhtml); - $derivedrecord->html = $html; - return false; - } - - - /** - * @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) { - //Deleting the webwork derived questions - $records = get_records('question_webwork','question',$questionid,'','id'); - foreach($records as $record) { - $this->delete_derived_questions($record->id); - } - //Deleting the webwork questions - delete_records("question_webwork", "question", $questionid); + //update the derivations + $this->_update_derivations($wwquestionid); return true; } /** - * @desc Creates an empty response before student answers a question. This contains the possibly randomized seed for that particular student. Sticky seeds are created here. + * @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; - - //directory housekeeping (insure directories are setup) - mkdir($CFG->dataroot.'/wwquestions/users'); - mkdir($CFG->dataroot.'/wwquestions/users/'.$USER->id); - - - //here we get the derived results for this question - $results = get_records("question_webwork_derived","question_webwork",$question->webworkid,'','id'); - if(!$results) { + $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($results) == 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($results)-1); - $values = array_values($results); - $derivedid = $values[$random]->id; - - //more directory housekeeping - mkdir($CFG->dataroot.'/wwquestions/users/'.$USER->id.'/'.$derivedid); + $random = rand(0,count($derivations)-1); + $values = array_values($derivations); + $derivationid = $values[$random]->id; //get the actual data - $results = get_record('question_webwork_derived','id',$derivedid); - $state->responses['seed'] = $results->seed; - $state->responses['derivedid'] = $derivedid; + $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); - $unparsedhtml = base64_decode($results->html); - //parse source to figure out the fields - $parser = new HtmlParser($unparsedhtml); - $currentselect = ""; - while($parser->parse()) { - if ($parser->iNodeType == NODE_TYPE_ELEMENT) { - $nodename = $parser->iNodeName; - $name = $parser->iNodeAttributes['name']; - if(($nodename == "INPUT") || ($nodename == "SELECT") || ($nodename == "TEXTAREA")) { - //THIS IS A FIELD WE NEED TO KNOW ABOUT - $state->responses['answers'][$name] = ""; - } - } - } + //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['']; @@ -309,10 +182,11 @@ /** * @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) { - // TODO package up the students response from the $state->responses - // array into a string and save it in the question_states.answer field. $responses = $state->responses; $serialized = serialize($responses); $serialized = base64_encode($serialized); @@ -320,7 +194,11 @@ } /** - * @desc Prints the question. Calls the Webwork Server for appropriate HTML output and image paths. + * @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 c... [truncated message content] |