1: # The LearningOnline Network with CAPA
2: # Navigate Maps Display Handler
3: #
4: # $Id: lonnavdisplay.pm,v 1.39 2022/06/11 04:32:23 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: use LONCAPA::ltiutils;
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) {
53: &Apache::loncommon::content_type($r,'text/html');
54: $r->send_http_header;
55: return OK;
56: }
57:
58: # Check for critical messages and redirect if present.
59: my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'contents');
60: if ($redirect) {
61: &Apache::loncommon::content_type($r,'text/html');
62: $r->header_out(Location => $url);
63: return REDIRECT;
64: }
65:
66: # ------------------------------------------------------------ Get query string
67: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort',
68: 'showOnlyHomework',
69: 'postsymb']);
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);
73: my %prog_state=();
74: my $closure;
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') {
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.').
91: ' '.&mt('Please be patient').'.<br /></div>'.
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);
104: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
105: if ($ferr) {
106: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
107: $r->print($closure.&Apache::loncommon::end_page());
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:
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();
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: }
127: }
128:
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:
143: # Create the nav map
144: my $navmap = Apache::lonnavmaps::navmap->new();
145:
146: if (!defined($navmap)) {
147: if ($result eq 'update') {
148: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
149: $r->print($closure.&Apache::loncommon::end_page());
150: }
151: my $requrl = $r->uri;
152: $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
153: $env{'user.reinit'} = 1;
154: return HTTP_NOT_ACCEPTABLE;
155: }
156:
157: if ($result eq 'update') {
158: $r->rflush();
159: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
160: $r->print($closure);
161: $r->rflush();
162: } else {
163: # Send header, don't cache this page
164: &Apache::loncommon::content_type($r,'text/html');
165: $r->send_http_header;
166: &startpage($r);
167: }
168:
169: &startContentScreen($r,'navmaps');
170: unless ($result eq 'update') {
171: $r->rflush();
172: }
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:
183: my %toplinkitems=();
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()) {
193: $sequenceCount++;
194: $sequenceId = $curRes->map_pc();
195: } elsif ($curRes->is_problem()) {
196: $problemCount ++;
197: } else {
198: $notaprobCount ++;
199: }
200: }
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/) {
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;
225: my $now = time();
226:
227: while ($curRes = $iterator->next()) {
228: if (ref($curRes) && $curRes->is_problem()) {
229: my $status = $curRes->status();
230: my $thisduedate=$curRes->duedate();
231: if ($thisduedate > $now
232: && $curRes->completable()) {
233:
234: $foundDoableProblem = 1;
235:
236: if (!defined($minimumduedate)
237: || $thisduedate<$minimumduedate) {
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) {
255: $r->print("<span class=\"LC_info\">"
256: .&mt("All homework assignments have been completed.")
257: ."</span>");
258: }
259: } else {
260: my $link = '/adm/navmaps?jumpToFirstHomework';
261: unless ($notools) {
262: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
263: 'location.href="'.$link.'"',
264: "Show my first due problem");
265: }
266: }
267:
268: my $suppressEmptySequences = 0;
269: my $filterFunc = undef;
270: my $resource_no_folder_link = 0;
271:
272: # Display only due homework.
273: my $showOnlyHomework = 0;
274: if ($env{'form.showOnlyHomework'} eq "1") {
275: $showOnlyHomework = 1;
276: $suppressEmptySequences = 1;
277: $filterFunc = sub { my $res = shift;
278: return $res->completable() || $res->is_map();
279: };
280: my $link = '/adm/navmaps?sort='.$env{'form.sort'};
281: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
282: 'location.href="'.$link.'"',
283: 'Show everything');
284: $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
285: $env{'form.filter'} = '';
286: $env{'form.condition'} = 1;
287: $resource_no_folder_link = 1;
288: } else {
289: my $link = '/adm/navmaps?sort='.$env{'form.sort'}.'&showOnlyHomework=1';
290: unless ($notools) {
291: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
292: 'location.href="'.$link.'"',
293: 'Show only uncompleted problems');
294: }
295: }
296:
297: my %selected=($env{'form.sort'} => ' selected="selected"');
298: my $sort_html;
299: unless ($notools) {
300: $sort_html=(
301: '<form name="sortForm" action="">
302: <span class="LC_nobreak">
303: <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
304: '.&mt('Sort by:').'
305: <select name="sort" onchange="document.sortForm.submit()">
306: <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
307: <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
308: <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Due Date').'</option>
309: <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
310: </select>
311: </span>
312: </form>');
313: }
314: # renderer call
315: my $renderArgs = { 'cols' => [0,1,2,3],
316: 'sort' => $env{'form.sort'},
317: 'url' => '/adm/navmaps',
318: 'navmap' => $navmap,
319: 'suppressNavmap' => 1,
320: 'suppressEmptySequences' => $suppressEmptySequences,
321: 'filterFunc' => $filterFunc,
322: 'resource_no_folder_link' => $resource_no_folder_link,
323: 'sort_html'=> $sort_html,
324: 'r' => $r,
325: 'caller' => 'navmapsdisplay',
326: 'linkitems' => \%toplinkitems,
327: 'notools' => $notools};
328:
329: my $render = &Apache::lonnavmaps::render($renderArgs);
330:
331: # If no resources were printed, print a reassuring message so the
332: # user knows there was no error.
333: if ($renderArgs->{'counter'} == 0) {
334: if ($showOnlyHomework) {
335: $r->print("<p><span class=\"LC_info\">".&mt("All homework is currently completed.")."</span></p>");
336: } else { # both jumpToFirstHomework and normal use the same: course must be empty
337: $r->print("<p><span class=\"LC_info\">".&mt("This course is empty.")."</span></p>");
338: }
339: }
340: &endContentScreen($r);
341: $r->print(&Apache::loncommon::end_page());
342: $r->rflush();
343:
344: return OK;
345: }
346:
347: sub startpage {
348: my ($r) = @_;
349: # ----------------------------------------------------- Force menu registration
350: # Header
351: my $course_type = &Apache::loncommon::course_type();
352: my $title = $course_type . ' Contents';
353: my $brcrum = [{href => '/adm/navmaps',
354: text => &mt($course_type . ' Contents'),
355: no_mt => 1},
356: ];
357: my $args = {'bread_crumbs' => $brcrum};
358: my $start_page = &Apache::loncommon::start_page($title,undef,$args);
359: $r->print($start_page.
360: '<script type="text/javascript">'."\n".
361: '// <![CDATA['."\n".
362: 'window.focus();'."\n".
363: '// ]]>'."\n".
364: '</script>');
365: return;
366: }
367:
368: sub startContentScreen {
369: my ($r,$mode)=@_;
370:
371: $r->print("\n".'<ul class="LC_TabContentBigger" id="mainnav">'."\n");
372: $r->print('<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Main Content').' </b></a></li>'."\n");
373: my $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
374: my ($suppcount,$errors);
375: unless ($allowed) {
376: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
377: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
378: ($suppcount,$errors) = &Apache::lonnet::get_numsuppfiles($cnum,$cdom);
379: }
380: if ($allowed || $suppcount) {
381: $r->print('<li '.(($mode eq 'supplemental')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>');
382: }
383: $r->print('<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n");
384: $r->print('<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n");
385: $r->print("\n".'</ul>'."\n");
386: $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;">');
387: }
388:
389: sub endContentScreen {
390: my ($r)=@_;
391: $r->print('</div></div></div>');
392: }
393:
394: 1;
395: __END__
396:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>