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