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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.369.2.55! raeburn     4: # $Id: lonmenu.pm,v 1.369.2.54 2015/01/21 21:09:15 raeburn Exp $
1.11      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       www        28: #
                     29: 
1.244     jms        30: =head1 NAME
                     31: 
                     32: Apache::lonmenu
                     33: 
                     34: =head1 SYNOPSIS
                     35: 
1.369.2.3  raeburn    36: Loads contents of /home/httpd/lonTabs/mydesk.tab, 
                     37: used to generate inline menu, and Main Menu page. 
1.244     jms        38: 
                     39: This is part of the LearningOnline Network with CAPA project
                     40: described at http://www.lon-capa.org.
                     41: 
1.314     droeschl   42: =head1 GLOBAL VARIABLES
                     43: 
                     44: =over
                     45: 
                     46: =item @desklines
                     47: 
                     48: Each element of this array contains a line of mydesk.tab that doesn't start with
                     49: cat, prim or scnd. 
                     50: It gets filled in the BEGIN block of this module.
                     51: 
                     52: =item %category_names
                     53: 
                     54: The keys of this hash are the abbreviations used in mydesk.tab in those lines that 
                     55: start with cat, the values are strings representing titles. 
                     56: It gets filled in the BEGIN block of this module.
                     57: 
                     58: =item %category_members
                     59: 
                     60: TODO 
                     61: 
                     62: =item %category_positions
                     63: 
                     64: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
                     65: start with cat, its values are position vectors (column, row). 
                     66: It gets filled in the BEGIN block of this module.
                     67: 
                     68: =item $readdesk
                     69: 
                     70: Indicates that mydesk.tab has been read. 
                     71: It is set to 'done' in the BEGIN block of this module.
                     72: 
                     73: =item @primary_menu
                     74: 
                     75: The elements of this array reference arrays that are made up of the components
1.369.2.3  raeburn    76: of those lines of mydesk.tab that start with prim:.
1.314     droeschl   77: It is used by primary_menu() to generate the corresponding menu.
                     78: It gets filled in the BEGIN block of this module.
                     79: 
1.369.2.3  raeburn    80: =item %primary_sub_menu
                     81: 
                     82: The keys of this hash reference are the names of items in the primary_menu array 
                     83: which have sub-menus.  For each key, the corresponding value is a reference to
                     84: an array containing components extracted from lines in mydesk.tab which begin
                     85: with primsub:.
                     86: This hash, which is used by primary_menu to generate sub-menus, is populated in
                     87: the BEGIN block.
                     88: 
1.314     droeschl   89: =item @secondary_menu
                     90: 
                     91: The elements of this array reference arrays that are made up of the components
                     92: of those lines of mydesk.tab that start with scnd.
                     93: It is used by secondary_menu() to generate the corresponding menu.
                     94: It gets filled in the BEGIN block of this module.
                     95: 
                     96: =back
                     97: 
1.244     jms        98: =head1 SUBROUTINES
                     99: 
                    100: =over
                    101: 
1.314     droeschl  102: =item prep_menuitems(\@menuitem)
                    103: 
                    104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and 
                    105: secondary_menu().
                    106: 
                    107: =item primary_menu()
                    108: 
1.369.2.42  raeburn   109: This routine evaluates @primary_menu and returns a two item array, 
                    110: with the array elements containing XHTML for the left and right sides of 
                    111: the menu that contains the following links: About, Message, Roles, Help, Logout 
1.314     droeschl  112: @primary_menu is filled within the BEGIN block of this module with 
1.369.2.42  raeburn   113: entries from mydesk.tab
1.314     droeschl  114: 
                    115: =item secondary_menu()
                    116: 
                    117: Same as primary_menu() but operates on @secondary_menu.
                    118: 
1.369.2.6  raeburn   119: =item create_submenu()
                    120: 
                    121: Creates XHTML for unordered list of sub-menu items which belong to a
                    122: particular top-level menu item. Uses hover pseudo class in css to display
                    123: dropdown list when mouse hovers over top-level item. Support for IE6
                    124: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
                    125: level item, which employs jQuery to handle behavior on mouseover.
                    126: 
                    127: Inputs: 4 - (a) link and (b) target for anchor href in top level item,
                    128:             (c) title for text wrapped by anchor tag in top level item.
                    129:             (d) reference to array of arrays of sub-menu items.
                    130: 
1.244     jms       131: =item innerregister()
                    132: 
1.320     droeschl  133: This gets called in order to register a URL in the body of the document
1.244     jms       134: 
1.369.2.17  raeburn   135: =item loadevents()
                    136: 
                    137: =item unloadevents()
                    138: 
                    139: =item startupremote()
                    140: 
                    141: =item setflags()
                    142: 
                    143: =item maincall()
                    144: 
                    145: =item load_remote_msg()
                    146: 
                    147: =item get_menu_name()
                    148: 
                    149: =item reopenmenu()
                    150: 
                    151: =item open()
                    152: 
                    153: Open the menu
                    154: 
1.244     jms       155: =item clear()
                    156: 
                    157: =item switch()
                    158: 
                    159: Switch a button or create a link
                    160: Switch acts on the javascript that is executed when a button is clicked.  
                    161: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
                    162: 
                    163: =item secondlevel()
                    164: 
                    165: =item openmenu()
                    166: 
                    167: =item inlinemenu()
                    168: 
                    169: =item rawconfig()
                    170: 
                    171: =item utilityfunctions()
                    172: 
1.369.2.6  raeburn   173: Output from this routine is a number of javascript functions called by
                    174: items in the inline menu, and in some cases items in the Main Menu page. 
                    175: 
1.244     jms       176: =item serverform()
                    177: 
                    178: =item constspaceform()
                    179: 
                    180: =item get_nav_status()
                    181: 
                    182: =item hidden_button_check()
                    183: 
                    184: =item roles_selector()
                    185: 
                    186: =item jump_to_role()
                    187: 
                    188: =back
                    189: 
                    190: =cut
                    191: 
1.1       www       192: package Apache::lonmenu;
                    193: 
                    194: use strict;
1.152     albertel  195: use Apache::lonnet;
1.47      matthew   196: use Apache::lonhtmlcommon();
1.115     albertel  197: use Apache::loncommon();
1.127     albertel  198: use Apache::lonenc();
1.88      www       199: use Apache::lonlocal;
1.361     raeburn   200: use Apache::lonmsg();
1.207     foxr      201: use LONCAPA qw(:DEFAULT :match);
1.282     amueller  202: use HTML::Entities();
1.369.2.8  raeburn   203: use Apache::lonwishlist();
1.88      www       204: 
1.283     droeschl  205: use vars qw(@desklines %category_names %category_members %category_positions 
1.369.2.5  raeburn   206:             $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
1.88      www       207: 
1.56      www       208: my @inlineremote;
1.38      www       209: 
1.283     droeschl  210: sub prep_menuitem {
1.291     raeburn   211:     my ($menuitem) = @_;
                    212:     return '' unless(ref($menuitem) eq 'ARRAY');
1.283     droeschl  213:     my $link;
                    214:     if ($$menuitem[1]) { # graphical Link
                    215:         $link = "<img class=\"LC_noBorder\""
1.291     raeburn   216:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
                    217:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283     droeschl  218:     } else {             # textual Link
1.291     raeburn   219:         $link = &mt($$menuitem[3]);
                    220:     }
1.316     droeschl  221:     return '<li><a' 
                    222:            # highlighting for new messages
                    223:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
1.325     droeschl  224:            . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
1.283     droeschl  225: }
                    226: 
1.369.2.42  raeburn   227: # primary_menu() evaluates @primary_menu and returns a two item array,
                    228: # with the array elements containing XHTML for the left and right sides of 
                    229: # the menu that contains the following links:
                    230: # Personal, About, Message, Roles, Help, Logout
1.283     droeschl  231: # @primary_menu is filled within the BEGIN block of this module with 
                    232: # entries from mydesk.tab
                    233: sub primary_menu {
1.369.2.42  raeburn   234:     my %menu;
1.283     droeschl  235:     # each element of @primary contains following array:
1.369.2.42  raeburn   236:     # (link url, icon path, alt text, link text, condition, position)
1.319     raeburn   237:     my $public;
                    238:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                    239:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
                    240:         $public = 1;
                    241:     }
1.283     droeschl  242:     foreach my $menuitem (@primary_menu) {
                    243:         # evaluate conditions 
1.296     droeschl  244:         next if    ref($menuitem)       ne 'ARRAY';    #
1.283     droeschl  245:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
1.291     raeburn   246:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
1.283     droeschl  247:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
1.291     raeburn   248:                 && !&Apache::lonmsg::mynewmail();      # 
1.319     raeburn   249:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
                    250:                 && $public;                            ##who should not see all
                    251:                                                        ##links
1.283     droeschl  252:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
1.319     raeburn   253:                 && !$public;                           # only visible to public
                    254:                                                        # users
1.283     droeschl  255:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
1.291     raeburn   256:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
1.283     droeschl  257:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
1.291     raeburn   258:                 && !&Apache::loncommon::show_course(); ##
                    259:         
1.369.2.3  raeburn   260:         my $title = $menuitem->[3];
1.369.2.42  raeburn   261:         my $position = $menuitem->[5];
                    262:         if ($position eq '') {
                    263:             $position = 'right';
                    264:         }
1.369.2.3  raeburn   265:         if (defined($primary_submenu{$title})) {
1.369.2.6  raeburn   266:             my ($link,$target);
1.369.2.3  raeburn   267:             if ($menuitem->[0] ne '') {
                    268:                 $link = $menuitem->[0];
                    269:                 $target = '_top';
                    270:             } else {
                    271:                 $link = '#';
                    272:             }
1.369.2.6  raeburn   273:             my @primsub;
1.369.2.3  raeburn   274:             if (ref($primary_submenu{$title}) eq 'ARRAY') {
1.369.2.6  raeburn   275:                 foreach my $item (@{$primary_submenu{$title}}) {
1.369.2.16  raeburn   276:                     next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'})); 
1.369.2.6  raeburn   277:                     next if ((($item->[2] eq 'portfolio') || 
                    278:                              ($item->[2] eq 'blog')) && 
                    279:                              (!&Apache::lonnet::usertools_access('','',$item->[2],
                    280:                                                            undef,'tools')));
                    281:                     push(@primsub,$item);
                    282:                 }
                    283:                 if (@primsub > 0) {
1.369.2.46  raeburn   284:                     $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
1.369.2.6  raeburn   285:                 } elsif ($link) {
1.369.2.42  raeburn   286:                     $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
1.369.2.3  raeburn   287:                 }
                    288:             }
                    289:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.340     raeburn   290:             if ($public) {
                    291:                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                    292:                 my $defdom = &Apache::lonnet::default_login_domain();
                    293:                 my $to = &Apache::loncommon::build_recipient_list(undef,
                    294:                                                                   'helpdeskmail',
                    295:                                                                   $defdom,$origmail);
                    296:                 if ($to ne '') {
1.369.2.42  raeburn   297:                     $menu{$position} .= &prep_menuitem($menuitem); 
1.340     raeburn   298:                 }
                    299:             } else {
1.369.2.42  raeburn   300:                 $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.340     raeburn   301:             }
1.283     droeschl  302:         } else {
1.369.2.42  raeburn   303:             $menu{$position} .= prep_menuitem($menuitem);
1.283     droeschl  304:         }
1.291     raeburn   305:     }
1.369.2.48  raeburn   306:     my @output = ('','');
                    307:     if ($menu{'left'} ne '') {
                    308:         $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
                    309:     }
                    310:     if ($menu{'right'} ne '') {
                    311:         $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
                    312:     }
                    313:     return @output;
1.283     droeschl  314: }
                    315: 
1.329     droeschl  316: #returns hashref {user=>'',dom=>''} containing:
                    317: #   own name, domain if user is au
                    318: #   name, domain of parent author if user is ca or aa
                    319: #empty return if user is not an author or not on homeserver
                    320: #
                    321: #TODO this should probably be moved somewhere more central
                    322: #since it can be used by different parts of the system
                    323: sub getauthor{
                    324:     return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
                    325: 
                    326:                         #co- or assistent author?
                    327:     my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
                    328:                        ? ($1, $2) #domain, username of the parent author
                    329:                        : @env{ ('request.role.domain', 'user.name') }; #own domain, username
                    330: 
                    331:     # current server == home server?
                    332:     my $home =  &Apache::lonnet::homeserver($user,$dom);
                    333:     foreach (&Apache::lonnet::current_machine_ids()){
                    334:         return {user => $user, dom => $dom} if $_ eq $home;
                    335:     }
                    336: 
                    337:     # if wrong server
                    338:     return;
                    339: }
1.283     droeschl  340: 
                    341: sub secondary_menu {
1.369.2.47  raeburn   342:     my ($httphost) = @_;
1.283     droeschl  343:     my $menu;
                    344: 
1.286     raeburn   345:     my $crstype = &Apache::loncommon::course_type();
1.327     droeschl  346:     my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'} 
                    347:                                                ? "/$env{'request.course.sec'}"
                    348:                                                : '');
                    349:     my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
1.369.2.5  raeburn   350:     my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
1.369.2.44  raeburn   351:     if ($canviewroster eq 'disabled') {
                    352:         undef($canviewroster);
                    353:     }
1.369.2.5  raeburn   354:     my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec);
                    355:     my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
                    356:     my $canviewwnew   = &Apache::lonnet::allowed('whn', $crs_sec);
1.341     www       357:     my $canmodpara    = &Apache::lonnet::allowed('opa', $crs_sec);
1.343     www       358:     my $canvgr        = &Apache::lonnet::allowed('vgr', $crs_sec);
1.369.2.5  raeburn   359:     my $canmgr        = &Apache::lonnet::allowed('mgr', $crs_sec);
1.343     www       360:     my $author        = &getauthor();
1.327     droeschl  361: 
1.369.2.45  raeburn   362:     my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv);
1.369.2.39  raeburn   363:     if ($env{'request.course.id'}) {
                    364:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    365:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.369.2.41  raeburn   366:         unless ($canedit) {
1.369.2.39  raeburn   367:             unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
                    368:                 if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
                    369:                     ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
                    370:                     ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
                    371:                     ($env{'request.course.syllabustime'})) {
                    372:                     $showsyllabus = 1;
                    373:                 }
                    374:             }
                    375:             if ($env{'request.course.feeds'}) {
                    376:                 $showfeeds = 1;
                    377:             }
                    378:         }
1.369.2.45  raeburn   379:         unless ($canmgr) {
                    380:             my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
                    381:             if (keys(%slots) > 0) {
                    382:                 $showresv = 1;
                    383:             }
                    384:         }
