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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.430   ! raeburn     4: # $Id: lonmenu.pm,v 1.429 2014/09/22 01:02:52 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: #
                     29: 
1.244     jms        30: =head1 NAME
                     31: 
                     32: Apache::lonmenu
                     33: 
                     34: =head1 SYNOPSIS
                     35: 
1.371     raeburn    36: Loads contents of /home/httpd/lonTabs/mydesk.tab, 
                     37: used to generate inline menu, and Main Menu page. 
1.244     jms        38: 
                     39: This is part of the LearningOnline Network with CAPA project
                     40: described at http://www.lon-capa.org.
                     41: 
1.314     droeschl   42: =head1 GLOBAL VARIABLES
                     43: 
                     44: =over
                     45: 
                     46: =item @desklines
                     47: 
                     48: Each element of this array contains a line of mydesk.tab that doesn't start with
                     49: cat, prim or scnd. 
                     50: It gets filled in the BEGIN block of this module.
                     51: 
                     52: =item %category_names
                     53: 
                     54: The keys of this hash are the abbreviations used in mydesk.tab in those lines that 
                     55: start with cat, the values are strings representing titles. 
                     56: It gets filled in the BEGIN block of this module.
                     57: 
                     58: =item %category_members
                     59: 
                     60: TODO 
                     61: 
                     62: =item %category_positions
                     63: 
                     64: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
                     65: start with cat, its values are position vectors (column, row). 
                     66: It gets filled in the BEGIN block of this module.
                     67: 
                     68: =item $readdesk
                     69: 
                     70: Indicates that mydesk.tab has been read. 
                     71: It is set to 'done' in the BEGIN block of this module.
                     72: 
                     73: =item @primary_menu
                     74: 
                     75: The elements of this array reference arrays that are made up of the components
1.371     raeburn    76: of those lines of mydesk.tab that start with prim:.
1.314     droeschl   77: It is used by primary_menu() to generate the corresponding menu.
                     78: It gets filled in the BEGIN block of this module.
                     79: 
1.371     raeburn    80: =item %primary_sub_menu
                     81: 
                     82: The keys of this hash reference are the names of items in the primary_menu array 
                     83: which have sub-menus.  For each key, the corresponding value is a reference to
                     84: an array containing components extracted from lines in mydesk.tab which begin
                     85: with primsub:.
                     86: This hash, which is used by primary_menu to generate sub-menus, is populated in
                     87: the BEGIN block.
                     88: 
1.314     droeschl   89: =item @secondary_menu
                     90: 
                     91: The elements of this array reference arrays that are made up of the components
                     92: of those lines of mydesk.tab that start with scnd.
                     93: It is used by secondary_menu() to generate the corresponding menu.
                     94: It gets filled in the BEGIN block of this module.
                     95: 
                     96: =back
                     97: 
1.244     jms        98: =head1 SUBROUTINES
                     99: 
                    100: =over
                    101: 
1.314     droeschl  102: =item prep_menuitems(\@menuitem)
                    103: 
                    104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and 
                    105: secondary_menu().
                    106: 
                    107: =item primary_menu()
                    108: 
1.415     raeburn   109: This routine evaluates @primary_menu and returns a two item array, 
                    110: with the array elements containing XHTML for the left and right sides of 
                    111: the menu that contains the following links: About, Message, Roles, Help, Logout 
1.314     droeschl  112: @primary_menu is filled within the BEGIN block of this module with 
1.415     raeburn   113: entries from mydesk.tab
1.314     droeschl  114: 
                    115: =item secondary_menu()
                    116: 
                    117: Same as primary_menu() but operates on @secondary_menu.
                    118: 
1.375     raeburn   119: =item create_submenu()
                    120: 
                    121: Creates XHTML for unordered list of sub-menu items which belong to a 
                    122: particular top-level menu item. Uses hover pseudo class in css to display
                    123: dropdown list when mouse hovers over top-level item. Support for IE6 
                    124: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
                    125: level item, which employs jQuery to handle behavior on mouseover.
                    126: 
                    127: Inputs: 4 - (a) link and (b) target for anchor href in top level item,
                    128:             (c) title for text wrapped by anchor tag in top level item.
                    129:             (d) reference to array of arrays of sub-menu items.
                    130: 
1.244     jms       131: =item innerregister()
                    132: 
1.320     droeschl  133: This gets called in order to register a URL in the body of the document
1.244     jms       134: 
                    135: =item clear()
                    136: 
                    137: =item switch()
                    138: 
                    139: Switch a button or create a link
                    140: Switch acts on the javascript that is executed when a button is clicked.  
                    141: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
                    142: 
                    143: =item secondlevel()
                    144: 
                    145: =item openmenu()
                    146: 
                    147: =item inlinemenu()
                    148: 
                    149: =item rawconfig()
                    150: 
                    151: =item utilityfunctions()
                    152: 
1.371     raeburn   153: Output from this routine is a number of javascript functions called by
                    154: items in the inline menu, and in some cases items in the Main Menu page. 
                    155: 
1.244     jms       156: =item serverform()
                    157: 
                    158: =item constspaceform()
                    159: 
                    160: =item get_nav_status()
                    161: 
                    162: =item hidden_button_check()
                    163: 
                    164: =item roles_selector()
                    165: 
                    166: =item jump_to_role()
                    167: 
                    168: =back
                    169: 
                    170: =cut
                    171: 
1.1       www       172: package Apache::lonmenu;
                    173: 
                    174: use strict;
1.152     albertel  175: use Apache::lonnet;
1.47      matthew   176: use Apache::lonhtmlcommon();
1.115     albertel  177: use Apache::loncommon();
1.127     albertel  178: use Apache::lonenc();
1.88      www       179: use Apache::lonlocal;
1.361     raeburn   180: use Apache::lonmsg();
1.207     foxr      181: use LONCAPA qw(:DEFAULT :match);
1.282     amueller  182: use HTML::Entities();
1.346     wenzelju  183: use Apache::lonwishlist();
1.88      www       184: 
1.283     droeschl  185: use vars qw(@desklines %category_names %category_members %category_positions 
1.371     raeburn   186:             $readdesk @primary_menu %primary_submenu @secondary_menu);
1.88      www       187: 
1.56      www       188: my @inlineremote;
1.38      www       189: 
1.283     droeschl  190: sub prep_menuitem {
1.291     raeburn   191:     my ($menuitem) = @_;
                    192:     return '' unless(ref($menuitem) eq 'ARRAY');
1.283     droeschl  193:     my $link;
                    194:     if ($$menuitem[1]) { # graphical Link
                    195:         $link = "<img class=\"LC_noBorder\""
1.291     raeburn   196:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
                    197:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283     droeschl  198:     } else {             # textual Link
1.291     raeburn   199:         $link = &mt($$menuitem[3]);
                    200:     }
1.316     droeschl  201:     return '<li><a' 
                    202:            # highlighting for new messages
                    203:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
1.325     droeschl  204:            . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
1.283     droeschl  205: }
                    206: 
1.415     raeburn   207: # primary_menu() evaluates @primary_menu and returns a two item array,
                    208: # with the array elements containing XHTML for the left and right sides of 
                    209: # the menu that contains the following links:
                    210: # Personal, About, Message, Roles, Help, Logout
1.283     droeschl  211: # @primary_menu is filled within the BEGIN block of this module with 
                    212: # entries from mydesk.tab
                    213: sub primary_menu {
1.415     raeburn   214:     my (%menu);
1.283     droeschl  215:     # each element of @primary contains following array:
1.415     raeburn   216:     # (link url, icon path, alt text, link text, condition, position)
1.319     raeburn   217:     my $public;
                    218:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                    219:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
                    220:         $public = 1;
                    221:     }
1.283     droeschl  222:     foreach my $menuitem (@primary_menu) {
                    223:         # evaluate conditions 
1.296     droeschl  224:         next if    ref($menuitem)       ne 'ARRAY';    #
1.283     droeschl  225:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
1.291     raeburn   226:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
1.283     droeschl  227:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
1.291     raeburn   228:                 && !&Apache::lonmsg::mynewmail();      # 
1.319     raeburn   229:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
                    230:                 && $public;                            ##who should not see all
                    231:                                                        ##links
1.283     droeschl  232:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
1.319     raeburn   233:                 && !$public;                           # only visible to public
                    234:                                                        # users
1.283     droeschl  235:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
1.291     raeburn   236:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
1.283     droeschl  237:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
1.291     raeburn   238:                 && !&Apache::loncommon::show_course(); ##
                    239:         
1.371     raeburn   240:         my $title = $menuitem->[3];
1.415     raeburn   241:         my $position = $menuitem->[5];
                    242:         if ($position eq '') {
                    243:             $position = 'right';
                    244:         }
1.371     raeburn   245:         if (defined($primary_submenu{$title})) {
1.375     raeburn   246:             my ($link,$target);
1.371     raeburn   247:             if ($menuitem->[0] ne '') {
                    248:                 $link = $menuitem->[0];
                    249:                 $target = '_top';
                    250:             } else {
                    251:                 $link = '#';
                    252:             }
1.375     raeburn   253:             my @primsub;
1.371     raeburn   254:             if (ref($primary_submenu{$title}) eq 'ARRAY') {
1.375     raeburn   255:                 foreach my $item (@{$primary_submenu{$title}}) {
1.383     raeburn   256:                     next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
1.375     raeburn   257:                     next if ((($item->[2] eq 'portfolio') ||
                    258:                              ($item->[2] eq 'blog')) &&
                    259:                              (!&Apache::lonnet::usertools_access('','',$item->[2],
                    260:                                                            undef,'tools')));
                    261:                     push(@primsub,$item);
                    262:                 }
                    263:                 if (@primsub > 0) {
1.419     bisitz    264:                     $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
1.375     raeburn   265:                 } elsif ($link) {
1.415     raeburn   266:                     $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
1.371     raeburn   267:                 }
                    268:             }
                    269:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.340     raeburn   270:             if ($public) {
                    271:                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                    272:                 my $defdom = &Apache::lonnet::default_login_domain();
                    273:                 my $to = &Apache::loncommon::build_recipient_list(undef,
                    274:                                                                   'helpdeskmail',
                    275:                                                                   $defdom,$origmail);
                    276:                 if ($to ne '') {
1.415     raeburn   277:                     $menu{$position} .= &prep_menuitem($menuitem); 
1.340     raeburn   278:                 }
                    279:             } else {
1.415     raeburn   280:                 $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.340     raeburn   281:             }
1.283     droeschl  282:         } else {
1.415     raeburn   283:             $menu{$position} .= prep_menuitem($menuitem);
1.283     droeschl  284:         }
1.291     raeburn   285:     }
1.423     raeburn   286:     my @output = ('','');
                    287:     if ($menu{'left'} ne '') {
                    288:         $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
                    289:     }
                    290:     if ($menu{'right'} ne '') {
                    291:         $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
                    292:     }
                    293:     return @output;
1.283     droeschl  294: }
                    295: 
1.329     droeschl  296: #returns hashref {user=>'',dom=>''} containing:
                    297: #   own name, domain if user is au
                    298: #   name, domain of parent author if user is ca or aa
                    299: #empty return if user is not an author or not on homeserver
                    300: #
                    301: #TODO this should probably be moved somewhere more central
                    302: #since it can be used by different parts of the system
                    303: sub getauthor{
                    304:     return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
                    305: 
                    306:                         #co- or assistent author?
                    307:     my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
                    308:                        ? ($1, $2) #domain, username of the parent author
                    309:                        : @env{ ('request.role.domain', 'user.name') }; #own domain, username
                    310: 
                    311:     # current server == home server?
                    312:     my $home =  &Apache::lonnet::homeserver($user,$dom);
                    313:     foreach (&Apache::lonnet::current_machine_ids()){
                    314:         return {user => $user, dom => $dom} if $_ eq $home;
                    315:     }
                    316: 
                    317:     # if wrong server
                    318:     return;
                    319: }
