Annotation of loncom/interface/lonmenu.pm, revision 1.309.2.17

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.309.2.17! raeburn     4: # $Id: lonmenu.pm,v 1.309.2.16 2010/10/04 23:00:46 raeburn Exp $
1.11      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: #
1.1       www        28: #
1.269     droeschl   29: # There is one parameter controlling the action of this module:
1.48      www        30: #
                     31: # environment.remote - if this is 'on', the routines controll the remote
1.269     droeschl   32: # control, otherwise they render the main window controls; 
1.1       www        33: 
1.244     jms        34: =head1 NAME
                     35: 
                     36: Apache::lonmenu
                     37: 
                     38: =head1 SYNOPSIS
                     39: 
                     40: Coordinates the response to clicking an image.
                     41: 
                     42: This is part of the LearningOnline Network with CAPA project
                     43: described at http://www.lon-capa.org.
                     44: 
                     45: =head1 SUBROUTINES
                     46: 
                     47: =over
                     48: 
                     49: Little texts
                     50: 
                     51: =item initlittle()
                     52: 
                     53: =item menubuttons()
                     54: 
                     55: This gets called at the top of the body section
                     56: 
                     57: =item show_return_link()
                     58: 
                     59: =item registerurl()
                     60: 
                     61: This gets called in the header section
                     62: 
                     63: =item innerregister()
                     64: 
                     65: This gets called in order to register a URL, both with the Remote
                     66: and in the body of the document
                     67: 
                     68: =item loadevents()
                     69: 
                     70: =item unloadevents()
                     71: 
                     72: =item startupremote()
                     73: 
                     74: =item setflags()
                     75: 
                     76: =item maincall()
                     77: 
                     78: =item load_remote_msg()
                     79: 
                     80: =item get_menu_name()
                     81: 
                     82: =item reopenmenu()
                     83: 
                     84: =item open()
                     85: 
                     86: Open the menu
                     87: 
                     88: =item clear()
                     89: 
                     90: =item switch()
                     91: 
                     92: Switch a button or create a link
                     93: Switch acts on the javascript that is executed when a button is clicked.  
                     94: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
                     95: 
                     96: =item secondlevel()
                     97: 
                     98: =item openmenu()
                     99: 
                    100: =item inlinemenu()
                    101: 
                    102: =item rawconfig()
                    103: 
                    104: =item close()
                    105: 
                    106: =item footer()
                    107: 
                    108: =item utilityfunctions()
                    109: 
                    110: =item serverform()
                    111: 
                    112: =item constspaceform()
                    113: 
                    114: =item get_nav_status()
                    115: 
                    116: =item hidden_button_check()
                    117: 
                    118: =item roles_selector()
                    119: 
                    120: =item jump_to_role()
                    121: 
                    122: =back
                    123: 
                    124: =cut
                    125: 
1.1       www       126: package Apache::lonmenu;
                    127: 
                    128: use strict;
1.152     albertel  129: use Apache::lonnet;
1.47      matthew   130: use Apache::lonhtmlcommon();
1.115     albertel  131: use Apache::loncommon();
1.127     albertel  132: use Apache::lonenc();
1.88      www       133: use Apache::lonlocal;
1.309.2.12  raeburn   134: use Apache::loncoursequeueadmin;
1.207     foxr      135: use LONCAPA qw(:DEFAULT :match);
1.282     amueller  136: use HTML::Entities();
1.88      www       137: 
1.283     droeschl  138: use vars qw(@desklines %category_names %category_members %category_positions 
                    139:             $readdesk @primary_menu @secondary_menu);
1.88      www       140: 
1.56      www       141: my @inlineremote;
1.38      www       142: 
1.283     droeschl  143: sub prep_menuitem {
1.291     raeburn   144:     my ($menuitem) = @_;
                    145:     return '' unless(ref($menuitem) eq 'ARRAY');
1.283     droeschl  146:     my $link;
                    147:     if ($$menuitem[1]) { # graphical Link
                    148:         $link = "<img class=\"LC_noBorder\""
1.291     raeburn   149:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
                    150:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283     droeschl  151:     } else {             # textual Link
1.291     raeburn   152:         $link = &mt($$menuitem[3]);
                    153:     }
1.309.2.16  raeburn   154:     if($$menuitem[4] eq 'newmsg'){   #special style for New Messages
                    155:         return '<li><a href="'.$$menuitem[0].'"><span class="LC_new_message">'.$link.'</span></a></li>';
                    156:     }
1.299     raeburn   157:     return '<li><a href="'.$$menuitem[0].'">'.$link.'</a></li>';
1.283     droeschl  158: }
                    159: 
                    160: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
                    161: # that contains following links:
                    162: # About, Message, Roles, Help, Logout
                    163: # @primary_menu is filled within the BEGIN block of this module with 
                    164: # entries from mydesk.tab
                    165: sub primary_menu {
                    166:     my $menu;
1.309.2.1  raeburn   167:     my $custommenu = &Apache::loncommon::needs_gci_custom();
1.283     droeschl  168:     # each element of @primary contains following array:
                    169:     # (link url, icon path, alt text, link text, condition)
                    170:     foreach my $menuitem (@primary_menu) {
                    171:         # evaluate conditions 
1.296     droeschl  172:         next if    ref($menuitem)       ne 'ARRAY';    #
1.283     droeschl  173:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
1.291     raeburn   174:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
1.283     droeschl  175:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
1.291     raeburn   176:                 && !&Apache::lonmsg::mynewmail();      # 
1.283     droeschl  177:         next if    $$menuitem[4]        !~ /public/    ##we've a public user, 
                    178:                 && $env{'user.name'}    eq 'public'    ##who should not see all 
                    179:                 && $env{'user.domain'}  eq 'public';   ##links
                    180:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
                    181:                 && $env{'user.name'}    ne 'public'    # only visible to public
                    182:                 && $env{'user.domain'}  ne 'public';   # users
1.309.2.16  raeburn   183:         next if    $$menuitem[4]        eq 'gci'
                    184:                 && (!$custommenu || $env{'request.role'} =~ m{^st\./gcitest/});
                    185:         next if    $$menuitem[4]        eq 'home'
1.309.2.17! raeburn   186:                 && (($custommenu) || ($env{'user.domain'} eq 'gcitest'));
1.309.2.16  raeburn   187:         next if    $$menuitem[4]        eq 'gcitest'
1.309.2.17! raeburn   188:                 && (($env{'user.domain'} eq 'gci') || ($env{'request.role'} eq 'cm'));
1.309.2.1  raeburn   189:         next if    $$menuitem[4]        eq 'roles'     # hide links which are
                    190:                 && $custommenu;                        # not visible when GCI
                    191:         next if    $$menuitem[4]        eq 'courses'   # tabbed interface in use
                    192:                 && $custommenu;                        # 
1.283     droeschl  193:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
1.291     raeburn   194:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
1.283     droeschl  195:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
1.291     raeburn   196:                 && !&Apache::loncommon::show_course(); ##
                    197:         
                    198:             
1.283     droeschl  199:         if ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.291     raeburn   200:             $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.283     droeschl  201:         } else {
1.296     droeschl  202:             my @items = @{$menuitem};
                    203:             $items[0] = 'javascript:'.$menuitem->[0].';';
                    204:             $menu .= &prep_menuitem(\@items);
1.283     droeschl  205:         }
1.291     raeburn   206:     }
1.283     droeschl  207: 
1.291     raeburn   208:     return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
1.283     droeschl  209: }
                    210: 
                    211: 
                    212: sub secondary_menu {
                    213:     my $menu;
                    214: 
1.286     raeburn   215:     my $crstype = &Apache::loncommon::course_type();
                    216:     my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
                    217:     my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'}
                    218:                    . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
                    219:                                                  : '')); 
                    220:     my $showlink = &show_return_link();
                    221:     my %groups = &Apache::lonnet::get_active_groups(
                    222:                      $env{'user.domain'}, $env{'user.name'},
                    223:                      $env{'course.' . $env{'request.course.id'} . '.domain'},
                    224:                      $env{'course.' . $env{'request.course.id'} . '.num'});
1.309.2.16  raeburn   225:     my $custommenu = &Apache::loncommon::needs_gci_custom();
                    226:     my $numdc = &Apache::loncommon::check_for_gci_dc();
1.309.2.17! raeburn   227:     my $role = $env{'request.role'};
1.283     droeschl  228:     foreach my $menuitem (@secondary_menu) {
                    229:         # evaluate conditions 
1.296     droeschl  230:         next if    ref($menuitem)  ne 'ARRAY';
1.309.2.16  raeburn   231:         next if    $$menuitem[4]   eq 'showmenu'
1.309.2.17! raeburn   232:                 && ($custommenu || (!$numdc && $role eq 'cm'));
        !           233:         next if    $$menuitem[4]   ne 'showmenu'
        !           234:                 && $$menuitem[4]   ne 'author'
        !           235:                 && !$env{'request.course.id'};
1.283     droeschl  236:         next if    $$menuitem[4]   eq 'showreturn'
1.286     raeburn   237:                 && !$showlink
1.283     droeschl  238:                 && !($env{'request.state'} eq 'construct');
                    239:         next if    $$menuitem[4]   =~ /^mdc/
1.286     raeburn   240:                 && !$canedit;
                    241:         next if    $$menuitem[4]  eq 'mdcCourse'
                    242:                 && $crstype eq 'Community';
                    243:         next if    $$menuitem[4]  eq 'mdcCommunity'
                    244:                 && $crstype ne 'Community';
                    245:         next if    $$menuitem[4]  =~ /^remotenav/
1.283     droeschl  246:                 && $env{'environment.remotenavmap'} ne 'on';
1.286     raeburn   247:         next if    $$menuitem[4]  =~ /noremotenav/
1.283     droeschl  248:                 && $env{'environment.remotenavmap'} eq 'on';
1.295     raeburn   249:         next if $$menuitem[4] =~ /^(no|)remotenav$/ 
                    250:                 && $crstype eq 'Community';
                    251:         next if $$menuitem[4] =~ /^(no|)remotenavCommunity$/ 
                    252:                 && $crstype ne 'Community';
1.283     droeschl  253:         next if    $$menuitem[4]   =~ /showgroups$/
1.300     raeburn   254:                 && !$canviewgrps
1.286     raeburn   255:                 && !%groups;
1.309.2.16  raeburn   256:         next if   $$menuitem[4]  eq 'showroles'
1.309.2.17! raeburn   257:                 && ($custommenu || !$numdc || ($numdc && $env{'request.noversionuri'} eq '/adm/roles'));
1.309.2.16  raeburn   258:         if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'} && !$custommenu) {
1.283     droeschl  259:             # special treatment for role selector
1.298     raeburn   260:             my $roles_selector = &roles_selector(
1.283     droeschl  261:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
                    262:                         $env{'course.' . $env{'request.course.id'} . '.num'}  );
                    263: 
                    264:             $menu .= $roles_selector ? "<li>$roles_selector</li>"
                    265:                                      : '';
1.296     droeschl  266:         } elsif ($env{'environment.remotenavmap'} eq 'on') {
                    267:             # open link using javascript when remote navmap is activated
                    268:             my @items = @{$menuitem}; 
                    269:             if ($menuitem->[4] eq 'remotenav') {
                    270:                 $items[0] = "javascript:gonav('$menuitem->[0]');";
1.291     raeburn   271:             } else {
1.296     droeschl  272:                 $items[0] = "javascript:go('$menuitem->[0]');";
1.291     raeburn   273:             }
1.296     droeschl  274:             $menu .= &prep_menuitem(\@items);
                    275:         } else {
                    276:             $menu .= &prep_menuitem(\@$menuitem);
1.283     droeschl  277:         }
                    278:     }
                    279:     if ($menu =~ /\[url\].*\[symb\]/) {
1.291     raeburn   280:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
                    281:                              $env{'request.noversionuri'}));
1.283     droeschl  282: 
1.291     raeburn   283:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
                    284:                              $env{'request.symb'})); 
1.283     droeschl  285: 
                    286:         if (    $env{'request.state'} eq 'construct'
                    287:             and (   $env{'request.noversionuri'} eq '' 
                    288:                  || !defined($env{'request.noversionuri'}))) 
                    289:         {
                    290:             ($escurl = $env{'request.filename'}) =~ 
                    291:                 s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
                    292: 
1.291     raeburn   293:             $escurl  = &escape($escurl);
1.283     droeschl  294:         }    
                    295:         $menu =~ s/\[url\]/$escurl/g;
                    296:         $menu =~ s/\[symb\]/$escsymb/g;
                    297:     }
                    298: 
1.285     wenzelju  299:     return "<ul id=\"LC_secondary_menu\">$menu</ul>";
1.283     droeschl  300: }
                    301: 
