[system] / trunk / webwork-modperl / lib / WeBWorK / ContentGenerator / ProblemSets.pm Repository:
ViewVC logotype

View of /trunk/webwork-modperl/lib/WeBWorK/ContentGenerator/ProblemSets.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1722 - (download) (as text) (annotate)
Sun Jan 18 00:11:13 2004 UTC (9 years, 5 months ago) by gage
File size: 6712 byte(s)
A link to the instructor tools is placed prominately at the top of the page.
It is identical to the link to instructor tools on the left.
This responds to bug #325, but may not close it completely.

    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/ProblemSets.pm,v 1.36 2004/01/16 00:43:06 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::ProblemSets;
   18 use base qw(WeBWorK::ContentGenerator);
   19 
   20 =head1 NAME
   21 
   22 WeBWorK::ContentGenerator::ProblemSets - Display a list of built problem sets.
   23 
   24 =cut
   25 
   26 use strict;
   27 use warnings;
   28 use CGI qw();
   29 use WeBWorK::Utils qw(readFile formatDateTime sortByName);
   30 
   31 sub path {
   32   my ($self, $args) = @_;
   33 
   34   my $ce = $self->{ce};
   35   my $root = $ce->{webworkURLs}->{root};
   36   my $courseName = $ce->{courseName};
   37   return $self->pathMacro($args,
   38     "Home" => "$root",
   39     $courseName => "",
   40   );
   41 }
   42 
   43 sub title {
   44   my $self        = shift;
   45   my $r           = $self ->{r};
   46   my $db          = $self ->{db};
   47   my $user        = $r    -> param("user");
   48   my $courseName  = $self ->{ce} -> {courseName};
   49 
   50   return "WeBWorK welcomes user $user to $courseName" ;
   51 }
   52 
   53 sub body {
   54   my $self            = shift;
   55   my $r               = $self->{r};
   56   my $ce              = $self->{ce};
   57   my $db              = $self->{db};
   58   my $user            = $r->param("user");
   59   my $effectiveUser   = $r->param("effectiveUser");
   60   my $sort            = $r->param("sort") || "status";
   61   my $permissionLevel = $db->getPermissionLevel($user)->permission(); # checked???
   62   $permissionLevel    = 0 unless defined $permissionLevel;
   63   my $root            = $ce->{webworkURLs}->{root};
   64   my $courseName      = $ce->{courseName};
   65 
   66   ###################################################
   67   # Print link to instructor page for instructors
   68   ###################################################
   69   if ($permissionLevel >= 10 ) {
   70 
   71     my $instructorLink = "$root/$courseName/instructor/?" . $self->url_authen_args();
   72     print CGI::p({-align=>'center'},CGI::a({-href=>$instructorLink},'Link to Instructor Tools'));
   73   }
   74   ###################################################
   75   # Print message of the day motd
   76   ###################################################
   77   if (defined $ce->{courseFiles}->{motd}
   78     and $ce->{courseFiles}->{motd}) {
   79     my $motd = eval { readFile($ce->{courseFiles}->{motd}) };
   80     $@ or print $motd;
   81   }
   82 
   83   $sort = "status" unless $sort eq "status" or $sort eq "name";
   84   my $baseURL = $r->uri . "?" . $self->url_authen_args();
   85   my $nameHeader = ($sort eq "name") ? CGI::u("Name") : CGI::a({-href=>"$baseURL&sort=name"}, "Name");
   86   my $statusHeader = ($sort eq "status") ? CGI::u("Status") : CGI::a({-href=>"$baseURL&sort=status"}, "Status");
   87 
   88   print CGI::startform(-method=>"POST", -action=>$r->uri."hardcopy/");
   89   print $self->hidden_authen_fields;
   90   print CGI::start_table();
   91   print CGI::Tr(
   92     CGI::th("Sel."),
   93     CGI::th($nameHeader),
   94     CGI::th($statusHeader),
   95     #CGI::th("Hardcopy"),
   96   );
   97 
   98   my @setIDs = $db->listUserSets($effectiveUser);
   99 
  100   my @userSetIDs = map {[$effectiveUser, $_]} @setIDs;
  101   $WeBWorK::timer->continue("Begin collecting merged sets") if defined($WeBWorK::timer);
  102   my @sets = $db->getMergedSets( @userSetIDs );
  103   $WeBWorK::timer->continue("Begin sorting merged sets") if defined($WeBWorK::timer);
  104 
  105   @sets = sortByName("set_id", @sets) if $sort eq "name";
  106   @sets = sort byduedate @sets if $sort eq "status";
  107   $WeBWorK::timer->continue("End preparing merged sets") if defined($WeBWorK::timer);
  108 
  109   foreach my $set (@sets) {
  110     die "set $set not defined" unless $set;
  111     print $self->setListRow($set, ($permissionLevel > 0),
  112       ($permissionLevel > 0));
  113   }
  114 
  115   print CGI::end_table();
  116   my $pl = ($permissionLevel > 0 ? "s" : "");
  117   print CGI::p(CGI::submit("hardcopy", "Download Hardcopy for Selected Set$pl"));
  118   print CGI::endform();
  119 
  120   # feedback form
  121   my $feedbackURL = "$root/$courseName/feedback/";
  122 
  123 
  124   #print feedback form
  125   print
  126     CGI::start_form(-method=>"POST", -action=>$feedbackURL),"\n",
  127     $self->hidden_authen_fields,"\n",
  128     CGI::hidden("module",             __PACKAGE__),"\n",
  129     CGI::hidden("set",                ''),"\n",
  130     CGI::hidden("problem",            ''),"\n",
  131     CGI::hidden("displayMode",        $self->{displayMode}),"\n",
  132     CGI::hidden("showOldAnswers",     ''),"\n",
  133     CGI::hidden("showCorrectAnswers", ''),"\n",
  134     CGI::hidden("showHints",          ''),"\n",
  135     CGI::hidden("showSolutions",      ''),"\n",
  136     CGI::p({-align=>"left"},
  137       CGI::submit(-name=>"feedbackForm", -label=>"Email instructor")
  138     ),
  139     CGI::endform(),"\n";
  140 
  141   return "";
  142 }
  143 
  144 sub setListRow($$$) {
  145   my ($self, $set, $multiSet, $preOpenSets) = @_;
  146 
  147   my $name = $set->set_id;
  148 
  149   my $interactiveURL = "$name/?" . $self->url_authen_args;
  150   #my $hardcopyURL = "hardcopy/$name/?" . $self->url_authen_args;
  151 
  152   my $openDate = formatDateTime($set->open_date);
  153   my $dueDate = formatDateTime($set->due_date);
  154   my $answerDate = formatDateTime($set->answer_date);
  155 
  156   #my $checkbox = CGI::checkbox(-name=>"hcSet", -value=>$set->set_id, -label=>"");
  157 
  158   my $control = "";
  159   if ($multiSet) {
  160     $control = CGI::checkbox(
  161       -name=>"hcSet",
  162       -value=>$name,
  163       -label=>"",
  164     );
  165   } else {
  166     $control = CGI::radio_group(
  167       -name=>"hcSet",
  168       -values=>[$name],
  169       -default=>"-",
  170       -labels=>{$name => ""},
  171     );
  172   }
  173 
  174   my $interactive = CGI::a({-href=>$interactiveURL}, "set $name");
  175 
  176   my $status;
  177   if (time < $set->open_date) {
  178     $status = "opens at $openDate";
  179     $control = "" unless $preOpenSets;
  180     $interactive = $name unless $preOpenSets;
  181   } elsif (time < $set->due_date) {
  182     $status = "open, due $dueDate";
  183   } elsif (time < $set->answer_date) {
  184     $status = "closed, answers at $answerDate";
  185   } else {
  186     $status = "closed, answers available";
  187   }
  188 
  189   return CGI::Tr(CGI::td([
  190     $control,
  191     $interactive,
  192     $status,
  193   ]));
  194 }
  195 sub info {
  196   my $self = shift;
  197   my $r = $self->{r};
  198   my $ce = $self->{ce};
  199 
  200   if (defined $ce->{courseFiles}->{course_info}
  201     and $ce->{courseFiles}->{course_info}) {
  202     my $course_info = eval { readFile($ce->{courseFiles}->{course_info}) };
  203     $@ or print $course_info;
  204   }
  205   '';
  206 }
  207 sub byname { $a->set_id cmp $b->set_id; }
  208 sub byduedate { $a->due_date <=> $b->due_date; }
  209 
  210 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9