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

View of /branches/rel-2-3-dev/webwork2/lib/WeBWorK/ContentGenerator/Instructor/UsersAssignedToSet.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4396 - (download) (as text) (annotate)
Thu Aug 24 21:07:52 2006 UTC (6 years, 8 months ago)
File size: 8744 byte(s)
This commit was manufactured by cvs2svn to create branch 'rel-2-3-dev'.

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9