1.309.2.1  raeburn   302: sub gci_secondary_menu {
                    303:     my %courses = (
                    304:         'review' => 'gci_9615072b469884921gcil1',
                    305:         'submit' => 'gci_1H96711d710194bfegcil1',
1.309.2.15  raeburn   306:         'tutorial' => 'gci_5422913620b814c90gcil1',
1.309.2.1  raeburn   307:     );
                    308:     my %linktext = (
                    309:         'review'      => 'Review Questions',
                    310:         'submit'      => 'Submit Questions',
1.309.2.3  raeburn   311:         'managetest'  => 'Manage Tests',
1.309.2.15  raeburn   312:         'tutorial'    => 'Tutorials',
1.309.2.1  raeburn   313:     );
1.309.2.3  raeburn   314:     my %links = (
                    315:                   'managetest' => '/adm/menu',
                    316:                 );
                    317:     my $current = 'managetest';
1.309.2.5  raeburn   318:     if ($env{'form.destinationurl'} eq '/adm/gci_info') {
                    319:         undef($current);
                    320:     }
1.309.2.1  raeburn   321:     foreach my $key (keys(%courses)) {
                    322:         $links{$key} = "javascript:switchpage('$key');";
                    323:         if ($env{'request.course.id'} eq $courses{$key}) {
                    324:             $links{$key} = '/adm/navmaps';
                    325:             $current = $key;
1.309.2.3  raeburn   326:             $links{'managetest'} = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu';
1.309.2.1  raeburn   327:         }
                    328:     }
1.309.2.15  raeburn   329:     my @menutabs = ('review','submit','managetest','tutorial');
1.309.2.1  raeburn   330:     my $tabs;
                    331:     foreach my $item (@menutabs) {
                    332:         if ($item eq $current) {
                    333:             $tabs .= ' <li id="current"><a href="'.$links{$item}.'">'.
                    334:                      $linktext{$item}.'</a></li>';
                    335:         } else {
                    336:             $tabs .= ' <li><a href="'.$links{$item}.'">'.
                    337:                      $linktext{$item}.'</a></li>';
                    338:         }
                    339:     }
                    340:     return '<div id="gciheader">'.
                    341:            '<ul>'.$tabs.'</ul></div><br />';
                    342: }
1.283     droeschl  343: 
1.274     www       344: #
                    345: # This routine returns a translated hash for the menu items in the top inline menu row
                    346: # Probably should be in mydesk.tab
                    347: 
1.283     droeschl  348: #SD this sub is deprecated - don't use it
1.88      www       349: sub initlittle {
                    350:     return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
1.281     raeburn   351: 				       'nav' => 'Course Contents',
1.88      www       352: 				       'main' => 'Main Menu',
1.266     raeburn   353:                                        'roles' => (&Apache::loncommon::show_course()?
1.231     albertel  354:                                                     'Courses':'Roles'),
1.235     raeburn   355:                                        'other' => 'Other Roles',
1.219     albertel  356:                                        'docs' => 'Edit Course',
1.257     hauer     357:                                        'exit' => 'Logout',
1.202     albertel  358:                                        'login' => 'Log In',
1.165     raeburn   359: 				       'launch' => 'Launch Remote Control',
1.188     albertel  360:                                        'groups' => 'Groups',
1.286     raeburn   361:                                        'gdoc' => 'Community Documents',
1.184     raeburn   362:                                        );
1.88      www       363: }
                    364: 
1.283     droeschl  365: #SD this sub is deprecated - don't use it
                    366: #SD functionality is covered by new loncommon::bodytag and primary_menu(), secondary_menu()
1.38      www       367: sub menubuttons {
                    368:     my $forcereg=shift;
1.131     raeburn   369:     my $titletable=shift;
1.274     www       370: #
                    371: # Early-out for pages that should not have a menu, triggered by query string "inhibitmenu=yes"
                    372: #
1.112     albertel  373:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    374: 					    ['inhibitmenu']);
1.152     albertel  375:     if (($env{'form.inhibitmenu'} eq 'yes') ||
1.149     www       376:         ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
1.175     albertel  377: 
                    378:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
                    379: 
1.163     www       380:     my %lt=&initlittle();
1.55      www       381:     my $navmaps='';
1.59      www       382:     my $reloadlink='';
1.151     www       383:     my $docs='';
1.165     raeburn   384:     my $groups='';
1.235     raeburn   385:     my $roles='<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
                    386:     my $role_selector;
1.165     raeburn   387:     my $showgroups=0;
1.235     raeburn   388:     my ($cnum,$cdom);
1.274     www       389: #
                    390: # if the URL is hidden, symbs and the non-versioned version of the URL would be encrypted
                    391: #
1.183     www       392:     my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
                    393:     my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
1.176     albertel  394: 
1.199     albertel  395:     my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
1.253     kaisler   396:     $logo = '<a href="/adm/about.html"><img src="'.
                    397: 	$logo.'" alt="LON-CAPA Logo" class="LC_noBorder" /></a>';
1.199     albertel  398: 
1.152     albertel  399:     if ($env{'request.state'} eq 'construct') {
1.274     www       400: #
                    401: # We are in construction space
                    402: #
1.152     albertel  403:         if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
                    404:             my $returnurl = $env{'request.filename'};
1.134     raeburn   405:             $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
1.183     www       406:             $escurl = &escape($returnurl);
1.134     raeburn   407:         }
                    408:     }
1.165     raeburn   409:     if ($env{'request.course.id'}) {
1.274     www       410: #
                    411: # We are in a course
                    412: #
1.235     raeburn   413:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    414:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.165     raeburn   415:         my %coursegroups;
1.188     albertel  416:         my $viewgrps_permission =
1.197     raeburn   417: 	    &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.165     raeburn   418:         if (!$viewgrps_permission) {
1.235     raeburn   419:             %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum);
1.188     albertel  420: 	}
1.165     raeburn   421:         if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
                    422:             $showgroups = 1;
                    423:         }
1.235     raeburn   424:         $role_selector = &roles_selector($cdom,$cnum);
                    425:         if ($role_selector) {
                    426:             $roles = '<span class="LC_nobreak">'.$role_selector.'&nbsp;&nbsp;<a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></span>';
                    427:         }
1.165     raeburn   428:     }
                    429: 
1.267     droeschl  430:     if ($env{'environment.remote'} eq 'off') {
1.48      www       431: # Remote Control is switched off
1.58      www       432: # figure out colors
1.267     droeschl  433:         my %lt=&initlittle();
1.172     albertel  434: 
1.58      www       435:         my $domain=&Apache::loncommon::determinedomain();
1.291     raeburn   436:         my $function=&Apache::loncommon::get_users_function();
1.58      www       437:         my $link=&Apache::loncommon::designparm($function.'.link',$domain);
                    438:         my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
                    439:         my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
                    440:         my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
1.267     droeschl  441: 
                    442:         if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                    443:             return (<<ENDINLINEMENU);
1.285     wenzelju  444:             <ol class="LC_primary_menu LC_right">
1.271     droeschl  445:                 <li>$logo</li>
                    446:                 <li><a href="/adm/roles" target="_top">$lt{'login'}</a></li>
                    447:             </ol>
                    448:             <hr />
1.156     albertel  449: ENDINLINEMENU
                    450:         }
1.253     kaisler   451:         $roles = '<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
1.58      www       452: # Do we have a NAV link?
1.152     albertel  453:         if ($env{'request.course.id'}) {
1.141     albertel  454: 	    my $link='/adm/navmaps?postdata='.$escurl.'&amp;postsymb='.
                    455: 		$escsymb;
1.152     albertel  456: 	    if ($env{'environment.remotenavmap'} eq 'on') {
1.141     albertel  457: 		$link="javascript:gonav('".$link."')";
                    458: 	    }
                    459: 	    $navmaps=(<<ENDNAV);
1.253     kaisler   460: <li><a href="$link" target="_top">$lt{'nav'}</a></li>
1.114     albertel  461: ENDNAV
1.286     raeburn   462:             my $is_community = 
                    463:                 (&Apache::loncommon::course_type() eq 'Community');
1.152     albertel  464: 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.286     raeburn   465:                 my $text = ($is_community) ? $lt{'gdoc'} : $lt{'docs'};
1.151     www       466: 		$docs=(<<ENDDOCS);
1.253     kaisler   467: <li><a href="/adm/coursedocs" target="_top">$text</a></li>
1.151     www       468: ENDDOCS
                    469:             }
1.197     raeburn   470:             if ($showgroups) {
                    471:                 $groups =(<<ENDGROUPS);
1.253     kaisler   472: <li><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></li>
1.197     raeburn   473: ENDGROUPS
                    474:             }
1.228     albertel  475: 	    if (&show_return_link()) {
1.183     www       476:                 my $escreload=&escape('return:');
1.59      www       477:                 $reloadlink=(<<ENDRELOAD);
1.253     kaisler   478: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
1.59      www       479: ENDRELOAD
                    480:             }
1.235     raeburn   481:             if ($role_selector) {
1.253     kaisler   482:             	#$roles = '<td>'.$role_selector.'</td><td><a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></td>';
                    483: 				$role_selector = '<li>'.$role_selector.'</li>';
1.235     raeburn   484:             }
1.55      www       485:         }
1.163     www       486: 	if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
1.183     www       487: 	    my $escreload=&escape('return:');
1.163     www       488: 	    $reloadlink=(<<ENDCRELOAD);
1.253     kaisler   489: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
1.163     www       490: ENDCRELOAD
                    491:         }
1.276     droeschl  492:     my $reg     = $forcereg ? &innerregister($forcereg,$titletable) : '';
                    493:     my $form    = &serverform();
                    494:     my $utility = &utilityfunctions();
                    495: 
                    496:     #Prepare the message link that indicates the arrival of new mail
1.291     raeburn   497:     my $messagelink = &Apache::lonmsg::mynewmail() ? "Message (new)" : "Message";
1.276     droeschl  498:        $messagelink = '<a href="javascript:go(\'/adm/communicate\');">'
                    499:                       . mt($messagelink) .'</a>';
                    500: 
                    501:     my $helplink = &Apache::loncommon::top_nav_help('Help');
1.58      www       502: 	return (<<ENDINLINEMENU);
1.129     albertel  503: <script type="text/javascript">
1.277     bisitz    504: // <![CDATA[
1.150     albertel  505: // BEGIN LON-CAPA Internal
1.116     albertel  506: $utility
1.150     albertel  507: // ]]>
1.48      www       508: </script>
1.285     wenzelju  509: <ol class="LC_primary_menu LC_right">
1.253     kaisler   510: 	<li>$logo</li>
1.256     kaisler   511: 	<li>$messagelink</li>
1.253     kaisler   512: 	<li>$roles</li>
                    513: 	<li>$helplink</li>
                    514: 	<li><a href="/adm/logout" target="_top">$lt{'exit'}</a></li>
                    515: </ol>
1.285     wenzelju  516: <ul id="LC_secondary_menu">
1.253     kaisler   517: <li><a href="/adm/menu" target="_top">$lt{'main'}</a></li>
1.59      www       518: $reloadlink
1.55      www       519: $navmaps
1.151     www       520: $docs
1.165     raeburn   521: $groups
1.253     kaisler   522: $role_selector
1.263     droeschl  523: </ul>
1.168     albertel  524: $form
1.129     albertel  525: <script type="text/javascript">
1.48      www       526: // END LON-CAPA Internal
                    527: </script>
1.58      www       528: $reg
1.48      www       529: ENDINLINEMENU
                    530:     } else {
                    531: 	return '';
                    532:     }
1.72      www       533: }
                    534: 
1.228     albertel  535: sub show_return_link {
1.309.2.17! raeburn   536:     return unless ($env{'request.course.id'});
1.309.2.16  raeburn   537:     if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)})
                    538:         || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) {
                    539:         return if ($env{'form.register'});
                    540:     }
1.228     albertel  541:     return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
                    542: 	     $env{'request.symb'} eq '')
                    543: 	    ||
                    544: 	    ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
                    545: 	    ||
                    546: 	    (($env{'request.noversionuri'}=~/^\/adm\//) &&
                    547: 	     ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
                    548: 	     ($env{'request.noversionuri'}!~
1.309.2.16  raeburn   549: 	      m[^/adm/.*/(smppg|bulletinboard)($|\?)])
1.228     albertel  550: 	     ));
                    551: }
                    552: 
1.38      www       553: 
                    554: sub registerurl {
1.173     albertel  555:     my ($forcereg) = @_;
1.38      www       556:     my $result = '';
1.175     albertel  557:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.66      albertel  558:     my $force_title='';
1.152     albertel  559:     if ($env{'request.state'} eq 'construct') {
1.66      albertel  560: 	$force_title=&Apache::lonxml::display_title();
                    561:     }
1.269     droeschl  562:     if (($env{'environment.remote'} eq 'off') ||
1.152     albertel  563:         ((($env{'request.publicaccess'}) || 
1.83      www       564:          (!&Apache::lonnet::is_on_map(
1.183     www       565: 	   &unescape($env{'request.noversionuri'})))) &&
1.38      www       566:         (!$forcereg))) {
1.277     bisitz    567:  	return
                    568:         $result
                    569:        .'<script type="text/javascript">'."\n"
                    570:        .'// <![CDATA['."\n"
                    571:        .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
                    572:        .'// ]]>'."\n"
                    573:        .'</script>'
                    574:        .$force_title;
1.38      www       575:     }
1.41      www       576: # Graphical display after login only
1.174     albertel  577:     if ($env{'request.registered'} && !$forcereg) { return ''; }
1.173     albertel  578:     $result.=&innerregister($forcereg);
1.66      albertel  579:     return $result.$force_title;
1.40      www       580: }
                    581: 
                    582: sub innerregister {
1.308     raeburn   583:     my ($forcereg,$titletable,$bread_crumbs) = @_;
1.40      www       584:     my $result = '';
1.120     raeburn   585:     my ($uname,$thisdisfn);
1.152     albertel  586:     my $const_space = ($env{'request.state'} eq 'construct');
1.131     raeburn   587:     my $is_const_dir = 0;
1.120     raeburn   588: 
1.175     albertel  589:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40      www       590: 
1.174     albertel  591:     $env{'request.registered'} = 1;
1.40      www       592: 
1.267     droeschl  593:     my $noremote = ($env{'environment.remote'} eq 'off');
1.49      www       594:     
1.177     albertel  595:     undef(@inlineremote);
1.56      www       596: 
1.38      www       597:     my $reopen=&Apache::lonmenu::reopenmenu();
1.40      www       598: 
1.38      www       599:     my $newmail='';
1.267     droeschl  600: 
                    601:     if (&Apache::lonmsg::newmail() && !$noremote) { 
                    602:         # We have new mail and remote is up
                    603:         $newmail= 'swmenu.setstatus("you have","messages");';
1.233     www       604:     } 
1.276     droeschl  605: 
1.288     raeburn   606:     my ($breadcrumb,$separator);
1.267     droeschl  607:     if ($noremote
1.177     albertel  608: 	     && ($env{'request.symb'}) 
                    609: 	     && ($env{'request.course.id'})) {
1.267     droeschl  610: 
                    611:         my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
                    612:         my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
                    613: 
                    614:         my $maptitle = &Apache::lonnet::gettitle($mapurl);
                    615:         my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.299     raeburn   616:         my $contentstext;
                    617:         if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Community') {
                    618:             $contentstext = &mt('Community Contents');
                    619:         } else {
                    620:             $contentstext = &mt('Course Contents');
                    621:         }
1.309.2.16  raeburn   622:         my @crumbs;
                    623:         unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps')
                    624:                 && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
                    625:             @crumbs = ({text  => Apache::loncommon::course_type()
                    626:                                 . ' Contents',
                    627:                         href  => "Javascript:gopost('/adm/navmaps','')"});
                    628:         }
