Annotation of loncom/interface/lonmainmenu.pm, revision 1.8.4.7

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # displays the main menu
                      3: #
1.8.4.7 ! raeburn     4: # $Id: lonmainmenu.pm,v 1.8.4.6 2010/01/05 15:27:31 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.7 ! raeburn   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:     }
1.8.4.1   raeburn   113:     if ($custommenu) {
                    114:         $r->print(&Apache::lonmenu::inlinemenu('gcicustom',$switcher).$form);
1.8.4.6   raeburn   115:     } elsif ($env{'user.domain'} eq 'gcitest') {
                    116:         $r->print(&Apache::lonmenu::inlinemenu('gcistudent',$switcher).$form);
1.8.4.7 ! raeburn   117:     } elsif (!$rolecount) {
        !           118:         $r->print(&Apache::lonmenu::inlinemenu('gcinorole').$form);
1.8.4.1   raeburn   119:     } else {
                    120:         $r->print(&Apache::lonmenu::inlinemenu().$form);
                    121:     }
1.1       albertel  122:     $r->print(&Apache::loncommon::end_page());
                    123:     return OK;
                    124: }
                    125: 
1.8.4.1   raeburn   126: sub gcitest_switcher {
1.8.4.6   raeburn   127:     my ($role,%courses) = @_;
1.8.4.1   raeburn   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 '') {
1.8.4.2   raeburn   135:             $clean_title = $courses{$course}{'description'};
1.8.4.1   raeburn   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">'.
1.8.4.5   raeburn   154:                   '<select name="newrole" onchange="javascript:courseswitcher();">'.
1.8.4.1   raeburn   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);
1.8.4.6   raeburn   159:                 $output .= '<option value="'.$role.'./'.$cdom.'/'.$cnum.'">'.$courses{$course}{'description'}.'</option>';
1.8.4.1   raeburn   160:             }
                    161:         }
                    162:         $output .= '</select><input type="hidden" name="selectrole" value="" /></form>';
                    163:     }
                    164:     return $output;
                    165: }
1.1       albertel  166: 
1.8.4.3   raeburn   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: 
1.1       albertel  199: 1;
                    200: __END__
                    201: 
                    202: 
                    203: 
                    204: 
                    205: 
                    206: 
                    207: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>