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

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

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