Annotation of loncom/interface/lonnavdisplay.pm, revision 1.26
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # Navigate Maps Handler
3: #
1.26 ! raeburn 4: # $Id: lonnavdisplay.pm,v 1.25 2014/02/28 19:20:06 bisitz 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;
33: use Apache::Constants qw(:common :http);
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.26 ! raeburn 41: #use Time::HiRes qw( gettimeofday tv_interval );
1.1 albertel 42:
43: sub handler {
44: my $r = shift;
45: real_handler($r);
46: }
47:
48: sub real_handler {
49: my $r = shift;
50: #my $t0=[&gettimeofday()];
51: # Handle header-only request
52: if ($r->header_only) {
53: if ($env{'browser.mathml'}) {
54: &Apache::loncommon::content_type($r,'text/xml');
55: } else {
56: &Apache::loncommon::content_type($r,'text/html');
57: }
58: $r->send_http_header;
59: return OK;
60: }
61:
62: # Send header, don't cache this page
63: if ($env{'browser.mathml'}) {
64: &Apache::loncommon::content_type($r,'text/xml');
65: } else {
66: &Apache::loncommon::content_type($r,'text/html');
67: }
68: &Apache::loncommon::no_cache($r);
69:
70: my %toplinkitems=();
71:
72: # Create the nav map
73: my $navmap = Apache::lonnavmaps::navmap->new();
74:
75: if (!defined($navmap)) {
76: my $requrl = $r->uri;
77: $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
1.5 raeburn 78: $env{'user.reinit'} = 1;
1.1 albertel 79: return HTTP_NOT_ACCEPTABLE;
80: }
81: $r->send_http_header;
82:
83: # ------------------------------------------------------------ Get query string
1.17 raeburn 84: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sort','showOnlyHomework','postsymb','register']);
1.1 albertel 85:
86: # ----------------------------------------------------- Force menu registration
87: # Header
88: my $course_type = &Apache::loncommon::course_type();
1.15 droeschl 89: my $title = $course_type . ' Contents';
1.17 raeburn 90: my ($start_page,$args);
91: if ($env{'form.register'}) {
92: $args = {'force_register' => $env{'form.register'}};
93: $start_page = &Apache::loncommon::start_page($title,undef,$args);
94: } else {
95: my $brcrum = [{href => '/adm/navmaps',
96: text => &mt($course_type . ' Contents'),
97: no_mt => 1},
98: ];
99: $args = {'bread_crumbs' => $brcrum};
100: $start_page = &Apache::loncommon::start_page($title,undef,$args);
101: }
102: $r->print($start_page.
1.26 ! raeburn 103: '<script type="text/javascript">'."\n".
! 104: '// <![CDATA['."\n".
! 105: 'window.focus();'."\n".
! 106: '// ]]>'."\n".
! 107: '</script>');
1.20 raeburn 108: &startContentScreen($r,'navmaps');
1.1 albertel 109: $r->rflush();
110:
111: # Check that it's defined
112: if (!($navmap->courseMapDefined())) {
113: $r->print(&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT'));
114: $r->print('<span class="LC_error">'.&mt('Coursemap undefined.').
115: '</span>' .
116: &Apache::loncommon::end_page());
117: return OK;
118: }
119:
1.21 raeburn 120: my @resources = $navmap->retrieveResources();
121: my $sequenceCount = 0;
122: my $problemCount = 0;
123: my $notaprobCount = 0;
124: my $sequenceId;
125: my $notools;
126: foreach my $curRes (@resources) {
127: if (ref($curRes)) {
128: if ($curRes->is_sequence()) {
1.1 albertel 129: $sequenceCount++;
130: $sequenceId = $curRes->map_pc();
1.21 raeburn 131: } elsif ($curRes->is_problem()) {
132: $problemCount ++;
133: } else {
134: $notaprobCount ++;
1.1 albertel 135: }
136: }
1.21 raeburn 137: }
138: if (($sequenceCount == 1) && (!$problemCount) && ($notaprobCount <= 1)) {
139: $notools = 1;
140: }
141:
142: # If there's only one map in the top-level and we don't
143: # already have a filter, automatically display it
144: if ($ENV{QUERY_STRING} !~ /filter/) {
1.1 albertel 145: if ($sequenceCount == 1) {
146: # The automatic iterator creation in the render call
147: # will pick this up. We know the condition because
148: # the defined($env{'form.filter'}) also ensures this
149: # is a fresh call.
150: $env{'form.filter'} = "$sequenceId";
151: }
152: }
153:
154: # Check to see if the student is jumping to next open, do-able problem
155: if ($ENV{QUERY_STRING} =~ /^jumpToFirstHomework/) {
156: # Find the next homework problem that they can do.
157: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
158: my $curRes;
159: my $foundDoableProblem = 0;
160: my $minimumduedate;
1.2 albertel 161: my $now = time();
162:
1.1 albertel 163: while ($curRes = $iterator->next()) {
164: if (ref($curRes) && $curRes->is_problem()) {
165: my $status = $curRes->status();
1.2 albertel 166: my $thisduedate=$curRes->duedate();
167: if ($thisduedate > $now
168: && $curRes->completable()) {
1.1 albertel 169:
170: $foundDoableProblem = 1;
171:
1.2 albertel 172: if (!defined($minimumduedate)
173: || $thisduedate<$minimumduedate) {
1.1 albertel 174: # Pop open all previous maps
175: my $stack = $iterator->getStack();
176: pop @$stack; # last resource in the stack is the problem
177: # itself, which we don't need in the map stack
178: my @mapPcs = map {$_->map_pc()} @$stack;
179: $env{'form.filter'} = join(',', @mapPcs);
180:
181: # Mark as both "here" and "jump"
182: $env{'form.postsymb'} = $curRes->symb();
183: $minimumduedate=$thisduedate;
184: }
185: }
186: }
187: }
188:
189: # If we found no problems, print a note to that effect.
190: if (!$foundDoableProblem) {
1.7 schulted 191: $r->print("<span class=\"LC_info\">"
1.4 bisitz 192: .&mt("All homework assignments have been completed.")
1.7 schulted 193: ."</span>");
1.1 albertel 194: }
195: } else {
1.17 raeburn 196: my $link = 'navmaps?jumpToFirstHomework';
197: if ($env{'form.register'}) {
198: $link .= '&register='.$env{'form.register'};
199: }
1.21 raeburn 200: unless ($notools) {
201: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'firsthomework',
202: 'location.href="'.$link.'"',
203: "Show my first due problem");
204: }
1.1 albertel 205: }
206:
207: my $suppressEmptySequences = 0;
208: my $filterFunc = undef;
209: my $resource_no_folder_link = 0;
210:
211: # Display only due homework.
212: my $showOnlyHomework = 0;
213: if ($env{'form.showOnlyHomework'} eq "1") {
214: $showOnlyHomework = 1;
215: $suppressEmptySequences = 1;
216: $filterFunc = sub { my $res = shift;
217: return $res->completable() || $res->is_map();
218: };
1.17 raeburn 219: my $link = 'navmaps?sort='.$env{'form.sort'};
220: if ($env{'form.register'}) {
221: $link .= '&register='.$env{'form.register'};
222: }
1.1 albertel 223: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'everything',
1.17 raeburn 224: 'location.href="'.$link.'"',
225: 'Show everything');
1.7 schulted 226: $r->print("<span class=\"LC_info\">".&mt("Uncompleted Problems")."</span>");
1.1 albertel 227: $env{'form.filter'} = '';
228: $env{'form.condition'} = 1;
229: $resource_no_folder_link = 1;
230: } else {
1.17 raeburn 231: my $link = 'navmaps?sort='.$env{'form.sort'}.'&showOnlyHomework=1';
232: if ($env{'form.register'}) {
233: $link .= '&register='.$env{'form.register'};
234: }
1.21 raeburn 235: unless ($notools) {
236: &Apache::lonnavmaps::add_linkitem(\%toplinkitems,'uncompleted',
237: 'location.href="'.$link.'"',
238: 'Show only uncompleted problems');
239: }
1.1 albertel 240: }
241:
1.10 bisitz 242: my %selected=($env{'form.sort'} => ' selected="selected"');
1.21 raeburn 243: my $sort_html;
244: unless ($notools) {
245: $sort_html=(
246: '<form name="sortForm" action="">
1.17 raeburn 247: <span class="LC_nobreak">
248: <input type="hidden" name="showOnlyHomework" value="'.$env{'form.showOnlyHomework'}.'" />
249: '.&mt('Sort by:').'
1.18 bisitz 250: <select name="sort" onchange="document.sortForm.submit()">
1.17 raeburn 251: <option value="default"'.$selected{'default'}.'>'.&mt('Default').'</option>
252: <option value="title"'.$selected{'title'}.'>'.&mt('Title').'</option>
1.25 bisitz 253: <option value="duedate"'.$selected{'duedate'}.'>'.&mt('Due Date').'</option>
1.17 raeburn 254: <option value="discussion"'.$selected{'discussion'}.'>'.&mt('Has New Discussion').'</option>
1.1 albertel 255: </select>
1.17 raeburn 256: <input type="hidden" name="register" value="'.$env{'form.register'}.'" />
1.9 bisitz 257: </span>
1.17 raeburn 258: </form>');
1.21 raeburn 259: }
1.1 albertel 260: # renderer call
261: my $renderArgs = { 'cols' => [0,1,2,3],
262: 'sort' => $env{'form.sort'},
263: 'url' => '/adm/navmaps',
264: 'navmap' => $navmap,
265: 'suppressNavmap' => 1,
266: 'suppressEmptySequences' => $suppressEmptySequences,
267: 'filterFunc' => $filterFunc,
268: 'resource_no_folder_link' => $resource_no_folder_link,
269: 'sort_html'=> $sort_html,
270: 'r' => $r,
271: 'caller' => 'navmapsdisplay',
1.21 raeburn 272: 'linkitems' => \%toplinkitems,
273: 'notools' => $notools};
274:
1.1 albertel 275: my $render = &Apache::lonnavmaps::render($renderArgs);
276:
277: # If no resources were printed, print a reassuring message so the
278: # user knows there was no error.
279: if ($renderArgs->{'counter'} == 0) {
280: if ($showOnlyHomework) {
1.7 schulted 281: $r->print("<p><span class=\"LC_info\">".&mt("All homework is currently completed.")."</span></p>");
1.1 albertel 282: } else { # both jumpToFirstHomework and normal use the same: course must be empty
1.7 schulted 283: $r->print("<p><span class=\"LC_info\">".&mt("This course is empty.")."</span></p>");
1.1 albertel 284: }
285: }
286: #my $td=&tv_interval($t0);
287: #$r->print("<br />$td");
1.20 raeburn 288: &endContentScreen($r);
1.1 albertel 289: $r->print(&Apache::loncommon::end_page());
290: $r->rflush();
291:
292: return OK;
293: }
294:
1.20 raeburn 295: sub startContentScreen {
296: my ($r,$mode)=@_;
297:
298: $r->print("\n".'<ul class="LC_TabContentBigger" id="mainnav">'."\n");
1.22 www 299: $r->print('<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Main Content').' </b></a></li>'."\n");
1.23 raeburn 300: my $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
301: my ($suppcount,$errors);
302: unless ($allowed) {
303: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.24 raeburn 304: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.23 raeburn 305: ($suppcount,$errors) = &Apache::lonnet::get_numsuppfiles($cnum,$cdom);
306: }
1.24 raeburn 307: if ($allowed || $suppcount) {
1.23 raeburn 308: $r->print('<li '.(($mode eq 'supplemental')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>');
309: }
1.20 raeburn 310: $r->print('<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n");
311: $r->print('<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n");
312: $r->print("\n".'</ul>'."\n");
313: $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;">');
314: }
315:
316: sub endContentScreen {
317: my ($r)=@_;
318: $r->print('</div></div></div>');
319: }
320:
1.1 albertel 321: 1;
322: __END__
323:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>