1.369.2.39  raeburn   385:     }
                    386: 
1.369.2.31  raeburn   387:     my ($canmodifycoauthor);
                    388:     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
                    389:         my $extent = "$env{'user.domain'}/$env{'user.name'}";
                    390:         if ((&Apache::lonnet::allowed('cca',$extent)) ||
                    391:             (&Apache::lonnet::allowed('caa',$extent))) {
                    392:             $canmodifycoauthor = 1;
                    393:         }
                    394:     }
                    395: 
1.286     raeburn   396:     my %groups = &Apache::lonnet::get_active_groups(
                    397:                      $env{'user.domain'}, $env{'user.name'},
                    398:                      $env{'course.' . $env{'request.course.id'} . '.domain'},
                    399:                      $env{'course.' . $env{'request.course.id'} . '.num'});
1.327     droeschl  400: 
1.369.2.30  raeburn   401:     my ($roleswitcher_js,$roleswitcher_form);
                    402: 
1.283     droeschl  403:     foreach my $menuitem (@secondary_menu) {
                    404:         # evaluate conditions 
1.296     droeschl  405:         next if    ref($menuitem)  ne 'ARRAY';
1.283     droeschl  406:         next if    $$menuitem[4]   ne 'always'
1.369.2.31  raeburn   407:                 && ($$menuitem[4]  ne 'author' && $$menuitem[4] ne 'cca')
1.283     droeschl  408:                 && !$env{'request.course.id'};
                    409:         next if    $$menuitem[4]   =~ /^mdc/
1.286     raeburn   410:                 && !$canedit;
1.369.2.5  raeburn   411:         next if    $$menuitem[4]  eq 'mdcCourse'
                    412:                 && ($crstype eq 'Community');
                    413:         next if    $$menuitem[4]  eq 'mdcCommunity'
                    414:                 && ($crstype eq 'Course');
1.341     www       415:         next if    $$menuitem[4]  eq 'nvgr'
                    416:                 && $canvgr;
                    417:         next if    $$menuitem[4]  eq 'vgr'
                    418:                 && !$canvgr;
1.327     droeschl  419:         next if    $$menuitem[4]   eq 'cst'
                    420:                 && !$canmodifyuser;
1.343     www       421:         next if    $$menuitem[4]   eq 'ncst'
1.369.2.5  raeburn   422:                 && ($canmodifyuser || !$canviewroster);
1.343     www       423:         next if    $$menuitem[4]   eq 'mgr'
                    424:                 && !$canmgr;
1.369.2.45  raeburn   425:         next if    $$menuitem[4]   eq 'showresv'
                    426:                 && !$showresv;
1.327     droeschl  427:         next if    $$menuitem[4]   eq 'whn'
                    428:                 && !$canviewwnew;
                    429:         next if    $$menuitem[4]   eq 'opa'
                    430:                 && !$canmodpara;
1.369.2.5  raeburn   431:         next if    $$menuitem[4]   eq 'nvcg'
                    432:                 && ($canviewgrps || !%groups);
1.369.2.39  raeburn   433:         next if    $$menuitem[4]   eq 'showsyllabus'
                    434:                 && !$showsyllabus;
                    435:         next if    $$menuitem[4]   eq 'showfeeds'
                    436:                 && !$showfeeds;
1.329     droeschl  437:         next if    $$menuitem[4]    eq 'author'
                    438:                 && !$author;
1.369.2.31  raeburn   439:         next if    $$menuitem[4]    eq 'cca'
                    440:                 && !$canmodifycoauthor;
1.283     droeschl  441: 
1.369.2.5  raeburn   442:         my $title = $menuitem->[3];
                    443:         if (defined($secondary_submenu{$title})) {
1.369.2.6  raeburn   444:             my ($link,$target);
1.369.2.5  raeburn   445:             if ($menuitem->[0] ne '') {
                    446:                 $link = $menuitem->[0];
                    447:                 $target = '_top';
                    448:             } else {
                    449:                 $link = '#';
                    450:             }
1.369.2.43  raeburn   451:             my @scndsub;
1.369.2.5  raeburn   452:             if (ref($secondary_submenu{$title}) eq 'ARRAY') {
                    453:                 foreach my $item (@{$secondary_submenu{$title}}) {
                    454:                     if (ref($item) eq 'ARRAY') {
                    455:                         next if ($item->[2] eq 'vgr' && !$canvgr);
                    456:                         next if ($item->[2] eq 'opa' && !$canmodpara);
                    457:                         next if ($item->[2] eq 'cst' && !$canmodifyuser);
                    458:                         next if ($item->[2] eq 'mgr' && !$canmgr);
                    459:                         next if ($item->[2] eq 'vcg' && !$canviewgrps);
1.369.2.41  raeburn   460:                         next if ($item->[2] eq 'mdc' && !$canedit);
1.369.2.5  raeburn   461:                         push(@scndsub,$item); 
                    462:                     }
                    463:                 }
1.369.2.6  raeburn   464:                 if (@scndsub > 0) {
1.369.2.46  raeburn   465:                     $menu .= &create_submenu($link,$target,$title,\@scndsub,1);
1.369.2.41  raeburn   466:                 } elsif ($link ne '#') {
1.369.2.7  raeburn   467:                     $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
1.369.2.5  raeburn   468:                 }
                    469:             }
                    470:         } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283     droeschl  471:             # special treatment for role selector
1.369.2.30  raeburn   472:             ($roleswitcher_js,$roleswitcher_form,my $switcher) =
                    473:                 &roles_selector(
1.283     droeschl  474:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
1.369.2.47  raeburn   475:                         $env{'course.' . $env{'request.course.id'} . '.num'},
                    476:                         $httphost
1.369.2.30  raeburn   477:                 );
                    478:             $menu .= $switcher;
1.296     droeschl  479:         } else {
1.369.2.39  raeburn   480:             if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
                    481:                 my $url = $$menuitem[0];
                    482:                 $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
                    483:                 if (&Apache::lonnet::is_on_map($url)) {
                    484:                     unless ($$menuitem[0] =~ /\?register=1/) {
                    485:                         $$menuitem[0] .= '?register=1';
                    486:                     }
                    487:                 } else {
                    488:                     $$menuitem[0] =~ s{\?register=1}{};
                    489:                 }
                    490:             }
1.296     droeschl  491:             $menu .= &prep_menuitem(\@$menuitem);
1.283     droeschl  492:         }
                    493:     }
                    494:     if ($menu =~ /\[url\].*\[symb\]/) {
1.291     raeburn   495:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
                    496:                              $env{'request.noversionuri'}));
1.283     droeschl  497: 
1.291     raeburn   498:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
                    499:                              $env{'request.symb'})); 
1.283     droeschl  500: 
                    501:         if (    $env{'request.state'} eq 'construct'
                    502:             and (   $env{'request.noversionuri'} eq '' 
                    503:                  || !defined($env{'request.noversionuri'}))) 
                    504:         {
1.359     raeburn   505:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                    506:             ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
1.291     raeburn   507:             $escurl  = &escape($escurl);
1.283     droeschl  508:         }    
                    509:         $menu =~ s/\[url\]/$escurl/g;
                    510:         $menu =~ s/\[symb\]/$escsymb/g;
                    511:     }
1.329     droeschl  512:     $menu =~ s/\[uname\]/$$author{user}/g;
                    513:     $menu =~ s/\[udom\]/$$author{dom}/g;
1.369.2.41  raeburn   514:     if ($env{'request.course.id'}) {  
1.369.2.40  raeburn   515:         $menu =~ s/\[cnum\]/$cnum/g;
                    516:         $menu =~ s/\[cdom\]/$cdom/g;
                    517:     }
1.369.2.22  raeburn   518:     if ($menu) {
                    519:         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
                    520:     }
1.369.2.30  raeburn   521:     if ($roleswitcher_form) {
                    522:         $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
                    523:     }
1.369.2.22  raeburn   524:     return $menu;
1.283     droeschl  525: }
                    526: 
1.369.2.6  raeburn   527: sub create_submenu {
1.369.2.46  raeburn   528:     my ($link,$target,$title,$submenu,$translate) = @_;
1.369.2.6  raeburn   529:     return unless (ref($submenu) eq 'ARRAY');
1.369.2.11  raeburn   530:     my $disptarget;
                    531:     if ($target ne '') {
                    532:         $disptarget = ' target="'.$target.'"';
                    533:     }
1.369.2.42  raeburn   534:     my $name;
                    535:     if ($title eq 'Personal') {
                    536:         if ($env{'user.name'} && $env{'user.domain'}) {
                    537:             $name = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
                    538:         } else {
                    539:             $name = &mt($title);
                    540:         }
                    541:     } else {
                    542:         $name = &mt($title);
                    543:     }
1.369.2.6  raeburn   544:     my $menu = '<li class="LC_hoverable">'.
1.369.2.42  raeburn   545:                '<a href="'.$link.'"'.$disptarget.'>'.
                    546:                '<span class="LC_nobreak">'.$name.
1.369.2.6  raeburn   547:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
                    548:                ' &#9660;</span></span></a>'.
                    549:                '<ul>';
                    550:     my $count = 0;
                    551:     my $numsub = scalar(@{$submenu});
                    552:     foreach my $item (@{$submenu}) {
                    553:         $count ++;
                    554:         if (ref($item) eq 'ARRAY') {
1.369.2.43  raeburn   555:             my $href = $item->[0];
                    556:             if ($href =~ /(aboutme|rss\.html)$/) {
                    557:                 next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
                    558:                 $href =~ s/\[domain\]/$env{'user.domain'}/g;
                    559:                 $href =~ s/\[user\]/$env{'user.name'}/g;
                    560:             }
1.369.2.6  raeburn   561:             my $borderbot;
                    562:             if ($count == $numsub) {
                    563:                 $borderbot = 'border-bottom:1px solid black;';
                    564:             }
1.369.2.50  raeburn   565:             unless (($href eq '') || ($href =~ /^\#/)) {
                    566:                 $target = ' target="_top"';
                    567:             }
1.369.2.6  raeburn   568:             $menu .= '<li style="margin:0;padding:0;'.
1.369.2.50  raeburn   569:                      $borderbot.'"><a href="'.$href.'"'.$target.'>';
1.369.2.46  raeburn   570:             if ($translate) {
                    571:                 $menu .= &mt($item->[1]);
                    572:             } else {
                    573:                 $menu .= $item->[1];
                    574:             }
                    575:             $menu .= '</a></li>';
1.369.2.6  raeburn   576:         }
                    577:     }
                    578:     $menu .= '</ul></li>';
                    579:     return $menu;
                    580: }
                    581: 
1.369.2.17  raeburn   582: sub registerurl {
                    583:     my ($forcereg) = @_;
                    584:     my $result = '';
                    585:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
                    586:     my $force_title='';
                    587:     if ($env{'request.state'} eq 'construct') {
                    588:         $force_title=&Apache::lonxml::display_title();
                    589:     }
1.369.2.25  raeburn   590:     if (($env{'environment.remote'} ne 'on') ||
1.369.2.17  raeburn   591:         ((($env{'request.publicaccess'}) ||
                    592:          (!&Apache::lonnet::is_on_map(
                    593:            &unescape($env{'request.noversionuri'})))) &&
                    594:         (!$forcereg))) {
                    595:         return
                    596:         $result
                    597:        .'<script type="text/javascript">'."\n"
                    598:        .'// <![CDATA['."\n"
                    599:        .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
                    600:        .'// ]]>'."\n"
                    601:        .'</script>'
                    602:        .$force_title;
                    603:     }
                    604: # Graphical display after login only
                    605:     if ($env{'request.registered'} && !$forcereg) { return ''; }
                    606:     $result.=&innerregister($forcereg);
                    607:     return $result.$force_title;
                    608: }
                    609: 
1.40      www       610: sub innerregister {
1.369.2.26  raeburn   611:     my ($forcereg,$bread_crumbs,$group) = @_;
1.152     albertel  612:     my $const_space = ($env{'request.state'} eq 'construct');
1.131     raeburn   613:     my $is_const_dir = 0;
1.120     raeburn   614: 
1.175     albertel  615:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40      www       616: 
1.174     albertel  617:     $env{'request.registered'} = 1;
1.40      www       618: 
1.369.2.25  raeburn   619:     my $noremote = ($env{'environment.remote'} ne 'on');
1.369.2.17  raeburn   620: 
1.177     albertel  621:     undef(@inlineremote);
1.56      www       622: 
1.369.2.17  raeburn   623:     my $reopen=&Apache::lonmenu::reopenmenu();
                    624: 
                    625:     my $newmail='';
                    626: 
                    627:     if (&Apache::lonmsg::newmail() && !$noremote) {
                    628:         # We have new mail and remote is up
                    629:         $newmail= 'swmenu.setstatus("you have","messages");';
                    630:     }
                    631: 
1.369.2.27  raeburn   632:     my ($mapurl,$resurl);
1.369.2.26  raeburn   633: 
1.369.2.27  raeburn   634:     if ($env{'request.course.id'}) {
                    635:         if ($env{'request.symb'}) {
                    636:             ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
                    637:             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
1.267     droeschl  638: 
1.369.2.27  raeburn   639:             my $maptitle = &Apache::lonnet::gettitle($mapurl);
                    640:             my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.267     droeschl  641: 
1.318     droeschl  642: 
                    643: #SD
                    644: #course_type only Course and Community?
                    645: #
1.369.2.27  raeburn   646:             my @crumbs;
                    647:             unless (($forcereg) && 
                    648:                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
                    649:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
                    650:                 @crumbs = ({text  => Apache::loncommon::course_type() 
                    651:                                     . ' Contents', 
                    652:                             href  => "Javascript:gopost('/adm/navmaps','')"});
                    653:             }
                    654:             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
                    655:                 push(@crumbs, {text  => '...',
                    656:                                no_mt => 1});
                    657:             }
                    658: 
                    659:             push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
                    660:                                                        && $maptitle ne 'default.sequence' 
                    661:                                                        && $maptitle ne $coursetitle);
                    662: 
                    663:             push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
                    664:             &Apache::lonhtmlcommon::clear_breadcrumbs();
                    665:             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
                    666:         } else {
                    667:             $resurl = $env{'request.noversionuri'};
                    668:             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
                    669:             my $crstype = &Apache::loncommon::course_type();
                    670:             my $title = &mt('View Resource');
                    671:             if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
                    672:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
                    673:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    674:                 if ($env{'form.title'}) {
                    675:                     $title = $env{'form.title'};
                    676:                 }
                    677:                 my $trail;
                    678:                 if ($env{'form.folderpath'}) {
1.369.2.29  raeburn   679:                     &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
1.369.2.27  raeburn   680:                     ($trail) =
                    681:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    682:                 } else {
                    683:                     &Apache::lonhtmlcommon::add_breadcrumb(
                    684:                     {text  => "Supplemental $crstype Content",
                    685:                      href  => "javascript:gopost('/adm/supplemental','')"});
                    686:                     $title = &mt('View Resource');
                    687:                     ($trail) =
                    688:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    689:                 }
                    690:                 return $trail;
1.369.2.39  raeburn   691:             } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
                    692:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    693:                 &prepare_functions('/public'.$courseurl."/syllabus",
                    694:                                    $forcereg,$group,undef,undef,1);
                    695:                 $title = &mt('Syllabus File');
                    696:                 my ($trail) =
                    697:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    698:                 return $trail;
1.369.2.27  raeburn   699:             }
                    700:             unless ($env{'request.state'} eq 'construct') {
                    701:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    702:                 &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
                    703:             }
                    704:         }
