Features & Development

Essay Answers and pretending it's past due

Essay Answers and pretending it's past due

by Raghu Gompa -
Number of replies: 2
Dear Davide, in your sample problem set you set up a button to pretend it is past due date. Can you please tell me how you were able to accomplish that? Thanks. .. Raghu
In reply to Raghu Gompa

Re: Essay Answers and pretending it's past due

by Davide Cervone -
I've split this into a separate discussion, since the other one was already getting pretty long, and it was about the discussion-based problems, whereas this one is about the essay problem library.

The button you refer to is inserted using an extra macro file for that purpose. It is called in the PGcourse.pl file, so it is not readily apparent from the source code, but if you follow the PGcourse.pl link, you should see a loadMacros() call to the file Essay_Answers.pl. The contents of that file is:

    if ($displayMode =~ m/HTML/) {
      $pastDue = (defined($inputs_ref->{pastDue}) ? " CHECKED" : "");
         '<DIV ID="source_button" STYLE="float:right; margin-right:2em; text-align:right">'
        .  '<SCRIPT>'
        .  'function showSource () {'
        .  '  window.open("'.$htmlURL."show-source.cgi/$probFileName".'","ww_source");'
        .  '}'
        .  'function submitForm () {'
        .  '  (document.getElementsByName("problemMainForm"))[0].submit();'
        .  '}'
        .  '</SCRIPT>'
        .  '<INPUT TYPE="button" VALUE="Show Problem Source" onClick="showSource()"> '
        .  '<INPUT TYPE="submit" NAME="submitAnswers" VALUE="Set Score to 0"><br>'
        .  '<INPUT TYPE="checkbox" NAME="pastDue" VALUE="1"'.$pastDue.' onChange="submitForm()"> '
        .    'Pretend the set is past due.'
      if ($pastDue) {$dueDate = time() - 1000; _answerEssay_init()}
      $_grader = $PG_FLAGS{PROBLEM_GRADER_TO_USE} || \&avg_problem_grader;
      install_problem_grader(sub {
        my ($result,$state) = &{$_grader}(@_);
        if ($inputs_ref->{submitAnswers} && $inputs_ref->{submitAnswers} eq 'Set Score to 0') {
          $result->{score} = 0;
          $state->{recorded_score} = 0;
          $state->{num_of_correct_ans} = 0;
          $state->{num_of_incorrect_ans} = 0;
        return ($result,$state);
This includes all three buttons (the "Show Problem Source" button, the "Set Score to 0" button, and the "Pretend the set is past due" checkbox). You could eliminate most of it if all you wanted was the "Pretend it is past due" function. Mostly, it just sets the $dueDate variable to be earlier than the current time so that the _answerEssay_init() routine will think it is past the due date.

The grader is only used to reset the scores to zero, so you could drop that (and its button) if you don't want that feature. The showSource() function is only needed for showing the source, so that (and its associated button) could be left out if you don't want those features.

It might be helpful to say what you are trying to accomplish, since this might not be the best way to do it.


In reply to Davide Cervone

Re: Essay Answers and pretending it's past due

by Raghu Gompa -

Dear Davide, thank you very much for your post.

I have asked the question about pretend past due button, because I was intrigued by it presence not knowing where it came from.

I am also interested to know about this button, because I wanted to create similar buttons for various problems (discussions) in various problem sets. Let me explain further:

I have problem sets MyGoals, MyJournal, MyParticipation. First two sets have only one question and the last one has 5 questions. In order to go the discussions, you need to go through several pages. I wanted to create one page with buttons to jump between pages for "view all" discussions. In order to achieve that I need to set a variable ($mydir) to different paths of directories with a click of a button.

I am thinking in these lines (I am writing this in a hurry - it may have some mistakes - it is not tested yet):

'<DIV ID="source_button" STYLE="float:right; margin-right:2em; text-align:right">'
. '<SCRIPT>'
. 'function submitForm () {'
. ' $mydir="/Discussion/MyParticipation";'
. '}'

. 'function submit1Form () {'
. ' $mydir="/Discussion/MyJournal";'
. '}'
. 'function submit2Form () {'
. ' $mydir="/Discussion/MyGoals";'
. '}'
. '</SCRIPT>'.

'<INPUT TYPE="button" VALUE="MyGoals" onClick="submit2Form()"> '
. '<INPUT TYPE="button" VALUE="MyJournal" onClick="submit1Form()"> '
. '<INPUT TYPE="button" VALUE="MyParticipation" onClick="submitForm()"> '.'</DIV>'

.. Raghu