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

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

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