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

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9