[system] / branches / rel-2-1-patches / webwork2 / lib / WeBWorK / ContentGenerator / ProblemSets.pm Repository:
ViewVC logotype

View of /branches/rel-2-1-patches/webwork2/lib/WeBWorK/ContentGenerator/ProblemSets.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1846 - (download) (as text) (annotate)
Sat Mar 6 00:48:16 2004 UTC (9 years, 2 months ago) by gage
Original Path: trunk/webwork2/lib/WeBWorK/ContentGenerator/ProblemSets.pm
File size: 8558 byte(s)
Changes to the ways links are constructed on this, the front page,
of WeBWorK.  I believe this is where links missing webwork2 or missing
the course name started to appear.  In fact I'm surprised it worked at
all.

the current patches are hacks.  This page needs to be adapted to
URLpath.
It would be a good script to do next.

--Mike

    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.41 2004/01/25 20:04:20 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   # Print link to instructor page for instructors
   67   if ($permissionLevel >= 10 ) {
   68 
   69     my $instructorLink = "$root/$courseName/instructor/?" . $self->url_authen_args();
   70     print CGI::p({-align=>'center'},CGI::a({-href=>$instructorLink},'Instructor Tools'));
   71   }
   72   # Print message of the day (motd)
   73   if (defined $ce->{courseFiles}->{motd}
   74     and $ce->{courseFiles}->{motd}) {
   75     my $motd = eval { readFile($ce->{courseFiles}->{motd}) };
   76     $@ or print $motd;
   77   }
   78 
   79   $sort = "status" unless $sort eq "status" or $sort eq "name";
   80   my $baseURL = $r->uri . "?" . $self->url_authen_args();
   81   my $nameHeader = ($sort eq "name") ? CGI::u("Name") : CGI::a({-href=>"$baseURL&sort=name"}, "Name");
   82   my $statusHeader = ($sort eq "status") ? CGI::u("Status") : CGI::a({-href=>"$baseURL&sort=status"}, "Status");
   83 
   84   my $actionURL    = $r->uri;     #FIXME Hack Hack
   85   $actionURL =~ s|/$||;
   86   $actionURL .= "/hardcopy/";
   87   print CGI::startform(-method=>"POST", -action=>$actionURL);
   88   print $self->hidden_authen_fields;
   89   print CGI::start_table();
   90   print CGI::Tr(
   91     CGI::th("Sel."),
   92     CGI::th($nameHeader),
   93     CGI::th($statusHeader),
   94     #CGI::th("Hardcopy"),
   95   );
   96 
   97   my @setIDs = $db->listUserSets($effectiveUser);
   98 
   99   my @userSetIDs = map {[$effectiveUser, $_]} @setIDs;
  100   $WeBWorK::timer->continue("Begin collecting merged sets") if defined($WeBWorK::timer);
  101   my @sets = $db->getMergedSets( @userSetIDs );
  102   $WeBWorK::timer->continue("Begin sorting merged sets") if defined($WeBWorK::timer);
  103 
  104   @sets = sortByName("set_id", @sets) if $sort eq "name";
  105   @sets = sort byduedate @sets if $sort eq "status";
  106   $WeBWorK::timer->continue("End preparing merged sets") if defined($WeBWorK::timer);
  107 
  108   foreach my $set (@sets) {
  109     die "set $set not defined" unless $set;
  110     print $self->setListRow($set, ($permissionLevel > 0),
  111       ($permissionLevel > 0));
  112   }
  113 
  114   print CGI::end_table();
  115   my $pl = ($permissionLevel > 0 ? "s" : "");
  116   print CGI::p(CGI::submit("hardcopy", "Download Hardcopy for Selected Set$pl"));
  117   print CGI::endform();
  118 
  119   # feedback form url
  120   my $feedbackURL = "$root/$courseName/feedback/";
  121 
  122   #print feedback form
  123   print
  124     CGI::start_form(-method=>"POST", -action=>$feedbackURL),"\n",
  125     $self->hidden_authen_fields,"\n",
  126     CGI::hidden("module",             __PACKAGE__),"\n",
  127     CGI::hidden("set",                ''),"\n",
  128     CGI::hidden("problem",            ''),"\n",
  129     CGI::hidden("displayMode",        $self->{displayMode}),"\n",
  130     CGI::hidden("showOldAnswers",     ''),"\n",
  131     CGI::hidden("showCorrectAnswers", ''),"\n",
  132     CGI::hidden("showHints",          ''),"\n",
  133     CGI::hidden("showSolutions",      ''),"\n",
  134     CGI::p({-align=>"left"},
  135       CGI::submit(-name=>"feedbackForm", -label=>"Email instructor")
  136     ),
  137     CGI::endform(),"\n";
  138 
  139   return "";
  140 }
  141 
  142 sub setListRow($$$) {
  143   my ($self, $set, $multiSet, $preOpenSets) = @_;
  144 
  145   my $name = $set->set_id;
  146   my $ce              = $self->{ce};
  147   my $root            = $ce->{webworkURLs}->{root};
  148   my $courseName      = $ce->{courseName};
  149   # FIXME  -- better way to find the path
  150   my $interactiveURL = "$root/$courseName/$name/?" . $self->url_authen_args;
  151   #my $hardcopyURL = "hardcopy/$name/?" . $self->url_authen_args;
  152 
  153   my $openDate = formatDateTime($set->open_date);
  154   my $dueDate = formatDateTime($set->due_date);
  155   my $answerDate = formatDateTime($set->answer_date);
  156 
  157   #my $checkbox = CGI::checkbox(-name=>"hcSet", -value=>$set->set_id, -label=>"");
  158 
  159   my $control = "";
  160   if ($multiSet) {
  161     $control = CGI::checkbox(
  162       -name=>"hcSet",
  163       -value=>$name,
  164       -label=>"",
  165     );
  166   } else {
  167     $control = CGI::radio_group(
  168       -name=>"hcSet",
  169       -values=>[$name],
  170       -default=>"-",
  171       -labels=>{$name => ""},
  172     );
  173   }
  174 
  175   my $interactive = CGI::a({-href=>$interactiveURL}, "set $name");
  176 
  177   my $status;
  178   if (time < $set->open_date) {
  179     $status = "opens at $openDate";
  180     $control = "" unless $preOpenSets;
  181     $interactive = $name unless $preOpenSets;
  182   } elsif (time < $set->due_date) {
  183     $status = "open, due $dueDate";
  184   } elsif (time < $set->answer_date) {
  185     $status = "closed, answers at $answerDate";
  186   } else {
  187     $status = "closed, answers available";
  188   }
  189 
  190   return CGI::Tr(CGI::td([
  191     $control,
  192     $interactive,
  193     $status,
  194   ]));
  195 }
  196 sub info {
  197   my $self       = shift;
  198   my $r          = $self->{r};
  199   my $ce         = $self->{ce};
  200   my $db         = $self->{db};
  201   my $user       = $r->param("user");
  202   my $root       = $ce->{webworkURLs}->{root};
  203   my $courseName = $ce->{courseName};
  204   ###########################################################
  205   # The course information and problems are located in the course templates directory.
  206   # Course information has the name  defined by courseFiles->{course_info}
  207   #
  208   # Only files under the template directory ( or linked to this location) can be edited.
  209   #
  210   # editMode = temporaryFile    (view the temp file defined by course_info.txt.user_name.tmp
  211   #                              instead of the file course_info.txt)
  212   # The editFileSuffix is "user_name.tmp" by default.  It's definition should be moved to Instructor.pm #FIXME
  213   ###########################################################
  214   if (defined $ce->{courseFiles}->{course_info}
  215     and $ce->{courseFiles}->{course_info})     {
  216     my $course_info_path  = $ce->{courseDirs}->{templates}
  217                          .'/'. $ce->{courseFiles}->{course_info};
  218     my $editFileSuffix      = $user.'.tmp';  #FIXME -- this could be moved to Instructor.pm
  219     $course_info_path    .= ".$editFileSuffix" if defined($r->param("editMode")) and $r->param("editMode") eq 'temporaryFile';
  220 
  221     my $course_info = eval { readFile($course_info_path) };
  222     $@ or print $course_info;
  223     my $user            = $r->param("user");
  224     my $permissionLevel = $db->getPermissionLevel($user)->permission(); # checked???
  225     $permissionLevel    = 0 unless defined $permissionLevel;
  226       if ($permissionLevel>=10) {
  227       my $editURL = "$root/$courseName/instructor/pgProblemEditor/?"
  228               .$self->url_authen_args
  229               ."&file_type=course_info"
  230       ;
  231       my $editText      = "Edit message file";
  232       $editText         = "Edit temporary message file" if defined($r->param("editMode")) and $r->param("editMode") eq 'temporaryFile';
  233       print CGI::br(), CGI::a({-href=>$editURL}, $editText);
  234       }
  235 
  236   }
  237 
  238 
  239   '';
  240 }
  241 sub byname { $a->set_id cmp $b->set_id; }
  242 sub byduedate { $a->due_date <=> $b->due_date; }
  243 
  244 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9