1.289     raeburn   629:         if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
                    630:             push(@crumbs, {text  => '...',
                    631:                            no_mt => 1});
                    632:         }
1.268     droeschl  633: 
                    634:         push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
                    635:                                                    && $maptitle ne 'default.sequence' 
                    636:                                                    && $maptitle ne $coursetitle);
                    637: 
                    638:         push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
                    639: 
1.291     raeburn   640:         &Apache::lonhtmlcommon::clear_breadcrumbs();
                    641:         &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
1.301     droeschl  642:         #$breadcrumb .= &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
1.288     raeburn   643: 	unless (($env{'request.state'} eq 'edit') || ($newmail) ||
                    644: 		($env{'request.state'} eq 'construct') ||
                    645: 		($env{'form.register'})) {
                    646:             $separator = &Apache::loncommon::head_subbox();
                    647:         }
1.267     droeschl  648:         #
1.65      www       649:     }
1.152     albertel  650:     if ($env{'request.state'} eq 'construct') {
1.131     raeburn   651:         $newmail = $titletable;
1.267     droeschl  652:     } 
                    653:     my $timesync   = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
                    654:     my $tablestart = ( $noremote ? '<table id="LC_menubuttons">' : '');
                    655:     my $tableend   = ( $noremote ? '</table>' : '');
1.41      www       656: # =============================================================================
                    657: # ============================ This is for URLs that actually can be registered
1.296     droeschl  658:     if (($env{'request.noversionuri'}!~m{^/(res/)*adm/}) || ($forcereg)) {
1.40      www       659: # -- This applies to homework problems for users with grading privileges
1.152     albertel  660: 	my $crs='/'.$env{'request.course.id'};
                    661: 	if ($env{'request.course.sec'}) {
                    662: 	    $crs.='_'.$env{'request.course.sec'};
1.107     albertel  663: 	}
                    664: 	$crs=~s/\_/\//g;
                    665: 
1.38      www       666:         my $hwkadd='';
1.152     albertel  667:         if ($env{'request.symb'} ne '' &&
1.161     albertel  668: 	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
1.79      www       669: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
1.259     bisitz    670: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]',
1.40      www       671:                        "gocmd('/adm/grades','gradingmenu')",
                    672:                        'Modify user grades for this assessment resource');
1.154     www       673:             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
                    674: 		$hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
                    675:                        "gocmd('/adm/grades','submission')",
                    676: 		       'View user submissions for this assessment resource');
1.38      www       677:             }
1.107     albertel  678: 	}
1.152     albertel  679: 	if ($env{'request.symb'} ne '' &&
1.145     albertel  680: 	    &Apache::lonnet::allowed('opa',$crs)) {
1.107     albertel  681: 	    $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
                    682: 			     "gocmd('/adm/parmset','set')",
1.196     www       683: 			     'Modify parameter settings for this resource');
1.38      www       684: 	}
1.40      www       685: # -- End Homework
1.38      www       686:         ###
                    687:         ### Determine whether or not to display the 'cstr' button for this
                    688:         ### resource
                    689:         ###
                    690:         my $editbutton = '';
1.258     raeburn   691:         my $noeditbutton = 1;
                    692:         my ($cnum,$cdom);
                    693:         if ($env{'request.course.id'}) {
                    694:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    695:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    696:         }
1.152     albertel  697:         if ($env{'user.author'}) {
1.234     raeburn   698:             if ($env{'request.role'}=~/^(aa|ca|au)/) {
1.274     www       699: #
                    700: # We have the role of an author
                    701: #
1.38      www       702:                 # Set defaults for authors
                    703:                 my ($top,$bottom) = ('con-','struct');
1.152     albertel  704:                 my $action = "go('/priv/".$env{'user.name'}."');";
                    705:                 my $cadom  = $env{'request.role.domain'};
                    706:                 my $caname = $env{'user.name'};
1.236     bisitz    707:                 my $desc = "Enter my construction space";
1.38      www       708:                 # Set defaults for co-authors
1.152     albertel  709:                 if ($env{'request.role'} =~ /^ca/) { 
1.206     albertel  710:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.38      www       711:                     ($top,$bottom) = ('co con-','struct');
                    712:                     $action = "go('/priv/".$caname."');";
                    713:                     $desc = "Enter construction space as co-author";
1.234     raeburn   714:                 } elsif ($env{'request.role'} =~ /^aa/) {
                    715:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                    716:                     ($top,$bottom) = ('co con-','struct');
                    717:                     $action = "go('/priv/".$caname."');";
                    718:                     $desc = "Enter construction space as assistant co-author";
1.38      www       719:                 }
                    720:                 # Check that we are on the correct machine
                    721:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel  722: 		my $allowed=0;
                    723: 		my @ids=&Apache::lonnet::current_machine_ids();
                    724: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    725: 		if (!$allowed) {
                    726: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
1.258     raeburn   727:                     $noeditbutton = 0;
1.38      www       728:                 }
                    729:             }
1.274     www       730: #
                    731: # We are an author for some stuff, but currently do not have the role of author.
                    732: # Figure out if we have authoring privileges for the resource we are looking at.
                    733: # This should maybe become a privilege check in lonnet
                    734: #
1.38      www       735:             ##
                    736:             ## Determine if user can edit url.
                    737:             ##
                    738:             my $cfile='';
                    739:             my $cfuname='';
                    740:             my $cfudom='';
1.258     raeburn   741:             my $uploaded;
1.152     albertel  742:             if ($env{'request.filename'}) {
                    743:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.258     raeburn   744:                 if (defined($cnum) && defined($cdom)) {
                    745:                     $uploaded = &is_course_upload($file,$cnum,$cdom);
                    746:                 }
                    747:                 if (!$uploaded) {
                    748:                     $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
                    749:                     # Check that the user has permission to edit this resource
                    750:                     ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
                    751:                     if (defined($cfudom)) {
                    752: 		        my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
                    753: 		        my $allowed=0;
                    754: 		        my @ids=&Apache::lonnet::current_machine_ids();
                    755: 		        foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    756: 		        if ($allowed) {
                    757:                             $cfile=$file;
                    758:                         }
1.38      www       759:                     }
                    760:                 }
1.258     raeburn   761:             }
1.38      www       762:             # Finally, turn the button on or off
1.120     raeburn   763:             if ($cfile && !$const_space) {
1.302     raeburn   764:                 my $nocrsedit;
                    765:                 # Suppress display where CC has switched to student role.
                    766:                 if ($env{'request.course.id'}) {
                    767:                     unless(&Apache::lonnet::allowed('mdc',
                    768:                                                     $env{'request.course.id'})) {
                    769:                         $nocrsedit = 1;
                    770:                     }
                    771:                 }
                    772:                 if ($nocrsedit) {
                    773:                     $editbutton=&clear(6,1);
                    774:                 } else {
                    775:                     $editbutton=&switch
                    776:                        ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
1.38      www       777:                      "go('".$cfile."');","Edit this resource");
1.302     raeburn   778:                     $noeditbutton = 0;
                    779:                 }
1.38      www       780:             } elsif ($editbutton eq '') {
1.191     www       781:                 $editbutton=&clear(6,1);
1.38      www       782:             }
                    783:         }
1.258     raeburn   784:         if (($noeditbutton) && ($env{'request.filename'})) { 
                    785:             if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
                    786:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                    787:                 if (defined($cnum) && defined($cdom)) {
                    788:                     if (&is_course_upload($file,$cnum,$cdom)) {
                    789:                         my $cfile = &edit_course_upload($file,$cnum,$cdom);
                    790:                         if ($cfile) {
                    791:                             $editbutton=&switch
                    792:                                         ('','',6,1,'pcstr.gif','edit[_1]',
                    793:                                          'resource[_2]',"go('".$cfile."');",
                    794:                                          'Edit this resource');
                    795:                         }
                    796:                     }
                    797:                 }
                    798:             }
                    799:         }
1.38      www       800:         ###
                    801:         ###
1.41      www       802: # Prepare the rest of the buttons
1.120     raeburn   803:         my $menuitems;
                    804:         if ($const_space) {
1.274     www       805: #
                    806: # We are in construction space
                    807: #
1.128     albertel  808: 	    my ($uname,$thisdisfn) =
1.152     albertel  809: 		($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
1.121     raeburn   810:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
1.131     raeburn   811:             if ($currdir =~ m-/$-) {
                    812:                 $is_const_dir = 1;
                    813:             } else {
1.267     droeschl  814:                 $currdir =~ s|[^/]+$||;
1.200     foxr      815: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208     albertel  816: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274     www       817: #
                    818: # Probably should be in mydesk.tab
                    819: #
1.131     raeburn   820:                 $menuitems=(<<ENDMENUITEMS);
1.208     albertel  821: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
1.200     foxr      822: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
1.259     bisitz    823: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
1.200     foxr      824: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
                    825: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
1.120     raeburn   826: ENDMENUITEMS
1.131     raeburn   827:             }
1.308     raeburn   828:             if ($noremote) {
                    829:                 if (ref($bread_crumbs) eq 'ARRAY') {
                    830:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    831:                     foreach my $crumb (@{$bread_crumbs}){
                    832:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
                    833:                     }
                    834:                 }
                    835:             }
1.203     foxr      836:         } elsif ( defined($env{'request.course.id'}) && 
                    837: 		 $env{'request.symb'} ne '' ) {
1.274     www       838: #
                    839: # We are in a course and looking at a registred URL
                    840: # Should probably be in mydesk.tab
                    841: #
1.120     raeburn   842: 	    $menuitems=(<<ENDMENUITEMS);
1.41      www       843: c&3&1
1.209     www       844: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
                    845: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
1.77      www       846: c&6&3
                    847: c&8&1
                    848: c&8&2
1.106     www       849: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.209     www       850: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
1.41      www       851: ENDMENUITEMS
1.216     albertel  852: 
1.243     tempelho  853: my $currentURL = &Apache::loncommon::get_symb();
                    854: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
                    855: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
                    856: $menuitems.="s&9&3&";
                    857: if(length($annotation) > 0){
                    858: 	$menuitems.="anot2.gif";
                    859: }else{
                    860: 	$menuitems.="anot.gif";
                    861: }
                    862: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
                    863: $menuitems.="Make notes and annotations about this resource&&1\n";
                    864: 
1.279     raeburn   865:             unless ($noremote) { 
                    866:                 my $showreqcrs = &check_for_rcrs();
                    867:                 if ($showreqcrs) {
                    868:                     $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]".
                    869:                                 "&go('/adm/requestcourse')&Course requests\n";
                    870:                 }
                    871:             }
1.309.2.16  raeburn   872:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|portfolio)(\?|$)/) {
1.294     raeburn   873: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
1.216     albertel  874: 		    $menuitems.=(<<ENDREALRES);
1.259     bisitz    875: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
1.216     albertel  876: ENDREALRES
                    877:                 }
1.120     raeburn   878: 	        $menuitems.=(<<ENDREALRES);
1.106     www       879: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
                    880: s&8&2&fdbk.gif&feedback[_1]&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1.77      www       881: ENDREALRES
1.120     raeburn   882: 	    }
                    883:         }
1.203     foxr      884: 	if ($env{'request.uri'} =~ /^\/res/) {
                    885: 	    $menuitems .= (<<ENDMENUITEMS);
                    886: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
                    887: ENDMENUITEMS
                    888: 	}
1.41      www       889:         my $buttons='';
                    890:         foreach (split(/\n/,$menuitems)) {
                    891: 	    my ($command,@rest)=split(/\&/,$_);
1.220     raeburn   892:             my $idx=10*$rest[0]+$rest[1];
                    893:             if (&hidden_button_check() eq 'yes') {
                    894:                 if ($idx == 21 ||$idx == 23) {
                    895:                     $buttons.=&switch('','',@rest);
                    896:                 } else {
                    897:                     $buttons.=&clear(@rest);
                    898:                 }
                    899:             } else {  
                    900:                 if ($command eq 's') {
                    901: 	            $buttons.=&switch('','',@rest);
                    902:                 } else {
                    903:                     $buttons.=&clear(@rest);
                    904:                 }
1.41      www       905:             }
                    906:         }