1.283     droeschl  320: 
                    321: sub secondary_menu {
1.421     raeburn   322:     my ($httphost) = @_;
1.283     droeschl  323:     my $menu;
                    324: 
1.286     raeburn   325:     my $crstype = &Apache::loncommon::course_type();
1.327     droeschl  326:     my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'} 
                    327:                                                ? "/$env{'request.course.sec'}"
                    328:                                                : '');
                    329:     my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
1.376     raeburn   330:     my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
1.418     raeburn   331:     if ($canviewroster eq 'disabled') {
                    332:         undef($canviewroster);
                    333:     }
1.327     droeschl  334:     my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec); 
                    335:     my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec); 
                    336:     my $canviewwnew   = &Apache::lonnet::allowed('whn', $crs_sec); 
1.341     www       337:     my $canmodpara    = &Apache::lonnet::allowed('opa', $crs_sec);
1.343     www       338:     my $canvgr        = &Apache::lonnet::allowed('vgr', $crs_sec);
                    339:     my $canmgr        = &Apache::lonnet::allowed('mgr', $crs_sec); 
                    340:     my $author        = &getauthor();
1.327     droeschl  341: 
1.417     raeburn   342:     my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv);
1.413     raeburn   343:     if ($env{'request.course.id'}) {
                    344:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    345:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    346:         if ($canedit) {
                    347:             $showsyllabus = 1;
                    348:             $showfeeds = 1;
                    349:         } else {
1.414     raeburn   350:             unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
                    351:                 if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
                    352:                     ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
                    353:                     ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
                    354:                     ($env{'request.course.syllabustime'})) {
                    355:                     $showsyllabus = 1;
                    356:                 }
                    357:             }
                    358:             if ($env{'request.course.feeds'}) {
                    359:                 $showfeeds = 1;
1.413     raeburn   360:             }
                    361:         }
1.417     raeburn   362:         unless ($canmgr) {
                    363:             my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
                    364:             if (keys(%slots) > 0) {
                    365:                 $showresv = 1;
                    366:             }
                    367:         }
1.413     raeburn   368:     }
                    369: 
1.404     raeburn   370:     my ($canmodifycoauthor); 
                    371:     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
                    372:         my $extent = "$env{'user.domain'}/$env{'user.name'}";
                    373:         if ((&Apache::lonnet::allowed('cca',$extent)) ||
                    374:             (&Apache::lonnet::allowed('caa',$extent))) {
                    375:             $canmodifycoauthor = 1;
                    376:         }
                    377:     }
                    378: 
1.286     raeburn   379:     my %groups = &Apache::lonnet::get_active_groups(
                    380:                      $env{'user.domain'}, $env{'user.name'},
                    381:                      $env{'course.' . $env{'request.course.id'} . '.domain'},
                    382:                      $env{'course.' . $env{'request.course.id'} . '.num'});
1.327     droeschl  383: 
1.401     raeburn   384:     my ($roleswitcher_js,$roleswitcher_form);
                    385: 
1.283     droeschl  386:     foreach my $menuitem (@secondary_menu) {
                    387:         # evaluate conditions 
1.296     droeschl  388:         next if    ref($menuitem)  ne 'ARRAY';
1.283     droeschl  389:         next if    $$menuitem[4]   ne 'always'
1.404     raeburn   390:                 && ($$menuitem[4]   ne 'author' && $$menuitem[4] ne 'cca')
1.283     droeschl  391:                 && !$env{'request.course.id'};
                    392:         next if    $$menuitem[4]   =~ /^mdc/
1.286     raeburn   393:                 && !$canedit;
1.341     www       394:         next if    $$menuitem[4]  eq 'nvgr'
                    395:                 && $canvgr;
                    396:         next if    $$menuitem[4]  eq 'vgr'
                    397:                 && !$canvgr;
1.327     droeschl  398:         next if    $$menuitem[4]   eq 'cst'
                    399:                 && !$canmodifyuser;
1.343     www       400:         next if    $$menuitem[4]   eq 'ncst'
1.376     raeburn   401:                 && ($canmodifyuser || !$canviewroster);
1.343     www       402:         next if    $$menuitem[4]   eq 'mgr'
                    403:                 && !$canmgr;
1.417     raeburn   404:         next if    $$menuitem[4]   eq 'showresv'
                    405:                 && !$showresv;
1.327     droeschl  406:         next if    $$menuitem[4]   eq 'whn'
                    407:                 && !$canviewwnew;
                    408:         next if    $$menuitem[4]   eq 'opa'
                    409:                 && !$canmodpara;
1.283     droeschl  410:         next if    $$menuitem[4]   =~ /showgroups$/
1.300     raeburn   411:                 && !$canviewgrps
1.286     raeburn   412:                 && !%groups;
1.413     raeburn   413:         next if    $$menuitem[4]   eq 'showsyllabus'
                    414:                 && !$showsyllabus;
                    415:         next if    $$menuitem[4]   eq 'showfeeds'
                    416:                 && !$showfeeds;
1.329     droeschl  417:         next if    $$menuitem[4]    eq 'author'
                    418:                 && !$author;
1.404     raeburn   419:         next if    $$menuitem[4]    eq 'cca'
                    420:                 && !$canmodifycoauthor;
1.283     droeschl  421: 
1.286     raeburn   422:         if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283     droeschl  423:             # special treatment for role selector
1.401     raeburn   424:             ($roleswitcher_js,$roleswitcher_form,my $switcher) =
                    425:                 &roles_selector(
1.283     droeschl  426:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
1.421     raeburn   427:                         $env{'course.' . $env{'request.course.id'} . '.num'},
                    428:                         $httphost
1.401     raeburn   429:                 );
                    430:             $menu .= $switcher;
1.296     droeschl  431:         } else {
1.414     raeburn   432:             if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
                    433:                 my $url = $$menuitem[0];
                    434:                 $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
                    435:                 if (&Apache::lonnet::is_on_map($url)) {
                    436:                     unless ($$menuitem[0] =~ /\?register=1/) {
                    437:                         $$menuitem[0] .= '?register=1';
                    438:                     }
                    439:                 } else {
                    440:                     $$menuitem[0] =~ s{\?register=1}{};
                    441:                 }
                    442:             }
1.296     droeschl  443:             $menu .= &prep_menuitem(\@$menuitem);
1.283     droeschl  444:         }
                    445:     }
                    446:     if ($menu =~ /\[url\].*\[symb\]/) {
1.291     raeburn   447:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
                    448:                              $env{'request.noversionuri'}));
1.283     droeschl  449: 
1.291     raeburn   450:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
                    451:                              $env{'request.symb'})); 
1.283     droeschl  452: 
                    453:         if (    $env{'request.state'} eq 'construct'
                    454:             and (   $env{'request.noversionuri'} eq '' 
                    455:                  || !defined($env{'request.noversionuri'}))) 
                    456:         {
1.359     raeburn   457:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                    458:             ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
1.291     raeburn   459:             $escurl  = &escape($escurl);
1.283     droeschl  460:         }    
                    461:         $menu =~ s/\[url\]/$escurl/g;
                    462:         $menu =~ s/\[symb\]/$escsymb/g;
                    463:     }
1.329     droeschl  464:     $menu =~ s/\[uname\]/$$author{user}/g;
                    465:     $menu =~ s/\[udom\]/$$author{dom}/g;
1.413     raeburn   466:     if ($showsyllabus || $showfeeds) {
                    467:         $menu =~ s/\[cnum\]/$cnum/g;
                    468:         $menu =~ s/\[cdom\]/$cdom/g;
                    469:     }
1.385     raeburn   470:     if ($menu) {
                    471:         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
                    472:     }
1.401     raeburn   473:     if ($roleswitcher_form) {
                    474:         $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
                    475:     }
1.385     raeburn   476:     return $menu;
1.283     droeschl  477: }
                    478: 
1.375     raeburn   479: sub create_submenu {
1.419     bisitz    480:     my ($link,$target,$title,$submenu,$translate) = @_;
1.375     raeburn   481:     return unless (ref($submenu) eq 'ARRAY');
1.379     raeburn   482:     my $disptarget;
                    483:     if ($target ne '') {
                    484:         $disptarget = ' target="'.$target.'"';
                    485:     }
1.415     raeburn   486:     my $name;
                    487:     if ($title eq 'Personal') {
                    488:         if ($env{'user.name'} && $env{'user.domain'}) {
                    489:             $name = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
                    490:         } else {
                    491:             $name = &mt($title);
                    492:         }
                    493:     } else {
                    494:         $name = &mt($title);
                    495:     }
1.375     raeburn   496:     my $menu = '<li class="LC_hoverable">'.
1.379     raeburn   497:                '<a href="'.$link.'"'.$disptarget.'>'.
1.415     raeburn   498:                '<span class="LC_nobreak">'.$name.
1.375     raeburn   499:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
                    500:                ' &#9660;</span></span></a>'.
                    501:                '<ul>';
                    502:     my $count = 0;
                    503:     my $numsub = scalar(@{$submenu});
                    504:     foreach my $item (@{$submenu}) {
                    505:         $count ++;
                    506:         if (ref($item) eq 'ARRAY') {
1.416     raeburn   507:             my $href = $item->[0];
                    508:             if ($href =~ /(aboutme|rss\.html)$/) {
                    509:                 next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
                    510:                 $href =~ s/\[domain\]/$env{'user.domain'}/g;
                    511:                 $href =~ s/\[user\]/$env{'user.name'}/g;
                    512:             }
1.375     raeburn   513:             my $borderbot;
                    514:             if ($count == $numsub) {
                    515:                 $borderbot = 'border-bottom:1px solid black;';
                    516:             }
1.426     raeburn   517:             unless (($href eq '') || ($href =~ /^\#/)) {
1.425     raeburn   518:                 $target = ' target="_top"';
                    519:             }
1.375     raeburn   520:             $menu .= '<li style="margin:0;padding:0;'.
1.425     raeburn   521:                      $borderbot.'"><a href="'.$href.'"'.$target.'>';
1.419     bisitz    522:             if ($translate) {
                    523:                 $menu .= &mt($item->[1]);
                    524:             } else {
                    525:                 $menu .= $item->[1];
                    526:             }
1.420     raeburn   527:             $menu .= '</a></li>';
1.375     raeburn   528:         }
                    529:     }
                    530:     $menu .= '</ul></li>';
                    531:     return $menu;
                    532: }
                    533: 
1.40      www       534: sub innerregister {
1.390     raeburn   535:     my ($forcereg,$bread_crumbs,$group) = @_;
1.152     albertel  536:     my $const_space = ($env{'request.state'} eq 'construct');
1.131     raeburn   537:     my $is_const_dir = 0;
1.120     raeburn   538: 
1.175     albertel  539:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40      www       540: 
1.174     albertel  541:     $env{'request.registered'} = 1;
1.40      www       542: 
1.177     albertel  543:     undef(@inlineremote);
1.56      www       544: 
1.393     raeburn   545:     my ($mapurl,$resurl);
1.390     raeburn   546: 
1.393     raeburn   547:     if ($env{'request.course.id'}) {
                    548:         if ($env{'request.symb'}) {
                    549:             ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
                    550:             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
1.267     droeschl  551: 
1.393     raeburn   552:             my $maptitle = &Apache::lonnet::gettitle($mapurl);
                    553:             my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.318     droeschl  554: 
                    555: #SD
                    556: #course_type only Course and Community?
                    557: #
1.393     raeburn   558:             my @crumbs;
                    559:             unless (($forcereg) &&
                    560:                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
                    561:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
                    562:                 @crumbs = ({text  => Apache::loncommon::course_type() 
                    563:                                     . ' Contents', 
                    564:                             href  => "Javascript:gopost('/adm/navmaps','')"});
                    565:             }
                    566:             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
                    567:                 push(@crumbs, {text  => '...',
                    568:                                no_mt => 1});
                    569:             }
                    570: 
                    571:             push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
                    572:                                                        && $maptitle ne 'default.sequence' 
                    573:                                                        && $maptitle ne $coursetitle);
1.268     droeschl  574: 
1.393     raeburn   575:             push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
                    576:             &Apache::lonhtmlcommon::clear_breadcrumbs();
                    577:             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
                    578:         } else {
                    579:             $resurl = $env{'request.noversionuri'};
                    580:             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
                    581:             my $crstype = &Apache::loncommon::course_type();
                    582:             my $title = &mt('View Resource');
                    583:             if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
                    584:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
1.392     raeburn   585:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
1.393     raeburn   586:                 if ($env{'form.title'}) {
                    587:                     $title = $env{'form.title'};
                    588:                 }
1.394     raeburn   589:                 my $trail;
1.393     raeburn   590:                 if ($env{'form.folderpath'}) {
1.399     raeburn   591:                     &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
1.394     raeburn   592:                     ($trail) =
1.393     raeburn   593:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    594:                 } else {
                    595:                     &Apache::lonhtmlcommon::add_breadcrumb(
1.392     raeburn   596:                     {text  => "Supplemental $crstype Content",
                    597:                      href  => "javascript:gopost('/adm/supplemental','')"});
1.393     raeburn   598:                     $title = &mt('View Resource');
1.394     raeburn   599:                     ($trail) = 
                    600:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.392     raeburn   601:                 }
1.394     raeburn   602:                 return $trail;
1.412     raeburn   603:             } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
                    604:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    605:                 &prepare_functions('/public'.$courseurl."/syllabus",
                    606:                                    $forcereg,$group,undef,undef,1);
                    607:                 $title = &mt('Syllabus File');
                    608:                 my ($trail) =
                    609:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    610:                 return $trail;
1.392     raeburn   611:             }
1.395     raeburn   612:             unless ($env{'request.state'} eq 'construct') {
                    613:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    614:                 &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
                    615:             }
