1: # The LearningOnline Network with CAPA
2: # displays the main menu
3: #
4: # $Id: lonmainmenu.pm,v 1.8.4.5 2009/12/15 05:17:52 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: # There are two parameters controlling the action of this module:
30: #
31: # browser.interface - if this is 'textual', it overrides the second parameter
32: # and goes to screen reader PDA mode
33: #
34: # environment.remote - if this is 'on', the routines controll the remote
35: # control, otherwise they render the main window controls; ignored it
36: # browser.interface is 'textual'
37: #
38:
39: package Apache::lonmainmenu;
40:
41: use strict;
42: use Apache::Constants qw(:common);
43: use Apache::loncommon();
44: use Apache::lonnet;
45: use Apache::lonmenu();
46: use Apache::lonlocal;
47: use LONCAPA qw(:DEFAULT :match);
48:
49: sub handler {
50: my $r = shift;
51: &Apache::loncommon::no_cache($r);
52: &Apache::loncommon::content_type($r,'text/html');
53: $r->send_http_header;
54: return OK if $r->header_only;
55:
56: my $form;
57: if ($env{'environment.remote'} ne 'off') {
58: $form=&Apache::lonmenu::serverform();
59: }
60:
61: my $custommenu = &Apache::loncommon::needs_gci_custom();
62: my ($script_tag,$switcher);
63: if ($env{'environment.remote'} ne 'off') {
64: my $utility=&Apache::lonmenu::utilityfunctions('/adm/menu');
65: $script_tag=(<<ENDSCRIPT);
66: <script type="text/javascript">
67: $utility
68: </script>
69: ENDSCRIPT
70: } elsif ($custommenu) {
71: my $switcher_js;
72: my %courses = &Apache::loncommon::existing_gcitest_courses();
73: my $numcourses = keys(%courses);
74: if ($numcourses > 0) {
75: $switcher = &gcitest_switcher(%courses);
76: my $current;
77: if ($env{'request.course.id'}) {
78: $current = 'cc./'.$env{'course.'.$env{'request.course.id'}.'.domain'}.
79: '/'.$env{'course.'.$env{'request.course.id'}.'.num'};
80: }
81: $switcher_js = &gcitest_switcher_js($current,$numcourses);
82: $script_tag= <<"ENDSCRIPT";
83: <script type="text/javascript">
84: // <![CDATA[
85:
86: $switcher_js
87:
88: // ]]>
89: </script>
90: ENDSCRIPT
91: }
92: }
93: # ---- Print the screen, pretend to be in text mode to generate text-based menu
94: # temporarily set interface to "faketextual" and remote to "off", which renders
95: # the main menu
96: $env{'browser.interface'}='faketextual';
97: $env{'environment.remote'}='off';
98:
99: $r->print(&Apache::loncommon::start_page( 'Main Menu',
100: $script_tag,
101: {'bread_crumbs' => 1}));
102: if ($custommenu) {
103: $r->print(&Apache::lonmenu::inlinemenu('gcicustom',$switcher).$form);
104: } else {
105: $r->print(&Apache::lonmenu::inlinemenu().$form);
106: }
107: $r->print(&Apache::loncommon::end_page());
108: return OK;
109: }
110:
111: sub gcitest_switcher {
112: my (%courses) = @_;
113: my $output;
114: my %Sortby;
115: foreach my $course (sort(keys(%courses))) {
116: next unless (ref($courses{$course}) eq 'HASH');
117: my $clean_title = $courses{$course}{'description'};
118: $clean_title =~ s/\W+//g;
119: if ($clean_title eq '') {
120: $clean_title = $courses{$course}{'description'};
121: }
122: push(@{$Sortby{$clean_title}},$course);
123: }
124: my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
125: my $default;
126: if (@sorted_courses > 1) {
127: if (($env{'request.course.id'}) && ($courses{$env{'request.course.id'}})) {
128: $default = &mt('Switch concept test ...');
129: } else {
130: $default = &mt('Select a concept test ...');
131: }
132: } else {
133: unless (($env{'request.course.id'}) && ($courses{$env{'request.course.id'}})) {
134: $default = &mt('Select concept test ...');
135: }
136: }
137: if ($default) {
138: $output = '<form name="pickrole" action="/adm/roles" method="post">'.
139: '<select name="newrole" onchange="javascript:courseswitcher();">'.
140: '<option value="" selected="selected">'.$default.'</option>';
141: foreach my $item (@sorted_courses) {
142: foreach my $course (@{$Sortby{$item}}) {
143: my ($cdom,$cnum) = split('_',$course);
144: $output .= '<option value="cc./'.$cdom.'/'.$cnum.'">'.$courses{$course}{'description'}.'</option>';
145: }
146: }
147: $output .= '</select><input type="hidden" name="selectrole" value="" /></form>';
148: }
149: return $output;
150: }
151:
152: sub gcitest_switcher_js {
153: my ($current,$numcourses) = @_;
154: my $output = <<"ENDJS";
155:
156: function courseswitcher(caller) {
157: var numcourses = $numcourses;
158: var current = '$current';
159: var choice = document.pickrole.newrole.options[document.pickrole.newrole.selectedIndex].value;
160: if (choice == '') {
161: if (caller == 'icon') {
162: alert('No Concept Test selected');
163: }
164: document.pickrole.selectrole.value = '';
165: return;
166: }
167: if (choice == current) {
168: if ((caller != 'icon') && (numcourses > 1)) {
169: alert('You have selected the current course.\\nPlease select a different Concept Test course');
170: }
171: document.pickrole.newrole.selectedIndex = 0;
172: document.pickrole.selectrole.value = '';
173: return;
174: }
175: document.pickrole.selectrole.value = '1';
176: document.pickrole.submit();
177: return;
178: }
179:
180: ENDJS
181: return $output;
182: }
183:
184: 1;
185: __END__
186:
187:
188:
189:
190:
191:
192:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>