File:
[LON-CAPA] /
loncom /
interface /
lonmainmenu.pm
Revision
1.8.4.7:
download - view:
text,
annotated -
select for diffs
Fri Jan 15 04:12:54 2010 UTC (14 years, 6 months ago) by
raeburn
Branches:
GCI_3
Diff to branchpoint 1.8:
preferred,
unified
- Customization for GCI_3.
- Custom menu when current user has no roles, i.e., is a user who has
created an account but has yet to be approved for enrollment in the
GCI Inventory course.
- Table of pending enrollment requests displayed.
1: # The LearningOnline Network with CAPA
2: # displays the main menu
3: #
4: # $Id: lonmainmenu.pm,v 1.8.4.7 2010/01/15 04:12:54 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) || ($env{'user.domain'} eq 'gcitest')) {
71: my $role = 'st';
72: if ($custommenu) {
73: $role = 'cc';
74: }
75: my $switcher_js;
76: my %courses = &Apache::loncommon::existing_gcitest_courses($role);
77: my $numcourses = keys(%courses);
78: if ($numcourses > 0) {
79: $switcher = &gcitest_switcher($role,%courses);
80: my $current;
81: if ($env{'request.course.id'}) {
82: $current = $role.'./'.$env{'course.'.$env{'request.course.id'}.'.domain'}.
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">
88: // <![CDATA[
89:
90: $switcher_js
91:
92: // ]]>
93: </script>
94: ENDSCRIPT
95: }
96: }
97: # ---- Print the screen, pretend to be in text mode to generate text-based menu
98: # temporarily set interface to "faketextual" and remote to "off", which renders
99: # the main menu
100: $env{'browser.interface'}='faketextual';
101: $env{'environment.remote'}='off';
102:
103: $r->print(&Apache::loncommon::start_page( 'Main Menu',
104: $script_tag,
105: {'bread_crumbs' => 1}));
106: my $rolecount = 0;
107: unless (($custommenu) || ($env{'user.domain'} eq 'gcitest')) {
108: foreach my $envkey (keys(%env)) {
109: next unless ($envkey =~ /^user\.role\./);
110: $rolecount ++;
111: }
112: }
113: if ($custommenu) {
114: $r->print(&Apache::lonmenu::inlinemenu('gcicustom',$switcher).$form);
115: } elsif ($env{'user.domain'} eq 'gcitest') {
116: $r->print(&Apache::lonmenu::inlinemenu('gcistudent',$switcher).$form);
117: } elsif (!$rolecount) {
118: $r->print(&Apache::lonmenu::inlinemenu('gcinorole').$form);
119: } else {
120: $r->print(&Apache::lonmenu::inlinemenu().$form);
121: }
122: $r->print(&Apache::loncommon::end_page());
123: return OK;
124: }
125:
126: sub gcitest_switcher {
127: my ($role,%courses) = @_;
128: my $output;
129: my %Sortby;
130: foreach my $course (sort(keys(%courses))) {
131: next unless (ref($courses{$course}) eq 'HASH');
132: my $clean_title = $courses{$course}{'description'};
133: $clean_title =~ s/\W+//g;
134: if ($clean_title eq '') {
135: $clean_title = $courses{$course}{'description'};
136: }
137: push(@{$Sortby{$clean_title}},$course);
138: }
139: my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
140: my $default;
141: if (@sorted_courses > 1) {
142: if (($env{'request.course.id'}) && ($courses{$env{'request.course.id'}})) {
143: $default = &mt('Switch concept test ...');
144: } else {
145: $default = &mt('Select a concept test ...');
146: }
147: } else {
148: unless (($env{'request.course.id'}) && ($courses{$env{'request.course.id'}})) {
149: $default = &mt('Select concept test ...');
150: }
151: }
152: if ($default) {
153: $output = '<form name="pickrole" action="/adm/roles" method="post">'.
154: '<select name="newrole" onchange="javascript:courseswitcher();">'.
155: '<option value="" selected="selected">'.$default.'</option>';
156: foreach my $item (@sorted_courses) {
157: foreach my $course (@{$Sortby{$item}}) {
158: my ($cdom,$cnum) = split('_',$course);
159: $output .= '<option value="'.$role.'./'.$cdom.'/'.$cnum.'">'.$courses{$course}{'description'}.'</option>';
160: }
161: }
162: $output .= '</select><input type="hidden" name="selectrole" value="" /></form>';
163: }
164: return $output;
165: }
166:
167: sub gcitest_switcher_js {
168: my ($current,$numcourses) = @_;
169: my $output = <<"ENDJS";
170:
171: function courseswitcher(caller) {
172: var numcourses = $numcourses;
173: var current = '$current';
174: var choice = document.pickrole.newrole.options[document.pickrole.newrole.selectedIndex].value;
175: if (choice == '') {
176: if (caller == 'icon') {
177: alert('No Concept Test selected');
178: }
179: document.pickrole.selectrole.value = '';
180: return;
181: }
182: if (choice == current) {
183: if ((caller != 'icon') && (numcourses > 1)) {
184: alert('You have selected the current course.\\nPlease select a different Concept Test course');
185: }
186: document.pickrole.newrole.selectedIndex = 0;
187: document.pickrole.selectrole.value = '';
188: return;
189: }
190: document.pickrole.selectrole.value = '1';
191: document.pickrole.submit();
192: return;
193: }
194:
195: ENDJS
196: return $output;
197: }
198:
199: 1;
200: __END__
201:
202:
203:
204:
205:
206:
207:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>