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