File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.320: download - view: text, annotated - select for diffs
Mon Mar 22 15:10:10 2010 UTC (14 years, 2 months ago) by droeschl
Branches: MAIN
CVS tags: HEAD
This fixes the Course Contents link in main menu and in problem breadcrumbs.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.320 2010/03/22 15:10:10 droeschl Exp $
    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: #
   28: #
   29: # There is one parameter controlling the action of this module:
   30: #
   31: 
   32: =head1 NAME
   33: 
   34: Apache::lonmenu
   35: 
   36: =head1 SYNOPSIS
   37: 
   38: Coordinates the response to clicking an image.
   39: 
   40: This is part of the LearningOnline Network with CAPA project
   41: described at http://www.lon-capa.org.
   42: 
   43: =head1 GLOBAL VARIABLES
   44: 
   45: =over
   46: 
   47: =item @desklines
   48: 
   49: Each element of this array contains a line of mydesk.tab that doesn't start with
   50: cat, prim or scnd. 
   51: It gets filled in the BEGIN block of this module.
   52: 
   53: =item %category_names
   54: 
   55: The keys of this hash are the abbreviations used in mydesk.tab in those lines that 
   56: start with cat, the values are strings representing titles. 
   57: It gets filled in the BEGIN block of this module.
   58: 
   59: =item %category_members
   60: 
   61: TODO 
   62: 
   63: =item %category_positions
   64: 
   65: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
   66: start with cat, its values are position vectors (column, row). 
   67: It gets filled in the BEGIN block of this module.
   68: 
   69: =item $readdesk
   70: 
   71: Indicates that mydesk.tab has been read. 
   72: It is set to 'done' in the BEGIN block of this module.
   73: 
   74: =item @primary_menu
   75: 
   76: The elements of this array reference arrays that are made up of the components
   77: of those lines of mydesk.tab that start with prim.
   78: It is used by primary_menu() to generate the corresponding menu.
   79: It gets filled in the BEGIN block of this module.
   80: 
   81: =item @secondary_menu
   82: 
   83: The elements of this array reference arrays that are made up of the components
   84: of those lines of mydesk.tab that start with scnd.
   85: It is used by secondary_menu() to generate the corresponding menu.
   86: It gets filled in the BEGIN block of this module.
   87: 
   88: =back
   89: 
   90: =head1 SUBROUTINES
   91: 
   92: =over
   93: 
   94: =item prep_menuitems(\@menuitem)
   95: 
   96: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and 
   97: secondary_menu().
   98: 
   99: =item primary_menu()
  100: 
  101: This routine evaluates @primary_menu and returns XHTML for the menu
  102: that contains following links: About, Message, Roles, Help, Logout
  103: @primary_menu is filled within the BEGIN block of this module with 
  104: entries from mydesk.tab 
  105: 
  106: =item secondary_menu()
  107: 
  108: Same as primary_menu() but operates on @secondary_menu.
  109: 
  110: =item show_return_link()
  111: 
  112: =item registerurl()
  113: 
  114: This gets called in the header section
  115: 
  116: =item innerregister()
  117: 
  118: This gets called in order to register a URL in the body of the document
  119: 
  120: =item clear()
  121: 
  122: =item switch()
  123: 
  124: Switch a button or create a link
  125: Switch acts on the javascript that is executed when a button is clicked.  
  126: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  127: 
  128: =item secondlevel()
  129: 
  130: =item openmenu()
  131: 
  132: =item inlinemenu()
  133: 
  134: =item rawconfig()
  135: 
  136: =item utilityfunctions()
  137: 
  138: =item serverform()
  139: 
  140: =item constspaceform()
  141: 
  142: =item get_nav_status()
  143: 
  144: =item hidden_button_check()
  145: 
  146: =item roles_selector()
  147: 
  148: =item jump_to_role()
  149: 
  150: =back
  151: 
  152: =cut
  153: 
  154: package Apache::lonmenu;
  155: 
  156: use strict;
  157: use Apache::lonnet;
  158: use Apache::lonhtmlcommon();
  159: use Apache::loncommon();
  160: use Apache::lonenc();
  161: use Apache::lonlocal;
  162: use LONCAPA qw(:DEFAULT :match);
  163: use HTML::Entities();
  164: 
  165: use vars qw(@desklines %category_names %category_members %category_positions 
  166:             $readdesk @primary_menu @secondary_menu);
  167: 
  168: my @inlineremote;
  169: 
  170: sub prep_menuitem {
  171:     my ($menuitem) = @_;
  172:     return '' unless(ref($menuitem) eq 'ARRAY');
  173:     my $link;
  174:     if ($$menuitem[1]) { # graphical Link
  175:         $link = "<img class=\"LC_noBorder\""
  176:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
  177:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
  178:     } else {             # textual Link
  179:         $link = &mt($$menuitem[3]);
  180:     }
  181:     return '<li><a' 
  182:            # highlighting for new messages
  183:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
  184:            . qq| href="$$menuitem[0]">$link</a></li>|;
  185: }
  186: 
  187: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
  188: # that contains following links:
  189: # About, Message, Roles, Help, Logout
  190: # @primary_menu is filled within the BEGIN block of this module with 
  191: # entries from mydesk.tab
  192: sub primary_menu {
  193:     my $menu;
  194:     # each element of @primary contains following array:
  195:     # (link url, icon path, alt text, link text, condition)
  196:     my $public;
  197:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
  198:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
  199:         $public = 1;
  200:     }
  201:     foreach my $menuitem (@primary_menu) {
  202:         # evaluate conditions 
  203:         next if    ref($menuitem)       ne 'ARRAY';    #
  204:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
  205:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
  206:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
  207:                 && !&Apache::lonmsg::mynewmail();      # 
  208:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
  209:                 && $public;                            ##who should not see all
  210:                                                        ##links
  211:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
  212:                 && !$public;                           # only visible to public
  213:                                                        # users
  214:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
  215:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
  216:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
  217:                 && !&Apache::loncommon::show_course(); ##
  218:         
  219:             
  220:         if ($$menuitem[3] eq 'Help') { # special treatment for helplink
  221:             $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
  222:         } else {
  223:             my @items = @{$menuitem};
  224:             $items[0] = 'javascript:'.$menuitem->[0].';';
  225:             $menu .= &prep_menuitem(\@items);
  226:         }
  227:     }
  228: 
  229:     return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
  230: }
  231: 
  232: 
  233: sub secondary_menu {
  234:     my $menu;
  235: 
  236:     my $crstype = &Apache::loncommon::course_type();
  237:     my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
  238:     my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'}
  239:                    . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
  240:                                                  : '')); 
  241:     my $showlink = &show_return_link();
  242:     my %groups = &Apache::lonnet::get_active_groups(
  243:                      $env{'user.domain'}, $env{'user.name'},
  244:                      $env{'course.' . $env{'request.course.id'} . '.domain'},
  245:                      $env{'course.' . $env{'request.course.id'} . '.num'});
  246:     foreach my $menuitem (@secondary_menu) {
  247:         # evaluate conditions 
  248:         next if    ref($menuitem)  ne 'ARRAY';
  249:         next if    $$menuitem[4]   ne 'always'
  250:                 && !$env{'request.course.id'};
  251:         next if    $$menuitem[4]   eq 'showreturn'
  252:                 && !$showlink
  253:                 && !($env{'request.state'} eq 'construct');
  254:         next if    $$menuitem[4]   =~ /^mdc/
  255:                 && !$canedit;
  256:         next if    $$menuitem[4]  eq 'mdcCourse'
  257:                 && $crstype eq 'Community';
  258:         next if    $$menuitem[4]  eq 'mdcCommunity'
  259:                 && $crstype ne 'Community';
  260:         next if    $$menuitem[4] =~ /^Course$/
  261:                 && $crstype eq 'Community';
  262:         next if    $$menuitem[4] =~ /^Community$/
  263:                 && $crstype ne 'Community';
  264:         next if    $$menuitem[4]   =~ /showgroups$/
  265:                 && !$canviewgrps
  266:                 && !%groups;
  267: 
  268:         if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
  269:             # special treatment for role selector
  270:             my $roles_selector = &roles_selector(
  271:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
  272:                         $env{'course.' . $env{'request.course.id'} . '.num'}  );
  273: 
  274:             $menu .= $roles_selector ? "<li>$roles_selector</li>"
  275:                                      : '';
  276:         } else {
  277:             $menu .= &prep_menuitem(\@$menuitem);
  278:         }
  279:     }
  280:     if ($menu =~ /\[url\].*\[symb\]/) {
  281:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
  282:                              $env{'request.noversionuri'}));
  283: 
  284:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
  285:                              $env{'request.symb'})); 
  286: 
  287:         if (    $env{'request.state'} eq 'construct'
  288:             and (   $env{'request.noversionuri'} eq '' 
  289:                  || !defined($env{'request.noversionuri'}))) 
  290:         {
  291:             ($escurl = $env{'request.filename'}) =~ 
  292:                 s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
  293: 
  294:             $escurl  = &escape($escurl);
  295:         }    
  296:         $menu =~ s/\[url\]/$escurl/g;
  297:         $menu =~ s/\[symb\]/$escsymb/g;
  298:     }
  299: 
  300:     return "<ul id=\"LC_secondary_menu\">$menu</ul>";
  301: }
  302: 
  303: sub show_return_link {
  304:     return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
  305: 	     $env{'request.symb'} eq '')
  306: 	    ||
  307: 	    ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
  308: 	    ||
  309: 	    (($env{'request.noversionuri'}=~/^\/adm\//) &&
  310: 	     ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
  311: 	     ($env{'request.noversionuri'}!~
  312: 	      m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
  313: 	     ));
  314: }
  315: 
  316: 
  317: sub registerurl {
  318:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  319:     return Apache::lonxml::display_title();
  320: }
  321: 
  322: sub innerregister {
  323:     my ($forcereg,$titletable,$bread_crumbs) = @_;
  324:     my ($uname,$thisdisfn);
  325:     my $const_space = ($env{'request.state'} eq 'construct');
  326:     my $is_const_dir = 0;
  327: 
  328:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  329: 
  330:     $env{'request.registered'} = 1;
  331: 
  332:     undef(@inlineremote);
  333: 
  334:     if ( $env{'request.symb'} && $env{'request.course.id'} ) {
  335: 
  336:         my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  337:         my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
  338: 
  339:         my $maptitle = &Apache::lonnet::gettitle($mapurl);
  340:         my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
  341: 
  342: #SD
  343: #course_type only Course and Community?
  344: #
  345:         my @crumbs = ({text  => Apache::loncommon::course_type() 
  346:                                 . ' Contents', 
  347:                        href  => "Javascript:gopost('/adm/navmaps','')"});
  348: 
  349:         if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
  350:             push(@crumbs, {text  => '...',
  351:                            no_mt => 1});
  352:         }
  353: 
  354:         push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
  355:                                                    && $maptitle ne 'default.sequence' 
  356:                                                    && $maptitle ne $coursetitle);
  357: 
  358:         push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
  359: 
  360:         &Apache::lonhtmlcommon::clear_breadcrumbs();
  361:         &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
  362:     }
  363: # =============================================================================
  364: # ============================ This is for URLs that actually can be registered
  365:     return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/}) 
  366:                        || $forcereg );
  367: 
  368: # -- This applies to homework problems for users with grading privileges
  369: 	my $crs='/'.$env{'request.course.id'};
  370: 	if ($env{'request.course.sec'}) {
  371: 	    $crs.='_'.$env{'request.course.sec'};
  372: 	}
  373: 	$crs=~s/\_/\//g;
  374: 
  375:         my $hwkadd='';
  376:         if ($env{'request.symb'} ne '' &&
  377: 	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
  378: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
  379: 		$hwkadd.=&switch('','',7,2,'pgrd.png','problem[_1]','grades[_4]',
  380:                        "gocmd('/adm/grades','gradingmenu')",
  381:                        'Modify user grades for this assessment resource');
  382:             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
  383: 		$hwkadd.=&switch('','',7,2,'subm.png','view sub-[_1]','missions[_1]',
  384:                        "gocmd('/adm/grades','submission')",
  385: 		       'View user submissions for this assessment resource');
  386:             }
  387: 	}
  388: 	if ($env{'request.symb'} ne '' &&
  389: 	    &Apache::lonnet::allowed('opa',$crs)) {
  390: 	    $hwkadd.=&switch('','',7,3,'pparm.png','problem[_2]','parms[_2]',
  391: 			     "gocmd('/adm/parmset','set')",
  392: 			     'Modify parameter settings for this resource');
  393: 	}
  394: # -- End Homework
  395:         ###
  396:         ### Determine whether or not to display the 'cstr' button for this
  397:         ### resource
  398:         ###
  399:         my $editbutton = '';
  400:         my $noeditbutton = 1;
  401:         my ($cnum,$cdom);
  402:         if ($env{'request.course.id'}) {
  403:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  404:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  405:         }
  406:         if ($env{'user.author'}) {
  407:             if ($env{'request.role'}=~/^(aa|ca|au)/) {
  408: #
  409: # We have the role of an author
  410: #
  411:                 # Set defaults for authors
  412:                 my ($top,$bottom) = ('con-','struct');
  413:                 my $action = "go('/priv/".$env{'user.name'}."');";
  414:                 my $cadom  = $env{'request.role.domain'};
  415:                 my $caname = $env{'user.name'};
  416:                 my $desc = "Enter my construction space";
  417:                 # Set defaults for co-authors
  418:                 if ($env{'request.role'} =~ /^ca/) { 
  419:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
  420:                     ($top,$bottom) = ('co con-','struct');
  421:                     $action = "go('/priv/".$caname."');";
  422:                     $desc = "Enter construction space as co-author";
  423:                 } elsif ($env{'request.role'} =~ /^aa/) {
  424:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
  425:                     ($top,$bottom) = ('co con-','struct');
  426:                     $action = "go('/priv/".$caname."');";
  427:                     $desc = "Enter construction space as assistant co-author";
  428:                 }
  429:                 # Check that we are on the correct machine
  430:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
  431: 		my $allowed=0;
  432: 		my @ids=&Apache::lonnet::current_machine_ids();
  433: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  434: 		if (!$allowed) {
  435: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
  436:                     $noeditbutton = 0;
  437:                 }
  438:             }
  439: #
  440: # We are an author for some stuff, but currently do not have the role of author.
  441: # Figure out if we have authoring privileges for the resource we are looking at.
  442: # This should maybe become a privilege check in lonnet
  443: #
  444:             ##
  445:             ## Determine if user can edit url.
  446:             ##
  447:             my $cfile='';
  448:             my $cfuname='';
  449:             my $cfudom='';
  450:             my $uploaded;
  451:             if ($env{'request.filename'}) {
  452:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
  453:                 if (defined($cnum) && defined($cdom)) {
  454:                     $uploaded = &is_course_upload($file,$cnum,$cdom);
  455:                 }
  456:                 if (!$uploaded) {
  457:                     $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
  458:                     # Check that the user has permission to edit this resource
  459:                     ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
  460:                     if (defined($cfudom)) {
  461: 		        my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
  462: 		        my $allowed=0;
  463: 		        my @ids=&Apache::lonnet::current_machine_ids();
  464: 		        foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  465: 		        if ($allowed) {
  466:                             $cfile=$file;
  467:                         }
  468:                     }
  469:                 }
  470:             }
  471:             # Finally, turn the button on or off
  472:             if ($cfile && !$const_space) {
  473:                 my $nocrsedit;
  474:                 # Suppress display where CC has switched to student role.
  475:                 if ($env{'request.course.id'}) {
  476:                     unless(&Apache::lonnet::allowed('mdc',
  477:                                                     $env{'request.course.id'})) {
  478:                         $nocrsedit = 1;
  479:                     }
  480:                 }
  481:                 if ($nocrsedit) {
  482:                     $editbutton=&clear(6,1);
  483:                 } else {
  484:                     $editbutton=&switch
  485:                        ('','',6,1,'pcstr.png','edit[_1]','resource[_2]',
  486:                      "go('".$cfile."');","Edit this resource");
  487:                     $noeditbutton = 0;
  488:                 }
  489:             } elsif ($editbutton eq '') {
  490:                 $editbutton=&clear(6,1);
  491:             }
  492:         }
  493:         if (($noeditbutton) && ($env{'request.filename'})) { 
  494:             if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  495:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
  496:                 if (defined($cnum) && defined($cdom)) {
  497:                     if (&is_course_upload($file,$cnum,$cdom)) {
  498:                         my $cfile = &edit_course_upload($file,$cnum,$cdom);
  499:                         if ($cfile) {
  500:                             $editbutton=&switch
  501:                                         ('','',6,1,'pcstr.png','edit[_1]',
  502:                                          'resource[_2]',"go('".$cfile."');",
  503:                                          'Edit this resource');
  504:                         }
  505:                     }
  506:                 }
  507:             }
  508:         }
  509:         ###
  510:         ###
  511: # Prepare the rest of the buttons
  512:         my $menuitems;
  513:         if ($const_space) {
  514: #
  515: # We are in construction space
  516: #
  517: 	    my ($uname,$thisdisfn) =
  518: 		($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
  519:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
  520:             if ($currdir =~ m-/$-) {
  521:                 $is_const_dir = 1;
  522:             } else {
  523:                 $currdir =~ s|[^/]+$||;
  524: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  525: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
  526: #
  527: # Probably should be in mydesk.tab
  528: #
  529:                 $menuitems=(<<ENDMENUITEMS);
  530: s&6&1&list.png&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
  531: s&6&2&rtrv.png&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
  532: s&6&3&pub.png&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
  533: s&7&1&del.png&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
  534: s&7&2&prt.png&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
  535: ENDMENUITEMS
  536:             }
  537:                 if (ref($bread_crumbs) eq 'ARRAY') {
  538:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
  539:                     foreach my $crumb (@{$bread_crumbs}){
  540:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
  541:                     }
  542:                 }
  543:         } elsif ( defined($env{'request.course.id'}) && 
  544: 		 $env{'request.symb'} ne '' ) {
  545: #
  546: # We are in a course and looking at a registred URL
  547: # Should probably be in mydesk.tab
  548: #
  549: 	    $menuitems=(<<ENDMENUITEMS);
  550: c&3&1
  551: s&2&1&back.png&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
  552: s&2&3&forw.png&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
  553: c&6&3
  554: c&8&1
  555: c&8&2
  556: s&8&3&prt.png&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  557: s&9&1&sbkm.png&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
  558: ENDMENUITEMS
  559: 
  560: my $currentURL = &Apache::loncommon::get_symb();
  561: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
  562: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
  563: $menuitems.="s&9&3&";
  564: if(length($annotation) > 0){
  565: 	$menuitems.="anot2.png";
  566: }else{
  567: 	$menuitems.="anot.png";
  568: }
  569: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
  570: $menuitems.="Make notes and annotations about this resource&&1\n";
  571: 
  572:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
  573: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
  574: 		    $menuitems.=(<<ENDREALRES);
  575: s&6&3&catalog.png&catalog[_2]&info[_1]&catalog_info()&Show Metadata
  576: ENDREALRES
  577:                 }
  578: 	        $menuitems.=(<<ENDREALRES);
  579: s&8&1&eval.png&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  580: s&8&2&fdbk.png&feedback[_1]&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
  581: ENDREALRES
  582: 	    }
  583:         }
  584: 	if ($env{'request.uri'} =~ /^\/res/) {
  585: 	    $menuitems .= (<<ENDMENUITEMS);
  586: s&8&3&prt.png&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  587: ENDMENUITEMS
  588: 	}
  589:         my $buttons='';
  590:         foreach (split(/\n/,$menuitems)) {
  591: 	    my ($command,@rest)=split(/\&/,$_);
  592:             my $idx=10*$rest[0]+$rest[1];
  593:             if (&hidden_button_check() eq 'yes') {
  594:                 if ($idx == 21 ||$idx == 23) {
  595:                     $buttons.=&switch('','',@rest);
  596:                 } else {
  597:                     $buttons.=&clear(@rest);
  598:                 }
  599:             } else {  
  600:                 if ($command eq 's') {
  601: 	            $buttons.=&switch('','',@rest);
  602:                 } else {
  603:                     $buttons.=&clear(@rest);
  604:                 }
  605:             }
  606:         }
  607: 
  608: 	    my $addremote=0;
  609: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
  610:     if ($addremote) {
  611: 
  612:         Apache::lonhtmlcommon::clear_breadcrumb_tools();
  613: 
  614:             Apache::lonhtmlcommon::add_breadcrumb_tool(
  615:                 'navigation', @inlineremote[21,23]);
  616: 
  617:         if(hidden_button_check() ne 'yes') {
  618:             Apache::lonhtmlcommon::add_breadcrumb_tool(
  619:                 'tools', @inlineremote[93,91,81,82,83]);
  620: 
  621:             #publish button in construction space
  622:             if ($env{'request.state'} eq 'construct'){
  623:                 Apache::lonhtmlcommon::add_breadcrumb_tool(
  624:                      'advtools', @inlineremote[63]);
  625:             }else{
  626:                 Apache::lonhtmlcommon::add_breadcrumb_tool(
  627:                      'tools', @inlineremote[63]);
  628:             }
  629:             
  630: 
  631:             Apache::lonhtmlcommon::add_breadcrumb_tool(
  632:                 'advtools', @inlineremote[61,71,72,73,92]);
  633:         }
  634:     }
  635: 
  636:     return   Apache::lonhtmlcommon::scripttag('', 'start')
  637:            . Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
  638:            . Apache::lonhtmlcommon::scripttag('', 'end');
  639: }
  640: 
  641: sub is_course_upload {
  642:     my ($file,$cnum,$cdom) = @_;
  643:     my $uploadpath = &LONCAPA::propath($cdom,$cnum);
  644:     $uploadpath =~ s{^\/}{};
  645:     if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
  646:         ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
  647:         return 1;
  648:     }
  649:     return;
  650: }
  651: 
  652: sub edit_course_upload {
  653:     my ($file,$cnum,$cdom) = @_;
  654:     my $cfile;
  655:     if ($file =~/\.(htm|html|css|js|txt)$/) {
  656:         my $ext = $1;
  657:         my $url = &Apache::lonnet::hreflocation('',$file);
  658:         my $home = &Apache::lonnet::homeserver($cnum,$cdom);
  659:         my @ids=&Apache::lonnet::current_machine_ids();
  660:         my $dest;
  661:         if ($home && grep(/^\Q$home\E$/,@ids)) {
  662:             $dest = $url.'?forceedit=1';
  663:         } else {
  664:             unless (&Apache::lonnet::get_locks()) {
  665:                 $dest = '/adm/switchserver?otherserver='.
  666:                         $home.'&role='.$env{'request.role'}.
  667:                         '&url='.$url.'&forceedit=1';
  668:             }
  669:         }
  670:         if ($dest) {
  671:             $cfile = &HTML::Entities::encode($dest,'"<>&');
  672:         }
  673:     }
  674:     return $cfile;
  675: }
  676: 
  677: # ================================================================== Raw Config
  678: 
  679: #SD
  680: #this is called by
  681: #lonmenu
  682: #
  683: sub clear {
  684:     my ($row,$col)=@_;
  685:     $inlineremote[10*$row+$col]='';
  686:     return ''; 
  687: }
  688: 
  689: # ============================================ Switch a button or create a link
  690: # Switch acts on the javascript that is executed when a button is clicked.  
  691: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  692: 
  693: sub switch {
  694:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
  695:     $act=~s/\$uname/$uname/g;
  696:     $act=~s/\$udom/$udom/g;
  697:     $top=&mt($top);
  698:     $bot=&mt($bot);
  699:     $desc=&mt($desc);
  700:     my $idx=10*$row+$col;
  701:     $category_members{$cat}.=':'.$idx;
  702: 
  703: # Inline Menu
  704:     if ($nobreak==2) { return ''; }
  705:     my $text=$top.' '.$bot;
  706:     $text=~s/\s*\-\s*//gs;
  707: 
  708:     my $pic=
  709: 	   '<img alt="'.$text.'" src="'.
  710: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
  711: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
  712:     if ($env{'browser.interface'} eq 'faketextual') {
  713: # Main Menu
  714: 	   if ($nobreak==3) {
  715: 	       $inlineremote[$idx]="\n".
  716: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
  717: 		   '</td><td align="left">'.
  718: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
  719: 	   } elsif ($nobreak) {
  720: 	       $inlineremote[$idx]="\n<tr>".
  721: 		   '<td align="left">'.
  722: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
  723:                     <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>';
  724: 	   } else {
  725: 	       $inlineremote[$idx]="\n<tr>".
  726: 		   '<td align="left">'.
  727: 		   '<a href="javascript:'.$act.';">'.$pic.
  728: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
  729: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
  730: 	   }
  731:     } else {
  732: # Inline Menu
  733:       $inlineremote[$idx]=
  734:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
  735:        '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
  736:     }
  737:     return '';
  738: }
  739: 
  740: sub secondlevel {
  741:     my $output='';
  742:     my 
  743:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
  744:     if ($prt eq 'any') {
  745: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  746:     } elsif ($prt=~/^r(\w+)/) {
  747:         if ($rol eq $1) {
  748:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  749:         }
  750:     }
  751:     return $output;
  752: }
  753: 
  754: sub inlinemenu {
  755:     undef(@inlineremote);
  756:     undef(%category_members);
  757: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
  758:     &rawconfig(1);
  759:     my $output='<table><tr>';
  760:     for (my $col=1; $col<=2; $col++) {
  761:         $output.='<td class="LC_mainmenu_col_fieldset">';
  762:         for (my $row=1; $row<=8; $row++) {
  763:             foreach my $cat (keys(%category_members)) {
  764:                if ($category_positions{$cat} ne "$col,$row") { next; }
  765:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
  766:                $output.='<div class="LC_Box LC_400Box">';
  767: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
  768:                $output.='<table>';
  769:                my %active=();
  770:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
  771:                   if ($inlineremote[$menu_item]) {
  772:                      $active{$menu_item}=1;
  773:                   }
  774:                }  
  775:                foreach my $item (sort(keys(%active))) {
  776:                   $output.=$inlineremote[$item];
  777:                }
  778:                $output.='</table>';
  779:                $output.='</div>';
  780:             }
  781:          }
  782:          $output.="</td>";
  783:     }
  784:     $output.="</tr></table>";
  785:     return $output;
  786: }
  787: 
  788: sub rawconfig {
  789: #
  790: # This evaluates mydesk.tab
  791: # Need to add more positions and more privileges to deal with all
  792: # menu items.
  793: #
  794:     my $textualoverride=shift;
  795:     my $output='';
  796:     return '' unless $textualoverride;
  797:     my $uname=$env{'user.name'};
  798:     my $udom=$env{'user.domain'};
  799:     my $adv=$env{'user.adv'};
  800:     my $show_course=&Apache::loncommon::show_course();
  801:     my $author=$env{'user.author'};
  802:     my $crs='';
  803:     my $crstype='';
  804:     if ($env{'request.course.id'}) {
  805:        $crs='/'.$env{'request.course.id'};
  806:        if ($env{'request.course.sec'}) {
  807: 	   $crs.='_'.$env{'request.course.sec'};
  808:        }
  809:        $crs=~s/\_/\//g;
  810:        $crstype = &Apache::loncommon::course_type();
  811:     }
  812:     my $pub=($env{'request.state'} eq 'published');
  813:     my $con=($env{'request.state'} eq 'construct');
  814:     my $rol=$env{'request.role'};
  815:     my $requested_domain = $env{'request.role.domain'};
  816:     foreach my $line (@desklines) {
  817:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
  818:         $prt=~s/\$uname/$uname/g;
  819:         $prt=~s/\$udom/$udom/g;
  820:         if ($prt =~ /\$crs/) {
  821:             next unless ($env{'request.course.id'});
  822:             next if ($crstype eq 'Community');
  823:             $prt=~s/\$crs/$crs/g;
  824:         } elsif ($prt =~ /\$cmty/) {
  825:             next unless ($env{'request.course.id'});
  826:             next if ($crstype ne 'Community');
  827:             $prt=~s/\$cmty/$crs/g;
  828:         }
  829:         $prt=~s/\$requested_domain/$requested_domain/g;
  830:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
  831:         if ($pro eq 'clear') {
  832: 	    $output.=&clear($row,$col);
  833:         } elsif ($pro eq 'any') {
  834:                $output.=&secondlevel(
  835: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
  836: 	} elsif ($pro eq 'smp') {
  837:             unless ($adv) {
  838:                $output.=&secondlevel(
  839:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
  840:             }
  841:         } elsif ($pro eq 'adv') {
  842:             if ($adv) {
  843:                $output.=&secondlevel(
  844: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
  845:             }
  846: 	} elsif ($pro eq 'shc') {
  847:             if ($show_course) {
  848:                $output.=&secondlevel(
  849:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
  850:             }
  851:         } elsif ($pro eq 'nsc') {
  852:             if (!$show_course) {
  853:                $output.=&secondlevel(
  854: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
  855:             }
  856:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
  857:             my $priv = $1;
  858:             if ($priv =~ /^mdc(Course|Community)/) {
  859:                 if ($crstype eq $1) {
  860:                     $priv = 'mdc';
  861:                 } else {
  862:                     next;
  863:                 }
  864:             }
  865: 	    if (&Apache::lonnet::allowed($priv,$prt)) {
  866:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  867:             }
  868:         } elsif ($pro eq 'course')  {
  869:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
  870:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  871: 	    }
  872:         } elsif ($pro eq 'community')  {
  873:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
  874:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  875:             }
  876:         } elsif ($pro =~ /^courseenv_(.*)$/) {
  877:             my $key = $1;
  878:             if ($crstype ne 'Community') {
  879:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
  880:                 if ($key eq 'canuse_pdfforms') {
  881:                     if ($env{'request.course.id'} && $coursepref eq '') {
  882:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
  883:                         $coursepref = $domdefs{'canuse_pdfforms'};
  884:                     }
  885:                 }
  886:                 if ($coursepref) { 
  887:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  888:                 }
  889:             }
  890:         } elsif ($pro =~ /^communityenv_(.*)$/) {
  891:             my $key = $1;
  892:             if ($crstype eq 'Community') {
  893:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
  894:                 if ($key eq 'canuse_pdfforms') {
  895:                     if ($env{'request.course.id'} && $coursepref eq '') {
  896:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
  897:                         $coursepref = $domdefs{'canuse_pdfforms'};
  898:                     }
  899:                 }
  900:                 if ($coursepref) { 
  901:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  902:                 }
  903:             }
  904:         } elsif ($pro =~ /^course_(.*)$/) {
  905:             # Check for permissions inside of a course
  906:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
  907:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
  908:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
  909:                  )) {
  910:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  911: 	    }
  912:         } elsif ($pro =~ /^community_(.*)$/) {
  913:             # Check for permissions inside of a community
  914:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
  915:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
  916:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
  917:                  )) {
  918:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  919:             }
  920:         } elsif ($pro eq 'author') {
  921:             if ($author) {
  922:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
  923:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
  924:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
  925:                     # Check that we are on the correct machine
  926:                     my $cadom=$requested_domain;
  927:                     my $caname=$env{'user.name'};
  928:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
  929: 		       ($cadom,$caname)=
  930:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
  931:                     }                       
  932:                     $act =~ s/\$caname/$caname/g;
  933:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
  934: 		    my $allowed=0;
  935: 		    my @ids=&Apache::lonnet::current_machine_ids();
  936: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  937: 		    if ($allowed) {
  938:                         $output.=&switch($caname,$cadom,
  939:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
  940:                     }
  941:                 }
  942:             }
  943:         } elsif ($pro eq 'tools') {
  944:             my @tools = ('aboutme','blog','portfolio');
  945:             if (grep(/^\Q$prt\E$/,@tools)) {
  946:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
  947:                                                        $env{'user.domain'},
  948:                                                        $prt,undef,'tools')) {
  949:                     $output.=&clear($row,$col);
  950:                     next;
  951:                 }
  952:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
  953:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
  954:                     next;
  955:                 }
  956:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
  957:                     next;
  958:                 }
  959:                 my $showreqcrs = &check_for_rcrs();
  960:                 if (!$showreqcrs) {
  961:                     $output.=&clear($row,$col);
  962:                     next;
  963:                 }
  964:             }
  965:             $prt='any';
  966:             $output.=&secondlevel(
  967:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
  968:         }
  969:     }
  970:     return $output;
  971: }
  972: 
  973: sub check_for_rcrs {
  974:     my $showreqcrs = 0;
  975:     my @reqtypes = ('official','unofficial','community');
  976:     foreach my $type (@reqtypes) {
  977:         if (&Apache::lonnet::usertools_access($env{'user.name'},
  978:                                               $env{'user.domain'},
  979:                                               $type,undef,'requestcourses')) {
  980:             $showreqcrs = 1;
  981:             last;
  982:         }
  983:     }
  984:     if (!$showreqcrs) {
  985:         foreach my $type (@reqtypes) {
  986:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
  987:                 $showreqcrs = 1;
  988:                 last;
  989:             }
  990:         }
  991:     }
  992:     return $showreqcrs;
  993: }
  994: 
  995: sub dc_popup_js {
  996:     my %lt = &Apache::lonlocal::texthash(
  997:                                           more => '(More ...)',
  998:                                           less => '(Less ...)',
  999:                                         );
 1000:     return <<"END";
 1001: 
 1002: function showCourseID() {
 1003:     document.getElementById('dccid').style.display='block';
 1004:     document.getElementById('dccid').style.textAlign='left';
 1005:     document.getElementById('dccid').style.textFace='normal';
 1006:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>';
 1007:     return;
 1008: }
 1009: 
 1010: function hideCourseID() {
 1011:     document.getElementById('dccid').style.display='none';
 1012:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()">$lt{'more'}</a>';
 1013:     return;
 1014: }
 1015: 
 1016: END
 1017: 
 1018: }
 1019: 
 1020: sub utilityfunctions {
 1021:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1022:     if ($currenturl =~ m{^/adm/wrapper/ext/}
 1023:         && $env{'request.external.querystring'} ) {
 1024:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
 1025:     }
 1026:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1027:     
 1028:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1029: 
 1030:     my $dc_popup_cid;
 1031:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
 1032:                         $env{'course.'.$env{'request.course.id'}.
 1033:                                  '.domain'}.'/'})) {
 1034:         $dc_popup_cid = &dc_popup_js();
 1035:     }
 1036: 
 1037:     my $start_page_annotate = 
 1038:         &Apache::loncommon::start_page('Annotator',undef,
 1039: 				       {'only_body' => 1,
 1040: 					'js_ready'  => 1,
 1041: 					'bgcolor'   => '#BBBBBB',
 1042: 					'add_entries' => {
 1043: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1044: 
 1045:     my $end_page_annotate = 
 1046:         &Apache::loncommon::end_page({'js_ready' => 1});
 1047: 
 1048:     my $start_page_bookmark = 
 1049:         &Apache::loncommon::start_page('Bookmarks',undef,
 1050: 				       {'only_body' => 1,
 1051: 					'js_ready'  => 1,
 1052: 					'bgcolor'   => '#BBBBBB',});
 1053: 
 1054:     my $end_page_bookmark = 
 1055:         &Apache::loncommon::end_page({'js_ready' => 1});
 1056: 
 1057: return (<<ENDUTILITY)
 1058: 
 1059:     var currentURL="$currenturl";
 1060:     var reloadURL="$currenturl";
 1061:     var currentSymb="$currentsymb";
 1062: 
 1063: $dc_popup_cid
 1064: 
 1065: function go(url) {
 1066:    if (url!='' && url!= null) {
 1067:        currentURL = null;
 1068:        currentSymb= null;
 1069:        window.location.href=url;
 1070:    }
 1071: }
 1072: 
 1073: function gotop(url) {
 1074:     if (url!='' && url!= null) {
 1075:         top.location.href = url;
 1076:     }
 1077: }
 1078: 
 1079: function gopost(url,postdata) {
 1080:    if (url!='') {
 1081:       this.document.server.action=url;
 1082:       this.document.server.postdata.value=postdata;
 1083:       this.document.server.command.value='';
 1084:       this.document.server.url.value='';
 1085:       this.document.server.symb.value='';
 1086:       this.document.server.submit();
 1087:    }
 1088: }
 1089: 
 1090: function gocmd(url,cmd) {
 1091:    if (url!='') {
 1092:       this.document.server.action=url;
 1093:       this.document.server.postdata.value='';
 1094:       this.document.server.command.value=cmd;
 1095:       this.document.server.url.value=currentURL;
 1096:       this.document.server.symb.value=currentSymb;
 1097:       this.document.server.submit();
 1098:    }
 1099: }
 1100: 
 1101: function gocstr(url,filename) {
 1102:     if (url == '/adm/cfile?action=delete') {
 1103:         this.document.cstrdelete.filename.value = filename
 1104:         this.document.cstrdelete.submit();
 1105:         return;
 1106:     }
 1107:     if (url == '/adm/printout') {
 1108:         this.document.cstrprint.postdata.value = filename
 1109:         this.document.cstrprint.curseed.value = 0;
 1110:         this.document.cstrprint.problemtype.value = 0;
 1111:         if (this.document.lonhomework) {
 1112:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1113:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1114:             }
 1115:             if (this.document.lonhomework.problemtype) {
 1116: 		if (this.document.lonhomework.problemtype.value) {
 1117: 		    this.document.cstrprint.problemtype.value = 
 1118: 			this.document.lonhomework.problemtype.value;
 1119: 		} else if (this.document.lonhomework.problemtype.options) {
 1120: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1121: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1122: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1123: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1124: 				}
 1125: 			}
 1126: 		    }
 1127: 		}
 1128: 	    }
 1129: 	}
 1130:         this.document.cstrprint.submit();
 1131:         return;
 1132:     }
 1133:     if (url !='') {
 1134:         this.document.constspace.filename.value = filename;
 1135:         this.document.constspace.action = url;
 1136:         this.document.constspace.submit();
 1137:     }
 1138: }
 1139: 
 1140: function golist(url) {
 1141:    if (url!='' && url!= null) {
 1142:        currentURL = null;
 1143:        currentSymb= null;
 1144:        top.location.href=url;
 1145:    }
 1146: }
 1147: 
 1148: 
 1149: 
 1150: function catalog_info() {
 1151:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1152: }
 1153: 
 1154: function chat_win() {
 1155:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
 1156: }
 1157: 
 1158: function group_chat(group) {
 1159:    var url = '/adm/groupchat?group='+group;
 1160:    var winName = 'LONchat_'+group;
 1161:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1162: }
 1163: 
 1164: function edit_bookmarks() {
 1165:    go('');
 1166:    w_BookmarkPal_flag=1;
 1167:    bookmarkpal=window.open("/adm/bookmarks",
 1168:                "BookmarkPal", "width=400,height=505,scrollbars=0");
 1169: }
 1170: 
 1171: function annotate() {
 1172:    w_Annotator_flag=1;
 1173:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1174:    annotator.document.write(
 1175:    '$start_page_annotate'
 1176:   +"<form name='goannotate' target='Annotator' method='post' "
 1177:   +"action='/adm/annotations'>"
 1178:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 1179:   +"<\\/form>"
 1180:   +'$end_page_annotate');
 1181:    annotator.document.close();
 1182: }
 1183: 
 1184: function set_bookmark() {
 1185:    go('');
 1186:    clienttitle=document.title;
 1187:    clienthref=location.pathname;
 1188:    w_bmquery_flag=1;
 1189:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
 1190:    bmquery.document.write(
 1191:    '$start_page_bookmark'
 1192:    +'<center><form method="post"'
 1193:    +' name="newlink" action="/adm/bookmarks" target="bmquery" '
 1194:    +'> <table width="340" height="150" '
 1195:    +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
 1196:    +'type="text" name="title" size="45" value="'+clienttitle+'" />'
 1197:    +'<br />Address:<br /><input type="text" name="address" size="45" '
 1198:    +'value="'+clienthref+'" /><br /><center><input type="submit" '
 1199:    +'value="Save" /> <input type="button" value="Close" '
 1200:    +'onclick="javascript:window.close();" /></center></td>'
 1201:    +'</tr></table></form></center>'
 1202:    +'$end_page_bookmark' );
 1203:    bmquery.document.close();
 1204: }
 1205: 
 1206: ENDUTILITY
 1207: }
 1208: 
 1209: sub serverform {
 1210:     return(<<ENDSERVERFORM);
 1211: <form name="server" action="/adm/logout" method="post" target="_top">
 1212: <input type="hidden" name="postdata" value="none" />
 1213: <input type="hidden" name="command" value="none" />
 1214: <input type="hidden" name="url" value="none" />
 1215: <input type="hidden" name="symb" value="none" />
 1216: </form>
 1217: ENDSERVERFORM
 1218: }
 1219: 
 1220: sub constspaceform {
 1221:     return(<<ENDCONSTSPACEFORM);
 1222: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1223: <input type="hidden" name="filename" value="" />
 1224: </form>
 1225: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1226: <input type="hidden" name="action" value="delete" /> 
 1227: <input type="hidden" name="filename" value="" />
 1228: </form>
 1229: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1230: <input type="hidden" name="postdata" value="" />
 1231: <input type="hidden" name="curseed" value="" />
 1232: <input type="hidden" name="problemtype" value="" />
 1233: </form>
 1234: 
 1235: ENDCONSTSPACEFORM
 1236: }
 1237: 
 1238: sub hidden_button_check {
 1239:     if ( $env{'request.course.id'} eq ''
 1240:          || $env{'request.role.adv'} ) {
 1241: 
 1242:         return;
 1243:     }
 1244:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 1245:     return $buttonshide; 
 1246: }
 1247: 
 1248: sub roles_selector {
 1249:     my ($cdom,$cnum) = @_;
 1250:     my $crstype = &Apache::loncommon::course_type();
 1251:     my $now = time;
 1252:     my (%courseroles,%seccount);
 1253:     my $is_cc;
 1254:     my $role_selector;
 1255:     my $ccrole;
 1256:     if ($crstype eq 'Community') {
 1257:         $ccrole = 'co';
 1258:     } else {
 1259:         $ccrole = 'cc';
 1260:     } 
 1261:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
 1262:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
 1263:         
 1264:         if ((($start) && ($start<0)) || 
 1265:             (($end) && ($end<$now))  ||
 1266:             (($start) && ($now<$start))) {
 1267:             $is_cc = 0;
 1268:         } else {
 1269:             $is_cc = 1;
 1270:         }
 1271:     }
 1272:     if ($is_cc) {
 1273:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
 1274:     } else {
 1275:         my %gotnosection;
 1276:         foreach my $item (keys(%env)) {
 1277:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 1278:                 my $role = $1;
 1279:                 my $sec = $2;
 1280:                 next if ($role eq 'gr');
 1281:                 my ($start,$end) = split(/\./,$env{$item});
 1282:                 next if (($start && $start > $now) || ($end && $end < $now));
 1283:                 if ($sec eq '') {
 1284:                     if (!$gotnosection{$role}) {
 1285:                         $seccount{$role} ++;
 1286:                         $gotnosection{$role} = 1;
 1287:                     }
 1288:                 }
 1289:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 1290:                     if ($sec ne '') {
 1291:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
 1292:                             push(@{$courseroles{$role}},$sec);
 1293:                             $seccount{$role} ++;
 1294:                         }
 1295:                     }
 1296:                 } else {
 1297:                     @{$courseroles{$role}} = ();
 1298:                     if ($sec ne '') {
 1299:                         $seccount{$role} ++;
 1300:                         push(@{$courseroles{$role}},$sec);
 1301:                     }
 1302:                 }
 1303:             }
 1304:         }
 1305:     }
 1306:     my $switchtext;
 1307:     if ($crstype eq 'Community') {
 1308:         $switchtext = &mt('Switch community role to...')
 1309:     } else {
 1310:         $switchtext = &mt('Switch course role to...')
 1311:     }
 1312:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
 1313:     if (keys(%courseroles) > 1) {
 1314:         $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
 1315:         $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
 1316:                           <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
 1317:         $role_selector .= '<option value="">'.$switchtext.'</option>';
 1318:         foreach my $role (@roles_order) {
 1319:             if (defined($courseroles{$role})) {
 1320:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>'; 
 1321:             }
 1322:         }
 1323:         foreach my $role (sort(keys(%courseroles))) {
 1324:             if ($role =~ /^cr/) {
 1325:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
 1326:             }
 1327:         }
 1328:         $role_selector .= '</select>'."\n".
 1329:                '<input type="hidden" name="destinationurl" value="'.
 1330:                &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n".
 1331:                '<input type="hidden" name="gotorole" value="1" />'."\n".
 1332:                '<input type="hidden" name="selectrole" value="" />'."\n".
 1333:                '<input type="hidden" name="switch" value="1" />'."\n".
 1334:                '</form>';
 1335:     }
 1336:     return $role_selector;
 1337: }
 1338: 
 1339: sub get_all_courseroles {
 1340:     my ($cdom,$cnum,$courseroles,$seccount) = @_;
 1341:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
 1342:         return;
 1343:     }
 1344:     my ($result,$cached) = 
 1345:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
 1346:     if (defined($cached)) {
 1347:         if (ref($result) eq 'HASH') {
 1348:             if ((ref($result->{'roles'}) eq 'HASH') && 
 1349:                 (ref($result->{'seccount'}) eq 'HASH')) {
 1350:                 %{$courseroles} = %{$result->{'roles'}};
 1351:                 %{$seccount} = %{$result->{'seccount'}};
 1352:                 return;
 1353:             }
 1354:         }
 1355:     }
 1356:     my %gotnosection;
 1357:     my %adv_roles =
 1358:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 1359:     foreach my $role (keys(%adv_roles)) {
 1360:         my ($urole,$usec) = split(/:/,$role);
 1361:         if (!$gotnosection{$urole}) {
 1362:             $seccount->{$urole} ++;
 1363:             $gotnosection{$urole} = 1;
 1364:         }
 1365:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
 1366:             if ($usec ne '') {
 1367:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
 1368:                     push(@{$courseroles->{$urole}},$usec);
 1369:                     $seccount->{$urole} ++;
 1370:                 }
 1371:             }
 1372:         } else {
 1373:             @{$courseroles->{$urole}} = ();
 1374:             if ($usec ne '') {
 1375:                 $seccount->{$urole} ++;
 1376:                 push(@{$courseroles->{$urole}},$usec);
 1377:             }
 1378:         }
 1379:     }
 1380:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
 1381:     @{$courseroles->{'st'}} = ();
 1382:     if (keys(%sections_count) > 0) {
 1383:         push(@{$courseroles->{'st'}},keys(%sections_count));
 1384:         $seccount->{'st'} = scalar(keys(%sections_count)); 
 1385:     }
 1386:     my $rolehash = {
 1387:                      'roles'    => $courseroles,
 1388:                      'seccount' => $seccount,
 1389:                    };
 1390:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
 1391:     return;
 1392: }
 1393: 
 1394: sub jump_to_role {
 1395:     my ($cdom,$cnum,$seccount,$courseroles) = @_;
 1396:     my %lt = &Apache::lonlocal::texthash(
 1397:                 this => 'This role has section(s) associated with it.',
 1398:                 ente => 'Enter a specific section.',
 1399:                 orlb => 'Enter a specific section, or leave blank for no section.',
 1400:                 avai => 'Available sections are:',
 1401:                 youe => 'You entered an invalid section choice:',
 1402:                 plst => 'Please try again',
 1403:     );
 1404:     my $js;
 1405:     if (ref($courseroles) eq 'HASH') {
 1406:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 1407:               '    var numsec = new Array();'."\n".
 1408:               '    var rolesections = new Array();'."\n".
 1409:               '    var rolenames = new Array();'."\n".
 1410:               '    var roleseclist = new Array();'."\n";
 1411:         my @items = keys(%{$courseroles});
 1412:         for (my $i=0; $i<@items; $i++) {
 1413:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 1414:             my ($secs,$secstr);
 1415:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 1416:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 1417:                 $secs = join('","',@sections);
 1418:                 $secstr = join(', ',@sections);
 1419:             }
 1420:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 1421:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 1422:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 1423:         }
 1424:     }
 1425:     return <<"END";
 1426: <script type="text/javascript">
 1427: //<![CDATA[
 1428: function adhocRole(roleitem) {
 1429:     $js
 1430:     var newrole =  document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
 1431:     if (newrole == '') {
 1432:         return; 
 1433:     } 
 1434:     var fullrole = newrole+'./$cdom/$cnum';
 1435:     var selidx = '';
 1436:     for (var i=0; i<rolenames.length; i++) {
 1437:         if (rolenames[i] == newrole) {
 1438:             selidx = i;
 1439:         }
 1440:     }
 1441:     var secok = 1;
 1442:     var secchoice = '';
 1443:     if (selidx >= 0) {
 1444:         if (numsec[selidx] > 1) {
 1445:             secok = 0;
 1446:             var numrolesec = rolesections[selidx].length;
 1447:             var msgidx = numsec[selidx] - numrolesec;
 1448:             secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 1449:             if (secchoice == '') {
 1450:                 if (msgidx > 0) {
 1451:                     secok = 1;
 1452:                 }
 1453:             } else {
 1454:                 for (var j=0; j<rolesections[selidx].length; j++) {
 1455:                     if (rolesections[selidx][j] == secchoice) {
 1456:                         secok = 1;
 1457:                     }
 1458:                 }
 1459:             }
 1460:         } else {
 1461:             if (rolesections[selidx].length == 1) {
 1462:                 secchoice = rolesections[selidx][0];
 1463:             }
 1464:         }
 1465:     }
 1466:     if (secok == 1) {
 1467:         if (secchoice != '') {
 1468:             fullrole += '/'+secchoice;
 1469:         }
 1470:     } else {
 1471:         document.rolechooser.elements[roleitem].selectedIndex = 0;
 1472:         if (secchoice != null) {
 1473:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 1474:         }
 1475:         return;
 1476:     }
 1477:     if (fullrole == "$env{'request.role'}") {
 1478:         return;
 1479:     }
 1480:     itemid = retrieveIndex('gotorole');
 1481:     if (itemid != -1) {
 1482:         document.rolechooser.elements[itemid].name = fullrole;
 1483:     }
 1484:     document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
 1485:     document.rolechooser.selectrole.value = '1';
 1486:     document.rolechooser.submit();
 1487:     return;
 1488: }
 1489: 
 1490: function retrieveIndex(item) {
 1491:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 1492:         if (document.rolechooser.elements[i].name == item) {
 1493:             return i;
 1494:         }
 1495:     }
 1496:     return -1;
 1497: }
 1498: // ]]>
 1499: </script>
 1500: END
 1501: }
 1502: 
 1503: 
 1504: # ================================================================ Main Program
 1505: 
 1506: BEGIN {
 1507:     if (! defined($readdesk)) {
 1508:         {
 1509:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 1510:             if ( CORE::open( my $config,"<$tabfile") ) {
 1511:                 while (my $configline=<$config>) {
 1512:                     $configline=(split(/\#/,$configline))[0];
 1513:                     $configline=~s/^\s+//;
 1514:                     chomp($configline);
 1515:                     if ($configline=~/^cat\:/) {
 1516:                         my @entries=split(/\:/,$configline);
 1517:                         $category_positions{$entries[2]}=$entries[1];
 1518:                         $category_names{$entries[2]}=$entries[3];
 1519:                     } elsif ($configline=~/^prim\:/) {
 1520:                         my @entries = (split(/\:/, $configline))[1..5];
 1521:                         push @primary_menu, \@entries;
 1522:                     } elsif ($configline=~/^scnd\:/) {
 1523:                         my @entries = (split(/\:/, $configline))[1..5];
 1524:                         push @secondary_menu, \@entries; 
 1525:                     } elsif ($configline) {
 1526:                         push(@desklines,$configline);
 1527:                     }
 1528:                 }
 1529:                 CORE::close($config);
 1530:             }
 1531:         }
 1532:         $readdesk='done';
 1533:     }
 1534: }
 1535: 
 1536: 1;
 1537: __END__
 1538: 

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