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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2109 - (download) (as text) (annotate)
Fri May 14 18:26:11 2004 UTC (9 years ago) by toenail
File size: 8126 byte(s)
added text classes for students with status Audit, Drop, Enrolled

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/UsersAssignedToSet.pm,v 1.10 2004/05/11 21:03:09 toenail 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::Instructor::UsersAssignedToSet;
   18 use base qw(WeBWorK::ContentGenerator::Instructor);
   19 
   20 =head1 NAME
   21 
   22 WeBWorK::ContentGenerator::Instructor::UsersAssignedToSet - List and edit the
   23 users to which sets are assigned.
   24 
   25 =cut
   26 
   27 use strict;
   28 use warnings;
   29 use CGI qw();
   30 use WeBWorK::Utils qw(formatDateTime);
   31 
   32 sub initialize {
   33   my ($self)     = @_;
   34   my $r          = $self->r;
   35       my $urlpath    = $r->urlpath;
   36   my $authz      = $r->authz;
   37   my $db         = $r->db;
   38   my $setID      = $urlpath->arg("setID");
   39   my $user       = $r->param('user');
   40 
   41   unless ($authz->hasPermissions($user, "assign_problem_sets")) {
   42     $self->addmessage(CGI::div({class=>"ResultsWithError"}, CGI::p("You are not authorized to assign problem sets")));
   43     return;
   44   }
   45 
   46   my @users = $db->listUsers;
   47   my %selectedUsers = map {$_ => 1} $r->param('selected');
   48 
   49   my $doAssignToSelected = 0;
   50 
   51   # get the global user, if there is one
   52   my $globalUserID = "";
   53   $globalUserID = $db->{set}->{params}->{globalUserID}
   54     if ref $db->{set} eq "WeBWorK::DB::Schema::GlobalTableEmulator";
   55 
   56   if (defined $r->param('assignToAll')) {
   57     $WeBWorK::timer->continue("assignSetToAllUsers($setID)") if defined $WeBWorK::timer;
   58     $self->addmessage(CGI::div({class=>'ResultsWithoutError'}, "Problems have been assigned to all current users."));
   59     $self->assignSetToAllUsers($setID);
   60     $WeBWorK::timer->continue("done assignSetToAllUsers($setID)") if defined $WeBWorK::timer;
   61   } elsif (defined $r->param('unassignFromAll') and defined($r->param('unassignFromAllSafety')) and $r->param('unassignFromAllSafety')==1) {
   62     %selectedUsers = ( $globalUserID => 1 );
   63     $self->addmessage(CGI::div({class=>'ResultsWithoutError'}, "Problems for all students have been unassigned."));
   64     $doAssignToSelected = 1;
   65   } elsif (defined $r->param('assignToSelected')) {
   66       $self->addmessage(CGI::div({class=>'ResultsWithoutError'}, "Problems for selected students have been reassigned."));
   67     $doAssignToSelected = 1;
   68   } else {
   69      # no action taken
   70      $self->addmessage(CGI::div({class=>'ResultsWithError'}, "No action taken"));
   71   }
   72 
   73   if ($doAssignToSelected) {
   74     my $setRecord = $db->getGlobalSet($setID); #checked
   75     die "Unable to get global set record for $setID " unless $setRecord;
   76 
   77     foreach my $selectedUser (@users) {
   78       if (exists $selectedUsers{$selectedUser}) {
   79         $WeBWorK::timer->continue("assignSetToUser($selectedUser, ...)") if defined $WeBWorK::timer;
   80         $self->assignSetToUser($selectedUser, $setRecord);
   81         $WeBWorK::timer->continue("done assignSetToUser($selectedUser, ...)") if defined $WeBWorK::timer;
   82       } else {
   83         next if $selectedUser eq $globalUserID;
   84         $db->deleteUserSet($selectedUser, $setID);
   85       }
   86     }
   87   }
   88 }
   89 
   90 sub getSetName {
   91   my ($self, $pathSetName) = @_;
   92   if (ref $pathSetName eq "HASH") {
   93     $pathSetName = undef;
   94   }
   95   return $pathSetName;
   96 }
   97 
   98 
   99 sub body {
  100   my ($self)         = @_;
  101   my $r              = $self->r;
  102   my $urlpath        = $r->urlpath;
  103   my $db             = $r->db;
  104   my $ce             = $r->ce;
  105   my $authz          = $r->authz;
  106   my $webworkRoot    = $ce->{webworkURLs}->{root};
  107   my $courseName     = $urlpath->arg("courseID");
  108   my $setID          = $urlpath->arg("setID");
  109   my $user           = $r->param('user');
  110 
  111   return CGI::em("You are not authorized to access the Instructor tools.")
  112     unless $authz->hasPermissions($user, "access_instructor_tools");
  113 
  114   my @users = $db->listUsers;
  115   print CGI::start_form({method=>"post", action => $self->systemLink( $urlpath, authen=>0) });
  116 
  117   print CGI::p(
  118         CGI::submit({name=>"assignToAll", value => "Assign to All Current Users"}), CGI::i("This action can take a long time if there are many students.")
  119       ),
  120       CGI::div({-style=>"color:red"}, "Do not uncheck students, unless you know what you are doing.",CGI::br(),
  121              "There is NO undo for unassigning students. "),
  122         CGI::p("When you unassign
  123                 by unchecking a student's name, you destroy all
  124                 of the data for problem set $setID for this student. You will then need to
  125                 reassign the set to these students and they will receive new versions of the problems.
  126                 Make sure this is what you want to do before unchecking students."
  127   );
  128 
  129   print CGI::start_table({});
  130   # get user records
  131   my @userRecords  = ();
  132   foreach my $currentUser ( @users) {
  133     my $userObj = $db->getUser($currentUser); #checked
  134     die "Unable to find user object for $currentUser. " unless $userObj;
  135     push (@userRecords, $userObj );
  136   }
  137   @userRecords = sort { ( lc($a->section) cmp lc($b->section) ) ||
  138                        ( lc($a->last_name) cmp lc($b->last_name )) } @userRecords;
  139 
  140   # get the global user, if there is one
  141   my $globalUserID = "";
  142   $globalUserID = $db->{set}->{params}->{globalUserID}
  143     if ref $db->{set} eq "WeBWorK::DB::Schema::GlobalTableEmulator";
  144 
  145   foreach my $userRecord (@userRecords) {
  146 
  147     my $statusClass = $ce->{siteDefaults}->{status}->{$userRecord->{status}} || "";
  148 
  149     my $user = $userRecord->user_id;
  150     my $userSetRecord = $db->getUserSet($user, $setID); #checked
  151     # don't need to check here, undefined values are handled below
  152     #die "Unable to find record for user $user and set $setID " unless $userSetRecord;
  153     my $prettyName = $userRecord->last_name
  154       . ", "
  155       . $userRecord->first_name;
  156     my $dueDate    = $userSetRecord->due_date if ref($userSetRecord);
  157     my $prettyDate = ($dueDate)?  '(' . formatDateTime($dueDate) . ') ' : '';
  158     print CGI::Tr({},
  159       CGI::td({}, [
  160         ($user eq $globalUserID
  161           ? "" # no checkbox for global user!
  162           : CGI::checkbox({
  163             type=>"checkbox",
  164             name=>"selected",
  165             checked=>(
  166               defined($userSetRecord) # && $statusClass ne "Drop"
  167               ? "on"
  168               : ""
  169             ),
  170             value=>$user,
  171             label=>"",
  172           })
  173         ),
  174         CGI::div({class=>$statusClass}, $user),
  175         "($prettyName)", " ", $userRecord->section, " ",
  176         (
  177           defined $userSetRecord
  178           ? $prettyDate . CGI::a(
  179             {href=>$self->systemLink($urlpath->new(type =>'instructor_set_detail',
  180                                                    args =>{courseID => $courseName,
  181                                                            setID    => $setID
  182                                                    }),
  183                                      params =>{editForUser=> $user}
  184             )},
  185             "Edit data for $user"
  186           )
  187           : ()
  188         ),
  189       ])
  190     );
  191   }
  192   print CGI::end_table();
  193   print $self->hidden_authen_fields;
  194   print CGI::submit({name=>"assignToSelected", value=>"Save"});
  195   print CGI::p( CGI::hr(),
  196           CGI::div( {class=>'ResultsWithError'},
  197             "There is NO undo for this function.
  198                 Do not use it unless you know what you are doing!  When you unassign
  199                 a student using this button, or by unchecking their name, you destroy all
  200                 of the data for problem set $setID for this student.",
  201             CGI::br(),
  202             CGI::submit({name=>"unassignFromAll", value=>"Unassign from All Users"}),
  203             CGI::radio_group(-name=>"unassignFromAllSafety", -values=>[0,1], -default=>0, -labels=>{0=>'Read only', 1=>'Allow unassign'}),
  204 
  205           ),
  206 
  207 
  208           CGI::hr(),
  209   );
  210   print CGI::end_form();
  211 
  212   return "";
  213 }
  214 
  215 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9