Annotation of loncom/interface/lonnavdisplay.pm, revision 1.22.4.10.2.6
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.10.2.6! (raeburn 4:: # $Id: lonnavdisplay.pm,v 1.22.4.10.2.5 2025/02/07 20:58:59 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.22.4.10.2.6! (raeburn 42:: use LONCAPA;
1.1 albertel 43:
44: sub handler {
45: my $r = shift;
46: real_handler($r);
47: }
48:
49: sub real_handler {
50: my $r = shift;
51: # Handle header-only request
52: if ($r->header_only) {
1.22.4.6 raeburn 53: &Apache::loncommon::content_type($r,'text/html');
1.1 albertel 54: $r->send_http_header;
55: return OK;
56: }
57:
1.22.4.5 raeburn 58: # Check for critical messages and redirect if present.
1.22.4.10.2.1 (raeburn 59:: my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'contents');
1.22.4.5 raeburn 60: if ($redirect) {
61: &Apache::loncommon::content_type($r,'text/html');
62: $r->header_out(Location => $url);
63: return REDIRECT;
64: }
65:
1.22.4.8 raeburn 66: # ------------------------------------------------------------ Get query string
67: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort',
68: 'showOnlyHomework',
1.22.4.10.2.2 (raeburn 69:: 'postsymb']);
1.22.4.6 raeburn 70: # Check if course needs to be re-initialized
71: my $loncaparev = $r->dir_config('lonVersion');
72: my ($result,@reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
1.22.4.8 raeburn 73: my %prog_state=();
74: my $closure;
1.22.4.6 raeburn 75:
76: if ($result eq 'switch') {
1.1 albertel 77: &Apache::loncommon::content_type($r,'text/html');
1.22.4.6 raeburn 78: $r->send_http_header;
79: $r->print(&Apache::loncommon::check_release_result(@reinit));
80: return OK;
1.22.4.10.2.3 (raeburn 81:: }
82:: my ($cid,$cnum,$cdom);
83:: if ($result) {
84:: $cid = $env{'request.course.id'};
85:: $cnum = $env{'course.'.$cid.'.num'};
86:: $cdom = $env{'course.'.$cid.'.domain'};
87:: }
88:: if (($result eq 'main') || ($result eq 'both')) {
1.22.4.8 raeburn 89: &Apache::loncommon::content_type($r,'text/html');
90: $r->send_http_header;
91: &startpage($r);
92: my $preamble = '<div id="LC_update_'.$cid.'" class="LC_info">'.
93: '<br />'.
94: &mt('Your course session is being updated because of recent changes by course personnel.').
1.22.4.10 raeburn 95: ' '.&mt('Please be patient').'.<br /></div>'.
1.22.4.8 raeburn 96: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
97: $closure = <<ENDCLOSE;
98: <script type="text/javascript">
99: // <![CDATA[
100: \$("#LC_update_$cid").hide('slow');
101: // ]]>
102: </script>
103: ENDCLOSE
104: %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
105: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Updating course'));
106: $r->rflush();
107: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum",\%prog_state,$r);
1.22.4.10 raeburn 108: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
1.22.4.6 raeburn 109: if ($ferr) {
1.22.4.8 raeburn 110: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
111: $r->print($closure.&Apache::loncommon::end_page());
1.22.4.6 raeburn 112: my $requrl = $r->uri;
113: $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
114: $env{'user.reinit'} = 1;
115: return HTTP_NOT_ACCEPTABLE;
116: }
1.1 albertel 117: }
1.22.4.10.2.3 (raeburn 118:: if (($result eq 'both') || ($result eq 'supp')) {
119:: my $possdel;
120:: if ($result eq 'supp') {
121:: $possdel = 1;
122:: }
123:: my ($supplemental,$refs_updated) = &Apache::loncommon::get_supplemental($cnum,$cdom,'',$possdel);
124:: unless ($refs_updated) {
125:: &Apache::loncommon::set_supp_httprefs($cnum,$cdom,$supplemental,$possdel);
126:: }
127:: }
1.1 albertel 128:
129: # Create the nav map
130: my $navmap = Apache::lonnavmaps::navmap->new();
131:
132: if (!defined($navmap)) {
1.22.4.10.2.5 (raeburn 133:: if (($result eq 'main') || ($result eq 'both')) {
1.22.4.8 raeburn 134: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
135: $r->print($closure.&Apache::loncommon::end_page());
136: }
1.1 albertel 137: my $requrl = $r->uri;
138: $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
1.5 raeburn 139: $env{'user.reinit'} = 1;
1.1 albertel 140: return HTTP_NOT_ACCEPTABLE;
141: }
1.22.4.6 raeburn 142:
1.22.4.10.2.5 (raeburn 143:: if (($result eq 'main') || ($result eq 'both')) {
1.22.4.8 raeburn 144: $r->rflush();
145: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
146: $r->print($closure);
147: $r->rflush();
1.17 raeburn 148: } else {
1.22.4.8 raeburn 149: # Send header, don't cache this page
150: &Apache::loncommon::content_type($r,'text/html');
151: $r->send_http_header;
152: &startpage($r);
1.17 raeburn 153: }
1.22.4.8 raeburn 154:
1.20 raeburn 155: &startContentScreen($r,'navmaps');
1.22.4.10.2.5 (raeburn 156:: unless (($result eq 'main') || ($result eq 'both')) {
1.22.4.8 raeburn 157: $r->rflush();
158: }
1.1 albertel 159:
160: # Check that it's defined
161: if (!($navmap->courseMapDefined())) {
162: $r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
163: $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
164: '</span>' .
165: &Apache::loncommon::end_page());
166: return OK;
167: }
168:
1.22.4.6 raeburn 169: my %toplinkitems=();
1.21 raeburn 170: my @resources = $navmap->retrieveResources();
171: my $sequenceCount = 0;
172: my $problemCount = 0;
173: my $notaprobCount = 0;
174: my $sequenceId;
175: my $notools;
176: foreach my $curRes (@resources) {
177: if (ref($curRes)) {
178: if ($curRes->is_sequence()) {
1.1 albertel 179: $sequenceCount++;
180: $sequenceId = $curRes->map_pc();
1.21 raeburn 181: } elsif ($curRes->is_problem()) {
182: $problemCount ++;
183: } else {
184: $notaprobCount ++;
1.1 albertel 185: }
186: }
1.21 raeburn 187: }
188: if (($sequenceCount == 1) && (!$problemCount) && ($notaprobCount <= 1)) {
189: $notools = 1;
190: }
191:
192: # If there's only one map in the top-level and we don't
193: # already have a filter, automatically display it
194: if ($ENV{QUERY_STRING} !~ /filter/) {
1.1 albertel 195: if ($sequenceCount == 1) {
196: # The automatic iterator creation in the render call
197: # will pick this up. We know the condition because
198: # the defined($env{'form.filter'}) also ensures this
199: # is a fresh call.
200: $env{'form.filter'} = "$sequenceId";
201: }
202: }
203:
204: # Check to see if the student is jumping to next open, do-able problem
205: if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
206: # Find the next homework problem that they can do.
207: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
208: my $curRes;
209: my $foundDoableProblem = 0;
210: my $minimumduedate;
1.2 albertel 211: my $now = time();
212:
1.1 albertel 213: while ($curRes = $iterator->next()) {
214: if (ref($curRes) && $curRes->is_problem()) {
215: my $status = $curRes->status();
1.2 albertel 216: my $thisduedate=$curRes->duedate();
217: if ($thisduedate > $now
218: && $curRes->completable()) {
1.1 albertel 219:
220: $foundDoableProblem = 1;
221:
1.2 albertel 222: if (!defined($minimumduedate)
223: || $thisduedate<$minimumduedate) {
1.1 albertel 224: # Pop open all previous maps
225: my $stack = $iterator->getStack();
226: pop @$stack; # last resource in the stack is the problem
227: # itself, which we don't need in the map stack
228: my @mapPcs = map {$_->map_pc()} @$stack;
229: $env{'form.filter'} = join(',', @mapPcs);
230:
231: # Mark as both "here" and "jump"
232: $env{'form.postsymb'} = $curRes->symb();
233: $minimumduedate=$thisduedate;
234: }
235: }
236: }
237: }
238:
239: # If we found no problems, print a note to that effect.
240: if (!$foundDoableProblem) {
1.7 schulted 241: $r->print("<span class=\"LC_info\">"
1.4 bisitz 242: .&mt("All homework assignments have been completed.")
1.7 schulted 243: ."</span>");
1.1 albertel 244: }
245: } else {
1.22.4.9 raeburn 246: my $link = '/adm/navmaps?jumpToFirstHomework';
1.21 raeburn 247: unless ($notools) {
248: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
249: 'location.href="'.$link.'"',
250: "Show my first due problem");
251: }
1.1 albertel 252: }
253:
254: my $suppressEmptySequences = 0;
255: my $filterFunc = undef;
256: my $resource_no_folder_link = 0;
257:
258: # Display only due homework.
259: my $showOnlyHomework = 0;
260: if ($env{'form.showOnlyHomework'} eq "1") {
261: $showOnlyHomework = 1;
262: $suppressEmptySequences = 1;
263: $filterFunc = sub { my $res = shift;
264: return $res->completable() || $res->is_map();
265: };
1.22.4.9 raeburn 266: my $link = '/adm/navmaps?sort='.$env{'form.sort'};
1.1 albertel 267: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
1.17 raeburn 268: 'location.href="'.$link.'"',
269: 'Show everything');
1.7 schulted 270: $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
1.1 albertel 271: $env{'form.filter'} = '';
272: $env{'form.condition'} = 1;
273: $resource_no_folder_link = 1;
274: } else {
1.22.4.9 raeburn 275: my $link = '/adm/navmaps?sort='.$env{'form.sort'}.'&showOnlyHomework=1';
1.21 raeburn 276: unless ($notools) {
277: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
278: 'location.href="'.$link.'"',
279: 'Show only uncompleted problems');
280: }
1.1 albertel 281: }
282:
1.10 bisitz 283: my %selected=($env{'form.sort'} => ' selected="selected"');
1.21 raeburn 284: my $sort_html;
285: unless ($notools) {
286: $sort_html=(
287: '<form name="sortForm" action="">
1.17 raeburn 288: <span class="LC_nobreak">
289: <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
290: '.&mt('Sort by:').'
1.18 bisitz 291: <select name="sort" onchange="document.sortForm.submit()">
1.17 raeburn 292: <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
293: <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
1.22.4.3 raeburn 294: <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Due Date').'</option>
1.17 raeburn 295: <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
1.1 albertel 296: </select>
1.9 bisitz 297: </span>
1.17 raeburn 298: </form>');
1.21 raeburn 299: }
1.1 albertel 300: # renderer call
301: my $renderArgs = { 'cols' => [0,1,2,3],
302: 'sort' => $env{'form.sort'},
303: 'url' => '/adm/navmaps',
304: 'navmap' => $navmap,
305: 'suppressNavmap' => 1,
306: 'suppressEmptySequences' => $suppressEmptySequences,
307: 'filterFunc' => $filterFunc,
308: 'resource_no_folder_link' => $resource_no_folder_link,
309: 'sort_html'=> $sort_html,
310: 'r' => $r,
311: 'caller' => 'navmapsdisplay',
1.21 raeburn 312: 'linkitems' => \%toplinkitems,
313: 'notools' => $notools};
314:
1.1 albertel 315: my $render = &Apache::lonnavmaps::render($renderArgs);
316:
317: # If no resources were printed, print a reassuring message so the
318: # user knows there was no error.
319: if ($renderArgs->{'counter'} == 0) {
1.22.4.10.2.6! (raeburn 320:: my $noresmsg;
1.1 albertel 321: if ($showOnlyHomework) {
1.22.4.10.2.6! (raeburn 322:: $noresmsg = &mt('All homework is currently completed.');
1.1 albertel 323: } else { # both jumpToFirstHomework and normal use the same: course must be empty
1.22.4.10.2.6! (raeburn 324:: $noresmsg = &mt('This course is empty.');
! 325:: if (($renderArgs->{'deeplinknolist'}) &&
! 326:: ($env{'request.course.deeponlyprot'})) {
! 327:: my ($linkprot,$currmatch,$othermatches,@names);
! 328:: if ($env{'request.linkprot'}) {
! 329:: ($linkprot) = split(/:/,$env{'request.linkprot'});
! 330:: }
! 331:: foreach my $launcher (split(/&/,$env{'request.course.deeponlyprot'})) {
! 332:: my ($name,$itemnums) = split(/:/,$launcher);
! 333:: my @nums = split(/,/,$itemnums);
! 334:: if (($linkprot) &&
! 335:: (grep(/^\Q$linkprot\E$/,@nums))) {
! 336:: $currmatch = &LONCAPA::unescape($name);
! 337:: if (@nums > 1) {
! 338:: $othermatches = 1;
! 339:: }
! 340:: } else {
! 341:: push(@names,&LONCAPA::unescape($name));
! 342:: }
! 343:: }
! 344:: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
! 345:: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 346:: my $has_supp = &Apache::lonnet::has_unhidden_suppfiles($cnum,$cdom);
! 347:: if ($linkprot) {
! 348:: if ($currmatch) {
! 349:: if ($has_supp) {
! 350:: $noresmsg = &mt('No main content available when accessed using the link you followed from [_1].',
! 351:: $currmatch);
! 352:: } else {
! 353:: $noresmsg = &mt('No content available when accessed using the link you followed from [_1].',
! 354:: $currmatch);
! 355:: }
! 356:: if ($othermatches) {
! 357:: $noresmsg = '<br />';
! 358:: if ($has_supp) {
! 359:: $noresmsg .= &mt('Main content may be available by following a different link from [_1].',
! 360:: $currmatch);
! 361:: } else {
! 362:: $noresmsg .= &mt('Content may be available by following a different link from [_1].',
! 363:: $currmatch);
! 364:: }
! 365:: }
! 366:: } else {
! 367:: if ($has_supp) {
! 368:: $noresmsg = &mt('No main content available using the link you followed.');
! 369:: } else {
! 370:: $noresmsg = &mt('No content available using the link you followed.');
! 371:: }
! 372:: }
! 373:: } elsif (@names > 0) {
! 374:: if ($has_supp) {
! 375:: $noresmsg = &mt('No main content available from direct login to this course.');
! 376:: } else {
! 377:: $noresmsg = &mt('No content available from direct login to this course.');
! 378:: }
! 379:: }
! 380:: if (@names == 1) {
! 381:: $noresmsg .= '<br />';
! 382:: if ($has_supp) {
! 383:: $noresmsg .= &mt('Main content is likely available by following links from [_1]',
! 384:: $names[0]);
! 385:: } else {
! 386:: $noresmsg .= &mt('Content is likely available by following links from [_1]',
! 387:: $names[0]);
! 388:: }
! 389:: } elsif (@names > 1) {
! 390:: $noresmsg .= '<br />';
! 391:: if ($has_supp) {
! 392:: $noresmsg .= &mt('Main content is likely available by following links from the following: [_1]',
! 393:: join(', ',@names));
! 394:: } else {
! 395:: $noresmsg .= &mt('Content is likely available by following links from the following: [_1]',
! 396:: join(', ',@names));
! 397:: }
! 398:: }
! 399:: }
1.1 albertel 400: }
1.22.4.10.2.6! (raeburn 401:: $r->print('<p><span class="LC_info">'.$noresmsg.'</span></p>');
1.1 albertel 402: }
1.20 raeburn 403: &endContentScreen($r);
1.1 albertel 404: $r->print(&Apache::loncommon::end_page());
405: $r->rflush();
406:
407: return OK;
408: }
409:
1.22.4.8 raeburn 410: sub startpage {
411: my ($r) = @_;
412: # ----------------------------------------------------- Force menu registration
413: # Header
414: my $course_type = &Apache::loncommon::course_type();
415: my $title = $course_type . ' Contents';
1.22.4.10.2.2 (raeburn 416:: my $brcrum = [{href => '/adm/navmaps',
417:: text => &mt($course_type . ' Contents'),
418:: no_mt => 1},
419:: ];
420:: my $args = {'bread_crumbs' => $brcrum};
1.22.4.10.2.4 (raeburn 421:: $r->print(&Apache::loncommon::start_page($title,undef,$args).
1.22.4.8 raeburn 422: '<script type="text/javascript">'."\n".
423: '// <![CDATA['."\n".
424: 'window.focus();'."\n".
425: '// ]]>'."\n".
426: '</script>');
427: return;
428: }
429:
1.20 raeburn 430: sub startContentScreen {
431: my ($r,$mode)=@_;
432:
433: $r->print("\n".'<ul class="LC_TabContentBigger" id="mainnav">'."\n");
1.22 www 434: $r->print('<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Main Content').' </b></a></li>'."\n");
1.22.4.10.2.3 (raeburn 435:: my $supptab;
436:: if ($env{'request.role.adv'}) {
437:: $supptab = 1;
438:: } else {
1.22.4.2 raeburn 439: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
440: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.22.4.10.2.3 (raeburn 441:: $supptab = &Apache::lonnet::has_unhidden_suppfiles($cnum,$cdom);
1.22.4.2 raeburn 442: }
1.22.4.10.2.3 (raeburn 443:: if ($supptab) {
1.22.4.2 raeburn 444: $r->print('<li '.(($mode eq 'supplemental')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>');
445: }
1.20 raeburn 446: $r->print('<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n");
447: $r->print("\n".'</ul>'."\n");
448: $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;">');
449: }
450:
451: sub endContentScreen {
452: my ($r)=@_;
453: $r->print('</div></div></div>');
454: }
455:
1.1 albertel 456: 1;
457: __END__
458:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>