1.148     albertel  907: 
1.267     droeschl  908:         if ($noremote) {
1.148     albertel  909: 	    my $addremote=0;
1.267     droeschl  910: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.148     albertel  911: 	    my $inlinebuttons='';
1.309.2.16  raeburn   912: 
1.301     droeschl  913:     if ($addremote) {
                    914: 
1.304     droeschl  915:         Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301     droeschl  916: 
1.309.2.16  raeburn   917:             Apache::lonhtmlcommon::add_breadcrumb_tool(
                    918:                 'navigation', @inlineremote[21,23]);
                    919:         if(hidden_button_check() ne 'yes') {
                    920:             Apache::lonhtmlcommon::add_breadcrumb_tool(
                    921:                 'tools', @inlineremote[93,91,81,82,83]);
                    922: 
                    923:             #publish button in construction space
                    924:             if ($env{'request.state'} eq 'construct'){
                    925:                 Apache::lonhtmlcommon::add_breadcrumb_tool(
                    926:                      'advtools', @inlineremote[63]);
                    927:             }else{
                    928:                 Apache::lonhtmlcommon::add_breadcrumb_tool(
                    929:                      'tools', @inlineremote[63]);
                    930:             }
                    931: 
                    932:             unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
                    933:                 Apache::lonhtmlcommon::add_breadcrumb_tool(
                    934:                     'advtools', @inlineremote[61,71,72,73,92]);
                    935:             }
1.301     droeschl  936:         }
                    937: 
                    938: #       # Registered, textual output
                    939: #        if ( $env{'environment.icons'} eq 'iconsonly' ) {
                    940: #            $inlinebuttons = (<<ENDARROWSINLINE);
                    941: #<tr><td>
                    942: #$inlineremote[21] $inlineremote[23]
                    943: #ENDARROWSINLINE
                    944: #            if ( &hidden_button_check() ne 'yes' ) {
                    945: #                $inlinebuttons .= (<<ENDINLINEICONS);
                    946: #$inlineremote[61] $inlineremote[63]
                    947: #$inlineremote[71] $inlineremote[72] $inlineremote[73]
                    948: #$inlineremote[81] $inlineremote[82] $inlineremote[83]
                    949: #$inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
                    950: #ENDINLINEICONS
                    951: #            }
                    952: #        } else { # not iconsonly
                    953: #            if ( $inlineremote[21] ne '' || $inlineremote[23] ne '' ) {
                    954: #                $inlinebuttons = (<<ENDFIRSTLINE);
                    955: #<tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
                    956: #ENDFIRSTLINE
                    957: #            }
                    958: #            if ( &hidden_button_check() ne 'yes' ) {
                    959: #                foreach my $row ( 6 .. 9 ) {
                    960: #                    if (   $inlineremote[ ${row} . '1' ] ne ''
                    961: #                        || $inlineremote[ $row . '2' ] ne ''
                    962: #                        || $inlineremote[ $row . '3' ] ne '' )
                    963: #                    {
                    964: #                        $inlinebuttons .= <<"ENDLINE";
                    965: #<tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
                    966: #ENDLINE
                    967: #                    }
                    968: #                }
                    969: #            }
                    970: #        }
                    971:     }
                    972:         #SD see below
                    973:         $breadcrumb = &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
1.41      www       974: 	    $result =(<<ENDREGTEXT);
1.129     albertel  975: <script type="text/javascript">
1.42      www       976: // BEGIN LON-CAPA Internal
                    977: </script>
1.41      www       978: $timesync
1.267     droeschl  979: $breadcrumb
1.305     bisitz    980: <!-- $tablestart -->
                    981: <!-- $inlinebuttons -->
                    982: <!-- $tableend -->
1.224     albertel  983: $newmail
1.305     bisitz    984: <!-- $separator -->
1.129     albertel  985: <script type="text/javascript">
1.64      www       986: // END LON-CAPA Internal
1.42      www       987: </script>
                    988: 
1.41      www       989: ENDREGTEXT
                    990: # Registered, graphical output
                    991:         } else {
1.152     albertel  992: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.183     www       993: 	    $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
1.152     albertel  994: 	    my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.113     albertel  995: 	    my $navstatus=&get_nav_status();
1.140     albertel  996: 	    my $clearcstr;
1.148     albertel  997: 
1.152     albertel  998: 	    if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1.41      www       999: 	    $result = (<<ENDREGTHIS);
1.38      www      1000:      
1.129     albertel 1001: <script type="text/javascript">
1.277     bisitz   1002: // <![CDATA[
1.150     albertel 1003: // BEGIN LON-CAPA Internal
1.42      www      1004: var swmenu=null;
1.38      www      1005: 
                   1006:     function LONCAPAreg() {
                   1007: 	  swmenu=$reopen;
                   1008:           swmenu.clearTimeout(swmenu.menucltim);
                   1009:           $timesync
                   1010:           $newmail
1.41      www      1011:           $buttons
1.84      www      1012: 	  swmenu.currentURL="$requri";
1.85      www      1013:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
1.125     albertel 1014:           swmenu.currentSymb="$cursymb";
                   1015:           swmenu.reloadSymb="$cursymb";
1.38      www      1016:           swmenu.currentStale=0;
1.113     albertel 1017: 	  $navstatus
1.38      www      1018:           $hwkadd
                   1019:           $editbutton
                   1020:     }
                   1021: 
                   1022:     function LONCAPAstale() {
                   1023: 	  swmenu=$reopen
                   1024:           swmenu.currentStale=1;
                   1025:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
                   1026:              swmenu.switchbutton
                   1027:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
                   1028: 	  }
                   1029:           swmenu.clearbut(7,2);
                   1030:           swmenu.clearbut(7,3);
                   1031:           swmenu.menucltim=swmenu.setTimeout(
                   1032:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.140     albertel 1033:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1.38      www      1034: 			  2000);
                   1035:       }
                   1036: 
1.150     albertel 1037: // END LON-CAPA Internal 
1.277     bisitz   1038: // ]]>
1.38      www      1039: </script>
                   1040: ENDREGTHIS
1.41      www      1041:         }
                   1042: # =============================================================================
1.38      www      1043:     } else {
1.41      www      1044: # ========================================== This can or will not be registered
1.267     droeschl 1045:         if ($noremote) {
1.269     droeschl 1046: # Not registered
1.267     droeschl 1047:             $result= (<<ENDDONOTREGTEXT);
1.41      www      1048: ENDDONOTREGTEXT
                   1049:         } else {
                   1050: # Not registered, graphical
                   1051:            $result = (<<ENDDONOTREGTHIS);
1.38      www      1052: 
1.129     albertel 1053: <script type="text/javascript">
1.277     bisitz   1054: // <![CDATA[
1.38      www      1055: // BEGIN LON-CAPA Internal
1.42      www      1056: var swmenu=null;
1.38      www      1057: 
                   1058:     function LONCAPAreg() {
                   1059: 	  swmenu=$reopen
                   1060:           $timesync
                   1061:           swmenu.currentStale=1;
                   1062:           swmenu.clearbut(2,1);
                   1063:           swmenu.clearbut(2,3);
                   1064:           swmenu.clearbut(8,1);
                   1065:           swmenu.clearbut(8,2);
                   1066:           swmenu.clearbut(8,3);
                   1067:           if (swmenu.currentURL) {
                   1068:              swmenu.switchbutton
                   1069:               (3,1,'reload.gif','return','location','go(currentURL)');
                   1070:  	  } else {
                   1071: 	      swmenu.clearbut(3,1);
                   1072:           }
                   1073:     }
                   1074: 
                   1075:     function LONCAPAstale() {
                   1076:     }
                   1077: 
                   1078: // END LON-CAPA Internal
1.277     bisitz   1079: // ]]>
1.38      www      1080: </script>
                   1081: ENDDONOTREGTHIS
1.41      www      1082:        }
                   1083: # =============================================================================
1.38      www      1084:     }
                   1085:     return $result;
                   1086: }
                   1087: 
1.258     raeburn  1088: sub is_course_upload {
                   1089:     my ($file,$cnum,$cdom) = @_;
                   1090:     my $uploadpath = &LONCAPA::propath($cdom,$cnum);
                   1091:     $uploadpath =~ s{^\/}{};
                   1092:     if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
                   1093:         ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
                   1094:         return 1;
                   1095:     }
                   1096:     return;
                   1097: }
                   1098: 
                   1099: sub edit_course_upload {
                   1100:     my ($file,$cnum,$cdom) = @_;
                   1101:     my $cfile;
                   1102:     if ($file =~/\.(htm|html|css|js|txt)$/) {
                   1103:         my $ext = $1;
                   1104:         my $url = &Apache::lonnet::hreflocation('',$file);
                   1105:         my $home = &Apache::lonnet::homeserver($cnum,$cdom);
                   1106:         my @ids=&Apache::lonnet::current_machine_ids();
                   1107:         my $dest;
                   1108:         if ($home && grep(/^\Q$home\E$/,@ids)) {
                   1109:             $dest = $url.'?forceedit=1';
                   1110:         } else {
                   1111:             unless (&Apache::lonnet::get_locks()) {
                   1112:                 $dest = '/adm/switchserver?otherserver='.
                   1113:                         $home.'&role='.$env{'request.role'}.
                   1114:                         '&url='.$url.'&forceedit=1';
                   1115:             }
                   1116:         }
                   1117:         if ($dest) {
                   1118:             $cfile = &HTML::Entities::encode($dest,'"<>&');
                   1119:         }
                   1120:     }
                   1121:     return $cfile;
                   1122: }
                   1123: 