1.392     raeburn   616:         }
1.390     raeburn   617:     } elsif (! $const_space){
1.328     droeschl  618:         #a situation when we're looking at a resource outside of context of a 
                    619:         #course or construction space (e.g. with cumulative rights)
                    620:         &Apache::lonhtmlcommon::clear_breadcrumbs();
1.390     raeburn   621:         unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                    622:             &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
                    623:         }
1.65      www       624:     }
1.41      www       625: # =============================================================================
                    626: # ============================ This is for URLs that actually can be registered
1.316     droeschl  627:     return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/}) 
                    628:                        || $forcereg );
1.390     raeburn   629:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                    630:         $forceview,$editbutton);
1.391     raeburn   631:     if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
                    632:         ($env{'request.role'} !~/^(aa|ca|au)/)) {
1.390     raeburn   633:         $editbutton = &prepare_functions($resurl,$forcereg,$group);
                    634:     }
                    635:     if ($editbutton eq '') {
1.399     raeburn   636:         $editbutton = &clear(6,1);
1.390     raeburn   637:     }
1.317     droeschl  638: 
1.390     raeburn   639: #
                    640: # This applies in course context
                    641: #
                    642:     if ($env{'request.course.id'}) {
                    643:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    644:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    645:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                    646:         my @privs;
                    647:         if ($env{'request.symb'} ne '') {
                    648:              if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
                    649:                  push(@privs,('mgr','vgr'));
                    650:              }
                    651:              push(@privs,'opa');
                    652:         }
                    653:         foreach my $priv (@privs) {
                    654:             $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                    655:             if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                    656:                 $perms{$priv} = 
                    657:                     &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                    658:             }
                    659:         }
                    660: #
                    661: # Determine whether or not to show Grades and Submissions buttons
                    662: #
                    663:         if ($env{'request.symb'} ne '' &&
                    664:             $env{'request.filename'}=~/$LONCAPA::assess_re/) {
                    665:             if ($perms{'mgr'}) {
                    666:                 &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
                    667:                         "gocmd('/adm/grades','gradingmenu')",
                    668:                         'Content Grades');
                    669:             } elsif ($perms{'vgr'}) {
                    670:                 &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
                    671:                         "gocmd('/adm/grades','submission')",
                    672:                         'Content Submissions');
                    673:              }
                    674:         }
                    675:         if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
                    676:             &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
                    677:                     "gocmd('/adm/parmset','set')",
                    678:                     'Content Settings');
1.107     albertel  679: 	}
1.393     raeburn   680: # End grades/submissions check
1.107     albertel  681: 
1.274     www       682: #
1.393     raeburn   683: # This applies to items inside a folder/page modifiable in the course.
1.274     www       684: #
1.390     raeburn   685:         if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
1.393     raeburn   686:             my $text = 'Edit Folder';
1.395     raeburn   687:             if (($mapurl =~ /\.page$/) ||
                    688:                 ($env{'request.symb'}=~
1.396     raeburn   689:                      m{uploaded/$cdom/$cnum/default_\d+\.page$}))  {
1.393     raeburn   690:                 $text = 'Edit Page';
                    691:             }
                    692:             &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
1.390     raeburn   693:                     "gocmd('/adm/coursedocs','direct')",
                    694:                     'Folder/Page Content');
1.258     raeburn   695:         }
1.390     raeburn   696: # End modifiable folder/page container check
                    697:     }
                    698: # End course context
                    699: 
1.41      www       700: # Prepare the rest of the buttons
1.383     raeburn   701:         my ($menuitems,$got_prt,$got_wishlist);
1.120     raeburn   702:         if ($const_space) {
1.274     www       703: #
                    704: # We are in construction space
                    705: #
1.353     www       706: 
1.355     raeburn   707:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.353     www       708: 	    my ($udom,$uname,$thisdisfn) =
1.355     raeburn   709: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1.353     www       710:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1.131     raeburn   711:             if ($currdir =~ m-/$-) {
                    712:                 $is_const_dir = 1;
                    713:             } else {
1.267     droeschl  714:                 $currdir =~ s|[^/]+$||;
1.200     foxr      715: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208     albertel  716: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274     www       717: #
                    718: # Probably should be in mydesk.tab
                    719: #
1.131     raeburn   720:                 $menuitems=(<<ENDMENUITEMS);
1.344     www       721: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1.353     www       722: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
                    723: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
                    724: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
                    725: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1.120     raeburn   726: ENDMENUITEMS
1.131     raeburn   727:             }
1.308     raeburn   728:                 if (ref($bread_crumbs) eq 'ARRAY') {
                    729:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    730:                     foreach my $crumb (@{$bread_crumbs}){
                    731:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
                    732:                     }
                    733:                 }
1.203     foxr      734:         } elsif ( defined($env{'request.course.id'}) && 
                    735: 		 $env{'request.symb'} ne '' ) {
1.274     www       736: #
1.383     raeburn   737: # We are in a course and looking at a registered URL
1.274     www       738: # Should probably be in mydesk.tab
                    739: #
1.120     raeburn   740: 	    $menuitems=(<<ENDMENUITEMS);
1.41      www       741: c&3&1
1.344     www       742: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
                    743: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
1.77      www       744: c&6&3
                    745: c&8&1
                    746: c&8&2
1.344     www       747: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.41      www       748: ENDMENUITEMS
1.383     raeburn   749:             $got_prt = 1;
                    750:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
                    751:                 && (!$env{'request.enc'})) {
1.332     wenzelju  752:                 # wishlist is only available for users with access to resource-pool
                    753:                 # and links can only be set for resources within the resource-pool
                    754:                 $menuitems .= (<<ENDMENUITEMS);
1.430   ! raeburn   755: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink('',currentURL)&Save a link for this resource in my personal Stored Links repository&&1
1.332     wenzelju  756: ENDMENUITEMS
1.383     raeburn   757:                 $got_wishlist = 1;
1.332     wenzelju  758:             }
1.216     albertel  759: 
1.243     tempelho  760: my $currentURL = &Apache::loncommon::get_symb();
                    761: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
                    762: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
                    763: $menuitems.="s&9&3&";
                    764: if(length($annotation) > 0){
1.317     droeschl  765: 	$menuitems.="anot2.png";
1.243     tempelho  766: }else{
1.317     droeschl  767: 	$menuitems.="anot.png";
1.243     tempelho  768: }
1.344     www       769: $menuitems.="&Notes&&annotate()&";
1.243     tempelho  770: $menuitems.="Make notes and annotations about this resource&&1\n";
1.428     raeburn   771: my $is_mobile;
                    772: if ($env{'browser.mobile'}) {
                    773:     $is_mobile = 1;
                    774: }
1.243     tempelho  775: 
1.323     raeburn   776:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1.382     raeburn   777: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
1.216     albertel  778: 		    $menuitems.=(<<ENDREALRES);
1.428     raeburn   779: s&6&3&catalog.png&Info&info[_1]&catalog_info('$is_mobile')&Show Metadata
1.216     albertel  780: ENDREALRES
                    781:                 }
1.422     raeburn   782:                 unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
                    783:                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) {  
1.382     raeburn   784:                     $menuitems.=(<<ENDREALRES);
1.344     www       785: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1.382     raeburn   786: ENDREALRES
                    787:                 }
1.422     raeburn   788:                 unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
                    789:                     $menuitems.=(<<ENDREALRES);
1.344     www       790: s&8&2&fdbk.png&Communicate&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1.77      www       791: ENDREALRES
1.422     raeburn   792:                 }
1.120     raeburn   793: 	    }
                    794:         }
1.203     foxr      795: 	if ($env{'request.uri'} =~ /^\/res/) {
1.383     raeburn   796:             unless ($got_prt) {
                    797: 	        $menuitems .= (<<ENDMENUITEMS);
1.344     www       798: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.203     foxr      799: ENDMENUITEMS
1.384     raeburn   800:                 $got_prt = 1;
1.383     raeburn   801:             }
                    802:             unless ($got_wishlist) {
                    803:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
                    804:                     # wishlist is only available for users with access to resource-pool
                    805:                     $menuitems .= (<<ENDMENUITEMS);
1.430   ! raeburn   806: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink('',currentURL)&Save a link for this resource in your personal Stored Links repository&&1
1.332     wenzelju  807: ENDMENUITEMS
1.383     raeburn   808:                     $got_wishlist = 1;
                    809:                 }
                    810: 	    }
                    811:         }
