File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.323: download - view: text, annotated - select for diffs
Mon Mar 29 00:53:52 2010 UTC (14 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- No "Return to Last Location" when viewing special documents included in
  course:  (navmaps, aboutme, viewclasslist).
- No evaluation, feedback or metadata icons in secondary menu for
  special documents: navmaps, aboutme, viewclasslist, aboutme/portfolio
  (accessible files in group or user portfolio) included in course.

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

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