1.38      www      1124: sub loadevents() {
1.152     albertel 1125:     if ($env{'request.state'} eq 'construct' ||
1.175     albertel 1126: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38      www      1127:     return 'LONCAPAreg();';
                   1128: }
                   1129: 
                   1130: sub unloadevents() {
1.152     albertel 1131:     if ($env{'request.state'} eq 'construct' ||
1.175     albertel 1132: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38      www      1133:     return 'LONCAPAstale();';
                   1134: }
1.30      www      1135: 
1.32      www      1136: 
                   1137: sub startupremote {
                   1138:     my ($lowerurl)=@_;
1.269     droeschl 1139:     if ($env{'environment.remote'} eq 'off') {
1.34      www      1140:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
                   1141:     }
1.49      www      1142: #
                   1143: # The Remote actually gets launched!
                   1144: #
1.32      www      1145:     my $configmenu=&rawconfig();
1.183     www      1146:     my $esclowerurl=&escape($lowerurl);
1.119     www      1147:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1.32      www      1148:     return(<<ENDREMOTESTARTUP);
1.129     albertel 1149: <script type="text/javascript">
1.277     bisitz   1150: // <![CDATA[
1.118     albertel 1151: var timestart;
1.35      www      1152: function wheelswitch() {
1.118     albertel 1153:     if (typeof(document.wheel) != 'undefined') {
                   1154: 	if (typeof(document.wheel.spin) != 'undefined') {
                   1155: 	    var date=new Date();
                   1156: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
                   1157: 	    document.wheel.spin.value=$message;
                   1158: 	}
                   1159:     }
1.35      www      1160:    if (window.status=='|') { 
                   1161:       window.status='/'; 
                   1162:    } else {
                   1163:       if (window.status=='/') {
                   1164:          window.status='-';
                   1165:       } else {
                   1166:          if (window.status=='-') { 
                   1167:             window.status='\\\\'; 
                   1168:          } else {
                   1169:             if (window.status=='\\\\') { window.status='|'; }
                   1170:          }
                   1171:       }
                   1172:    } 
                   1173: }
                   1174: 
1.32      www      1175: // ---------------------------------------------------------- The wait function
                   1176: var canceltim;
                   1177: function wait() {
                   1178:    if ((menuloaded==1) || (tim==1)) {
1.35      www      1179:       window.status='Done.';
1.32      www      1180:       if (tim==0) {
                   1181:          clearTimeout(canceltim);
                   1182:          $configmenu
                   1183:          window.location='$lowerurl';  
                   1184:       } else {
1.52      www      1185: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
1.32      www      1186:       }
                   1187:    } else {
1.35      www      1188:       wheelswitch();
                   1189:       setTimeout('wait();',200);
1.32      www      1190:    }
                   1191: }
                   1192: 
                   1193: function main() {
1.52      www      1194:    canceltim=setTimeout('tim=1;',30000);
1.35      www      1195:    window.status='-';
1.118     albertel 1196:    var date=new Date();
                   1197:    timestart=date.getTime();
1.32      www      1198:    wait();
                   1199: }
                   1200: 
1.277     bisitz   1201: // ]]>
1.32      www      1202: </script>
                   1203: ENDREMOTESTARTUP
                   1204: }
                   1205: 
                   1206: sub setflags() {
                   1207:     return(<<ENDSETFLAGS);
1.129     albertel 1208: <script type="text/javascript">
1.277     bisitz   1209: // <![CDATA[
1.32      www      1210:     menuloaded=0;
                   1211:     tim=0;
1.277     bisitz   1212: // ]]>
1.32      www      1213: </script>
                   1214: ENDSETFLAGS
                   1215: }
                   1216: 
                   1217: sub maincall() {
1.269     droeschl 1218:     if ($env{'environment.remote'} eq 'off') { return ''; }
1.32      www      1219:     return(<<ENDMAINCALL);
1.129     albertel 1220: <script type="text/javascript">
1.277     bisitz   1221: // <![CDATA[
1.32      www      1222:     main();
1.277     bisitz   1223: // ]]>
1.32      www      1224: </script>
                   1225: ENDMAINCALL
                   1226: }
1.118     albertel 1227: 
                   1228: sub load_remote_msg {
                   1229:     my ($lowerurl)=@_;
                   1230: 
1.269     droeschl 1231:     if ($env{'environment.remote'} eq 'off') { return ''; }
1.118     albertel 1232: 
1.183     www      1233:     my $esclowerurl=&escape($lowerurl);
1.261     bisitz   1234:     my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
                   1235:                 ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
                   1236:                 ,'</a>');
1.118     albertel 1237:     return(<<ENDREMOTEFORM);
                   1238: <p>
                   1239: <form name="wheel">
1.119     www      1240: <input name="spin" type="text" size="60" />
1.118     albertel 1241: </form>
                   1242: </p>
                   1243: <p>$link</p>
                   1244: ENDREMOTEFORM
                   1245: }
1.230     albertel 1246: 
                   1247: sub get_menu_name {
                   1248:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
                   1249:     $hostid =~ s/\W//g;
                   1250:     return 'LCmenu'.$hostid;
                   1251: }
                   1252: 
1.30      www      1253: 
                   1254: sub reopenmenu {
1.269     droeschl 1255:    if ($env{'environment.remote'} eq 'off') { return ''; }
1.230     albertel 1256:    my $menuname = &get_menu_name();
1.47      matthew  1257:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                   1258:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30      www      1259: } 
                   1260: 
1.1       www      1261: 
                   1262: sub open {
1.22      www      1263:     my $returnval='';
1.269     droeschl 1264:     if ($env{'environment.remote'} eq 'off') { 
1.277     bisitz   1265: 	return
                   1266:         '<script type="text/javascript">'."\n"
                   1267:        .'// <![CDATA['."\n"
                   1268:        .'self.name="loncapaclient";'."\n"
                   1269:        .'// ]]>'."\n"
                   1270:        .'</script>';
1.111     albertel 1271:     }
1.230     albertel 1272:     my $menuname = &get_menu_name();
1.222     albertel 1273:     
                   1274: #    unless (shift eq 'unix') {
1.22      www      1275: # resizing does not work on linux because of virtual desktop sizes
1.222     albertel 1276: #       $returnval.=(<<ENDRESIZE);
                   1277: #if (window.screen) {
                   1278: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
                   1279: #    self.moveTo(190,15);
                   1280: #}
                   1281: #ENDRESIZE
                   1282: #    }
1.277     bisitz   1283:     $returnval=(<<ENDOPEN);
                   1284: // <![CDATA[
1.35      www      1285: window.status='Opening LON-CAPA Remote Control';
1.272     droeschl 1286: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
1.191     www      1287: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.71      www      1288: self.name='loncapaclient';
1.277     bisitz   1289: // ]]>
1.1       www      1290: ENDOPEN
1.129     albertel 1291:     return '<script type="text/javascript">'.$returnval.'</script>';
1.1       www      1292: }
                   1293: 
1.2       www      1294: 
                   1295: # ================================================================== Raw Config
                   1296: 
1.3       www      1297: sub clear {
                   1298:     my ($row,$col)=@_;
1.269     droeschl 1299:     unless ($env{'environment.remote'} eq 'off') {
1.275     www      1300:        if (($row<1) || ($row>13)) { return ''; }
1.35      www      1301:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.56      www      1302:    } else { 
                   1303:        $inlineremote[10*$row+$col]='';
                   1304:        return ''; 
                   1305:    }
1.3       www      1306: }
                   1307: 
1.40      www      1308: # ============================================ Switch a button or create a link
1.25      matthew  1309: # Switch acts on the javascript that is executed when a button is clicked.  
                   1310: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www      1311: 
1.2       www      1312: sub switch {
1.209     www      1313:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2       www      1314:     $act=~s/\$uname/$uname/g;
                   1315:     $act=~s/\$udom/$udom/g;
1.88      www      1316:     $top=&mt($top);
                   1317:     $bot=&mt($bot);
                   1318:     $desc=&mt($desc);
1.238     www      1319:     if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
                   1320:        $img=&mt($img);
                   1321:     }
1.209     www      1322:     my $idx=10*$row+$col;
                   1323:     $category_members{$cat}.=':'.$idx;
                   1324: 
1.269     droeschl 1325:     unless ($env{'environment.remote'} eq 'off') {
1.275     www      1326:        if (($row<1) || ($row>13)) { return ''; }
1.50      www      1327: # Remote
1.34      www      1328:        return "\n".
1.35      www      1329:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.34      www      1330:    } else {
1.50      www      1331: # Inline Remote
1.213     www      1332:        if ($env{'environment.icons'} ne 'classic') {
                   1333:           $img=~s/\.gif$/\.png/;
                   1334:        }
1.41      www      1335:        if ($nobreak==2) { return ''; }
1.34      www      1336:        my $text=$top.' '.$bot;
1.78      www      1337:        $text=~s/\s*\-\s*//gs;
1.105     www      1338: 
1.99      www      1339:        my $pic=
1.225     albertel 1340: 	   '<img alt="'.$text.'" src="'.
                   1341: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303     droeschl 1342: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.177     albertel 1343:        if ($env{'browser.interface'} eq 'faketextual') {
1.274     www      1344: # Main Menu
1.103     www      1345: 	   if ($nobreak==3) {
1.209     www      1346: 	       $inlineremote[$idx]="\n".
1.177     albertel 1347: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
1.247     harmsja  1348: 		   '</td><td align="left">'.
1.103     www      1349: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                   1350: 	   } elsif ($nobreak) {
1.209     www      1351: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1352: 		   '<td align="left">'.
1.177     albertel 1353: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215     www      1354:                     <td class="LC_menubuttons_text" align="left"><a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$text.'</span></a></td>';
1.103     www      1355: 	   } else {
1.209     www      1356: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1357: 		   '<td align="left">'.
1.103     www      1358: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel 1359: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215     www      1360: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103     www      1361: 	   }
1.94      www      1362:        } else {
1.103     www      1363: # Inline Menu
1.218     www      1364:            if ($env{'environment.icons'} eq 'iconsonly') {
                   1365:               $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
                   1366:            } else {
                   1367: 	      $inlineremote[$idx]=
1.301     droeschl 1368: 		   '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.215     www      1369: 		   '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
1.218     www      1370:            }
1.94      www      1371:        }
1.34      www      1372:    }
1.56      www      1373:     return '';
1.2       www      1374: }
                   1375: 
                   1376: sub secondlevel {
                   1377:     my $output='';
                   1378:     my 
1.209     www      1379:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2       www      1380:     if ($prt eq 'any') {
1.209     www      1381: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1382:     } elsif ($prt=~/^r(\w+)/) {
                   1383:         if ($rol eq $1) {
1.209     www      1384:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1385:         }
                   1386:     }
                   1387:     return $output;
                   1388: }
                   1389: 
1.18      www      1390: sub openmenu {
1.230     albertel 1391:     my $menuname = &get_menu_name();
1.269     droeschl 1392:     if ($env{'environment.remote'} eq 'off') { return ''; }
1.47      matthew  1393:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                   1394:     return "window.open(".$nothing.",'".$menuname."');";
1.18      www      1395: }
                   1396: 
1.56      www      1397: sub inlinemenu {
1.309.2.16  raeburn  1398:     my ($context) = @_;
1.210     albertel 1399:     undef(@inlineremote);
                   1400:     undef(%category_members);
1.309.2.1  raeburn  1401:     my $output;
1.309.2.16  raeburn  1402:     if ($context eq 'gcicustom') {
                   1403:         my (%can_request,%request_domains,$canreq,$createtext);
                   1404:         my $role = 'st';
                   1405:         my $custommenu = &Apache::loncommon::needs_gci_custom();
                   1406:         if ($custommenu) {
                   1407:             $role = 'cc';
                   1408:         }
                   1409:         my %courses = &Apache::loncommon::existing_gcitest_courses($role);
                   1410:         my $numcourses = keys(%courses);
                   1411:         my ($switcher_js,$switcher);
                   1412:         my $formname = 'testpicker';
                   1413:         if ($numcourses > 0) {
                   1414:             $switcher = &Apache::loncommon::gcitest_switcher($role,$formname,%courses);
                   1415:             my $current;
                   1416:             my $cid = $env{'request.course.id'};
                   1417:             if ($cid) {
                   1418:                 $current = $role.'./'.$env{'course.'.$cid.'.domain'}.
                   1419:                            '/'.$env{'course.'.$cid.'.num'};
                   1420:             }
                   1421:             $switcher_js = &Apache::loncommon::gcitest_switcher_js($current,$numcourses,$formname);
                   1422:             if ($switcher_js) {
                   1423:                 $switcher_js= <<"ENDSCRIPT";
                   1424: <script type="text/javascript">
                   1425: // <![CDATA[
                   1426: 
                   1427: $switcher_js
                   1428: 
                   1429: // ]]>
                   1430: </script>
                   1431: 
                   1432: ENDSCRIPT
1.309.2.7  raeburn  1433:             }
1.309.2.16  raeburn  1434:             $switcher = $switcher_js.$switcher;
1.309.2.7  raeburn  1435:         }
1.309.2.16  raeburn  1436:         if ($env{'user.domain'} eq 'gci') {
                   1437:             $canreq =
                   1438:                 &Apache::lonnet::check_can_request('gcitest',\%can_request,\%request_domains);
                   1439:             $createtext = &mt('Create Concept Test');
                   1440:             if ($numcourses) {
                   1441:                 $createtext = &mt('Create New Test');
                   1442:             }
1.309.2.1  raeburn  1443:         }
1.309.2.8  raeburn  1444:         if ($env{'request.course.id'}) {
1.309.2.16  raeburn  1445:             if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
                   1446:                 $output .= 
                   1447:                   '<div class="LC_Box LC_800Box LC_GCI_Menu">'.
                   1448:                   '<h3 class="LC_hcell">'.&mt('Test Management').'</h3>'.
                   1449:                   '<div class="LC_GCI_Menu_left">'.
                   1450:                   '<dl class="LC_GCI_Menu">'.
                   1451:                   '<dt><a href="/adm/navmaps">'.&mt('Concept Test Contents').'</a></dt>'.
                   1452:                   '<dd style="background-image:url(\'/res/adm/pages/nav.png\');"><a class="LC_menubuttons_link" href="/adm/navmaps">'.&mt('Display the table of contents for your Concept Test.').'</a></dd>'.
                   1453:                   '<dt><a href="/adm/coursedocs">'.&mt('Assemble Concept Test').'</a></dt>'.
                   1454:                   '<dd style="background-image:url(\'/res/adm/pages/docs.png\');"><a class="LC_menubuttons_link" href="/adm/coursedocs">'.&mt('If no students have attempted the Concept Test you will be able to modify it. You can also change the start and end date of the test itself.').'</a></dd>'.
                   1455:                   '<dt><a href="/adm/createuser">'.&mt('Enrollment and Student Activity').'</a></dt>'.
                   1456:                   '<dd style="background-image:url(\'/res/adm/pages/cprv.png\');"><a class="LC_menubuttons_link" href="/adm/createuser">'.&mt('Display or download a course roster, and view information about completion status and last login. You can also add new students, or change access dates for existing students.').'</a></dd></dl></div>'.
                   1457:                   '<div class="LC_GCI_Menu_right"><dl class="LC_GCI_Menu">'.
                   1458:                   '<dt><a href="/adm/whatsnew">'.&mt("What's New?").'</a></dt>'.
                   1459:                   '<dd style="background-image:url(\'/res/adm/pages/new.png\');"><a class="LC_menubuttons_link" href="/adm/whatsnew">'.&mt('View information about changes in your Concept Test course.').'</a></dd>'.
                   1460:                   '<dt><a href="/adm/printout">'.&mt('Prepare Printable Concept Test').'</a></dt>'.
                   1461:                   '<dd style="background-image:url(\'/res/adm/pages/prnt.png\');"><a class="LC_menubuttons_link" href="/adm/printout">'.&mt('Create a PDF which you can send to a printer to create a hardcopy of the Concept Test.').'</a></dd>'.
                   1462:                   '<dt><a href="/adm/statistics">'.&mt('Concept Test Statistics').'</a></dt>'.
                   1463:                   '<dd style="background-image:url(\'/res/adm/pages/chrt.png\');"><a class="LC_menubuttons_link" href="/adm/statistics">'.&mt('After the closing date of the Concept Test you can view and download statistics for the test, as well as anonymized submission data.').'</a></dd>';
                   1464:                 if ($canreq) {
                   1465:                     $output .= '<dt><a href="javascript:switchpage('."'createtest'".');">'.&mt('Create New Test').'</a></dt>'.
                   1466:                                '<dd style="background-image:url(\'/res/adm/pages/rcrs.png\');"><a class="LC_menubuttons_link" href="javascript:switchpage('."'createtest'".');">'.
                   1467:                                &mt('Create a new Concept Test Course Container. Choose GCI questions  to include in the test and upload a student roster.').'</a></dd>';
                   1468:                 }
                   1469:                 $output .= '</dl></div></div><br clear="all"/>';
1.309.2.7  raeburn  1470:             } else {
                   1471:                 my $navtext = &mt('Table of Contents');
1.309.2.16  raeburn  1472:                 my $navdesc = &mt('Display Table of Contents for Geoscience Concept Inventory');
1.309.2.7  raeburn  1473:                 if ($env{'request.role.domain'} eq 'gcitest') {
                   1474:                     $navtext = &mt('Display Test Contents');
1.309.2.16  raeburn  1475:                     $navdesc = &mt('Display the table of contents for this Concept Test');
                   1476:                 }
                   1477:                 $output .= 
                   1478:                            '<div class="LC_Box LC_800Box LC_GCI_Menu">'.
                   1479:                            '<h3 class="LC_hcell">'.&mt('Utilities').'</h3>'.
                   1480:                            '<div class="LC_GCI_Menu_left">'.
                   1481:                            '<dl class="LC_GCI_Menu">'.
                   1482:                            '<dt><a href="/adm/navmaps">'.$navtext.'</dt>'.
                   1483:                            '<dd style="background-image:url(\'/res/adm/pages/nav.png\');">'.
                   1484:                            '<a class="LC_menubuttons_link" href="/adm/navmaps">'.$navdesc.'</a></dd></dl></div>';
                   1485:                 if ($canreq) {
                   1486:                     $output .= '<div class="LC_GCI_Menu_right">'.
                   1487:                                '<dl class="LC_GCI_Menu">'.
                   1488:                                '<dt><a href="javascript:switchpage('."'createtest'".');">'.$createtext.'</a></dt>'.
                   1489:                                '<dd style="background-image:url(\'/res/adm/pages/rcrs.png\');"><a class="LC_menubuttons_link" href="javascript:switchpage('."'createtest'".');">'.&mt('Create a new Concept Test Course Container').'</a>. '.&mt('Choose GCI questions to include in the test and upload a student roster.').'</dd></dl></div>';
                   1490:                 }
                   1491:                 $output .= '</div><br clear="all"/>';
                   1492:             }
                   1493:         } elsif ($switcher || $canreq) {
                   1494:             $output .= '<br /><br />'.
                   1495:                        '<div class="LC_Box LC_800Box LC_GCI_Menu">'.
                   1496:                        '<h3 class="LC_hcell">'.&mt('Utilities').'</h3>'.
                   1497:                        '<div class="LC_GCI_Menu_left">'.
                   1498:                        '<dl class="LC_GCI_Menu">';
                   1499:             if ($canreq) {
                   1500:                 $output .= '<dt><a href="javascript:switchpage('."'createtest'".');">'.$createtext.'</a></dt>'.
                   1501:                            '<dd style="background-image:url(\'/res/adm/pages/rcrs.png\');"><a class="LC_menubuttons_link" href="javascript:switchpage('."'createtest'".');">'.&mt('Create a new Concept Test Course Container. Choose GCI questions to include in the test and upload a student roster.').'</a></dd></dl></div>';
                   1502:                 if ($switcher) {
                   1503:                     $output .= '<div class="LC_GCI_Menu_right">'.
                   1504:                                '<dl class="LC_GCI_Menu">';
1.309.2.7  raeburn  1505:                 }
                   1506:             }
1.309.2.16  raeburn  1507:             if ($switcher) {
                   1508:                 $output .= '<dt>'.&mt('Select Concept Test').'</dt>'.
                   1509:                            '<dd style="background-image:url(\'/res/adm/pages/roles.png\');">'.$switcher.'<br /><br /></dd></dl></div>';
1.309.2.12  raeburn  1510:             }
1.309.2.16  raeburn  1511:             $output .= '</div><br clear="all"/>';
                   1512:         }
                   1513:     } elsif ($context eq 'gcinorole') {
                   1514:         my $queued =  &Apache::loncoursequeueadmin::queued_selfenrollment('notitle');
                   1515:         if ($queued) {
                   1516:             $output .= 
                   1517:                        '<div class="LC_Box LC_800Box">'.
                   1518:                        '<h3 class="LC_hcell">'.&mt('Pending Enrollment Requests').'</h3>'.
                   1519:                        $queued.
                   1520:                        '</div>';
1.309.2.12  raeburn  1521:         }
1.309.2.2  raeburn  1522:     } else {
1.309.2.1  raeburn  1523:         # calling rawconfig with "1" will evaluate mydesk.tab, 
                   1524:         # even if there is no active remote control
                   1525:         &rawconfig(1);
1.309.2.2  raeburn  1526:         $output='<table><tr>';
1.309.2.1  raeburn  1527:         for (my $col=1; $col<=2; $col++) {
                   1528:             $output.='<td class="LC_mainmenu_col_fieldset">';
                   1529:             for (my $row=1; $row<=8; $row++) {
                   1530:                 foreach my $cat (keys(%category_members)) {
                   1531:                     if ($category_positions{$cat} ne "$col,$row") { next; }
                   1532:                     $output.='<div class="LC_Box LC_400Box">';
                   1533: 	            $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
                   1534:                     $output.='<table>';
                   1535:                     my %active=();
                   1536:                     foreach my $menu_item (split(/\:/,$category_members{$cat})) {
                   1537:                         if ($inlineremote[$menu_item]) {
                   1538:                             $active{$menu_item}=1;
                   1539:                         }
                   1540:                     }
                   1541:                     foreach my $item (sort(keys(%active))) {
                   1542:                         $output.=$inlineremote[$item];
                   1543:                     }
                   1544:                     $output.='</table>';
                   1545:                     $output.='</div>';
1.309.2.2  raeburn  1546:                 }
1.240     riegler  1547:             }
1.309.2.1  raeburn  1548:             $output.="</td>";
                   1549:         }
                   1550:         $output.="</tr></table>";
1.240     riegler  1551:     }
                   1552:     return $output;
                   1553: }
                   1554: 
