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

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # displays the main menu
                      3: #
1.8.4.1 ! raeburn     4: # $Id: lonmainmenu.pm,v 1.8 2009/07/13 08:24:21 www 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.1 ! raeburn    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: $switcher_js
        !            85: </script>
        !            86: ENDSCRIPT
        !            87:         }
1.1       albertel   88:     }
                     89: # ---- Print the screen, pretend to be in text mode to generate text-based menu
1.8       www        90: # temporarily set interface to "faketextual" and remote to "off", which renders
                     91: # the main menu
1.7       www        92:     $env{'browser.interface'}='faketextual';
                     93:     $env{'environment.remote'}='off';
                     94: 
1.6       droeschl   95:     $r->print(&Apache::loncommon::start_page( 'Main Menu',
                     96:                                               $script_tag,
                     97:                                               {'bread_crumbs' => 1}));
1.8.4.1 ! raeburn    98:     if ($custommenu) {
        !            99:         $r->print(&Apache::lonmenu::inlinemenu('gcicustom',$switcher).$form);
        !           100:     } else {
        !           101:         $r->print(&Apache::lonmenu::inlinemenu().$form);
        !           102:     }
1.1       albertel  103:     $r->print(&Apache::loncommon::end_page());
                    104:     return OK;
                    105: }
                    106: 
1.8.4.1 ! raeburn   107: sub gcitest_switcher {
        !           108:     my (%courses) = @_;
        !           109:     my $output;
        !           110:     my %Sortby;
        !           111:     foreach my $course (sort(keys(%courses))) {
        !           112:         next unless (ref($courses{$course}) eq 'HASH');
        !           113:         my $clean_title = $courses{$course}{'description'};
        !           114:         $clean_title =~ s/\W+//g;
        !           115:         if ($clean_title eq '') {
        !           116:             $clean_title = $courseinfo{$course}{'description'};
        !           117:         }
        !           118:         push(@{$Sortby{$clean_title}},$course);
        !           119:     }
        !           120:     my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
        !           121:     my $default;
        !           122:     if (@sorted_courses > 1) {
        !           123:         if (($env{'request.course.id'}) && ($courses{$env{'request.course.id'}})) {
        !           124:             $default = &mt('Switch concept test ...');
        !           125:         } else {
        !           126:             $default = &mt('Select a concept test ...');
        !           127:         }
        !           128:     } else {
        !           129:         unless (($env{'request.course.id'}) && ($courses{$env{'request.course.id'}})) {
        !           130:             $default = &mt('Select concept test ...');
        !           131:         }
        !           132:     }
        !           133:     if ($default) {
        !           134:         $output = '<form name="pickrole" action="/adm/roles" method="post">'.
        !           135:                   '<select name="newrole" method="post" onchange="javascript:courseswitcher();">'.
        !           136:                   '<option value="" selected="selected">'.$default.'</option>';
        !           137:         foreach my $item (@sorted_courses) {
        !           138:             foreach my $course (@{$Sortby{$item}}) {
        !           139:                 my ($cdom,$cnum) = split('_',$course);
        !           140:                 $output .= '<option value="cc./'.$cdom.'/'.$cnum.'">'.$item.'</option>';
        !           141:             }
        !           142:         }
        !           143:         $output .= '</select><input type="hidden" name="selectrole" value="" /></form>';
        !           144:     }
        !           145:     return $output;
        !           146: }
1.1       albertel  147: 
                    148: 1;
                    149: __END__
                    150: 
                    151: 
                    152: 
                    153: 
                    154: 
                    155: 
                    156: 

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