1.41      www       812:         my $buttons='';
                    813:         foreach (split(/\n/,$menuitems)) {
                    814: 	    my ($command,@rest)=split(/\&/,$_);
1.220     raeburn   815:             my $idx=10*$rest[0]+$rest[1];
                    816:             if (&hidden_button_check() eq 'yes') {
                    817:                 if ($idx == 21 ||$idx == 23) {
                    818:                     $buttons.=&switch('','',@rest);
                    819:                 } else {
                    820:                     $buttons.=&clear(@rest);
                    821:                 }
                    822:             } else {  
                    823:                 if ($command eq 's') {
                    824: 	            $buttons.=&switch('','',@rest);
                    825:                 } else {
                    826:                     $buttons.=&clear(@rest);
                    827:                 }
1.41      www       828:             }
                    829:         }
1.148     albertel  830: 
                    831: 	    my $addremote=0;
1.267     droeschl  832: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.301     droeschl  833:     if ($addremote) {
                    834: 
1.342     www       835:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301     droeschl  836: 
1.342     www       837:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.312     droeschl  838:                 'navigation', @inlineremote[21,23]);
                    839: 
1.378     raeburn   840:         my $countdown = &countdown_timer();
                    841:         if (&hidden_button_check() eq 'yes') {
                    842:             if ($countdown) {
                    843:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
                    844:             }
                    845:         } else {
                    846:             my @tools = @inlineremote[93,91,81,82,83];
                    847:             if ($countdown) {
                    848:                 unshift(@tools,$countdown);
                    849:             }
1.342     www       850:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.378     raeburn   851:                 'tools',@tools);
1.313     droeschl  852: 
                    853:             #publish button in construction space
                    854:             if ($env{'request.state'} eq 'construct'){
1.342     www       855:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349     raeburn   856:                      'advtools', $inlineremote[63]);
1.342     www       857:             } else {
                    858:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349     raeburn   859:                      'tools', $inlineremote[63]);
1.313     droeschl  860:             }
1.390     raeburn   861:             &advtools_crumbs(@inlineremote);
1.301     droeschl  862:         }
1.38      www       863:     }
                    864: 
1.342     www       865:     return   &Apache::lonhtmlcommon::scripttag('', 'start')
                    866:            . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
                    867:            . &Apache::lonhtmlcommon::scripttag('', 'end');
1.38      www       868: }
                    869: 
1.389     raeburn   870: sub get_editbutton {
1.390     raeburn   871:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
1.398     raeburn   872:     my $jscall;
                    873:     if (($forceview) && ($env{'form.todocs'})) {
                    874:         my ($folderpath,$command);
                    875:         if ($env{'request.symb'}) {
                    876:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
                    877:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
                    878:             $folderpath = $env{'form.folderpath'};
                    879:             $command = '&forcesupplement=1';
                    880:         }
                    881:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
                    882:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
                    883:     } else {
                    884:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1.393     raeburn   885:                                                 $forceedit,$forcereg,$env{'request.symb'},
                    886:                                                 &escape($env{'form.folderpath'}),
                    887:                                                 &escape($env{'form.title'}),$env{'form.idx'},
1.398     raeburn   888:                                                 &escape($env{'form.suppurl'},$env{'form.todocs'}));
                    889:     }
1.389     raeburn   890:     if ($jscall) {
1.390     raeburn   891:         my $icon = 'pcstr.png';
                    892:         my $label = 'Edit';
                    893:         if ($forceview) {
                    894:             $icon = 'tolastloc.png';
                    895:             $label = 'Exit Editing';
                    896:         }
                    897:         &switch('','',6,1,$icon,$label,'resource[_2]',
                    898:                 $jscall,"Edit this resource");
                    899:         return 1;
                    900:     }
                    901:     return;
                    902: }
                    903: 
                    904: sub prepare_functions {
1.393     raeburn   905:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_;
1.390     raeburn   906:     unless ($env{'request.registered'}) {
                    907:         undef(@inlineremote);
                    908:     }
                    909:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                    910:         $forceview);
                    911: 
                    912:     if ($env{'request.course.id'}) {
                    913:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    914:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    915:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                    916:     }
                    917: 
                    918:     my $editbutton = '';
                    919: #
                    920: # Determine whether or not to display 'Edit' icon/button
                    921: #
                    922:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
                    923:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.391     raeburn   924:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                    925:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                    926:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                    927:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                    928:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.390     raeburn   929:                                           $forceedit,$forceview,$forcereg);
                    930:         }
1.391     raeburn   931:     } elsif ((!$env{'request.course.id'}) &&
1.390     raeburn   932:              ($env{'user.author'}) && ($env{'request.filename'}) &&
                    933:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
                    934: #
                    935: # Currently do not have the role of author or co-author.
                    936: # Do we have authoring privileges for the resource?
                    937: #
                    938:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
                    939:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                    940:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                    941:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                    942:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                    943:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                    944:                                           $forceedit,$forceview,$forcereg);
                    945:         }
                    946:     } elsif ($env{'request.course.id'}) {
                    947: #
                    948: # This applies in course context
                    949: #
1.412     raeburn   950:         if (($perms{'mdc'}) &&
                    951:             (($resurl eq "/public/$cdom/$cnum/syllabus") ||
                    952:             ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
1.411     raeburn   953:             $cfile = $resurl;
                    954:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
                    955:             if ($env{'form.forceedit'}) {
                    956:                 $forceview = 1;
1.390     raeburn   957:             } else {
1.411     raeburn   958:                 $forceedit = 1;
1.390     raeburn   959:             }
1.411     raeburn   960:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                    961:                                           $forceedit,$forceview,$forcereg);
1.393     raeburn   962:         } elsif (($resurl eq '/adm/extresedit') &&
                    963:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
                    964:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                    965:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                    966:                                                $env{'form.symb'});
                    967:             if ($cfile ne '') {
                    968:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
                    969:                                               $forceedit,$forceview,$forcereg,
                    970:                                               $env{'form.title'},$env{'form.suppurl'});
                    971:             }
1.406     raeburn   972:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
                    973:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
                    974:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                    975:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                    976:                                                $env{'form.symb'});
                    977:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                    978:                                           $forceedit,$forceview,$forcereg);
1.405     raeburn   979:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
                    980:                  ($resurl ne '/cgi-bin/printout.pl')) {
1.390     raeburn   981:             if ($env{'request.filename'}) {
                    982:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                    983:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
                    984:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                    985:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                    986:                 if ($cfile ne '') {
                    987:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
                    988:                                                   $forceedit,$forceview,$forcereg);
                    989:                 }
                    990:             }
                    991:         }
                    992:     }
                    993: # End determination of 'Edit' icon/button display
                    994: 
1.393     raeburn   995:     if ($env{'request.course.id'}) {
1.390     raeburn   996: # This applies to about me page for users in a course
1.391     raeburn   997:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.390     raeburn   998:             my ($sdom,$sname) = ($1,$2);
                    999:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
                   1000:                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
                   1001:                         '',
1.415     raeburn  1002:                         "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
1.390     raeburn  1003:                             'Send message to specific user');
                   1004:             }
1.391     raeburn  1005:             my $hideprivileged = 1;
                   1006:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
                   1007:                                            $hideprivileged)) {
1.390     raeburn  1008:                 foreach my $priv ('vsa','vgr','srm') {
                   1009:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                   1010:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                   1011:                         $perms{$priv} =
                   1012:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                   1013:                     }
                   1014:                 }
                   1015:                 if ($perms{'vsa'}) {
                   1016:                     &switch('','',6,5,'trck-22x22.png','Activity',
                   1017:                             '',
                   1018:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
                   1019:                             'View recent activity by this person');
                   1020:                 }
                   1021:                 if ($perms{'vgr'}) {
                   1022:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
                   1023:                             '',
1.415     raeburn  1024:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
1.390     raeburn  1025:                             'Slot reservation history');
                   1026:                 }
                   1027:                 if ($perms{'srm'}) {
                   1028:                     &switch('','',6,7,'contact-new-22x22.png','Records',
                   1029:                             '',
1.415     raeburn  1030:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
1.390     raeburn  1031:                             'Add records');
                   1032:                 }
                   1033:             }
1.393     raeburn  1034:         }
                   1035:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
                   1036:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
                   1037:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
                   1038:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1.397     raeburn  1039:              ($resurl eq '/adm/supplemental') ||
                   1040:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
                   1041:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1.393     raeburn  1042:             my @folders=split('&',$env{'form.folderpath'});
1.394     raeburn  1043:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1.393     raeburn  1044:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
                   1045:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1.415     raeburn  1046:                         "location.href='/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath=$esc_path'",
1.393     raeburn  1047:                         'Folder/Page Content');
                   1048:             }
1.390     raeburn  1049:         }
                   1050:     }
                   1051: 
                   1052: # End checking for items for about me page for users in a course
1.393     raeburn  1053:     if ($docscrumbs) {
                   1054:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1055:         &advtools_crumbs(@inlineremote);
                   1056:         return $editbutton;
                   1057:     } elsif ($env{'request.registered'}) {
1.390     raeburn  1058:         return $editbutton;
                   1059:     } else {
                   1060:         if (ref($bread_crumbs) eq 'ARRAY') {
                   1061:             if (@inlineremote > 0) {
                   1062:                 if (ref($advtools) eq 'ARRAY') {
                   1063:                     @{$advtools} = @inlineremote;
                   1064:                 }
                   1065:             }
                   1066:             return;
                   1067:         } elsif (@inlineremote > 0) {
                   1068:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1069:             &advtools_crumbs(@inlineremote);
                   1070:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
                   1071:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
                   1072:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
                   1073:         }
                   1074:     }
                   1075: }
                   1076: 
                   1077: sub advtools_crumbs {
                   1078:     my @funcs = @_;
                   1079:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                   1080:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1081:             'advtools', @funcs[61,64,65,66,67,74]);
                   1082:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
                   1083:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1084:             'advtools', @funcs[61,71,72,73,74,92]);
1.393     raeburn  1085:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
                   1086:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.407     raeburn  1087:             'advtools', $funcs[61]);
1.393     raeburn  1088:     }
1.412     raeburn  1089:     return;
1.258     raeburn  1090: }
                   1091: 
1.2       www      1092: # ================================================================== Raw Config
                   1093: 
1.3       www      1094: sub clear {
                   1095:     my ($row,$col)=@_;
1.316     droeschl 1096:     $inlineremote[10*$row+$col]='';
                   1097:     return ''; 
1.3       www      1098: }
                   1099: 
1.40      www      1100: # ============================================ Switch a button or create a link
1.25      matthew  1101: # Switch acts on the javascript that is executed when a button is clicked.  
                   1102: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www      1103: 