1.2       www      1555: sub rawconfig {
1.274     www      1556: #
                   1557: # This evaluates mydesk.tab
                   1558: # Need to add more positions and more privileges to deal with all
                   1559: # menu items.
                   1560: #
1.34      www      1561:     my $textualoverride=shift;
                   1562:     my $output='';
1.269     droeschl 1563:     unless ($env{'environment.remote'} eq 'off') {
1.35      www      1564:        $output.=
                   1565:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
                   1566: "\nwindow.status='Configuring Remote Control ';";
1.34      www      1567:     } else {
                   1568:        unless ($textualoverride) { return ''; }
                   1569:     }
1.152     albertel 1570:     my $uname=$env{'user.name'};
                   1571:     my $udom=$env{'user.domain'};
                   1572:     my $adv=$env{'user.adv'};
1.266     raeburn  1573:     my $show_course=&Apache::loncommon::show_course();
1.152     albertel 1574:     my $author=$env{'user.author'};
1.5       www      1575:     my $crs='';
1.295     raeburn  1576:     my $crstype='';
1.152     albertel 1577:     if ($env{'request.course.id'}) {
                   1578:        $crs='/'.$env{'request.course.id'};
                   1579:        if ($env{'request.course.sec'}) {
                   1580: 	   $crs.='_'.$env{'request.course.sec'};
1.7       www      1581:        }
1.8       www      1582:        $crs=~s/\_/\//g;
1.295     raeburn  1583:        $crstype = &Apache::loncommon::course_type();
1.5       www      1584:     }
1.152     albertel 1585:     my $pub=($env{'request.state'} eq 'published');
                   1586:     my $con=($env{'request.state'} eq 'construct');
                   1587:     my $rol=$env{'request.role'};
                   1588:     my $requested_domain = $env{'request.role.domain'};
1.184     raeburn  1589:     foreach my $line (@desklines) {
1.209     www      1590:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3       www      1591:         $prt=~s/\$uname/$uname/g;
                   1592:         $prt=~s/\$udom/$udom/g;
1.295     raeburn  1593:         if ($prt =~ /\$crs/) {
                   1594:             next unless ($env{'request.course.id'});
                   1595:             next if ($crstype eq 'Community');
                   1596:             $prt=~s/\$crs/$crs/g;
                   1597:         } elsif ($prt =~ /\$cmty/) {
                   1598:             next unless ($env{'request.course.id'});
                   1599:             next if ($crstype ne 'Community');
                   1600:             $prt=~s/\$cmty/$crs/g;
                   1601:         }
1.25      matthew  1602:         $prt=~s/\$requested_domain/$requested_domain/g;
1.211     www      1603:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3       www      1604:         if ($pro eq 'clear') {
1.4       www      1605: 	    $output.=&clear($row,$col);
1.3       www      1606:         } elsif ($pro eq 'any') {
1.2       www      1607:                $output.=&secondlevel(
1.209     www      1608: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1609: 	} elsif ($pro eq 'smp') {
                   1610:             unless ($adv) {
                   1611:                $output.=&secondlevel(
1.209     www      1612:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1613:             }
                   1614:         } elsif ($pro eq 'adv') {
                   1615:             if ($adv) {
                   1616:                $output.=&secondlevel(
1.209     www      1617: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1618:             }
1.231     albertel 1619: 	} elsif ($pro eq 'shc') {
                   1620:             if ($show_course) {
                   1621:                $output.=&secondlevel(
                   1622:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1623:             }
                   1624:         } elsif ($pro eq 'nsc') {
                   1625:             if (!$show_course) {
                   1626:                $output.=&secondlevel(
                   1627: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1628:             }
1.81      matthew  1629:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295     raeburn  1630:             my $priv = $1;
                   1631:             if ($priv =~ /^mdc(Course|Community)/) {
                   1632:                 if ($crstype eq $1) {
                   1633:                     $priv = 'mdc';
                   1634:                 } else {
                   1635:                     next;
                   1636:                 }
                   1637:             }
                   1638: 	    if (&Apache::lonnet::allowed($priv,$prt)) {
1.209     www      1639:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4       www      1640:             }
1.295     raeburn  1641:         } elsif ($pro eq 'course')  {
                   1642:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209     www      1643:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81      matthew  1644: 	    }
1.295     raeburn  1645:         } elsif ($pro eq 'community')  {
                   1646:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
                   1647:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1648:             }
1.124     matthew  1649:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                   1650:             my $key = $1;
1.307     raeburn  1651:             if ($crstype ne 'Community') {
                   1652:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1653:                 if ($key eq 'canuse_pdfforms') {
                   1654:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1655:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1656:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1657:                     }
                   1658:                 }
                   1659:                 if ($coursepref) { 
                   1660:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1661:                 }
1.295     raeburn  1662:             }
                   1663:         } elsif ($pro =~ /^communityenv_(.*)$/) {
                   1664:             my $key = $1;
1.307     raeburn  1665:             if ($crstype eq 'Community') {
                   1666:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1667:                 if ($key eq 'canuse_pdfforms') {
                   1668:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1669:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1670:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1671:                     }
                   1672:                 }
                   1673:                 if ($coursepref) { 
                   1674:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1675:                 }
1.124     matthew  1676:             }
1.81      matthew  1677:         } elsif ($pro =~ /^course_(.*)$/) {
                   1678:             # Check for permissions inside of a course
1.295     raeburn  1679:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
1.152     albertel 1680:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1681:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81      matthew  1682:                  )) {
1.209     www      1683:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26      www      1684: 	    }
1.295     raeburn  1685:         } elsif ($pro =~ /^community_(.*)$/) {
                   1686:             # Check for permissions inside of a community
                   1687:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
                   1688:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1689:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
                   1690:                  )) {
                   1691:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1692:             }
1.4       www      1693:         } elsif ($pro eq 'author') {
                   1694:             if ($author) {
1.152     albertel 1695:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234     raeburn  1696:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
1.152     albertel 1697:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19      matthew  1698:                     # Check that we are on the correct machine
1.29      matthew  1699:                     my $cadom=$requested_domain;
1.152     albertel 1700:                     my $caname=$env{'user.name'};
1.234     raeburn  1701:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29      matthew  1702: 		       ($cadom,$caname)=
1.206     albertel 1703:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29      matthew  1704:                     }                       
                   1705:                     $act =~ s/\$caname/$caname/g;
1.19      matthew  1706:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel 1707: 		    my $allowed=0;
                   1708: 		    my @ids=&Apache::lonnet::current_machine_ids();
                   1709: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   1710: 		    if ($allowed) {
1.209     www      1711:                         $output.=&switch($caname,$cadom,
                   1712:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19      matthew  1713:                     }
1.6       www      1714:                 }
1.2       www      1715:             }
1.248     raeburn  1716:         } elsif ($pro eq 'tools') {
                   1717:             my @tools = ('aboutme','blog','portfolio');
                   1718:             if (grep(/^\Q$prt\E$/,@tools)) {
1.249     raeburn  1719:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251     raeburn  1720:                                                        $env{'user.domain'},
                   1721:                                                        $prt,undef,'tools')) {
                   1722:                     $output.=&clear($row,$col);
                   1723:                     next;
                   1724:                 }
1.278     raeburn  1725:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
                   1726:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
                   1727:                     next;
                   1728:                 }
                   1729:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
                   1730:                     next;
                   1731:                 }
1.279     raeburn  1732:                 my $showreqcrs = &check_for_rcrs();
1.251     raeburn  1733:                 if (!$showreqcrs) {
1.248     raeburn  1734:                     $output.=&clear($row,$col);
                   1735:                     next;
                   1736:                 }
                   1737:             }
                   1738:             $prt='any';
                   1739:             $output.=&secondlevel(
                   1740:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1741:         }
1.13      harris41 1742:     }
1.269     droeschl 1743:     unless ($env{'environment.remote'} eq 'off') {
1.35      www      1744:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.123     www      1745:        if (&Apache::lonmsg::newmail()) { 
                   1746: 	   $output.='swmenu.setstatus("you have","messages");';
                   1747:        }
1.34      www      1748:     }
1.123     www      1749: 
1.2       www      1750:     return $output;
                   1751: }
                   1752: 
1.279     raeburn  1753: sub check_for_rcrs {
                   1754:     my $showreqcrs = 0;
1.280     raeburn  1755:     my @reqtypes = ('official','unofficial','community');
                   1756:     foreach my $type (@reqtypes) {
1.279     raeburn  1757:         if (&Apache::lonnet::usertools_access($env{'user.name'},
                   1758:                                               $env{'user.domain'},
                   1759:                                               $type,undef,'requestcourses')) {
                   1760:             $showreqcrs = 1;
                   1761:             last;
                   1762:         }
                   1763:     }
1.280     raeburn  1764:     if (!$showreqcrs) {
                   1765:         foreach my $type (@reqtypes) {
                   1766:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
                   1767:                 $showreqcrs = 1;
                   1768:                 last;
                   1769:             }
                   1770:         }
                   1771:     }
1.279     raeburn  1772:     return $showreqcrs;
                   1773: }
                   1774: 
