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

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

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