1.2       www      1104: sub switch {
1.209     www      1105:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2       www      1106:     $act=~s/\$uname/$uname/g;
                   1107:     $act=~s/\$udom/$udom/g;
1.88      www      1108:     $top=&mt($top);
                   1109:     $bot=&mt($bot);
                   1110:     $desc=&mt($desc);
1.209     www      1111:     my $idx=10*$row+$col;
                   1112:     $category_members{$cat}.=':'.$idx;
                   1113: 
1.320     droeschl 1114: # Inline Menu
1.317     droeschl 1115:     if ($nobreak==2) { return ''; }
                   1116:     my $text=$top.' '.$bot;
                   1117:     $text=~s/\s*\-\s*//gs;
1.105     www      1118: 
1.317     droeschl 1119:     my $pic=
1.225     albertel 1120: 	   '<img alt="'.$text.'" src="'.
                   1121: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303     droeschl 1122: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317     droeschl 1123:     if ($env{'browser.interface'} eq 'faketextual') {
1.274     www      1124: # Main Menu
1.103     www      1125: 	   if ($nobreak==3) {
1.209     www      1126: 	       $inlineremote[$idx]="\n".
1.177     albertel 1127: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
1.247     harmsja  1128: 		   '</td><td align="left">'.
1.103     www      1129: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                   1130: 	   } elsif ($nobreak) {
1.209     www      1131: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1132: 		   '<td align="left">'.
1.177     albertel 1133: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215     www      1134:                     <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      1135: 	   } else {
1.209     www      1136: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1137: 		   '<td align="left">'.
1.103     www      1138: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel 1139: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215     www      1140: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103     www      1141: 	   }
1.317     droeschl 1142:     } else {
1.103     www      1143: # Inline Menu
1.378     raeburn  1144:         my @tools = (93,91,81,82,83);
                   1145:         unless ($env{'request.state'} eq 'construct') {
                   1146:             push(@tools,63);
                   1147:         }
                   1148:         if (($env{'environment.icons'} eq 'iconsonly') && 
                   1149:             (grep(/^$idx$/,@tools))) {
                   1150:             $inlineremote[$idx] =
                   1151:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
                   1152:         } else {
                   1153:             $inlineremote[$idx] =
1.317     droeschl 1154:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344     www      1155:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
1.378     raeburn  1156:         }
1.317     droeschl 1157:     }
1.56      www      1158:     return '';
1.2       www      1159: }
                   1160: 
                   1161: sub secondlevel {
                   1162:     my $output='';
                   1163:     my 
1.209     www      1164:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2       www      1165:     if ($prt eq 'any') {
1.209     www      1166: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1167:     } elsif ($prt=~/^r(\w+)/) {
                   1168:         if ($rol eq $1) {
1.209     www      1169:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1170:         }
                   1171:     }
                   1172:     return $output;
                   1173: }
                   1174: 
1.56      www      1175: sub inlinemenu {
1.210     albertel 1176:     undef(@inlineremote);
                   1177:     undef(%category_members);
1.275     www      1178: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56      www      1179:     &rawconfig(1);
1.309     bisitz   1180:     my $output='<table><tr>';
1.209     www      1181:     for (my $col=1; $col<=2; $col++) {
1.241     riegler  1182:         $output.='<td class="LC_mainmenu_col_fieldset">';
1.209     www      1183:         for (my $row=1; $row<=8; $row++) {
                   1184:             foreach my $cat (keys(%category_members)) {
                   1185:                if ($category_positions{$cat} ne "$col,$row") { next; }
1.247     harmsja  1186:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309     bisitz   1187:                $output.='<div class="LC_Box LC_400Box">';
                   1188: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247     harmsja  1189:                $output.='<table>';
1.240     riegler  1190:                my %active=();
                   1191:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
                   1192:                   if ($inlineremote[$menu_item]) {
                   1193:                      $active{$menu_item}=1;
                   1194:                   }
                   1195:                }  
                   1196:                foreach my $item (sort(keys(%active))) {
                   1197:                   $output.=$inlineremote[$item];
                   1198:                }
                   1199:                $output.='</table>';
1.245     harmsja  1200:                $output.='</div>';
1.240     riegler  1201:             }
                   1202:          }
                   1203:          $output.="</td>";
                   1204:     }
                   1205:     $output.="</tr></table>";
                   1206:     return $output;
                   1207: }
                   1208: 
1.2       www      1209: sub rawconfig {
1.274     www      1210: #
                   1211: # This evaluates mydesk.tab
                   1212: # Need to add more positions and more privileges to deal with all
                   1213: # menu items.
                   1214: #
1.34      www      1215:     my $textualoverride=shift;
                   1216:     my $output='';
1.316     droeschl 1217:     return '' unless $textualoverride;
1.152     albertel 1218:     my $uname=$env{'user.name'};
                   1219:     my $udom=$env{'user.domain'};
                   1220:     my $adv=$env{'user.adv'};
1.266     raeburn  1221:     my $show_course=&Apache::loncommon::show_course();
1.152     albertel 1222:     my $author=$env{'user.author'};
1.5       www      1223:     my $crs='';
1.295     raeburn  1224:     my $crstype='';
1.152     albertel 1225:     if ($env{'request.course.id'}) {
                   1226:        $crs='/'.$env{'request.course.id'};
                   1227:        if ($env{'request.course.sec'}) {
                   1228: 	   $crs.='_'.$env{'request.course.sec'};
1.7       www      1229:        }
1.8       www      1230:        $crs=~s/\_/\//g;
1.295     raeburn  1231:        $crstype = &Apache::loncommon::course_type();
1.5       www      1232:     }
1.152     albertel 1233:     my $pub=($env{'request.state'} eq 'published');
                   1234:     my $con=($env{'request.state'} eq 'construct');
                   1235:     my $rol=$env{'request.role'};
1.427     raeburn  1236:     my $requested_domain;
                   1237:     if ($rol) {
                   1238:        $requested_domain = $env{'request.role.domain'};
                   1239:     }
1.184     raeburn  1240:     foreach my $line (@desklines) {
1.209     www      1241:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3       www      1242:         $prt=~s/\$uname/$uname/g;
                   1243:         $prt=~s/\$udom/$udom/g;
1.295     raeburn  1244:         if ($prt =~ /\$crs/) {
                   1245:             next unless ($env{'request.course.id'});
                   1246:             next if ($crstype eq 'Community');
                   1247:             $prt=~s/\$crs/$crs/g;
                   1248:         } elsif ($prt =~ /\$cmty/) {
                   1249:             next unless ($env{'request.course.id'});
                   1250:             next if ($crstype ne 'Community');
                   1251:             $prt=~s/\$cmty/$crs/g;
                   1252:         }
1.427     raeburn  1253:         if ($prt =~ m/\$requested_domain/) {
                   1254:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
                   1255:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
                   1256:             } else {
                   1257:                 $prt=~s/\$requested_domain/$requested_domain/g;
                   1258:             }
                   1259:         }
1.211     www      1260:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3       www      1261:         if ($pro eq 'clear') {
1.4       www      1262: 	    $output.=&clear($row,$col);
1.3       www      1263:         } elsif ($pro eq 'any') {
1.2       www      1264:                $output.=&secondlevel(
1.209     www      1265: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1266: 	} elsif ($pro eq 'smp') {
                   1267:             unless ($adv) {
                   1268:                $output.=&secondlevel(
1.209     www      1269:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1270:             }
                   1271:         } elsif ($pro eq 'adv') {
                   1272:             if ($adv) {
                   1273:                $output.=&secondlevel(
1.209     www      1274: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1275:             }
1.231     albertel 1276: 	} elsif ($pro eq 'shc') {
                   1277:             if ($show_course) {
                   1278:                $output.=&secondlevel(
                   1279:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1280:             }
                   1281:         } elsif ($pro eq 'nsc') {
                   1282:             if (!$show_course) {
                   1283:                $output.=&secondlevel(
                   1284: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1285:             }
1.81      matthew  1286:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295     raeburn  1287:             my $priv = $1;
                   1288:             if ($priv =~ /^mdc(Course|Community)/) {
                   1289:                 if ($crstype eq $1) {
                   1290:                     $priv = 'mdc';
                   1291:                 } else {
                   1292:                     next;
                   1293:                 }
                   1294:             }
1.427     raeburn  1295:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
                   1296:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
                   1297:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4       www      1298:             }
1.295     raeburn  1299:         } elsif ($pro eq 'course')  {
                   1300:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209     www      1301:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81      matthew  1302: 	    }
1.295     raeburn  1303:         } elsif ($pro eq 'community')  {
                   1304:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
                   1305:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1306:             }
1.124     matthew  1307:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                   1308:             my $key = $1;
1.307     raeburn  1309:             if ($crstype ne 'Community') {
                   1310:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1311:                 if ($key eq 'canuse_pdfforms') {
                   1312:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1313:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1314:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1315:                     }
                   1316:                 }
                   1317:                 if ($coursepref) { 
                   1318:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1319:                 }
1.295     raeburn  1320:             }
                   1321:         } elsif ($pro =~ /^communityenv_(.*)$/) {
                   1322:             my $key = $1;
1.307     raeburn  1323:             if ($crstype eq 'Community') {
                   1324:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1325:                 if ($key eq 'canuse_pdfforms') {
                   1326:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1327:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1328:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1329:                     }
                   1330:                 }
                   1331:                 if ($coursepref) { 
                   1332:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1333:                 }
1.124     matthew  1334:             }
1.81      matthew  1335:         } elsif ($pro =~ /^course_(.*)$/) {
                   1336:             # Check for permissions inside of a course
1.295     raeburn  1337:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
1.152     albertel 1338:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1339:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81      matthew  1340:                  )) {
1.209     www      1341:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26      www      1342: 	    }
1.295     raeburn  1343:         } elsif ($pro =~ /^community_(.*)$/) {
                   1344:             # Check for permissions inside of a community
                   1345:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
                   1346:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1347:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
                   1348:                  )) {
                   1349:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1350:             }
1.4       www      1351:         } elsif ($pro eq 'author') {
                   1352:             if ($author) {
1.152     albertel 1353:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234     raeburn  1354:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
1.152     albertel 1355:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19      matthew  1356:                     # Check that we are on the correct machine
1.29      matthew  1357:                     my $cadom=$requested_domain;
1.152     albertel 1358:                     my $caname=$env{'user.name'};
1.234     raeburn  1359:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29      matthew  1360: 		       ($cadom,$caname)=
1.206     albertel 1361:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29      matthew  1362:                     }                       
                   1363:                     $act =~ s/\$caname/$caname/g;
1.353     www      1364:                     $act =~ s/\$cadom/$cadom/g;
1.19      matthew  1365:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel 1366: 		    my $allowed=0;
                   1367: 		    my @ids=&Apache::lonnet::current_machine_ids();
                   1368: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   1369: 		    if ($allowed) {
1.209     www      1370:                         $output.=&switch($caname,$cadom,
                   1371:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19      matthew  1372:                     }
1.6       www      1373:                 }
1.2       www      1374:             }
1.248     raeburn  1375:         } elsif ($pro eq 'tools') {
                   1376:             my @tools = ('aboutme','blog','portfolio');
                   1377:             if (grep(/^\Q$prt\E$/,@tools)) {
1.249     raeburn  1378:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251     raeburn  1379:                                                        $env{'user.domain'},
                   1380:                                                        $prt,undef,'tools')) {
                   1381:                     $output.=&clear($row,$col);
                   1382:                     next;
                   1383:                 }
1.278     raeburn  1384:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
                   1385:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
                   1386:                     next;
                   1387:                 }
                   1388:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
                   1389:                     next;
                   1390:                 }
1.279     raeburn  1391:                 my $showreqcrs = &check_for_rcrs();
1.251     raeburn  1392:                 if (!$showreqcrs) {
1.248     raeburn  1393:                     $output.=&clear($row,$col);
                   1394:                     next;
                   1395:                 }
                   1396:             }
                   1397:             $prt='any';
                   1398:             $output.=&secondlevel(
                   1399:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1400:         }
1.13      harris41 1401:     }
1.2       www      1402:     return $output;
                   1403: }
                   1404: 
