File:
[LON-CAPA] /
loncom /
interface /
lonwishlistdisplay.pm
Revision
1.7:
download - view:
text,
annotated -
select for diffs
Fri Dec 24 00:48:30 2021 UTC (2 years, 9 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
HEAD
- Bug 6955 IP-based blocking.
- Course search, Stored links, and Resource Annotations added to functions
which can be blocked by client IP. (User with evb priv in course exempt).
1: # The LearningOnline Network with CAPA
2: # Routines to display the wishlist (handler)
3: #
4: # $Id: lonwishlistdisplay.pm,v 1.7 2021/12/24 00:48:30 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::lonwishlistdisplay;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::lonnet;
34: use Apache::loncommon();
35: use Apache::lonhtmlcommon;
36: use Apache::lonlocal;
37: use Apache::lonwishlist;
38: use LONCAPA;
39: use Tree;
40:
41:
42: # Global variables
43: my $root;
44: my @childrenRt;
45: my %TreeHash;
46:
47:
48: # ----------------------------------------------------- Main Handler, package lonwishlistdisplay
49: sub handler {
50: my ($r) = @_;
51:
52: if ($r->header_only) {
53: &Apache::loncommon::content_type($r,'text/html');
54: $r->send_http_header;
55: return OK;
56: }
57:
58: if ($env{'user.adv'}) {
59: &Apache::loncommon::content_type($r,'text/html');
60: $r->send_http_header;
61: } else {
62: $env{'user.error.msg'}=
63: "/adm/wishlist:bre:0:0:No rights to access Stored Links";
64: return HTTP_NOT_ACCEPTABLE;
65: }
66:
67: my $clientip = &Apache::lonnet::get_requestor_ip($r);
68: my ($blocked,$blocktext) =
69: &Apache::loncommon::blocking_status('wishlist',$clientip);
70: if ($blocked) {
71: &Apache::lonhtmlcommon::clear_breadcrumbs();
72: &Apache::lonhtmlcommon::add_breadcrumb(
73: { href => '/adm/wishlist',
74: text => 'Stored Links'});
75: my $startPage = &Apache::loncommon::start_page('Stored Links');
76: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Stored Links','Wishlist');
77: my $endpage = &Apache::loncommon::end_page();
78: $r->print($startPage.$breadcrumbs.$blocktext);
79: return OK;
80: }
81:
82: if (&Apache::lonwishlist::getWishlist() ne 'error') {
83: # get wishlist entries from user-data db-file and build a tree out of these entries
84: %TreeHash = &Apache::lonwishlist::getWishlist();
85:
86: $root = &Apache::Tree::HashToTree(\%TreeHash);
87: @childrenRt = $root->children();
88:
89: # create a new entry
90: if ($env{'form.title'}) {
91: $root = &Apache::lonwishlist::newEntry($root, $env{'form.title'}, $env{'form.path'}, $env{'form.note'});
92: }
93:
94: # get unprocessed_cgi (i.e. marked entries, mode ...)
95: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','mark','markedToMove','mode','newtitle','note','rat','setTitle','setPath']);
96:
97: # change the order of entries within a level, that means sorting the entries
98: my $changeOrder = 0;
99: if (defined($env{'form.sel'})) {
100: my @sel = &Apache::loncommon::get_env_multiple('form.sel');
101: my $indexNode;
102: my $at;
103: for (my $s=0; $s<($#sel+1); $s++) {
104: if ($sel[$s] ne '') {
105: $indexNode = $s;
106: $at = $sel[$s]-1;
107: }
108: }
109: if ($at ne '') {
110: $changeOrder = 1;
111: $root = &Apache::lonwishlist::sortEntries($root, $indexNode,$at);
112: }
113: }
114:
115: # get all marked (checkboxes) entries
116: my @marked = ();
117: if (defined($env{'form.mark'})) {
118: @marked = &Apache::loncommon::get_env_multiple('form.mark');
119: }
120:
121: # move entries from one folder to another
122: if (defined($env{'form.markedToMove'})) {
123: my $markedToMove = $env{'form.markedToMove'};
124: my @ToMove = split(/\,/,$markedToMove);
125: my $moveTo = $env{'form.mark'};
126: if (defined($moveTo)) {
127: $root = &Apache::lonwishlist::moveEntries($root, \@ToMove,$moveTo);
128: }
129: $changeOrder = 1;
130: }
131:
132: # delete entries
133: if ($env{'form.action'} eq 'delete') {
134: $root = &Apache::lonwishlist::deleteEntries($root, \@marked);
135: }
136:
137: # get all titles and notes and save them
138: # only save, if user wants to save changes
139: # do not save, when current action is 'delete' or 'sort' or 'move'
140: my @newTitles = ();
141: my @newPaths = ();
142: my @newNotes = ();
143: if ((defined $env{'form.newtitle'} || defined $env{'form.newpath'} || defined $env{'form.newnote'})
144: && ($env{'form.action'} ne 'noSave') && ($env{'form.action'} ne 'delete') && !$changeOrder) {
145: @newTitles = &Apache::loncommon::get_env_multiple('form.newtitle');
146: @newPaths = &Apache::loncommon::get_env_multiple('form.newpath');
147: @newNotes = &Apache::loncommon::get_env_multiple('form.newnote');
148: my $node = 0;
149: foreach my $t (@newTitles) {
150: $root = &Apache::lonwishlist::setNewTitle($root, $node, $t);
151: $node++;
152: }
153: $node = 0;
154: my $path = 0;
155: for (my $i = 0; $i < ($#newTitles+1); $i++ ) {
156: if (&Apache::lonwishlist::setNewPath($root, $node, $newPaths[$path])) {
157: $path++;
158: }
159: $node++;
160: }
161: $node = 0;
162: foreach my $n (@newNotes) {
163: $root = &Apache::lonwishlist::setNewNote($root, $node, $n);
164: $node++;
165: }
166: }
167:
168: # Create HTML-markup
169: my $page;
170: if ($env{'form.mode'} eq 'edit') {
171: $page = &Apache::lonwishlist::makePage($root, "edit");
172: } elsif ($env{'form.mode'} eq 'move') {
173: $page = &Apache::lonwishlist::makePage($root, "move", \@marked);
174: } elsif ($env{'form.mode'} eq 'import') {
175: $page = &Apache::lonwishlist::makePageImport($root, $env{'form.rat'});
176: } elsif ($env{'form.mode'} eq 'newLink') {
177: $page = &Apache::lonwishlist::makePopUpNewLink($env{'form.setTitle'},$env{'form.setPath'});
178: } elsif ($env{'form.mode'} eq 'newFolder') {
179: $page = &Apache::lonwishlist::makePopUpNewFolder();
180: } elsif ($env{'form.mode'} eq 'set') {
181: $page = &Apache::lonwishlist::makePageSet();
182: } else {
183: $page = &Apache::lonwishlist::makePage($root, "view");
184: }
185: @marked = ();
186: $r->print($page);
187: } else {
188: # An error occurred, print an error-page
189: my $errorPage = &Apache::lonwishlist::makeErrorPage();
190: $r->print($errorPage);
191: }
192: return OK;
193: }
194:
195: 1;
196: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>