1: # The LearningOnline Network with CAPA
2: # Navigate Maps Display Handler
3: #
4: # $Id: lonnavdisplay.pm,v 1.32 2015/03/30 22:29:24 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:
30: package Apache::lonnavdisplay;
31:
32: use strict;
33: use Apache::Constants qw(:common :http REDIRECT);
34: use Apache::lonmenu();
35: use Apache::loncommon();
36: use Apache::lonnavmaps();
37: use Apache::lonhtmlcommon();
38: use Apache::lonnet;
39: use Apache::lonlocal;
40: use Apache::londocs();
41: use Apache::lonuserstate;
42:
43: sub handler {
44: my $r = shift;
45: real_handler($r);
46: }
47:
48: sub real_handler {
49: my $r = shift;
50: # Handle header-only request
51: if ($r->header_only) {
52: &Apache::loncommon::content_type($r,'text/html');
53: $r->send_http_header;
54: return OK;
55: }
56:
57: # Check for critical messages and redirect if present.
58: my ($redirect,$url) = &Apache::loncommon::critical_redirect(300);
59: if ($redirect) {
60: &Apache::loncommon::content_type($r,'text/html');
61: $r->header_out(Location => $url);
62: return REDIRECT;
63: }
64:
65: # Check if course needs to be re-initialized
66: my $loncaparev = $r->dir_config('lonVersion');
67: my ($result,@reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
68:
69: if ($result eq 'switch') {
70: &Apache::loncommon::content_type($r,'text/html');
71: $r->send_http_header;
72: $r->print(&Apache::loncommon::check_release_result(@reinit));
73: return OK;
74: } elsif ($result eq 'update') {
75: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
76: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
77: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
78: if ($ferr) {
79: my $requrl = $r->uri;
80: $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
81: $env{'user.reinit'} = 1;
82: return HTTP_NOT_ACCEPTABLE;
83: }
84: }
85:
86: # Create the nav map
87: my $navmap = Apache::lonnavmaps::navmap->new();
88:
89: if (!defined($navmap)) {
90: my $requrl = $r->uri;
91: $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
92: $env{'user.reinit'} = 1;
93: return HTTP_NOT_ACCEPTABLE;
94: }
95:
96: # Send header, don't cache this page
97: &Apache::loncommon::content_type($r,'text/html');
98: $r->send_http_header;
99:
100: # ------------------------------------------------------------ Get query string
101: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort','showOnlyHomework','postsymb','register']);
102:
103: # ----------------------------------------------------- Force menu registration
104: # Header
105: my $course_type = &Apache::loncommon::course_type();
106: my $title = $course_type . ' Contents';
107: my ($start_page,$args);
108: if ($env{'form.register'}) {
109: $args = {'force_register' => $env{'form.register'}};
110: $start_page = &Apache::loncommon::start_page($title,undef,$args);
111: } else {
112: my $brcrum = [{href => '/adm/navmaps',
113: text => &mt($course_type . ' Contents'),
114: no_mt => 1},
115: ];
116: $args = {'bread_crumbs' => $brcrum};
117: $start_page = &Apache::loncommon::start_page($title,undef,$args);
118: }
119: $r->print($start_page.
120: '<script type="text/javascript">'."\n".
121: '// <![CDATA['."\n".
122: 'window.focus();'."\n".
123: '// ]]>'."\n".
124: '</script>');
125: &startContentScreen($r,'navmaps');
126: $r->rflush();
127:
128: # Check that it's defined
129: if (!($navmap->courseMapDefined())) {
130: $r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
131: $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
132: '</span>' .
133: &Apache::loncommon::end_page());
134: return OK;
135: }
136:
137: my %toplinkitems=();
138: my @resources = $navmap->retrieveResources();
139: my $sequenceCount = 0;
140: my $problemCount = 0;
141: my $notaprobCount = 0;
142: my $sequenceId;
143: my $notools;
144: foreach my $curRes (@resources) {
145: if (ref($curRes)) {
146: if ($curRes->is_sequence()) {
147: $sequenceCount++;
148: $sequenceId = $curRes->map_pc();
149: } elsif ($curRes->is_problem()) {
150: $problemCount ++;
151: } else {
152: $notaprobCount ++;
153: }
154: }
155: }
156: if (($sequenceCount == 1) && (!$problemCount) && ($notaprobCount <= 1)) {
157: $notools = 1;
158: }
159:
160: # If there's only one map in the top-level and we don't
161: # already have a filter, automatically display it
162: if ($ENV{QUERY_STRING} !~ /filter/) {
163: if ($sequenceCount == 1) {
164: # The automatic iterator creation in the render call
165: # will pick this up. We know the condition because
166: # the defined($env{'form.filter'}) also ensures this
167: # is a fresh call.
168: $env{'form.filter'} = "$sequenceId";
169: }
170: }
171:
172: # Check to see if the student is jumping to next open, do-able problem
173: if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
174: # Find the next homework problem that they can do.
175: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
176: my $curRes;
177: my $foundDoableProblem = 0;
178: my $minimumduedate;
179: my $now = time();
180:
181: while ($curRes = $iterator->next()) {
182: if (ref($curRes) && $curRes->is_problem()) {
183: my $status = $curRes->status();
184: my $thisduedate=$curRes->duedate();
185: if ($thisduedate > $now
186: && $curRes->completable()) {
187:
188: $foundDoableProblem = 1;
189:
190: if (!defined($minimumduedate)
191: || $thisduedate<$minimumduedate) {
192: # Pop open all previous maps
193: my $stack = $iterator->getStack();
194: pop @$stack; # last resource in the stack is the problem
195: # itself, which we don't need in the map stack
196: my @mapPcs = map {$_->map_pc()} @$stack;
197: $env{'form.filter'} = join(',', @mapPcs);
198:
199: # Mark as both "here" and "jump"
200: $env{'form.postsymb'} = $curRes->symb();
201: $minimumduedate=$thisduedate;
202: }
203: }
204: }
205: }
206:
207: # If we found no problems, print a note to that effect.
208: if (!$foundDoableProblem) {
209: $r->print("<span class=\"LC_info\">"
210: .&mt("All homework assignments have been completed.")
211: ."</span>");
212: }
213: } else {
214: my $link = 'navmaps?jumpToFirstHomework';
215: if ($env{'form.register'}) {
216: $link .= '&register='.$env{'form.register'};
217: }
218: unless ($notools) {
219: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
220: 'location.href="'.$link.'"',
221: "Show my first due problem");
222: }
223: }
224:
225: my $suppressEmptySequences = 0;
226: my $filterFunc = undef;
227: my $resource_no_folder_link = 0;
228:
229: # Display only due homework.
230: my $showOnlyHomework = 0;
231: if ($env{'form.showOnlyHomework'} eq "1") {
232: $showOnlyHomework = 1;
233: $suppressEmptySequences = 1;
234: $filterFunc = sub { my $res = shift;
235: return $res->completable() || $res->is_map();
236: };
237: my $link = 'navmaps?sort='.$env{'form.sort'};
238: if ($env{'form.register'}) {
239: $link .= '&register='.$env{'form.register'};
240: }
241: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
242: 'location.href="'.$link.'"',
243: 'Show everything');
244: $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
245: $env{'form.filter'} = '';
246: $env{'form.condition'} = 1;
247: $resource_no_folder_link = 1;
248: } else {
249: my $link = 'navmaps?sort='.$env{'form.sort'}.'&showOnlyHomework=1';
250: if ($env{'form.register'}) {
251: $link .= '&register='.$env{'form.register'};
252: }
253: unless ($notools) {
254: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
255: 'location.href="'.$link.'"',
256: 'Show only uncompleted problems');
257: }
258: }
259:
260: my %selected=($env{'form.sort'} => ' selected="selected"');
261: my $sort_html;
262: unless ($notools) {
263: $sort_html=(
264: '<form name="sortForm" action="">
265: <span class="LC_nobreak">
266: <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
267: '.&mt('Sort by:').'
268: <select name="sort" onchange="document.sortForm.submit()">
269: <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
270: <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
271: <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Due Date').'</option>
272: <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
273: </select>
274: <input type="hidden" name="register" value="'.$env{'form.register'}.'" />
275: </span>
276: </form>');
277: }
278: # renderer call
279: my $renderArgs = { 'cols' => [0,1,2,3],
280: 'sort' => $env{'form.sort'},
281: 'url' => '/adm/navmaps',
282: 'navmap' => $navmap,
283: 'suppressNavmap' => 1,
284: 'suppressEmptySequences' => $suppressEmptySequences,
285: 'filterFunc' => $filterFunc,
286: 'resource_no_folder_link' => $resource_no_folder_link,
287: 'sort_html'=> $sort_html,
288: 'r' => $r,
289: 'caller' => 'navmapsdisplay',
290: 'linkitems' => \%toplinkitems,
291: 'notools' => $notools};
292:
293: my $render = &Apache::lonnavmaps::render($renderArgs);
294:
295: # If no resources were printed, print a reassuring message so the
296: # user knows there was no error.
297: if ($renderArgs->{'counter'} == 0) {
298: if ($showOnlyHomework) {
299: $r->print("<p><span class=\"LC_info\">".&mt("All homework is currently completed.")."</span></p>");
300: } else { # both jumpToFirstHomework and normal use the same: course must be empty
301: $r->print("<p><span class=\"LC_info\">".&mt("This course is empty.")."</span></p>");
302: }
303: }
304: &endContentScreen($r);
305: $r->print(&Apache::loncommon::end_page());
306: $r->rflush();
307:
308: return OK;
309: }
310:
311: sub startContentScreen {
312: my ($r,$mode)=@_;
313:
314: $r->print("\n".'<ul class="LC_TabContentBigger" id="mainnav">'."\n");
315: $r->print('<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Main Content').' </b></a></li>'."\n");
316: my $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
317: my ($suppcount,$errors);
318: unless ($allowed) {
319: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
320: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
321: ($suppcount,$errors) = &Apache::lonnet::get_numsuppfiles($cnum,$cdom);
322: }
323: if ($allowed || $suppcount) {
324: $r->print('<li '.(($mode eq 'supplemental')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>');
325: }
326: $r->print('<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n");
327: $r->print('<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n");
328: $r->print("\n".'</ul>'."\n");
329: $r->print('<div class="LC_Box" style="clear:both;margin:0;"><div id="maincoursedoc" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">');
330: }
331:
332: sub endContentScreen {
333: my ($r)=@_;
334: $r->print('</div></div></div>');
335: }
336:
337: 1;
338: __END__
339:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>