Annotation of loncom/interface/lonnavdisplay.pm, revision 1.40
1.1 albertel 1: # The LearningOnline Network with CAPA
1.28 raeburn 2: # Navigate Maps Display Handler
1.1 albertel 3: #
1.40 ! raeburn 4: # $Id: lonnavdisplay.pm,v 1.39 2022/06/11 04:32:23 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.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.30 raeburn 53: &Apache::loncommon::content_type($r,'text/html');
1.1 albertel 54: $r->send_http_header;
55: return OK;
56: }
57:
1.27 musolffc 58: # Check for critical messages and redirect if present.
1.34 raeburn 59: my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'contents');
1.27 musolffc 60: if ($redirect) {
61: &Apache::loncommon::content_type($r,'text/html');
62: $r->header_out(Location => $url);
63: return REDIRECT;
64: }
65:
1.35 raeburn 66: # ------------------------------------------------------------ Get query string
67: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort',
68: 'showOnlyHomework',
1.39 raeburn 69: 'postsymb']);
1.31 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.35 raeburn 73: my %prog_state=();
74: my $closure;
1.31 raeburn 75:
76: if ($result eq 'switch') {
77: &Apache::loncommon::content_type($r,'text/html');
78: $r->send_http_header;
79: $r->print(&Apache::loncommon::check_release_result(@reinit));
80: return OK;
1.40 ! 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.35 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.38 raeburn 95: ' '.&mt('Please be patient').'.<br /></div>'.
1.35 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.38 raeburn 108: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
1.31 raeburn 109: if ($ferr) {
1.35 raeburn 110: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
111: $r->print($closure.&Apache::loncommon::end_page());
1.31 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: }
117: }
1.40 ! 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::lonnet::get_supplemental($cnum,$cdom,'',$possdel);
! 124: unless ($refs_updated) {
! 125: &Apache::loncommon::set_supp_httprefs($cnum,$cdom,$supplemental,$possdel);
! 126: }
! 127: }
1.31 raeburn 128:
1.33 raeburn 129: my $course_type = &Apache::loncommon::course_type();
130: if (($course_type eq 'Placement') && (!$env{'request.role.adv'})) {
131: my $furl = &Apache::lonpageflip::first_accessible_resource();
1.35 raeburn 132: if ($result eq 'update') {
133: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
134: $r->print($closure.&Apache::loncommon::end_page());
135: return OK;
136: } else {
137: &Apache::loncommon::content_type($r,'text/html');
138: $r->header_out(Location => $furl);
139: return REDIRECT;
140: }
1.33 raeburn 141: }
142:
1.36 raeburn 143: if ($env{'request.lti.login'}) {
144: if ($env{'request.lti.uri'} ne '') {
145: my $cid = $env{'request.course.id'};
146: my $cnum = $env{'course.'.$cid.'.num'};
147: my $cdom = $env{'course.'.$cid.'.domain'};
148: my ($scope,$url) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},$cdom,$cnum);
149: if (($scope eq 'map') || ($scope eq 'resource')) {
150: &Apache::loncommon::content_type($r,'text/html');
151: $r->header_out(Location => $url);
152: return REDIRECT;
153: }
154: }
155: }
156:
1.1 albertel 157: # Create the nav map
158: my $navmap = Apache::lonnavmaps::navmap->new();
159:
160: if (!defined($navmap)) {
1.35 raeburn 161: if ($result eq 'update') {
162: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
163: $r->print($closure.&Apache::loncommon::end_page());
164: }
1.1 albertel 165: my $requrl = $r->uri;
166: $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
1.5 raeburn 167: $env{'user.reinit'} = 1;
1.1 albertel 168: return HTTP_NOT_ACCEPTABLE;
169: }
1.30 raeburn 170:
1.35 raeburn 171: if ($result eq 'update') {
172: $r->rflush();
173: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
174: $r->print($closure);
175: $r->rflush();
1.17 raeburn 176: } else {
1.35 raeburn 177: # Send header, don't cache this page
178: &Apache::loncommon::content_type($r,'text/html');
179: $r->send_http_header;
180: &startpage($r);
1.17 raeburn 181: }
1.35 raeburn 182:
1.20 raeburn 183: &startContentScreen($r,'navmaps');
1.35 raeburn 184: unless ($result eq 'update') {
185: $r->rflush();
186: }
1.1 albertel 187:
188: # Check that it's defined
189: if (!($navmap->courseMapDefined())) {
190: $r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
191: $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
192: '</span>' .
193: &Apache::loncommon::end_page());
194: return OK;
195: }
196:
1.30 raeburn 197: my %toplinkitems=();
1.21 raeburn 198: my @resources = $navmap->retrieveResources();
199: my $sequenceCount = 0;
200: my $problemCount = 0;
201: my $notaprobCount = 0;
202: my $sequenceId;
203: my $notools;
204: foreach my $curRes (@resources) {
205: if (ref($curRes)) {
206: if ($curRes->is_sequence()) {
1.1 albertel 207: $sequenceCount++;
208: $sequenceId = $curRes->map_pc();
1.21 raeburn 209: } elsif ($curRes->is_problem()) {
210: $problemCount ++;
211: } else {
212: $notaprobCount ++;
1.1 albertel 213: }
214: }
1.21 raeburn 215: }
216: if (($sequenceCount == 1) && (!$problemCount) && ($notaprobCount <= 1)) {
217: $notools = 1;
218: }
219:
220: # If there's only one map in the top-level and we don't
221: # already have a filter, automatically display it
222: if ($ENV{QUERY_STRING} !~ /filter/) {
1.1 albertel 223: if ($sequenceCount == 1) {
224: # The automatic iterator creation in the render call
225: # will pick this up. We know the condition because
226: # the defined($env{'form.filter'}) also ensures this
227: # is a fresh call.
228: $env{'form.filter'} = "$sequenceId";
229: }
230: }
231:
232: # Check to see if the student is jumping to next open, do-able problem
233: if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
234: # Find the next homework problem that they can do.
235: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
236: my $curRes;
237: my $foundDoableProblem = 0;
238: my $minimumduedate;
1.2 albertel 239: my $now = time();
240:
1.1 albertel 241: while ($curRes = $iterator->next()) {
242: if (ref($curRes) && $curRes->is_problem()) {
243: my $status = $curRes->status();
1.2 albertel 244: my $thisduedate=$curRes->duedate();
245: if ($thisduedate > $now
246: && $curRes->completable()) {
1.1 albertel 247:
248: $foundDoableProblem = 1;
249:
1.2 albertel 250: if (!defined($minimumduedate)
251: || $thisduedate<$minimumduedate) {
1.1 albertel 252: # Pop open all previous maps
253: my $stack = $iterator->getStack();
254: pop @$stack; # last resource in the stack is the problem
255: # itself, which we don't need in the map stack
256: my @mapPcs = map {$_->map_pc()} @$stack;
257: $env{'form.filter'} = join(',', @mapPcs);
258:
259: # Mark as both "here" and "jump"
260: $env{'form.postsymb'} = $curRes->symb();
261: $minimumduedate=$thisduedate;
262: }
263: }
264: }
265: }
266:
267: # If we found no problems, print a note to that effect.
268: if (!$foundDoableProblem) {
1.7 schulted 269: $r->print("<span class=\"LC_info\">"
1.4 bisitz 270: .&mt("All homework assignments have been completed.")
1.7 schulted 271: ."</span>");
1.1 albertel 272: }
273: } else {
1.37 raeburn 274: my $link = '/adm/navmaps?jumpToFirstHomework';
1.21 raeburn 275: unless ($notools) {
276: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
277: 'location.href="'.$link.'"',
278: "Show my first due problem");
279: }
1.1 albertel 280: }
281:
282: my $suppressEmptySequences = 0;
283: my $filterFunc = undef;
284: my $resource_no_folder_link = 0;
285:
286: # Display only due homework.
287: my $showOnlyHomework = 0;
288: if ($env{'form.showOnlyHomework'} eq "1") {
289: $showOnlyHomework = 1;
290: $suppressEmptySequences = 1;
291: $filterFunc = sub { my $res = shift;
292: return $res->completable() || $res->is_map();
293: };
1.37 raeburn 294: my $link = '/adm/navmaps?sort='.$env{'form.sort'};
1.1 albertel 295: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
1.17 raeburn 296: 'location.href="'.$link.'"',
297: 'Show everything');
1.7 schulted 298: $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
1.1 albertel 299: $env{'form.filter'} = '';
300: $env{'form.condition'} = 1;
301: $resource_no_folder_link = 1;
302: } else {
1.37 raeburn 303: my $link = '/adm/navmaps?sort='.$env{'form.sort'}.'&showOnlyHomework=1';
1.21 raeburn 304: unless ($notools) {
305: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
306: 'location.href="'.$link.'"',
307: 'Show only uncompleted problems');
308: }
1.1 albertel 309: }
310:
1.10 bisitz 311: my %selected=($env{'form.sort'} => ' selected="selected"');
1.21 raeburn 312: my $sort_html;
313: unless ($notools) {
314: $sort_html=(
315: '<form name="sortForm" action="">
1.17 raeburn 316: <span class="LC_nobreak">
317: <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
318: '.&mt('Sort by:').'
1.18 bisitz 319: <select name="sort" onchange="document.sortForm.submit()">
1.17 raeburn 320: <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
321: <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
1.25 bisitz 322: <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Due Date').'</option>
1.17 raeburn 323: <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
1.1 albertel 324: </select>
1.9 bisitz 325: </span>
1.17 raeburn 326: </form>');
1.21 raeburn 327: }
1.1 albertel 328: # renderer call
329: my $renderArgs = { 'cols' => [0,1,2,3],
330: 'sort' => $env{'form.sort'},
331: 'url' => '/adm/navmaps',
332: 'navmap' => $navmap,
333: 'suppressNavmap' => 1,
334: 'suppressEmptySequences' => $suppressEmptySequences,
335: 'filterFunc' => $filterFunc,
336: 'resource_no_folder_link' => $resource_no_folder_link,
337: 'sort_html'=> $sort_html,
338: 'r' => $r,
339: 'caller' => 'navmapsdisplay',
1.21 raeburn 340: 'linkitems' => \%toplinkitems,
341: 'notools' => $notools};
342:
1.1 albertel 343: my $render = &Apache::lonnavmaps::render($renderArgs);
344:
345: # If no resources were printed, print a reassuring message so the
346: # user knows there was no error.
347: if ($renderArgs->{'counter'} == 0) {
348: if ($showOnlyHomework) {
1.7 schulted 349: $r->print("<p><span class=\"LC_info\">".&mt("All homework is currently completed.")."</span></p>");
1.1 albertel 350: } else { # both jumpToFirstHomework and normal use the same: course must be empty
1.7 schulted 351: $r->print("<p><span class=\"LC_info\">".&mt("This course is empty.")."</span></p>");
1.1 albertel 352: }
353: }
1.20 raeburn 354: &endContentScreen($r);
1.1 albertel 355: $r->print(&Apache::loncommon::end_page());
356: $r->rflush();
357:
358: return OK;
359: }
360:
1.35 raeburn 361: sub startpage {
362: my ($r) = @_;
363: # ----------------------------------------------------- Force menu registration
364: # Header
365: my $course_type = &Apache::loncommon::course_type();
366: my $title = $course_type . ' Contents';
1.39 raeburn 367: my $brcrum = [{href => '/adm/navmaps',
368: text => &mt($course_type . ' Contents'),
369: no_mt => 1},
370: ];
371: my $args = {'bread_crumbs' => $brcrum};
372: my $start_page = &Apache::loncommon::start_page($title,undef,$args);
1.35 raeburn 373: $r->print($start_page.
374: '<script type="text/javascript">'."\n".
375: '// <![CDATA['."\n".
376: 'window.focus();'."\n".
377: '// ]]>'."\n".
378: '</script>');
379: return;
380: }
381:
1.20 raeburn 382: sub startContentScreen {
383: my ($r,$mode)=@_;
384:
385: $r->print("\n".'<ul class="LC_TabContentBigger" id="mainnav">'."\n");
1.22 www 386: $r->print('<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Main Content').' </b></a></li>'."\n");
1.40 ! raeburn 387: my $supptab;
! 388: if ($env{'request.role.adv'}) {
! 389: $supptab = 1;
! 390: } else {
1.23 raeburn 391: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.24 raeburn 392: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.40 ! raeburn 393: $supptab = &Apache::lonnet::has_unhidden_suppfiles($cnum,$cdom);
1.23 raeburn 394: }
1.40 ! raeburn 395: if ($supptab) {
1.23 raeburn 396: $r->print('<li '.(($mode eq 'supplemental')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>');
397: }
1.20 raeburn 398: $r->print('<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n");
399: $r->print('<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n");
400: $r->print("\n".'</ul>'."\n");
401: $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;">');
402: }
403:
404: sub endContentScreen {
405: my ($r)=@_;
406: $r->print('</div></div></div>');
407: }
408:
1.1 albertel 409: 1;
410: __END__
411:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>