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