[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / Assigner.pm Repository:
ViewVC logotype

View of /trunk/webwork2/lib/WeBWorK/ContentGenerator/Instructor/Assigner.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3559 - (download) (as text) (annotate)
Wed Aug 24 02:22:59 2005 UTC (7 years, 8 months ago) by jj
File size: 6363 byte(s)
Removed initialize function which did nothing.  Moved the actual assignments/unassignments to pre_header_initialize so they could use the messaging system.

    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/Assigner.pm,v 1.32 2005/08/24 01:52:27 jj 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::Assigner;
   18 use base qw(WeBWorK::ContentGenerator::Instructor);
   19 
   20 =head1 NAME
   21 
   22 WeBWorK::ContentGenerator::Instructor::Assigner - Assign homework sets to users.
   23 
   24 =cut
   25 
   26 use strict;
   27 use warnings;
   28 use CGI qw();
   29 use WeBWorK::HTML::ScrollingRecordList qw/scrollingRecordList/;
   30 
   31 sub pre_header_initialize {
   32   my ($self) = @_;
   33   my $r = $self->r;
   34   my $db = $r->db;
   35   my $authz = $r->authz;
   36   my $ce = $r->ce;
   37   my $user = $r->param('user');
   38 
   39   # Permissions dealt with in the body
   40   return "" unless $authz->hasPermissions($user, "access_instructor_tools");
   41   return "" unless $authz->hasPermissions($user, "assign_problem_sets");
   42 
   43   my @selected_users = $r->param("selected_users");
   44   my @selected_sets = $r->param("selected_sets");
   45 
   46   if (defined $r->param("assign") || defined $r->param("unassign")) {
   47     if  (@selected_users && @selected_sets) {
   48       my @results;  # This is not used?
   49       if(defined $r->param("assign")) {
   50         $self->assignSetsToUsers(\@selected_sets, \@selected_users);
   51         $self->addgoodmessage('All assignments were made successfully.');
   52       }
   53       if (defined $r->param("unassign")) {
   54         if(defined $r->param('unassignFromAllSafety') and $r->param('unassignFromAllSafety')==1) {
   55           $self->unassignSetsFromUsers(\@selected_sets, \@selected_users) if(defined $r->param("unassign"));
   56           $self->addgoodmessage('All unassignments were made successfully.');
   57         } else { # asked for unassign, but no safety radio toggle
   58           $self->addbadmessage('Unassignments were not done.  You need to both click to "Allow unassign" and click on the Unassign button.');
   59         }
   60       }
   61 
   62       if (@results) { # Can't get here?
   63         $self->addbadmessage(
   64           "The following error(s) occured while assigning:".
   65           CGI::ul(CGI::li(\@results))
   66         );
   67       }
   68     } else {
   69       $self->addbadmessage("You must select one or more users below.")
   70         unless @selected_users;
   71       $self->addbadmessage("You must select one or more sets below.")
   72         unless @selected_sets;
   73     }
   74   }
   75 }
   76 
   77 sub body {
   78   my ($self) = @_;
   79   my $r = $self->r;
   80   my $db = $r->db;
   81   my $authz = $r->authz;
   82   my $ce = $r->ce;
   83 
   84   my $user = $r->param('user');
   85 
   86   # Check permissions
   87   return CGI::div({class=>"ResultsWithError"}, "You are not authorized to access the Instructor tools.")
   88     unless $authz->hasPermissions($user, "access_instructor_tools");
   89 
   90   return CGI::div({class=>"ResultsWithError"}, "You are not authorized to assign homework sets.")
   91     unless $authz->hasPermissions($user, "assign_problem_sets");
   92 
   93 
   94   print CGI::p("Select one or more sets and one or more users below to assign/unassign"
   95     . " each selected set to/from all selected users.");
   96 
   97   my @userIDs = $db->listUsers;
   98   my @Users = $db->getUsers(@userIDs);
   99 ## Mark's Edits for filtering
  100   my @myUsers;
  101 
  102 
  103   my (@viewable_sections, @viewable_recitations);
  104 
  105   if (defined @{$ce->{viewable_sections}->{$user}})
  106     {@viewable_sections = @{$ce->{viewable_sections}->{$user}};}
  107   if (defined @{$ce->{viewable_recitations}->{$user}})
  108     {@viewable_recitations = @{$ce->{viewable_recitations}->{$user}};}
  109   if (@viewable_sections or @viewable_recitations){
  110     foreach my $student (@Users){
  111       my $keep = 0;
  112       foreach my $sec (@viewable_sections){
  113         if ($student->section() eq $sec){$keep = 1;}
  114       }
  115       foreach my $rec (@viewable_recitations){
  116         if ($student->section() eq $rec){$keep = 1;}
  117       }
  118       if ($keep) {push @myUsers, $student;}
  119     }
  120     @Users = @myUsers;
  121   }
  122 ## End Mark's Edits
  123 
  124 
  125   my @globalSetIDs = $db->listGlobalSets;
  126   my @GlobalSets = $db->getGlobalSets(@globalSetIDs);
  127 
  128   my $scrolling_user_list = scrollingRecordList({
  129     name => "selected_users",
  130     request => $r,
  131     default_sort => "lnfn",
  132     default_format => "lnfn_uid",
  133     default_filters => ["all"],
  134     size => 20,
  135     multiple => 1,
  136   }, @Users);
  137 
  138   my $scrolling_set_list = scrollingRecordList({
  139     name => "selected_sets",
  140     request => $r,
  141     default_sort => "set_id",
  142     default_format => "set_id",
  143     default_filters => ["all"],
  144     size => 20,
  145     multiple => 1,
  146   }, @GlobalSets);
  147 
  148   print CGI::start_form({method=>"post", action=>$r->uri()});
  149   print $self->hidden_authen_fields();
  150 
  151   print CGI::table({class=>"FormLayout"},
  152     CGI::Tr(
  153       CGI::th("Users"),
  154       CGI::th("Sets"),
  155     ),
  156     CGI::Tr(
  157       CGI::td($scrolling_user_list),
  158       CGI::td($scrolling_set_list),
  159     ),
  160     CGI::Tr(
  161       CGI::td({colspan=>2, class=>"ButtonRow"},
  162         CGI::submit(
  163           -name => "assign",
  164           -value => "Assign selected sets to selected users",
  165           -style => "width: 45ex",
  166         ),
  167       ),
  168     ),
  169     CGI::Tr(
  170       CGI::td({colspan=>2},
  171         CGI::div({class=>'ResultsWithError', style=>'color:red'},
  172           "Do not unassign students unless you know what you are doing.",
  173           CGI::br(),
  174           "There is NO undo for unassigning students. ",
  175           CGI::br(),
  176           CGI::submit(
  177             -name => "unassign",
  178             -value => "Unassign selected sets from selected users",
  179             -style => "width: 45ex",
  180           ),
  181           CGI::radio_group(-name=>"unassignFromAllSafety", -values=>[0,1], -default=>0, -labels=>{0=>'Assignments only', 1=>'Allow unassign'}),
  182         ),
  183       ),
  184     ),
  185   );
  186 
  187 
  188 
  189   print CGI::p("When you unassign a student's name, you destroy all
  190       of the data for that homework set for that student. You will then need to
  191       reassign the set(s) to these students and they will receive new versions of the problems.
  192       Make sure this is what you want to do before unassigning students."
  193   );
  194 
  195   print CGI::end_form();
  196 
  197   return "";
  198 }
  199 
  200 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9