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