1.2       www      1775: # ======================================================================= Close
1.1       www      1776: 
                   1777: sub close {
1.269     droeschl 1778:     if ($env{'environment.remote'} eq 'off') { return ''; }
1.230     albertel 1779:     my $menuname = &get_menu_name();
1.1       www      1780:     return(<<ENDCLOSE);
1.129     albertel 1781: <script type="text/javascript">
1.277     bisitz   1782: // <![CDATA[
1.35      www      1783: window.status='Accessing Remote Control';
1.30      www      1784: menu=window.open("/adm/rat/empty.html","$menuname",
1.1       www      1785:                  "height=350,width=150,scrollbars=no,menubar=no");
1.35      www      1786: window.status='Disabling Remote Control';
                   1787: menu.active=0;
1.31      www      1788: menu.autologout=0;
1.35      www      1789: window.status='Closing Remote Control';
1.1       www      1790: menu.close();
1.35      www      1791: window.status='Done.';
1.277     bisitz   1792: // ]]>
1.1       www      1793: </script>
                   1794: ENDCLOSE
                   1795: }
                   1796: 
                   1797: # ====================================================================== Footer
                   1798: 
                   1799: sub footer {
                   1800: 
1.33      www      1801: }
                   1802: 
1.122     albertel 1803: sub nav_control_js {
1.152     albertel 1804:     my $nav=($env{'environment.remotenavmap'} eq 'on');
1.122     albertel 1805:     return (<<NAVCONTROL);
                   1806:     var w_loncapanav_flag="$nav";
                   1807: 
                   1808: 
                   1809: function gonav(url) {
                   1810:    if (w_loncapanav_flag != 1) {
                   1811:       gopost(url,'');
                   1812:    }  else {
                   1813:       navwindow=window.open(url,
                   1814:                   "loncapanav","height=600,width=400,scrollbars=1"); 
                   1815:    }
                   1816: }
                   1817: NAVCONTROL
                   1818: }
                   1819: 
1.306     raeburn  1820: sub dc_popup_js {
                   1821:     my %lt = &Apache::lonlocal::texthash(
                   1822:                                           more => '(More ...)',
                   1823:                                           less => '(Less ...)',
                   1824:                                         );
                   1825:     return <<"END";
                   1826: 
                   1827: function showCourseID() {
                   1828:     document.getElementById('dccid').style.display='block';
                   1829:     document.getElementById('dccid').style.textAlign='left';
1.307     raeburn  1830:     document.getElementById('dccid').style.textFace='normal';
1.306     raeburn  1831:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>';
                   1832:     return;
                   1833: }
                   1834: 
                   1835: function hideCourseID() {
                   1836:     document.getElementById('dccid').style.display='none';
                   1837:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()">$lt{'more'}</a>';
                   1838:     return;
                   1839: }
                   1840: 
                   1841: END
                   1842: 
                   1843: }
                   1844: 
1.42      www      1845: sub utilityfunctions {
1.309.2.1  raeburn  1846:     my ($caller,$custommenu) = @_;
1.269     droeschl 1847:     unless ($env{'environment.remote'} eq 'off' || 
                   1848:             $caller eq '/adm/menu') { 
                   1849:             return ''; }
1.309.2.1  raeburn  1850:      
                   1851:     my $gcimenujs;
                   1852:     if ($custommenu) {
1.309.2.10  raeburn  1853:         my %concepttests = &Apache::loncommon::existing_gcitest_courses('cc');
1.309.2.1  raeburn  1854:         my $managetesturl = '/adm/menu';
                   1855:         my $createtesturl = '/adm/requestcourse';
                   1856:         if (($env{'request.course.id'}) &&
                   1857:             ($env{'course.'.$env{'request.course.id'}.'.domain'} eq 'gci')) {
                   1858:             my @items = keys(%concepttests);
                   1859:             if (@items== 1) {
                   1860:                 my $newrole = $items[0];
                   1861:                 $newrole =~ s{_}{/};
                   1862:                 $managetesturl = '/adm/roles?selectrole=1&cc./'.$newrole.'=1';
                   1863:             } else {
                   1864:                 $managetesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu';
                   1865:             }
                   1866:         }
                   1867:         if ($env{'request.course.id'}) {
                   1868:             $createtesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2frequestcourse';
                   1869:         }
                   1870:         $gcimenujs = <<"ENDCUSTOM";
                   1871: 
                   1872: function switchpage(caller) {
                   1873:     if (caller == 'review') {
                   1874:         document.location.href = '/adm/roles?selectrole=1&st./gci/9615072b469884921gcil1=1';
                   1875:     }
                   1876:     if (caller == 'submit') {
                   1877:         document.location.href = '/adm/roles?selectrole=1&st./gci/1H96711d710194bfegcil1=1';
                   1878:     }
                   1879:     if (caller == 'createtest') {
                   1880:         document.location.href = '$createtesturl';
                   1881:     }
                   1882:     if (caller == 'managetest') {
                   1883:         document.location.href = '$managetesturl';
                   1884:     }
1.309.2.15  raeburn  1885:     if (caller == 'tutorial') {
                   1886:         document.location.href = '/adm/roles?selectrole=1&st./gci/5422913620b814c90gcil1=1';
                   1887:     }
1.309.2.1  raeburn  1888:     return;
                   1889: }
                   1890: 
                   1891: ENDCUSTOM
                   1892:     }
                   1893:        
1.152     albertel 1894:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.293     raeburn  1895:     if ($currenturl =~ m{^/adm/wrapper/ext/}) {
                   1896:         if ($env{'request.external.querystring'}) {
                   1897:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
                   1898:         }
                   1899:     }
1.183     www      1900:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125     albertel 1901:     
1.152     albertel 1902:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.122     albertel 1903:     my $nav_control=&nav_control_js();
1.175     albertel 1904: 
1.306     raeburn  1905:     my $dc_popup_cid;
                   1906:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   1907:                         $env{'course.'.$env{'request.course.id'}.
                   1908:                                  '.domain'}.'/'})) {
                   1909:         $dc_popup_cid = &dc_popup_js();
                   1910:     }
                   1911: 
1.175     albertel 1912:     my $start_page_annotate = 
                   1913:         &Apache::loncommon::start_page('Annotator',undef,
                   1914: 				       {'only_body' => 1,
                   1915: 					'js_ready'  => 1,
                   1916: 					'bgcolor'   => '#BBBBBB',
                   1917: 					'add_entries' => {
                   1918: 					    'onload' => 'javascript:document.goannotate.submit();'}});
                   1919: 
1.205     albertel 1920:     my $end_page_annotate = 
                   1921:         &Apache::loncommon::end_page({'js_ready' => 1});
                   1922: 
1.175     albertel 1923:     my $start_page_bookmark = 
                   1924:         &Apache::loncommon::start_page('Bookmarks',undef,
                   1925: 				       {'only_body' => 1,
                   1926: 					'js_ready'  => 1,
                   1927: 					'bgcolor'   => '#BBBBBB',});
                   1928: 
1.205     albertel 1929:     my $end_page_bookmark = 
1.175     albertel 1930:         &Apache::loncommon::end_page({'js_ready' => 1});
                   1931: 
1.42      www      1932: return (<<ENDUTILITY)
                   1933: 
                   1934:     var currentURL="$currenturl";
                   1935:     var reloadURL="$currenturl";
                   1936:     var currentSymb="$currentsymb";
                   1937: 
1.114     albertel 1938: $nav_control
1.306     raeburn  1939: $dc_popup_cid
1.114     albertel 1940: 
1.309.2.1  raeburn  1941: $gcimenujs
                   1942: 
1.42      www      1943: function go(url) {
                   1944:    if (url!='' && url!= null) {
                   1945:        currentURL = null;
                   1946:        currentSymb= null;
                   1947:        window.location.href=url;
                   1948:    }
                   1949: }
                   1950: 
1.297     raeburn  1951: function gotop(url) {
                   1952:     if (url!='' && url!= null) {
                   1953:         top.location.href = url;
                   1954:     }
                   1955: }
                   1956: 
1.42      www      1957: function gopost(url,postdata) {
                   1958:    if (url!='') {
                   1959:       this.document.server.action=url;
                   1960:       this.document.server.postdata.value=postdata;
                   1961:       this.document.server.command.value='';
                   1962:       this.document.server.url.value='';
                   1963:       this.document.server.symb.value='';
                   1964:       this.document.server.submit();
                   1965:    }
                   1966: }
                   1967: 
                   1968: function gocmd(url,cmd) {
                   1969:    if (url!='') {
                   1970:       this.document.server.action=url;
                   1971:       this.document.server.postdata.value='';
                   1972:       this.document.server.command.value=cmd;
                   1973:       this.document.server.url.value=currentURL;
                   1974:       this.document.server.symb.value=currentSymb;
                   1975:       this.document.server.submit();
                   1976:    }
1.57      www      1977: }
                   1978: 
1.121     raeburn  1979: function gocstr(url,filename) {
                   1980:     if (url == '/adm/cfile?action=delete') {
                   1981:         this.document.cstrdelete.filename.value = filename
                   1982:         this.document.cstrdelete.submit();
                   1983:         return;
                   1984:     }
1.137     raeburn  1985:     if (url == '/adm/printout') {
                   1986:         this.document.cstrprint.postdata.value = filename
                   1987:         this.document.cstrprint.curseed.value = 0;
                   1988:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  1989:         if (this.document.lonhomework) {
                   1990:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   1991:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   1992:             }
                   1993:             if (this.document.lonhomework.problemtype) {
1.164     albertel 1994: 		if (this.document.lonhomework.problemtype.value) {
                   1995: 		    this.document.cstrprint.problemtype.value = 
                   1996: 			this.document.lonhomework.problemtype.value;
                   1997: 		} else if (this.document.lonhomework.problemtype.options) {
                   1998: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   1999: 			if (this.document.lonhomework.problemtype.options[i].selected) {
                   2000: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   2001: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   2002: 				}
                   2003: 			}
                   2004: 		    }
                   2005: 		}
                   2006: 	    }
                   2007: 	}
1.137     raeburn  2008:         this.document.cstrprint.submit();
                   2009:         return;
                   2010:     }
1.121     raeburn  2011:     if (url !='') {
                   2012:         this.document.constspace.filename.value = filename;
                   2013:         this.document.constspace.action = url;
                   2014:         this.document.constspace.submit();
                   2015:     }
                   2016: }
                   2017: 
1.131     raeburn  2018: function golist(url) {
                   2019:    if (url!='' && url!= null) {
                   2020:        currentURL = null;
                   2021:        currentSymb= null;
                   2022:        top.location.href=url;
                   2023:    }
                   2024: }
                   2025: 
                   2026: 
1.121     raeburn  2027: 
1.57      www      2028: function catalog_info() {
1.102     albertel 2029:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.57      www      2030: }
                   2031: 
                   2032: function chat_win() {
1.290     raeburn  2033:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42      www      2034: }
1.169     raeburn  2035: 
                   2036: function group_chat(group) {
                   2037:    var url = '/adm/groupchat?group='+group;
                   2038:    var winName = 'LONchat_'+group;
                   2039:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
                   2040: }
1.175     albertel 2041: 
                   2042: function edit_bookmarks() {
                   2043:    go('');
                   2044:    w_BookmarkPal_flag=1;
                   2045:    bookmarkpal=window.open("/adm/bookmarks",
                   2046:                "BookmarkPal", "width=400,height=505,scrollbars=0");
                   2047: }
                   2048: 
                   2049: function annotate() {
                   2050:    w_Annotator_flag=1;
                   2051:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
                   2052:    annotator.document.write(
                   2053:    '$start_page_annotate'
                   2054:   +"<form name='goannotate' target='Annotator' method='post' "
                   2055:   +"action='/adm/annotations'>"
1.217     albertel 2056:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181     albertel 2057:   +"<\\/form>"
1.205     albertel 2058:   +'$end_page_annotate');
1.175     albertel 2059:    annotator.document.close();
                   2060: }
                   2061: 
                   2062: function set_bookmark() {
                   2063:    go('');
                   2064:    clienttitle=document.title;
                   2065:    clienthref=location.pathname;
                   2066:    w_bmquery_flag=1;
                   2067:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
                   2068:    bmquery.document.write(
                   2069:    '$start_page_bookmark'
1.260     bisitz   2070:    +'<center><form method="post"'
                   2071:    +' name="newlink" action="/adm/bookmarks" target="bmquery" '
                   2072:    +'> <table width="340" height="150" '
                   2073:    +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
                   2074:    +'type="text" name="title" size="45" value="'+clienttitle+'" />'
                   2075:    +'<br />Address:<br /><input type="text" name="address" size="45" '
                   2076:    +'value="'+clienthref+'" /><br /><center><input type="submit" '
                   2077:    +'value="Save" /> <input type="button" value="Close" '
                   2078:    +'onclick="javascript:window.close();" /></center></td>'
                   2079:    +'</tr></table></form></center>'
1.205     albertel 2080:    +'$end_page_bookmark' );
1.175     albertel 2081:    bmquery.document.close();
                   2082: }
                   2083: 
1.42      www      2084: ENDUTILITY
                   2085: }
                   2086: 
                   2087: sub serverform {
                   2088:     return(<<ENDSERVERFORM);
1.181     albertel 2089: <form name="server" action="/adm/logout" method="post" target="_top">
1.42      www      2090: <input type="hidden" name="postdata" value="none" />
                   2091: <input type="hidden" name="command" value="none" />
                   2092: <input type="hidden" name="url" value="none" />
                   2093: <input type="hidden" name="symb" value="none" />
                   2094: </form>
                   2095: ENDSERVERFORM
                   2096: }
1.113     albertel 2097: 
1.121     raeburn  2098: sub constspaceform {
                   2099:     return(<<ENDCONSTSPACEFORM);
1.181     albertel 2100: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121     raeburn  2101: <input type="hidden" name="filename" value="" />
                   2102: </form>
1.181     albertel 2103: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121     raeburn  2104: <input type="hidden" name="action" value="delete" /> 
                   2105: <input type="hidden" name="filename" value="" />
                   2106: </form>
1.181     albertel 2107: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137     raeburn  2108: <input type="hidden" name="postdata" value="" />
                   2109: <input type="hidden" name="curseed" value="" />
                   2110: <input type="hidden" name="problemtype" value="" />
                   2111: </form>
                   2112: 
1.121     raeburn  2113: ENDCONSTSPACEFORM
                   2114: }
                   2115: 
                   2116: 
