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

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

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