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

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

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