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

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

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