[system] / branches / rel-2-2-dev / webwork2 / lib / WeBWorK / ContentGenerator / LoginProctor.pm Repository:
ViewVC logotype

View of /branches/rel-2-2-dev/webwork2/lib/WeBWorK/ContentGenerator/LoginProctor.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4006 - (download) (as text) (annotate)
Fri Feb 3 00:19:35 2006 UTC (7 years, 3 months ago) by sh002i
File size: 8109 byte(s)
disable editFileSuffix since it is not used and is dumb.

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader$
    5 #
    6 # This program is free software; you can redistribute it and/or modify it under
    7 # the terms of either: (a) the GNU General Public License as published by the
    8 # Free Software Foundation; either version 2, or (at your option) any later
    9 # version, or (b) the "Artistic License" which comes with this package.
   10 #
   11 # This program is distributed in the hope that it will be useful, but WITHOUT
   12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   14 # Artistic License for more details.
   15 ################################################################################
   16 
   17 package WeBWorK::ContentGenerator::LoginProctor;
   18 use base qw(WeBWorK::ContentGenerator);
   19 
   20 =head1 NAME
   21 
   22 WeBWorK::ContentGenerator::LoginProctor - display a login form for
   23 GatewayQuiz proctored tests.
   24 
   25 =cut
   26 
   27 use strict;
   28 use warnings;
   29 use CGI qw();
   30 use WeBWorK::Utils qw(readFile dequote);
   31 use WeBWorK::ContentGenerator::GatewayQuiz qw(can_recordAnswers);
   32 
   33 # This content generator is NOT logged in.
   34 # FIXME  I'm not sure this is really what we want for the proctor login,
   35 # FIXME  but I also don't know what this actually does, so I'm ignoring it
   36 # FIXME  for now.
   37 sub if_loggedin {
   38   my ($self, $arg) = @_;
   39 
   40   return !$arg;
   41 }
   42 
   43 sub info {
   44   my ($self) = @_;
   45   my $r = $self->r;
   46   my $ce = $r->ce;
   47 
   48   my $result;
   49 
   50   # This section should be kept in sync with the Home.pm version
   51   my $site_info = $ce->{webworkFiles}->{site_info};
   52   if (defined $site_info and $site_info) {
   53     # deal with previewing a temporary file
   54     # FIXME: DANGER: this code allows viewing of any file
   55     # FIXME: this code is disabled because PGProblemEditor no longer uses editFileSuffix
   56     #if (defined $r->param("editMode") and $r->param("editMode") eq "temporaryFile"
   57     #   and defined $r->param("editFileSuffix")) {
   58     # $site_info .= $r->param("editFileSuffix");
   59     #}
   60 
   61     if (-f $site_info) {
   62       my $text = eval { readFile($site_info) };
   63       if ($@) {
   64         $result .= CGI::h2("Site Information");
   65         $result .= CGI::div({class=>"ResultsWithError"}, $@);
   66       } elsif ($text =~ /\S/) {
   67         $result .= CGI::h2("Site Information");
   68         $result .= $text;
   69       }
   70     }
   71   }
   72 
   73   # FIXME this is basically the same code as above... TIME TO REFACTOR!
   74   my $login_info = $ce->{courseFiles}->{login_info};
   75   if (defined $login_info and $login_info) {
   76     # login info is relative to the templates directory, apparently
   77     $login_info = $ce->{courseDirs}->{templates} . "/$login_info";
   78 
   79     # deal with previewing a temporary file
   80     # FIXME: DANGER: this code allows viewing of any file
   81     # FIXME: this code is disabled because PGProblemEditor no longer uses editFileSuffix
   82     #if (defined $r->param("editMode") and $r->param("editMode") eq "temporaryFile"
   83     #   and defined $r->param("editFileSuffix")) {
   84     # $login_info .= $r->param("editFileSuffix");
   85     #}
   86 
   87     if (-f $login_info) {
   88       my $text = eval { readFile($login_info) };
   89       if ($@) {
   90         $result .= CGI::h2("Login Info");
   91         $result .= CGI::div({class=>"ResultsWithError"}, $@);
   92       } elsif ($text =~ /\S/) {
   93         $result .= CGI::h2("Login Info");
   94         $result .= $text;
   95       }
   96     }
   97   }
   98 
   99   if (defined $result and $result ne "") {
  100     return CGI::div({class=>"info-box", id=>"InfoPanel"}, $result);
  101   } else {
  102     return "";
  103   }
  104 }
  105 
  106 sub body {
  107   my ($self) = @_;
  108   my $r = $self->r;
  109   my $ce = $r->ce;
  110   my $db = $r->db;
  111   my $urlpath = $r->urlpath;
  112 
  113   # convenient data variables
  114   my $effectiveUser = $r->param("effectiveUser") || "";
  115   my $user = $r->param("user");
  116   my $proctorUser = $r->param("proctor_user") || "";
  117   my $key = $r->param("proctor_key");
  118   my $passwd = $r->param("proctor_passwd") || "";
  119   my $course = $urlpath->arg("courseID");
  120   my $setID = $urlpath->arg("setID");
  121   my $timeNow = time();
  122 
  123   # data collection
  124   my $submitAnswers = $r->param("submitAnswers");
  125   my $EffectiveUser = $db->getUser($effectiveUser);
  126   my $User = $db->getUser($user);
  127 
  128   my $effectiveUserFullName = $EffectiveUser->first_name() . " " .
  129       $EffectiveUser->last_name();
  130 
  131   # save the userset for use below
  132   my $UserSet;
  133   # version_last_attempt_time conditional: if we're submitting the set
  134   # for the last time we need to save the submission time.
  135   if ( $submitAnswers ) {
  136 
  137     # getMergedVersionedSet returns either the set requested (if the setID
  138     #   is versioned, "setName,vN") or the latest set (if not).  This should
  139     #   be by default the set we want.
  140       $UserSet = $db->getMergedVersionedSet($effectiveUser, $setID);
  141     # this should never error out, but we'll check anyway
  142       die("Proctor login generated for grade attempt on a nonexistent " .
  143     "set?!\n") if ( ! defined($UserSet) );
  144 
  145     # we need these to get a problem from the set
  146       my $setVersionName = ( $setID =~ /,v(\d+)$/ ) ? $setID :
  147     $UserSet->set_id();
  148       $setID =~ s/,v\d+$//;
  149 
  150     # we only save the submission time if the attempt will be recorded,
  151     #   so we have to do some research to determine if that's the case
  152       my $PermissionLevel = $db->getPermissionLevel($user);
  153       my $Problem =
  154     $db->getMergedVersionedProblem($effectiveUser, $setID,
  155                  $setVersionName, 1);
  156     # set last_attempt_time if appropriate
  157       if ( WeBWorK::ContentGenerator::GatewayQuiz::can_recordAnswers($self,$User, $PermissionLevel,
  158       $EffectiveUser, $UserSet, $Problem) ) {
  159     $UserSet->version_last_attempt_time( $timeNow );
  160     $db->putVersionedUserSet( $UserSet );
  161       }
  162   }
  163 
  164 
  165   print CGI::p(CGI::strong("Proctor authorization required."), "\n\n");
  166     # WeBWorK::Authen::verifyProctor will set the note "authen_error"
  167     # if invalid authentication is found.  If this is done, it's a signal to
  168     # us to yell at the user for doing that, since Authen isn't a content-
  169     # generating module.
  170   if ($r->notes("authen_error")) {
  171     print CGI::div({class=>"ResultsWithError"},
  172       CGI::p($r->notes("authen_error"))
  173     );
  174   }
  175 
  176     # also print a message about submission times if we're submitting
  177     # an answer
  178   if ( $submitAnswers ) {
  179       my $dueTime = $UserSet->due_date();
  180       my $timeLimit = $UserSet->version_time_limit();
  181       my ($color, $msg) = ("#ddddff", "");
  182 
  183       if ( $dueTime < $timeNow ) {
  184     $color = "#ffffaa";
  185     $msg = CGI::br() . "\nThe time limit on this assignment " .
  186         "was exceeded.\nThe assignment may be checked, but " .
  187         "the result will not be counted.\n";
  188       }
  189       my $style = "background-color: $color; color: black; " .
  190     "border: solid black 1px; padding: 2px;";
  191       print CGI::div({-style=>$style},
  192          CGI::strong("Grading assignment: ", CGI::br(),
  193                "Submission time: ",
  194                scalar(localtime($timeNow)), CGI::br(),
  195                "Due: ",
  196                scalar(localtime($dueTime)), $msg));
  197   }
  198 
  199   print CGI::div({style=>"background-color:#ddddff;"},
  200            CGI::p("User's uniqname is: ",
  201             CGI::strong("$effectiveUser"),"\n",
  202             CGI::br(),"User's name is: ",
  203             CGI::strong("$effectiveUserFullName"),"\n")),"\n";
  204 
  205   print CGI::startform({-method=>"POST", -action=>$r->uri});
  206 
  207   # write out the form data posted to the requested URI
  208 # print $self->print_form_data('<input type="hidden" name="','" value="',"\"/>\n",qr/^(user|passwd|key|force_passwd_authen|procter_user|proctor_key|proctor_password)$/);
  209   my @fields_to_print =
  210       grep { ! /^(user)|(effectiveUser)|(passwd)|(key)|(force_password_authen)|(proctor_user)|(proctor_key)|(proctor_passwd)$/ } $r->param();
  211 
  212   print $self->hidden_fields(@fields_to_print) if ( @fields_to_print );
  213   print $self->hidden_authen_fields,"\n";
  214 
  215   print CGI::table({class=>"FormLayout"},
  216     CGI::Tr([
  217     CGI::td([
  218       "Proctor username:",
  219       CGI::input({-type=>"text", -name=>"proctor_user", -value=>""}),
  220     ]),
  221     CGI::td([
  222       "Proctor password:",
  223       CGI::input({-type=>"password", -name=>"proctor_passwd", -value=>""}),
  224     ]),
  225    ])
  226   );
  227 
  228   print CGI::input({-type=>"submit", -value=>"Continue"});
  229   print CGI::endform();
  230 
  231   return "";
  232 }
  233 
  234 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9