1.369.2.26  raeburn   705:     } elsif (! $const_space){
1.328     droeschl  706:         #a situation when we're looking at a resource outside of context of a 
                    707:         #course or construction space (e.g. with cumulative rights)
                    708:         &Apache::lonhtmlcommon::clear_breadcrumbs();
1.369.2.26  raeburn   709:         unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                    710:             &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
                    711:         }
1.65      www       712:     }
1.369.2.17  raeburn   713:     my $timesync   = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
1.41      www       714: # =============================================================================
                    715: # ============================ This is for URLs that actually can be registered
1.369.2.18  raeburn   716:     if ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
1.369.2.17  raeburn   717:                        || ($forcereg)) {
1.369.2.28  raeburn   718: 
                    719:         my %swtext;
                    720:         if ($noremote) {
                    721:             %swtext = &get_inline_text();
                    722:         } else {
                    723:             %swtext = &get_rc_text();
                    724:         }
                    725:         my $hwkadd='';
                    726: 
                    727:         my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                    728:             $forceview,$editbutton);
                    729:         if (($resurl =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) ||
                    730:             ($env{'request.role'} !~/^(aa|ca|au)/)) {
1.369.2.37  raeburn   731:             if (($env{'environment.remote'} eq 'on') && ($env{'request.symb'})) {
                    732:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    733:             }
1.369.2.28  raeburn   734:             $editbutton = &prepare_functions($resurl,$forcereg,$group);
                    735:         }
                    736:         if ($editbutton eq '') {
1.369.2.29  raeburn   737:             $editbutton = &clear(6,1);
1.369.2.28  raeburn   738:         }
1.369.2.26  raeburn   739: 
                    740: #
                    741: # This applies in course context
                    742: #
1.369.2.28  raeburn   743:         if ($env{'request.course.id'}) {
                    744:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    745:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    746:             $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                    747:             my @privs;
                    748:             if ($env{'request.symb'} ne '') {
                    749:                 if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
                    750:                     push(@privs,('mgr','vgr'));
                    751:                 }
                    752:                 push(@privs,'opa');
                    753:             }
                    754:             foreach my $priv (@privs) {
                    755:                 $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                    756:                 if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                    757:                     $perms{$priv} =
                    758:                         &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                    759:                 }
1.258     raeburn   760:             }
1.369.2.26  raeburn   761: #
                    762: # Determine whether or not to show Grades and Submissions buttons
                    763: #
1.369.2.28  raeburn   764:             if ($env{'request.symb'} ne '' &&
                    765:                 $env{'request.filename'}=~/$LONCAPA::assess_re/) {
                    766:                 if ($perms{'mgr'}) {
                    767:                     $hwkadd.= &switch('','',7,2,'pgrd.png','Content Grades',
                    768:                                       'grades[_4]',
                    769:                                       "gocmd('/adm/grades','gradingmenu')",
                    770:                                       'Content Grades');
                    771:                 } elsif ($perms{'vgr'}) {
                    772:                     $hwkadd .= &switch('','',7,2,'subm.png','Content Submissions',
                    773:                                        'missions[_1]',
                    774:                                        "gocmd('/adm/grades','submission')",
                    775:                                        'Content Submissions');
                    776:                 }
                    777:             }
                    778:             if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
                    779:                 $hwkadd .= &switch('','',7,3,'pparm.png','Content Settings',
                    780:                                    'parms[_2]',"gocmd('/adm/parmset','set')",
                    781:                                    'Content Settings');
                    782:             }
1.369.2.26  raeburn   783: # End grades/submissions check
                    784: 
                    785: #
                    786: # This applies to items inside a folder/page modifiable in the course.
                    787: #
1.369.2.28  raeburn   788:             if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
                    789:                 my $text = 'Edit Folder';
                    790:                 if (($mapurl =~ /\.page$/) ||
                    791:                     ($env{'request.symb'}=~
                    792:                          m{uploaded/$cdom/$cnum/default_\d+\.page$}))  {
                    793:                     $text = 'Edit Page';
                    794:                 }
                    795:                 $hwkadd .= &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
                    796:                                    "gocmd('/adm/coursedocs','direct')",
                    797:                                    'Folder/Page Content');
                    798:             }
1.369.2.26  raeburn   799: # End modifiable folder/page container check
1.369.2.28  raeburn   800:         }
1.369.2.26  raeburn   801: # End course context
                    802: 
1.41      www       803: # Prepare the rest of the buttons
1.369.2.21  raeburn   804:         my ($menuitems,$got_prt,$got_wishlist,$cstritems);
1.120     raeburn   805:         if ($const_space) {
1.274     www       806: #
                    807: # We are in construction space
                    808: #
1.353     www       809: 
1.355     raeburn   810:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.353     www       811: 	    my ($udom,$uname,$thisdisfn) =
1.355     raeburn   812: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1.353     www       813:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1.131     raeburn   814:             if ($currdir =~ m-/$-) {
                    815:                 $is_const_dir = 1;
1.369.2.55! raeburn   816:                 if ($thisdisfn eq '') {
        !           817:                     $is_const_dir = 2;
        !           818:                 }
1.131     raeburn   819:             } else {
1.267     droeschl  820:                 $currdir =~ s|[^/]+$||;
1.200     foxr      821: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208     albertel  822: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274     www       823: #
                    824: # Probably should be in mydesk.tab
                    825: #
1.131     raeburn   826:                 $menuitems=(<<ENDMENUITEMS);
1.369.2.21  raeburn   827: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
                    828: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
                    829: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
                    830: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
                    831: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1.120     raeburn   832: ENDMENUITEMS
1.369.2.21  raeburn   833:                 unless ($noremote) {
                    834:                     $cstritems = $menuitems;
                    835:                     undef($menuitems);
                    836:                 }
1.131     raeburn   837:             }
1.369.2.28  raeburn   838:             if (ref($bread_crumbs) eq 'ARRAY') {
                    839:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    840:                 foreach my $crumb (@{$bread_crumbs}){
                    841:                      &Apache::lonhtmlcommon::add_breadcrumb($crumb);
1.308     raeburn   842:                 }
1.369.2.28  raeburn   843:             }
1.203     foxr      844:         } elsif ( defined($env{'request.course.id'}) && 
                    845: 		 $env{'request.symb'} ne '' ) {
1.274     www       846: #
1.369.2.16  raeburn   847: # We are in a course and looking at a registered URL
1.274     www       848: # Should probably be in mydesk.tab
                    849: #
1.369.2.19  raeburn   850: 
1.120     raeburn   851: 	    $menuitems=(<<ENDMENUITEMS);
1.41      www       852: c&3&1
1.369.2.19  raeburn   853: s&2&1&back.png&$swtext{'back'}&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
                    854: s&2&3&forw.png&$swtext{'forw'}&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
1.77      www       855: c&6&3
                    856: c&8&1
                    857: c&8&2
1.369.2.19  raeburn   858: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.41      www       859: ENDMENUITEMS
1.369.2.16  raeburn   860:             $got_prt = 1;
                    861:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
                    862:                 && (!$env{'request.enc'})) {
1.369.2.8  raeburn   863:                 # wishlist is only available for users with access to resource-pool
                    864:                 # and links can only be set for resources within the resource-pool
                    865:                 $menuitems .= (<<ENDMENUITEMS);
1.369.2.54  raeburn   866: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink('',currentURL)&Save a link for this resource in my personal Stored Links repository&&1
1.369.2.8  raeburn   867: ENDMENUITEMS
1.369.2.16  raeburn   868:                 $got_wishlist = 1;
1.369.2.8  raeburn   869:             }
1.216     albertel  870: 
1.243     tempelho  871: my $currentURL = &Apache::loncommon::get_symb();
                    872: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
                    873: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
                    874: $menuitems.="s&9&3&";
                    875: if(length($annotation) > 0){
1.317     droeschl  876: 	$menuitems.="anot2.png";
1.243     tempelho  877: }else{
1.317     droeschl  878: 	$menuitems.="anot.png";
1.243     tempelho  879: }
1.369.2.19  raeburn   880: $menuitems.="&$swtext{'anot'}&tations[_1]&annotate()&";
1.243     tempelho  881: $menuitems.="Make notes and annotations about this resource&&1\n";
1.369.2.52  raeburn   882: my $is_mobile;
                    883: if ($env{'browser.mobile'}) {
                    884:     $is_mobile = 1;
                    885: }
1.243     tempelho  886: 
1.323     raeburn   887:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1.369.2.15  raeburn   888: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
1.216     albertel  889: 		    $menuitems.=(<<ENDREALRES);
1.369.2.52  raeburn   890: s&6&3&catalog.png&$swtext{'catalog'}&info[_1]&catalog_info('$is_mobile')&Show Metadata
1.216     albertel  891: ENDREALRES
                    892:                 }
1.369.2.48  raeburn   893:                 unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
                    894:                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) { 
1.369.2.14  raeburn   895: 	            $menuitems.=(<<ENDREALRES);
1.369.2.19  raeburn   896: s&8&1&eval.png&$swtext{'eval'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1.369.2.14  raeburn   897: ENDREALRES
                    898:                 }
1.369.2.48  raeburn   899:                 unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
                    900:                     $menuitems.=(<<ENDREALRES);
1.369.2.19  raeburn   901: s&8&2&fdbk.png&$swtext{'fdbk'}&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1.77      www       902: ENDREALRES
1.369.2.48  raeburn   903:                 }
1.120     raeburn   904: 	    }
                    905:         }
1.203     foxr      906: 	if ($env{'request.uri'} =~ /^\/res/) {
1.369.2.16  raeburn   907:             unless ($got_prt) {
                    908: 	        $menuitems .= (<<ENDMENUITEMS);
1.369.2.19  raeburn   909: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.203     foxr      910: ENDMENUITEMS
1.369.2.16  raeburn   911:                 $got_prt = 1;
                    912:             }
                    913:             unless ($got_wishlist) {
                    914:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
                    915:                     # wishlist is only available for users with access to resource-pool
                    916:                     $menuitems .= (<<ENDMENUITEMS);
1.369.2.54  raeburn   917: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink('',currentURL)&Save a link for this resource in your personal Stored Links repository&&1
1.369.2.8  raeburn   918: ENDMENUITEMS
1.369.2.16  raeburn   919:                     $got_wishlist = 1;
1.369.2.17  raeburn   920:                 }
1.369.2.8  raeburn   921:             }
1.203     foxr      922: 	}
1.369.2.20  raeburn   923:         unless ($got_prt) {
                    924:             $menuitems .= (<<ENDMENUITEMS);
                    925: c&8&3
                    926: ENDMENUITEMS
                    927:         }
                    928:         unless ($got_wishlist) {
                    929:             $menuitems .= (<<ENDMENUITEMS);
                    930: c&9&1
                    931: ENDMENUITEMS
                    932:         }
1.41      www       933:         my $buttons='';
                    934:         foreach (split(/\n/,$menuitems)) {
                    935: 	    my ($command,@rest)=split(/\&/,$_);
1.220     raeburn   936:             my $idx=10*$rest[0]+$rest[1];
                    937:             if (&hidden_button_check() eq 'yes') {
                    938:                 if ($idx == 21 ||$idx == 23) {
                    939:                     $buttons.=&switch('','',@rest);
                    940:                 } else {
                    941:                     $buttons.=&clear(@rest);
                    942:                 }
                    943:             } else {  
                    944:                 if ($command eq 's') {
                    945: 	            $buttons.=&switch('','',@rest);
                    946:                 } else {
                    947:                     $buttons.=&clear(@rest);
                    948:                 }
1.41      www       949:             }
                    950:         }
1.369.2.17  raeburn   951:         if ($noremote) {
1.148     albertel  952: 	    my $addremote=0;
1.267     droeschl  953: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.369.2.17  raeburn   954:             if ($addremote) {
1.301     droeschl  955: 
1.369.2.17  raeburn   956:                 &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301     droeschl  957: 
1.369.2.17  raeburn   958:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
                    959:                     'navigation', @inlineremote[21,23]);
                    960: 
                    961:                 my $countdown = &countdown_timer();
                    962:                 if (&hidden_button_check() eq 'yes') {
                    963:                     if ($countdown) {
                    964:                         &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
                    965:                     }
                    966:                 } else {
                    967:                     my @tools = @inlineremote[93,91,81,82,83];
                    968:                     if ($countdown) {
                    969:                         unshift(@tools,$countdown);
                    970:                     }
                    971:                     &Apache::lonhtmlcommon::add_breadcrumb_tool(
                    972:                         'tools',@tools);
1.312     droeschl  973: 
1.369.2.17  raeburn   974:                     #publish button in construction space
                    975:                     if ($env{'request.state'} eq 'construct'){
                    976:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                    977:                             'advtools', $inlineremote[63]);
                    978:                     } else {
                    979:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                    980:                             'tools', $inlineremote[63]);
                    981:                     }
