Annotation of loncom/interface/lonmainmenu.pm, revision 1.8.4.6
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # displays the main menu
3: #
1.8.4.6 ! raeburn 4: # $Id: lonmainmenu.pm,v 1.8.4.5 2009/12/15 05:17:52 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: # 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();
1.2 albertel 44: use Apache::lonnet;
45: use Apache::lonmenu();
1.8.4.1 raeburn 46: use Apache::lonlocal;
47: use LONCAPA qw(:DEFAULT :match);
1.1 albertel 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;
1.7 www 57: if ($env{'environment.remote'} ne 'off') {
1.1 albertel 58: $form=&Apache::lonmenu::serverform();
59: }
1.3 albertel 60:
1.8.4.1 raeburn 61: my $custommenu = &Apache::loncommon::needs_gci_custom();
62: my ($script_tag,$switcher);
1.1 albertel 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
1.8.4.6 ! raeburn 70: } elsif (($custommenu) || ($env{'user.domain'} eq 'gcitest')) {
! 71: my $role = 'st';
! 72: if ($custommenu) {
! 73: $role = 'cc';
! 74: }
1.8.4.1 raeburn 75: my $switcher_js;
1.8.4.6 ! raeburn 76: my %courses = &Apache::loncommon::existing_gcitest_courses($role);
1.8.4.1 raeburn 77: my $numcourses = keys(%courses);
78: if ($numcourses > 0) {
1.8.4.6 ! raeburn 79: $switcher = &gcitest_switcher($role,%courses);
1.8.4.1 raeburn 80: my $current;
81: if ($env{'request.course.id'}) {
1.8.4.6 ! raeburn 82: $current = $role.'./'.$env{'course.'.$env{'request.course.id'}.'.domain'}.
1.8.4.1 raeburn 83: '/'.$env{'course.'.$env{'request.course.id'}.'.num'};
84: }
85: $switcher_js = &gcitest_switcher_js($current,$numcourses);
86: $script_tag= <<"ENDSCRIPT";
87: <script type="text/javascript">
1.8.4.5 raeburn 88: // <![CDATA[
89:
1.8.4.1 raeburn 90: $switcher_js
1.8.4.5 raeburn 91:
92: // ]]>
1.8.4.1 raeburn 93: </script>
94: ENDSCRIPT
95: }
1.1 albertel 96: }
97: # ---- Print the screen, pretend to be in text mode to generate text-based menu
1.8 www 98: # temporarily set interface to "faketextual" and remote to "off", which renders
99: # the main menu
1.7 www 100: $env{'browser.interface'}='faketextual';
101: $env{'environment.remote'}='off';
102:
1.6 droeschl 103: $r->print(&Apache::loncommon::start_page( 'Main Menu',
104: $script_tag,
105: {'bread_crumbs' => 1}));
1.8.4.1 raeburn 106: if ($custommenu) {
107: $r->print(&Apache::lonmenu::inlinemenu('gcicustom',$switcher).$form);
1.8.4.6 ! raeburn 108: } elsif ($env{'user.domain'} eq 'gcitest') {
! 109: $r->print(&Apache::lonmenu::inlinemenu('gcistudent',$switcher).$form);
1.8.4.1 raeburn 110: } else {
111: $r->print(&Apache::lonmenu::inlinemenu().$form);
112: }
1.1 albertel 113: $r->print(&Apache::loncommon::end_page());
114: return OK;
115: }
116:
1.8.4.1 raeburn 117: sub gcitest_switcher {
1.8.4.6 ! raeburn 118: my ($role,%courses) = @_;
1.8.4.1 raeburn 119: my $output;
120: my %Sortby;
121: foreach my $course (sort(keys(%courses))) {
122: next unless (ref($courses{$course}) eq 'HASH');
123: my $clean_title = $courses{$course}{'description'};
124: $clean_title =~ s/\W+//g;
125: if ($clean_title eq '') {
1.8.4.2 raeburn 126: $clean_title = $courses{$course}{'description'};
1.8.4.1 raeburn 127: }
128: push(@{$Sortby{$clean_title}},$course);
129: }
130: my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
131: my $default;
132: if (@sorted_courses > 1) {
133: if (($env{'request.course.id'}) && ($courses{$env{'request.course.id'}})) {
134: $default = &mt('Switch concept test ...');
135: } else {
136: $default = &mt('Select a concept test ...');
137: }
138: } else {
139: unless (($env{'request.course.id'}) && ($courses{$env{'request.course.id'}})) {
140: $default = &mt('Select concept test ...');
141: }
142: }
143: if ($default) {
144: $output = '<form name="pickrole" action="/adm/roles" method="post">'.
1.8.4.5 raeburn 145: '<select name="newrole" onchange="javascript:courseswitcher();">'.
1.8.4.1 raeburn 146: '<option value="" selected="selected">'.$default.'</option>';
147: foreach my $item (@sorted_courses) {
148: foreach my $course (@{$Sortby{$item}}) {
149: my ($cdom,$cnum) = split('_',$course);
1.8.4.6 ! raeburn 150: $output .= '<option value="'.$role.'./'.$cdom.'/'.$cnum.'">'.$courses{$course}{'description'}.'</option>';
1.8.4.1 raeburn 151: }
152: }
153: $output .= '</select><input type="hidden" name="selectrole" value="" /></form>';
154: }
155: return $output;
156: }
1.1 albertel 157:
1.8.4.3 raeburn 158: sub gcitest_switcher_js {
159: my ($current,$numcourses) = @_;
160: my $output = <<"ENDJS";
161:
162: function courseswitcher(caller) {
163: var numcourses = $numcourses;
164: var current = '$current';
165: var choice = document.pickrole.newrole.options[document.pickrole.newrole.selectedIndex].value;
166: if (choice == '') {
167: if (caller == 'icon') {
168: alert('No Concept Test selected');
169: }
170: document.pickrole.selectrole.value = '';
171: return;
172: }
173: if (choice == current) {
174: if ((caller != 'icon') && (numcourses > 1)) {
175: alert('You have selected the current course.\\nPlease select a different Concept Test course');
176: }
177: document.pickrole.newrole.selectedIndex = 0;
178: document.pickrole.selectrole.value = '';
179: return;
180: }
181: document.pickrole.selectrole.value = '1';
182: document.pickrole.submit();
183: return;
184: }
185:
186: ENDJS
187: return $output;
188: }
189:
1.1 albertel 190: 1;
191: __END__
192:
193:
194:
195:
196:
197:
198:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>