1.279     raeburn  1405: sub check_for_rcrs {
                   1406:     my $showreqcrs = 0;
1.424     raeburn  1407:     my @reqtypes = ('official','unofficial','community','textbook');
1.280     raeburn  1408:     foreach my $type (@reqtypes) {
1.279     raeburn  1409:         if (&Apache::lonnet::usertools_access($env{'user.name'},
                   1410:                                               $env{'user.domain'},
                   1411:                                               $type,undef,'requestcourses')) {
                   1412:             $showreqcrs = 1;
                   1413:             last;
                   1414:         }
                   1415:     }
1.280     raeburn  1416:     if (!$showreqcrs) {
                   1417:         foreach my $type (@reqtypes) {
                   1418:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
                   1419:                 $showreqcrs = 1;
                   1420:                 last;
                   1421:             }
                   1422:         }
                   1423:     }
1.279     raeburn  1424:     return $showreqcrs;
                   1425: }
                   1426: 
1.306     raeburn  1427: sub dc_popup_js {
                   1428:     my %lt = &Apache::lonlocal::texthash(
                   1429:                                           more => '(More ...)',
                   1430:                                           less => '(Less ...)',
                   1431:                                         );
                   1432:     return <<"END";
                   1433: 
                   1434: function showCourseID() {
                   1435:     document.getElementById('dccid').style.display='block';
                   1436:     document.getElementById('dccid').style.textAlign='left';
1.307     raeburn  1437:     document.getElementById('dccid').style.textFace='normal';
1.369     raeburn  1438:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306     raeburn  1439:     return;
                   1440: }
                   1441: 
                   1442: function hideCourseID() {
                   1443:     document.getElementById('dccid').style.display='none';
1.369     raeburn  1444:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306     raeburn  1445:     return;
                   1446: }
                   1447: 
                   1448: END
                   1449: 
                   1450: }
                   1451: 
1.378     raeburn  1452: sub countdown_toggle_js {
                   1453:     return <<"END";
                   1454: 
                   1455: function toggleCountdown() {
                   1456:     var countdownid = document.getElementById('duedatecountdown');
                   1457:     var currstyle = countdownid.style.display;
                   1458:     if (currstyle == 'inline') {
                   1459:         countdownid.style.display = 'none';
                   1460:         document.getElementById('ddcountcollapse').innerHTML='';
                   1461:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
                   1462:     } else {
                   1463:         countdownid.style.display = 'inline';
                   1464:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
                   1465:         document.getElementById('ddcountexpand').innerHTML='';
                   1466:     }
                   1467:     return;
                   1468: }
                   1469: 
                   1470: END
                   1471: }
                   1472: 
1.42      www      1473: sub utilityfunctions {
1.421     raeburn  1474:     my ($httphost) = @_;
1.152     albertel 1475:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.316     droeschl 1476:     if ($currenturl =~ m{^/adm/wrapper/ext/}
                   1477:         && $env{'request.external.querystring'} ) {
1.293     raeburn  1478:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
                   1479:     }
1.183     www      1480:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125     albertel 1481:     
1.152     albertel 1482:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.175     albertel 1483: 
1.306     raeburn  1484:     my $dc_popup_cid;
                   1485:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   1486:                         $env{'course.'.$env{'request.course.id'}.
                   1487:                                  '.domain'}.'/'})) {
                   1488:         $dc_popup_cid = &dc_popup_js();
                   1489:     }
                   1490: 
1.175     albertel 1491:     my $start_page_annotate = 
                   1492:         &Apache::loncommon::start_page('Annotator',undef,
                   1493: 				       {'only_body' => 1,
                   1494: 					'js_ready'  => 1,
                   1495: 					'bgcolor'   => '#BBBBBB',
                   1496: 					'add_entries' => {
                   1497: 					    'onload' => 'javascript:document.goannotate.submit();'}});
                   1498: 
1.205     albertel 1499:     my $end_page_annotate = 
                   1500:         &Apache::loncommon::end_page({'js_ready' => 1});
                   1501: 
1.389     raeburn  1502:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336     raeburn  1503: 
1.368     www      1504:     my $esc_url=&escape($currenturl);
                   1505:     my $esc_symb=&escape($currentsymb);
1.332     wenzelju 1506: 
1.378     raeburn  1507:     my $countdown = &countdown_toggle_js();
                   1508: 
1.429     raeburn  1509:     my $hostvar = '
                   1510: function setLCHost() {
                   1511:     var lcHostname="";
                   1512: ';
                   1513:     if ($httphost =~ m{^https?\://}) {
                   1514:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
                   1515:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
                   1516:                     '    var match = hostReg.exec(lcServer);'."\n".
                   1517:                     '    if (match.length) {'."\n".
                   1518:                     '        if (match[1] == location.hostname) {'."\n".
                   1519:                     '            lcHostname=lcServer;'."\n".
                   1520:                     '        }'."\n".
                   1521:                     '    }'."\n";
                   1522:     }
                   1523:     
                   1524:     $hostvar .= '    return lcHostname;'."\n".
                   1525: '}'."\n";
                   1526: 
1.42      www      1527: return (<<ENDUTILITY)
1.429     raeburn  1528:     $hostvar
1.368     www      1529:     var currentURL=unescape("$esc_url");
                   1530:     var reloadURL=unescape("$esc_url");
                   1531:     var currentSymb=unescape("$esc_symb");
1.42      www      1532: 
1.306     raeburn  1533: $dc_popup_cid
1.114     albertel 1534: 
1.389     raeburn  1535: $jumptores
1.336     raeburn  1536: 
1.42      www      1537: function gopost(url,postdata) {
                   1538:    if (url!='') {
1.429     raeburn  1539:       var lcHostname = setLCHost();
                   1540:       this.document.server.action=lcHostname+url;
1.42      www      1541:       this.document.server.postdata.value=postdata;
                   1542:       this.document.server.command.value='';
                   1543:       this.document.server.url.value='';
                   1544:       this.document.server.symb.value='';
                   1545:       this.document.server.submit();
                   1546:    }
                   1547: }
                   1548: 
                   1549: function gocmd(url,cmd) {
                   1550:    if (url!='') {
1.429     raeburn  1551:       var lcHostname = setLCHost();
                   1552:       this.document.server.action=lcHostname+url;
1.42      www      1553:       this.document.server.postdata.value='';
                   1554:       this.document.server.command.value=cmd;
                   1555:       this.document.server.url.value=currentURL;
                   1556:       this.document.server.symb.value=currentSymb;
                   1557:       this.document.server.submit();
                   1558:    }
1.57      www      1559: }
                   1560: 
1.121     raeburn  1561: function gocstr(url,filename) {
                   1562:     if (url == '/adm/cfile?action=delete') {
                   1563:         this.document.cstrdelete.filename.value = filename
                   1564:         this.document.cstrdelete.submit();
                   1565:         return;
                   1566:     }
1.137     raeburn  1567:     if (url == '/adm/printout') {
                   1568:         this.document.cstrprint.postdata.value = filename
                   1569:         this.document.cstrprint.curseed.value = 0;
                   1570:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  1571:         if (this.document.lonhomework) {
                   1572:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   1573:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   1574:             }
                   1575:             if (this.document.lonhomework.problemtype) {
1.164     albertel 1576: 		if (this.document.lonhomework.problemtype.value) {
                   1577: 		    this.document.cstrprint.problemtype.value = 
                   1578: 			this.document.lonhomework.problemtype.value;
                   1579: 		} else if (this.document.lonhomework.problemtype.options) {
                   1580: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   1581: 			if (this.document.lonhomework.problemtype.options[i].selected) {
                   1582: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   1583: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   1584: 				}
                   1585: 			}
                   1586: 		    }
                   1587: 		}
                   1588: 	    }
                   1589: 	}
1.137     raeburn  1590:         this.document.cstrprint.submit();
                   1591:         return;
                   1592:     }
1.121     raeburn  1593:     if (url !='') {
                   1594:         this.document.constspace.filename.value = filename;
                   1595:         this.document.constspace.action = url;
                   1596:         this.document.constspace.submit();
                   1597:     }
                   1598: }
                   1599: 
1.131     raeburn  1600: function golist(url) {
                   1601:    if (url!='' && url!= null) {
                   1602:        currentURL = null;
                   1603:        currentSymb= null;
1.429     raeburn  1604:        var lcHostname = setLCHost();
                   1605:        top.location.href=lcHostname+url;
1.131     raeburn  1606:    }
                   1607: }
                   1608: 
                   1609: 
1.121     raeburn  1610: 
1.428     raeburn  1611: function catalog_info(isMobile) {
                   1612:     if (isMobile == 1) {
                   1613:         openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
                   1614:     } else {
                   1615:         loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
                   1616:     }
1.57      www      1617: }
                   1618: 
                   1619: function chat_win() {
1.429     raeburn  1620:    var lcHostname = setLCHost();
                   1621:    lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42      www      1622: }
1.169     raeburn  1623: 
                   1624: function group_chat(group) {
1.429     raeburn  1625:    var lcHostname = setLCHost();
                   1626:    var url = lcHostname+'/adm/groupchat?group='+group;
1.169     raeburn  1627:    var winName = 'LONchat_'+group;
                   1628:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
                   1629: }
1.175     albertel 1630: 
                   1631: function annotate() {
                   1632:    w_Annotator_flag=1;
                   1633:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
                   1634:    annotator.document.write(
                   1635:    '$start_page_annotate'
                   1636:   +"<form name='goannotate' target='Annotator' method='post' "
                   1637:   +"action='/adm/annotations'>"
1.217     albertel 1638:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181     albertel 1639:   +"<\\/form>"
1.205     albertel 1640:   +'$end_page_annotate');
1.175     albertel 1641:    annotator.document.close();
                   1642: }
                   1643: 
1.370     raeburn  1644: function open_StoredLinks_Import(rat) {
1.335     wenzelju 1645:    var newWin;
1.429     raeburn  1646:    var lcHostname = setLCHost();
1.335     wenzelju 1647:    if (rat) {
1.429     raeburn  1648:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.334     wenzelju 1649:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1.335     wenzelju 1650:    }
                   1651:    else {
1.429     raeburn  1652:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
1.335     wenzelju 1653:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
                   1654:    }
1.334     wenzelju 1655:    newWin.focus();
                   1656: }
                   1657: 
1.372     raeburn  1658: (function (\$) {
                   1659:   \$(document).ready(function () {
                   1660:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
                   1661:     /*\@cc_on
                   1662:       if (!window.XMLHttpRequest) {
                   1663:         \$('.LC_hoverable').each(function () {
                   1664:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
                   1665:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
                   1666:         });
                   1667:       }
                   1668:     \@*/
                   1669:   });
                   1670: }(jQuery));
                   1671: 
1.378     raeburn  1672: $countdown
                   1673: 
1.42      www      1674: ENDUTILITY
                   1675: }
                   1676: 
                   1677: sub serverform {
                   1678:     return(<<ENDSERVERFORM);
1.181     albertel 1679: <form name="server" action="/adm/logout" method="post" target="_top">
1.42      www      1680: <input type="hidden" name="postdata" value="none" />
                   1681: <input type="hidden" name="command" value="none" />
                   1682: <input type="hidden" name="url" value="none" />
                   1683: <input type="hidden" name="symb" value="none" />
                   1684: </form>
                   1685: ENDSERVERFORM
                   1686: }