1.369.2.26  raeburn   982:                     &advtools_crumbs(@inlineremote);
1.369.2.17  raeburn   983:                 }
1.369.2.10  raeburn   984:             }
1.369.2.55! raeburn   985:             my ($topic_help,$topic_help_text);
        !           986:             if ($is_const_dir == 2) {
        !           987:                 if ((($ENV{'SERVER_PORT'} == 443) ||
        !           988:                      ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) &&
        !           989:                      (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
        !           990:                     $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
        !           991:                                  'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
        !           992:                     $topic_help_text = 'About WebDAV access';
        !           993:                 }
        !           994:             }
1.369.2.18  raeburn   995:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
1.369.2.55! raeburn   996:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
1.369.2.18  raeburn   997:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
                    998: 
1.369.2.10  raeburn   999:         } else {
1.369.2.21  raeburn  1000:             my $cstrcrumbs;
                   1001:             if ($const_space) {
                   1002:                 foreach (split(/\n/,$cstritems)) {
                   1003:                     my ($command,@rest)=split(/\&/,$_);
                   1004:                     my $idx=10*$rest[0]+$rest[1];
                   1005:                     &switch('','',@rest);
                   1006:                 }
                   1007:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('advtools',
                   1008:                                                             @inlineremote[63,61,71,72]);
                   1009: 
                   1010:                 $cstrcrumbs = &Apache::lonhtmlcommon::scripttag('', 'start')
                   1011:                              .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
                   1012:                              .&Apache::lonhtmlcommon::scripttag('', 'end');
                   1013:             }
1.369.2.17  raeburn  1014:             my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
                   1015:             $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
                   1016:             my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
                   1017:             my $navstatus=&get_nav_status();
                   1018:             my $clearcstr;
1.313     droeschl 1019: 
1.369.2.17  raeburn  1020:             if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
                   1021:             return <<ENDREGTHIS;
                   1022: 
                   1023: <script type="text/javascript">
                   1024: // <![CDATA[
                   1025: // BEGIN LON-CAPA Internal
                   1026: var swmenu=null;
                   1027: 
                   1028:     function LONCAPAreg() {
                   1029:           swmenu=$reopen;
                   1030:           swmenu.clearTimeout(swmenu.menucltim);
                   1031:           $timesync
                   1032:           $newmail
                   1033:           $buttons
                   1034:           swmenu.currentURL="$requri";
                   1035:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
                   1036:           swmenu.currentSymb="$cursymb";
                   1037:           swmenu.reloadSymb="$cursymb";
                   1038:           swmenu.currentStale=0;
                   1039:           $navstatus
                   1040:           $hwkadd
                   1041:           $editbutton
                   1042:     }
                   1043: 
                   1044:     function LONCAPAstale() {
                   1045:           swmenu=$reopen
                   1046:           swmenu.currentStale=1;
                   1047:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
                   1048:              swmenu.switchbutton
                   1049:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
                   1050:           }
                   1051:           swmenu.clearbut(7,2);
                   1052:           swmenu.clearbut(7,3);
                   1053:           swmenu.menucltim=swmenu.setTimeout(
                   1054:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
                   1055:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
                   1056:                           2000);
                   1057:       }
                   1058: 
                   1059: // END LON-CAPA Internal
                   1060: // ]]>
                   1061: </script>
1.369.2.21  raeburn  1062: 
                   1063: $cstrcrumbs
1.369.2.17  raeburn  1064: ENDREGTHIS
1.301     droeschl 1065:         }
1.369.2.18  raeburn  1066:     } else {
                   1067:        unless ($noremote) {
                   1068: # Not registered, graphical
                   1069:            return (<<ENDDONOTREGTHIS);
                   1070: 
                   1071: <script type="text/javascript">
                   1072: // <![CDATA[
                   1073: // BEGIN LON-CAPA Internal
                   1074: var swmenu=null;
1.38      www      1075: 
1.369.2.18  raeburn  1076:     function LONCAPAreg() {
                   1077:           swmenu=$reopen
                   1078:           $timesync
                   1079:           swmenu.currentStale=1;
                   1080:           swmenu.clearbut(2,1);
                   1081:           swmenu.clearbut(2,3);
                   1082:           swmenu.clearbut(8,1);
                   1083:           swmenu.clearbut(8,2);
                   1084:           swmenu.clearbut(8,3);
1.369.2.20  raeburn  1085:           swmenu.clearbut(9,1);
1.369.2.18  raeburn  1086:           if (swmenu.currentURL) {
                   1087:              swmenu.switchbutton
                   1088:               (3,1,'reload.gif','return','location','go(currentURL)');
                   1089:           } else {
                   1090:               swmenu.clearbut(3,1);
                   1091:           }
                   1092:     }
                   1093: 
                   1094:     function LONCAPAstale() {
                   1095:     }
                   1096: 
                   1097: // END LON-CAPA Internal
                   1098: // ]]>
                   1099: </script>
                   1100: ENDDONOTREGTHIS
                   1101: 
                   1102:         }
                   1103:         return '';
                   1104:     }
1.38      www      1105: }
                   1106: 
1.369.2.19  raeburn  1107: sub get_inline_text {
                   1108:     my %text = (
                   1109:                  pgrd     => 'Content Grades',
                   1110:                  subm     => 'Content Submissions',
                   1111:                  pparm    => 'Content Settings',
                   1112:                  docs     => 'Folder/Page Content',
                   1113:                  pcstr    => 'Edit',
                   1114:                  prt      => 'Print',
                   1115:                  alnk     => 'Stored Links',
                   1116:                  anot     => 'Notes',
                   1117:                  catalog  => 'Info',
                   1118:                  eval     => 'Evaluate',
                   1119:                  fdbk     => 'Feedback',
                   1120:     );
                   1121:     return %text;
                   1122: }
                   1123: 
                   1124: sub get_rc_text {
                   1125:     my %text = (
                   1126:                    pgrd    => 'problem[_1]',
                   1127:                    subm    => 'view sub-[_1]',
                   1128:                    pparm   => 'problem[_2]',
                   1129:                    pcstr   => 'edit[_1]',
                   1130:                    prt     => 'prepare[_1]',
                   1131:                    back    => 'backward[_1]',
                   1132:                    forw    => 'forward[_1]',
                   1133:                    alnk    => 'add to[_1]',
                   1134:                    anot    => 'anno-[_1]',
                   1135:                    catalog => 'catalog[_2]',
                   1136:                    eval    => 'evaluate[_1]',
                   1137:                    fdbk    => 'feedback[_1]',
                   1138:     );
                   1139:     return %text;
                   1140: }
                   1141: 
1.369.2.17  raeburn  1142: sub loadevents() {
                   1143:     if ($env{'request.state'} eq 'construct' ||
                   1144:         $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
                   1145:     return 'LONCAPAreg();';
                   1146: }
                   1147: 
                   1148: sub unloadevents() {
                   1149:     if ($env{'request.state'} eq 'construct' ||
                   1150:         $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
                   1151:     return 'LONCAPAstale();';
                   1152: }
                   1153: 
1.369.2.1  raeburn  1154: sub startupremote {
                   1155:     my ($lowerurl)=@_;
1.369.2.17  raeburn  1156:     unless ($env{'environment.remote'} eq 'on') {
                   1157:         return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
1.369.2.1  raeburn  1158:     }
                   1159: #
                   1160: # The Remote actually gets launched!
                   1161: #
                   1162:     my $configmenu=&rawconfig();
                   1163:     my $esclowerurl=&escape($lowerurl);
                   1164:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
                   1165:     return(<<ENDREMOTESTARTUP);
                   1166: <script type="text/javascript">
                   1167: // <![CDATA[
                   1168: var timestart;
                   1169: function wheelswitch() {
                   1170:     if (typeof(document.wheel) != 'undefined') {
                   1171:         if (typeof(document.wheel.spin) != 'undefined') {
                   1172:             var date=new Date();
                   1173:             var waited=Math.round(30-((date.getTime()-timestart)/1000));
                   1174:             document.wheel.spin.value=$message;
                   1175:         }
                   1176:     }
                   1177:    if (window.status=='|') {
                   1178:       window.status='/';
                   1179:    } else {
                   1180:       if (window.status=='/') {
                   1181:          window.status='-';
                   1182:       } else {
                   1183:          if (window.status=='-') {
                   1184:             window.status='\\\\';
                   1185:          } else {
                   1186:             if (window.status=='\\\\') { window.status='|'; }
                   1187:          }
                   1188:       }
                   1189:    }
                   1190: }
                   1191: 
                   1192: // ---------------------------------------------------------- The wait function
                   1193: var canceltim;
                   1194: function wait() {
                   1195:    if ((menuloaded==1) || (tim==1)) {
                   1196:       window.status='Done.';
                   1197:       if (tim==0) {
                   1198:          clearTimeout(canceltim);
                   1199:          $configmenu
                   1200:          window.location='$lowerurl';
                   1201:       } else {
                   1202:           window.location='/adm/remote?action=collapse&url=$esclowerurl';
                   1203:       }
                   1204:    } else {
                   1205:       wheelswitch();
                   1206:       setTimeout('wait();',200);
                   1207:    }
                   1208: }
                   1209: 
                   1210: function main() {
                   1211:    canceltim=setTimeout('tim=1;',30000);
                   1212:    window.status='-';
                   1213:    var date=new Date();
                   1214:    timestart=date.getTime();
                   1215:    wait();
                   1216: }
                   1217: 
                   1218: // ]]>
                   1219: </script>
                   1220: ENDREMOTESTARTUP
                   1221: }
                   1222: 
                   1223: sub setflags() {
                   1224:     return(<<ENDSETFLAGS);
                   1225: <script type="text/javascript">
                   1226: // <![CDATA[
                   1227:     menuloaded=0;
                   1228:     tim=0;
                   1229: // ]]>
                   1230: </script>
                   1231: ENDSETFLAGS
                   1232: }
                   1233: 
                   1234: sub maincall() {
1.369.2.17  raeburn  1235:     unless ($env{'environment.remote'} eq 'on') { return ''; }
1.369.2.1  raeburn  1236:     return(<<ENDMAINCALL);
                   1237: <script type="text/javascript">
                   1238: // <![CDATA[
                   1239:     main();
                   1240: // ]]>
                   1241: </script>
                   1242: ENDMAINCALL
                   1243: }
                   1244: 
                   1245: sub load_remote_msg {
                   1246:     my ($lowerurl)=@_;
                   1247: 
1.369.2.17  raeburn  1248:     unless ($env{'environment.remote'} eq 'on') { return ''; }
1.369.2.1  raeburn  1249: 
                   1250:     my $esclowerurl=&escape($lowerurl);
                   1251:     my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
                   1252:                 ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
                   1253:                 ,'</a>');
                   1254:     return(<<ENDREMOTEFORM);
                   1255: <p>
                   1256: <form name="wheel">
                   1257: <input name="spin" type="text" size="60" />
                   1258: </form>
                   1259: </p>
                   1260: <p>$link</p>
                   1261: ENDREMOTEFORM
                   1262: }
                   1263: 
                   1264: sub get_menu_name {
                   1265:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
                   1266:     $hostid =~ s/\W//g;
                   1267:     return 'LCmenu'.$hostid;
                   1268: }
                   1269: 
                   1270: 
                   1271: sub reopenmenu {
1.369.2.17  raeburn  1272:    unless ($env{'environment.remote'} eq 'on') { return ''; }
1.369.2.1  raeburn  1273:    my $menuname = &get_menu_name();
                   1274:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                   1275:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
                   1276: }
                   1277: 
                   1278: 
                   1279: sub open {
                   1280:     my $returnval='';
1.369.2.17  raeburn  1281:     unless ($env{'environment.remote'} eq 'on') {
1.369.2.1  raeburn  1282:         return
                   1283:         '<script type="text/javascript">'."\n"
                   1284:        .'// <![CDATA['."\n"
                   1285:        .'self.name="loncapaclient";'."\n"
                   1286:        .'// ]]>'."\n"
                   1287:        .'</script>';
                   1288:     }
                   1289:     my $menuname = &get_menu_name();
                   1290: 
                   1291: #    unless (shift eq 'unix') {
                   1292: # resizing does not work on linux because of virtual desktop sizes
                   1293: #       $returnval.=(<<ENDRESIZE);
                   1294: #if (window.screen) {
                   1295: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
                   1296: #    self.moveTo(190,15);
                   1297: #}
                   1298: #ENDRESIZE
                   1299: #    }
                   1300:     $returnval=(<<ENDOPEN);
                   1301: // <![CDATA[
                   1302: window.status='Opening LON-CAPA Remote Control';
                   1303: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
                   1304: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
                   1305: self.name='loncapaclient';
                   1306: // ]]>
                   1307: ENDOPEN
                   1308:     return '<script type="text/javascript">'.$returnval.'</script>';
                   1309: }
                   1310: 
1.369.2.26  raeburn  1311: sub get_editbutton {
                   1312:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
1.369.2.27  raeburn  1313:     my $jscall;
                   1314:     if (($forceview) && ($env{'form.todocs'})) {
                   1315:         my ($folderpath,$command);
                   1316:         if ($env{'request.symb'}) {
                   1317:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
                   1318:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
                   1319:             $folderpath = $env{'form.folderpath'};
                   1320:             $command = '&forcesupplement=1';
                   1321:         }
                   1322:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
                   1323:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
                   1324:     } else {
                   1325:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
                   1326:                                                 $forceedit,$forcereg,$env{'request.symb'},
                   1327:                                                 &escape($env{'form.folderpath'}),
                   1328:                                                 &escape($env{'form.title'}),$env{'form.idx'},
                   1329:                                                 &escape($env{'form.suppurl'},$env{'form.todocs'}));
                   1330:     }
1.369.2.26  raeburn  1331:     if ($jscall) {
                   1332:         my $icon = 'pcstr.png';
                   1333:         my $label = 'Edit';
                   1334:         if ($forceview) {
                   1335:             $icon = 'tolastloc.png';
                   1336:             $label = 'Exit Editing';
                   1337:         }
1.369.2.37  raeburn  1338:         my $infunc = 1;
                   1339:         my $clearbutton;
                   1340:         if ($env{'environment.remote'} eq 'on') {
                   1341:             if ($cfile =~ m{^/priv/}) {
                   1342:                 undef($infunc);
                   1343:                 $label = 'edit';
                   1344:             } else {
                   1345:                 $clearbutton = 1;
                   1346:             }
                   1347:         }
                   1348:         my $editor = &switch('','',6,1,$icon,$label,'resource[_2]',
                   1349:                              $jscall,"Edit this resource",'','',$infunc);
                   1350:         if ($infunc) {
                   1351:             return 1;
                   1352:         } elsif ($clearbutton) {
                   1353:             return &clear(6,1);
                   1354:         } else {
                   1355:             return $editor;
                   1356:         }
1.369.2.26  raeburn  1357:     }
                   1358:     return;
                   1359: }
                   1360: 
                   1361: sub prepare_functions {
1.369.2.37  raeburn  1362:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$forbodytag) = @_;
1.369.2.26  raeburn  1363:     unless ($env{'request.registered'}) {
                   1364:         undef(@inlineremote);
                   1365:     }
                   1366:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                   1367:         $forceview);
                   1368: 
                   1369:     if ($env{'request.course.id'}) {
                   1370:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1371:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1372:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                   1373:     }
                   1374: 
                   1375:     my $editbutton = '';
                   1376: #
                   1377: # Determine whether or not to display 'Edit' icon/button
                   1378: #
                   1379:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
                   1380:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.369.2.27  raeburn  1381:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1382:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1383:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1384:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                   1385:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.369.2.26  raeburn  1386:                                           $forceedit,$forceview,$forcereg);
                   1387:         }
