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