1.113     albertel 1687: 
1.121     raeburn  1688: sub constspaceform {
                   1689:     return(<<ENDCONSTSPACEFORM);
1.181     albertel 1690: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121     raeburn  1691: <input type="hidden" name="filename" value="" />
                   1692: </form>
1.181     albertel 1693: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121     raeburn  1694: <input type="hidden" name="action" value="delete" /> 
                   1695: <input type="hidden" name="filename" value="" />
                   1696: </form>
1.181     albertel 1697: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137     raeburn  1698: <input type="hidden" name="postdata" value="" />
                   1699: <input type="hidden" name="curseed" value="" />
                   1700: <input type="hidden" name="problemtype" value="" />
                   1701: </form>
                   1702: 
1.121     raeburn  1703: ENDCONSTSPACEFORM
                   1704: }
                   1705: 
1.220     raeburn  1706: sub hidden_button_check {
1.317     droeschl 1707:     if ( $env{'request.course.id'} eq ''
                   1708:          || $env{'request.role.adv'} ) {
                   1709: 
1.220     raeburn  1710:         return;
                   1711:     }
1.232     raeburn  1712:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
                   1713:     return $buttonshide; 
1.220     raeburn  1714: }
1.184     raeburn  1715: 
1.235     raeburn  1716: sub roles_selector {
1.421     raeburn  1717:     my ($cdom,$cnum,$httphost) = @_;
1.298     raeburn  1718:     my $crstype = &Apache::loncommon::course_type();
1.235     raeburn  1719:     my $now = time;
1.350     raeburn  1720:     my (%courseroles,%seccount,%courseprivs);
1.235     raeburn  1721:     my $is_cc;
1.401     raeburn  1722:     my ($js,$form,$switcher,$switchtext);
1.298     raeburn  1723:     my $ccrole;
                   1724:     if ($crstype eq 'Community') {
                   1725:         $ccrole = 'co';
                   1726:     } else {
                   1727:         $ccrole = 'cc';
1.350     raeburn  1728:     }
1.386     raeburn  1729:     my ($priv,$gotsymb,$destsymb);
1.350     raeburn  1730:     my $destinationurl = $ENV{'REQUEST_URI'};
1.386     raeburn  1731:     if ($destinationurl =~ /\?symb=/) {
                   1732:         $gotsymb = 1;
                   1733:     } elsif ($destinationurl =~ m{^/enc/}) {
                   1734:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
                   1735:         if ($plainurl =~ /\?symb=/) {
                   1736:             $gotsymb = 1;
                   1737:         }
                   1738:     }
                   1739:     unless ($gotsymb) {
                   1740:         $destsymb = &Apache::lonnet::symbread();
                   1741:         if ($destsymb ne '') {
                   1742:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
                   1743:         }
                   1744:     }
1.350     raeburn  1745:     my $reqprivs = &required_privs();
                   1746:     if (ref($reqprivs) eq 'HASH') {
                   1747:         my $destination = $destinationurl;
                   1748:         $destination =~ s/(\?.*)$//;
                   1749:         if (exists($reqprivs->{$destination})) {
                   1750:             $priv = $reqprivs->{$destination};
                   1751:         }
                   1752:     }
1.298     raeburn  1753:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
                   1754:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235     raeburn  1755:         
                   1756:         if ((($start) && ($start<0)) || 
                   1757:             (($end) && ($end<$now))  ||
                   1758:             (($start) && ($now<$start))) {
                   1759:             $is_cc = 0;
                   1760:         } else {
                   1761:             $is_cc = 1;
                   1762:         }
                   1763:     }
                   1764:     if ($is_cc) {
1.350     raeburn  1765:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1.235     raeburn  1766:     } else {
1.262     raeburn  1767:         my %gotnosection;
1.235     raeburn  1768:         foreach my $item (keys(%env)) {
1.239     raeburn  1769:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235     raeburn  1770:                 my $role = $1;
                   1771:                 my $sec = $2;
                   1772:                 next if ($role eq 'gr');
                   1773:                 my ($start,$end) = split(/\./,$env{$item});
                   1774:                 next if (($start && $start > $now) || ($end && $end < $now));
                   1775:                 if ($sec eq '') {
1.239     raeburn  1776:                     if (!$gotnosection{$role}) {
                   1777:                         $seccount{$role} ++;
                   1778:                         $gotnosection{$role} = 1;
                   1779:                     }
1.235     raeburn  1780:                 }
1.350     raeburn  1781:                 if ($priv ne '') {
                   1782:                     my $cnumsec = $cnum;
                   1783:                     if ($sec ne '') {
                   1784:                         $cnumsec .= "/$sec";
                   1785:                     }
                   1786:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
                   1787:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
                   1788:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
                   1789:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
                   1790:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
                   1791:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
                   1792:                 }
1.235     raeburn  1793:                 if (ref($courseroles{$role}) eq 'ARRAY') {
1.239     raeburn  1794:                     if ($sec ne '') {
1.264     raeburn  1795:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239     raeburn  1796:                             push(@{$courseroles{$role}},$sec);
                   1797:                             $seccount{$role} ++;
                   1798:                         }
                   1799:                     }
                   1800:                 } else {
                   1801:                     @{$courseroles{$role}} = ();
                   1802:                     if ($sec ne '') {
                   1803:                         $seccount{$role} ++;
1.235     raeburn  1804:                         push(@{$courseroles{$role}},$sec);
                   1805:                     }
                   1806:                 }
                   1807:             }
                   1808:         }
                   1809:     }
1.419     bisitz   1810:     $switchtext = 'Switch role'; # do not translate here
1.298     raeburn  1811:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.402     raeburn  1812:     my $numdiffsec;
                   1813:     if (keys(%seccount) == 1) {
                   1814:         foreach my $key (keys(%seccount)) {
                   1815:             $numdiffsec = $seccount{$key};
                   1816:         }
                   1817:     }
                   1818:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
1.401     raeburn  1819:         my @submenu;
                   1820:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
                   1821:         $form = 
1.421     raeburn  1822:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
1.401     raeburn  1823:             '  <input type="hidden" name="destinationurl" value="'.
                   1824:             &HTML::Entities::encode($destinationurl).'" />'."\n".
                   1825:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
                   1826:             '  <input type="hidden" name="selectrole" value="" />'."\n".
1.402     raeburn  1827:             '  <input type="hidden" name="switchrole" value="" />'."\n";
                   1828:         if ($destsymb ne '') {
                   1829:             $form .= '  <input type="hidden" name="destsymb" value="'.
                   1830:                         &HTML::Entities::encode($destsymb).'" />'."\n";
                   1831:         }
                   1832:         $form .= '</form>'."\n";
1.235     raeburn  1833:         foreach my $role (@roles_order) {
1.402     raeburn  1834:             my $include;
1.235     raeburn  1835:             if (defined($courseroles{$role})) {
1.402     raeburn  1836:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
                   1837:                     if ($seccount{$role} > 1) {
                   1838:                         $include = 1;
                   1839:                     }
                   1840:                 } else {
                   1841:                     $include = 1;
                   1842:                 }
                   1843:             }
                   1844:             if ($include) {
1.401     raeburn  1845:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
                   1846:                                &Apache::lonnet::plaintext($role,$crstype)]);
1.235     raeburn  1847:             }
                   1848:         }
                   1849:         foreach my $role (sort(keys(%courseroles))) {
                   1850:             if ($role =~ /^cr/) {
1.403     raeburn  1851:                 my $include;
                   1852:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
1.402     raeburn  1853:                     if ($seccount{$role} > 1) {
                   1854:                         $include = 1;
                   1855:                     }
1.403     raeburn  1856:                 } else {
                   1857:                     $include = 1; 
                   1858:                 }
                   1859:                 if ($include) {
                   1860:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
                   1861:                                    &Apache::lonnet::plaintext($role)]);
                   1862:                 }
1.235     raeburn  1863:             }
                   1864:         }
1.401     raeburn  1865:         if (@submenu > 0) {
                   1866:             $switcher = &create_submenu('','',$switchtext,\@submenu);
1.386     raeburn  1867:         }
1.235     raeburn  1868:     }
1.401     raeburn  1869:     return ($js,$form,$switcher);
1.235     raeburn  1870: }
                   1871: 
1.262     raeburn  1872: sub get_all_courseroles {
1.350     raeburn  1873:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351     raeburn  1874:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350     raeburn  1875:             (ref($courseprivs) eq 'HASH')) {
1.262     raeburn  1876:         return;
                   1877:     }
                   1878:     my ($result,$cached) = 
                   1879:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
                   1880:     if (defined($cached)) {
                   1881:         if (ref($result) eq 'HASH') {
                   1882:             if ((ref($result->{'roles'}) eq 'HASH') && 
1.350     raeburn  1883:                 (ref($result->{'seccount'}) eq 'HASH') && 
                   1884:                 (ref($result->{'privs'}) eq 'HASH')) {
1.262     raeburn  1885:                 %{$courseroles} = %{$result->{'roles'}};
                   1886:                 %{$seccount} = %{$result->{'seccount'}};
1.350     raeburn  1887:                 %{$courseprivs} = %{$result->{'privs'}};
1.262     raeburn  1888:                 return;
                   1889:             }
                   1890:         }
                   1891:     }
                   1892:     my %gotnosection;
                   1893:     my %adv_roles =
                   1894:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
                   1895:     foreach my $role (keys(%adv_roles)) {
                   1896:         my ($urole,$usec) = split(/:/,$role);
                   1897:         if (!$gotnosection{$urole}) {
                   1898:             $seccount->{$urole} ++;
                   1899:             $gotnosection{$urole} = 1;
                   1900:         }
                   1901:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
                   1902:             if ($usec ne '') {
                   1903:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
                   1904:                     push(@{$courseroles->{$urole}},$usec);
                   1905:                     $seccount->{$urole} ++;
                   1906:                 }
                   1907:             }
                   1908:         } else {
                   1909:             @{$courseroles->{$urole}} = ();
                   1910:             if ($usec ne '') {
                   1911:                 $seccount->{$urole} ++;
                   1912:                 push(@{$courseroles->{$urole}},$usec);
                   1913:             }
                   1914:         }
1.350     raeburn  1915:         my $area = '/'.$cdom.'/'.$cnum;
                   1916:         if ($usec ne '') {
                   1917:             $area .= '/'.$usec;
                   1918:         }
                   1919:         if ($role =~ /^cr\//) {
                   1920:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
                   1921:         } else {
                   1922:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
                   1923:         }
1.262     raeburn  1924:     }
                   1925:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
                   1926:     @{$courseroles->{'st'}} = ();
1.350     raeburn  1927:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262     raeburn  1928:     if (keys(%sections_count) > 0) {
                   1929:         push(@{$courseroles->{'st'}},keys(%sections_count));
1.350     raeburn  1930:         $seccount->{'st'} = scalar(keys(%sections_count));
1.262     raeburn  1931:     }
1.410     raeburn  1932:     $seccount->{'st'} ++; # Increment for a section-less student role.  
1.262     raeburn  1933:     my $rolehash = {
                   1934:                      'roles'    => $courseroles,
                   1935:                      'seccount' => $seccount,
1.350     raeburn  1936:                      'privs'    => $courseprivs,
1.262     raeburn  1937:                    };
                   1938:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
                   1939:     return;
                   1940: }
                   1941: 