1.369.2.27  raeburn  1388:     } elsif ((!$env{'request.course.id'}) &&
1.369.2.26  raeburn  1389:              ($env{'user.author'}) && ($env{'request.filename'}) &&
                   1390:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
                   1391: #
                   1392: # Currently do not have the role of author or co-author.
                   1393: # Do we have authoring privileges for the resource?
                   1394: #
                   1395:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1396:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1397:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1398:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1399:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                   1400:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1401:                                           $forceedit,$forceview,$forcereg);
                   1402:         }
                   1403:     } elsif ($env{'request.course.id'}) {
                   1404: #
                   1405: # This applies in course context
                   1406: #
1.369.2.39  raeburn  1407:         if (($perms{'mdc'}) &&
                   1408:             (($resurl eq "/public/$cdom/$cnum/syllabus") ||
                   1409:             ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
                   1410:             $cfile = $resurl;
                   1411:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
                   1412:             if ($env{'form.forceedit'}) {
                   1413:                 $forceview = 1;
1.369.2.26  raeburn  1414:             } else {
1.369.2.39  raeburn  1415:                 $forceedit = 1;
1.369.2.26  raeburn  1416:             }
1.369.2.39  raeburn  1417:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1418:                                           $forceedit,$forceview,$forcereg);
1.369.2.27  raeburn  1419:         } elsif (($resurl eq '/adm/extresedit') &&
                   1420:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
                   1421:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1422:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1423:                                                $env{'form.symb'});
                   1424:             if ($cfile ne '') {
                   1425:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1426:                                               $forceedit,$forceview,$forcereg,
                   1427:                                               $env{'form.title'},$env{'form.suppurl'});
                   1428:             }
1.369.2.32  raeburn  1429:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
                   1430:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
                   1431:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1432:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1433:                                                $env{'form.symb'});
                   1434:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1435:                                           $forceedit,$forceview,$forcereg);
1.369.2.31  raeburn  1436:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
                   1437:                  ($resurl ne '/cgi-bin/printout.pl')) {
1.369.2.26  raeburn  1438:             if ($env{'request.filename'}) {
                   1439:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1440:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1441:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1442:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1443:                 if ($cfile ne '') {
                   1444:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1445:                                                   $forceedit,$forceview,$forcereg);
                   1446:                 }
                   1447:             }
                   1448:         }
                   1449:     }
                   1450: # End determination of 'Edit' icon/button display
                   1451: 
                   1452:     if ($env{'request.course.id'}) {
1.369.2.27  raeburn  1453: # This applies to about me page for users in a course
1.369.2.29  raeburn  1454:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.369.2.26  raeburn  1455:             my ($sdom,$sname) = ($1,$2);
                   1456:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
                   1457:                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
                   1458:                         '',
1.369.2.42  raeburn  1459:                         "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
1.369.2.37  raeburn  1460:                             'Send message to specific user','','',1);
1.369.2.26  raeburn  1461:             }
1.369.2.27  raeburn  1462:             my $hideprivileged = 1;
                   1463:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
                   1464:                                            $hideprivileged)) {
1.369.2.26  raeburn  1465:                 foreach my $priv ('vsa','vgr','srm') {
                   1466:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                   1467:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                   1468:                         $perms{$priv} =
                   1469:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                   1470:                     }
                   1471:                 }
                   1472:                 if ($perms{'vsa'}) {
                   1473:                     &switch('','',6,5,'trck-22x22.png','Activity',
                   1474:                             '',
                   1475:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
1.369.2.37  raeburn  1476:                             'View recent activity by this person','','',1);
1.369.2.26  raeburn  1477:                 }
                   1478:                 if ($perms{'vgr'}) {
                   1479:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
                   1480:                             '',
1.369.2.42  raeburn  1481:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
1.369.2.37  raeburn  1482:                             'Slot reservation history','','',1);
1.369.2.26  raeburn  1483:                 }
                   1484:                 if ($perms{'srm'}) {
                   1485:                     &switch('','',6,7,'contact-new-22x22.png','Records',
                   1486:                             '',
1.369.2.42  raeburn  1487:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
1.369.2.37  raeburn  1488:                             'Add records','','',1);
1.369.2.26  raeburn  1489:                 }
                   1490:             }
1.369.2.27  raeburn  1491:         }
                   1492:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
                   1493:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
                   1494:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
                   1495:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
                   1496:              ($resurl eq '/adm/supplemental') ||
                   1497:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
                   1498:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
                   1499:             my @folders=split('&',$env{'form.folderpath'});
                   1500:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
                   1501:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
                   1502:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1.369.2.42  raeburn  1503:                         "location.href='/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath=$esc_path'",
1.369.2.37  raeburn  1504:                         'Folder/Page Content','','',1);
1.369.2.27  raeburn  1505:             }
1.369.2.26  raeburn  1506:         }
                   1507:     }
                   1508: 
                   1509: # End checking for items for about me page for users in a course
1.369.2.27  raeburn  1510:     if ($docscrumbs) {
                   1511:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1512:         &advtools_crumbs(@inlineremote);
                   1513:         return $editbutton;
1.369.2.37  raeburn  1514:     } elsif (($env{'request.registered'}) && (!ref($forbodytag))) {
1.369.2.26  raeburn  1515:         return $editbutton;
                   1516:     } else {
                   1517:         if (ref($bread_crumbs) eq 'ARRAY') {
                   1518:             if (@inlineremote > 0) {
                   1519:                 if (ref($advtools) eq 'ARRAY') {
                   1520:                     @{$advtools} = @inlineremote;
                   1521:                 }
                   1522:             }
                   1523:             return;
                   1524:         } elsif (@inlineremote > 0) {
                   1525:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1526:             &advtools_crumbs(@inlineremote);
1.369.2.37  raeburn  1527:             if (ref($forbodytag)) {
                   1528:                 $$forbodytag =
                   1529:                     &Apache::lonhtmlcommon::scripttag('', 'start')
                   1530:                    .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
                   1531:                    .&Apache::lonhtmlcommon::scripttag('', 'end');
                   1532:             }
                   1533:             return;
1.369.2.26  raeburn  1534:         }
                   1535:     }
                   1536: }
                   1537: 
                   1538: sub advtools_crumbs {
                   1539:     my @funcs = @_;
                   1540:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                   1541:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1542:             'advtools', @funcs[61,64,65,66,67,74]);
                   1543:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
                   1544:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1545:             'advtools', @funcs[61,71,72,73,74,92]);
1.369.2.27  raeburn  1546:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
                   1547:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.369.2.33  raeburn  1548:             'advtools', $funcs[61]);
1.369.2.26  raeburn  1549:     }
                   1550: }
1.369.2.1  raeburn  1551: 
1.2       www      1552: # ================================================================== Raw Config
                   1553: 
1.3       www      1554: sub clear {
                   1555:     my ($row,$col)=@_;
1.369.2.17  raeburn  1556:     if ($env{'environment.remote'} eq 'on') {
                   1557:        if (($row<1) || ($row>13)) { return ''; }
                   1558:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
                   1559:     } else {
                   1560:         $inlineremote[10*$row+$col]='';
                   1561:         return '';
                   1562:     }
1.3       www      1563: }
                   1564: 
1.40      www      1565: # ============================================ Switch a button or create a link
1.25      matthew  1566: # Switch acts on the javascript that is executed when a button is clicked.  
                   1567: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www      1568: 
1.2       www      1569: sub switch {
1.369.2.37  raeburn  1570:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc)=@_;
1.2       www      1571:     $act=~s/\$uname/$uname/g;
                   1572:     $act=~s/\$udom/$udom/g;
1.88      www      1573:     $top=&mt($top);
                   1574:     $bot=&mt($bot);
                   1575:     $desc=&mt($desc);
1.209     www      1576:     my $idx=10*$row+$col;
                   1577:     $category_members{$cat}.=':'.$idx;
                   1578: 
1.369.2.37  raeburn  1579:     if (($env{'environment.remote'} eq 'on') && (!$infunc)) {
1.369.2.17  raeburn  1580:         if (($row<1) || ($row>13)) { return ''; }
1.369.2.21  raeburn  1581:         if ($env{'request.state'} eq 'construct') {
                   1582:             my $text = $top.' '.$bot;
                   1583:             $text=~s/\s*\-\s*//gs;
                   1584:             my $pic = '<img alt="'.$text.'" src="'.
                   1585:                       &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
                   1586:                       '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
                   1587:            $inlineremote[$idx] =
                   1588:                '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.
                   1589:                $pic.'<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
                   1590:         }
1.369.2.17  raeburn  1591: # Remote
                   1592:         $img=~s/\.png$/\.gif/;
                   1593:         return "\n".
                   1594:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
                   1595:     }
                   1596: 
1.320     droeschl 1597: # Inline Menu
1.317     droeschl 1598:     if ($nobreak==2) { return ''; }
                   1599:     my $text=$top.' '.$bot;
                   1600:     $text=~s/\s*\-\s*//gs;
1.105     www      1601: 
1.317     droeschl 1602:     my $pic=
1.225     albertel 1603: 	   '<img alt="'.$text.'" src="'.
                   1604: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303     droeschl 1605: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317     droeschl 1606:     if ($env{'browser.interface'} eq 'faketextual') {
1.274     www      1607: # Main Menu
1.103     www      1608: 	   if ($nobreak==3) {
1.209     www      1609: 	       $inlineremote[$idx]="\n".
1.177     albertel 1610: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
1.247     harmsja  1611: 		   '</td><td align="left">'.
1.103     www      1612: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                   1613: 	   } elsif ($nobreak) {
1.209     www      1614: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1615: 		   '<td align="left">'.
1.177     albertel 1616: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215     www      1617:                     <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      1618: 	   } else {
1.209     www      1619: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1620: 		   '<td align="left">'.
1.103     www      1621: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel 1622: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215     www      1623: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103     www      1624: 	   }
1.317     droeschl 1625:     } else {
1.103     www      1626: # Inline Menu
1.369.2.10  raeburn  1627:         my @tools = (93,91,81,82,83);
                   1628:         unless ($env{'request.state'} eq 'construct') {
                   1629:             push(@tools,63);
                   1630:         }
                   1631:         if (($env{'environment.icons'} eq 'iconsonly') &&
                   1632:             (grep(/^$idx$/,@tools))) {
                   1633:             $inlineremote[$idx] =
                   1634:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
                   1635:         } else {
                   1636:             $inlineremote[$idx] =
1.317     droeschl 1637:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344     www      1638:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
1.369.2.10  raeburn  1639:         }
1.317     droeschl 1640:     }
1.56      www      1641:     return '';
1.2       www      1642: }
                   1643: 
                   1644: sub secondlevel {
                   1645:     my $output='';
                   1646:     my 
1.209     www      1647:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2       www      1648:     if ($prt eq 'any') {
1.209     www      1649: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1650:     } elsif ($prt=~/^r(\w+)/) {
                   1651:         if ($rol eq $1) {
1.209     www      1652:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1653:         }
                   1654:     }
                   1655:     return $output;
                   1656: }
                   1657: 
1.369.2.17  raeburn  1658: sub openmenu {
                   1659:     my $menuname = &get_menu_name();
                   1660:     unless ($env{'environment.remote'} eq 'on') { return ''; }
                   1661:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                   1662:     return "window.open(".$nothing.",'".$menuname."');";
                   1663: }
                   1664: 
1.56      www      1665: sub inlinemenu {
1.210     albertel 1666:     undef(@inlineremote);
                   1667:     undef(%category_members);
1.275     www      1668: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56      www      1669:     &rawconfig(1);
1.309     bisitz   1670:     my $output='<table><tr>';
1.209     www      1671:     for (my $col=1; $col<=2; $col++) {
1.241     riegler  1672:         $output.='<td class="LC_mainmenu_col_fieldset">';
1.209     www      1673:         for (my $row=1; $row<=8; $row++) {
                   1674:             foreach my $cat (keys(%category_members)) {
                   1675:                if ($category_positions{$cat} ne "$col,$row") { next; }
1.247     harmsja  1676:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309     bisitz   1677:                $output.='<div class="LC_Box LC_400Box">';
                   1678: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247     harmsja  1679:                $output.='<table>';
1.240     riegler  1680:                my %active=();
                   1681:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
                   1682:                   if ($inlineremote[$menu_item]) {
                   1683:                      $active{$menu_item}=1;
                   1684:                   }
                   1685:                }  
                   1686:                foreach my $item (sort(keys(%active))) {
                   1687:                   $output.=$inlineremote[$item];
                   1688:                }
                   1689:                $output.='</table>';
1.245     harmsja  1690:                $output.='</div>';
1.240     riegler  1691:             }
                   1692:          }
                   1693:          $output.="</td>";
                   1694:     }
                   1695:     $output.="</tr></table>";
                   1696:     return $output;
                   1697: }
                   1698: 
