File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.318: download - view: text, annotated - select for diffs
Tue Mar 16 19:55:49 2010 UTC (14 years, 2 months ago) by droeschl
Branches: MAIN
CVS tags: HEAD
In process of removing remote control, remote navmap and different icon modes code
- mostly remote navmap related code and files removed
- some minor refactoring
- some translations added/removed

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

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