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

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

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