1.2       www      1699: sub rawconfig {
1.274     www      1700: #
                   1701: # This evaluates mydesk.tab
                   1702: # Need to add more positions and more privileges to deal with all
                   1703: # menu items.
                   1704: #
1.34      www      1705:     my $textualoverride=shift;
                   1706:     my $output='';
1.369.2.17  raeburn  1707:     if ($env{'environment.remote'} eq 'on') {
                   1708:        $output.=
                   1709:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
                   1710: "\nwindow.status='Configuring Remote Control ';";
                   1711:     } else {
                   1712:         unless ($textualoverride) { return ''; }
                   1713:     }
1.152     albertel 1714:     my $uname=$env{'user.name'};
                   1715:     my $udom=$env{'user.domain'};
                   1716:     my $adv=$env{'user.adv'};
1.266     raeburn  1717:     my $show_course=&Apache::loncommon::show_course();
1.152     albertel 1718:     my $author=$env{'user.author'};
1.5       www      1719:     my $crs='';
1.295     raeburn  1720:     my $crstype='';
1.152     albertel 1721:     if ($env{'request.course.id'}) {
                   1722:        $crs='/'.$env{'request.course.id'};
                   1723:        if ($env{'request.course.sec'}) {
                   1724: 	   $crs.='_'.$env{'request.course.sec'};
1.7       www      1725:        }
1.8       www      1726:        $crs=~s/\_/\//g;
1.295     raeburn  1727:        $crstype = &Apache::loncommon::course_type();
1.5       www      1728:     }
1.152     albertel 1729:     my $pub=($env{'request.state'} eq 'published');
                   1730:     my $con=($env{'request.state'} eq 'construct');
                   1731:     my $rol=$env{'request.role'};
1.369.2.51  raeburn  1732:     my $requested_domain;
                   1733:     if ($rol) {
                   1734:        $requested_domain = $env{'request.role.domain'};
                   1735:     }
1.184     raeburn  1736:     foreach my $line (@desklines) {
1.209     www      1737:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3       www      1738:         $prt=~s/\$uname/$uname/g;
                   1739:         $prt=~s/\$udom/$udom/g;
1.295     raeburn  1740:         if ($prt =~ /\$crs/) {
                   1741:             next unless ($env{'request.course.id'});
                   1742:             next if ($crstype eq 'Community');
                   1743:             $prt=~s/\$crs/$crs/g;
                   1744:         } elsif ($prt =~ /\$cmty/) {
                   1745:             next unless ($env{'request.course.id'});
                   1746:             next if ($crstype ne 'Community');
                   1747:             $prt=~s/\$cmty/$crs/g;
                   1748:         }
1.369.2.51  raeburn  1749:         if ($prt =~ m/\$requested_domain/) {
                   1750:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
                   1751:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
                   1752:             } else {
                   1753:                 $prt=~s/\$requested_domain/$requested_domain/g;
                   1754:             }
                   1755:         }
1.211     www      1756:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3       www      1757:         if ($pro eq 'clear') {
1.4       www      1758: 	    $output.=&clear($row,$col);
1.3       www      1759:         } elsif ($pro eq 'any') {
1.2       www      1760:                $output.=&secondlevel(
1.209     www      1761: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1762: 	} elsif ($pro eq 'smp') {
                   1763:             unless ($adv) {
                   1764:                $output.=&secondlevel(
1.209     www      1765:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1766:             }
                   1767:         } elsif ($pro eq 'adv') {
                   1768:             if ($adv) {
                   1769:                $output.=&secondlevel(
1.209     www      1770: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1771:             }
1.231     albertel 1772: 	} elsif ($pro eq 'shc') {
                   1773:             if ($show_course) {
                   1774:                $output.=&secondlevel(
                   1775:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1776:             }
                   1777:         } elsif ($pro eq 'nsc') {
                   1778:             if (!$show_course) {
                   1779:                $output.=&secondlevel(
                   1780: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1781:             }
1.81      matthew  1782:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295     raeburn  1783:             my $priv = $1;
                   1784:             if ($priv =~ /^mdc(Course|Community)/) {
                   1785:                 if ($crstype eq $1) {
                   1786:                     $priv = 'mdc';
                   1787:                 } else {
                   1788:                     next;
                   1789:                 }
                   1790:             }
1.369.2.51  raeburn  1791:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
                   1792:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
                   1793:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4       www      1794:             }
1.295     raeburn  1795:         } elsif ($pro eq 'course')  {
                   1796:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209     www      1797:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81      matthew  1798: 	    }
1.295     raeburn  1799:         } elsif ($pro eq 'community')  {
                   1800:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
                   1801:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1802:             }
1.124     matthew  1803:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                   1804:             my $key = $1;
1.307     raeburn  1805:             if ($crstype ne 'Community') {
                   1806:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1807:                 if ($key eq 'canuse_pdfforms') {
                   1808:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1809:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1810:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1811:                     }
                   1812:                 }
                   1813:                 if ($coursepref) { 
                   1814:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1815:                 }
1.295     raeburn  1816:             }
                   1817:         } elsif ($pro =~ /^communityenv_(.*)$/) {
                   1818:             my $key = $1;
1.307     raeburn  1819:             if ($crstype eq 'Community') {
                   1820:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1821:                 if ($key eq 'canuse_pdfforms') {
                   1822:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1823:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1824:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1825:                     }
                   1826:                 }
                   1827:                 if ($coursepref) { 
                   1828:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1829:                 }
1.124     matthew  1830:             }
1.81      matthew  1831:         } elsif ($pro =~ /^course_(.*)$/) {
                   1832:             # Check for permissions inside of a course
1.295     raeburn  1833:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
1.152     albertel 1834:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1835:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81      matthew  1836:                  )) {
1.209     www      1837:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26      www      1838: 	    }
1.295     raeburn  1839:         } elsif ($pro =~ /^community_(.*)$/) {
                   1840:             # Check for permissions inside of a community
                   1841:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
                   1842:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1843:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
                   1844:                  )) {
                   1845:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1846:             }
1.4       www      1847:         } elsif ($pro eq 'author') {
                   1848:             if ($author) {
1.152     albertel 1849:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234     raeburn  1850:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
1.152     albertel 1851:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19      matthew  1852:                     # Check that we are on the correct machine
1.29      matthew  1853:                     my $cadom=$requested_domain;
1.152     albertel 1854:                     my $caname=$env{'user.name'};
1.234     raeburn  1855:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29      matthew  1856: 		       ($cadom,$caname)=
1.206     albertel 1857:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29      matthew  1858:                     }                       
                   1859:                     $act =~ s/\$caname/$caname/g;
1.353     www      1860:                     $act =~ s/\$cadom/$cadom/g;
1.19      matthew  1861:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel 1862: 		    my $allowed=0;
                   1863: 		    my @ids=&Apache::lonnet::current_machine_ids();
                   1864: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   1865: 		    if ($allowed) {
1.209     www      1866:                         $output.=&switch($caname,$cadom,
                   1867:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19      matthew  1868:                     }
1.6       www      1869:                 }
1.2       www      1870:             }
1.248     raeburn  1871:         } elsif ($pro eq 'tools') {
                   1872:             my @tools = ('aboutme','blog','portfolio');
                   1873:             if (grep(/^\Q$prt\E$/,@tools)) {
1.249     raeburn  1874:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251     raeburn  1875:                                                        $env{'user.domain'},
                   1876:                                                        $prt,undef,'tools')) {
                   1877:                     $output.=&clear($row,$col);
                   1878:                     next;
                   1879:                 }
1.278     raeburn  1880:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
                   1881:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
                   1882:                     next;
                   1883:                 }
                   1884:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
                   1885:                     next;
                   1886:                 }
1.279     raeburn  1887:                 my $showreqcrs = &check_for_rcrs();
1.251     raeburn  1888:                 if (!$showreqcrs) {
1.248     raeburn  1889:                     $output.=&clear($row,$col);
                   1890:                     next;
                   1891:                 }
                   1892:             }
                   1893:             $prt='any';
                   1894:             $output.=&secondlevel(
                   1895:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1896:         }
1.13      harris41 1897:     }
1.369.2.17  raeburn  1898:     if ($env{'environment.remote'} eq 'on') {
                   1899:         $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
                   1900:         if (&Apache::lonmsg::newmail()) {
                   1901:             $output.='swmenu.setstatus("you have","messages");';
                   1902:         }
                   1903:     }
1.2       www      1904:     return $output;
                   1905: }
                   1906: 
1.279     raeburn  1907: sub check_for_rcrs {
                   1908:     my $showreqcrs = 0;
1.369.2.49  raeburn  1909:     my @reqtypes = ('official','unofficial','community','textbook');
1.280     raeburn  1910:     foreach my $type (@reqtypes) {
1.279     raeburn  1911:         if (&Apache::lonnet::usertools_access($env{'user.name'},
                   1912:                                               $env{'user.domain'},
                   1913:                                               $type,undef,'requestcourses')) {
                   1914:             $showreqcrs = 1;
                   1915:             last;
                   1916:         }
                   1917:     }
1.280     raeburn  1918:     if (!$showreqcrs) {
                   1919:         foreach my $type (@reqtypes) {
                   1920:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
                   1921:                 $showreqcrs = 1;
                   1922:                 last;
                   1923:             }
                   1924:         }
                   1925:     }
1.279     raeburn  1926:     return $showreqcrs;
                   1927: }
                   1928: 
1.369.2.1  raeburn  1929: # ======================================================================= Close
                   1930: 
                   1931: sub close {
1.369.2.17  raeburn  1932:     unless ($env{'environment.remote'} eq 'on') { return ''; }
1.369.2.1  raeburn  1933:     my $menuname = &get_menu_name();
                   1934:     return(<<ENDCLOSE);
                   1935: <script type="text/javascript">
                   1936: // <![CDATA[
                   1937: window.status='Accessing Remote Control';
                   1938: menu=window.open("/adm/rat/empty.html","$menuname",
                   1939:                  "height=350,width=150,scrollbars=no,menubar=no");
                   1940: window.status='Disabling Remote Control';
                   1941: menu.active=0;
                   1942: menu.autologout=0;
                   1943: window.status='Closing Remote Control';
                   1944: menu.close();
                   1945: window.status='Done.';
                   1946: // ]]>
                   1947: </script>
                   1948: ENDCLOSE
                   1949: }
                   1950: 
1.306     raeburn  1951: sub dc_popup_js {
                   1952:     my %lt = &Apache::lonlocal::texthash(
                   1953:                                           more => '(More ...)',
                   1954:                                           less => '(Less ...)',
                   1955:                                         );
                   1956:     return <<"END";
                   1957: 
                   1958: function showCourseID() {
                   1959:     document.getElementById('dccid').style.display='block';
                   1960:     document.getElementById('dccid').style.textAlign='left';
1.307     raeburn  1961:     document.getElementById('dccid').style.textFace='normal';
1.369     raeburn  1962:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306     raeburn  1963:     return;
                   1964: }
                   1965: 
                   1966: function hideCourseID() {
                   1967:     document.getElementById('dccid').style.display='none';
1.369     raeburn  1968:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306     raeburn  1969:     return;
                   1970: }
                   1971: 
                   1972: END
                   1973: 
                   1974: }
                   1975: 
1.369.2.10  raeburn  1976: sub countdown_toggle_js {
                   1977:     return <<"END";
                   1978: 
                   1979: function toggleCountdown() {
                   1980:     var countdownid = document.getElementById('duedatecountdown');
                   1981:     var currstyle = countdownid.style.display;
                   1982:     if (currstyle == 'inline') {
                   1983:         countdownid.style.display = 'none';
                   1984:         document.getElementById('ddcountcollapse').innerHTML='';
                   1985:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
                   1986:     } else {
                   1987:         countdownid.style.display = 'inline';
                   1988:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
                   1989:         document.getElementById('ddcountexpand').innerHTML='';
                   1990:     }
                   1991:     return;
                   1992: }
                   1993: 
                   1994: END
                   1995: }
                   1996: 
1.42      www      1997: sub utilityfunctions {
1.369.2.47  raeburn  1998:     my ($httphost) = @_;
1.152     albertel 1999:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.316     droeschl 2000:     if ($currenturl =~ m{^/adm/wrapper/ext/}
                   2001:         && $env{'request.external.querystring'} ) {
1.293     raeburn  2002:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
                   2003:     }
1.183     www      2004:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125     albertel 2005:     
1.152     albertel 2006:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.175     albertel 2007: 
1.306     raeburn  2008:     my $dc_popup_cid;
                   2009:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   2010:                         $env{'course.'.$env{'request.course.id'}.
                   2011:                                  '.domain'}.'/'})) {
                   2012:         $dc_popup_cid = &dc_popup_js();
                   2013:     }
                   2014: 
1.175     albertel 2015:     my $start_page_annotate = 
                   2016:         &Apache::loncommon::start_page('Annotator',undef,
                   2017: 				       {'only_body' => 1,
                   2018: 					'js_ready'  => 1,
                   2019: 					'bgcolor'   => '#BBBBBB',
                   2020: 					'add_entries' => {
                   2021: 					    'onload' => 'javascript:document.goannotate.submit();'}});
                   2022: 
1.205     albertel 2023:     my $end_page_annotate = 
                   2024:         &Apache::loncommon::end_page({'js_ready' => 1});
                   2025: 
1.369.2.26  raeburn  2026:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336     raeburn  2027: 
1.368     www      2028:     my $esc_url=&escape($currenturl);
                   2029:     my $esc_symb=&escape($currentsymb);
1.332     wenzelju 2030: 
1.369.2.10  raeburn  2031:     my $countdown = &countdown_toggle_js();
                   2032: 
1.369.2.53  raeburn  2033:     my $hostvar = '
                   2034: function setLCHost() {
                   2035:     var lcHostname="";
                   2036: ';
                   2037:     if ($httphost =~ m{^https?\://}) {
                   2038:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
                   2039:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
                   2040:                     '    var match = hostReg.exec(lcServer);'."\n".
                   2041:                     '    if (match.length) {'."\n".
                   2042:                     '        if (match[1] == location.hostname) {'."\n".
                   2043:                     '            lcHostname=lcServer;'."\n".
                   2044:                     '        }'."\n".
                   2045:                     '    }'."\n";
                   2046:     }
                   2047: 
                   2048:     $hostvar .= '    return lcHostname;'."\n".
                   2049: '}'."\n";
                   2050: 
1.42      www      2051: return (<<ENDUTILITY)
1.369.2.53  raeburn  2052:     $hostvar
1.368     www      2053:     var currentURL=unescape("$esc_url");
                   2054:     var reloadURL=unescape("$esc_url");
                   2055:     var currentSymb=unescape("$esc_symb");
1.42      www      2056: 
1.306     raeburn  2057: $dc_popup_cid
1.114     albertel 2058: 
1.42      www      2059: function go(url) {
                   2060:    if (url!='' && url!= null) {
                   2061:        currentURL = null;
                   2062:        currentSymb= null;
1.369.2.53  raeburn  2063:        var lcHostname = setLCHost();
                   2064:        window.location.href=lcHostname+url;
1.42      www      2065:    }
                   2066: }
                   2067: 
1.369.2.26  raeburn  2068: $jumptores
1.336     raeburn  2069: 
1.42      www      2070: function gopost(url,postdata) {
                   2071:    if (url!='') {
1.369.2.53  raeburn  2072:       var lcHostname = setLCHost();
                   2073:       this.document.server.action=lcHostname+url;
1.42      www      2074:       this.document.server.postdata.value=postdata;
                   2075:       this.document.server.command.value='';
                   2076:       this.document.server.url.value='';
                   2077:       this.document.server.symb.value='';
                   2078:       this.document.server.submit();
                   2079:    }
                   2080: }
                   2081: 
                   2082: function gocmd(url,cmd) {
                   2083:    if (url!='') {
1.369.2.53  raeburn  2084:       var lcHostname = setLCHost();
                   2085:       this.document.server.action=lcHostname+url;
1.42      www      2086:       this.document.server.postdata.value='';
                   2087:       this.document.server.command.value=cmd;
                   2088:       this.document.server.url.value=currentURL;
                   2089:       this.document.server.symb.value=currentSymb;
                   2090:       this.document.server.submit();
                   2091:    }
1.57      www      2092: }
                   2093: 
1.121     raeburn  2094: function gocstr(url,filename) {
                   2095:     if (url == '/adm/cfile?action=delete') {
                   2096:         this.document.cstrdelete.filename.value = filename
                   2097:         this.document.cstrdelete.submit();
                   2098:         return;
                   2099:     }
1.137     raeburn  2100:     if (url == '/adm/printout') {
                   2101:         this.document.cstrprint.postdata.value = filename
                   2102:         this.document.cstrprint.curseed.value = 0;
                   2103:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  2104:         if (this.document.lonhomework) {
                   2105:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   2106:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   2107:             }
                   2108:             if (this.document.lonhomework.problemtype) {
1.164     albertel 2109: 		if (this.document.lonhomework.problemtype.value) {
                   2110: 		    this.document.cstrprint.problemtype.value = 
                   2111: 			this.document.lonhomework.problemtype.value;
                   2112: 		} else if (this.document.lonhomework.problemtype.options) {
                   2113: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   2114: 			if (this.document.lonhomework.problemtype.options[i].selected) {
                   2115: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   2116: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   2117: 				}
                   2118: 			}
                   2119: 		    }
                   2120: 		}
                   2121: 	    }
                   2122: 	}
1.137     raeburn  2123:         this.document.cstrprint.submit();
                   2124:         return;
                   2125:     }
