File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.319: download - view: text, annotated - select for diffs
Wed Mar 17 19:35:56 2010 UTC (14 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- If no user session, display same menu items as shown to "public" users.
  (appropriate for /adm/resetpw, /adm/createaccount, /adm/coursecatalog).

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

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