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

View of /branches/rel-2-4-dev/webwork2/lib/WeBWorK/ContentGenerator/Instructor/Index.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: 13622 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/Index.pm,v 1.58 2007/04/04 15:05:27 glarose 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::Index;
   18 use base qw(WeBWorK::ContentGenerator::Instructor);
   19 
   20 =head1 NAME
   21 
   22 WeBWorK::ContentGenerator::Instructor::Index - Menu interface to the Instructor
   23 pages
   24 
   25 =cut
   26 
   27 use strict;
   28 use warnings;
   29 #use CGI qw(-nosticky );
   30 use WeBWorK::CGI;
   31 use WeBWorK::HTML::ScrollingRecordList qw/scrollingRecordList/;
   32 #use WeBWorK::Utils::FilterRecords qw/getFiltersForClass/;
   33 
   34 use constant E_NO_USERS     => "Please do not select any users.";
   35 use constant E_NO_SETS      => "Please do not select any sets.";
   36 use constant E_MAX_ONE_USER => "Please select at most one user.";
   37 use constant E_MAX_ONE_SET  => "Please select at most one set.";
   38 use constant E_ONE_USER     => "Please select exactly one user.";
   39 use constant E_ONE_SET      => "Please select exactly one set.";
   40 use constant E_MIN_ONE_USER => "Please select at least one user.";
   41 use constant E_MIN_ONE_SET  => "Please select at least one set.";
   42 use constant E_SET_NAME     => "Please specify a homework set name.";
   43 use constant E_BAD_NAME     => "Please use only letter, digits, -, _ and . in your set name.";
   44 
   45 sub pre_header_initialize {
   46   my ($self) = @_;
   47   my $r = $self->r;
   48   my $ce = $r->ce;
   49   my $db = $r->db;
   50   my $authz = $r->authz;
   51   my $urlpath = $r->urlpath;
   52 
   53   my $courseID = $urlpath->arg("courseID");
   54   my $userID = $r->param("user");
   55   my $eUserID = $r->param("effectiveUser");
   56   $self->{courseName} = $courseID;
   57   # Check permissions
   58   return unless ($authz->hasPermissions($userID, "access_instructor_tools"));
   59 
   60   my @selectedUserIDs = $r->param("selected_users");
   61   my @selectedSetIDs = $r->param("selected_sets");
   62 
   63   my $nusers = @selectedUserIDs;
   64   my $nsets = @selectedSetIDs;
   65 
   66   my $firstUserID = $nusers ? $selectedUserIDs[0] : "";
   67   my $firstSetID = $nsets ? $selectedSetIDs[0] : "";
   68 
   69   # these will be used to construct a new URL
   70   my $module;
   71   my %args = ( courseID => $courseID );
   72   my %params;
   73 
   74   my $pfx = "WeBWorK::ContentGenerator";
   75   my $ipfx = "WeBWorK::ContentGenerator::Instructor";
   76 
   77   my @error;
   78 
   79   # depending on which button was pushed, fill values in for URL construction
   80 
   81   defined param $r "sets_assigned_to_user" and do {
   82     if ($nusers == 1) {
   83       $module = "${ipfx}::UserDetail";
   84       $args{userID} = $firstUserID;
   85       $params{fromTools} = 1;
   86     } else {
   87       push @error, E_ONE_USER;
   88     }
   89   };
   90 
   91   defined param $r "users_assigned_to_set" and do {
   92     if ($nsets == 1) {
   93       $module = "${ipfx}::UsersAssignedToSet";
   94       $args{setID} = $firstSetID;
   95       $params{fromTools} = 1;
   96     } else {
   97       push @error, E_ONE_SET;
   98     }
   99   };
  100 
  101   defined param $r "edit_users" and do {
  102     if ($nusers >= 1) {
  103       $module = "${ipfx}::UserList";
  104       $params{visible_users} = \@selectedUserIDs;
  105       $params{editMode} = 1;
  106     } else {
  107       push @error, E_MIN_ONE_USER;
  108     }
  109   };
  110 
  111   defined param $r "edit_sets" and do {
  112     if ($nsets == 1) {
  113       $module = "${ipfx}::ProblemSetDetail";
  114       $args{setID} = $firstSetID;
  115     } else {
  116       push @error, E_ONE_SET;
  117 
  118     }
  119   };
  120 
  121   defined param $r "prob_lib" and do {
  122     if ($nsets == 1) {
  123           $module = "${ipfx}::SetMaker";
  124       $params{local_sets} = $firstSetID;
  125     } elsif ($nsets == 0) {
  126         $module = "${ipfx}::SetMaker";
  127     } else {
  128       push @error, E_ONE_SET;
  129 
  130     }
  131   };
  132 
  133   defined param $r "user_stats" and do {
  134     if ($nusers == 1) {
  135       $module = "${ipfx}::Stats";
  136       $args{statType} = "student"; # FIXME: fix URLPath -- i shouldn't have to type this!
  137       $args{userID} = $firstUserID;
  138     } else {
  139       push @error, E_ONE_USER;
  140     }
  141   };
  142 
  143   defined param $r "set_stats" and do {
  144     if ($nsets == 1) {
  145       $module = "${ipfx}::Stats";
  146       $args{statType} = "set"; # FIXME: fix URLPath -- i shouldn't have to type this!
  147       $args{setID} = $firstSetID;
  148     } else {
  149       push @error, E_ONE_SET;
  150     }
  151   };
  152 
  153   defined param $r "user_progress" and do {
  154     if ($nusers == 1) {
  155       $module = "${ipfx}::StudentProgress";
  156       $args{statType} = "student"; # FIXME: fix URLPath -- i shouldn't have to type this!
  157       $args{userID} = $firstUserID;
  158     } else {
  159       push @error, E_ONE_USER;
  160     }
  161   };
  162 
  163   defined param $r "set_progress" and do {
  164     if ($nsets == 1) {
  165       $module = "${ipfx}::StudentProgress";
  166       $args{statType} = "set"; # FIXME: fix URLPath -- i shouldn't have to type this!
  167       $args{setID} = $firstSetID;
  168     } else {
  169       push @error, E_ONE_SET;
  170     }
  171   };
  172 
  173   defined param $r "user_options" and do {
  174     if ($nusers == 1) {
  175       $module = "${pfx}::Options";
  176       $params{effectiveUser} = $firstUserID;
  177     } else {
  178       push @error, E_ONE_USER;
  179     }
  180   };
  181 
  182   defined param $r "score_sets" and do {
  183     if ($nsets >= 1) {
  184       $module = "${ipfx}::Scoring";
  185       $params{selectedSet} = \@selectedSetIDs;
  186       $params{scoreSelected} = 1;
  187     } else {
  188       push @error, E_MIN_ONE_SET;
  189     }
  190   };
  191 
  192   defined param $r "assign_users" and do {
  193     if ($nusers >= 1 and $nsets >= 1) {
  194       $module = "${ipfx}::Assigner";
  195       $params{selected_users} = \@selectedUserIDs;
  196       $params{selected_sets} = \@selectedSetIDs;
  197       $params{assign} = "Assign selected sets to selected users";
  198     } else {
  199       push @error, E_MIN_ONE_USER unless $nusers >= 1;
  200       push @error, E_MIN_ONE_SET unless $nsets >= 1;
  201     }
  202   };
  203 
  204   defined param $r "act_as_user" and do {
  205     if ($nusers == 1 and $nsets <= 1) {
  206       if ($nsets) {
  207         $module = "${pfx}::ProblemSet";
  208         $args{setID} = $firstSetID;
  209       } else {
  210         $module = "${pfx}::ProblemSets";
  211       }
  212       $params{effectiveUser} = $firstUserID;
  213     } else {
  214       push @error, E_ONE_USER unless $nusers == 1;
  215       push @error, E_MAX_ONE_SET unless $nsets <= 1;
  216     }
  217   };
  218 
  219   defined param $r "edit_set_for_users" and do {
  220     if ($nusers >= 1 and $nsets == 1) {
  221       $module = "${ipfx}::ProblemSetDetail";
  222       $args{setID} = $firstSetID;
  223       $params{editForUser} = \@selectedUserIDs;
  224     } else {
  225       push @error, E_MIN_ONE_USER unless $nusers >= 1;
  226       push @error, E_ONE_SET unless $nsets == 1;
  227 
  228     }
  229   };
  230 
  231   defined param $r "create_set" and do {
  232     my $setname = $r->param("new_set_name");
  233     if ($setname && $setname ne 'Name for new set here') {
  234     if ($setname =~ /^[\w.-]*$/) {
  235     $module = "${ipfx}::SetMaker";
  236     $params{new_local_set} = "Create a New Set in this Course";
  237     $params{new_set_name} = $setname;
  238     $params{selfassign} = 1;
  239       } else {
  240     push @error, E_BAD_NAME;
  241       }
  242     } else {
  243     push @error, E_SET_NAME;
  244     }
  245   };
  246 
  247   defined param $r "add_users" and do {
  248     $module = "${ipfx}::AddUsers";
  249   };
  250 
  251   defined param $r "email_users" and do {
  252     $module = "${ipfx}::SendMail";
  253   };
  254 
  255   defined param $r "transfer_files" and do {
  256     $module = "${ipfx}::FileManager";
  257   };
  258 
  259   push @error, "You are not allowed to act as a student."
  260     if (defined param $r "act_as_user" and not $authz->hasPermissions($userID, "become_student"));
  261   push @error, "You are not allowed to modify homework sets."
  262     if ((defined param $r "edit_sets" or defined param $r "edit_set_for_users") and not $authz->hasPermissions($userID, "modify_problem_sets"));
  263   push @error, "You are not allowed to assign homework sets."
  264     if ((defined param $r "sets_assigned_to_user" or defined param $r "users_assigned_to_set") and not $authz->hasPermissions($userID, "assign_problem_sets"));
  265   push @error, "You are not allowed to modify student data."
  266     if ((defined param $r "edit_users" or defined param $r "user_options" or defined param $r "user_options") and not $authz->hasPermissions($userID, "modify_student_data"));
  267   push @error, "You are not allowed to score sets."
  268     if (defined param $r "score_sets" and not $authz->hasPermissions($userID, "score_sets"));
  269 
  270   # handle errors, redirect to target page
  271   if (@error) {
  272     $self->addbadmessage(CGI::p(join(CGI::br(),@error)));
  273 
  274   } elsif ($module) {
  275     my $page = $urlpath->newFromModule($module, %args);
  276     my $url = $self->systemLink($page, params => \%params);
  277     $self->reply_with_redirect($url);
  278   }
  279 }
  280 
  281 sub body {
  282   my ($self) = @_;
  283   my $r = $self->r;
  284   my $db = $r->db;
  285   my $ce = $r->ce;
  286   my $authz = $r->authz;
  287   my $courseName = $self->{courseName};
  288   my $user = $r->param("user");
  289 
  290   return CGI::div({class=>"ResultsWithError"}, "You are not authorized to access the Instructor tools.")
  291     unless $authz->hasPermissions($user, "access_instructor_tools");
  292 
  293   print CGI::p({},"Use the interface below to quickly access commonly-used
  294   instructor tools, or select a tool from the list to the left.", CGI::br(),
  295   "Select user(s) and/or set(s) below and click the action button
  296   of your choice.");
  297 
  298   # DBFIXME shouldn't need to use list of IDs, use iterator for results, marks edits in WHERE clause
  299   # the grep here prevents set-level proctors from being displayed here
  300   my @userIDs = grep {$_ !~ /^set_id:/} $db->listUsers;
  301   my @Users = $db->getUsers(@userIDs);
  302 
  303 ## Mark's Edits for filtering
  304   my @myUsers;
  305 
  306   my (@viewable_sections,@viewable_recitations);
  307 
  308   if (defined @{$ce->{viewable_sections}->{$user}})
  309     {@viewable_sections = @{$ce->{viewable_sections}->{$user}};}
  310   if (defined @{$ce->{viewable_recitations}->{$user}})
  311     {@viewable_recitations = @{$ce->{viewable_recitations}->{$user}};}
  312 
  313   if (@viewable_sections or @viewable_recitations){
  314     foreach my $student (@Users){
  315       my $keep = 0;
  316       foreach my $sec (@viewable_sections){
  317         if ($student->section() eq $sec){$keep = 1;}
  318       }
  319       foreach my $rec (@viewable_recitations){
  320         if ($student->recitation() eq $rec){$keep = 1;}
  321       }
  322       if ($keep) {push @myUsers, $student;}
  323     }
  324     @Users = @myUsers;
  325   }
  326 ## End Mark's Edits
  327 
  328   # DBFIXME shouldn't need to use list of IDs, use iterator for results
  329   my @globalSetIDs = $db->listGlobalSets;
  330   my @GlobalSets = $db->getGlobalSets(@globalSetIDs);
  331 
  332   my @selected_users = $r->param("selected_users");
  333   my @selected_sets = $r->param("selected_sets");
  334 
  335   my $scrolling_user_list = scrollingRecordList({
  336       name => "selected_users",
  337       request => $r,
  338       default_sort => "lnfn",
  339       default_format => "lnfn_uid",
  340       default_filters => ["all"],
  341       size => 10,
  342       multiple => 1,
  343     }, @Users);
  344 
  345   my $scrolling_set_list = scrollingRecordList({
  346     name => "selected_sets",
  347     request => $r,
  348     default_sort => "set_id",
  349     default_format => "sid",
  350     default_filters => ["all"],
  351     size => 10,
  352     multiple => 1,
  353   }, @GlobalSets);
  354 
  355   print CGI::start_form({method=>"get", action=>$r->uri()});
  356   print $self->hidden_authen_fields();
  357 
  358   print CGI::table({class=>"FormLayout"},
  359     CGI::Tr({},
  360       CGI::th("Users"),
  361       CGI::th("Sets"),
  362     ),
  363     CGI::Tr({},
  364       CGI::td({style=>"width:50%"}, $scrolling_user_list),
  365       CGI::td({style=>"width:50%"}, $scrolling_set_list),
  366     ),
  367     CGI::Tr({class=>"ButtonRow"}, [
  368       CGI::td([
  369         CGI::submit(-name=>"sets_assigned_to_user", -label=>"View/edit")." all sets for one <b>user</b>(set dates, scores)",
  370         CGI::submit(-name=>"users_assigned_to_set", -label=>"View/edit")." all users for one <b>set</b>",
  371       ]),
  372       CGI::td([
  373         CGI::submit(-name=>"edit_users", -label=>"Edit"). " class list data for selected <b>users</b>",
  374         CGI::submit(-name=>"edit_sets", -label=>"Edit"). " one <b>set</b>" . "&nbsp; &nbsp; ".
  375         "or &nbsp; ".CGI::submit(-name=>"prob_lib",-label=>"add problems")." to one <b>set</b>",
  376       ]),
  377       CGI::td([
  378         CGI::submit(-name=>"user_stats", -label=>"Statistics")." or ".
  379         CGI::submit(-name=>"user_progress", -label=>"progress")." for one <b>user</b>",
  380         CGI::submit(-name=>"set_stats", -label=>"Statistics")." or ".
  381         CGI::submit(-name=>"set_progress", -label=>"progress")." for one <b>set</b>",
  382       ]),
  383       CGI::td([
  384         CGI::submit(-name=>"user_options", -label=>"Change password")." for one <b>user</b>",
  385         CGI::submit(-name=>"score_sets", -label=>"Score"). " selected <b>sets</b>",
  386       ]),
  387       CGI::td([
  388         CGI::submit(-name=>"add_users", -label=>"Add")." new users",
  389         CGI::submit(-name=>"create_set", -label=>"Create"). " new set: ".
  390            CGI::textfield(-name=>"new_set_name",
  391              -default=>"Name for new set here",
  392              -override=>1, -size=>20),
  393         ]),
  394     ]),
  395     CGI::Tr({class=>"ButtonRowCenter"},
  396       CGI::td({-colspan=>2, align=>"center"},
  397         CGI::table({-border=>0, align=>"center"},
  398           CGI::Tr({-align=>"left"}, [
  399             CGI::td({-height=>2}),
  400             CGI::td(CGI::submit(-name=>"assign_users", -label=>"Assign")." selected <b>users</b> to selected <b>sets</b>"),
  401             CGI::td(CGI::submit(-name=>"act_as_user", -label=>"Act as")." one <b>user</b> (on one <b>set</b>)"),
  402             CGI::td(CGI::submit(-name=>"edit_set_for_users", -label=>"Edit"). " one <b>set</b> for  <b>users</b>"),
  403             CGI::td({-height=>4}),
  404             CGI::td(CGI::submit(-name=>"email_users", -label=>"Email"). " your students"),
  405             ($authz->hasPermissions($user, "manage_course_files")
  406               ? CGI::td(CGI::submit(-name=>"transfer_files", -label=>"Transfer"). " course files")
  407               : ()
  408             ),
  409           ])
  410         )
  411       )
  412     ),
  413   );
  414 
  415   print CGI::end_form();
  416 
  417   return "";
  418 }
  419 
  420 1;
  421 
  422 __END__
  423 
  424 =head1 AUTHOR
  425 
  426 Written by Dennis Lambe Jr., malsyned (at) math.rochester.edu.
  427 
  428 =cut

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9