1.121     raeburn  2126:     if (url !='') {
                   2127:         this.document.constspace.filename.value = filename;
                   2128:         this.document.constspace.action = url;
                   2129:         this.document.constspace.submit();
                   2130:     }
                   2131: }
                   2132: 
1.131     raeburn  2133: function golist(url) {
                   2134:    if (url!='' && url!= null) {
                   2135:        currentURL = null;
                   2136:        currentSymb= null;
1.369.2.53  raeburn  2137:        var lcHostname = setLCHost();
                   2138:        top.location.href=lcHostname+url;
1.131     raeburn  2139:    }
                   2140: }
                   2141: 
                   2142: 
1.121     raeburn  2143: 
1.369.2.52  raeburn  2144: function catalog_info(isMobile) {
                   2145:     if (isMobile == 1) {
                   2146:         openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
                   2147:     } else {
                   2148:         loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
                   2149:     }
1.57      www      2150: }
                   2151: 
                   2152: function chat_win() {
1.369.2.53  raeburn  2153:    var lcHostname = setLCHost();
                   2154:    lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42      www      2155: }
1.169     raeburn  2156: 
                   2157: function group_chat(group) {
1.369.2.53  raeburn  2158:    var lcHostname = setLCHost();
                   2159:    var url = lcHostname+'/adm/groupchat?group='+group;
1.169     raeburn  2160:    var winName = 'LONchat_'+group;
                   2161:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
                   2162: }
1.175     albertel 2163: 
                   2164: function annotate() {
                   2165:    w_Annotator_flag=1;
                   2166:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
                   2167:    annotator.document.write(
                   2168:    '$start_page_annotate'
                   2169:   +"<form name='goannotate' target='Annotator' method='post' "
                   2170:   +"action='/adm/annotations'>"
1.217     albertel 2171:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181     albertel 2172:   +"<\\/form>"
1.205     albertel 2173:   +'$end_page_annotate');
1.175     albertel 2174:    annotator.document.close();
                   2175: }
                   2176: 
1.369.2.8  raeburn  2177: function open_StoredLinks_Import(rat) {
                   2178:    var newWin;
1.369.2.53  raeburn  2179:    var lcHostname = setLCHost();
1.369.2.8  raeburn  2180:    if (rat) {
1.369.2.53  raeburn  2181:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.369.2.8  raeburn  2182:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
                   2183:    }
                   2184:    else {
1.369.2.53  raeburn  2185:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
1.369.2.8  raeburn  2186:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
                   2187:    }
                   2188:    newWin.focus();
                   2189: }
                   2190: 
1.369.2.4  raeburn  2191: (function (\$) {
                   2192:   \$(document).ready(function () {
                   2193:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
                   2194:     /*\@cc_on
                   2195:       if (!window.XMLHttpRequest) {
                   2196:         \$('.LC_hoverable').each(function () {
                   2197:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
                   2198:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
                   2199:         });
                   2200:       }
                   2201:     \@*/
                   2202:   });
                   2203: }(jQuery));
                   2204: 
1.369.2.10  raeburn  2205: $countdown
                   2206: 
1.42      www      2207: ENDUTILITY
                   2208: }
                   2209: 
                   2210: sub serverform {
                   2211:     return(<<ENDSERVERFORM);
1.181     albertel 2212: <form name="server" action="/adm/logout" method="post" target="_top">
1.42      www      2213: <input type="hidden" name="postdata" value="none" />
                   2214: <input type="hidden" name="command" value="none" />
                   2215: <input type="hidden" name="url" value="none" />
                   2216: <input type="hidden" name="symb" value="none" />
                   2217: </form>
                   2218: ENDSERVERFORM
                   2219: }
1.113     albertel 2220: 
1.121     raeburn  2221: sub constspaceform {
                   2222:     return(<<ENDCONSTSPACEFORM);
1.181     albertel 2223: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121     raeburn  2224: <input type="hidden" name="filename" value="" />
                   2225: </form>
1.181     albertel 2226: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121     raeburn  2227: <input type="hidden" name="action" value="delete" /> 
                   2228: <input type="hidden" name="filename" value="" />
                   2229: </form>
1.181     albertel 2230: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137     raeburn  2231: <input type="hidden" name="postdata" value="" />
                   2232: <input type="hidden" name="curseed" value="" />
                   2233: <input type="hidden" name="problemtype" value="" />
                   2234: </form>
                   2235: 
1.121     raeburn  2236: ENDCONSTSPACEFORM
                   2237: }
                   2238: 
1.369.2.17  raeburn  2239: sub get_nav_status {
                   2240:     my $navstatus="swmenu.w_loncapanav_flag=";
                   2241:     if ($env{'environment.remotenavmap'} eq 'on') {
                   2242:         $navstatus.="1";
                   2243:     } else {
                   2244:         $navstatus.="-1";
                   2245:     }
                   2246:     return $navstatus;
                   2247: }
                   2248: 
1.220     raeburn  2249: sub hidden_button_check {
1.317     droeschl 2250:     if ( $env{'request.course.id'} eq ''
                   2251:          || $env{'request.role.adv'} ) {
                   2252: 
1.220     raeburn  2253:         return;
                   2254:     }
1.232     raeburn  2255:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
                   2256:     return $buttonshide; 
1.220     raeburn  2257: }
1.184     raeburn  2258: 
1.235     raeburn  2259: sub roles_selector {
1.369.2.47  raeburn  2260:     my ($cdom,$cnum,$httphost) = @_;
1.298     raeburn  2261:     my $crstype = &Apache::loncommon::course_type();
1.235     raeburn  2262:     my $now = time;
1.350     raeburn  2263:     my (%courseroles,%seccount,%courseprivs);
1.235     raeburn  2264:     my $is_cc;
1.369.2.30  raeburn  2265:     my ($js,$form,$switcher,$switchtext);
1.298     raeburn  2266:     my $ccrole;
                   2267:     if ($crstype eq 'Community') {
                   2268:         $ccrole = 'co';
                   2269:     } else {
                   2270:         $ccrole = 'cc';
1.350     raeburn  2271:     }
1.369.2.23  raeburn  2272:     my ($priv,$gotsymb,$destsymb);
1.350     raeburn  2273:     my $destinationurl = $ENV{'REQUEST_URI'};
1.369.2.23  raeburn  2274:     if ($destinationurl =~ /\?symb=/) {
                   2275:         $gotsymb = 1;
                   2276:     } elsif ($destinationurl =~ m{^/enc/}) {
                   2277:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
                   2278:         if ($plainurl =~ /\?symb=/) {
                   2279:             $gotsymb = 1;
                   2280:         }
                   2281:     }
                   2282:     unless ($gotsymb) {
                   2283:         $destsymb = &Apache::lonnet::symbread();
                   2284:         if ($destsymb ne '') {
                   2285:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
                   2286:         }
                   2287:     }
1.350     raeburn  2288:     my $reqprivs = &required_privs();
                   2289:     if (ref($reqprivs) eq 'HASH') {
                   2290:         my $destination = $destinationurl;
                   2291:         $destination =~ s/(\?.*)$//;
                   2292:         if (exists($reqprivs->{$destination})) {
                   2293:             $priv = $reqprivs->{$destination};
                   2294:         }
                   2295:     }
1.298     raeburn  2296:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
                   2297:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235     raeburn  2298:         
                   2299:         if ((($start) && ($start<0)) || 
                   2300:             (($end) && ($end<$now))  ||
                   2301:             (($start) && ($now<$start))) {
                   2302:             $is_cc = 0;
                   2303:         } else {
                   2304:             $is_cc = 1;
                   2305:         }
                   2306:     }
                   2307:     if ($is_cc) {
1.350     raeburn  2308:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1.235     raeburn  2309:     } else {
1.262     raeburn  2310:         my %gotnosection;
1.235     raeburn  2311:         foreach my $item (keys(%env)) {
1.239     raeburn  2312:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235     raeburn  2313:                 my $role = $1;
                   2314:                 my $sec = $2;
                   2315:                 next if ($role eq 'gr');
                   2316:                 my ($start,$end) = split(/\./,$env{$item});
                   2317:                 next if (($start && $start > $now) || ($end && $end < $now));
                   2318:                 if ($sec eq '') {
1.239     raeburn  2319:                     if (!$gotnosection{$role}) {
                   2320:                         $seccount{$role} ++;
                   2321:                         $gotnosection{$role} = 1;
                   2322:                     }
1.235     raeburn  2323:                 }
1.350     raeburn  2324:                 if ($priv ne '') {
                   2325:                     my $cnumsec = $cnum;
                   2326:                     if ($sec ne '') {
                   2327:                         $cnumsec .= "/$sec";
                   2328:                     }
                   2329:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
                   2330:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
                   2331:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
                   2332:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
                   2333:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
                   2334:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
                   2335:                 }
1.235     raeburn  2336:                 if (ref($courseroles{$role}) eq 'ARRAY') {
1.239     raeburn  2337:                     if ($sec ne '') {
1.264     raeburn  2338:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239     raeburn  2339:                             push(@{$courseroles{$role}},$sec);
                   2340:                             $seccount{$role} ++;
                   2341:                         }
                   2342:                     }
                   2343:                 } else {
                   2344:                     @{$courseroles{$role}} = ();
                   2345:                     if ($sec ne '') {
                   2346:                         $seccount{$role} ++;
1.235     raeburn  2347:                         push(@{$courseroles{$role}},$sec);
                   2348:                     }
                   2349:                 }
                   2350:             }
                   2351:         }
                   2352:     }
1.369.2.46  raeburn  2353:     $switchtext = 'Switch role'; # do not translate here
1.298     raeburn  2354:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.369.2.30  raeburn  2355:     my $numdiffsec;
                   2356:     if (keys(%seccount) == 1) {
                   2357:         foreach my $key (keys(%seccount)) {
                   2358:             $numdiffsec = $seccount{$key};
                   2359:         }
                   2360:     }
                   2361:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
                   2362:         my @submenu;
                   2363:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
                   2364:         $form = 
1.369.2.47  raeburn  2365:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
1.369.2.30  raeburn  2366:             '  <input type="hidden" name="destinationurl" value="'.
                   2367:             &HTML::Entities::encode($destinationurl).'" />'."\n".
                   2368:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
                   2369:             '  <input type="hidden" name="selectrole" value="" />'."\n".
                   2370:             '  <input type="hidden" name="switchrole" value="" />'."\n";
                   2371:         if ($destsymb ne '') {
                   2372:             $form .= '   <input type="hidden" name="destsymb" value="'.
                   2373:                          &HTML::Entities::encode($destsymb).'" />'."\n";
                   2374:         }
                   2375:         $form .= '</form>'."\n";
1.235     raeburn  2376:         foreach my $role (@roles_order) {
1.369.2.30  raeburn  2377:             my $include;
1.235     raeburn  2378:             if (defined($courseroles{$role})) {
1.369.2.30  raeburn  2379:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
                   2380:                     if ($seccount{$role} > 1) {
                   2381:                         $include = 1;
                   2382:                     }
                   2383:                 } else {
                   2384:                     $include = 1;
                   2385:                 }
                   2386:             }
                   2387:             if ($include) {
                   2388:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
                   2389:                                &Apache::lonnet::plaintext($role,$crstype)]);
1.235     raeburn  2390:             }
                   2391:         }
                   2392:         foreach my $role (sort(keys(%courseroles))) {
                   2393:             if ($role =~ /^cr/) {
1.369.2.30  raeburn  2394:                 my $include;
                   2395:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
                   2396:                     if ($seccount{$role} > 1) {
                   2397:                         $include = 1;
                   2398:                     }
                   2399:                 } else {
                   2400:                     $include = 1;
                   2401:                 }
                   2402:                 if ($include) {
                   2403:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
                   2404:                                    &Apache::lonnet::plaintext($role)]);
                   2405:                 }
1.235     raeburn  2406:             }
                   2407:         }
1.369.2.30  raeburn  2408:         if (@submenu > 0) {
                   2409:             $switcher = &create_submenu('','',$switchtext,\@submenu);
1.369.2.23  raeburn  2410:         }
1.235     raeburn  2411:     }
1.369.2.30  raeburn  2412:     return ($js,$form,$switcher);
1.235     raeburn  2413: }
                   2414: 
