[system] / trunk / webwork-modperl / lib / WeBWorK / ContentGenerator / LoginProctor.pm Repository:
ViewVC logotype

View of /trunk/webwork-modperl/lib/WeBWorK/ContentGenerator/LoginProctor.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3973 - (download) (as text) (annotate)
Wed Jan 25 23:13:56 2006 UTC (7 years, 3 months ago) by sh002i
File size: 7908 byte(s)
forward-port from rel-2-2-dev: (update copyright date range -- 2000-2006.
this is probably overkill, since there are some files that were created
after 2000 and some files that were last modified before 2006.)

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/LoginProctor.pm,v 1.4 2006/01/22 02:53:24 sh002i Exp $
    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     if (defined $r->param("editMode") and $r->param("editMode") eq "temporaryFile"
   55         and defined $r->param("editFileSuffix")) {
   56       $site_info .= $r->param("editFileSuffix");
   57     }
   58 
   59     if (-f $site_info) {
   60       my $text = eval { readFile($site_info) };
   61       if ($@) {
   62         $result .= CGI::h2("Site Information");
   63         $result .= CGI::div({class=>"ResultsWithError"}, $@);
   64       } elsif ($text =~ /\S/) {
   65         $result .= CGI::h2("Site Information");
   66         $result .= $text;
   67       }
   68     }
   69   }
   70 
   71   # FIXME this is basically the same code as above... TIME TO REFACTOR!
   72   my $login_info = $ce->{courseFiles}->{login_info};
   73   if (defined $login_info and $login_info) {
   74     # login info is relative to the templates directory, apparently
   75     $login_info = $ce->{courseDirs}->{templates} . "/$login_info";
   76 
   77     # deal with previewing a temporary file
   78     if (defined $r->param("editMode") and $r->param("editMode") eq "temporaryFile"
   79         and defined $r->param("editFileSuffix")) {
   80       $login_info .= $r->param("editFileSuffix");
   81     }
   82 
   83     if (-f $login_info) {
   84       my $text = eval { readFile($login_info) };
   85       if ($@) {
   86         $result .= CGI::h2("Login Info");
   87         $result .= CGI::div({class=>"ResultsWithError"}, $@);
   88       } elsif ($text =~ /\S/) {
   89         $result .= CGI::h2("Login Info");
   90         $result .= $text;
   91       }
   92     }
   93   }
   94 
   95   if (defined $result and $result ne "") {
   96     return CGI::div({class=>"info-box", id=>"InfoPanel"}, $result);
   97   } else {
   98     return "";
   99   }
  100 }
  101 
  102 sub body {
  103   my ($self) = @_;
  104   my $r = $self->r;
  105   my $ce = $r->ce;
  106   my $db = $r->db;
  107   my $urlpath = $r->urlpath;
  108 
  109   # convenient data variables
  110   my $effectiveUser = $r->param("effectiveUser") || "";
  111   my $user = $r->param("user");
  112   my $proctorUser = $r->param("proctor_user") || "";
  113   my $key = $r->param("proctor_key");
  114   my $passwd = $r->param("proctor_passwd") || "";
  115   my $course = $urlpath->arg("courseID");
  116   my $setID = $urlpath->arg("setID");
  117   my $timeNow = time();
  118 
  119   # data collection
  120   my $submitAnswers = $r->param("submitAnswers");
  121   my $EffectiveUser = $db->getUser($effectiveUser);
  122   my $User = $db->getUser($user);
  123 
  124   my $effectiveUserFullName = $EffectiveUser->first_name() . " " .
  125       $EffectiveUser->last_name();
  126 
  127   # save the userset for use below
  128   my $UserSet;
  129   # version_last_attempt_time conditional: if we're submitting the set
  130   # for the last time we need to save the submission time.
  131   if ( $submitAnswers ) {
  132 
  133     # getMergedVersionedSet returns either the set requested (if the setID
  134     #   is versioned, "setName,vN") or the latest set (if not).  This should
  135     #   be by default the set we want.
  136       $UserSet = $db->getMergedVersionedSet($effectiveUser, $setID);
  137     # this should never error out, but we'll check anyway
  138       die("Proctor login generated for grade attempt on a nonexistent " .
  139     "set?!\n") if ( ! defined($UserSet) );
  140 
  141     # we need these to get a problem from the set
  142       my $setVersionName = ( $setID =~ /,v(\d+)$/ ) ? $setID :
  143     $UserSet->set_id();
  144       $setID =~ s/,v\d+$//;
  145 
  146     # we only save the submission time if the attempt will be recorded,
  147     #   so we have to do some research to determine if that's the case
  148       my $PermissionLevel = $db->getPermissionLevel($user);
  149       my $Problem =
  150     $db->getMergedVersionedProblem($effectiveUser, $setID,
  151                  $setVersionName, 1);
  152     # set last_attempt_time if appropriate
  153       if ( WeBWorK::ContentGenerator::GatewayQuiz::can_recordAnswers($self,$User, $PermissionLevel,
  154       $EffectiveUser, $UserSet, $Problem) ) {
  155     $UserSet->version_last_attempt_time( $timeNow );
  156     $db->putVersionedUserSet( $UserSet );
  157       }
  158   }
  159 
  160 
  161   print CGI::p(CGI::strong("Proctor authorization required."), "\n\n");
  162     # WeBWorK::Authen::verifyProctor will set the note "authen_error"
  163     # if invalid authentication is found.  If this is done, it's a signal to
  164     # us to yell at the user for doing that, since Authen isn't a content-
  165     # generating module.
  166   if ($r->notes("authen_error")) {
  167     print CGI::div({class=>"ResultsWithError"},
  168       CGI::p($r->notes("authen_error"))
  169     );
  170   }
  171 
  172     # also print a message about submission times if we're submitting
  173     # an answer
  174   if ( $submitAnswers ) {
  175       my $dueTime = $UserSet->due_date();
  176       my $timeLimit = $UserSet->version_time_limit();
  177       my ($color, $msg) = ("#ddddff", "");
  178 
  179       if ( $dueTime < $timeNow ) {
  180     $color = "#ffffaa";
  181     $msg = CGI::br() . "\nThe time limit on this assignment " .
  182         "was exceeded.\nThe assignment may be checked, but " .
  183         "the result will not be counted.\n";
  184       }
  185       my $style = "background-color: $color; color: black; " .
  186     "border: solid black 1px; padding: 2px;";
  187       print CGI::div({-style=>$style},
  188          CGI::strong("Grading assignment: ", CGI::br(),
  189                "Submission time: ",
  190                scalar(localtime($timeNow)), CGI::br(),
  191                "Due: ",
  192                scalar(localtime($dueTime)), $msg));
  193   }
  194 
  195   print CGI::div({style=>"background-color:#ddddff;"},
  196            CGI::p("User's uniqname is: ",
  197             CGI::strong("$effectiveUser"),"\n",
  198             CGI::br(),"User's name is: ",
  199             CGI::strong("$effectiveUserFullName"),"\n")),"\n";
  200 
  201   print CGI::startform({-method=>"POST", -action=>$r->uri});
  202 
  203   # write out the form data posted to the requested URI
  204 # print $self->print_form_data('<input type="hidden" name="','" value="',"\"/>\n",qr/^(user|passwd|key|force_passwd_authen|procter_user|proctor_key|proctor_password)$/);
  205   my @fields_to_print =
  206       grep { ! /^(user)|(effectiveUser)|(passwd)|(key)|(force_password_authen)|(proctor_user)|(proctor_key)|(proctor_passwd)$/ } $r->param();
  207 
  208   print $self->hidden_fields(@fields_to_print) if ( @fields_to_print );
  209   print $self->hidden_authen_fields,"\n";
  210 
  211   print CGI::table({class=>"FormLayout"},
  212     CGI::Tr([
  213     CGI::td([
  214       "Proctor username:",
  215       CGI::input({-type=>"text", -name=>"proctor_user", -value=>""}),
  216     ]),
  217     CGI::td([
  218       "Proctor password:",
  219       CGI::input({-type=>"password", -name=>"proctor_passwd", -value=>""}),
  220     ]),
  221    ])
  222   );
  223 
  224   print CGI::input({-type=>"submit", -value=>"Continue"});
  225   print CGI::endform();
  226 
  227   return "";
  228 }
  229 
  230 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9