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