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

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

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