![]() ![]() | ![]() |
- Customization for GCI_3 - Backport 1.340.
1: # The LearningOnline Network with CAPA 2: # Routines to control the menu 3: # 4: # $Id: lonmenu.pm,v 1.309.2.20 2010/12/02 13:07:08 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: # environment.remote - if this is 'on', the routines controll the remote 32: # control, otherwise they render the main window controls; 33: 34: =head1 NAME 35: 36: Apache::lonmenu 37: 38: =head1 SYNOPSIS 39: 40: Coordinates the response to clicking an image. 41: 42: This is part of the LearningOnline Network with CAPA project 43: described at http://www.lon-capa.org. 44: 45: =head1 SUBROUTINES 46: 47: =over 48: 49: Little texts 50: 51: =item initlittle() 52: 53: =item menubuttons() 54: 55: This gets called at the top of the body section 56: 57: =item show_return_link() 58: 59: =item registerurl() 60: 61: This gets called in the header section 62: 63: =item innerregister() 64: 65: This gets called in order to register a URL, both with the Remote 66: and in the body of the document 67: 68: =item loadevents() 69: 70: =item unloadevents() 71: 72: =item startupremote() 73: 74: =item setflags() 75: 76: =item maincall() 77: 78: =item load_remote_msg() 79: 80: =item get_menu_name() 81: 82: =item reopenmenu() 83: 84: =item open() 85: 86: Open the menu 87: 88: =item clear() 89: 90: =item switch() 91: 92: Switch a button or create a link 93: Switch acts on the javascript that is executed when a button is clicked. 94: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)". 95: 96: =item secondlevel() 97: 98: =item openmenu() 99: 100: =item inlinemenu() 101: 102: =item rawconfig() 103: 104: =item close() 105: 106: =item footer() 107: 108: =item utilityfunctions() 109: 110: =item serverform() 111: 112: =item constspaceform() 113: 114: =item get_nav_status() 115: 116: =item hidden_button_check() 117: 118: =item roles_selector() 119: 120: =item jump_to_role() 121: 122: =back 123: 124: =cut 125: 126: package Apache::lonmenu; 127: 128: use strict; 129: use Apache::lonnet; 130: use Apache::lonhtmlcommon(); 131: use Apache::loncommon(); 132: use Apache::lonenc(); 133: use Apache::lonlocal; 134: use Apache::loncoursequeueadmin; 135: use LONCAPA qw(:DEFAULT :match); 136: use HTML::Entities(); 137: 138: use vars qw(@desklines %category_names %category_members %category_positions 139: $readdesk @primary_menu @secondary_menu); 140: 141: my @inlineremote; 142: 143: sub prep_menuitem { 144: my ($menuitem) = @_; 145: return '' unless(ref($menuitem) eq 'ARRAY'); 146: my $link; 147: if ($$menuitem[1]) { # graphical Link 148: $link = "<img class=\"LC_noBorder\"" 149: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 150: . " alt=\"" . &mt($$menuitem[2]) . "\" />"; 151: } else { # textual Link 152: $link = &mt($$menuitem[3]); 153: } 154: if($$menuitem[4] eq 'newmsg'){ #special style for New Messages 155: return '<li><a href="'.$$menuitem[0].'"><span class="LC_new_message">'.$link.'</span></a></li>'; 156: } 157: return '<li><a href="'.$$menuitem[0].'">'.$link.'</a></li>'; 158: } 159: 160: # primary_menu() evaluates @primary_menu and returns XHTML for the menu 161: # that contains following links: 162: # About, Message, Roles, Help, Logout 163: # @primary_menu is filled within the BEGIN block of this module with 164: # entries from mydesk.tab 165: sub primary_menu { 166: my $menu; 167: my $custommenu = &Apache::loncommon::needs_gci_custom(); 168: my $numdc = &Apache::loncommon::check_for_gci_dc(); 169: # each element of @primary contains following array: 170: # (link url, icon path, alt text, link text, condition) 171: my $public; 172: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) 173: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) { 174: $public = 1; 175: } 176: foreach my $menuitem (@primary_menu) { 177: # evaluate conditions 178: next if ref($menuitem) ne 'ARRAY'; # 179: next if $$menuitem[4] eq 'nonewmsg' # show links depending on 180: && &Apache::lonmsg::mynewmail(); # whether a new msg 181: next if $$menuitem[4] eq 'newmsg' # arrived or not 182: && !&Apache::lonmsg::mynewmail(); # 183: next if $$menuitem[4] !~ /public/ ##we've a public user, 184: && $public; ##who should not see all 185: ##links 186: next if $$menuitem[4] eq 'onlypublic'# hide links which are 187: && !$public; # only visible to public 188: # users 189: next if $$menuitem[4] eq 'gci' 190: && (!$custommenu || $env{'request.role'} =~ m{^st\./gcitest/}); 191: next if $$menuitem[4] eq 'home' 192: && (($custommenu) || ($env{'user.domain'} eq 'gcitest') || 193: (($env{'user.domain'} eq 'gci') && !$numdc)); 194: next if $$menuitem[4] eq 'gcitest' 195: && (($env{'user.domain'} eq 'gci') || ($env{'request.role'} eq 'cm')); 196: next if $$menuitem[4] eq 'roles' # hide links which are 197: && $custommenu; # not visible when GCI 198: next if $$menuitem[4] eq 'courses' # tabbed interface in use 199: && $custommenu; # 200: next if $$menuitem[4] eq 'roles' ##show links depending on 201: && &Apache::loncommon::show_course(); ##term 'Courses' or 202: next if $$menuitem[4] eq 'courses' ##'Roles' wanted 203: && !&Apache::loncommon::show_course(); ## 204: 205: 206: if ($$menuitem[3] eq 'Help') { # special treatment for helplink 207: if ($public) { 208: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; 209: my $defdom = &Apache::lonnet::default_login_domain(); 210: my $to = &Apache::loncommon::build_recipient_list(undef, 211: 'helpdeskmail', 212: $defdom,$origmail); 213: if ($to ne '') { 214: $menu .= &prep_menuitem($menuitem); 215: } 216: } else { 217: $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>'; 218: } 219: } else { 220: my @items = @{$menuitem}; 221: $items[0] = 'javascript:'.$menuitem->[0].';'; 222: $menu .= &prep_menuitem(\@items); 223: } 224: } 225: 226: return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>"; 227: } 228: 229: 230: sub secondary_menu { 231: my $menu; 232: 233: my $crstype = &Apache::loncommon::course_type(); 234: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'}); 235: my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'} 236: . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}" 237: : '')); 238: my $showlink = &show_return_link(); 239: my %groups = &Apache::lonnet::get_active_groups( 240: $env{'user.domain'}, $env{'user.name'}, 241: $env{'course.' . $env{'request.course.id'} . '.domain'}, 242: $env{'course.' . $env{'request.course.id'} . '.num'}); 243: my $custommenu = &Apache::loncommon::needs_gci_custom(); 244: my $numdc = &Apache::loncommon::check_for_gci_dc(); 245: my $role = $env{'request.role'}; 246: foreach my $menuitem (@secondary_menu) { 247: # evaluate conditions 248: next if ref($menuitem) ne 'ARRAY'; 249: next if $$menuitem[4] eq 'showmenu' 250: && ($custommenu || (!$numdc && $role eq 'cm')); 251: next if $$menuitem[4] ne 'showmenu' 252: && $$menuitem[4] ne 'author' 253: && !$env{'request.course.id'}; 254: next if $$menuitem[4] eq 'showreturn' 255: && !$showlink 256: && !($env{'request.state'} eq 'construct'); 257: next if $$menuitem[4] =~ /^mdc/ 258: && !$canedit; 259: next if $$menuitem[4] eq 'mdcCourse' 260: && $crstype eq 'Community'; 261: next if $$menuitem[4] eq 'mdcCommunity' 262: && $crstype ne 'Community'; 263: next if $$menuitem[4] =~ /^remotenav/ 264: && $env{'environment.remotenavmap'} ne 'on'; 265: next if $$menuitem[4] =~ /noremotenav/ 266: && $env{'environment.remotenavmap'} eq 'on'; 267: next if $$menuitem[4] =~ /^(no|)remotenav$/ 268: && $crstype eq 'Community'; 269: next if $$menuitem[4] =~ /^(no|)remotenavCommunity$/ 270: && $crstype ne 'Community'; 271: next if $$menuitem[4] =~ /showgroups$/ 272: && !$canviewgrps 273: && !%groups; 274: next if $$menuitem[4] eq 'showroles' 275: && ($custommenu || !$numdc || ($numdc && $env{'request.noversionuri'} eq '/adm/roles')); 276: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'} && !$custommenu) { 277: # special treatment for role selector 278: my $roles_selector = &roles_selector( 279: $env{'course.' . $env{'request.course.id'} . '.domain'}, 280: $env{'course.' . $env{'request.course.id'} . '.num'} ); 281: 282: $menu .= $roles_selector ? "<li>$roles_selector</li>" 283: : ''; 284: } elsif ($env{'environment.remotenavmap'} eq 'on') { 285: # open link using javascript when remote navmap is activated 286: my @items = @{$menuitem}; 287: if ($menuitem->[4] eq 'remotenav') { 288: $items[0] = "javascript:gonav('$menuitem->[0]');"; 289: } else { 290: $items[0] = "javascript:go('$menuitem->[0]');"; 291: } 292: $menu .= &prep_menuitem(\@items); 293: } else { 294: $menu .= &prep_menuitem(\@$menuitem); 295: } 296: } 297: if ($menu =~ /\[url\].*\[symb\]/) { 298: my $escurl = &escape( &Apache::lonenc::check_encrypt( 299: $env{'request.noversionuri'})); 300: 301: my $escsymb = &escape( &Apache::lonenc::check_encrypt( 302: $env{'request.symb'})); 303: 304: if ( $env{'request.state'} eq 'construct' 305: and ( $env{'request.noversionuri'} eq '' 306: || !defined($env{'request.noversionuri'}))) 307: { 308: ($escurl = $env{'request.filename'}) =~ 309: s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2}; 310: 311: $escurl = &escape($escurl); 312: } 313: $menu =~ s/\[url\]/$escurl/g; 314: $menu =~ s/\[symb\]/$escsymb/g; 315: } 316: 317: return "<ul id=\"LC_secondary_menu\">$menu</ul>"; 318: } 319: 320: sub gci_secondary_menu { 321: my %courses = ( 322: 'review' => 'gci_9615072b469884921gcil1', 323: 'submit' => 'gci_1H96711d710194bfegcil1', 324: 'tutorial' => 'gci_5422913620b814c90gcil1', 325: ); 326: my %linktext = ( 327: 'review' => 'Review Questions', 328: 'submit' => 'Submit Questions', 329: 'managetest' => 'Manage Tests', 330: 'tutorial' => 'Tutorials', 331: ); 332: my %links = ( 333: 'managetest' => '/adm/menu', 334: ); 335: my $current = 'managetest'; 336: if ($env{'form.destinationurl'} eq '/adm/gci_info') { 337: undef($current); 338: } 339: foreach my $key (keys(%courses)) { 340: $links{$key} = "javascript:switchpage('$key');"; 341: if ($env{'request.course.id'} eq $courses{$key}) { 342: if ($env{'environment.remotenavmap'} eq 'on') { 343: $links{$key} = "javascript:gonav('/adm/navmaps')"; 344: } else { 345: $links{$key} = '/adm/navmaps'; 346: } 347: $current = $key; 348: $links{'managetest'} = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu'; 349: } 350: } 351: my @menutabs = ('review','submit','managetest','tutorial'); 352: my $tabs; 353: foreach my $item (@menutabs) { 354: if ($item eq $current) { 355: $tabs .= '<li id="current"><a href="'.$links{$item}.'">'. 356: $linktext{$item}.'</a></li>'; 357: } else { 358: $tabs .= '<li><a href="'.$links{$item}.'">'. 359: $linktext{$item}.'</a></li>'; 360: } 361: } 362: return '<div id="gciheader">'. 363: '<ul>'.$tabs.'</ul></div><br />'; 364: } 365: 366: # 367: # This routine returns a translated hash for the menu items in the top inline menu row 368: # Probably should be in mydesk.tab 369: 370: #SD this sub is deprecated - don't use it 371: sub initlittle { 372: return &Apache::lonlocal::texthash('ret' => 'Return to Last Location', 373: 'nav' => 'Course Contents', 374: 'main' => 'Main Menu', 375: 'roles' => (&Apache::loncommon::show_course()? 376: 'Courses':'Roles'), 377: 'other' => 'Other Roles', 378: 'docs' => 'Edit Course', 379: 'exit' => 'Logout', 380: 'login' => 'Log In', 381: 'launch' => 'Launch Remote Control', 382: 'groups' => 'Groups', 383: 'gdoc' => 'Community Documents', 384: ); 385: } 386: 387: #SD this sub is deprecated - don't use it 388: #SD functionality is covered by new loncommon::bodytag and primary_menu(), secondary_menu() 389: sub menubuttons { 390: my $forcereg=shift; 391: my $titletable=shift; 392: # 393: # Early-out for pages that should not have a menu, triggered by query string "inhibitmenu=yes" 394: # 395: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, 396: ['inhibitmenu']); 397: if (($env{'form.inhibitmenu'} eq 'yes') || 398: ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; } 399: 400: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } 401: 402: my %lt=&initlittle(); 403: my $navmaps=''; 404: my $reloadlink=''; 405: my $docs=''; 406: my $groups=''; 407: my $roles='<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>'; 408: my $role_selector; 409: my $showgroups=0; 410: my ($cnum,$cdom); 411: # 412: # if the URL is hidden, symbs and the non-versioned version of the URL would be encrypted 413: # 414: my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'})); 415: my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'})); 416: 417: my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif"); 418: $logo = '<a href="/adm/about.html"><img src="'. 419: $logo.'" alt="LON-CAPA Logo" class="LC_noBorder" /></a>'; 420: 421: if ($env{'request.state'} eq 'construct') { 422: # 423: # We are in construction space 424: # 425: if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) { 426: my $returnurl = $env{'request.filename'}; 427: $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:; 428: $escurl = &escape($returnurl); 429: } 430: } 431: if ($env{'request.course.id'}) { 432: # 433: # We are in a course 434: # 435: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 436: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; 437: my %coursegroups; 438: my $viewgrps_permission = 439: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); 440: if (!$viewgrps_permission) { 441: %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum); 442: } 443: if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) { 444: $showgroups = 1; 445: } 446: $role_selector = &roles_selector($cdom,$cnum); 447: if ($role_selector) { 448: $roles = '<span class="LC_nobreak">'.$role_selector.' <a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></span>'; 449: } 450: } 451: 452: if ($env{'environment.remote'} eq 'off') { 453: # Remote Control is switched off 454: # figure out colors 455: my %lt=&initlittle(); 456: 457: my $domain=&Apache::loncommon::determinedomain(); 458: my $function=&Apache::loncommon::get_users_function(); 459: my $link=&Apache::loncommon::designparm($function.'.link',$domain); 460: my $alink=&Apache::loncommon::designparm($function.'.alink',$domain); 461: my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain); 462: my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain); 463: 464: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { 465: return (<<ENDINLINEMENU); 466: <ol class="LC_primary_menu LC_right"> 467: <li>$logo</li> 468: <li><a href="/adm/roles" target="_top">$lt{'login'}</a></li> 469: </ol> 470: <hr /> 471: ENDINLINEMENU 472: } 473: $roles = '<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>'; 474: # Do we have a NAV link? 475: if ($env{'request.course.id'}) { 476: my $link='/adm/navmaps?postdata='.$escurl.'&postsymb='. 477: $escsymb; 478: if ($env{'environment.remotenavmap'} eq 'on') { 479: $link="javascript:gonav('".$link."')"; 480: } 481: $navmaps=(<<ENDNAV); 482: <li><a href="$link" target="_top">$lt{'nav'}</a></li> 483: ENDNAV 484: my $is_community = 485: (&Apache::loncommon::course_type() eq 'Community'); 486: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { 487: my $text = ($is_community) ? $lt{'gdoc'} : $lt{'docs'}; 488: $docs=(<<ENDDOCS); 489: <li><a href="/adm/coursedocs" target="_top">$text</a></li> 490: ENDDOCS 491: } 492: if ($showgroups) { 493: $groups =(<<ENDGROUPS); 494: <li><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></li> 495: ENDGROUPS 496: } 497: if (&show_return_link()) { 498: my $escreload=&escape('return:'); 499: $reloadlink=(<<ENDRELOAD); 500: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li> 501: ENDRELOAD 502: } 503: if ($role_selector) { 504: #$roles = '<td>'.$role_selector.'</td><td><a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></td>'; 505: $role_selector = '<li>'.$role_selector.'</li>'; 506: } 507: } 508: if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) { 509: my $escreload=&escape('return:'); 510: $reloadlink=(<<ENDCRELOAD); 511: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li> 512: ENDCRELOAD 513: } 514: my $reg = $forcereg ? &innerregister($forcereg,$titletable) : ''; 515: my $form = &serverform(); 516: my $utility = &utilityfunctions(); 517: 518: #Prepare the message link that indicates the arrival of new mail 519: my $messagelink = &Apache::lonmsg::mynewmail() ? "Message (new)" : "Message"; 520: $messagelink = '<a href="javascript:go(\'/adm/communicate\');">' 521: . mt($messagelink) .'</a>'; 522: 523: my $helplink = &Apache::loncommon::top_nav_help('Help'); 524: return (<<ENDINLINEMENU); 525: <script type="text/javascript"> 526: // <![CDATA[ 527: // BEGIN LON-CAPA Internal 528: $utility 529: // ]]> 530: </script> 531: <ol class="LC_primary_menu LC_right"> 532: <li>$logo</li> 533: <li>$messagelink</li> 534: <li>$roles</li> 535: <li>$helplink</li> 536: <li><a href="/adm/logout" target="_top">$lt{'exit'}</a></li> 537: </ol> 538: <ul id="LC_secondary_menu"> 539: <li><a href="/adm/menu" target="_top">$lt{'main'}</a></li> 540: $reloadlink 541: $navmaps 542: $docs 543: $groups 544: $role_selector 545: </ul> 546: $form 547: <script type="text/javascript"> 548: // END LON-CAPA Internal 549: </script> 550: $reg 551: ENDINLINEMENU 552: } else { 553: return ''; 554: } 555: } 556: 557: sub show_return_link { 558: return unless ($env{'request.course.id'}); 559: if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)}) 560: || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) { 561: return if ($env{'form.register'}); 562: } 563: return (($env{'request.noversionuri'}=~m{^/(res|public)/} && 564: $env{'request.symb'} eq '') 565: || 566: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl}) 567: || 568: (($env{'request.noversionuri'}=~/^\/adm\//) && 569: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) && 570: ($env{'request.noversionuri'}!~ 571: m[^/adm/.*/(smppg|bulletinboard)($|\?)]) 572: )); 573: } 574: 575: 576: sub registerurl { 577: my ($forcereg) = @_; 578: my $result = ''; 579: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } 580: my $force_title=''; 581: if ($env{'request.state'} eq 'construct') { 582: $force_title=&Apache::lonxml::display_title(); 583: } 584: if (($env{'environment.remote'} eq 'off') || 585: ((($env{'request.publicaccess'}) || 586: (!&Apache::lonnet::is_on_map( 587: &unescape($env{'request.noversionuri'})))) && 588: (!$forcereg))) { 589: return 590: $result 591: .'<script type="text/javascript">'."\n" 592: .'// <![CDATA['."\n" 593: .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n" 594: .'// ]]>'."\n" 595: .'</script>' 596: .$force_title; 597: } 598: # Graphical display after login only 599: if ($env{'request.registered'} && !$forcereg) { return ''; } 600: $result.=&innerregister($forcereg); 601: return $result.$force_title; 602: } 603: 604: sub innerregister { 605: my ($forcereg,$titletable,$bread_crumbs) = @_; 606: my $result = ''; 607: my ($uname,$thisdisfn); 608: my $const_space = ($env{'request.state'} eq 'construct'); 609: my $is_const_dir = 0; 610: 611: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } 612: 613: $env{'request.registered'} = 1; 614: 615: my $noremote = ($env{'environment.remote'} eq 'off'); 616: 617: undef(@inlineremote); 618: 619: my $reopen=&Apache::lonmenu::reopenmenu(); 620: 621: my $newmail=''; 622: 623: if (&Apache::lonmsg::newmail() && !$noremote) { 624: # We have new mail and remote is up 625: $newmail= 'swmenu.setstatus("you have","messages");'; 626: } 627: 628: my ($breadcrumb,$separator); 629: if ($noremote 630: && ($env{'request.symb'}) 631: && ($env{'request.course.id'})) { 632: 633: my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread()); 634: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'}; 635: 636: my $maptitle = &Apache::lonnet::gettitle($mapurl); 637: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread()); 638: my $contentstext; 639: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Community') { 640: $contentstext = &mt('Community Contents'); 641: } else { 642: $contentstext = &mt('Course Contents'); 643: } 644: my @crumbs; 645: unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps') 646: && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) { 647: my $link = "javascript:gopost('/adm/navmaps','')"; 648: if ($env{'environment.remotenavmap'} eq 'on') { 649: $link = "javascript:gonav('/adm/navmaps','')" 650: } 651: @crumbs = ({text => Apache::loncommon::course_type() 652: . ' Contents', 653: href => $link}); 654: } 655: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 656: push(@crumbs, {text => '...', 657: no_mt => 1}); 658: } 659: 660: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 661: && $maptitle ne 'default.sequence' 662: && $maptitle ne $coursetitle); 663: 664: push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 665: 666: &Apache::lonhtmlcommon::clear_breadcrumbs(); 667: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs); 668: #$breadcrumb .= &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0); 669: unless (($env{'request.state'} eq 'edit') || ($newmail) || 670: ($env{'request.state'} eq 'construct') || 671: ($env{'form.register'})) { 672: $separator = &Apache::loncommon::head_subbox(); 673: } 674: # 675: } 676: if ($env{'request.state'} eq 'construct') { 677: $newmail = $titletable; 678: } 679: my $timesync = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' ); 680: my $tablestart = ( $noremote ? '<table id="LC_menubuttons">' : ''); 681: my $tableend = ( $noremote ? '</table>' : ''); 682: # ============================================================================= 683: # ============================ This is for URLs that actually can be registered 684: if (($env{'request.noversionuri'}!~m{^/(res/)*adm/}) || ($forcereg)) { 685: # -- This applies to homework problems for users with grading privileges 686: my $crs='/'.$env{'request.course.id'}; 687: if ($env{'request.course.sec'}) { 688: $crs.='_'.$env{'request.course.sec'}; 689: } 690: $crs=~s/\_/\//g; 691: 692: my $hwkadd=''; 693: if ($env{'request.symb'} ne '' && 694: $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) { 695: if (&Apache::lonnet::allowed('mgr',$crs)) { 696: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]', 697: "gocmd('/adm/grades','gradingmenu')", 698: 'Modify user grades for this assessment resource'); 699: } elsif (&Apache::lonnet::allowed('vgr',$crs)) { 700: $hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]', 701: "gocmd('/adm/grades','submission')", 702: 'View user submissions for this assessment resource'); 703: } 704: } 705: if ($env{'request.symb'} ne '' && 706: &Apache::lonnet::allowed('opa',$crs)) { 707: $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]', 708: "gocmd('/adm/parmset','set')", 709: 'Modify parameter settings for this resource'); 710: } 711: # -- End Homework 712: ### 713: ### Determine whether or not to display the 'cstr' button for this 714: ### resource 715: ### 716: my $editbutton = ''; 717: my $noeditbutton = 1; 718: my ($cnum,$cdom); 719: if ($env{'request.course.id'}) { 720: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; 721: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; 722: } 723: if ($env{'user.author'}) { 724: if ($env{'request.role'}=~/^(aa|ca|au)/) { 725: # 726: # We have the role of an author 727: # 728: # Set defaults for authors 729: my ($top,$bottom) = ('con-','struct'); 730: my $action = "go('/priv/".$env{'user.name'}."');"; 731: my $cadom = $env{'request.role.domain'}; 732: my $caname = $env{'user.name'}; 733: my $desc = "Enter my construction space"; 734: # Set defaults for co-authors 735: if ($env{'request.role'} =~ /^ca/) { 736: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/); 737: ($top,$bottom) = ('co con-','struct'); 738: $action = "go('/priv/".$caname."');"; 739: $desc = "Enter construction space as co-author"; 740: } elsif ($env{'request.role'} =~ /^aa/) { 741: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/); 742: ($top,$bottom) = ('co con-','struct'); 743: $action = "go('/priv/".$caname."');"; 744: $desc = "Enter construction space as assistant co-author"; 745: } 746: # Check that we are on the correct machine 747: my $home = &Apache::lonnet::homeserver($caname,$cadom); 748: my $allowed=0; 749: my @ids=&Apache::lonnet::current_machine_ids(); 750: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } 751: if (!$allowed) { 752: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc); 753: $noeditbutton = 0; 754: } 755: } 756: # 757: # We are an author for some stuff, but currently do not have the role of author. 758: # Figure out if we have authoring privileges for the resource we are looking at. 759: # This should maybe become a privilege check in lonnet 760: # 761: ## 762: ## Determine if user can edit url. 763: ## 764: my $cfile=''; 765: my $cfuname=''; 766: my $cfudom=''; 767: my $uploaded; 768: if ($env{'request.filename'}) { 769: my $file=&Apache::lonnet::declutter($env{'request.filename'}); 770: if (defined($cnum) && defined($cdom)) { 771: $uploaded = &is_course_upload($file,$cnum,$cdom); 772: } 773: if (!$uploaded) { 774: $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/; 775: # Check that the user has permission to edit this resource 776: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1); 777: if (defined($cfudom)) { 778: my $home=&Apache::lonnet::homeserver($cfuname,$cfudom); 779: my $allowed=0; 780: my @ids=&Apache::lonnet::current_machine_ids(); 781: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } 782: if ($allowed) { 783: $cfile=$file; 784: } 785: } 786: } 787: } 788: # Finally, turn the button on or off 789: if ($cfile && !$const_space) { 790: my $nocrsedit; 791: # Suppress display where CC has switched to student role. 792: if ($env{'request.course.id'}) { 793: unless(&Apache::lonnet::allowed('mdc', 794: $env{'request.course.id'})) { 795: $nocrsedit = 1; 796: } 797: } 798: if ($nocrsedit) { 799: $editbutton=&clear(6,1); 800: } else { 801: $editbutton=&switch 802: ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]', 803: "go('".$cfile."');","Edit this resource"); 804: $noeditbutton = 0; 805: } 806: } elsif ($editbutton eq '') { 807: $editbutton=&clear(6,1); 808: } 809: } 810: if (($noeditbutton) && ($env{'request.filename'})) { 811: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { 812: my $file=&Apache::lonnet::declutter($env{'request.filename'}); 813: if (defined($cnum) && defined($cdom)) { 814: if (&is_course_upload($file,$cnum,$cdom)) { 815: my $cfile = &edit_course_upload($file,$cnum,$cdom); 816: if ($cfile) { 817: $editbutton=&switch 818: ('','',6,1,'pcstr.gif','edit[_1]', 819: 'resource[_2]',"go('".$cfile."');", 820: 'Edit this resource'); 821: } 822: } 823: } 824: } 825: } 826: ### 827: ### 828: # Prepare the rest of the buttons 829: my $menuitems; 830: if ($const_space) { 831: # 832: # We are in construction space 833: # 834: my ($uname,$thisdisfn) = 835: ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|); 836: my $currdir = '/priv/'.$uname.'/'.$thisdisfn; 837: if ($currdir =~ m-/$-) { 838: $is_const_dir = 1; 839: } else { 840: $currdir =~ s|[^/]+$||; 841: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn); 842: my $esc_currdir = &Apache::loncommon::escape_single($currdir); 843: # 844: # Probably should be in mydesk.tab 845: # 846: $menuitems=(<<ENDMENUITEMS); 847: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory 848: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version 849: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource 850: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource 851: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document 852: ENDMENUITEMS 853: } 854: if ($noremote) { 855: if (ref($bread_crumbs) eq 'ARRAY') { 856: &Apache::lonhtmlcommon::clear_breadcrumbs(); 857: foreach my $crumb (@{$bread_crumbs}){ 858: &Apache::lonhtmlcommon::add_breadcrumb($crumb); 859: } 860: } 861: } 862: } elsif ( defined($env{'request.course.id'}) && 863: $env{'request.symb'} ne '' ) { 864: # 865: # We are in a course and looking at a registred URL 866: # Should probably be in mydesk.tab 867: # 868: $menuitems=(<<ENDMENUITEMS); 869: c&3&1 870: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1 871: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3 872: c&6&3 873: c&8&1 874: c&8&2 875: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document 876: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1 877: ENDMENUITEMS 878: 879: my $currentURL = &Apache::loncommon::get_symb(); 880: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL); 881: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc); 882: $menuitems.="s&9&3&"; 883: if(length($annotation) > 0){ 884: $menuitems.="anot2.gif"; 885: }else{ 886: $menuitems.="anot.gif"; 887: } 888: $menuitems.="&anno-[_1]&tations[_1]&annotate()&"; 889: $menuitems.="Make notes and annotations about this resource&&1\n"; 890: 891: unless ($noremote) { 892: my $showreqcrs = &check_for_rcrs(); 893: if ($showreqcrs) { 894: $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]". 895: "&go('/adm/requestcourse')&Course requests\n"; 896: } 897: } 898: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|portfolio)(\?|$)/) { 899: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) { 900: $menuitems.=(<<ENDREALRES); 901: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata 902: ENDREALRES 903: } 904: $menuitems.=(<<ENDREALRES); 905: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource 906: s&8&2&fdbk.gif&feedback[_1]&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource 907: ENDREALRES 908: } 909: } 910: if ($env{'request.uri'} =~ /^\/res/) { 911: $menuitems .= (<<ENDMENUITEMS); 912: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document 913: ENDMENUITEMS 914: } 915: my $buttons=''; 916: foreach (split(/\n/,$menuitems)) { 917: my ($command,@rest)=split(/\&/,$_); 918: my $idx=10*$rest[0]+$rest[1]; 919: if (&hidden_button_check() eq 'yes') { 920: if ($idx == 21 ||$idx == 23) { 921: $buttons.=&switch('','',@rest); 922: } else { 923: $buttons.=&clear(@rest); 924: } 925: } else { 926: if ($command eq 's') { 927: $buttons.=&switch('','',@rest); 928: } else { 929: $buttons.=&clear(@rest); 930: } 931: } 932: } 933: 934: if ($noremote) { 935: my $addremote=0; 936: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} } 937: my $inlinebuttons=''; 938: 939: if ($addremote) { 940: 941: Apache::lonhtmlcommon::clear_breadcrumb_tools(); 942: 943: Apache::lonhtmlcommon::add_breadcrumb_tool( 944: 'navigation', @inlineremote[21,23]); 945: if(hidden_button_check() ne 'yes') { 946: Apache::lonhtmlcommon::add_breadcrumb_tool( 947: 'tools', @inlineremote[93,91,81,82,83]); 948: 949: #publish button in construction space 950: if ($env{'request.state'} eq 'construct'){ 951: Apache::lonhtmlcommon::add_breadcrumb_tool( 952: 'advtools', @inlineremote[63]); 953: }else{ 954: Apache::lonhtmlcommon::add_breadcrumb_tool( 955: 'tools', @inlineremote[63]); 956: } 957: 958: unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) { 959: Apache::lonhtmlcommon::add_breadcrumb_tool( 960: 'advtools', @inlineremote[61,71,72,73,92]); 961: } 962: } 963: 964: # # Registered, textual output 965: # if ( $env{'environment.icons'} eq 'iconsonly' ) { 966: # $inlinebuttons = (<<ENDARROWSINLINE); 967: #<tr><td> 968: #$inlineremote[21] $inlineremote[23] 969: #ENDARROWSINLINE 970: # if ( &hidden_button_check() ne 'yes' ) { 971: # $inlinebuttons .= (<<ENDINLINEICONS); 972: #$inlineremote[61] $inlineremote[63] 973: #$inlineremote[71] $inlineremote[72] $inlineremote[73] 974: #$inlineremote[81] $inlineremote[82] $inlineremote[83] 975: #$inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr> 976: #ENDINLINEICONS 977: # } 978: # } else { # not iconsonly 979: # if ( $inlineremote[21] ne '' || $inlineremote[23] ne '' ) { 980: # $inlinebuttons = (<<ENDFIRSTLINE); 981: #<tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr> 982: #ENDFIRSTLINE 983: # } 984: # if ( &hidden_button_check() ne 'yes' ) { 985: # foreach my $row ( 6 .. 9 ) { 986: # if ( $inlineremote[ ${row} . '1' ] ne '' 987: # || $inlineremote[ $row . '2' ] ne '' 988: # || $inlineremote[ $row . '3' ] ne '' ) 989: # { 990: # $inlinebuttons .= <<"ENDLINE"; 991: #<tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr> 992: #ENDLINE 993: # } 994: # } 995: # } 996: # } 997: } 998: #SD see below 999: $breadcrumb = &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0); 1000: $result =(<<ENDREGTEXT); 1001: <script type="text/javascript"> 1002: // BEGIN LON-CAPA Internal 1003: </script> 1004: $timesync 1005: $breadcrumb 1006: <!-- $tablestart --> 1007: <!-- $inlinebuttons --> 1008: <!-- $tableend --> 1009: $newmail 1010: <!-- $separator --> 1011: <script type="text/javascript"> 1012: // END LON-CAPA Internal 1013: </script> 1014: 1015: ENDREGTEXT 1016: # Registered, graphical output 1017: } else { 1018: my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0])); 1019: $requri=&Apache::lonenc::check_encrypt(&unescape($requri)); 1020: my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'}); 1021: my $navstatus=&get_nav_status(); 1022: my $clearcstr; 1023: 1024: if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; } 1025: $result = (<<ENDREGTHIS); 1026: 1027: <script type="text/javascript"> 1028: // <![CDATA[ 1029: // BEGIN LON-CAPA Internal 1030: var swmenu=null; 1031: 1032: function LONCAPAreg() { 1033: swmenu=$reopen; 1034: swmenu.clearTimeout(swmenu.menucltim); 1035: $timesync 1036: $newmail 1037: $buttons 1038: swmenu.currentURL="$requri"; 1039: swmenu.reloadURL=swmenu.currentURL+window.location.search; 1040: swmenu.currentSymb="$cursymb"; 1041: swmenu.reloadSymb="$cursymb"; 1042: swmenu.currentStale=0; 1043: $navstatus 1044: $hwkadd 1045: $editbutton 1046: } 1047: 1048: function LONCAPAstale() { 1049: swmenu=$reopen 1050: swmenu.currentStale=1; 1051: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 1052: swmenu.switchbutton 1053: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence'); 1054: } 1055: swmenu.clearbut(7,2); 1056: swmenu.clearbut(7,3); 1057: swmenu.menucltim=swmenu.setTimeout( 1058: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+ 1059: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr', 1060: 2000); 1061: } 1062: 1063: // END LON-CAPA Internal 1064: // ]]> 1065: </script> 1066: ENDREGTHIS 1067: } 1068: # ============================================================================= 1069: } else { 1070: # ========================================== This can or will not be registered 1071: if ($noremote) { 1072: # Not registered 1073: $result= (<<ENDDONOTREGTEXT); 1074: ENDDONOTREGTEXT 1075: } else { 1076: # Not registered, graphical 1077: $result = (<<ENDDONOTREGTHIS); 1078: 1079: <script type="text/javascript"> 1080: // <![CDATA[ 1081: // BEGIN LON-CAPA Internal 1082: var swmenu=null; 1083: 1084: function LONCAPAreg() { 1085: swmenu=$reopen 1086: $timesync 1087: swmenu.currentStale=1; 1088: swmenu.clearbut(2,1); 1089: swmenu.clearbut(2,3); 1090: swmenu.clearbut(8,1); 1091: swmenu.clearbut(8,2); 1092: swmenu.clearbut(8,3); 1093: if (swmenu.currentURL) { 1094: swmenu.switchbutton 1095: (3,1,'reload.gif','return','location','go(currentURL)'); 1096: } else { 1097: swmenu.clearbut(3,1); 1098: } 1099: } 1100: 1101: function LONCAPAstale() { 1102: } 1103: 1104: // END LON-CAPA Internal 1105: // ]]> 1106: </script> 1107: ENDDONOTREGTHIS 1108: } 1109: # ============================================================================= 1110: } 1111: return $result; 1112: } 1113: 1114: sub is_course_upload { 1115: my ($file,$cnum,$cdom) = @_; 1116: my $uploadpath = &LONCAPA::propath($cdom,$cnum); 1117: $uploadpath =~ s{^\/}{}; 1118: if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) || 1119: ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) { 1120: return 1; 1121: } 1122: return; 1123: } 1124: 1125: sub edit_course_upload { 1126: my ($file,$cnum,$cdom) = @_; 1127: my $cfile; 1128: if ($file =~/\.(htm|html|css|js|txt)$/) { 1129: my $ext = $1; 1130: my $url = &Apache::lonnet::hreflocation('',$file); 1131: my $home = &Apache::lonnet::homeserver($cnum,$cdom); 1132: my @ids=&Apache::lonnet::current_machine_ids(); 1133: my $dest; 1134: if ($home && grep(/^\Q$home\E$/,@ids)) { 1135: $dest = $url.'?forceedit=1'; 1136: } else { 1137: unless (&Apache::lonnet::get_locks()) { 1138: $dest = '/adm/switchserver?otherserver='. 1139: $home.'&role='.$env{'request.role'}. 1140: '&url='.$url.'&forceedit=1'; 1141: } 1142: } 1143: if ($dest) { 1144: $cfile = &HTML::Entities::encode($dest,'"<>&'); 1145: } 1146: } 1147: return $cfile; 1148: } 1149: 1150: sub loadevents() { 1151: if ($env{'request.state'} eq 'construct' || 1152: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } 1153: return 'LONCAPAreg();'; 1154: } 1155: 1156: sub unloadevents() { 1157: if ($env{'request.state'} eq 'construct' || 1158: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } 1159: return 'LONCAPAstale();'; 1160: } 1161: 1162: 1163: sub startupremote { 1164: my ($lowerurl)=@_; 1165: if ($env{'environment.remote'} eq 'off') { 1166: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />'); 1167: } 1168: # 1169: # The Remote actually gets launched! 1170: # 1171: my $configmenu=&rawconfig(); 1172: my $esclowerurl=&escape($lowerurl); 1173: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited'); 1174: return(<<ENDREMOTESTARTUP); 1175: <script type="text/javascript"> 1176: // <![CDATA[ 1177: var timestart; 1178: function wheelswitch() { 1179: if (typeof(document.wheel) != 'undefined') { 1180: if (typeof(document.wheel.spin) != 'undefined') { 1181: var date=new Date(); 1182: var waited=Math.round(30-((date.getTime()-timestart)/1000)); 1183: document.wheel.spin.value=$message; 1184: } 1185: } 1186: if (window.status=='|') { 1187: window.status='/'; 1188: } else { 1189: if (window.status=='/') { 1190: window.status='-'; 1191: } else { 1192: if (window.status=='-') { 1193: window.status='\\\\'; 1194: } else { 1195: if (window.status=='\\\\') { window.status='|'; } 1196: } 1197: } 1198: } 1199: } 1200: 1201: // ---------------------------------------------------------- The wait function 1202: var canceltim; 1203: function wait() { 1204: if ((menuloaded==1) || (tim==1)) { 1205: window.status='Done.'; 1206: if (tim==0) { 1207: clearTimeout(canceltim); 1208: $configmenu 1209: window.location='$lowerurl'; 1210: } else { 1211: window.location='/adm/remote?action=collapse&url=$esclowerurl'; 1212: } 1213: } else { 1214: wheelswitch(); 1215: setTimeout('wait();',200); 1216: } 1217: } 1218: 1219: function main() { 1220: canceltim=setTimeout('tim=1;',30000); 1221: window.status='-'; 1222: var date=new Date(); 1223: timestart=date.getTime(); 1224: wait(); 1225: } 1226: 1227: // ]]> 1228: </script> 1229: ENDREMOTESTARTUP 1230: } 1231: 1232: sub setflags() { 1233: return(<<ENDSETFLAGS); 1234: <script type="text/javascript"> 1235: // <![CDATA[ 1236: menuloaded=0; 1237: tim=0; 1238: // ]]> 1239: </script> 1240: ENDSETFLAGS 1241: } 1242: 1243: sub maincall() { 1244: if ($env{'environment.remote'} eq 'off') { return ''; } 1245: return(<<ENDMAINCALL); 1246: <script type="text/javascript"> 1247: // <![CDATA[ 1248: main(); 1249: // ]]> 1250: </script> 1251: ENDMAINCALL 1252: } 1253: 1254: sub load_remote_msg { 1255: my ($lowerurl)=@_; 1256: 1257: if ($env{'environment.remote'} eq 'off') { return ''; } 1258: 1259: my $esclowerurl=&escape($lowerurl); 1260: my $link=&mt('[_1]Continue[_2] on in Inline Menu mode' 1261: ,'<a href="/adm/remote?action=collapse&url='.$esclowerurl.'">' 1262: ,'</a>'); 1263: return(<<ENDREMOTEFORM); 1264: <p> 1265: <form name="wheel"> 1266: <input name="spin" type="text" size="60" /> 1267: </form> 1268: </p> 1269: <p>$link</p> 1270: ENDREMOTEFORM 1271: } 1272: 1273: sub get_menu_name { 1274: my $hostid = $Apache::lonnet::perlvar{'lonHostID'}; 1275: $hostid =~ s/\W//g; 1276: return 'LCmenu'.$hostid; 1277: } 1278: 1279: 1280: sub reopenmenu { 1281: if ($env{'environment.remote'} eq 'off') { return ''; } 1282: my $menuname = &get_menu_name(); 1283: my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); 1284: return('window.open('.$nothing.',"'.$menuname.'","",false);'); 1285: } 1286: 1287: 1288: sub open { 1289: my $returnval=''; 1290: if ($env{'environment.remote'} eq 'off') { 1291: return 1292: '<script type="text/javascript">'."\n" 1293: .'// <![CDATA['."\n" 1294: .'self.name="loncapaclient";'."\n" 1295: .'// ]]>'."\n" 1296: .'</script>'; 1297: } 1298: my $menuname = &get_menu_name(); 1299: 1300: # unless (shift eq 'unix') { 1301: # resizing does not work on linux because of virtual desktop sizes 1302: # $returnval.=(<<ENDRESIZE); 1303: #if (window.screen) { 1304: # self.resizeTo(screen.availWidth-215,screen.availHeight-55); 1305: # self.moveTo(190,15); 1306: #} 1307: #ENDRESIZE 1308: # } 1309: $returnval=(<<ENDOPEN); 1310: // <![CDATA[ 1311: window.status='Opening LON-CAPA Remote Control'; 1312: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname", 1313: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5"); 1314: self.name='loncapaclient'; 1315: // ]]> 1316: ENDOPEN 1317: return '<script type="text/javascript">'.$returnval.'</script>'; 1318: } 1319: 1320: 1321: # ================================================================== Raw Config 1322: 1323: sub clear { 1324: my ($row,$col)=@_; 1325: unless ($env{'environment.remote'} eq 'off') { 1326: if (($row<1) || ($row>13)) { return ''; } 1327: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col);); 1328: } else { 1329: $inlineremote[10*$row+$col]=''; 1330: return ''; 1331: } 1332: } 1333: 1334: # ============================================ Switch a button or create a link 1335: # Switch acts on the javascript that is executed when a button is clicked. 1336: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)". 1337: 1338: sub switch { 1339: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_; 1340: $act=~s/\$uname/$uname/g; 1341: $act=~s/\$udom/$udom/g; 1342: $top=&mt($top); 1343: $bot=&mt($bot); 1344: $desc=&mt($desc); 1345: if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) { 1346: $img=&mt($img); 1347: } 1348: my $idx=10*$row+$col; 1349: $category_members{$cat}.=':'.$idx; 1350: 1351: unless ($env{'environment.remote'} eq 'off') { 1352: if (($row<1) || ($row>13)) { return ''; } 1353: # Remote 1354: return "\n". 1355: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc");); 1356: } else { 1357: # Inline Remote 1358: if ($env{'environment.icons'} ne 'classic') { 1359: $img=~s/\.gif$/\.png/; 1360: } 1361: if ($nobreak==2) { return ''; } 1362: my $text=$top.' '.$bot; 1363: $text=~s/\s*\-\s*//gs; 1364: 1365: my $pic= 1366: '<img alt="'.$text.'" src="'. 1367: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img). 1368: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />'; 1369: if ($env{'browser.interface'} eq 'faketextual') { 1370: # Main Menu 1371: if ($nobreak==3) { 1372: $inlineremote[$idx]="\n". 1373: '<td class="LC_menubuttons_text" align="right">'.$text. 1374: '</td><td align="left">'. 1375: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>'; 1376: } elsif ($nobreak) { 1377: $inlineremote[$idx]="\n<tr>". 1378: '<td align="left">'. 1379: '<a href="javascript:'.$act.';">'.$pic.'</a></td> 1380: <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>'; 1381: } else { 1382: $inlineremote[$idx]="\n<tr>". 1383: '<td align="left">'. 1384: '<a href="javascript:'.$act.';">'.$pic. 1385: '</a></td><td class="LC_menubuttons_text" colspan="3">'. 1386: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>'; 1387: } 1388: } else { 1389: # Inline Menu 1390: if ($env{'environment.icons'} eq 'iconsonly') { 1391: $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>'; 1392: } else { 1393: $inlineremote[$idx]= 1394: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic. 1395: '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>'; 1396: } 1397: } 1398: } 1399: return ''; 1400: } 1401: 1402: sub secondlevel { 1403: my $output=''; 1404: my 1405: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_; 1406: if ($prt eq 'any') { 1407: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); 1408: } elsif ($prt=~/^r(\w+)/) { 1409: if ($rol eq $1) { 1410: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); 1411: } 1412: } 1413: return $output; 1414: } 1415: 1416: sub openmenu { 1417: my $menuname = &get_menu_name(); 1418: if ($env{'environment.remote'} eq 'off') { return ''; } 1419: my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); 1420: return "window.open(".$nothing.",'".$menuname."');"; 1421: } 1422: 1423: sub inlinemenu { 1424: my ($context) = @_; 1425: undef(@inlineremote); 1426: undef(%category_members); 1427: my $output; 1428: if ($context eq 'gcicustom') { 1429: my (%can_request,%request_domains,$canreq,$createtext); 1430: my $role = 'st'; 1431: my $custommenu = &Apache::loncommon::needs_gci_custom(); 1432: if ($custommenu) { 1433: $role = 'cc'; 1434: } 1435: my %courses = &Apache::loncommon::existing_gcitest_courses($role); 1436: my $numcourses = keys(%courses); 1437: my ($switcher_js,$switcher); 1438: my $formname = 'testpicker'; 1439: if ($numcourses > 0) { 1440: $switcher = &Apache::loncommon::gcitest_switcher($role,$formname,%courses); 1441: my $current; 1442: my $cid = $env{'request.course.id'}; 1443: if ($cid) { 1444: $current = $role.'./'.$env{'course.'.$cid.'.domain'}. 1445: '/'.$env{'course.'.$cid.'.num'}; 1446: } 1447: $switcher_js = &Apache::loncommon::gcitest_switcher_js($current,$numcourses,$formname); 1448: if ($switcher_js) { 1449: $switcher_js= <<"ENDSCRIPT"; 1450: <script type="text/javascript"> 1451: // <![CDATA[ 1452: 1453: $switcher_js 1454: 1455: // ]]> 1456: </script> 1457: 1458: ENDSCRIPT 1459: } 1460: $switcher = $switcher_js.$switcher; 1461: } 1462: if ($env{'user.domain'} eq 'gci') { 1463: $canreq = 1464: &Apache::lonnet::check_can_request('gcitest',\%can_request,\%request_domains); 1465: $createtext = &mt('Create Concept Test'); 1466: if ($numcourses) { 1467: $createtext = &mt('Create New Test'); 1468: } 1469: } 1470: if ($env{'request.course.id'}) { 1471: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { 1472: my $navlink; 1473: if ($env{'environment.remotenavmap'} eq 'on') { 1474: $navlink = "javascript:gonav('/adm/navmaps')"; 1475: } else { 1476: $navlink = '/adm/navmaps'; 1477: } 1478: $output .= 1479: '<br /><br clear="all" /><div class="LC_Box LC_GCI_Menu">'. 1480: '<h3 class="LC_hcell">'.&mt('Management').'</h3>'. 1481: '<div class="LC_GCI_Menu_left">'. 1482: '<dl class="LC_GCI_Menu">'. 1483: '<dt><a href="'.$navlink.'">'.&mt('Concept Test Contents').'</a></dt>'. 1484: '<dd style="background-image:url(\'/res/adm/pages/nav.png\');"><a class="LC_menubuttons_link" href="'.$navlink.'">'.&mt('Display the table of contents for your Concept Test.').'</a></dd>'. 1485: '<dt><a href="/adm/coursedocs">'.&mt('Assemble Concept Test').'</a></dt>'. 1486: '<dd style="background-image:url(\'/res/adm/pages/docs.png\');"><a class="LC_menubuttons_link" href="/adm/coursedocs">'.&mt('If no students have attempted the Concept Test you will be able to modify it. You can also change the start and end date of the test itself.').'</a></dd>'. 1487: '<dt><a href="/adm/createuser">'.&mt('Enrollment and Student Activity').'</a></dt>'. 1488: '<dd style="background-image:url(\'/res/adm/pages/cprv.png\');"><a class="LC_menubuttons_link" href="/adm/createuser">'.&mt('Display or download a course roster, and view information about completion status and last login. You can also add new students, or change access dates for existing students.').'</a></dd></dl></div>'. 1489: '<div class="LC_GCI_Menu_right"><dl class="LC_GCI_Menu">'. 1490: '<dt><a href="/adm/whatsnew">'.&mt("What's New?").'</a></dt>'. 1491: '<dd style="background-image:url(\'/res/adm/pages/new.png\');"><a class="LC_menubuttons_link" href="/adm/whatsnew">'.&mt('View information about changes in your Concept Test course.').'</a></dd>'. 1492: '<dt><a href="/adm/printout">'.&mt('Prepare Printable Concept Test').'</a></dt>'. 1493: '<dd style="background-image:url(\'/res/adm/pages/prnt.png\');"><a class="LC_menubuttons_link" href="/adm/printout">'.&mt('Create a PDF which you can send to a printer to create a hardcopy of the Concept Test.').'</a></dd>'. 1494: '<dt><a href="/adm/statistics">'.&mt('Concept Test Statistics').'</a></dt>'. 1495: '<dd style="background-image:url(\'/res/adm/pages/chrt.png\');"><a class="LC_menubuttons_link" href="/adm/statistics">'.&mt('After the closing date of the Concept Test you can view and download statistics for the test, as well as anonymized submission data.').'</a></dd>'; 1496: if ($canreq) { 1497: $output .= '<dt><a href="javascript:switchpage('."'createtest'".');">'.&mt('Create New Test').'</a></dt>'. 1498: '<dd style="background-image:url(\'/res/adm/pages/rcrs.png\');"><a class="LC_menubuttons_link" href="javascript:switchpage('."'createtest'".');">'. 1499: &mt('Create a new Concept Test Course Container. Choose GCI questions to include in the test and upload a student roster.').'</a></dd>'; 1500: } 1501: $output .= '</dl></div></div><br clear="all"/>'; 1502: } else { 1503: my $navtext = &mt('Table of Contents'); 1504: my $navdesc = &mt('Display Table of Contents for Geoscience Concept Inventory'); 1505: if ($env{'request.role.domain'} eq 'gcitest') { 1506: $navtext = &mt('Display Test Contents'); 1507: $navdesc = &mt('Display the table of contents for this Concept Test'); 1508: } 1509: my $navlink; 1510: if ($env{'environment.remotenavmap'} eq 'on') { 1511: $navlink = "javascript:gonav('/adm/navmaps');" 1512: } else { 1513: $navlink = '/adm/navmaps'; 1514: } 1515: $output .= 1516: '<div class="LC_Box LC_GCI_Menu">'. 1517: '<h3 class="LC_hcell">'.&mt('Utilities').'</h3>'. 1518: '<div class="LC_GCI_Menu_left">'. 1519: '<dl class="LC_GCI_Menu">'. 1520: '<dt><a href="'.$navlink.'">'.$navtext.'</dt>'. 1521: '<dd style="background-image:url(\'/res/adm/pages/nav.png\');">'. 1522: '<a class="LC_menubuttons_link" href="'.$navlink.'">'.$navdesc.'</a></dd></dl></div>'; 1523: if ($canreq) { 1524: $output .= '<div class="LC_GCI_Menu_right">'. 1525: '<dl class="LC_GCI_Menu">'. 1526: '<dt><a href="javascript:switchpage('."'createtest'".');">'.$createtext.'</a></dt>'. 1527: '<dd style="background-image:url(\'/res/adm/pages/rcrs.png\');"><a class="LC_menubuttons_link" href="javascript:switchpage('."'createtest'".');">'.&mt('Create a new Concept Test Course Container').'</a>. '.&mt('Choose GCI questions to include in the test and upload a student roster.').'</dd></dl></div>'; 1528: } 1529: $output .= '</div><br clear="all"/>'; 1530: } 1531: } elsif ($switcher || $canreq) { 1532: $output .= '<br /><br />'. 1533: '<div class="LC_Box LC_GCI_Menu">'. 1534: '<h3 class="LC_hcell">'.&mt('Utilities').'</h3>'. 1535: '<div class="LC_GCI_Menu_left">'. 1536: '<dl class="LC_GCI_Menu">'; 1537: if ($canreq) { 1538: $output .= '<dt><a href="javascript:switchpage('."'createtest'".');">'.$createtext.'</a></dt>'. 1539: '<dd style="background-image:url(\'/res/adm/pages/rcrs.png\');"><a class="LC_menubuttons_link" href="javascript:switchpage('."'createtest'".');">'.&mt('Create a new Concept Test Course Container. Choose GCI questions to include in the test and upload a student roster.').'</a></dd></dl></div>'; 1540: if ($switcher) { 1541: $output .= '<div class="LC_GCI_Menu_right">'. 1542: '<dl class="LC_GCI_Menu">'; 1543: } 1544: } 1545: if ($switcher) { 1546: $output .= '<dt>'.&mt('Select Concept Test').'</dt>'. 1547: '<dd style="background-image:url(\'/res/adm/pages/roles.png\');">'.$switcher.'<br /><br /></dd></dl></div>'; 1548: } 1549: $output .= '</div><br clear="all"/>'; 1550: } 1551: } elsif ($context eq 'gcinorole') { 1552: my $queued = &Apache::loncoursequeueadmin::queued_selfenrollment('notitle'); 1553: if ($queued) { 1554: $output .= 1555: '<div class="LC_Box">'. 1556: '<h3 class="LC_hcell">'.&mt('Pending Enrollment Requests').'</h3>'. 1557: $queued. 1558: '</div>'; 1559: } 1560: } else { 1561: # calling rawconfig with "1" will evaluate mydesk.tab, 1562: # even if there is no active remote control 1563: &rawconfig(1); 1564: $output='<table><tr>'; 1565: for (my $col=1; $col<=2; $col++) { 1566: $output.='<td class="LC_mainmenu_col_fieldset">'; 1567: for (my $row=1; $row<=8; $row++) { 1568: foreach my $cat (keys(%category_members)) { 1569: if ($category_positions{$cat} ne "$col,$row") { next; } 1570: $output.='<div class="LC_Box LC_400Box">'; 1571: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>'; 1572: $output.='<table>'; 1573: my %active=(); 1574: foreach my $menu_item (split(/\:/,$category_members{$cat})) { 1575: if ($inlineremote[$menu_item]) { 1576: $active{$menu_item}=1; 1577: } 1578: } 1579: foreach my $item (sort(keys(%active))) { 1580: $output.=$inlineremote[$item]; 1581: } 1582: $output.='</table>'; 1583: $output.='</div>'; 1584: } 1585: } 1586: $output.="</td>"; 1587: } 1588: $output.="</tr></table>"; 1589: } 1590: return $output; 1591: } 1592: 1593: sub rawconfig { 1594: # 1595: # This evaluates mydesk.tab 1596: # Need to add more positions and more privileges to deal with all 1597: # menu items. 1598: # 1599: my $textualoverride=shift; 1600: my $output=''; 1601: unless ($env{'environment.remote'} eq 'off') { 1602: $output.= 1603: "window.status='Opening Remote Control';var swmenu=".&openmenu(). 1604: "\nwindow.status='Configuring Remote Control ';"; 1605: } else { 1606: unless ($textualoverride) { return ''; } 1607: } 1608: my $uname=$env{'user.name'}; 1609: my $udom=$env{'user.domain'}; 1610: my $adv=$env{'user.adv'}; 1611: my $show_course=&Apache::loncommon::show_course(); 1612: my $author=$env{'user.author'}; 1613: my $crs=''; 1614: my $crstype=''; 1615: if ($env{'request.course.id'}) { 1616: $crs='/'.$env{'request.course.id'}; 1617: if ($env{'request.course.sec'}) { 1618: $crs.='_'.$env{'request.course.sec'}; 1619: } 1620: $crs=~s/\_/\//g; 1621: $crstype = &Apache::loncommon::course_type(); 1622: } 1623: my $pub=($env{'request.state'} eq 'published'); 1624: my $con=($env{'request.state'} eq 'construct'); 1625: my $rol=$env{'request.role'}; 1626: my $requested_domain = $env{'request.role.domain'}; 1627: foreach my $line (@desklines) { 1628: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line); 1629: $prt=~s/\$uname/$uname/g; 1630: $prt=~s/\$udom/$udom/g; 1631: if ($prt =~ /\$crs/) { 1632: next unless ($env{'request.course.id'}); 1633: next if ($crstype eq 'Community'); 1634: $prt=~s/\$crs/$crs/g; 1635: } elsif ($prt =~ /\$cmty/) { 1636: next unless ($env{'request.course.id'}); 1637: next if ($crstype ne 'Community'); 1638: $prt=~s/\$cmty/$crs/g; 1639: } 1640: $prt=~s/\$requested_domain/$requested_domain/g; 1641: if ($category_names{$cat}!~/\w/) { $cat='oth'; } 1642: if ($pro eq 'clear') { 1643: $output.=&clear($row,$col); 1644: } elsif ($pro eq 'any') { 1645: $output.=&secondlevel( 1646: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); 1647: } elsif ($pro eq 'smp') { 1648: unless ($adv) { 1649: $output.=&secondlevel( 1650: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); 1651: } 1652: } elsif ($pro eq 'adv') { 1653: if ($adv) { 1654: $output.=&secondlevel( 1655: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); 1656: } 1657: } elsif ($pro eq 'shc') { 1658: if ($show_course) { 1659: $output.=&secondlevel( 1660: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); 1661: } 1662: } elsif ($pro eq 'nsc') { 1663: if (!$show_course) { 1664: $output.=&secondlevel( 1665: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); 1666: } 1667: } elsif (($pro=~/^p(\w+)/) && ($prt)) { 1668: my $priv = $1; 1669: if ($priv =~ /^mdc(Course|Community)/) { 1670: if ($crstype eq $1) { 1671: $priv = 'mdc'; 1672: } else { 1673: next; 1674: } 1675: } 1676: if (&Apache::lonnet::allowed($priv,$prt)) { 1677: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); 1678: } 1679: } elsif ($pro eq 'course') { 1680: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) { 1681: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); 1682: } 1683: } elsif ($pro eq 'community') { 1684: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) { 1685: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); 1686: } 1687: } elsif ($pro =~ /^courseenv_(.*)$/) { 1688: my $key = $1; 1689: if ($crstype ne 'Community') { 1690: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key}; 1691: if ($key eq 'canuse_pdfforms') { 1692: if ($env{'request.course.id'} && $coursepref eq '') { 1693: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'}); 1694: $coursepref = $domdefs{'canuse_pdfforms'}; 1695: } 1696: } 1697: if ($coursepref) { 1698: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); 1699: } 1700: } 1701: } elsif ($pro =~ /^communityenv_(.*)$/) { 1702: my $key = $1; 1703: if ($crstype eq 'Community') { 1704: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key}; 1705: if ($key eq 'canuse_pdfforms') { 1706: if ($env{'request.course.id'} && $coursepref eq '') { 1707: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'}); 1708: $coursepref = $domdefs{'canuse_pdfforms'}; 1709: } 1710: } 1711: if ($coursepref) { 1712: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); 1713: } 1714: } 1715: } elsif ($pro =~ /^course_(.*)$/) { 1716: # Check for permissions inside of a course 1717: if (($env{'request.course.id'}) && ($crstype ne 'Community') && 1718: (&Apache::lonnet::allowed($1,$env{'request.course.id'}. 1719: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) 1720: )) { 1721: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); 1722: } 1723: } elsif ($pro =~ /^community_(.*)$/) { 1724: # Check for permissions inside of a community 1725: if (($env{'request.course.id'}) && ($crstype eq 'Community') && 1726: (&Apache::lonnet::allowed($1,$env{'request.course.id'}. 1727: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) 1728: )) { 1729: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); 1730: } 1731: } elsif ($pro eq 'author') { 1732: if ($author) { 1733: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) || 1734: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 1735: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) { 1736: # Check that we are on the correct machine 1737: my $cadom=$requested_domain; 1738: my $caname=$env{'user.name'}; 1739: if (($prt eq 'rca') || ($prt eq 'raa')) { 1740: ($cadom,$caname)= 1741: ($env{'request.role'}=~/($match_domain)\/($match_username)$/); 1742: } 1743: $act =~ s/\$caname/$caname/g; 1744: my $home = &Apache::lonnet::homeserver($caname,$cadom); 1745: my $allowed=0; 1746: my @ids=&Apache::lonnet::current_machine_ids(); 1747: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } 1748: if ($allowed) { 1749: $output.=&switch($caname,$cadom, 1750: $row,$col,$img,$top,$bot,$act,$desc,$cat); 1751: } 1752: } 1753: } 1754: } elsif ($pro eq 'tools') { 1755: my @tools = ('aboutme','blog','portfolio'); 1756: if (grep(/^\Q$prt\E$/,@tools)) { 1757: if (!&Apache::lonnet::usertools_access($env{'user.name'}, 1758: $env{'user.domain'}, 1759: $prt,undef,'tools')) { 1760: $output.=&clear($row,$col); 1761: next; 1762: } 1763: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) { 1764: if (($prt eq 'reqcrsnsc') && ($show_course)) { 1765: next; 1766: } 1767: if (($prt eq 'reqcrsshc') && (!$show_course)) { 1768: next; 1769: } 1770: my $showreqcrs = &check_for_rcrs(); 1771: if (!$showreqcrs) { 1772: $output.=&clear($row,$col); 1773: next; 1774: } 1775: } 1776: $prt='any'; 1777: $output.=&secondlevel( 1778: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); 1779: } 1780: } 1781: unless ($env{'environment.remote'} eq 'off') { 1782: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';"; 1783: if (&Apache::lonmsg::newmail()) { 1784: $output.='swmenu.setstatus("you have","messages");'; 1785: } 1786: } 1787: 1788: return $output; 1789: } 1790: 1791: sub check_for_rcrs { 1792: my $showreqcrs = 0; 1793: my @reqtypes = ('official','unofficial','community'); 1794: foreach my $type (@reqtypes) { 1795: if (&Apache::lonnet::usertools_access($env{'user.name'}, 1796: $env{'user.domain'}, 1797: $type,undef,'requestcourses')) { 1798: $showreqcrs = 1; 1799: last; 1800: } 1801: } 1802: if (!$showreqcrs) { 1803: foreach my $type (@reqtypes) { 1804: if ($env{'environment.reqcrsotherdom.'.$type} ne '') { 1805: $showreqcrs = 1; 1806: last; 1807: } 1808: } 1809: } 1810: return $showreqcrs; 1811: } 1812: 1813: # ======================================================================= Close 1814: 1815: sub close { 1816: if ($env{'environment.remote'} eq 'off') { return ''; } 1817: my $menuname = &get_menu_name(); 1818: return(<<ENDCLOSE); 1819: <script type="text/javascript"> 1820: // <![CDATA[ 1821: window.status='Accessing Remote Control'; 1822: menu=window.open("/adm/rat/empty.html","$menuname", 1823: "height=350,width=150,scrollbars=no,menubar=no"); 1824: window.status='Disabling Remote Control'; 1825: menu.active=0; 1826: menu.autologout=0; 1827: window.status='Closing Remote Control'; 1828: menu.close(); 1829: window.status='Done.'; 1830: // ]]> 1831: </script> 1832: ENDCLOSE 1833: } 1834: 1835: # ====================================================================== Footer 1836: 1837: sub footer { 1838: 1839: } 1840: 1841: sub nav_control_js { 1842: my $nav=($env{'environment.remotenavmap'} eq 'on'); 1843: return (<<NAVCONTROL); 1844: var w_loncapanav_flag="$nav"; 1845: 1846: 1847: function gonav(url) { 1848: if (w_loncapanav_flag != 1) { 1849: gopost(url,''); 1850: } else { 1851: navwindow=window.open(url, 1852: "loncapanav","height=600,width=400,scrollbars=1"); 1853: } 1854: } 1855: NAVCONTROL 1856: } 1857: 1858: sub dc_popup_js { 1859: my %lt = &Apache::lonlocal::texthash( 1860: more => '(More ...)', 1861: less => '(Less ...)', 1862: ); 1863: return <<"END"; 1864: 1865: function showCourseID() { 1866: document.getElementById('dccid').style.display='block'; 1867: document.getElementById('dccid').style.textAlign='left'; 1868: document.getElementById('dccid').style.textFace='normal'; 1869: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>'; 1870: return; 1871: } 1872: 1873: function hideCourseID() { 1874: document.getElementById('dccid').style.display='none'; 1875: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()">$lt{'more'}</a>'; 1876: return; 1877: } 1878: 1879: END 1880: 1881: } 1882: 1883: sub utilityfunctions { 1884: my ($caller,$custommenu) = @_; 1885: unless ($env{'environment.remote'} eq 'off' || 1886: $caller eq '/adm/menu') { 1887: return ''; } 1888: 1889: my $gcimenujs; 1890: if ($custommenu) { 1891: my %concepttests = &Apache::loncommon::existing_gcitest_courses('cc'); 1892: my $managetesturl = '/adm/menu'; 1893: my $createtesturl = '/adm/requestcourse'; 1894: if (($env{'request.course.id'}) && 1895: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq 'gci')) { 1896: my @items = keys(%concepttests); 1897: if (@items== 1) { 1898: my $newrole = $items[0]; 1899: $newrole =~ s{_}{/}; 1900: $managetesturl = '/adm/roles?selectrole=1&cc./'.$newrole.'=1'; 1901: } else { 1902: $managetesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu'; 1903: } 1904: } 1905: if ($env{'request.course.id'}) { 1906: $createtesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2frequestcourse'; 1907: } 1908: $gcimenujs = <<"ENDCUSTOM"; 1909: 1910: function switchpage(caller) { 1911: if (caller == 'review') { 1912: document.location.href = '/adm/roles?selectrole=1&st./gci/9615072b469884921gcil1=1'; 1913: } 1914: if (caller == 'submit') { 1915: document.location.href = '/adm/roles?selectrole=1&st./gci/1H96711d710194bfegcil1=1'; 1916: } 1917: if (caller == 'createtest') { 1918: document.location.href = '$createtesturl'; 1919: } 1920: if (caller == 'managetest') { 1921: document.location.href = '$managetesturl'; 1922: } 1923: if (caller == 'tutorial') { 1924: document.location.href = '/adm/roles?selectrole=1&st./gci/5422913620b814c90gcil1=1'; 1925: } 1926: return; 1927: } 1928: 1929: ENDCUSTOM 1930: } 1931: 1932: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0])); 1933: if ($currenturl =~ m{^/adm/wrapper/ext/}) { 1934: if ($env{'request.external.querystring'}) { 1935: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'}; 1936: } 1937: } 1938: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl)); 1939: 1940: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'}); 1941: my $nav_control=&nav_control_js(); 1942: 1943: my $dc_popup_cid; 1944: if ($env{'user.adv'} && exists($env{'user.role.dc./'. 1945: $env{'course.'.$env{'request.course.id'}. 1946: '.domain'}.'/'})) { 1947: $dc_popup_cid = &dc_popup_js(); 1948: } 1949: 1950: my $start_page_annotate = 1951: &Apache::loncommon::start_page('Annotator',undef, 1952: {'only_body' => 1, 1953: 'js_ready' => 1, 1954: 'bgcolor' => '#BBBBBB', 1955: 'add_entries' => { 1956: 'onload' => 'javascript:document.goannotate.submit();'}}); 1957: 1958: my $end_page_annotate = 1959: &Apache::loncommon::end_page({'js_ready' => 1}); 1960: 1961: my $start_page_bookmark = 1962: &Apache::loncommon::start_page('Bookmarks',undef, 1963: {'only_body' => 1, 1964: 'js_ready' => 1, 1965: 'bgcolor' => '#BBBBBB',}); 1966: 1967: my $end_page_bookmark = 1968: &Apache::loncommon::end_page({'js_ready' => 1}); 1969: 1970: return (<<ENDUTILITY) 1971: 1972: var currentURL="$currenturl"; 1973: var reloadURL="$currenturl"; 1974: var currentSymb="$currentsymb"; 1975: 1976: $nav_control 1977: $dc_popup_cid 1978: 1979: $gcimenujs 1980: 1981: function go(url) { 1982: if (url!='' && url!= null) { 1983: currentURL = null; 1984: currentSymb= null; 1985: window.location.href=url; 1986: } 1987: } 1988: 1989: function gotop(url) { 1990: if (url!='' && url!= null) { 1991: top.location.href = url; 1992: } 1993: } 1994: 1995: function gopost(url,postdata) { 1996: if (url!='') { 1997: this.document.server.action=url; 1998: this.document.server.postdata.value=postdata; 1999: this.document.server.command.value=''; 2000: this.document.server.url.value=''; 2001: this.document.server.symb.value=''; 2002: this.document.server.submit(); 2003: } 2004: } 2005: 2006: function gocmd(url,cmd) { 2007: if (url!='') { 2008: this.document.server.action=url; 2009: this.document.server.postdata.value=''; 2010: this.document.server.command.value=cmd; 2011: this.document.server.url.value=currentURL; 2012: this.document.server.symb.value=currentSymb; 2013: this.document.server.submit(); 2014: } 2015: } 2016: 2017: function gocstr(url,filename) { 2018: if (url == '/adm/cfile?action=delete') { 2019: this.document.cstrdelete.filename.value = filename 2020: this.document.cstrdelete.submit(); 2021: return; 2022: } 2023: if (url == '/adm/printout') { 2024: this.document.cstrprint.postdata.value = filename 2025: this.document.cstrprint.curseed.value = 0; 2026: this.document.cstrprint.problemtype.value = 0; 2027: if (this.document.lonhomework) { 2028: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) { 2029: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value 2030: } 2031: if (this.document.lonhomework.problemtype) { 2032: if (this.document.lonhomework.problemtype.value) { 2033: this.document.cstrprint.problemtype.value = 2034: this.document.lonhomework.problemtype.value; 2035: } else if (this.document.lonhomework.problemtype.options) { 2036: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) { 2037: if (this.document.lonhomework.problemtype.options[i].selected) { 2038: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 2039: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value 2040: } 2041: } 2042: } 2043: } 2044: } 2045: } 2046: this.document.cstrprint.submit(); 2047: return; 2048: } 2049: if (url !='') { 2050: this.document.constspace.filename.value = filename; 2051: this.document.constspace.action = url; 2052: this.document.constspace.submit(); 2053: } 2054: } 2055: 2056: function golist(url) { 2057: if (url!='' && url!= null) { 2058: currentURL = null; 2059: currentSymb= null; 2060: top.location.href=url; 2061: } 2062: } 2063: 2064: 2065: 2066: function catalog_info() { 2067: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no'); 2068: } 2069: 2070: function chat_win() { 2071: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no'); 2072: } 2073: 2074: function group_chat(group) { 2075: var url = '/adm/groupchat?group='+group; 2076: var winName = 'LONchat_'+group; 2077: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no'); 2078: } 2079: 2080: function edit_bookmarks() { 2081: go(''); 2082: w_BookmarkPal_flag=1; 2083: bookmarkpal=window.open("/adm/bookmarks", 2084: "BookmarkPal", "width=400,height=505,scrollbars=0"); 2085: } 2086: 2087: function annotate() { 2088: w_Annotator_flag=1; 2089: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0'); 2090: annotator.document.write( 2091: '$start_page_annotate' 2092: +"<form name='goannotate' target='Annotator' method='post' " 2093: +"action='/adm/annotations'>" 2094: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />" 2095: +"<\\/form>" 2096: +'$end_page_annotate'); 2097: annotator.document.close(); 2098: } 2099: 2100: function set_bookmark() { 2101: go(''); 2102: clienttitle=document.title; 2103: clienthref=location.pathname; 2104: w_bmquery_flag=1; 2105: bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0'); 2106: bmquery.document.write( 2107: '$start_page_bookmark' 2108: +'<center><form method="post"' 2109: +' name="newlink" action="/adm/bookmarks" target="bmquery" ' 2110: +'> <table width="340" height="150" ' 2111: +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input ' 2112: +'type="text" name="title" size="45" value="'+clienttitle+'" />' 2113: +'<br />Address:<br /><input type="text" name="address" size="45" ' 2114: +'value="'+clienthref+'" /><br /><center><input type="submit" ' 2115: +'value="Save" /> <input type="button" value="Close" ' 2116: +'onclick="javascript:window.close();" /></center></td>' 2117: +'</tr></table></form></center>' 2118: +'$end_page_bookmark' ); 2119: bmquery.document.close(); 2120: } 2121: 2122: ENDUTILITY 2123: } 2124: 2125: sub serverform { 2126: return(<<ENDSERVERFORM); 2127: <form name="server" action="/adm/logout" method="post" target="_top"> 2128: <input type="hidden" name="postdata" value="none" /> 2129: <input type="hidden" name="command" value="none" /> 2130: <input type="hidden" name="url" value="none" /> 2131: <input type="hidden" name="symb" value="none" /> 2132: </form> 2133: ENDSERVERFORM 2134: } 2135: 2136: sub constspaceform { 2137: return(<<ENDCONSTSPACEFORM); 2138: <form name="constspace" action="/adm/logout" method="post" target="_top"> 2139: <input type="hidden" name="filename" value="" /> 2140: </form> 2141: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top"> 2142: <input type="hidden" name="action" value="delete" /> 2143: <input type="hidden" name="filename" value="" /> 2144: </form> 2145: <form name="cstrprint" action="/adm/printout" target="_parent" method="post"> 2146: <input type="hidden" name="postdata" value="" /> 2147: <input type="hidden" name="curseed" value="" /> 2148: <input type="hidden" name="problemtype" value="" /> 2149: </form> 2150: 2151: ENDCONSTSPACEFORM 2152: } 2153: 2154: 2155: sub get_nav_status { 2156: my $navstatus="swmenu.w_loncapanav_flag="; 2157: if ($env{'environment.remotenavmap'} eq 'on') { 2158: $navstatus.="1"; 2159: } else { 2160: $navstatus.="-1"; 2161: } 2162: return $navstatus; 2163: } 2164: 2165: sub hidden_button_check { 2166: my $hidden; 2167: if ($env{'request.course.id'} eq '') { 2168: return; 2169: } 2170: if ($env{'request.role.adv'}) { 2171: unless (&Apache::loncommon::needs_gci_custom()) { 2172: return; 2173: } 2174: } 2175: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide'); 2176: return $buttonshide; 2177: } 2178: 2179: sub roles_selector { 2180: my ($cdom,$cnum) = @_; 2181: my $crstype = &Apache::loncommon::course_type(); 2182: my $now = time; 2183: my (%courseroles,%seccount); 2184: my $is_cc; 2185: my $role_selector; 2186: my $ccrole; 2187: if ($crstype eq 'Community') { 2188: $ccrole = 'co'; 2189: } else { 2190: $ccrole = 'cc'; 2191: } 2192: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) { 2193: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}); 2194: 2195: if ((($start) && ($start<0)) || 2196: (($end) && ($end<$now)) || 2197: (($start) && ($now<$start))) { 2198: $is_cc = 0; 2199: } else { 2200: $is_cc = 1; 2201: } 2202: } 2203: if ($is_cc) { 2204: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount); 2205: } else { 2206: my %gotnosection; 2207: foreach my $item (keys(%env)) { 2208: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) { 2209: my $role = $1; 2210: my $sec = $2; 2211: next if ($role eq 'gr'); 2212: my ($start,$end) = split(/\./,$env{$item}); 2213: next if (($start && $start > $now) || ($end && $end < $now)); 2214: if ($sec eq '') { 2215: if (!$gotnosection{$role}) { 2216: $seccount{$role} ++; 2217: $gotnosection{$role} = 1; 2218: } 2219: } 2220: if (ref($courseroles{$role}) eq 'ARRAY') { 2221: if ($sec ne '') { 2222: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) { 2223: push(@{$courseroles{$role}},$sec); 2224: $seccount{$role} ++; 2225: } 2226: } 2227: } else { 2228: @{$courseroles{$role}} = (); 2229: if ($sec ne '') { 2230: $seccount{$role} ++; 2231: push(@{$courseroles{$role}},$sec); 2232: } 2233: } 2234: } 2235: } 2236: } 2237: my $switchtext; 2238: if ($crstype eq 'Community') { 2239: $switchtext = &mt('Switch community role to...') 2240: } else { 2241: $switchtext = &mt('Switch course role to...') 2242: } 2243: my @roles_order = ($ccrole,'in','ta','ep','ad','st'); 2244: if (keys(%courseroles) > 1) { 2245: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles); 2246: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles"> 2247: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">'; 2248: $role_selector .= '<option value="">'.$switchtext.'</option>'; 2249: foreach my $role (@roles_order) { 2250: if (defined($courseroles{$role})) { 2251: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>'; 2252: } 2253: } 2254: foreach my $role (sort(keys(%courseroles))) { 2255: if ($role =~ /^cr/) { 2256: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 2257: } 2258: } 2259: $role_selector .= '</select>'."\n". 2260: '<input type="hidden" name="destinationurl" value="'. 2261: &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n". 2262: '<input type="hidden" name="gotorole" value="1" />'."\n". 2263: '<input type="hidden" name="selectrole" value="" />'."\n". 2264: '<input type="hidden" name="switch" value="1" />'."\n". 2265: '</form>'; 2266: } 2267: return $role_selector; 2268: } 2269: 2270: sub get_all_courseroles { 2271: my ($cdom,$cnum,$courseroles,$seccount) = @_; 2272: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) { 2273: return; 2274: } 2275: my ($result,$cached) = 2276: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum); 2277: if (defined($cached)) { 2278: if (ref($result) eq 'HASH') { 2279: if ((ref($result->{'roles'}) eq 'HASH') && 2280: (ref($result->{'seccount'}) eq 'HASH')) { 2281: %{$courseroles} = %{$result->{'roles'}}; 2282: %{$seccount} = %{$result->{'seccount'}}; 2283: return; 2284: } 2285: } 2286: } 2287: my %gotnosection; 2288: my %adv_roles = 2289: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1); 2290: foreach my $role (keys(%adv_roles)) { 2291: my ($urole,$usec) = split(/:/,$role); 2292: if (!$gotnosection{$urole}) { 2293: $seccount->{$urole} ++; 2294: $gotnosection{$urole} = 1; 2295: } 2296: if (ref($courseroles->{$urole}) eq 'ARRAY') { 2297: if ($usec ne '') { 2298: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) { 2299: push(@{$courseroles->{$urole}},$usec); 2300: $seccount->{$urole} ++; 2301: } 2302: } 2303: } else { 2304: @{$courseroles->{$urole}} = (); 2305: if ($usec ne '') { 2306: $seccount->{$urole} ++; 2307: push(@{$courseroles->{$urole}},$usec); 2308: } 2309: } 2310: } 2311: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']); 2312: @{$courseroles->{'st'}} = (); 2313: if (keys(%sections_count) > 0) { 2314: push(@{$courseroles->{'st'}},keys(%sections_count)); 2315: $seccount->{'st'} = scalar(keys(%sections_count)); 2316: } 2317: my $rolehash = { 2318: 'roles' => $courseroles, 2319: 'seccount' => $seccount, 2320: }; 2321: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash); 2322: return; 2323: } 2324: 2325: sub jump_to_role { 2326: my ($cdom,$cnum,$seccount,$courseroles) = @_; 2327: my %lt = &Apache::lonlocal::texthash( 2328: this => 'This role has section(s) associated with it.', 2329: ente => 'Enter a specific section.', 2330: orlb => 'Enter a specific section, or leave blank for no section.', 2331: avai => 'Available sections are:', 2332: youe => 'You entered an invalid section choice:', 2333: plst => 'Please try again', 2334: ); 2335: my $js; 2336: if (ref($courseroles) eq 'HASH') { 2337: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 2338: ' var numsec = new Array();'."\n". 2339: ' var rolesections = new Array();'."\n". 2340: ' var rolenames = new Array();'."\n". 2341: ' var roleseclist = new Array();'."\n"; 2342: my @items = keys(%{$courseroles}); 2343: for (my $i=0; $i<@items; $i++) { 2344: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n"; 2345: my ($secs,$secstr); 2346: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') { 2347: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}}; 2348: $secs = join('","',@sections); 2349: $secstr = join(', ',@sections); 2350: } 2351: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n". 2352: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n". 2353: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n"; 2354: } 2355: } 2356: return <<"END"; 2357: <script type="text/javascript"> 2358: //<![CDATA[ 2359: function adhocRole(roleitem) { 2360: $js 2361: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value; 2362: if (newrole == '') { 2363: return; 2364: } 2365: var fullrole = newrole+'./$cdom/$cnum'; 2366: var selidx = ''; 2367: for (var i=0; i<rolenames.length; i++) { 2368: if (rolenames[i] == newrole) { 2369: selidx = i; 2370: } 2371: } 2372: var secok = 1; 2373: var secchoice = ''; 2374: if (selidx >= 0) { 2375: if (numsec[selidx] > 1) { 2376: secok = 0; 2377: var numrolesec = rolesections[selidx].length; 2378: var msgidx = numsec[selidx] - numrolesec; 2379: secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],""); 2380: if (secchoice == '') { 2381: if (msgidx > 0) { 2382: secok = 1; 2383: } 2384: } else { 2385: for (var j=0; j<rolesections[selidx].length; j++) { 2386: if (rolesections[selidx][j] == secchoice) { 2387: secok = 1; 2388: } 2389: } 2390: } 2391: } else { 2392: if (rolesections[selidx].length == 1) { 2393: secchoice = rolesections[selidx][0]; 2394: } 2395: } 2396: } 2397: if (secok == 1) { 2398: if (secchoice != '') { 2399: fullrole += '/'+secchoice; 2400: } 2401: } else { 2402: document.rolechooser.elements[roleitem].selectedIndex = 0; 2403: if (secchoice != null) { 2404: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}"); 2405: } 2406: return; 2407: } 2408: if (fullrole == "$env{'request.role'}") { 2409: return; 2410: } 2411: itemid = retrieveIndex('gotorole'); 2412: if (itemid != -1) { 2413: document.rolechooser.elements[itemid].name = fullrole; 2414: } 2415: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole; 2416: document.rolechooser.selectrole.value = '1'; 2417: document.rolechooser.submit(); 2418: return; 2419: } 2420: 2421: function retrieveIndex(item) { 2422: for (var i=0;i<document.rolechooser.elements.length;i++) { 2423: if (document.rolechooser.elements[i].name == item) { 2424: return i; 2425: } 2426: } 2427: return -1; 2428: } 2429: // ]]> 2430: </script> 2431: END 2432: } 2433: 2434: 2435: # ================================================================ Main Program 2436: 2437: BEGIN { 2438: if (! defined($readdesk)) { 2439: { 2440: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab'; 2441: if ( CORE::open( my $config,"<$tabfile") ) { 2442: while (my $configline=<$config>) { 2443: $configline=(split(/\#/,$configline))[0]; 2444: $configline=~s/^\s+//; 2445: chomp($configline); 2446: if ($configline=~/^cat\:/) { 2447: my @entries=split(/\:/,$configline); 2448: $category_positions{$entries[2]}=$entries[1]; 2449: $category_names{$entries[2]}=$entries[3]; 2450: } elsif ($configline=~/^prim\:/) { 2451: my @entries = (split(/\:/, $configline))[1..5]; 2452: push @primary_menu, \@entries; 2453: } elsif ($configline=~/^scnd\:/) { 2454: my @entries = (split(/\:/, $configline))[1..5]; 2455: push @secondary_menu, \@entries; 2456: } elsif ($configline) { 2457: push(@desklines,$configline); 2458: } 2459: } 2460: CORE::close($config); 2461: } 2462: } 2463: $readdesk='done'; 2464: } 2465: } 2466: 2467: 1; 2468: __END__ 2469: