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

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

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