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

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

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