File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.321: download - view: text, annotated - select for diffs
Mon Mar 22 20:11:22 2010 UTC (14 years, 2 months ago) by droeschl
Branches: MAIN
CVS tags: HEAD
In process of removing remote control, remote navmap and different icon modes code
- removed no_inline_link argument from loncommon::start_page, loncommon::bodytag
- removed subs
    o loncommon::head: it wasn't used
    o loncommon::endheadtag: functionality now covered by loncommon::headtag
    o lonmenu::registerurl: functionality moved to loncommon::headtag, because it was the only function that called registerurl
- removed remote control related translations in de.pm
- refactoring and cleanup

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

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