You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(53) |
Feb
(56) |
Mar
|
Apr
|
May
(30) |
Jun
(78) |
Jul
(121) |
Aug
(155) |
Sep
(77) |
Oct
(61) |
Nov
(45) |
Dec
(94) |
2006 |
Jan
(116) |
Feb
(33) |
Mar
(11) |
Apr
(23) |
May
(60) |
Jun
(89) |
Jul
(130) |
Aug
(109) |
Sep
(124) |
Oct
(63) |
Nov
(82) |
Dec
(45) |
2007 |
Jan
(31) |
Feb
(35) |
Mar
(123) |
Apr
(36) |
May
(18) |
Jun
(134) |
Jul
(133) |
Aug
(241) |
Sep
(126) |
Oct
(31) |
Nov
(15) |
Dec
(5) |
2008 |
Jan
(11) |
Feb
(6) |
Mar
(16) |
Apr
(29) |
May
(43) |
Jun
(149) |
Jul
(27) |
Aug
(29) |
Sep
(37) |
Oct
(20) |
Nov
(4) |
Dec
(6) |
2009 |
Jan
(34) |
Feb
(30) |
Mar
(16) |
Apr
(6) |
May
(1) |
Jun
(32) |
Jul
(22) |
Aug
(7) |
Sep
(18) |
Oct
(50) |
Nov
(22) |
Dec
(8) |
2010 |
Jan
(17) |
Feb
(15) |
Mar
(10) |
Apr
(9) |
May
(67) |
Jun
(30) |
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
(1) |
Dec
|
From: Matt L. v. a. <we...@ma...> - 2007-09-11 23:15:03
|
Log Message: ----------- Removed Files: ------------- wwmoodle/wwquestion/simpletest: sampleProblem.pg testquestiontype.php Revision Data ------------- --- wwquestion/simpletest/sampleProblem.pg +++ /dev/null @@ -1,30 +0,0 @@ -# marks_first_test.pg #Standard Probability Problem #Drawing colored marbles from a bag - -DOCUMENT(); - -loadMacros("PG.pl", - "PGbasicmacros.pl", - "PGchoicemacros.pl", - "PGanswermacros.pl", - "PGauxiliaryFunctions.pl"); - -TEXT(beginproblem()); -$showPartialCorrectAnswers = 0; - -$total = random(15,25,1); -$some = random(5,10,1); - -BEGIN_TEXT; -You own $total CDs. You want to randomly arrange $some of them in a CD rack. -What is the probability that the rack ends up in alphabetical order? -$BR -$BR -The probability that the CDs are in alphabetical order is \{ans_rule(15)\}. -END_TEXT - -$ans = 1/fact($some); - -ANS(num_cmp($ans, mode => 'std')); - -ENDDOCUMENT(); - --- wwquestion/simpletest/testquestiontype.php +++ /dev/null @@ -1,153 +0,0 @@ -<?php -require_once(dirname(__FILE__) . '/../../../../config.php'); - -global $CFG; -require_once($CFG->libdir . '/simpletestlib.php'); -require_once($CFG->dirroot . '/question/type/webwork/questiontype.php'); -require_once($CFG->dirroot . '/question/type/webwork/locallib.php'); -require_once($CFG->dirroot . '/question/type/webwork/config.php'); - - -class webwork_qtype_test extends UnitTestCase { - var $qtype; - var $questioncode; - - function setUp() { - global $CFG; - $this->qtype = new webwork_qtype(); - $filepath = $CFG->dirroot . '/question/type/webwork/simpletest/sampleProblem.pg'; - if(!file_exists($filepath)) { - die('Test PG file doesnt exist.'); - } - $this->questioncode = file_get_contents($filepath); - } - - function tearDown() { - $this->qtype = null; - } - - /** - * @desc Test Module Name. - */ - function test_name() { - $this->assertEqual($this->qtype->name(),'webwork','Module Test'); - } - - /** - * @desc Test WSDL Path is set. - */ - function test_wsdl_path() { - $this->assertNotEqual(WWQUESTION_WSDL,'ENTER YOUR WSDL PATH HERE','WSDL Path Test'); - } - - /** - * @desc Test Menu Name - */ - function test_menu_name() { - $this->assertEqual($this->qtype->menu_name(),'WeBWorK','Menu Test'); - } - - /** - * @desc Test Basic Communication - */ - function test_basic_communication() { - $client = new webwork_client(); - $response = $client->handler('hello'); - $this->assertEqual('hello world!',$response,'Webwork Server Communication Test.'); - } - - /** - * @desc Test that problem is rendered - */ - function test_render_communication() { - $question->code = base64_encode(stripslashes($this->questioncode)); - $question->trials = 10; - $question->seed = 0; - $results = webwork_get_derivations($question); - $numresults = count($results); - $warning = false; - $error = false; - $ret = $this->assertEqual('10',$numresults,'PG Count Test'); - if($ret) { - foreach($results as $record) { - if((isset($record['errors'])) && ($record['errors'] != '') && ($record['errors'] != null)) { - $error = true; - $theerror = $record['errors']; - //$this->assertEqual(false,true); - } - if((isset($record['warnings'])) && ($record['warnings'] != '') && ($record['warnings'] != null)) { - $warning = true; - //$this->assertEqual(false,true); - } - } - } - $this->assertEqual(false,$error,'Sample PG Error Test'); - $this->assertEqual(false,$warning,'Sample PG Warning Test'); - } - - /** - * @desc Test creation of a wwquestion directory - */ - function test_create_wwquestion_directory() { - webwork_make_wwquestion_dir('SIMPLETEST'); - $path = webwork_get_wwquestion_path_full('SIMPLETEST'); - $this->assertEqual(is_dir($path),true,'Webwork Question Directory Creation Test.'); - webwork_delete_wwquestion_dir('SIMPLETEST'); - } - - /** - * @desc Test creation of a derivation directory - */ - function test_create_derivation_directory() { - webwork_make_derivation_dir('SIMPLETEST','SIMPLETEST'); - $path = webwork_get_derivation_path_full('SIMPLETEST','SIMPLETEST'); - $this->assertEqual(is_dir($path),true,'Webwork Derivation Directory Test.'); - webwork_delete_derivation_dir('SIMPLETEST','SIMPLETEST'); - } - -// function test_get_question_options() { -// } -// -// function test_get_numerical_units() { -// } -// -// function test_get_default_numerical_unit() { -// } -// -// function test_save_question_options() { -// } -// -// function test_save_numerical_units() { -// } -// -// function test_delete_question() { -// } -// -// function test_compare_responses() { -// } -// -// function test_test_response() { -// } -// -// function test_check_response(){ -// } -// -// function test_grade_responses() { -// } -// -// function test_get_correct_responses() { -// } -// -// function test_get_all_responses() { -// } - - -// function test_backup() { -// } -// -// function test_restore() { -// } -} - -?> - |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 23:05:57
|
Log Message: ----------- Removed Files: ------------- wwmoodle/wwquestion/lang/en_utf8: qtype_webwork.php wwmoodle/wwquestion/lang/en_utf8/help/quiz: webwork.html Revision Data ------------- --- wwquestion/lang/en_utf8/qtype_webwork.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php // $Id: qtype_webwork.php,v 1.5 2007/09/11 20:10:03 mleventi Exp $ -/** - * The language strings for the QTYPENAME question type. - * - * @copyright © 2006 YOURNAME - * @author YOUREMAILADDRESS - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package YOURPACKAGENAME - *//** */ - -$string['editingwebwork'] = 'Editing WeBWorK'; -$string['webwork'] = 'WeBWorK'; - -$string['error_client_construction'] = 'Error constructing client to Problem Server. Perhaps your WSDL Path is wrong?'; -$string['error_client_call'] = 'Error in communication with the Problem Server.'; - -$string['edit_codeheader'] = 'WeBWorK Code'; -$string['edit_fileheader'] = 'WeBWorK Files'; -$string['edit_optionheader'] = 'WeBWorK Options'; -$string['edit_codecheck'] = 'Code Checking'; - $string['edit_codecheck0'] = 'Turn Off (unadvised)'; - $string['edit_codecheck1'] = 'Reject Problem Seeds w/ Errors (silent)'; - $string['edit_codecheck2'] = 'Reject Question if any Errors exist (strict)'; - $string['edit_codecheck3'] = 'Reject Problem Seeds w/ Errors or Warnings (silent)'; - $string['edit_codecheck4'] = 'Reject Question if any Errors or Warnings exist (strict)'; -$string['edit_codefile'] = 'Question File'; -$string['edit_addcodefiles'] = 'Add More Question Files'; -$string['edit_code'] = 'Code'; -$string['edit_seed'] = 'Seed'; -$string['edit_trials'] = 'Trials'; -// TODO add any other requred strings. - -?> \ No newline at end of file |
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] |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 23:01:39
|
Log Message: ----------- Removed Files: ------------- wwmoodle/wwquestion/db: install.xml Revision Data ------------- --- wwquestion/db/install.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<XMLDB PATH="question/type/webwork/db" VERSION="20070903" COMMENT="XMLDB file for this question type" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd" -> - <TABLES> - <TABLE NAME="question_webwork" COMMENT="Options for webwork questions" NEXT="question_webwork_derived"> - <FIELDS> - <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="question"/> - <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="codecheck"/> - <FIELD NAME="codecheck" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="question" NEXT="code"/> - <FIELD NAME="code" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="codecheck" NEXT="seed"/> - <FIELD NAME="seed" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="code" NEXT="trials"/> - <FIELD NAME="trials" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" NEXT="grading" PREVIOUS="seed"/> - <FIELD NAME="grading" TYPE="int" LENGTH="10" NUTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="trials"/> - </FIELDS> - <KEYS> - <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for question_webwork" NEXT="question"/> - <KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="questions" REFFIELDS="id" PREVIOUS="primary"/> - </KEYS> - </TABLE> - <TABLE NAME="question_webwork_derived" COMMENT="Options for derived webwork questions" PREVIOUS="question_webwork"> - <FIELDS> - <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="question_webwork"/> - <FIELD NAME="question_webwork" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="html"/> - <FIELD NAME="html" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="question_webwork" NEXT="seed"/> - <FIELD NAME="seed" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="html"/> - </FIELDS> - <KEYS> - <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for question_webwork_derived" NEXT="question_webwork"/> - <KEY NAME="question_webwork" TYPE="foreign" FIELDS="question_webwork" REFTABLE="question_webwork" REFFIELDS="id" PREVIOUS="primary"/> - </KEYS> - </TABLE> - </TABLES> -</XMLDB> \ No newline at end of file |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:59:44
|
Log Message: ----------- New CVS directory structure Added Files: ----------- wwmoodle/wwquestion/bin: setup.pl wwmoodle/wwquestion/moodle/lang/en_utf8: qtype_webwork.php wwmoodle/wwquestion/moodle/lang/en_utf8/help/quiz: webwork.html wwmoodle/wwquestion/moodle/lang/en_utf8/help/webwork: code.html codecheck.html codeheader.html fileheader.html seed.html trials.html webwork.html wwmoodle/wwquestion/moodle/question/type/webwork: config.php display.html edit_webwork_form.php file.php files.php icon.gif locallib.php questiontype.php version.php wwmoodle/wwquestion/moodle/question/type/webwork/db: install.xml wwmoodle/wwquestion/moodle/question/type/webwork/simpletest: sampleProblem.pg testquestiontype.php Revision Data ------------- --- /dev/null +++ wwquestion/moodle/lang/en_utf8/qtype_webwork.php @@ -0,0 +1,33 @@ +<?php // $Id: qtype_webwork.php,v 1.1 2007/09/11 22:52:59 mleventi Exp $ +/** + * The language strings for the QTYPENAME question type. + * + * @copyright © 2006 YOURNAME + * @author YOUREMAILADDRESS + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package YOURPACKAGENAME + *//** */ + +$string['editingwebwork'] = 'Editing WeBWorK'; +$string['webwork'] = 'WeBWorK'; + +$string['error_client_construction'] = 'Error constructing client to Problem Server. Perhaps your WSDL Path is wrong?'; +$string['error_client_call'] = 'Error in communication with the Problem Server.'; + +$string['edit_codeheader'] = 'WeBWorK Code'; +$string['edit_fileheader'] = 'WeBWorK Files'; +$string['edit_optionheader'] = 'WeBWorK Options'; +$string['edit_codecheck'] = 'Code Checking'; + $string['edit_codecheck0'] = 'Turn Off (unadvised)'; + $string['edit_codecheck1'] = 'Reject Problem Seeds w/ Errors (silent)'; + $string['edit_codecheck2'] = 'Reject Question if any Errors exist (strict)'; + $string['edit_codecheck3'] = 'Reject Problem Seeds w/ Errors or Warnings (silent)'; + $string['edit_codecheck4'] = 'Reject Question if any Errors or Warnings exist (strict)'; +$string['edit_codefile'] = 'Question File'; +$string['edit_addcodefiles'] = 'Add More Question Files'; +$string['edit_code'] = 'Code'; +$string['edit_seed'] = 'Seed'; +$string['edit_trials'] = 'Trials'; +// TODO add any other requred strings. + +?> \ No newline at end of file --- /dev/null +++ wwquestion/moodle/lang/en_utf8/help/webwork/webwork.html @@ -0,0 +1,4 @@ +<p align="center"><b>WeBWorK</b></p> + +<p>TODO describe your question type and how to edit it here. This help file is +linked to from the top of the question editing form for you question type.</p> --- /dev/null +++ wwquestion/moodle/question/type/webwork/files.php @@ -0,0 +1,839 @@ +<?php // $Id: files.php,v 1.1 2007/09/11 22:53:00 mleventi Exp $ + +// Manage all uploaded files in a course file area + +// All the Moodle-specific stuff is in this top section +// Configuration and access control occurs here. +// Must define: USER, basedir, baseweb, html_header and html_footer +// USER is a persistent variable using sessions + + require('../../../config.php'); + require($CFG->libdir.'/filelib.php'); + require($CFG->libdir.'/adminlib.php'); + require($CFG->dirroot.'/question/type/webwork/locallib.php'); + + $id = required_param('id', PARAM_INT); + $qid = required_param('qid',PARAM_INT); + $file = optional_param('file', '', PARAM_PATH); + $wdir = optional_param('wdir', '', PARAM_PATH); + $action = optional_param('action', '', PARAM_ACTION); + $name = optional_param('name', '', PARAM_FILE); + $oldname = optional_param('oldname', '', PARAM_FILE); + $choose = optional_param('choose', '', PARAM_FILE); //in fact it is always 'formname.inputname' + $userfile= optional_param('userfile','',PARAM_FILE); + $save = optional_param('save', 0, PARAM_BOOL); + $text = optional_param('text', '', PARAM_RAW); + $confirm = optional_param('confirm', 0, PARAM_BOOL); + + if ($choose) { + if (count(explode('.', $choose)) > 2) { + print_error('Incorrect format for choose parameter'); + } + } + + if (! $course = get_record("course", "id", $id) ) { + print_error("That's an invalid course id"); + } + + //access is needed + require_login($course); + require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id)); + + + $baseweb = $CFG->wwwroot; + $basedir = $CFG->dataroot; + $userid = $USER->id; + + if($qid == -1) { + $searcher = webwork_get_tmp_path(); + } else { + $searcher = webwork_get_wwquestion_path($qid); + } + $wdir = str_replace($searcher,'',$wdir); + + if ($wdir == '') { + $wdir = "/"; + } + + if ($wdir{0} != '/') { + $wdir = "/".$wdir; + } + + //prefix the filepath + if($qid == -1) { + webwork_make_tmp_dir(); + $wdir = webwork_get_tmp_path() . $wdir; + } else { + if(!$question = get_record('question_webwork','id',$qid)) { + print_error("That's an invalid question id."); + } + $wdir = webwork_get_wwquestion_path($qid) . $wdir; + } + + if (!is_dir($basedir.$wdir)) { + //html_header($course, $wdir); + print_error("Requested directory does not exist."); + } + print_header(); + switch ($action) { + + case "upload": + //html_header($course, $wdir); + require_once($CFG->dirroot.'/lib/uploadlib.php'); + + if ($save and confirm_sesskey()) { + $course->maxbytes = 0; // We are ignoring course limits + $um = new upload_manager('userfile',false,false,$course,false,0); + $dir = "$basedir$wdir"; + if ($um->process_file_uploads($dir)) { + notify(get_string('uploadedfile')); + } + // um will take care of error reporting. + displaydir($wdir); + } else { + $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes); + $filesize = display_size($upload_max_filesize); + + $struploadafile = get_string("uploadafile"); + $struploadthisfile = get_string("uploadthisfile"); + $strmaxsize = get_string("maxsize", "", $filesize); + $strcancel = get_string("cancel"); + + echo "<p>$struploadafile ($strmaxsize) --> <b>$wdir</b></p>"; + echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"files.php\">"; + echo "<div>"; + echo "<table><tr><td colspan=\"2\">"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false); + echo " </td></tr></table>"; + echo " <input type=\"submit\" name=\"save\" value=\"$struploadthisfile\" />"; + echo "</div>"; + echo "</form>"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"$strcancel\" />"; + echo "</div>"; + echo "</form>"; + } + //html_footer(); + break; + + case "delete": + if ($confirm and confirm_sesskey()) { + //html_header($course, $wdir); + if (!empty($USER->filelist)) { + foreach ($USER->filelist as $file) { + $fullfile = $basedir.'/'.$file; + if (! fulldelete($fullfile)) { + echo "<br />Error: Could not delete: $fullfile"; + } + } + } + clearfilelist(); + displaydir($wdir); + //html_footer(); + + } else { + //html_header($course, $wdir); + + if (setfilelist($_POST)) { + notify(get_string('deletecheckwarning').':'); + print_simple_box_start("center"); + printfilelist($USER->filelist); + print_simple_box_end(); + echo "<br />"; + + require_once($CFG->dirroot.'/mod/resource/lib.php'); + $block = resource_delete_warning($course, $USER->filelist); + + if (empty($CFG->resource_blockdeletingfile) or $block == '') { + $optionsyes = array('id'=>$id, 'qid'=>$qid, 'wdir'=>$wdir, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'choose'=>$choose); + $optionsno = array('id'=>$id, 'qid'=>$qid, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose); + notice_yesno (get_string('deletecheckfiles'), 'files.php', 'files.php', $optionsyes, $optionsno, 'post', 'get'); + } else { + + notify(get_string('warningblockingdelete', 'resource')); + $options = array('id'=>$id, 'qid'=>$qid, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose); + print_continue("files.php?id=$id&qid=$qid&wdir=$wdir&action=cancel&choose=$choose"); + } + } else { + displaydir($wdir); + } + //html_footer(); + } + break; + + case "move": + //html_header($course, $wdir); + if (($count = setfilelist($_POST)) and confirm_sesskey()) { + $USER->fileop = $action; + $USER->filesource = $wdir; + echo "<p class=\"centerpara\">"; + print_string("selectednowmove", "moodle", $count); + echo "</p>"; + } + displaydir($wdir); + //html_footer(); + break; + + case "paste": + //html_header($course, $wdir); + if (isset($USER->fileop) and ($USER->fileop == "move") and confirm_sesskey()) { + foreach ($USER->filelist as $file) { + $shortfile = basename($file); + $oldfile = $basedir.'/'.$file; + $newfile = $basedir.$wdir."/".$shortfile; + if (!rename($oldfile, $newfile)) { + echo "<p>Error: $shortfile not moved</p>"; + } + } + } + clearfilelist(); + displaydir($wdir); + //html_footer(); + break; + + case "rename": + if (($name != '') and confirm_sesskey()) { + //html_header($course, $wdir); + $name = clean_filename($name); + if (file_exists($basedir.$wdir."/".$name)) { + echo "<center>Error: $name already exists!</center>"; + } else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) { + echo "<p align=\"center\">Error: could not rename $oldname to $name</p>"; + } else { + //file was renamed now update resources if needed + require_once($CFG->dirroot.'/mod/resource/lib.php'); + resource_renamefiles($course, $wdir, $oldname, $name); + } + displaydir($wdir); + + } else { + $strrename = get_string("rename"); + $strcancel = get_string("cancel"); + $strrenamefileto = get_string("renamefileto", "moodle", $file); + //html_header($course, $wdir, "form.name"); + echo "<p>$strrenamefileto:</p>"; + echo "<table><tr><td>"; + echo "<form action=\"files.php\" method=\"post\">"; + echo "<fieldset class=\"invisiblefieldset\">"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"rename\" />"; + echo " <input type=\"hidden\" name=\"oldname\" value=\"$file\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"$file\" />"; + echo " <input type=\"submit\" value=\"$strrename\" />"; + echo "</fieldset>"; + echo "</form>"; + echo "</td><td>"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"$strcancel\" />"; + echo "</div>"; + echo "</form>"; + echo "</td></tr></table>"; + } + //html_footer(); + break; + + case "makedir": + if (($name != '') and confirm_sesskey()) { + //html_header($course, $wdir); + $name = clean_filename($name); + if (file_exists("$basedir$wdir/$name")) { + echo "Error: $name already exists!"; + } else if (! make_upload_directory("$wdir/$name")) { + echo "Error: could not create $name"; + } + displaydir($wdir); + + } else { + $strcreate = get_string("create"); + $strcancel = get_string("cancel"); + $strcreatefolder = get_string("createfolder", "moodle", $wdir); + //html_header($course, $wdir, "form.name"); + echo "<p>$strcreatefolder:</p>"; + echo "<table><tr><td>"; + echo "<form action=\"files.php\" method=\"post\">"; + echo "<fieldset class=\"invisiblefieldset\">"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />"; + echo " <input type=\"text\" name=\"name\" size=\"35\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + echo " <input type=\"submit\" value=\"$strcreate\" />"; + echo "</fieldset>"; + echo "</form>"; + echo "</td><td>"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"$strcancel\" />"; + echo "</div>"; + echo "</form>"; + echo "</td></tr></table>"; + } + //html_footer(); + break; + + case "edit": + //html_header($course, $wdir); + if (($text != '') and confirm_sesskey()) { + $fileptr = fopen($basedir.'/'.$file,"w"); + $text = preg_replace('/\x0D/', '', $text); // http://moodle.org/mod/forum/discuss.php?d=38860 + fputs($fileptr, stripslashes($text)); + fclose($fileptr); + displaydir($wdir); + + } else { + $streditfile = get_string("edit", "", "<b>$file</b>"); + $fileptr = fopen($basedir.'/'.$file, "r"); + $contents = fread($fileptr, filesize($basedir.'/'.$file)); + fclose($fileptr); + + if (mimeinfo("type", $file) == "text/html") { + $usehtmleditor = can_use_html_editor(); + } else { + $usehtmleditor = false; + } + $usehtmleditor = false; // Always keep it off for now + + print_heading("$streditfile"); + + echo "<table><tr><td colspan=\"2\">"; + echo "<form action=\"files.php\" method=\"post\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"file\" value=\"$file\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"edit\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + print_textarea($usehtmleditor, 25, 80, 680, 400, "text", $contents); + echo "</td></tr><tr><td>"; + echo " <input type=\"submit\" value=\"".get_string("savechanges")."\" />"; + echo "</div>"; + echo "</form>"; + echo "</td><td>"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />"; + echo "</div>"; + echo "</form>"; + echo "</td></tr></table>"; + + if ($usehtmleditor) { + use_html_editor(); + } + + + } + //html_footer(); + break; + + case "zip": + if (($name != '') and confirm_sesskey()) { + //html_header($course, $wdir); + $name = clean_filename($name); + + $files = array(); + foreach ($USER->filelist as $file) { + $files[] = "$basedir/$file"; + } + + if (!zip_files($files,"$basedir$wdir/$name")) { + error(get_string("zipfileserror","error")); + } + + clearfilelist(); + displaydir($wdir); + + } else { + //html_header($course, $wdir, "form.name"); + + if (setfilelist($_POST)) { + echo "<p align=\"center\">".get_string("youareabouttocreatezip").":</p>"; + print_simple_box_start("center"); + printfilelist($USER->filelist); + print_simple_box_end(); + echo "<br />"; + echo "<p align=\"center\">".get_string("whattocallzip")."</p>"; + echo "<table><tr><td>"; + echo "<form action=\"files.php\" method=\"post\">"; + echo "<fieldset class=\"invisiblefieldset\">"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"zip\" />"; + echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"new.zip\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + echo " <input type=\"submit\" value=\"".get_string("createziparchive")."\" />"; + echo "<fieldset>"; + echo "</form>"; + echo "</td><td>"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />"; + echo "</div>"; + echo "</form>"; + echo "</td></tr></table>"; + } else { + displaydir($wdir); + clearfilelist(); + } + } + //html_footer(); + break; + + case "unzip": + //html_header($course, $wdir); + if (($file != '') and confirm_sesskey()) { + $strok = get_string("ok"); + $strunpacking = get_string("unpacking", "", $file); + + echo "<p align=\"center\">$strunpacking:</p>"; + + $file = basename($file); + + if (!unzip_file("$basedir$wdir/$file")) { + error(get_string("unzipfileserror","error")); + } + + echo "<div style=\"text-align:center\"><form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"$strok\" />"; + echo "</div>"; + echo "</form>"; + echo "</div>"; + } else { + displaydir($wdir); + } + //html_footer(); + break; + + case "listzip": + //html_header($course, $wdir); + if (($file != '') and confirm_sesskey()) { + $strname = get_string("name"); + $strsize = get_string("size"); + $strmodified = get_string("modified"); + $strok = get_string("ok"); + $strlistfiles = get_string("listfiles", "", $file); + + echo "<p align=\"center\">$strlistfiles:</p>"; + $file = basename($file); + + include_once("$CFG->libdir/pclzip/pclzip.lib.php"); + $archive = new PclZip(cleardoubleslashes("$basedir$wdir/$file")); + if (!$list = $archive->listContent(cleardoubleslashes("$basedir$wdir"))) { + notify($archive->errorInfo(true)); + + } else { + echo "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=\"640\" class=\"files\">"; + echo "<tr class=\"file\"><th align=\"left\" class=\"header name\" scope=\"col\">$strname</th><th align=\"right\" class=\"header size\" scope=\"col\">$strsize</th><th align=\"right\" class=\"header date\" scope=\"col\">$strmodified</th></tr>"; + foreach ($list as $item) { + echo "<tr>"; + print_cell("left", s($item['filename']), 'name'); + if (! $item['folder']) { + print_cell("right", display_size($item['size']), 'size'); + } else { + echo "<td> </td>"; + } + $filedate = userdate($item['mtime'], get_string("strftimedatetime")); + print_cell("right", $filedate, 'date'); + echo "</tr>"; + } + echo "</table>"; + } + echo "<br /><center><form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />"; + echo " <input type=\"submit\" value=\"$strok\" />"; + echo "</div>"; + echo "</form>"; + echo "</center>"; + } else { + displaydir($wdir); + } + //html_footer(); + break; + + case "restore": + //html_header($course, $wdir); + if (($file != '') and confirm_sesskey()) { + echo "<p align=\"center\">".get_string("youaregoingtorestorefrom").":</p>"; + print_simple_box_start("center"); + echo $file; + print_simple_box_end(); + echo "<br />"; + echo "<p align=\"center\">".get_string("areyousuretorestorethisinfo")."</p>"; + $restore_path = "$CFG->wwwroot/backup/restore.php"; + notice_yesno (get_string("areyousuretorestorethis"), + $restore_path."?id=".$id."&qid=".$qid."&file=".cleardoubleslashes($id.$wdir."/".$file)."&method=manual", + "files.php?id=$id&qid=$qid&wdir=$wdir&action=cancel"); + } else { + displaydir($wdir); + } + //html_footer(); + break; + + case "cancel": + clearfilelist(); + + default: + //html_header($course, $wdir); + displaydir($wdir); + //html_footer(); + break; +} + + +/// FILE FUNCTIONS /////////////////////////////////////////////////////////// + + +function setfilelist($VARS) { + global $USER; + + $USER->filelist = array (); + $USER->fileop = ""; + + $count = 0; + foreach ($VARS as $key => $val) { + if (substr($key,0,4) == "file") { + $count++; + $val = rawurldecode($val); + $USER->filelist[] = clean_param($val, PARAM_PATH); + } + } + return $count; +} + +function clearfilelist() { + global $USER; + + $USER->filelist = array (); + $USER->fileop = ""; +} + + +function printfilelist($filelist) { + global $CFG, $basedir; + + $strfolder = get_string("folder"); + $strfile = get_string("file"); + + foreach ($filelist as $file) { + if (is_dir($basedir.'/'.$file)) { + echo "<img src=\"$CFG->pixpath/f/folder.gif\" class=\"icon\" alt=\"$strfolder\" /> $file<br />"; + $subfilelist = array(); + $currdir = opendir($basedir.'/'.$file); + while (false !== ($subfile = readdir($currdir))) { + if ($subfile <> ".." && $subfile <> ".") { + $subfilelist[] = $file."/".$subfile; + } + } + printfilelist($subfilelist); + + } else { + $icon = mimeinfo("icon", $file); + echo "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" /> $file<br />"; + } + } +} + + +function print_cell($alignment='center', $text=' ', $class='') { + if ($class) { + $class = ' class="'.$class.'"'; + } + echo '<td align="'.$alignment.'" style="white-space:nowrap "'.$class.'>'.$text.'</td>'; +} + +function displaydir ($wdir) { +// $wdir == / or /a or /a/b/c/d etc + + global $basedir; + global $id; + global $qid; + global $USER, $CFG; + global $choose; + + $fullpath = $basedir.$wdir; + $dirlist = array(); + + $directory = opendir($fullpath); // Find all files + while (false !== ($file = readdir($directory))) { + if ($file == "." || $file == "..") { + continue; + } + + if (is_dir($fullpath."/".$file)) { + $dirlist[] = $file; + } else { + $filelist[] = $file; + } + } + closedir($directory); + + $strname = get_string("name"); + $strsize = get_string("size"); + $strmodified = get_string("modified"); + $straction = get_string("action"); + $strmakeafolder = get_string("makeafolder"); + $struploadafile = get_string("uploadafile"); + $strselectall = get_string("selectall"); + $strselectnone = get_string("deselectall"); + $strwithchosenfiles = get_string("withchosenfiles"); + $strmovetoanotherfolder = get_string("movetoanotherfolder"); + $strmovefilestohere = get_string("movefilestohere"); + $strdeletecompletely = get_string("deletecompletely"); + $strcreateziparchive = get_string("createziparchive"); + $strrename = get_string("rename"); + $stredit = get_string("edit"); + $strunzip = get_string("unzip"); + $strlist = get_string("list"); + $strrestore= get_string("restore"); + $strchoose = get_string("choose"); + $strfolder = get_string("folder"); + $strfile = get_string("file"); + + + echo "<form action=\"files.php\" method=\"post\" id=\"dirform\">"; + echo "<div>"; + echo '<input type="hidden" name="choose" value="'.$choose.'" />'; + // echo "<hr align=\"center\" noshade=\"noshade\" size=\"1\" />"; + echo "<hr/>"; + echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\" class=\"files\">"; + echo "<tr>"; + echo "<th scope=\"col\"></th>"; + echo "<th class=\"header name\" scope=\"col\">$strname</th>"; + echo "<th class=\"header size\" scope=\"col\">$strsize</th>"; + echo "<th class=\"header date\" scope=\"col\">$strmodified</th>"; + echo "<th class=\"header commands\" scope=\"col\">$straction</th>"; + echo "</tr>\n"; + + if ($wdir != "/") { + $dirlist[] = '..'; + } + + $count = 0; + + if (!empty($dirlist)) { + asort($dirlist); + foreach ($dirlist as $dir) { + echo "<tr class=\"folder\">"; + + if ($dir == '..') { + //only display parent if we are not in root of question + if($qid == -1) { + $tempstr = webwork_get_tmp_path() . '/'; + } else { + $tempstr = WWQUESTION_ROOTDIR . '/' . $qid . '/'; + } + if($tempstr != $wdir) { + $fileurl = rawurlencode(dirname($wdir)); + print_cell(); + // alt attribute intentionally empty to prevent repetition in screen reader + print_cell('left', '<a href="files.php?id='.$id.'&qid='.$qid.'&wdir='.$fileurl.'&choose='.$choose.'"><img src="'.$CFG->pixpath.'/f/parent.gif" class="icon" alt="" /> '.get_string('parentfolder').'</a>', 'name'); + print_cell(); + print_cell(); + print_cell(); + } + + } else { + $count++; + $filename = $fullpath."/".$dir; + $fileurl = rawurlencode($wdir."/".$dir); + $filesafe = rawurlencode($dir); + $filesize = display_size(get_directory_size("$fullpath/$dir")); + $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); + print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox'); + print_cell("left", "<a href=\"files.php?id=$id&qid=$qid&wdir=$fileurl&choose=$choose\"><img src=\"$CFG->pixpath/f/folder.gif\" class=\"icon\" alt=\"$strfolder\" /> ".htmlspecialchars($dir)."</a>", 'name'); + print_cell("right", $filesize, 'size'); + print_cell("right", $filedate, 'date'); + print_cell("right", "<a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands'); + } + + echo "</tr>"; + } + } + + + if (!empty($filelist)) { + asort($filelist); + foreach ($filelist as $file) { + + $icon = mimeinfo("icon", $file); + + $count++; + $filename = $fullpath."/".$file; + $fileurl = trim($wdir, "/")."/$file"; + $filesafe = rawurlencode($file); + $fileurlsafe = rawurlencode($fileurl); + $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); + + $selectfile = trim($fileurl, "/"); + + echo "<tr class=\"file\">"; + + print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox'); + echo "<td align=\"left\" style=\"white-space:nowrap\" class=\"name\">"; + if ($CFG->slasharguments) { + $ffurl = str_replace('//', '/', "/file.php/$fileurl"); + } else { + $ffurl = str_replace('//', '/', "/file.php?file=/$fileurl"); + } + link_to_popup_window ($ffurl, "display", + "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" /> ".htmlspecialchars($file), + 480, 640); + echo "</td>"; + + $file_size = filesize($filename); + print_cell("right", display_size($file_size), 'size'); + print_cell("right", $filedate, 'date'); + + if ($choose) { + $edittext = "<strong><a onclick=\"return set_value('$selectfile')\" href=\"#\">$strchoose</a></strong> "; + } else { + $edittext = ''; + } + + + if ($icon == "text.gif" || $icon == "html.gif") { + $edittext .= "<a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$fileurl&action=edit&choose=$choose\">$stredit</a>"; + } else if ($icon == "zip.gif") { + $edittext .= "<a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$fileurl&action=unzip&sesskey=$USER->sesskey&choose=$choose\">$strunzip</a> "; + $edittext .= "<a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$fileurl&action=listzip&sesskey=$USER->sesskey&choose=$choose\">$strlist</a> "; + if (!empty($CFG->backup_version) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { + $edittext .= "<a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$filesafe&action=restore&sesskey=$USER->sesskey&choose=$choose\">$strrestore</a> "; + } + } + + print_cell("right", "$edittext <a href=\"files.php?id=$id&qid=$qid&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands'); + + echo "</tr>"; + } + } + echo "</table>"; + echo "<hr />"; + //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; + + echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">"; + echo "<tr><td>"; + echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo '<input type="hidden" name="choose" value="'.$choose.'" />'; + echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" /> "; + echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + $options = array ( + "move" => "$strmovetoanotherfolder", + "delete" => "$strdeletecompletely", + "zip" => "$strcreateziparchive" + ); + if (!empty($count)) { + choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:getElementById('dirform').submit()"); + } + echo "</td></tr></table>"; + echo "</div>"; + echo "</form>"; + echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>"; + echo "<td align=\"center\">"; + if (!empty($USER->fileop) and ($USER->fileop == "move") and ($USER->filesource <> $wdir)) { + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />"; + echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />"; + echo " <input type=\"submit\" value=\"$strmovefilestohere\" />"; + echo "</div>"; + echo "</form>"; + } + echo "</td>"; + echo "<td align=\"right\">"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />"; + echo " <input type=\"submit\" value=\"$strmakeafolder\" />"; + echo "</div>"; + echo "</form>"; + echo "</td>"; + echo "<td align=\"right\">"; + echo "<form action=\"files.php\" method=\"get\">"; //dummy form - alignment only + echo "<fieldset class=\"invisiblefieldset\">"; + echo " <input type=\"button\" value=\"$strselectall\" onclick=\"checkall();\" />"; + echo " <input type=\"button\" value=\"$strselectnone\" onclick=\"uncheckall();\" />"; + echo "</fieldset>"; + echo "</form>"; + echo "</td>"; + echo "<td align=\"right\">"; + echo "<form action=\"files.php\" method=\"get\">"; + echo "<div>"; + echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; + echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; + echo " <input type=\"hidden\" name=\"qid\" value=\"$qid\" />"; + echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; + echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />"; + echo " <input type=\"submit\" value=\"$struploadafile\" />"; + echo "</div>"; + echo "</form>"; + echo "</td></tr>"; + echo "</table>"; + echo "<hr/>"; + //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; + +} + +?> + --- /dev/null +++ wwquestion/moodle/question/type/webwork/version.php @@ -0,0 +1,5 @@ +<?PHP // $Id: version.php,v 1.1 2007/09/11 22:53:00 mleventi Exp $ + +$plugin->version = 2007090700; +$plugin->requires = 2006032200; +?> \ No newline at end of file --- /dev/null +++ wwquestion/moodle/question/type/webwork/config.php @@ -0,0 +1,13 @@ +<?php + +//Path to the WSDL file on the Webwork Server +define('WWQUESTION_WSDL','ENTER YOUR WSDL PATH HERE','WSDL Path Test'); + +//Leave the rest alone +define('WWQUESTION_PREFIX','/wwquestions'); +define('WWQUESTION_ROOTDIR','/' . SITEID . WWQUESTION_PREFIX); + +define('WWQUESTION_RESPONSE_TIMEOUT',120); + + +?> --- /dev/null +++ wwquestion/moodle/question/type/webwork/questiontype.php @@ -0,0 +1,688 @@ +<?php + +require_once("$CFG->dirroot/question/type/webwork/config.php"); +require_once("$CFG->dirroot/question/type/webwork/locallib.php"); +require_once("$CFG->dirroot/question/type/questiontype.php"); +require_once("$CFG->dirroot/backup/lib.php"); + +/** + * The question type class for the webwork question type. + * + * @copyright © 2007 Matthew Leventi + * @author mle...@gm... + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package webwork_qtype +**/ + +/** + * The webwork question class + * + * Allows webwork questions to be used in Moodle through a new question type. + */ +class webwork_qtype extends default_questiontype { + + ////////////////////////////////////////////////////////////////// + // Functions overriding default_questiontype functions + ////////////////////////////////////////////////////////////////// + + /** + * @desc Required function that names the question type. + * @return string webwork. + */ + function name() { + return 'webwork'; + } + + /** + * @desc Gives the label in the Create Question dropdown. + * @return string WeBWorK + */ + function menu_name() { + return 'WeBWorK'; + } + + /** + * @desc Retrieves information out of question_webwork table and puts it into question object. + * @return boolean to indicate success of failure. + */ + function get_question_options(&$question) { + if (!$record = get_record('question_webwork', 'question', $question->id)) { + notify('Error: Missing question options!'); + return false; + } + $question->trials = $record->trials; + $question->seed = $record->seed; + $question->code = base64_decode($record->code); + $question->codecheck = $record->codecheck; + $question->grading = $record->grading; + //hold onto the ID of the question_webwork record + $question->webworkid = $record->id; + return true; + } + + /** + * @desc Saves the webwork question code and default seed setting into question_webwork. Will recreate all corresponding derived questions. + * @param $question object The question object holding new data. + * @return boolean to indicate success of failure. + */ + function save_question_options($question) { + //determing update or insert + $oldrecord = get_record('question_webwork','question',$question->id); + if(!$oldrecord) { + $isupdate = false; + } else { + $isupdate = true; + } + //set new variables for DB entry + $record = new stdClass; + $record->question = $question->id; + $record->codecheck = $question->codecheck; + $record->code = base64_encode(stripslashes($question->code)); + $record->seed = $question->seed; + $record->trials = $question->trials; + + $results = webwork_qtype::_derivations(); + if(count($results) > 0) { + $record->grading = $results[0]['grading']; + } + + //insert or update question in DB + if($isupdate) { + //update + $record->id = $oldrecord->id; + $errresult = update_record("question_webwork", $record); + if (!$errresult) { + $errresult->error = "Could not update question_webwork record! (id=$record->id)"; + return $errresult; + } + } else { + //insert + $errresult = insert_record("question_webwork", $record); + if (!$errresult) { + $errresult->error = "Could not insert question_webwork record!"; + return $errresult; + } + //set the new record id + $record->id = $errresult; + } + $wwquestionid = $record->id; + //copy the tmp directory to the question one + if($isupdate == false) { + rename(webwork_get_tmp_path_full(),webwork_get_wwquestion_path_full($wwquestionid)); + } + + + //update the derivations + $this->_update_derivations($wwquestionid); + return true; + } + + /** + * @desc Creates an empty response before a student answers a question. This contains the possibly randomized seed for that particular student. Sticky seeds are created here. + * @param $question object The question object. + * @param $state object The state object. + * @param $cmoptions object The cmoptions containing the course ID + * @param $attempt id The attempt ID. + * @return bool true. + */ + function create_session_and_responses(&$question, &$state, $cmoptions, $attempt) { + global $CFG,$USER; + //here we get the derived results for this question + $derivations = get_records("question_webwork_derived","question_webwork",$question->webworkid,'','id'); + if(!$derivations) { + print_error(get_string('error_db_webwork_derived','qtype_webwork')); + return false; + } + + //make sure its not 0 + if(count($derivations) == 0) { + print_error(get_string('error_no_webwork_derived','qtype_webwork')); + return false; + } + + //pick a random question based on time + srand(time()); + $random = rand(0,count($derivations)-1); + $values = array_values($derivations); + $derivationid = $values[$random]->id; + + //get the actual data + $derivation = get_record('question_webwork_derived','id',$derivationid); + //build state + $state->responses['seed'] = $derivation->seed; + $state->responses['derivationid'] = $derivation->id; + return true; + } + + /** + * @desc Deletes question from the question_webwork table + * @param integer $questionid The question being deleted + * @return boolean to indicate success of failure. + */ + function delete_question($questionid) { + //Get wwquestion from DB + $record = get_record('question_webwork','question',$questionid); + $wwquestionid = $record->id; + + //delete DB and Files + webwork_delete_wwquestion_dir($wwquestionid); + delete_records('question_webwork', 'id' , $wwquestionid); + + //delete derivations + webwork_delete_derivations_db($wwquestionid); + return true; + } + + /** + * @desc Decodes and unserializes a students response into the response array carried by state + * @param $question object The question object. + * @param $state object The state that needs to be restored. + * @return bool true. + */ + function restore_session_and_responses(&$question, &$state) { + $serializedresponse = $state->responses['']; + $serializedresponse = base64_decode($serializedresponse); + $responses = unserialize($serializedresponse); + $state->responses = $responses; + return true; + } + + /** + * @desc Serialize, encodes and inserts a students response into the question_states table. + * @param $question object The question object for the session. + * @param $state object The state to save. + * @return true, or error on db change. + */ + function save_session_and_responses(&$question, &$state) { + $responses = $state->responses; + $serialized = serialize($responses); + $serialized = base64_encode($serialized); + return set_field('question_states', 'answer', $serialized, 'id', $state->id); + } + + /** + * @desc Prints the question. Calls question_webwork_derived, and prints out the html associated with derivedid. + * @param $question object The question object to print. + * @param $state object The state of the responses for the question. + * @param $cmoptions object Options containing course ID. + * @param $options object + */ + function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { + global $CFG,$USER; + $readonly = empty($options->readonly) ? '' : 'disabled="disabled"'; + //Formulate question image and text + $questiontext = $this->format_text($question->questiontext, + $question->questiontextformat, $cmoptions); + $image = get_question_image($question, $cmoptions->course); + + $derivationid = $state->responses['derivationid']; + $derivation = get_record('question_webwork_derived','id',$derivationid); + + $unparsedhtml = base64_decode($derivation->html); + + //partial answers + $showPartiallyCorrectAnswers = $question->grading; + + //new array keyed by field + $fieldhash = $state->responses['answers']; + $answerfields = array(); + $parser = new HtmlParser($unparsedhtml); + $currentselect = ""; + while($parser->parse()) { + //change some attributes of html tags for moodle compliance + if ($parser->iNodeType == NODE_TYPE_ELEMENT) { + $nodename = $parser->iNodeName; + $name = $parser->iNodeAttributes['name']; + //handle generic change of node's attribute name + if(($nodename == "INPUT") || ($nodename == "SELECT") || ($nodename == "TEXTAREA")) { + $parser->iNodeAttributes['name'] = 'resp' . $question->id . '_' . $name; + if(($state->event == QUESTION_EVENTGRADE) && (isset($fieldhash[$name]))) { + if($showPartiallyCorrectAnswers) { + $parser->iNodeAttributes['class'] = $parser->iNodeAttributes['class'] . ' ' . question_get_feedback_class($fieldhash[$name]['score']); + } + } + if(!strstr($name,'previous')) { + $answerfields[$name] = $fieldhash[$name]; + } + } + //handle specific change + if($nodename == "INPUT") { + //put submitted value into field + if(isset($fieldhash[$name])) { + $parser->iNodeAttributes['value'] = $fieldhash[$name]['answer']; + } + } else if($nodename == "SELECT") { + $currentselect = $name; + } else if($nodename == "OPTION") { + if($parser->iNodeAttributes['value'] == $fieldhash[$currentselect]['answer']) + $parser->iNodeAttributes['selected'] = '1'; + } else if($nodename == "TEXTAREA") { + } + } + $problemhtml .= $parser->printTag(); + } + + //for the seed form field + $qid = $question->id; + $seed = $state->responses['seed']; + + + + //if the student has answered + include("$CFG->dirroot/question/type/webwork/display.html"); + } + + /** + * @desc Assigns a grade for a student response. Currently a percentage right/total questions. Calls the Webwork Server to evaluate answers. + * @param $question object The question to grade. + * @param $state object The response to the question. + * @param $cmoptions object ... + * @return boolean true. + */ + function grade_responses(&$question, &$state, $cmoptions) { + global $CFG,$USER; + + //get code and seed of the students problem + $code = base64_encode($question->code); + $seed = $state->responses['seed']; + $derivationid = $state->responses['derivationid']; + $wwquestionid = $question->webworkid; + + //get answers & build answer request + $answerarray = array(); + foreach($state->responses as $key => $value) { + array_push($answerarray, array('field' => $key, 'answer'=> $value)); + } + + //build problem request + $problem = array(); + $problem['code'] = $code; + $problem['seed'] = $seed; + $problem['files']= array(); + + //SOAP request + $params = array(); + $params['request'] = $problem; + $params['answers'] = $answerarray; + + //SOAP Call + $client = new webwork_client(); + $response = $client->handler('checkAnswers',$params); + + //process output from soap & calculate score + $answers = $response; + $state->raw_grade = 0; + $total = 0; + $num = 0; + foreach($answers as $answer) { + $total += $answer['score']; + $num++; + } + if($num != 0) { + $state->raw_grade = $total / $num; + } + + //create the directory for this user + webwork_make_derivation_user_dir($wwquestionid,$derivationid,$USER->id); + + // Apply the penalty for this attempt + $state->penalty = $question->penalty * $question->maxgrade; + + // mark the state as graded + $state->event = ($state->event == QUESTION_EVENTCLOSE) ? QUESTION_EVENTCLOSEANDGRADE : QUESTION_EVENTGRADE; + + //put the responses into the state to remember + $state->responses['answers'] = array(); + + foreach ($answers as $answer) { + $html = base64_decode($answer['preview']); + $copyto = webwork_get_derivation_user_path_full($wwquestionid,$derivationid,$USER->id); + $replacer = webwork_get_derivation_user_url($wwquestionid,$derivationid,$USER->id); + $html = webwork_parse_change_ans($html,$replacer,$copyto); + $answer['preview'] = $html; + $state->responses['answers'][$answer['field']] = $answer; + } + return true; + } + + /** + * @desc Comparison of two student responses for the same question. Checks based on seed equality, and response equality. + * Perhaps we could add check on evaluated answer (depends on whether the server is called before this function) + * @param $question object The question object to compare. + * @param $state object The first response. + * @param $teststate object The second response. + * @return boolean, Returns true if the state are equal | false if not. + */ + function compare_responses($question, $state, $teststate) { + if(sizeof($state->responses) != sizeof($teststate->responses)) { + return false; + } + //check values are equal + foreach($state->responses as $key => $value) { + if($value != $teststate->responses[$key]) { + return false; + } + } + return true; + } + + /** + * @desc Gets the correct answers from the SOAP server for the seed in state. Places them into the state->responses array. + * @param $question object The question object. + * @param $state object The state object. + * @return object Object containing the seed,derivedid, and answers. + */ + function get_correct_responses(&$question, &$state) { + //get code and seed of response + $code = base64_encode($question->code); + $seed = $state->responses['seed']; + $derivationid = $state->responses['derivationid']; + + //get empty answers & build answer request + $answerarray = array(); + foreach($state->responses as $key => $value) { + array_push($answerarray, array('field' => $key, 'answer'=> $value)); + } + + //build problem request + $problem = array(); + $problem['code'] = $code; + $problem['seed'] = $seed; + + //SOAP request + $params = array(); + $params['request'] = $problem; + $params['answers'] = $answerarray; + + //SOAP Call + $client = new webwork_client(); + $response = $client->handler('checkAnswers',$params); + + //make the state perfect graded + $state->raw_grade = 1; + $state->event = ($state->event == QUESTION_EVENTCLOSE) ? QUESTION_EVENTCLOSEANDGRADE : QUESTION_EVENTGRADE; + $state->penalty = 0; + + //process correct answers into fields + $answers = $response; + $ret = array(); + $ret['answers'] = array(); + + foreach ($answers as $answer) { + $ret['answers'][$answer['field']] = $answer; + $ret['answers'][$answer['field']]['answer'] = $answer['correct']; + $ret['answers'][$answer['field']]['score'] = 1; + $ret['answers'][$answer['field']]['evaluated'] = ""; + $ret['answers'][$answer['field']]['preview'] = ""; + } + + //push the seed onto the answer array, keep track of what seed these are for. + $ret['seed'] = $seed; + $ret['derivationid'] = $derivationid; + return $ret; + } + + /** + * @desc Enumerates the pictures for a response. + * @param $question object The question object. + * @param $state object The state object. + * @return array HTML code with <img> tag for each picture. + */ + function get_actual_response($question, $state) { + $temp = ''; + $i = 1; + foreach($state->responses['answers'] as $key => $value) { + $responses[] = "$i) " . $value['preview']; + $i++; + } + return $responses; + } + + /** + * @desc Prints a summary of a response. + * @param $question object The question object. + * @param $state object The state object. + * @return string HTML. + */ + function response_summary($question, $state, $length=80) { + // This should almost certainly be overridden + $responses = $this->get_actual_response($question, $state); + if (empty($responses) || !is_array($responses)) { + $responses = array(); + } + if (is_array($responses)) { + $responses = implode('<br/><br/>', $responses); + } + return $responses;//substr($responses, 0, $length); + } + + /** + * Changes all states for the given attempts over to a new question + * + * This is used by the versioning code if the teacher requests that a question + * gets replaced by the new version. In order for the attempts to be regraded + * properly all data in the states referring to the old question need to be + * changed to refer to the new version instead. In particular for question types + * that use the ... [truncated message content] |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:57:10
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle/question/type/webwork/simpletest In directory devel.webwork.rochester.edu:/tmp/cvs-serv67594/simpletest Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle/question/type/webwork/simpletest added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:56:55
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle/question/type/webwork/db In directory devel.webwork.rochester.edu:/tmp/cvs-serv67561/db Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle/question/type/webwork/db added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:56:40
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle/question/type/webwork In directory devel.webwork.rochester.edu:/tmp/cvs-serv67545/webwork Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle/question/type/webwork added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:56:23
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle/question/type In directory devel.webwork.rochester.edu:/tmp/cvs-serv67507/type Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle/question/type added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:56:19
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle/question In directory devel.webwork.rochester.edu:/tmp/cvs-serv67495/question Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle/question added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:55:39
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle/lang/en_utf8/help/webwork In directory devel.webwork.rochester.edu:/tmp/cvs-serv67467/webwork Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle/lang/en_utf8/help/webwork added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:55:20
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle/lang/en_utf8/help/quiz In directory devel.webwork.rochester.edu:/tmp/cvs-serv67442/quiz Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle/lang/en_utf8/help/quiz added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:55:19
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle/lang/en_utf8/help In directory devel.webwork.rochester.edu:/tmp/cvs-serv67430/help Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle/lang/en_utf8/help added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:50:42
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle/lang/en_utf8 In directory devel.webwork.rochester.edu:/tmp/cvs-serv67313/en_utf8 Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle/lang/en_utf8 added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:50:34
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle/lang In directory devel.webwork.rochester.edu:/tmp/cvs-serv67301/lang Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle/lang added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:49:49
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/bin In directory devel.webwork.rochester.edu:/tmp/cvs-serv67252/bin Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/bin added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:49:49
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/moodle In directory devel.webwork.rochester.edu:/tmp/cvs-serv67240/moodle Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/moodle added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:35:35
|
Log Message: ----------- Help Files Initial Add Added Files: ----------- wwmoodle/wwquestion/lang/en_utf8/help/quiz: webwork.html wwmoodle/wwquestion/lang/en_utf8/help/webwork: codecheck.html codeheader.html fileheader.html seed.html trials.html Revision Data ------------- |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:34:31
|
Update of /webwork/cvs/system/wwmoodle/wwquestion/lang/en_utf8/help/quiz In directory devel.webwork.rochester.edu:/tmp/cvs-serv66248/quiz Log Message: Directory /webwork/cvs/system/wwmoodle/wwquestion/lang/en_utf8/help/quiz added to the repository |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 22:34:04
|
Log Message: ----------- Help Files Modified Files: -------------- wwmoodle/wwquestion/lang/en_utf8/help/webwork: code.html Revision Data ------------- |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 20:19:08
|
Log Message: ----------- showPartialCorrectAnswers support. Modified Files: -------------- ww_question_server/bin/setup: setup.pl ww_question_server/lib: ProblemServer.pm ww_question_server/lib/ProblemServer: ProblemResponse.pm Revision Data ------------- Index: setup.pl =================================================================== RCS file: /webwork/cvs/system/ww_question_server/bin/setup/setup.pl,v retrieving revision 1.6 retrieving revision 1.7 diff -Lbin/setup/setup.pl -Lbin/setup/setup.pl -u -r1.6 -r1.7 --- bin/setup/setup.pl +++ bin/setup/setup.pl @@ -266,19 +266,40 @@ system('mv WSDL.wsdl ' . $root . '/htdocs/WSDL.wsdl'); } -print "Setting Directory Permissions\n"; -system("chmod -R 777 $root/tmp"); -system("chmod -R 777 $root/htdocs/tmp"); -print "Done\n"; + +$dirPerm = promptUser('Do you want me to set directory permissions(requires sudo) (y,n)','y'); +if($dirPerm eq 'y') { + print "Setting Directory Permissions\n"; + system("sudo chmod -R 777 $root/tmp"); + system("sudo chmod -R 777 $root/htdocs/tmp"); + print "Done\n"; +} print "********************************\n"; print "Your WSDL path: '" . $hostname . $files . '/'.$wsdlfilename."'\n"; print "********************************\n"; print "POST INSTALL\n"; -print "1) Append the following line to your apache configuration file:\n"; +$i = 1; +if($copyFiles eq 'n') { + print "$i) Copy the following files to their respective destinations\n"; + print "global.conf" . ' => ' . $root . "/conf/global.conf\n"; + print "problemserver.apache-config" . ' => ' .$root . "/conf/problemserver.apache-config\n"; + print "WSDL.wsdl" . ' => ' . $root . "/htdocs/WSDL.wsdl\n\n"; + $i++; +} + +if($dirPerm eq 'n') { + print "$i) Set the permissions on the following directories so they are read/write accessible by your webserver\n"; + print "$root/tmp\n"; + print "$root/htdocs/tmp\n\n"; + $i++; +} + +print "$i) Append the following line to your apache configuration file:\n"; print "Include $root/conf/problemserver.apache-config\n\n"; +$i++; -print "2) Restart Apache\n"; +print "$i) Restart Apache\n"; print "Your done, Enjoy!\n"; Index: ProblemServer.pm =================================================================== RCS file: /webwork/cvs/system/ww_question_server/lib/ProblemServer.pm,v retrieving revision 1.12 retrieving revision 1.13 diff -Llib/ProblemServer.pm -Llib/ProblemServer.pm -u -r1.12 -r1.13 --- lib/ProblemServer.pm +++ lib/ProblemServer.pm @@ -59,6 +59,8 @@ #Keep the Default Problem Environment $self->{problemEnviron} = ($self->{serverEnviron}{problemEnviron}); + $self->{safe} = new Safe; + bless $self; return $self; } @@ -166,7 +168,7 @@ #PRE-LOAD MACRO FILES eval{$self->{translator}->pre_load_macro_files( - new Safe, + $self->{safe}, $self->{serverEnviron}->{pg}->{directories}->{macros}, 'PG.pl', 'dangerousMacros.pl','IO.pl','PGbasicmacros.pl','PGanswermacros.pl' )}; @@ -298,6 +300,7 @@ $response->{warnings} = $self->{warnings}; $response->{output} = encode_base64(${$self->{translator}->r_text}); $response->{seed} = $self->{translator}->{envir}{problemSeed}; + $response->{grading} = $self->{translator}->rh_flags->{showPartialCorrectAnswers}; return $response; } sub clean { Index: ProblemResponse.pm =================================================================== RCS file: /webwork/cvs/system/ww_question_server/lib/ProblemServer/ProblemResponse.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -Llib/ProblemServer/ProblemResponse.pm -Llib/ProblemServer/ProblemResponse.pm -u -r1.3 -r1.4 --- lib/ProblemServer/ProblemResponse.pm +++ lib/ProblemServer/ProblemResponse.pm @@ -6,6 +6,7 @@ _ATTR warnings $string Any warnings from translation _ATTR errors $string Any errors from translation _ATTR seed $string The seed of the question. + _ATTR grading $string The grading option for the question. =end WSDL =cut sub new { @@ -16,6 +17,7 @@ $self->{warnings} = ""; $self->{errors} = ""; $self->{seed} = ""; + $self->{grading} = ""; bless $self; return $self; } |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 20:17:57
|
Log Message: ----------- New Unit Testing, ensures proper setup. Added Files: ----------- wwmoodle/wwquestion/simpletest: sampleProblem.pg testquestiontype.php Revision Data ------------- --- /dev/null +++ wwquestion/simpletest/sampleProblem.pg @@ -0,0 +1,30 @@ +# marks_first_test.pg #Standard Probability Problem #Drawing colored marbles from a bag + +DOCUMENT(); + +loadMacros("PG.pl", + "PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + "PGauxiliaryFunctions.pl"); + +TEXT(beginproblem()); +$showPartialCorrectAnswers = 0; + +$total = random(15,25,1); +$some = random(5,10,1); + +BEGIN_TEXT; +You own $total CDs. You want to randomly arrange $some of them in a CD rack. +What is the probability that the rack ends up in alphabetical order? +$BR +$BR +The probability that the CDs are in alphabetical order is \{ans_rule(15)\}. +END_TEXT + +$ans = 1/fact($some); + +ANS(num_cmp($ans, mode => 'std')); + +ENDDOCUMENT(); + |
From: Matt L. v. a. <we...@ma...> - 2007-09-11 20:16:43
|
Log Message: ----------- Version .4 Partial Answer Questions now supported Modified Files: -------------- wwmoodle/wwquestion: README.txt config.php display.html edit_webwork_form.php file.php locallib.php questiontype.php version.txt wwmoodle/wwquestion/db: install.xml wwmoodle/wwquestion/lang/en_utf8: qtype_webwork.php Revision Data ------------- Index: config.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/config.php,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwquestion/config.php -Lwwquestion/config.php -u -r1.1 -r1.2 --- wwquestion/config.php +++ wwquestion/config.php @@ -1,7 +1,7 @@ <?php //Path to the WSDL file on the Webwork Server -define('WWQUESTION_WSDL','http://128.151.231.20/problemserver_files/WSDL.wsdl'); +define('WWQUESTION_WSDL','ENTER YOUR WSDL PATH HERE','WSDL Path Test'); //Leave the rest alone define('WWQUESTION_PREFIX','/wwquestions'); Index: version.txt =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/version.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwquestion/version.txt -Lwwquestion/version.txt -u -r1.1 -r1.2 --- wwquestion/version.txt +++ wwquestion/version.txt @@ -1,5 +1,12 @@ Old versions: +Version .3 (9/11/2007) +* Derivation mismatch bugs fixed. +* New Test file +* External File support! (applet,images,graphs,etc) +* Code Refactoring +* New levels of Code Checking including warnings + Version .2 (August 2007) * DB consistency issues fixed (thanks to Jean-Marc) * New code checking, makes sure PG code is correct Index: display.html =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/display.html,v retrieving revision 1.7 retrieving revision 1.8 diff -Lwwquestion/display.html -Lwwquestion/display.html -u -r1.7 -r1.8 --- wwquestion/display.html +++ wwquestion/display.html @@ -17,9 +17,12 @@ <?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> @@ -31,12 +34,14 @@ <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> Index: README.txt =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/README.txt,v retrieving revision 1.5 retrieving revision 1.6 diff -Lwwquestion/README.txt -Lwwquestion/README.txt -u -r1.5 -r1.6 --- wwquestion/README.txt +++ wwquestion/README.txt @@ -1,122 +1,47 @@ Webwork Question Type ---------------------- -Version: 0.3 (stable) Released 9/9/2007 +Version: 0.4 (stable) Released 9/11/2007 Maintainer: Matthew Leventi <mle...@gm...> CVS: cvs.webwork.rochester.edu:/webwork/cvs/system wwmoodle/wwquestion -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. +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. Almost all WeBWorK questions should work with this system. (If you find one that doesnt send me a copy). * 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 -mysql command: ALTER TABLE mdl_question_webwork ADD COLUMN codecheck int(10) not null default 0; -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. +* Show Partial Answer Questions Work! +* New Unit Tests to ensure proper setup. +* Code refactoring + +Upgrading: +Backward Compatibility of existing questions is not guaranteeded. To upgrade your Database loading and unloading the webwork DB file in the XMLDB editor should make the necessary changes. Setup: 1) Make a new folder named 'webwork' in the question/type directory. -2) Copy all the files from this directory into . +2) Copy all the files into the new 'webwork' directory. 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/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 - -trials: The number of attempts the generator should make to generate and cache problems. - -Finding webwork questions: -http://cvs.webwork.rochester.edu/viewcvs.cgi/rochester_problib/?cvsroot=UR+Problem+Library (for now) - -Note: -Previewing the question will use random seeds. - -Example Problem: - -##DESCRIPTION - -# Singularities, Determine Type (Poles), Residues - -##ENDDESCRIPTION - - -DOCUMENT(); # This should be the first executable line in the problem. - -loadMacros( - "PGstandard.pl", # Standard macros for PG language - "MathObjects.pl", - "PGunion.pl", # Union College macros - #"PGcourse.pl", # Customization file for the course -); - -TEXT(beginproblem()); -$showPartialCorrectAnswers = 1; - -############################################################## -# -# Setup -# -Context("Point"); - -$a = non_zero_random(-10,10,1); - -$formula_string = Formula( "sin(1/($a*z))" ); - -@singularities = ("(0, 1/$a)" ); -$f = Compute("(0,1/$a)"); -############################################################## -# -# Text -# -# -Context()->texStrings; -BEGIN_TEXT - -Find the singularities and their residues for $PAR - -\[ $formula_string \] - -$PAR -\{ans_rule(60)\} -$PAR -List the singularities and their residues as ordered pairs. (for example, -(3, pi), (-1,2) means that there is a singularity at \(3\) with residue \(\pi\) -and a singularity at \(-1\) with residue \(2\). - -$PA -END_TEXT -Context()->normalStrings; -############################################################## -# -# Answers -# -# - -ANS(List(@singularities)->cmp(correct_ans=>$f->{correct_ans}) ); - - - -ENDDOCUMENT(); # This should be the last executable line in the problem. - +Testing: +1) In the site administration -> reports -> unit tests run the webwork unit tests. Enter '/question/type/webwork/simpletest' to only run the webwork tests. +Use: +Go into the question bank and create a new WeBWorK question. Besides the usual question options there are a few WeBWorL specific fields. +Code -> Copy and paste the PG code into this field. +Files -> Upload any necessary external files that the question depends on. +Code Check -> This determines how strict the checker should be in determining whether your question works +Seed -> The starting seed on which to create question derivations. +Trials -> The number of derivations to create. (Roughly) +Note on Question Creation: +As you increase trials question creation will take longer. If you need a lot of external files question creation will also take longer. Longest time I have seen is about a minute. The reason for the delay involves the creation of derived questions based on the PG code. It means that viewing of questions should be very fast. Student answer checks will also be faster. +Note on Randomness: +WeBWorK Questions are not truly random within this module. The trials option determines the size of a pool of questions that are generated from the PG code. Students will get a random derivation out of the pool as the question they have to answer. When an instructor previews a question in the bank he/she will see a random seed. +Finding webwork questions: +http://cvs.webwork.rochester.edu/viewcvs.cgi/rochester_problib/?cvsroot=UR+Problem+Library (for now) +An example can be found in simpletest/sampleProblem.pg as well. Index: questiontype.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/questiontype.php,v retrieving revision 1.12 retrieving revision 1.13 diff -Lwwquestion/questiontype.php -Lwwquestion/questiontype.php -u -r1.12 -r1.13 --- wwquestion/questiontype.php +++ wwquestion/questiontype.php @@ -54,6 +54,7 @@ $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; @@ -79,6 +80,12 @@ $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 @@ -213,6 +220,8 @@ $unparsedhtml = base64_decode($derivation->html); + //partial answers + $showPartiallyCorrectAnswers = $question->grading; //new array keyed by field $fieldhash = $state->responses['answers']; @@ -228,7 +237,9 @@ if(($nodename == "INPUT") || ($nodename == "SELECT") || ($nodename == "TEXTAREA")) { $parser->iNodeAttributes['name'] = 'resp' . $question->id . '_' . $name; if(($state->event == QUESTION_EVENTGRADE) && (isset($fieldhash[$name]))) { - $parser->iNodeAttributes['class'] = $parser->iNodeAttributes['class'] . ' ' . question_get_feedback_class($fieldhash[$name]['score']); + if($showPartiallyCorrectAnswers) { + $parser->iNodeAttributes['class'] = $parser->iNodeAttributes['class'] . ' ' . question_get_feedback_class($fieldhash[$name]['score']); + } } if(!strstr($name,'previous')) { $answerfields[$name] = $fieldhash[$name]; @@ -255,6 +266,8 @@ $qid = $question->id; $seed = $state->responses['seed']; + + //if the student has answered include("$CFG->dirroot/question/type/webwork/display.html"); } @@ -285,6 +298,7 @@ $problem = array(); $problem['code'] = $code; $problem['seed'] = $seed; + $problem['files']= array(); //SOAP request $params = array(); @@ -409,23 +423,40 @@ } /** - * @desc Prints a short 40 character limited version of all the answers for a question. + * @desc Enumerates the pictures for a response. * @param $question object The question object. * @param $state object The state object. + * @return array HTML code with <img> tag for each picture. */ function get_actual_response($question, $state) { $temp = ''; $i = 1; foreach($state->responses['answers'] as $key => $value) { - $temp .= "$i) " . $value['answer'] . " "; + $responses[] = "$i) " . $value['preview']; $i++; } - $lmax = 40; - $responses[] = (strlen($temp) > $lmax) ? substr($temp, 0, $lmax).'...' : $temp; return $responses; } /** + * @desc Prints a summary of a response. + * @param $question object The question object. + * @param $state object The state object. + * @return string HTML. + */ + function response_summary($question, $state, $length=80) { + // This should almost certainly be overridden + $responses = $this->get_actual_response($question, $state); + if (empty($responses) || !is_array($responses)) { + $responses = array(); + } + if (is_array($responses)) { + $responses = implode('<br/><br/>', $responses); + } + return $responses;//substr($responses, 0, $length); + } + + /** * Changes all states for the given attempts over to a new question * * This is used by the versioning code if the teacher requests that a question @@ -529,6 +560,28 @@ } /** + * Renders the question for printing and returns the LaTeX source produced + * + * This function should render the question suitable for a printed problem + * or solution sheet in LaTeX and return the rendered output. + * @return string The LaTeX output. + * @param object $question The question to be rendered. Question type + * specific information is included. + * @param object $state The state to render the question in. The + * question type specific information is also + * included. + * @param object $cmoptions + * @param string $type Indicates if the question or the solution is to be + * rendered with the values 'question' and + * 'solution'. + */ + function get_texsource(&$question, &$state, $cmoptions, $type) { + // The default implementation simply returns a string stating that + // the question is only available online. + return get_string('onlineonly', 'texsheet'); + } + + /** * Backup the data in the question * * This is used in question/backuplib.php Index: edit_webwork_form.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/edit_webwork_form.php,v retrieving revision 1.5 retrieving revision 1.6 diff -Lwwquestion/edit_webwork_form.php -Lwwquestion/edit_webwork_form.php -u -r1.5 -r1.6 --- wwquestion/edit_webwork_form.php +++ wwquestion/edit_webwork_form.php @@ -54,11 +54,13 @@ $codecheckoptions = array( 0 => get_string('edit_codecheck0','qtype_webwork'), 1 => get_string('edit_codecheck1','qtype_webwork'), - 2 => get_string('edit_codecheck2','qtype_webwork')); + 2 => get_string('edit_codecheck2','qtype_webwork'), + 3 => get_string('edit_codecheck3','qtype_webwork'), + 4 => get_string('edit_codecheck4','qtype_webwork')); $mform->addElement('select','codecheck', get_string('edit_codecheck', 'qtype_webwork'),$codecheckoptions); $mform->setType('codecheck',PARAM_INT); $mform->setHelpButton('codecheck', array('codecheck', get_string('edit_codecheck', 'qtype_webwork'), 'webwork')); - $mform->setDefault('codecheck',2); + $mform->setDefault('codecheck',4); //SEED $mform->addElement('text', 'seed', get_string('edit_seed','qtype_webwork'), @@ -83,164 +85,26 @@ function validation($data) { global $CFG; - //check that the code is valid - $err = $this->codecheck($data); - if($err != false) { - return $err; - } - return true; - } - - function codecheck($data) { - - //codechecklevel - $codechecklevel = $data['codecheck']; - //here we construct a temp question object - $question = new stdClass; - $question->code = base64_encode(stripslashes($data['code'])); - $question->seed = $data['seed']; - $question->trials = $data['trials']; - //temporary solution - if(!isset($this->question->webworkid)) { - $path = webwork_get_tmp_path_full(); - $urlpath = webwork_get_filehandler_path() . '/' . webwork_get_tmp_path() . '/'; + //is this a copy of a current question + if(isset($this->_form->_submitValues['makecopy'])) { + $questioncopy = true; } else { - $path = webwork_get_wwquestion_path_full($this->question->webworkid); - $urlpath = webwork_get_filehandler_path() . '/' . webwork_get_wwquestion_path($this->question->webworkid) . '/'; - } - $filelist = list_directories_and_files($path); - $filearray = array(); - - foreach($filelist as $file) { - if(!is_dir($path . '/' . $file)) { - $encode = base64_encode($urlpath . '/' . $file); - array_push($filearray,$encode); - } - - } - $question->files = $filearray; - - //one call to the server will return response for this code and keep it static in the function - $results = webwork_get_derivations($question); - //127.0.0.1 - //no code check - if($codechecklevel == 0) { - webwork_qtype::_derivations($results); - return false; - } - - //init error array - $errorresults = array(); - $noerrorresults = array(); - - //see if we got errors (split) - foreach($results as $record) { - if((isset($record['errors'])) && ($record['errors'] != '') && ($record['errors'] != null)) { - array_push($errorresults,$record); - } else { - array_push($noerrorresults,$record); - } - } - - $goodresults = array(); - $warningresults = array(); - - foreach($noerrorresults as $record) { - if((isset($record['warnings'])) && ($record['warnings'] != '') && ($record['warnings'] != null)) { - array_push($warningresults,$record); - } else { - array_push($goodresults,$record); - } - - } - - - //if there are good seeds we use those - if((count($goodresults) > 0) && ($codechecklevel == 1)) { - webwork_qtype::_derivations($goodresults); - return false; - } - - //if code check is strict - if(count($goodresults) == count($results)) { - webwork_qtype::_derivations($results); - return false; + $questioncopy = false; } + //webwork_question id + $wwquestionid = $this->question->webworkid; - $errormsgs = array(); - $warningmsgs = array(); - //at this point we are going to be invalid - //this correlates seeds with certain error messages for better output - //ERRORS - foreach($errorresults as $record) { - $found = 0; - $candidate = $record['errors'] . "<br>"; - $candidateseed = $record['seed']; - for($i=0;$i<count($errormsgs);$i++) { - if($candidate == $errormsgs[$i]['errors']) { - $found = 1; - $errormsgs[$i]['seeds'][] = $candidateseed; - } - } - if($found == 0) { - //new error message - $msg = array(); - $msg['errors'] = $candidate; - $msg['seeds'] = array(); - $msg['seeds'][] = $candidateseed; - $errormsgs[] = $msg; - } + //codecheck + $result = webwork_codecheck($data,$wwquestionid,$questioncopy); + if(is_array($result)) { + return $result; } - //WARNINGS - foreach($warningresults as $record) { - $found = 0; - $candidate = $record['warnings'] . "<br>"; - $candidateseed = $record['seed']; - for($i=0;$i<count($warningmsgs);$i++) { - if($candidate == $warningmsgs[$i]['errors']) { - $found = 1; - $warningmsgs[$i]['seeds'][] = $candidateseed; - } - } - if($found == 0) { - //new error message - $msg = array(); - $msg['warnings'] = $candidate; - $msg['seeds'] = array(); - $msg['seeds'][] = $candidateseed; - $warningmsgs[] = $msg; - } - - } - $output = "Errors in PG Code on: " . count($errorresults) . " out of " . count($results) . " seeds tried:<br>"; - //construct error statement - $counter = 1; - foreach($errormsgs as $msg) { - $output .= "$counter) "; - $output .= "Seeds ("; - foreach ($msg['seeds'] as $seed) { - $output .= $seed . " "; - } - $output .= ") gave Errors:" . $msg['errors'] . "<br><br>"; - $counter++; - } - $output .= "Warnings in PG Code on: " . count($warningresults) . " out of " . count($results) . " seeds tried:<br>"; - $counter = 1; - foreach($warningmsgs as $msg) { - $output .= "$counter) "; - $output .= "Seeds ("; - foreach ($msg['seeds'] as $seed) { - $output .= $seed . " "; - } - $output .= ") gave Warnings:" . $msg['warnings'] . "<br><br>"; - $counter++; - } - $returner =array(); - $returner['code'] = $output; - return $returner; + return true; } + + function qtype() { return 'webwork'; } Index: file.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/file.php,v retrieving revision 1.2 retrieving revision 1.3 diff -Lwwquestion/file.php -Lwwquestion/file.php -u -r1.2 -r1.3 --- wwquestion/file.php +++ wwquestion/file.php @@ -29,13 +29,12 @@ } //extra security for users - if($args[1] == 'users') { + /*if((count($args) > 6) && ($args[5] == 'users')) { //trying to get a user equation image - //BEEF this up with roles etc, so teachers have access to students pics so on. - if($args[2] != $USER->id) { - error('Access Denied to this Equation Image'); + if($args[6] != $USER->id) { + require_capability('moodle/mod/quiz:viewreports'); } - } + }*/ Index: locallib.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/locallib.php,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwquestion/locallib.php -Lwwquestion/locallib.php -u -r1.1 -r1.2 --- wwquestion/locallib.php +++ wwquestion/locallib.php @@ -1,6 +1,7 @@ <?php require_once("$CFG->dirroot/question/type/webwork/config.php"); +require_once("$CFG->dirroot/question/type/webwork/questiontype.php"); require_once("$CFG->libdir/soap/nusoap.php"); require_once("$CFG->libdir/filelib.php"); require_once("$CFG->libdir/setuplib.php"); @@ -166,6 +167,183 @@ return true; } +function webwork_codecheck($data,$wwquestionid,$questioncopy) { + //codechecklevel + $codechecklevel = $data['codecheck']; + + //here we construct a temp question object + $question = new stdClass; + $question->code = base64_encode(stripslashes($data['code'])); + $question->seed = $data['seed']; + $question->trials = $data['trials']; + + //handle the new question from old functionality + if($questioncopy) { + webwork_make_tmp_dir(); + $path = webwork_get_wwquestion_path_full($wwquestionid); + $filelist = list_directories_and_files($path); + //copy everthing but derivations folder into tmp folder + foreach($filelist as $file) { + if($file != 'derivations') { + webwork_copy_file("$path/$file",webwork_get_tmp_path_full() . '/' . $file); + } + } + } + + + //should we look in tmp or in wwquestion dir to find stuff + if(!isset($wwquestionid)) { + $path = webwork_get_tmp_path_full(); + $urlpath = webwork_get_filehandler_path() . '/' . webwork_get_tmp_path() . '/'; + } else { + $path = webwork_get_wwquestion_path_full($this->question->webworkid); + $urlpath = webwork_get_filehandler_path() . '/' . webwork_get_wwquestion_path($this->question->webworkid) . '/'; + } + $filelist = list_directories_and_files($path); + $filearray = array(); + + //files that need to be pushed + foreach($filelist as $file) { + if(!is_dir($path . '/' . $file)) { + $encode = base64_encode($urlpath . '/' . $file); + array_push($filearray,$encode); + } + } + + $question->files = $filearray; + + //one call to the server will return response for this code and keep it static in the function + $results = webwork_get_derivations($question); + + //filter errors and warnings + $errorresults = array(); + $noerrorresults = array(); + $warningresults = array(); + $goodresults = array(); + foreach($results as $record) { + if((isset($record['errors'])) && ($record['errors'] != '') && ($record['errors'] != null)) { + array_push($errorresults,$record); + } else { + array_push($noerrorresults,$record); + } + } + foreach($noerrorresults as $record) { + if((isset($record['warnings'])) && ($record['warnings'] != '') && ($record['warnings'] != null)) { + array_push($warningresults,$record); + } else { + array_push($goodresults,$record); + } + } + + switch($codechecklevel) { + //No code check + case 0: + webwork_qtype::_derivations($results); + return true; + break; + //reject seeds with errors + case 1: + if(count($noerrorresults) > 0) { + webwork_qtype::_derivations($noerrorresults); + return true; + } + break; + //reject if errors + case 2: + if(count($noerrorresults) == count($results)) { + webwork_qtype::_derivations($results); + return true; + } + break; + //reject seeds with errors or warnings + case 3: + if(count($goodresults) > 0) { + webwork_qtype::_derivations($goodresults); + return true; + } + break; + //reject if errors or warnings + case 4: + if(count($goodresults) == count($results)) { + webwork_qtype::_derivations($results); + return true; + } + break; + } + + $errormsgs = array(); + $warningmsgs = array(); + //at this point we are going to be invalid + //this correlates seeds with certain error messages for better output + //ERRORS + foreach($errorresults as $record) { + $found = 0; + $candidate = $record['errors'] . "<br>"; + $candidateseed = $record['seed']; + for($i=0;$i<count($errormsgs);$i++) { + if($candidate == $errormsgs[$i]['errors']) { + $found = 1; + $errormsgs[$i]['seeds'][] = $candidateseed; + } + } + if($found == 0) { + //new error message + $msg = array(); + $msg['errors'] = $candidate; + $msg['seeds'] = array(); + $msg['seeds'][] = $candidateseed; + $errormsgs[] = $msg; + } + } + //WARNINGS + foreach($warningresults as $record) { + $found = 0; + $candidate = $record['warnings'] . "<br>"; + $candidateseed = $record['seed']; + for($i=0;$i<count($warningmsgs);$i++) { + if($candidate == $warningmsgs[$i]['errors']) { + $found = 1; + $warningmsgs[$i]['seeds'][] = $candidateseed; + } + } + if($found == 0) { + //new error message + $msg = array(); + $msg['warnings'] = $candidate; + $msg['seeds'] = array(); + $msg['seeds'][] = $candidateseed; + $warningmsgs[] = $msg; + } + + } + $output = "Errors in PG Code on: " . count($errorresults) . " out of " . count($results) . " seeds tried:<br>"; + //construct error statement + $counter = 1; + foreach($errormsgs as $msg) { + $output .= "$counter) "; + $output .= "Seeds ("; + foreach ($msg['seeds'] as $seed) { + $output .= $seed . " "; + } + $output .= ") gave Errors:" . $msg['errors'] . "<br><br>"; + $counter++; + } + $output .= "Warnings in PG Code on: " . count($warningresults) . " out of " . count($results) . " seeds tried:<br>"; + $counter = 1; + foreach($warningmsgs as $msg) { + $output .= "$counter) "; + $output .= "Seeds ("; + foreach ($msg['seeds'] as $seed) { + $output .= $seed . " "; + } + $output .= ") gave Warnings:" . $msg['warnings'] . "<br><br>"; + $counter++; + } + $returner =array(); + $returner['code'] = $output; + return $returner; +} + ////////////////////////////////////////////////////////////////////////////////// //WEBWORK FILE RESOLVERS ////////////////////////////////////////////////////////////////////////////////// Index: install.xml =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/db/install.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -Lwwquestion/db/install.xml -Lwwquestion/db/install.xml -u -r1.4 -r1.5 --- wwquestion/db/install.xml +++ wwquestion/db/install.xml @@ -11,7 +11,8 @@ <FIELD NAME="codecheck" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="question" NEXT="code"/> <FIELD NAME="code" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="codecheck" NEXT="seed"/> <FIELD NAME="seed" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="code" NEXT="trials"/> - <FIELD NAME="trials" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="seed"/> + <FIELD NAME="trials" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" NEXT="grading" PREVIOUS="seed"/> + <FIELD NAME="grading" TYPE="int" LENGTH="10" NUTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="trials"/> </FIELDS> <KEYS> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for question_webwork" NEXT="question"/> Index: qtype_webwork.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwquestion/lang/en_utf8/qtype_webwork.php,v retrieving revision 1.4 retrieving revision 1.5 diff -Lwwquestion/lang/en_utf8/qtype_webwork.php -Lwwquestion/lang/en_utf8/qtype_webwork.php -u -r1.4 -r1.5 --- wwquestion/lang/en_utf8/qtype_webwork.php +++ wwquestion/lang/en_utf8/qtype_webwork.php @@ -20,7 +20,9 @@ $string['edit_codecheck'] = 'Code Checking'; $string['edit_codecheck0'] = 'Turn Off (unadvised)'; $string['edit_codecheck1'] = 'Reject Problem Seeds w/ Errors (silent)'; - $string['edit_codecheck2'] = 'Reject Question if any Errors (strict)'; + $string['edit_codecheck2'] = 'Reject Question if any Errors exist (strict)'; + $string['edit_codecheck3'] = 'Reject Problem Seeds w/ Errors or Warnings (silent)'; + $string['edit_codecheck4'] = 'Reject Question if any Errors or Warnings exist (strict)'; $string['edit_codefile'] = 'Question File'; $string['edit_addcodefiles'] = 'Add More Question Files'; $string['edit_code'] = 'Code'; |
From: dpvc v. a. <we...@ma...> - 2007-09-11 14:14:25
|
Log Message: ----------- A couple of syntax issues. Modified Files: -------------- pg/lib/Parser: Differentiation.pm Revision Data ------------- Index: Differentiation.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Parser/Differentiation.pm,v retrieving revision 1.13 retrieving revision 1.14 diff -Llib/Parser/Differentiation.pm -Llib/Parser/Differentiation.pm -u -r1.13 -r1.14 --- lib/Parser/Differentiation.pm +++ lib/Parser/Differentiation.pm @@ -13,7 +13,7 @@ sub Parser::D { my $self = shift; my $d; my @x = @_; my $x; - if (defined(@x[0]) && $x[0] =~ m/^\d+$/) { + if (defined($x[0]) && $x[0] =~ m/^\d+$/) { $d = shift(@x); $self->Error("You can only specify one variable when you give a derivative count") unless scalar(@x) <= 1; @@ -29,7 +29,7 @@ $self->Error("You must specify a variable to differentiate by") unless $n == 1; $x = $vars[0]; } - push(@x,$x); + CORE::push(@x,$x); } @x = ($x[0]) x $d if $d; my $f = $self->{tree}; |
From: dpvc v. a. <we...@ma...> - 2007-09-10 23:28:01
|
Log Message: ----------- Don't factor negatives out of multiple terms at once. Modified Files: -------------- pg/macros: contextLimitedPolynomial.pl Revision Data ------------- Index: contextLimitedPolynomial.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedPolynomial.pl,v retrieving revision 1.12 retrieving revision 1.13 diff -Lmacros/contextLimitedPolynomial.pl -Lmacros/contextLimitedPolynomial.pl -u -r1.12 -r1.13 --- macros/contextLimitedPolynomial.pl +++ macros/contextLimitedPolynomial.pl @@ -361,6 +361,10 @@ "${_}h"=>{class => 'LimitedPolynomial::Function::hyperbolic'} ); } + # + # Don't convert -ax-b to -(ax+b), etc. + # + $context->reduction->set("(-x)-y"=>0); main::Context("LimitedPolynomial"); ### FIXME: probably should require author to set this explicitly } |