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

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

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