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

Diff of /branches/rel-2-1-a1/webwork2/lib/WeBWorK/ContentGenerator/ProblemSet.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2531 Revision 2532
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/ProblemSet.pm,v 1.53 2004/06/03 19:38:45 toenail Exp $ 4# $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/ProblemSet.pm,v 1.56 2004/07/07 18:15:20 gage Exp $
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 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 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 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. 9# version, or (b) the "Artistic License" which comes with this package.
34sub initialize { 34sub initialize {
35 my ($self) = @_; 35 my ($self) = @_;
36 my $r = $self->r; 36 my $r = $self->r;
37 my $db = $r->db; 37 my $db = $r->db;
38 my $urlpath = $r->urlpath; 38 my $urlpath = $r->urlpath;
39 my $authz = $r->authz;
39 40
40 my $setName = $urlpath->arg("setID"); 41 my $setName = $urlpath->arg("setID");
41 my $userName = $r->param("user"); 42 my $userName = $r->param("user");
42 my $effectiveUserName = $r->param("effectiveUser"); 43 my $effectiveUserName = $r->param("effectiveUser");
43 44
44 my $user = $db->getUser($userName); # checked 45 my $user = $db->getUser($userName); # checked
45 my $effectiveUser = $db->getUser($effectiveUserName); # checked 46 my $effectiveUser = $db->getUser($effectiveUserName); # checked
46 my $set = $db->getMergedSet($effectiveUserName, $setName); # checked 47 my $set = $db->getMergedSet($effectiveUserName, $setName); # checked
47 my $permissionLevel = $db->getPermissionLevel($userName); # checked
48 48
49 die "user $user (real user) not found." unless $user; 49 die "user $user (real user) not found." unless $user;
50 die "effective user $effectiveUserName not found. One 'acts as' the effective user." unless $effectiveUser; 50 die "effective user $effectiveUserName not found. One 'acts as' the effective user." unless $effectiveUser;
51 die "permisson level for user $userName not found." unless $permissionLevel;
52 51
53 # A set is valid if it is defined and if it is either published or the user is privileged. 52 # A set is valid if it is defined and if it is either published or the user is privileged.
54 $self->{invalidSet} = !(defined $set && ($set->published || $permissionLevel->permission > 0)); 53 $self->{invalidSet} = !(defined $set && ($set->published || $authz->hasPermissions($userName, "view_unpublished_sets")));
55 return if $self->{invalidSet}; 54 return if $self->{invalidSet};
56 55
57 # FIXME: This is a temporary fix to fill in the database 56 # FIXME: This is a temporary fix to fill in the database
58 # We want the published field to contain either 1 or 0 so if it has not been set to 0, default to 1 57 # We want the published field to contain either 1 or 0 so if it has not been set to 0, default to 1
59 # this will fill in all the empty fields but not change anything that has been specifically set to 1 or 0 58 # this will fill in all the empty fields but not change anything that has been specifically set to 1 or 0
62 $set->published("1") if defined $set and defined($set->published) and $set->published ne "0"; 61 $set->published("1") if defined $set and defined($set->published) and $set->published ne "0";
63 $db->putGlobalSet($globalSet); 62 $db->putGlobalSet($globalSet);
64 63
65 my $publishedText = ($set->published) ? "visible to students." : "hidden from students."; 64 my $publishedText = ($set->published) ? "visible to students." : "hidden from students.";
66 my $publishedClass = ($set->published) ? "Published" : "Unpublished"; 65 my $publishedClass = ($set->published) ? "Published" : "Unpublished";
67 $self->addmessage(CGI::p("This set is " . CGI::font({class=>$publishedClass}, $publishedText))) if $permissionLevel->permission > 0; 66 $self->addmessage(CGI::p("This set is " . CGI::font({class=>$publishedClass}, $publishedText))) if $authz->hasPermissions($userName, "view_unpublished_sets");
68 67
69 $self->{userName} = $userName; 68 $self->{userName} = $userName;
70 $self->{user} = $user; 69 $self->{user} = $user;
71 $self->{effectiveUser} = $effectiveUser; 70 $self->{effectiveUser} = $effectiveUser;
72 $self->{set} = $set; 71 $self->{set} = $set;
73 $self->{permissionLevel} = $permissionLevel->permission;
74 72
75 ##### permissions ##### 73 ##### permissions #####
76 74
77 $self->{isOpen} = time >= $set->open_date || $permissionLevel->permission > 0; 75 $self->{isOpen} = time >= $set->open_date || $authz->hasPermissions($userName, "view_unopened_sets");
78} 76}
79 77
80sub nav { 78sub nav {
81 my ($self, $args) = @_; 79 my ($self, $args) = @_;
82 my $r = $self->r; 80 my $r = $self->r;
92 90
93sub siblings { 91sub siblings {
94 my ($self) = @_; 92 my ($self) = @_;
95 my $r = $self->r; 93 my $r = $self->r;
96 my $db = $r->db; 94 my $db = $r->db;
97 my $urlpath = $r->urlpath; 95 my $authz = $r->authz;
96 my $urlpath = $r->urlpath;
98 97
98
99 my $courseID = $urlpath->arg("courseID"); 99 my $courseID = $urlpath->arg("courseID");
100 my $user = $r->param('user');
100 my $eUserID = $r->param("effectiveUser"); 101 my $eUserID = $r->param("effectiveUser");
101 my @setIDs = sortByName(undef, $db->listUserSets($eUserID)); 102 my @setIDs = sortByName(undef, $db->listUserSets($eUserID));
102 103 # do not show unpublished siblings unless user is allowed to view unpublished sets
104 unless ($authz->hasPermissions($user, "view_unpublished_sets") ) {
105 @setIDs = grep {my $visible = $db->getGlobalSet( $_)->published; (defined($visible))? $visible : 1}
106 @setIDs;
107 }
103 print CGI::start_ul({class=>"LinksMenu"}); 108 print CGI::start_ul({class=>"LinksMenu"});
104 print CGI::start_li(); 109 print CGI::start_li();
105 print CGI::span({style=>"font-size:larger"}, "Problem Sets"); 110 print CGI::span({style=>"font-size:larger"}, "Problem Sets");
106 print CGI::start_ul(); 111 print CGI::start_ul();
107 112
108 # FIXME: setIDs contain no info on published/unpublished so unpublished sets are still printed 113 # FIXME: setIDs contain no info on published/unpublished so unpublished sets are still printed
109 $WeBWorK::timer->continue("Begin printing sets from listUserSets()") if defined $WeBWorK::timer; 114 $WeBWorK::timer->continue("Begin printing sets from listUserSets()") if defined $WeBWorK::timer;
110 foreach my $setID (@setIDs) { 115 foreach my $setID (@setIDs) {
111 my $setPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSet", 116 my $setPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSet",
112 courseID => $courseID, setID => $setID); 117 courseID => $courseID, setID => $setID);
113 print CGI::li(CGI::a({href=>$self->systemLink($setPage)}, $setID)); 118 print CGI::li(CGI::a({href=>$self->systemLink($setPage)}, $setID)) ;
114 } 119 }
115 $WeBWorK::timer->continue("End printing sets from listUserSets()") if defined $WeBWorK::timer; 120 $WeBWorK::timer->continue("End printing sets from listUserSets()") if defined $WeBWorK::timer;
116 121
117 # FIXME: when database calls are faster, this will get rid of unpublished sibling links 122 # FIXME: when database calls are faster, this will get rid of unpublished sibling links
118 #$WeBWorK::timer->continue("Begin printing sets from getMergedSets()") if defined $WeBWorK::timer; 123 #$WeBWorK::timer->continue("Begin printing sets from getMergedSets()") if defined $WeBWorK::timer;
119 #my @userSetIDs = map {[$eUserID, $_]} @setIDs; 124 #my @userSetIDs = map {[$eUserID, $_]} @setIDs;
120 #my @sets = $db->getMergedSets(@userSetIDs); 125 #my @sets = $db->getMergedSets(@userSetIDs);
121 #foreach my $set (@sets) { 126 #foreach my $set (@sets) {
122 # my $setPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSet", courseID => $courseID, setID => $set->set_id); 127 # my $setPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSet", courseID => $courseID, setID => $set->set_id);
123 # print CGI::li(CGI::a({href=>$self->systemLink($setPage)}, $set->set_id)) unless !(defined $set && ($set->published || $self->{permissionLevel} > 0)); 128 # print CGI::li(CGI::a({href=>$self->systemLink($setPage)}, $set->set_id)) unless !(defined $set && ($set->published || $authz->hasPermissions($user, "view_unpublished_sets"));
124 #} 129 #}
125 #$WeBWorK::timer->continue("Begin printing sets from getMergedSets()") if defined $WeBWorK::timer; 130 #$WeBWorK::timer->continue("Begin printing sets from getMergedSets()") if defined $WeBWorK::timer;
126 131
127 print CGI::end_ul(); 132 print CGI::end_ul();
128 print CGI::end_li(); 133 print CGI::end_li();
134sub info { 139sub info {
135 my ($self) = @_; 140 my ($self) = @_;
136 my $r = $self->r; 141 my $r = $self->r;
137 my $ce = $r->ce; 142 my $ce = $r->ce;
138 my $db = $r->db; 143 my $db = $r->db;
144 my $authz = $r->authz;
139 my $urlpath = $r->urlpath; 145 my $urlpath = $r->urlpath;
140 146
141 return "" unless $self->{isOpen}; 147 return "" unless $self->{isOpen};
142 148
143 my $courseID = $urlpath->arg("courseID"); 149 my $courseID = $urlpath->arg("courseID");
188 showSolutions => 0, 194 showSolutions => 0,
189 processAnswers => 0, 195 processAnswers => 0,
190 }, 196 },
191 ); 197 );
192 198
193 if (defined($set) and $set->set_header and $self->{permissionLevel} >= $ce->{permissionLevels}->{modify_problem_sets}) { 199 if (defined($set) and $set->set_header and $authz->hasPermissions($userID, "modify_problem_sets")) {
194 #FIXME ? can't edit the default set header this way 200 #FIXME ? can't edit the default set header this way
195 my $editorPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", 201 my $editorPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor",
196 courseID => $courseID, setID => $set->set_id, problemID => 0); 202 courseID => $courseID, setID => $set->set_id, problemID => 0);
197 my $editorURL = $self->systemLink($editorPage); 203 my $editorURL = $self->systemLink($editorPage);
198 204

Legend:
Removed from v.2531  
changed lines
  Added in v.2532

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9