From: Matt L. v. a. <we...@ma...> - 2007-09-11 23:04:46
|
Log Message: ----------- Removed Files: ------------- wwmoodle/wwquestion: config.php display.html edit_webwork_form.php file.php files.php htmlparser.php icon.gif locallib.php questiontype.php test.php version.php Revision Data ------------- --- wwquestion/config.php +++ /dev/null @@ -1,13 +0,0 @@ -<?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); - - -?> --- wwquestion/display.html +++ /dev/null @@ -1,70 +0,0 @@ -<div class="qtext"> - <?php echo $questiontext; ?> -</div> -<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; ?>_derivationid" name="resp<?php echo $qid; ?>_derivationid" type="hidden" value="<?php echo $derivationid; ?>" /> -</div> - -<?php if ($image) { ?> - <img class="qimage" src="<?php echo $image; ?>" alt="" /> -<?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"> - - <th class="c0"></th> - <?php if($showPartiallyCorrectAnswers == 1) { ?> - <th class="c0"></th> - <th class="c0">Result</th> - <?php } ?> - <th class="c0">Answer</th> - <th class="c0">Preview</th> - <th class="c0">Evaluated</th> - <th class="c0">Errors</th> - </tr> - <?php $i = 1; ?> - <?php $row = 1; foreach ($answerfields as $answerobj) { ?> - <tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>"> - <td class="c0"> - <?php echo $i . ')'; ?> - </td> - <?php if($showPartiallyCorrectAnswers == 1) { ?> - <td class="c0"> - <?php echo question_get_feedback_image($answerobj['score']); ?> - </td> - <td class="c0" style="width: 15%;"> - <?php if($answerobj['score'] == 1) { $class = 'correct'; echo "Correct"; } else { $class = 'incorrect'; echo "Incorrect"; } ?> - </td> - <?php } ?> - <td class="c0" style="width: 15%;"> - <?php echo $answerobj['answer']; ?> - </td> - <td class="c0" style="width: 15%;"> - <?php echo $answerobj['preview']; ?> - </td> - <td class="c0" style="width: 15%;"> - <?php echo $answerobj['evaluated']; ?> - </td> - <td class="c0" style="width: 40%;"> - <?php echo $answerobj['answer_msg']; ?> - </td> - </tr> - <?php $i++; ?> - <?php } ?> - </table> - <?php } ?> - - <?php if ($feedback) { ?> - <div class="feedback"> - <?php echo $feedback; ?> - </div> - <?php } ?> - - -</div> \ No newline at end of file --- wwquestion/files.php +++ /dev/null @@ -1,839 +0,0 @@ -<?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\" />"; - -} - -?> - --- wwquestion/htmlparser.php +++ /dev/null @@ -1,389 +0,0 @@ -<?php - -/* - * Copyright (c) 2003 Jose Solorzano. All rights reserved. - * Redistribution of source must retain this copyright notice. - * - * Jose Solorzano (http://jexpert.us) is a software consultant. - * - * Contributions by: - * - Leo West (performance improvements) - */ - -define ("NODE_TYPE_START",0); -define ("NODE_TYPE_ELEMENT",1); -define ("NODE_TYPE_ENDELEMENT",2); -define ("NODE_TYPE_TEXT",3); -define ("NODE_TYPE_COMMENT",4); -define ("NODE_TYPE_DONE",5); - -/** - * Class HtmlParser. - * To use, create an instance of the class passing - * HTML text. Then invoke parse() until it's false. - * When parse() returns true, $iNodeType, $iNodeName - * $iNodeValue and $iNodeAttributes are updated. - * - * To create an HtmlParser instance you may also - * use convenience functions HtmlParser_ForFile - * and HtmlParser_ForURL. - */ -class HtmlParser { - - /** - * Field iNodeType. - * May be one of the NODE_TYPE_* constants above. - */ - var $iNodeType; - - /** - * Field iNodeName. - * For elements, it's the name of the element. - */ - var $iNodeName = ""; - - /** - * Field iNodeValue. - * For text nodes, it's the text. - */ - var $iNodeValue = ""; - - /** - * Field iNodeAttributes. - * A string-indexed array containing attribute values - * of the current node. Indexes are always lowercase. - */ - var $iNodeAttributes; - - // The following fields should be - // considered private: - - var $iHtmlText; - var $iHtmlTextLength; - var $iHtmlTextIndex = 0; - var $iHtmlCurrentChar; - var $BOE_ARRAY; - var $B_ARRAY; - var $BOS_ARRAY; - - /** - * Constructor. - * Constructs an HtmlParser instance with - * the HTML text given. - */ - function HtmlParser ($aHtmlText) { - $this->iHtmlText = $aHtmlText; - $this->iHtmlTextLength = strlen($aHtmlText); - $this->iNodeAttributes = array(); - $this->setTextIndex (0); - - $this->BOE_ARRAY = array (" ", "\t", "\r", "\n", "=" ); - $this->B_ARRAY = array (" ", "\t", "\r", "\n" ); - $this->BOS_ARRAY = array (" ", "\t", "\r", "\n", "/" ); - } - - /** - * Method parse. - * Parses the next node. Returns false only if - * the end of the HTML text has been reached. - * Updates values of iNode* fields. - */ - function parse() { - $text = $this->skipToElement(); - if ($text != "") { - $this->iNodeType = NODE_TYPE_TEXT; - $this->iNodeName = "Text"; - $this->iNodeValue = $text; - return true; - } - return $this->readTag(); - } - function printTag() { - if($this->iNodeType == NODE_TYPE_ELEMENT) { - $temp = "<"; - $temp .= $this->iNodeName; - if(isset($this->iNodeAttributes['selected'])) { - $temp .= " selected"; - } - foreach($this->iNodeAttributes as $key => $value) { - if($key == 'selected') { - } else { - $temp .= " " . $key . "=" . '"' . $value . '"'; - } - } - $temp .= ">"; - } else if($this->iNodeType == NODE_TYPE_ENDELEMENT) { - $temp = "</" . $this->iNodeName . ">"; - } else if($this->iNodeType == NODE_TYPE_TEXT) { - $temp = $this->iNodeValue; - } else { - } - return $temp; - - - } - - function clearAttributes() { - $this->iNodeAttributes = array(); - } - - function readTag() { - if ($this->iCurrentChar != "<") { - $this->iNodeType = NODE_TYPE_DONE; - return false; - } - $this->clearAttributes(); - $this->skipMaxInTag ("<", 1); - if ($this->iCurrentChar == '/') { - $this->moveNext(); - $name = $this->skipToBlanksInTag(); - $this->iNodeType = NODE_TYPE_ENDELEMENT; - $this->iNodeName = $name; - $this->iNodeValue = ""; - $this->skipEndOfTag(); - return true; - } - $name = $this->skipToBlanksOrSlashInTag(); - if (!$this->isValidTagIdentifier ($name)) { - $comment = false; - if (strpos($name, "!--") === 0) { - $ppos = strpos($name, "--", 3); - if (strpos($name, "--", 3) === (strlen($name) - 2)) { - $this->iNodeType = NODE_TYPE_COMMENT; - $this->iNodeName = "Comment"; - $this->iNodeValue = "<" . $name . ">"; - $comment = true; - } - else { - $rest = $this->skipToStringInTag ("-->"); - if ($rest != "") { - $this->iNodeType = NODE_TYPE_COMMENT; - $this->iNodeName = "Comment"; - $this->iNodeValue = "<" . $name . $rest; - $comment = true; - // Already skipped end of tag - return true; - } - } - } - if (!$comment) { - $this->iNodeType = NODE_TYPE_TEXT; - $this->iNodeName = "Text"; - $this->iNodeValue = "<" . $name; - return true; - } - } - else { - $this->iNodeType = NODE_TYPE_ELEMENT; - $this->iNodeValue = ""; - $this->iNodeName = $name; - while ($this->skipBlanksInTag()) { - $attrName = $this->skipToBlanksOrEqualsInTag(); - if ($attrName != "" && $attrName != "/") { - $this->skipBlanksInTag(); - if ($this->iCurrentChar == "=") { - $this->skipEqualsInTag(); - $this->skipBlanksInTag(); - $value = $this->readValueInTag(); - $this->iNodeAttributes[strtolower($attrName)] = $value; - } - else { - $this->iNodeAttributes[strtolower($attrName)] = ""; - } - } - } - } - $this->skipEndOfTag(); - return true; - } - - function isValidTagIdentifier ($name) { - return ereg ("^[A-Za-z0-9_\\-]+$", $name); - } - - function skipBlanksInTag() { - return "" != ($this->skipInTag ($this->B_ARRAY)); - } - - function skipToBlanksOrEqualsInTag() { - return $this->skipToInTag ($this->BOE_ARRAY); - } - - function skipToBlanksInTag() { - return $this->skipToInTag ($this->B_ARRAY); - } - - function skipToBlanksOrSlashInTag() { - return $this->skipToInTag ($this->BOS_ARRAY); - } - - function skipEqualsInTag() { - return $this->skipMaxInTag ("=", 1); - } - - function readValueInTag() { - $ch = $this->iCurrentChar; - $value = ""; - if ($ch == "\"") { - $this->skipMaxInTag ("\"", 1); - $value = $this->skipToInTag ("\""); - $this->skipMaxInTag ("\"", 1); - } - else if ($ch == "'") { - $this->skipMaxInTag ("'", 1); - $value = $this->skipToInTag ("'"); - $this->skipMaxInTag ("'", 1); - } - else { - $value = $this->skipToBlanksInTag(); - } - return $value; - } - - function setTextIndex ($index) { - $this->iHtmlTextIndex = $index; - if ($index >= $this->iHtmlTextLength) { - $this->iCurrentChar = -1; - } - else { - $this->iCurrentChar = $this->iHtmlText{$index}; - } - } - - function moveNext() { - if ($this->iHtmlTextIndex < $this->iHtmlTextLength) { - $this->setTextIndex ($this->iHtmlTextIndex + 1); - return true; - } - else { - return false; - } - } - - function skipEndOfTag() { - while (($ch = $this->iCurrentChar) !== -1) { - if ($ch == ">") { - $this->moveNext(); - return; - } - $this->moveNext(); - } - } - - function skipInTag ($chars) { - $sb = ""; - while (($ch = $this->iCurrentChar) !== -1) { - if ($ch == ">") { - return $sb; - } else { - $match = false; - for ($idx = 0; $idx < count($chars); $idx++) { - if ($ch == $chars[$idx]) { - $match = true; - break; - } - } - if (!$match) { - return $sb; - } - $sb .= $ch; - $this->moveNext(); - } - } - return $sb; - } - - function skipMaxInTag ($chars, $maxChars) { - $sb = ""; - $count = 0; - while (($ch = $this->iCurrentChar) !== -1 && $count++ < $maxChars) { - if ($ch == ">") { - return $sb; - } else { - $match = false; - for ($idx = 0; $idx < count($chars); $idx++) { - if ($ch == $chars[$idx]) { - $match = true; - break; - } - } - if (!$match) { - return $sb; - } - $sb .= $ch; - $this->moveNext(); - } - } - return $sb; - } - - function skipToInTag ($chars) { - $sb = ""; - while (($ch = $this->iCurrentChar) !== -1) { - $match = $ch == ">"; - if (!$match) { - for ($idx = 0; $idx < count($chars); $idx++) { - if ($ch == $chars[$idx]) { - $match = true; - break; - } - } - } - if ($match) { - return $sb; - } - $sb .= $ch; - $this->moveNext(); - } - return $sb; - } - - function skipToElement() { - $sb = ""; - while (($ch = $this->iCurrentChar) !== -1) { - if ($ch == "<") { - return $sb; - } - $sb .= $ch; - $this->moveNext(); - } - return $sb; - } - - /** - * Returns text between current position and $needle, - * inclusive, or "" if not found. The current index is moved to a point - * after the location of $needle, or not moved at all - * if nothing is found. - */ - function skipToStringInTag ($needle) { - $pos = strpos ($this->iHtmlText, $needle, $this->iHtmlTextIndex); - if ($pos === false) { - return ""; - } - $top = $pos + strlen($needle); - $retvalue = substr ($this->iHtmlText, $this->iHtmlTextIndex, $top - $this->iHtmlTextIndex); - $this->setTextIndex ($top); - return $retvalue; - } -} - -function HtmlParser_ForFile ($fileName) { - return HtmlParser_ForURL($fileName); -} - -function HtmlParser_ForURL ($url) { - $fp = fopen ($url, "r"); - $content = ""; - while (true) { - $data = fread ($fp, 8192); - if (strlen($data) == 0) { - break; - } - $content .= $data; - } - fclose ($fp); - return new HtmlParser ($content); -} - -?> --- wwquestion/version.php +++ /dev/null @@ -1,5 +0,0 @@ -<?PHP // $Id: version.php,v 1.4 2007/09/09 02:53:16 mleventi Exp $ - -$plugin->version = 2007090700; -$plugin->requires = 2006032200; -?> \ No newline at end of file --- wwquestion/test.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php -//base configuration file for moodle -require_once('../../../config.php'); - -echo "<b>Testing WeBWorK Question Type Setup</b><br>"; -echo "------------------------------------------<br>"; - -//Tests configuration file existance -echo "1) Configuration File<br>"; -require_once("$CFG->dirroot/question/type/webwork/config.php"); -echo "WSDL Path: '" . WWQUESTION_WSDL . "'<br>"; -echo "WeBWorK Question Root Directory: '" . $CFG->dataroot . WWQUESTION_ROOTDIR . "'<br>"; -echo "Success<br><br>"; - -//Tests communication to server -echo "2) Connection to WeBWorK Question Server<br>"; -require_once('locallib.php'); -$client = new webwork_client(); -echo "Initalized...<br>"; -$response = $client->handler('hello'); -echo "Connected....<br>"; -echo "Response: $response<br>"; -echo "Success<br><br>"; - -echo "All tests completed successfully.<br>"; -echo "WeBWorK Question Type is setup.<br>"; - - - - - - - -?> --- wwquestion/questiontype.php +++ /dev/null @@ -1,688 +0,0 @@ -<?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... [truncated message content] |