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