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

View of /branches/rel-2-4-dev/webwork2/lib/WeBWorK/ContentGenerator/Instructor/Assigner.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5318 - (download) (as text) (annotate)
Mon Aug 13 22:53:51 2007 UTC (5 years, 9 months ago) by sh002i
File size: 6548 byte(s)
updated copyright dates

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Instructor/Assigner.pm,v 1.37 2006/09/25 22:14: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::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   # DBFIXME shouldn't have to get the user id list
   99   # DBFIXME mark's filtering should happen in a WHERE clause
  100   my @userIDs = $db->listUsers;
  101   my @Users = $db->getUsers(@userIDs);
  102 ## Mark's Edits for filtering
  103   my @myUsers;
  104 
  105 
  106   my (@viewable_sections, @viewable_recitations);
  107 
  108   if (defined @{$ce->{viewable_sections}->{$user}})
  109     {@viewable_sections = @{$ce->{viewable_sections}->{$user}};}
  110   if (defined @{$ce->{viewable_recitations}->{$user}})
  111     {@viewable_recitations = @{$ce->{viewable_recitations}->{$user}};}
  112   if (@viewable_sections or @viewable_recitations){
  113     foreach my $student (@Users){
  114       my $keep = 0;
  115       foreach my $sec (@viewable_sections){
  116         if ($student->section() eq $sec){$keep = 1;}
  117       }
  118       foreach my $rec (@viewable_recitations){
  119         if ($student->section() eq $rec){$keep = 1;}
  120       }
  121       if ($keep) {push @myUsers, $student;}
  122     }
  123     @Users = @myUsers;
  124   }
  125 ## End Mark's Edits
  126 
  127 
  128   # DBFIXME shouldn't have to get the set ID list
  129   my @globalSetIDs = $db->listGlobalSets;
  130   my @GlobalSets = $db->getGlobalSets(@globalSetIDs);
  131 
  132   my $scrolling_user_list = scrollingRecordList({
  133     name => "selected_users",
  134     request => $r,
  135     default_sort => "lnfn",
  136     default_format => "lnfn_uid",
  137     default_filters => ["all"],
  138     size => 20,
  139     multiple => 1,
  140   }, @Users);
  141 
  142   my $scrolling_set_list = scrollingRecordList({
  143     name => "selected_sets",
  144     request => $r,
  145     default_sort => "set_id",
  146     default_format => "set_id",
  147     default_filters => ["all"],
  148     size => 20,
  149     multiple => 1,
  150   }, @GlobalSets);
  151 
  152   print CGI::start_form({method=>"post", action=>$r->uri()});
  153   print $self->hidden_authen_fields();
  154 
  155   print CGI::table({class=>"FormLayout"},
  156     CGI::Tr(
  157       CGI::th("Users"),
  158       CGI::th("Sets"),
  159     ),
  160     CGI::Tr(
  161       CGI::td($scrolling_user_list),
  162       CGI::td($scrolling_set_list),
  163     ),
  164     CGI::Tr(
  165       CGI::td({colspan=>2, class=>"ButtonRow"},
  166         CGI::submit(
  167           -name => "assign",
  168           -value => "Assign selected sets to selected users",
  169           -style => "width: 45ex",
  170         ),
  171       ),
  172     ),
  173     CGI::Tr(
  174       CGI::td({colspan=>2},
  175         CGI::div({class=>'ResultsWithError', style=>'color:red'},
  176           "Do not unassign students unless you know what you are doing.",
  177           CGI::br(),
  178           "There is NO undo for unassigning students. ",
  179           CGI::br(),
  180           CGI::submit(
  181             -name => "unassign",
  182             -value => "Unassign selected sets from selected users",
  183             -style => "width: 45ex",
  184           ),
  185           CGI::radio_group(-name=>"unassignFromAllSafety", -values=>[0,1], -default=>0, -labels=>{0=>'Assignments only', 1=>'Allow unassign'}),
  186         ),
  187       ),
  188     ),
  189   );
  190 
  191 
  192 
  193   print CGI::p("When you unassign a student's name, you destroy all
  194       of the data for that homework set for that student. You will then need to
  195       reassign the set(s) to these students and they will receive new versions of the problems.
  196       Make sure this is what you want to do before unassigning students."
  197   );
  198 
  199   print CGI::end_form();
  200 
  201   return "";
  202 }
  203 
  204 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9