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

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

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