On Martin's suggestion, I am responding here to my previous post in
the "Teaching Online" forum and his response to it.
Briefly I want to interface Moodle to the web-based symbolic math.
problem generating/grading systems WIMS (http://wims.unice.fr/wims/)
and WeBWorK (http://webwork.math.rochester.edu/docs/docs/). [These
are open source systems, with GPL or GPL-like licenses.]
The resource->PROGRAM feature of Moodle 1.8 provides an effective
1-way channel of communication from Moodle to such systems. I was
trying to find some way of opening a channel in the opposite direction,
which those systems could use to report back to Moodle on the students'
progress on their assignments/tests/quizes within those system.
Since then I have had an idea about doing this. It is a bit of a
clunky solution, but it seems to me that it would not be very difficult
Briefly here's how it would work. Suppose I want my students to work
on an assignment in the WeBWorK system. I would create two activities
in my course: (1) a "program resource" linking to WeBWorK and (2) an
"offline assignment" which would contain the students' scores on the
Essentially all the work involved in implementing (1) is on the WeBWorK
side, and it's no problem for me. However to implement (2), I need to
do some hacking on the Moodle side. What I propose to do is to rip
some code from assignment/*.php to implement an interface
which would take in the following input data: (a) student's name
(b) assignment identifier (c) grade for the assignment (d) timestamp
(e) request authentication key, and then update the Moodle database
with the indicated grade for that assignment. The request authentication
key (e) would be the md5 hash of data (a)-(d) with a shared secret key
between Moodle and WeBWorK.
I've noticed a second (and from my point of view even more important)
reason to implement such an interface. There seems to no way (IS THERE?)
in Moodle to batch upload grades for an offline assignment (e.g. written
exams/quizes) -- one needs to manually enter grades for each individual
student. This is burdensome and error-prone for large classes.
Before I start working on this, I would like to get Martin's reaction
about the feasibility of this proposal. Also if any of you out there
have done some work along these lines, I would like to hear from you.
One additional point: in my setup Moodle and the external programs would all be running on the same Linux server.
Since my replies might be of some general interest, I am reposting them here.
I've already implemented the interface from Moodle to WeBWorK.
If I enter the following URL into Moodle as a "program resource"
Moodle adds the following user/authentication information (when I am logged in as guest):
to obtain the following URL
You can try it out yourself. You may need to recombine the URL into a single line if your mailer split it up.
What I am now looking at is implementing the interface in the opposite direction.
I am not exactly sure what you are looking for. Do you want to be able
to write physics problems for some hypothetical e-learning system using
Microsoft Word? That's not what WeBWorK is designed to do.
In WeBWorK each problem is a Perl script which emits Latex output.
The Latex output is then dynamically converted to html with gif/png
graphics which is sent to the client browser. When MathML is better
supported by Microsoft IE, the WeBWorK developers intend to process the
output into MathML instead of html/gif/png.
To write a WeBWorK problem you need to have some knowledge of both
Perl and Latex. I am afraid that if you want to write sophisticated
mathematics or physics problems, some programming will be need to be
The philosophy behind WeBWorK is not that each individual instructor
is expected to write their own problems. Rather people with some level
of technical expertise will write problems and share them with each
other to create a large library of freely available problems. Currently
there are over 2000 WeBWorK mathematics problems available (and a few
physics problems). It is feasible for an instructor with very minimal
knowledge of Latex/Perl to make some minor modifications in the
I should mention that WeBWorK evolved out of CAPA, a similar but
less sophisticated system for generating physics problems developed
at Michigan State University. While CAPA development seems to have
stagnated in the late 90's, recently they have become more active
again. You might want to search in Google for "CAPA" and "Michigan
State University". By the way, WeBWorK comes with a CAPA to WeBWorK
I think you are overlooking the point that the main difficulty
in these types of problems is that you need some method of checking
the student answers.
Even if the answers are supposed to be purely numerical, some
programming is required, since you will be using some random
parameters in the problems to prevent students from just copying
each others answers.
For more sophisticated problems, you want students to type in
some symbolic mathematical formulas as answers. There is no
mechanism in Moodle + Word for automatically checking such answers.
[WebCT has grading implemented via regular expression checking,
but this is pathetically inadequate.] So you will need to grade
such problems manually, which defeats the supposed advantages
There is supposed to be an some kind of web-based interface to
Mathematica, which might meet your needs. But I have no idea
whether it could be interfaced with Moodle or how efficient it
is if many students are using the system. It's quite expensive,
and I have even less love for Stephen Wolfram than I have for
> I see two options here:
> 1. Ext.Prog. sends back the grade
> 2. Moodles gets the grade
Actually I propose to do something different.
I will have wrapper scripts moodle2wwk.pl
and wwk2moodle.pl. The client browser will
never see a webwork url, just the moodle2wwk.pl
url with appropriate parameters. What will happen
is that whenever the user enters something into
the supplied form, moodle2wwk.pl ships it off
to the appropriate webwork module with an internal
Perl exec() call. The output of the webwork module
is in turn piped through another script wwk2moodle.pl
which replaces all the webwork urls by moodle2wwk urls.
This script will also strip out any links to webwork
which go outside the given assignment and provide a
link back to Moodle. When the student clicks on this
link, the wwk2moodle script will update the Moodle
database using the same php function calls that Moodle
uses to do manual updates.
Here's a link to the current preliminary version of
the moodle2wwk script. The wwk2moodle is not yet
implemented, so the pipe goes to a dummy script.
Oh yes, WeBWorK is open source. The function calls
you are seeing in my script are internal WWK function
I am pretty confident that my approach will work
since I've implemented a similar interface for imbedding
WIMS problems inside WeBWorK problems. [WIMS is the other
symbolic problem generating system I mentioned in my post.]
Here's a URL which demonstrates this:
By the way it is more difficult to currently interface WIMS
with Moodle directly, since it would require a Moodle API on
the individual problem level, rather than at a problem set
implementing a web based interface to a sophisticated symbolic
mathematics system. You might pose a problem which expects
some symbolic math. expression as an answer. But some malicious
hacker (or clever disgruntled student) might enter some dangerous
command in its place which might melt down your server. And it could
be quite difficult to distinguish between a legitimate answer and
something like that.
I would like to come back to your code for moodle - could I download it somewhere?
embedded in them, then you might take a look at Respondus. This
is commercial software into which you can paste Microsoft Word text with
equations. Respondus produces a WebCT quiz from this input, and
can optionally upload this into your WebCT account. It might be feasible
to write software which converts this to some format which Moodle can
use. [There is also a free version of Respondus, but it doesn't accept Word
As to security features of WeBWorK, let me describe how WWK checks
symbolic input for correctness. WWK accepts input in a relaxed form
of Maple syntax (e.g. it accepts xy instead of insisting on x*y). WWK
then parses this input and converts it to an expression tree form, with
numbers and variables as leaves and mathematical operations on the
nodes. WWK then produces 5 (default) sets of random numbers
in the interval from 0 to 1 (default) and substitutes them for the variables.
The resulting numerical expressions are then passed to Perl for evaluation
and the results are compared with results obtained by treating the supplied
correct answer similarly. If the results agree within a certain relative
tolerance, the input answer is accepted as correct. [There are some
potential pitfalls in this approach. For instance with the given defaults
2exp(100x)-2393284exp(-205x) might be accepted as a correct
solution to a linear differential equation instead of 2exp(100x)+3exp(-100x).
But generally it works very well.]
As to the security implications of this approach: First of all the range
of expressions accepted by the WWK algebra parser is much more
limited than that accepted by a general purpose symbolic algebra
package. It would be quite difficult to disguise some evil command
as an algebraic expression which would make sense to the parser.
If the parser can't make sense of the expression it just reports a
syntax error to the user. There is also a second line of defense.
When the transformed expressions are passed to Perl, they are
evaluated in a Perl "safe compartment", where only a small safe
subset of the Perl language is available.
WIMS on the other hand has a different approach. WIMS passes
its input to the public domain symbolic algebra system Maxima.
But before it does so, it changes its working directory to a temporary
directory, and forks a process with user and group id of the
unprivileged user "nobody".
Unfortunately I don't have enough time to get involved with helping with a solution but I'm watching here from the sidelines with great interest!
A small thought I've had is that perhaps a generic system for manually importing a set of results into an "offline" assignment would not actually be too difficult, as long as you can provide a tab-separated file with usernames and scores.
Thanks for providing such a wonderful platform for
us to build upon.
When you do have the time to return to Moodle development,
here are a few requests:
(a) Provide a third type of assignment, "program," which
would work the same way that program resource currently does.
(b) Provide an API for Moodle to accept grades from an external
program (properly authenticated of course), via an appropriate
(c) Moodle authenticates by md5 checksumming data with a shared
secret with the external program. Currently this shared secret
is assumed to be the student's login password. This doesn't
work with WeBWorK since we can't assume the student will use
the same password for both programs. So allow configuration of
a different shared secret with the external program. [I've
hacked my version of Moodle to do this.] Probably the best way
to do it would be have some appropriate input box in program
assignment setup and/or an option in config.php.
Incidentally I would be happy to contribute my wrapper scripts
(once I get them working of course) to some "contributions
archive" on your server under a GPL license.
can try logging into my Moodle course
as user/pwd doe.123/doe.123 to check it out. You can also log
in as guest, but in that case you won't see the grades updated
in Moodle, since that is not provided for guest users.
Since I am completely ignorant of SQL, and not very familiar
with php either, I import the grades into Moodle in a very
I ran into some real weirdities along the way, when I was trying to
get the score back to Moodle. (Getting the score from WeBWorK was
straightforward.) My general approach was to put a hacked version
of the php script moodle/mod/assignment/submissions.php into another
directory moodle/mod2/assignment/ (protected with an htaccess file).
The hacked version has all the authentication stripped out. I then
tried to use lynx (and also curl) to post the appropriate data
to the hacked script. On my home Linux machine, this works flawlessly.
Not on webwork though. The script seems to receive the data, but
it doesn't do anything with it. So I then tried submitting it
manually. There was no problem when I posted to the hacked script
with Mozilla. But with lynx I found I had to post the data twice
before the script responded. That is, the first time I hit the
submit link, the script responded by just redisplaying the same
old data. When I entered it again and hit the submit link again,
the script finally responded by recording the new data. It doesn't
look like it's possible to post data twice this way from the command
line. So then I tried to automate this with a lynx command script.
It worked great when I invoked it without the source/dump option.
But with the source or dump option, it seems that lynx quits
after it gets the update from the first unsuccessful submission.
So then I tried to do this from a Perl script, dumping all the
terminal output to /dev/null. When I invoked the script from
my home machine (but using the webwork server), this worked,
but not when I did all on webwork. To cut the long story
short, I finally got it to work by adding the option -term=xterm.
So now the interface is rather gruesome. One of the scripts
writes a lynx command script and then invokes lynx as above.
There are now 6 scripts in all:
moodle2wwk.pl handles the initial setup, calls
welcomeAction.pl and pipes it to
wwkmoodleWrapper.pl rewrites all the URLs in wwk output
moodle2wA - pipes all output from welcomeAction.pl back to
wwkmoodleWrapper.pl (1 line shell script)
moodle2p8 - pipes all output from processProblem8.pl back to
wwkmoodleWrapper.pl (also 1 line shell script)
return2moodle.pl gets the grades from wwk and then calls the
hacked Moodle script to get information about
where to record the grades in Moodle, with the
output piped to return2moodlep2.pl
return2moodlep2.pl analyzes the information obtained from
the first call to the hacked Moodle script,
prepares an appropriate lynx command script.
then invokes lynx to record the grades thru
the hacked Moodle script. Finally it informs
the user that the grades have been recorded
(or not as the case may be) and provides
a link for returning to Moodle.