1.235     raeburn  1942: sub jump_to_role {
1.350     raeburn  1943:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
1.239     raeburn  1944:     my %lt = &Apache::lonlocal::texthash(
                   1945:                 this => 'This role has section(s) associated with it.',
                   1946:                 ente => 'Enter a specific section.',
                   1947:                 orlb => 'Enter a specific section, or leave blank for no section.',
                   1948:                 avai => 'Available sections are:',
                   1949:                 youe => 'You entered an invalid section choice:',
1.352     raeburn  1950:                 plst => 'Please try again.',
1.350     raeburn  1951:                 role => 'The role you selected is not permitted to view the current page.',
                   1952:                 swit => 'Switch role, but display Main Menu page instead?',
1.239     raeburn  1953:     );
                   1954:     my $js;
                   1955:     if (ref($courseroles) eq 'HASH') {
                   1956:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
                   1957:               '    var numsec = new Array();'."\n".
                   1958:               '    var rolesections = new Array();'."\n".
                   1959:               '    var rolenames = new Array();'."\n".
                   1960:               '    var roleseclist = new Array();'."\n";
                   1961:         my @items = keys(%{$courseroles});
                   1962:         for (my $i=0; $i<@items; $i++) {
                   1963:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
                   1964:             my ($secs,$secstr);
                   1965:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
                   1966:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
                   1967:                 $secs = join('","',@sections);
                   1968:                 $secstr = join(', ',@sections);
                   1969:             }
                   1970:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
                   1971:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
                   1972:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
                   1973:         }
                   1974:     }
1.350     raeburn  1975:     my $checkroles = 0;
                   1976:     if ($priv && ref($courseprivs) eq 'HASH') {
                   1977:         my (%disallowed,%allowed,@disallow);
                   1978:         foreach my $role (sort(keys(%{$courseprivs}))) {
                   1979:             my $trole;
                   1980:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
                   1981:                 $trole = $1;
                   1982:             }
                   1983:             if (($trole ne '') && ($trole ne 'cm')) {
                   1984:                 if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
                   1985:                     $allowed{$trole} = 1;
                   1986:                 } else {
                   1987:                     $disallowed{$trole} = 1;
                   1988:                 }
                   1989:             }
                   1990:         }
                   1991:         foreach my $trole (keys(%disallowed)) {
                   1992:             unless ($allowed{$trole}) {
                   1993:                 push(@disallow,$trole);
                   1994:             }
                   1995:         }
                   1996:         if (@disallow > 0) {
                   1997:             $checkroles = 1;
                   1998:             $js .= "    var disallow = new Array('".join("','",@disallow)."');\n".
                   1999:                    "    var rolecheck = 1;\n";
                   2000:         }
                   2001:     }
                   2002:     if (!$checkroles) {
                   2003:         $js .=  "    var disallow = new Array();\n".
                   2004:                 "    rolecheck = 0;\n";
                   2005:     }
1.273     droeschl 2006:     return <<"END";
1.235     raeburn  2007: <script type="text/javascript">
1.273     droeschl 2008: //<![CDATA[
1.401     raeburn  2009: function adhocRole(newrole) {
1.239     raeburn  2010:     $js
1.235     raeburn  2011:     if (newrole == '') {
1.350     raeburn  2012:         return;
1.235     raeburn  2013:     } 
1.239     raeburn  2014:     var fullrole = newrole+'./$cdom/$cnum';
                   2015:     var selidx = '';
                   2016:     for (var i=0; i<rolenames.length; i++) {
                   2017:         if (rolenames[i] == newrole) {
                   2018:             selidx = i;
                   2019:         }
                   2020:     }
1.350     raeburn  2021:     if (rolecheck > 0) {
                   2022:         for (var i=0; i<disallow.length; i++) {
                   2023:             if (disallow[i] == newrole) {
                   2024:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
                   2025:                     document.rolechooser.destinationurl.value = '/adm/menu';
                   2026:                 } else {
                   2027:                     return;
                   2028:                 }
                   2029:             }
                   2030:         }
                   2031:     }
1.239     raeburn  2032:     var secok = 1;
                   2033:     var secchoice = '';
                   2034:     if (selidx >= 0) {
                   2035:         if (numsec[selidx] > 1) {
                   2036:             secok = 0;
                   2037:             var numrolesec = rolesections[selidx].length;
                   2038:             var msgidx = numsec[selidx] - numrolesec;
1.339     raeburn  2039:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239     raeburn  2040:             if (secchoice == '') {
                   2041:                 if (msgidx > 0) {
                   2042:                     secok = 1;
                   2043:                 }
                   2044:             } else {
                   2045:                 for (var j=0; j<rolesections[selidx].length; j++) {
                   2046:                     if (rolesections[selidx][j] == secchoice) {
                   2047:                         secok = 1;
                   2048:                     }
                   2049:                 }
                   2050:             }
                   2051:         } else {
                   2052:             if (rolesections[selidx].length == 1) {
                   2053:                 secchoice = rolesections[selidx][0];
                   2054:             }
                   2055:         }
                   2056:     }
                   2057:     if (secok == 1) {
                   2058:         if (secchoice != '') {
                   2059:             fullrole += '/'+secchoice;
                   2060:         }
                   2061:     } else {
                   2062:         if (secchoice != null) {
                   2063:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
                   2064:         }
                   2065:         return;
                   2066:     }
                   2067:     if (fullrole == "$env{'request.role'}") {
1.235     raeburn  2068:         return;
                   2069:     }
                   2070:     itemid = retrieveIndex('gotorole');
                   2071:     if (itemid != -1) {
1.239     raeburn  2072:         document.rolechooser.elements[itemid].name = fullrole;
1.235     raeburn  2073:     }
1.401     raeburn  2074:     document.rolechooser.switchrole.value = fullrole;
1.235     raeburn  2075:     document.rolechooser.selectrole.value = '1';
                   2076:     document.rolechooser.submit();
                   2077:     return;
                   2078: }
                   2079: 
                   2080: function retrieveIndex(item) {
                   2081:     for (var i=0;i<document.rolechooser.elements.length;i++) {
                   2082:         if (document.rolechooser.elements[i].name == item) {
                   2083:             return i;
                   2084:         }
                   2085:     }
                   2086:     return -1;
                   2087: }
1.273     droeschl 2088: // ]]>
1.235     raeburn  2089: </script>
                   2090: END
                   2091: }
                   2092: 
1.350     raeburn  2093: sub required_privs {
                   2094:     my $privs =  {
                   2095:              '/adm/parmset'      => 'opa',
                   2096:              '/adm/courseprefs'  => 'opa',
                   2097:              '/adm/whatsnew'     => 'whn',
                   2098:              '/adm/populate'     => 'cst',
                   2099:              '/adm/trackstudent' => 'vsa',
                   2100:              '/adm/statistics'   => 'vgr',
1.366     raeburn  2101:              '/adm/setblock'     => 'dcm',
1.367     raeburn  2102:              '/adm/coursedocs'   => 'mdc',
1.350     raeburn  2103:            };
                   2104:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364     raeburn  2105:         $privs->{'/adm/classcalc'}   = 'vgr',
                   2106:         $privs->{'/adm/assesscalc'}  = 'vgr',
                   2107:         $privs->{'/adm/studentcalc'} = 'vgr';
1.350     raeburn  2108:     }
                   2109:     return $privs;
                   2110: }
1.235     raeburn  2111: 
1.378     raeburn  2112: sub countdown_timer {
                   2113:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.387     raeburn  2114:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
                   2115:         my ($type,$hastimeleft,$slothastime);
                   2116:         my $now = time;
                   2117:         if ($env{'request.filename'} =~ /\.task$/) {
                   2118:             $type = 'Task';
                   2119:         } else {
                   2120:             $type = 'problem';
                   2121:         }
                   2122:         my ($status,$accessmsg,$slot_name,$slot) =
                   2123:             &Apache::lonhomework::check_slot_access('0',$type);
                   2124:         if ($slot_name ne '') {
                   2125:             if (ref($slot) eq 'HASH') {
                   2126:                 if (($slot->{'starttime'} < $now) &&
                   2127:                     ($slot->{'endtime'} > $now)) {
                   2128:                     $slothastime = 1;
                   2129:                 }
                   2130:             }
                   2131:         }
                   2132:         if ($status ne 'CAN_ANSWER') {
                   2133:             return;
                   2134:         }
1.378     raeburn  2135:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.380     raeburn  2136:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.381     raeburn  2137:         if (@interval > 1) {
                   2138:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
                   2139:             if ($first_access > 0) {
                   2140:                 if ($first_access+$interval[0] > time) {
                   2141:                     $hastimeleft = 1;
                   2142:                 }
                   2143:             }
                   2144:         }
1.380     raeburn  2145:         if (($duedate && $duedate > time) ||
1.387     raeburn  2146:             (!$duedate && $hastimeleft) ||
                   2147:             ($slot_name ne '' && $slothastime)) {
1.379     raeburn  2148:             my ($collapse,$expand,$alttxt,$title,$currdisp);
1.387     raeburn  2149:             if ((@interval > 1 && $hastimeleft) ||
                   2150:                 ($type eq 'Task' && $slothastime)) {
1.378     raeburn  2151:                 $currdisp = 'inline';
                   2152:                 $collapse = '&#9658;&nbsp;';
                   2153:             } else {
                   2154:                 $currdisp = 'none';
                   2155:                 $expand = '&#9668;&nbsp;';
                   2156:             }
                   2157:             unless ($env{'environment.icons'} eq 'iconsonly') {
1.379     raeburn  2158:                 $alttxt = &mt('Timer');
                   2159:                 $title = $alttxt.'&nbsp;';
1.378     raeburn  2160:             }
                   2161:             my $desc = &mt('Countdown to due date/time');
                   2162:             return <<END;
                   2163: 
                   2164: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2165: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
                   2166: $collapse
1.379     raeburn  2167: </span></a>
1.378     raeburn  2168: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
                   2169: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2170: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.379     raeburn  2171: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
1.378     raeburn  2172: END
                   2173:         }
                   2174:     }
                   2175:     return;
                   2176: }
                   2177: 
1.2       www      2178: # ================================================================ Main Program
                   2179: 
1.16      harris41 2180: BEGIN {
1.166     albertel 2181:     if (! defined($readdesk)) {
1.283     droeschl 2182:         {
                   2183:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   2184:             if ( CORE::open( my $config,"<$tabfile") ) {
                   2185:                 while (my $configline=<$config>) {
                   2186:                     $configline=(split(/\#/,$configline))[0];
                   2187:                     $configline=~s/^\s+//;
                   2188:                     chomp($configline);
1.209     www      2189:                     if ($configline=~/^cat\:/) {
1.283     droeschl 2190:                         my @entries=split(/\:/,$configline);
                   2191:                         $category_positions{$entries[2]}=$entries[1];
                   2192:                         $category_names{$entries[2]}=$entries[3];
                   2193:                     } elsif ($configline=~/^prim\:/) {
1.415     raeburn  2194:                         my @entries = (split(/\:/, $configline))[1..6];
1.400     raeburn  2195:                         push(@primary_menu,\@entries);
1.371     raeburn  2196:                     } elsif ($configline=~/^primsub\:/) {
                   2197:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.400     raeburn  2198:                         push(@{$primary_submenu{$parent}},\@entries);
1.283     droeschl 2199:                     } elsif ($configline=~/^scnd\:/) {
                   2200:                         my @entries = (split(/\:/, $configline))[1..5];
1.401     raeburn  2201:                         push(@secondary_menu,\@entries);
1.283     droeschl 2202:                     } elsif ($configline) {
                   2203:                         push(@desklines,$configline);
                   2204:                     }
                   2205:                 }
                   2206:                 CORE::close($config);
                   2207:             }
                   2208:         }
                   2209:         $readdesk='done';
1.2       www      2210:     }
                   2211: }
1.30      www      2212: 
1.1       www      2213: 1;
                   2214: __END__
                   2215: 

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