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

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

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