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

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

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