1.113     albertel 2117: sub get_nav_status {
                   2118:     my $navstatus="swmenu.w_loncapanav_flag=";
1.152     albertel 2119:     if ($env{'environment.remotenavmap'} eq 'on') {
1.113     albertel 2120: 	$navstatus.="1";
                   2121:     } else {
                   2122: 	$navstatus.="-1";
                   2123:     }
                   2124:     return $navstatus;
                   2125: }
                   2126: 
1.220     raeburn  2127: sub hidden_button_check {
                   2128:     my $hidden;
                   2129:     if ($env{'request.course.id'} eq '') {
                   2130:         return;
                   2131:     }
                   2132:     if ($env{'request.role.adv'}) {
1.309.2.6  raeburn  2133:         unless (&Apache::loncommon::needs_gci_custom()) {
                   2134:             return;
                   2135:         }
1.220     raeburn  2136:     }
1.232     raeburn  2137:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
                   2138:     return $buttonshide; 
1.220     raeburn  2139: }
1.184     raeburn  2140: 
1.235     raeburn  2141: sub roles_selector {
                   2142:     my ($cdom,$cnum) = @_;
1.298     raeburn  2143:     my $crstype = &Apache::loncommon::course_type();
1.235     raeburn  2144:     my $now = time;
1.262     raeburn  2145:     my (%courseroles,%seccount);
1.235     raeburn  2146:     my $is_cc;
                   2147:     my $role_selector;
1.298     raeburn  2148:     my $ccrole;
                   2149:     if ($crstype eq 'Community') {
                   2150:         $ccrole = 'co';
                   2151:     } else {
                   2152:         $ccrole = 'cc';
                   2153:     } 
                   2154:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
                   2155:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235     raeburn  2156:         
                   2157:         if ((($start) && ($start<0)) || 
                   2158:             (($end) && ($end<$now))  ||
                   2159:             (($start) && ($now<$start))) {
                   2160:             $is_cc = 0;
                   2161:         } else {
                   2162:             $is_cc = 1;
                   2163:         }
                   2164:     }
                   2165:     if ($is_cc) {
1.264     raeburn  2166:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
1.235     raeburn  2167:     } else {
1.262     raeburn  2168:         my %gotnosection;
1.235     raeburn  2169:         foreach my $item (keys(%env)) {
1.239     raeburn  2170:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235     raeburn  2171:                 my $role = $1;
                   2172:                 my $sec = $2;
                   2173:                 next if ($role eq 'gr');
                   2174:                 my ($start,$end) = split(/\./,$env{$item});
                   2175:                 next if (($start && $start > $now) || ($end && $end < $now));
                   2176:                 if ($sec eq '') {
1.239     raeburn  2177:                     if (!$gotnosection{$role}) {
                   2178:                         $seccount{$role} ++;
                   2179:                         $gotnosection{$role} = 1;
                   2180:                     }
1.235     raeburn  2181:                 }
                   2182:                 if (ref($courseroles{$role}) eq 'ARRAY') {
1.239     raeburn  2183:                     if ($sec ne '') {
1.264     raeburn  2184:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239     raeburn  2185:                             push(@{$courseroles{$role}},$sec);
                   2186:                             $seccount{$role} ++;
                   2187:                         }
                   2188:                     }
                   2189:                 } else {
                   2190:                     @{$courseroles{$role}} = ();
                   2191:                     if ($sec ne '') {
                   2192:                         $seccount{$role} ++;
1.235     raeburn  2193:                         push(@{$courseroles{$role}},$sec);
                   2194:                     }
                   2195:                 }
                   2196:             }
                   2197:         }
                   2198:     }
1.286     raeburn  2199:     my $switchtext;
                   2200:     if ($crstype eq 'Community') {
                   2201:         $switchtext = &mt('Switch community role to...')
                   2202:     } else {
                   2203:         $switchtext = &mt('Switch course role to...')
                   2204:     }
1.298     raeburn  2205:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.235     raeburn  2206:     if (keys(%courseroles) > 1) {
1.239     raeburn  2207:         $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
1.235     raeburn  2208:         $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
                   2209:                           <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1.286     raeburn  2210:         $role_selector .= '<option value="">'.$switchtext.'</option>';
1.235     raeburn  2211:         foreach my $role (@roles_order) {
                   2212:             if (defined($courseroles{$role})) {
1.298     raeburn  2213:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>'; 
1.235     raeburn  2214:             }
                   2215:         }
                   2216:         foreach my $role (sort(keys(%courseroles))) {
                   2217:             if ($role =~ /^cr/) {
                   2218:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
                   2219:             }
                   2220:         }
                   2221:         $role_selector .= '</select>'."\n".
                   2222:                '<input type="hidden" name="destinationurl" value="'.
1.282     amueller 2223:                &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n".
1.235     raeburn  2224:                '<input type="hidden" name="gotorole" value="1" />'."\n".
                   2225:                '<input type="hidden" name="selectrole" value="" />'."\n".
                   2226:                '<input type="hidden" name="switch" value="1" />'."\n".
                   2227:                '</form>';
                   2228:     }
                   2229:     return $role_selector;
                   2230: }
                   2231: 
1.262     raeburn  2232: sub get_all_courseroles {
                   2233:     my ($cdom,$cnum,$courseroles,$seccount) = @_;
                   2234:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
                   2235:         return;
                   2236:     }
                   2237:     my ($result,$cached) = 
                   2238:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
                   2239:     if (defined($cached)) {
                   2240:         if (ref($result) eq 'HASH') {
                   2241:             if ((ref($result->{'roles'}) eq 'HASH') && 
                   2242:                 (ref($result->{'seccount'}) eq 'HASH')) {
                   2243:                 %{$courseroles} = %{$result->{'roles'}};
                   2244:                 %{$seccount} = %{$result->{'seccount'}};
                   2245:                 return;
                   2246:             }
                   2247:         }
                   2248:     }
                   2249:     my %gotnosection;
                   2250:     my %adv_roles =
                   2251:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
                   2252:     foreach my $role (keys(%adv_roles)) {
                   2253:         my ($urole,$usec) = split(/:/,$role);
                   2254:         if (!$gotnosection{$urole}) {
                   2255:             $seccount->{$urole} ++;
                   2256:             $gotnosection{$urole} = 1;
                   2257:         }
                   2258:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
                   2259:             if ($usec ne '') {
                   2260:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
                   2261:                     push(@{$courseroles->{$urole}},$usec);
                   2262:                     $seccount->{$urole} ++;
                   2263:                 }
                   2264:             }
                   2265:         } else {
                   2266:             @{$courseroles->{$urole}} = ();
                   2267:             if ($usec ne '') {
                   2268:                 $seccount->{$urole} ++;
                   2269:                 push(@{$courseroles->{$urole}},$usec);
                   2270:             }
                   2271:         }
                   2272:     }
                   2273:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
                   2274:     @{$courseroles->{'st'}} = ();
                   2275:     if (keys(%sections_count) > 0) {
                   2276:         push(@{$courseroles->{'st'}},keys(%sections_count));
                   2277:         $seccount->{'st'} = scalar(keys(%sections_count)); 
                   2278:     }
                   2279:     my $rolehash = {
                   2280:                      'roles'    => $courseroles,
                   2281:                      'seccount' => $seccount,
                   2282:                    };
                   2283:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
                   2284:     return;
                   2285: }
                   2286: 
1.235     raeburn  2287: sub jump_to_role {
1.239     raeburn  2288:     my ($cdom,$cnum,$seccount,$courseroles) = @_;
                   2289:     my %lt = &Apache::lonlocal::texthash(
                   2290:                 this => 'This role has section(s) associated with it.',
                   2291:                 ente => 'Enter a specific section.',
                   2292:                 orlb => 'Enter a specific section, or leave blank for no section.',
                   2293:                 avai => 'Available sections are:',
                   2294:                 youe => 'You entered an invalid section choice:',
                   2295:                 plst => 'Please try again',
                   2296:     );
                   2297:     my $js;
                   2298:     if (ref($courseroles) eq 'HASH') {
                   2299:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
                   2300:               '    var numsec = new Array();'."\n".
                   2301:               '    var rolesections = new Array();'."\n".
                   2302:               '    var rolenames = new Array();'."\n".
                   2303:               '    var roleseclist = new Array();'."\n";
                   2304:         my @items = keys(%{$courseroles});
                   2305:         for (my $i=0; $i<@items; $i++) {
                   2306:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
                   2307:             my ($secs,$secstr);
                   2308:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
                   2309:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
                   2310:                 $secs = join('","',@sections);
                   2311:                 $secstr = join(', ',@sections);
                   2312:             }
                   2313:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
                   2314:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
                   2315:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
                   2316:         }
                   2317:     }
1.273     droeschl 2318:     return <<"END";
1.235     raeburn  2319: <script type="text/javascript">
1.273     droeschl 2320: //<![CDATA[
1.235     raeburn  2321: function adhocRole(roleitem) {
1.239     raeburn  2322:     $js
1.235     raeburn  2323:     var newrole =  document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
                   2324:     if (newrole == '') {
                   2325:         return; 
                   2326:     } 
1.239     raeburn  2327:     var fullrole = newrole+'./$cdom/$cnum';
                   2328:     var selidx = '';
                   2329:     for (var i=0; i<rolenames.length; i++) {
                   2330:         if (rolenames[i] == newrole) {
                   2331:             selidx = i;
                   2332:         }
                   2333:     }
                   2334:     var secok = 1;
                   2335:     var secchoice = '';
                   2336:     if (selidx >= 0) {
                   2337:         if (numsec[selidx] > 1) {
                   2338:             secok = 0;
                   2339:             var numrolesec = rolesections[selidx].length;
                   2340:             var msgidx = numsec[selidx] - numrolesec;
1.309.2.17! raeburn  2341:             secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239     raeburn  2342:             if (secchoice == '') {
                   2343:                 if (msgidx > 0) {
                   2344:                     secok = 1;
                   2345:                 }
                   2346:             } else {
                   2347:                 for (var j=0; j<rolesections[selidx].length; j++) {
                   2348:                     if (rolesections[selidx][j] == secchoice) {
                   2349:                         secok = 1;
                   2350:                     }
                   2351:                 }
                   2352:             }
                   2353:         } else {
                   2354:             if (rolesections[selidx].length == 1) {
                   2355:                 secchoice = rolesections[selidx][0];
                   2356:             }
                   2357:         }
                   2358:     }
                   2359:     if (secok == 1) {
                   2360:         if (secchoice != '') {
                   2361:             fullrole += '/'+secchoice;
                   2362:         }
                   2363:     } else {
                   2364:         document.rolechooser.elements[roleitem].selectedIndex = 0;
                   2365:         if (secchoice != null) {
                   2366:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
                   2367:         }
                   2368:         return;
                   2369:     }
                   2370:     if (fullrole == "$env{'request.role'}") {
1.235     raeburn  2371:         return;
                   2372:     }
                   2373:     itemid = retrieveIndex('gotorole');
                   2374:     if (itemid != -1) {
1.239     raeburn  2375:         document.rolechooser.elements[itemid].name = fullrole;
1.235     raeburn  2376:     }
1.239     raeburn  2377:     document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1.235     raeburn  2378:     document.rolechooser.selectrole.value = '1';
                   2379:     document.rolechooser.submit();
                   2380:     return;
                   2381: }
                   2382: 
                   2383: function retrieveIndex(item) {
                   2384:     for (var i=0;i<document.rolechooser.elements.length;i++) {
                   2385:         if (document.rolechooser.elements[i].name == item) {
                   2386:             return i;
                   2387:         }
                   2388:     }
                   2389:     return -1;
                   2390: }
1.273     droeschl 2391: // ]]>
1.235     raeburn  2392: </script>
                   2393: END
                   2394: }
                   2395: 
                   2396: 
1.2       www      2397: # ================================================================ Main Program
                   2398: 
1.16      harris41 2399: BEGIN {
1.166     albertel 2400:     if (! defined($readdesk)) {
1.283     droeschl 2401:         {
                   2402:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   2403:             if ( CORE::open( my $config,"<$tabfile") ) {
                   2404:                 while (my $configline=<$config>) {
                   2405:                     $configline=(split(/\#/,$configline))[0];
                   2406:                     $configline=~s/^\s+//;
                   2407:                     chomp($configline);
1.209     www      2408:                     if ($configline=~/^cat\:/) {
1.283     droeschl 2409:                         my @entries=split(/\:/,$configline);
                   2410:                         $category_positions{$entries[2]}=$entries[1];
                   2411:                         $category_names{$entries[2]}=$entries[3];
                   2412:                     } elsif ($configline=~/^prim\:/) {
                   2413:                         my @entries = (split(/\:/, $configline))[1..5];
                   2414:                         push @primary_menu, \@entries;
                   2415:                     } elsif ($configline=~/^scnd\:/) {
                   2416:                         my @entries = (split(/\:/, $configline))[1..5];
                   2417:                         push @secondary_menu, \@entries; 
                   2418:                     } elsif ($configline) {
                   2419:                         push(@desklines,$configline);
                   2420:                     }
                   2421:                 }
                   2422:                 CORE::close($config);
                   2423:             }
                   2424:         }
                   2425:         $readdesk='done';
1.2       www      2426:     }
                   2427: }
1.30      www      2428: 
1.1       www      2429: 1;
                   2430: __END__
                   2431: 

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