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

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

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