1.262     raeburn  2415: sub get_all_courseroles {
1.350     raeburn  2416:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351     raeburn  2417:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350     raeburn  2418:             (ref($courseprivs) eq 'HASH')) {
1.262     raeburn  2419:         return;
                   2420:     }
                   2421:     my ($result,$cached) = 
                   2422:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
                   2423:     if (defined($cached)) {
                   2424:         if (ref($result) eq 'HASH') {
                   2425:             if ((ref($result->{'roles'}) eq 'HASH') && 
1.350     raeburn  2426:                 (ref($result->{'seccount'}) eq 'HASH') && 
                   2427:                 (ref($result->{'privs'}) eq 'HASH')) {
1.262     raeburn  2428:                 %{$courseroles} = %{$result->{'roles'}};
                   2429:                 %{$seccount} = %{$result->{'seccount'}};
1.350     raeburn  2430:                 %{$courseprivs} = %{$result->{'privs'}};
1.262     raeburn  2431:                 return;
                   2432:             }
                   2433:         }
                   2434:     }
                   2435:     my %gotnosection;
                   2436:     my %adv_roles =
                   2437:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
                   2438:     foreach my $role (keys(%adv_roles)) {
                   2439:         my ($urole,$usec) = split(/:/,$role);
                   2440:         if (!$gotnosection{$urole}) {
                   2441:             $seccount->{$urole} ++;
                   2442:             $gotnosection{$urole} = 1;
                   2443:         }
                   2444:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
                   2445:             if ($usec ne '') {
                   2446:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
                   2447:                     push(@{$courseroles->{$urole}},$usec);
                   2448:                     $seccount->{$urole} ++;
                   2449:                 }
                   2450:             }
                   2451:         } else {
                   2452:             @{$courseroles->{$urole}} = ();
                   2453:             if ($usec ne '') {
                   2454:                 $seccount->{$urole} ++;
                   2455:                 push(@{$courseroles->{$urole}},$usec);
                   2456:             }
                   2457:         }
1.350     raeburn  2458:         my $area = '/'.$cdom.'/'.$cnum;
                   2459:         if ($usec ne '') {
                   2460:             $area .= '/'.$usec;
                   2461:         }
                   2462:         if ($role =~ /^cr\//) {
                   2463:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
                   2464:         } else {
                   2465:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
                   2466:         }
1.262     raeburn  2467:     }
                   2468:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
                   2469:     @{$courseroles->{'st'}} = ();
1.350     raeburn  2470:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262     raeburn  2471:     if (keys(%sections_count) > 0) {
                   2472:         push(@{$courseroles->{'st'}},keys(%sections_count));
1.350     raeburn  2473:         $seccount->{'st'} = scalar(keys(%sections_count));
1.262     raeburn  2474:     }
1.369.2.38  raeburn  2475:     $seccount->{'st'} ++; # Increment for a section-less student role.
1.262     raeburn  2476:     my $rolehash = {
                   2477:                      'roles'    => $courseroles,
                   2478:                      'seccount' => $seccount,
1.350     raeburn  2479:                      'privs'    => $courseprivs,
1.262     raeburn  2480:                    };
                   2481:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
                   2482:     return;
                   2483: }
                   2484: 
1.235     raeburn  2485: sub jump_to_role {
1.350     raeburn  2486:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
1.239     raeburn  2487:     my %lt = &Apache::lonlocal::texthash(
                   2488:                 this => 'This role has section(s) associated with it.',
                   2489:                 ente => 'Enter a specific section.',
                   2490:                 orlb => 'Enter a specific section, or leave blank for no section.',
                   2491:                 avai => 'Available sections are:',
                   2492:                 youe => 'You entered an invalid section choice:',
1.352     raeburn  2493:                 plst => 'Please try again.',
1.350     raeburn  2494:                 role => 'The role you selected is not permitted to view the current page.',
                   2495:                 swit => 'Switch role, but display Main Menu page instead?',
1.239     raeburn  2496:     );
                   2497:     my $js;
                   2498:     if (ref($courseroles) eq 'HASH') {
                   2499:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
                   2500:               '    var numsec = new Array();'."\n".
                   2501:               '    var rolesections = new Array();'."\n".
                   2502:               '    var rolenames = new Array();'."\n".
                   2503:               '    var roleseclist = new Array();'."\n";
                   2504:         my @items = keys(%{$courseroles});
                   2505:         for (my $i=0; $i<@items; $i++) {
                   2506:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
                   2507:             my ($secs,$secstr);
                   2508:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
                   2509:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
                   2510:                 $secs = join('","',@sections);
                   2511:                 $secstr = join(', ',@sections);
                   2512:             }
                   2513:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
                   2514:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
                   2515:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
                   2516:         }
                   2517:     }
1.350     raeburn  2518:     my $checkroles = 0;
                   2519:     if ($priv && ref($courseprivs) eq 'HASH') {
                   2520:         my (%disallowed,%allowed,@disallow);
                   2521:         foreach my $role (sort(keys(%{$courseprivs}))) {
                   2522:             my $trole;
                   2523:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
                   2524:                 $trole = $1;
                   2525:             }
                   2526:             if (($trole ne '') && ($trole ne 'cm')) {
                   2527:                 if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
                   2528:                     $allowed{$trole} = 1;
                   2529:                 } else {
                   2530:                     $disallowed{$trole} = 1;
                   2531:                 }
                   2532:             }
                   2533:         }
                   2534:         foreach my $trole (keys(%disallowed)) {
                   2535:             unless ($allowed{$trole}) {
                   2536:                 push(@disallow,$trole);
                   2537:             }
                   2538:         }
                   2539:         if (@disallow > 0) {
                   2540:             $checkroles = 1;
                   2541:             $js .= "    var disallow = new Array('".join("','",@disallow)."');\n".
                   2542:                    "    var rolecheck = 1;\n";
                   2543:         }
                   2544:     }
                   2545:     if (!$checkroles) {
                   2546:         $js .=  "    var disallow = new Array();\n".
                   2547:                 "    rolecheck = 0;\n";
                   2548:     }
1.273     droeschl 2549:     return <<"END";
1.235     raeburn  2550: <script type="text/javascript">
1.273     droeschl 2551: //<![CDATA[
1.369.2.30  raeburn  2552: function adhocRole(newrole) {
1.239     raeburn  2553:     $js
1.235     raeburn  2554:     if (newrole == '') {
1.350     raeburn  2555:         return;
1.235     raeburn  2556:     } 
1.239     raeburn  2557:     var fullrole = newrole+'./$cdom/$cnum';
                   2558:     var selidx = '';
                   2559:     for (var i=0; i<rolenames.length; i++) {
                   2560:         if (rolenames[i] == newrole) {
                   2561:             selidx = i;
                   2562:         }
                   2563:     }
1.350     raeburn  2564:     if (rolecheck > 0) {
                   2565:         for (var i=0; i<disallow.length; i++) {
                   2566:             if (disallow[i] == newrole) {
                   2567:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
                   2568:                     document.rolechooser.destinationurl.value = '/adm/menu';
                   2569:                 } else {
                   2570:                     return;
                   2571:                 }
                   2572:             }
                   2573:         }
                   2574:     }
1.239     raeburn  2575:     var secok = 1;
                   2576:     var secchoice = '';
                   2577:     if (selidx >= 0) {
                   2578:         if (numsec[selidx] > 1) {
                   2579:             secok = 0;
                   2580:             var numrolesec = rolesections[selidx].length;
                   2581:             var msgidx = numsec[selidx] - numrolesec;
1.339     raeburn  2582:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239     raeburn  2583:             if (secchoice == '') {
                   2584:                 if (msgidx > 0) {
                   2585:                     secok = 1;
                   2586:                 }
                   2587:             } else {
                   2588:                 for (var j=0; j<rolesections[selidx].length; j++) {
                   2589:                     if (rolesections[selidx][j] == secchoice) {
                   2590:                         secok = 1;
                   2591:                     }
                   2592:                 }
                   2593:             }
                   2594:         } else {
                   2595:             if (rolesections[selidx].length == 1) {
                   2596:                 secchoice = rolesections[selidx][0];
                   2597:             }
                   2598:         }
                   2599:     }
                   2600:     if (secok == 1) {
                   2601:         if (secchoice != '') {
                   2602:             fullrole += '/'+secchoice;
                   2603:         }
                   2604:     } else {
                   2605:         document.rolechooser.elements[roleitem].selectedIndex = 0;
                   2606:         if (secchoice != null) {
                   2607:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
                   2608:         }
                   2609:         return;
                   2610:     }
                   2611:     if (fullrole == "$env{'request.role'}") {
1.235     raeburn  2612:         return;
                   2613:     }
                   2614:     itemid = retrieveIndex('gotorole');
                   2615:     if (itemid != -1) {
1.239     raeburn  2616:         document.rolechooser.elements[itemid].name = fullrole;
1.235     raeburn  2617:     }
1.369.2.30  raeburn  2618:     document.rolechooser.switchrole.value = fullrole;
1.235     raeburn  2619:     document.rolechooser.selectrole.value = '1';
                   2620:     document.rolechooser.submit();
                   2621:     return;
                   2622: }
                   2623: 
                   2624: function retrieveIndex(item) {
                   2625:     for (var i=0;i<document.rolechooser.elements.length;i++) {
                   2626:         if (document.rolechooser.elements[i].name == item) {
                   2627:             return i;
                   2628:         }
                   2629:     }
                   2630:     return -1;
                   2631: }
1.273     droeschl 2632: // ]]>
1.235     raeburn  2633: </script>
                   2634: END
                   2635: }
                   2636: 
1.350     raeburn  2637: sub required_privs {
                   2638:     my $privs =  {
                   2639:              '/adm/parmset'      => 'opa',
                   2640:              '/adm/courseprefs'  => 'opa',
                   2641:              '/adm/whatsnew'     => 'whn',
                   2642:              '/adm/populate'     => 'cst',
                   2643:              '/adm/trackstudent' => 'vsa',
                   2644:              '/adm/statistics'   => 'vgr',
1.366     raeburn  2645:              '/adm/setblock'     => 'dcm',
1.367     raeburn  2646:              '/adm/coursedocs'   => 'mdc',
1.350     raeburn  2647:            };
                   2648:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364     raeburn  2649:         $privs->{'/adm/classcalc'}   = 'vgr',
                   2650:         $privs->{'/adm/assesscalc'}  = 'vgr',
                   2651:         $privs->{'/adm/studentcalc'} = 'vgr';
1.350     raeburn  2652:     }
                   2653:     return $privs;
                   2654: }
1.235     raeburn  2655: 
1.369.2.10  raeburn  2656: sub countdown_timer {
                   2657:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.369.2.24  raeburn  2658:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
                   2659:         my ($type,$hastimeleft,$slothastime);
                   2660:         my $now = time;
                   2661:         if ($env{'request.filename'} =~ /\.task$/) {
                   2662:             $type = 'Task';
                   2663:         } else {
                   2664:             $type = 'problem';
                   2665:         }
                   2666:         my ($status,$accessmsg,$slot_name,$slot) =
                   2667:             &Apache::lonhomework::check_slot_access('0',$type);
                   2668:         if ($slot_name ne '') {
                   2669:             if (ref($slot) eq 'HASH') {
                   2670:                 if (($slot->{'starttime'} < $now) &&
                   2671:                     ($slot->{'endtime'} > $now)) {
                   2672:                     $slothastime = 1;
                   2673:                 }
                   2674:             }
                   2675:         }
                   2676:         if ($status ne 'CAN_ANSWER') {
                   2677:             return;
                   2678:         }
1.369.2.10  raeburn  2679:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.369.2.12  raeburn  2680:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.369.2.13  raeburn  2681:         if (@interval > 1) {
                   2682:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
                   2683:             if ($first_access > 0) {
                   2684:                 if ($first_access+$interval[0] > time) {
                   2685:                     $hastimeleft = 1;
                   2686:                 }
                   2687:             }
                   2688:         }
1.369.2.12  raeburn  2689:         if (($duedate && $duedate > time) ||
1.369.2.24  raeburn  2690:             (!$duedate && $hastimeleft) ||
                   2691:             ($slot_name ne '' && $slothastime)) {
1.369.2.11  raeburn  2692:             my ($collapse,$expand,$alttxt,$title,$currdisp);
1.369.2.24  raeburn  2693:             if ((@interval > 1 && $hastimeleft) ||
                   2694:                 ($type eq 'Task' && $slothastime)) {
1.369.2.10  raeburn  2695:                 $currdisp = 'inline';
                   2696:                 $collapse = '&#9658;&nbsp;';
                   2697:             } else {
                   2698:                 $currdisp = 'none';
                   2699:                 $expand = '&#9668;&nbsp;';
                   2700:             }
                   2701:             unless ($env{'environment.icons'} eq 'iconsonly') {
1.369.2.11  raeburn  2702:                 $alttxt = &mt('Timer');
                   2703:                 $title = $alttxt.'&nbsp;';
1.369.2.10  raeburn  2704:             }
                   2705:             my $desc = &mt('Countdown to due date/time');
                   2706:             return <<END;
                   2707: 
                   2708: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2709: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
                   2710: $collapse
1.369.2.11  raeburn  2711: </span></a>
1.369.2.10  raeburn  2712: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
                   2713: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2714: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.369.2.11  raeburn  2715: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
1.369.2.10  raeburn  2716: END
                   2717:         }
                   2718:     }
                   2719:     return;
                   2720: }
                   2721: 
1.2       www      2722: # ================================================================ Main Program
                   2723: 
1.16      harris41 2724: BEGIN {
1.166     albertel 2725:     if (! defined($readdesk)) {
1.283     droeschl 2726:         {
                   2727:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   2728:             if ( CORE::open( my $config,"<$tabfile") ) {
                   2729:                 while (my $configline=<$config>) {
                   2730:                     $configline=(split(/\#/,$configline))[0];
                   2731:                     $configline=~s/^\s+//;
                   2732:                     chomp($configline);
1.209     www      2733:                     if ($configline=~/^cat\:/) {
1.283     droeschl 2734:                         my @entries=split(/\:/,$configline);
                   2735:                         $category_positions{$entries[2]}=$entries[1];
                   2736:                         $category_names{$entries[2]}=$entries[3];
                   2737:                     } elsif ($configline=~/^prim\:/) {
1.369.2.42  raeburn  2738:                         my @entries = (split(/\:/, $configline))[1..6];
1.369.2.30  raeburn  2739:                         push(@primary_menu,\@entries);
1.369.2.3  raeburn  2740:                     } elsif ($configline=~/^primsub\:/) {
                   2741:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.369.2.30  raeburn  2742:                         push(@{$primary_submenu{$parent}},\@entries);
1.283     droeschl 2743:                     } elsif ($configline=~/^scnd\:/) {
                   2744:                         my @entries = (split(/\:/, $configline))[1..5];
1.369.2.30  raeburn  2745:                         push(@secondary_menu,\@entries);
1.369.2.5  raeburn  2746:                     } elsif ($configline=~/^scndsub\:/) {
                   2747:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.369.2.30  raeburn  2748:                         push(@{$secondary_submenu{$parent}},\@entries);
1.283     droeschl 2749:                     } elsif ($configline) {
                   2750:                         push(@desklines,$configline);
                   2751:                     }
                   2752:                 }
                   2753:                 CORE::close($config);
                   2754:             }
                   2755:         }
                   2756:         $readdesk='done';
1.2       www      2757:     }
                   2758: }
1.30      www      2759: 
1.1       www      2760: 1;
                   2761: __END__
                   2762: 

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