Annotation of loncom/interface/lonmenu.pm, revision 1.293
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.293 ! raeburn 4: # $Id: lonmenu.pm,v 1.292 2009/10/17 01:04:56 raeburn Exp $
1.11 albertel 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: #
1.1 www 28: #
1.269 droeschl 29: # There is one parameter controlling the action of this module:
1.48 www 30: #
31: # environment.remote - if this is 'on', the routines controll the remote
1.269 droeschl 32: # control, otherwise they render the main window controls;
1.1 www 33:
1.244 jms 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:
1.1 www 126: package Apache::lonmenu;
127:
128: use strict;
1.152 albertel 129: use Apache::lonnet;
1.47 matthew 130: use Apache::lonhtmlcommon();
1.115 albertel 131: use Apache::loncommon();
1.127 albertel 132: use Apache::lonenc();
1.88 www 133: use Apache::lonlocal;
1.207 foxr 134: use LONCAPA qw(:DEFAULT :match);
1.282 amueller 135: use HTML::Entities();
1.88 www 136:
1.283 droeschl 137: use vars qw(@desklines %category_names %category_members %category_positions
138: $readdesk @primary_menu @secondary_menu);
1.88 www 139:
1.56 www 140: my @inlineremote;
1.38 www 141:
1.283 droeschl 142: sub prep_menuitem {
1.291 raeburn 143: my ($menuitem) = @_;
144: return '' unless(ref($menuitem) eq 'ARRAY');
1.283 droeschl 145: my $link;
146: if ($$menuitem[1]) { # graphical Link
147: $link = "<img class=\"LC_noBorder\""
1.291 raeburn 148: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
149: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283 droeschl 150: } else { # textual Link
1.291 raeburn 151: $link = &mt($$menuitem[3]);
152: }
153: return '<li><a href="'.$$menuitem[0].'">'.$link.'</a></li>';
1.283 droeschl 154: }
155:
156: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
157: # that contains following links:
158: # About, Message, Roles, Help, Logout
159: # @primary_menu is filled within the BEGIN block of this module with
160: # entries from mydesk.tab
161: sub primary_menu {
162: my $menu;
163: # each element of @primary contains following array:
164: # (link url, icon path, alt text, link text, condition)
165: foreach my $menuitem (@primary_menu) {
166: # evaluate conditions
167: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
1.291 raeburn 168: && &Apache::lonmsg::mynewmail(); # whether a new msg
1.283 droeschl 169: next if $$menuitem[4] eq 'newmsg' # arrived or not
1.291 raeburn 170: && !&Apache::lonmsg::mynewmail(); #
1.283 droeschl 171: next if $$menuitem[4] !~ /public/ ##we've a public user,
172: && $env{'user.name'} eq 'public' ##who should not see all
173: && $env{'user.domain'} eq 'public'; ##links
174: next if $$menuitem[4] eq 'onlypublic'# hide links which are
175: && $env{'user.name'} ne 'public' # only visible to public
176: && $env{'user.domain'} ne 'public'; # users
177: next if $$menuitem[4] eq 'roles' ##show links depending on
1.291 raeburn 178: && &Apache::loncommon::show_course(); ##term 'Courses' or
1.283 droeschl 179: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
1.291 raeburn 180: && !&Apache::loncommon::show_course(); ##
181:
182:
1.283 droeschl 183: if ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.291 raeburn 184: $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.283 droeschl 185: } else {
1.291 raeburn 186: if (ref($menuitem) eq 'ARRAY') {
187: my @items = @{$menuitem};
1.292 raeburn 188: $items[0] = 'javascript:'.$menuitem->[0].';';
1.291 raeburn 189: $menu .= &prep_menuitem(\@items);
190: }
1.283 droeschl 191: }
1.291 raeburn 192: }
1.283 droeschl 193:
1.291 raeburn 194: return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
1.283 droeschl 195: }
196:
197:
198: sub secondary_menu {
199: my $menu;
200:
1.286 raeburn 201: my $crstype = &Apache::loncommon::course_type();
202: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
203: my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'}
204: . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
205: : ''));
206: my $showlink = &show_return_link();
207: my %groups = &Apache::lonnet::get_active_groups(
208: $env{'user.domain'}, $env{'user.name'},
209: $env{'course.' . $env{'request.course.id'} . '.domain'},
210: $env{'course.' . $env{'request.course.id'} . '.num'});
1.283 droeschl 211: foreach my $menuitem (@secondary_menu) {
212: # evaluate conditions
213: next if $$menuitem[4] ne 'always'
214: && !$env{'request.course.id'};
215: next if $$menuitem[4] eq 'showreturn'
1.286 raeburn 216: && !$showlink
1.283 droeschl 217: && !($env{'request.state'} eq 'construct');
218: next if $$menuitem[4] =~ /^mdc/
1.286 raeburn 219: && !$canedit;
220: next if $$menuitem[4] eq 'mdcCourse'
221: && $crstype eq 'Community';
222: next if $$menuitem[4] eq 'mdcCommunity'
223: && $crstype ne 'Community';
224: next if $$menuitem[4] =~ /^remotenav/
1.283 droeschl 225: && $env{'environment.remotenavmap'} ne 'on';
1.286 raeburn 226: next if $$menuitem[4] =~ /noremotenav/
1.283 droeschl 227: && $env{'environment.remotenavmap'} eq 'on';
228: next if $$menuitem[4] =~ /showgroups$/
1.286 raeburn 229: && $canviewgrps
230: && !%groups;
1.283 droeschl 231:
1.286 raeburn 232: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283 droeschl 233: # special treatment for role selector
234: my $roles_selector = roles_selector(
235: $env{'course.' . $env{'request.course.id'} . '.domain'},
236: $env{'course.' . $env{'request.course.id'} . '.num'} );
237:
238: $menu .= $roles_selector ? "<li>$roles_selector</li>"
239: : '';
240: } else {
1.291 raeburn 241: if ($env{'environment.remotenavmap'} eq 'on') {
242: my @items = @{$menuitem};
243: if ($menuitem->[4] eq 'remotenav') {
244: $items[0] = "javascript:gonav('$menuitem->[0]');";
245: } else {
246: $items[0] = "javascript:go('$menuitem->[0]');";
247: }
248: $menu .= &prep_menuitem(\@items);
249: } else {
250: $menu .= &prep_menuitem(\@$menuitem);
251: }
1.283 droeschl 252: }
253: }
254: if ($menu =~ /\[url\].*\[symb\]/) {
1.291 raeburn 255: my $escurl = &escape( &Apache::lonenc::check_encrypt(
256: $env{'request.noversionuri'}));
1.283 droeschl 257:
1.291 raeburn 258: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
259: $env{'request.symb'}));
1.283 droeschl 260:
261: if ( $env{'request.state'} eq 'construct'
262: and ( $env{'request.noversionuri'} eq ''
263: || !defined($env{'request.noversionuri'})))
264: {
265: ($escurl = $env{'request.filename'}) =~
266: s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
267:
1.291 raeburn 268: $escurl = &escape($escurl);
1.283 droeschl 269: }
270: $menu =~ s/\[url\]/$escurl/g;
271: $menu =~ s/\[symb\]/$escsymb/g;
272: }
273:
1.285 wenzelju 274: return "<ul id=\"LC_secondary_menu\">$menu</ul>";
1.283 droeschl 275: }
276:
277:
1.274 www 278: #
279: # This routine returns a translated hash for the menu items in the top inline menu row
280: # Probably should be in mydesk.tab
281:
1.283 droeschl 282: #SD this sub is deprecated - don't use it
1.88 www 283: sub initlittle {
284: return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
1.281 raeburn 285: 'nav' => 'Course Contents',
1.88 www 286: 'main' => 'Main Menu',
1.266 raeburn 287: 'roles' => (&Apache::loncommon::show_course()?
1.231 albertel 288: 'Courses':'Roles'),
1.235 raeburn 289: 'other' => 'Other Roles',
1.219 albertel 290: 'docs' => 'Edit Course',
1.257 hauer 291: 'exit' => 'Logout',
1.202 albertel 292: 'login' => 'Log In',
1.165 raeburn 293: 'launch' => 'Launch Remote Control',
1.188 albertel 294: 'groups' => 'Groups',
1.286 raeburn 295: 'gdoc' => 'Community Documents',
1.184 raeburn 296: );
1.88 www 297: }
298:
1.283 droeschl 299: #SD this sub is deprecated - don't use it
300: #SD functionality is covered by new loncommon::bodytag and primary_menu(), secondary_menu()
1.38 www 301: sub menubuttons {
302: my $forcereg=shift;
1.131 raeburn 303: my $titletable=shift;
1.274 www 304: #
305: # Early-out for pages that should not have a menu, triggered by query string "inhibitmenu=yes"
306: #
1.112 albertel 307: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
308: ['inhibitmenu']);
1.152 albertel 309: if (($env{'form.inhibitmenu'} eq 'yes') ||
1.149 www 310: ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
1.175 albertel 311:
312: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
313:
1.163 www 314: my %lt=&initlittle();
1.55 www 315: my $navmaps='';
1.59 www 316: my $reloadlink='';
1.151 www 317: my $docs='';
1.165 raeburn 318: my $groups='';
1.235 raeburn 319: my $roles='<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
320: my $role_selector;
1.165 raeburn 321: my $showgroups=0;
1.235 raeburn 322: my ($cnum,$cdom);
1.274 www 323: #
324: # if the URL is hidden, symbs and the non-versioned version of the URL would be encrypted
325: #
1.183 www 326: my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
327: my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
1.176 albertel 328:
1.199 albertel 329: my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
1.253 kaisler 330: $logo = '<a href="/adm/about.html"><img src="'.
331: $logo.'" alt="LON-CAPA Logo" class="LC_noBorder" /></a>';
1.199 albertel 332:
1.152 albertel 333: if ($env{'request.state'} eq 'construct') {
1.274 www 334: #
335: # We are in construction space
336: #
1.152 albertel 337: if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
338: my $returnurl = $env{'request.filename'};
1.134 raeburn 339: $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
1.183 www 340: $escurl = &escape($returnurl);
1.134 raeburn 341: }
342: }
1.165 raeburn 343: if ($env{'request.course.id'}) {
1.274 www 344: #
345: # We are in a course
346: #
1.235 raeburn 347: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
348: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.165 raeburn 349: my %coursegroups;
1.188 albertel 350: my $viewgrps_permission =
1.197 raeburn 351: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.165 raeburn 352: if (!$viewgrps_permission) {
1.235 raeburn 353: %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum);
1.188 albertel 354: }
1.165 raeburn 355: if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
356: $showgroups = 1;
357: }
1.235 raeburn 358: $role_selector = &roles_selector($cdom,$cnum);
359: if ($role_selector) {
360: $roles = '<span class="LC_nobreak">'.$role_selector.' <a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></span>';
361: }
1.165 raeburn 362: }
363:
1.267 droeschl 364: if ($env{'environment.remote'} eq 'off') {
1.48 www 365: # Remote Control is switched off
1.58 www 366: # figure out colors
1.267 droeschl 367: my %lt=&initlittle();
1.172 albertel 368:
1.58 www 369: my $domain=&Apache::loncommon::determinedomain();
1.291 raeburn 370: my $function=&Apache::loncommon::get_users_function();
1.58 www 371: my $link=&Apache::loncommon::designparm($function.'.link',$domain);
372: my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
373: my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
374: my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
1.267 droeschl 375:
376: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
377: return (<<ENDINLINEMENU);
1.285 wenzelju 378: <ol class="LC_primary_menu LC_right">
1.271 droeschl 379: <li>$logo</li>
380: <li><a href="/adm/roles" target="_top">$lt{'login'}</a></li>
381: </ol>
382: <hr />
1.156 albertel 383: ENDINLINEMENU
384: }
1.253 kaisler 385: $roles = '<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
1.58 www 386: # Do we have a NAV link?
1.152 albertel 387: if ($env{'request.course.id'}) {
1.141 albertel 388: my $link='/adm/navmaps?postdata='.$escurl.'&postsymb='.
389: $escsymb;
1.152 albertel 390: if ($env{'environment.remotenavmap'} eq 'on') {
1.141 albertel 391: $link="javascript:gonav('".$link."')";
392: }
393: $navmaps=(<<ENDNAV);
1.253 kaisler 394: <li><a href="$link" target="_top">$lt{'nav'}</a></li>
1.114 albertel 395: ENDNAV
1.286 raeburn 396: my $is_community =
397: (&Apache::loncommon::course_type() eq 'Community');
1.152 albertel 398: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.286 raeburn 399: my $text = ($is_community) ? $lt{'gdoc'} : $lt{'docs'};
1.151 www 400: $docs=(<<ENDDOCS);
1.253 kaisler 401: <li><a href="/adm/coursedocs" target="_top">$text</a></li>
1.151 www 402: ENDDOCS
403: }
1.197 raeburn 404: if ($showgroups) {
405: $groups =(<<ENDGROUPS);
1.253 kaisler 406: <li><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></li>
1.197 raeburn 407: ENDGROUPS
408: }
1.228 albertel 409: if (&show_return_link()) {
1.183 www 410: my $escreload=&escape('return:');
1.59 www 411: $reloadlink=(<<ENDRELOAD);
1.253 kaisler 412: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
1.59 www 413: ENDRELOAD
414: }
1.235 raeburn 415: if ($role_selector) {
1.253 kaisler 416: #$roles = '<td>'.$role_selector.'</td><td><a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></td>';
417: $role_selector = '<li>'.$role_selector.'</li>';
1.235 raeburn 418: }
1.55 www 419: }
1.163 www 420: if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
1.183 www 421: my $escreload=&escape('return:');
1.163 www 422: $reloadlink=(<<ENDCRELOAD);
1.253 kaisler 423: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
1.163 www 424: ENDCRELOAD
425: }
1.276 droeschl 426: my $reg = $forcereg ? &innerregister($forcereg,$titletable) : '';
427: my $form = &serverform();
428: my $utility = &utilityfunctions();
429:
430: #Prepare the message link that indicates the arrival of new mail
1.291 raeburn 431: my $messagelink = &Apache::lonmsg::mynewmail() ? "Message (new)" : "Message";
1.276 droeschl 432: $messagelink = '<a href="javascript:go(\'/adm/communicate\');">'
433: . mt($messagelink) .'</a>';
434:
435: my $helplink = &Apache::loncommon::top_nav_help('Help');
1.58 www 436: return (<<ENDINLINEMENU);
1.129 albertel 437: <script type="text/javascript">
1.277 bisitz 438: // <![CDATA[
1.150 albertel 439: // BEGIN LON-CAPA Internal
1.116 albertel 440: $utility
1.150 albertel 441: // ]]>
1.48 www 442: </script>
1.285 wenzelju 443: <ol class="LC_primary_menu LC_right">
1.253 kaisler 444: <li>$logo</li>
1.256 kaisler 445: <li>$messagelink</li>
1.253 kaisler 446: <li>$roles</li>
447: <li>$helplink</li>
448: <li><a href="/adm/logout" target="_top">$lt{'exit'}</a></li>
449: </ol>
1.285 wenzelju 450: <ul id="LC_secondary_menu">
1.253 kaisler 451: <li><a href="/adm/menu" target="_top">$lt{'main'}</a></li>
1.59 www 452: $reloadlink
1.55 www 453: $navmaps
1.151 www 454: $docs
1.165 raeburn 455: $groups
1.253 kaisler 456: $role_selector
1.263 droeschl 457: </ul>
1.168 albertel 458: $form
1.129 albertel 459: <script type="text/javascript">
1.48 www 460: // END LON-CAPA Internal
461: </script>
1.58 www 462: $reg
1.48 www 463: ENDINLINEMENU
464: } else {
465: return '';
466: }
1.72 www 467: }
468:
1.228 albertel 469: sub show_return_link {
470: return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
471: $env{'request.symb'} eq '')
472: ||
473: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
474: ||
475: (($env{'request.noversionuri'}=~/^\/adm\//) &&
476: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
477: ($env{'request.noversionuri'}!~
478: m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
479: ));
480: }
481:
1.38 www 482:
483: sub registerurl {
1.173 albertel 484: my ($forcereg) = @_;
1.38 www 485: my $result = '';
1.175 albertel 486: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.66 albertel 487: my $force_title='';
1.152 albertel 488: if ($env{'request.state'} eq 'construct') {
1.66 albertel 489: $force_title=&Apache::lonxml::display_title();
490: }
1.269 droeschl 491: if (($env{'environment.remote'} eq 'off') ||
1.152 albertel 492: ((($env{'request.publicaccess'}) ||
1.83 www 493: (!&Apache::lonnet::is_on_map(
1.183 www 494: &unescape($env{'request.noversionuri'})))) &&
1.38 www 495: (!$forcereg))) {
1.277 bisitz 496: return
497: $result
498: .'<script type="text/javascript">'."\n"
499: .'// <![CDATA['."\n"
500: .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
501: .'// ]]>'."\n"
502: .'</script>'
503: .$force_title;
1.38 www 504: }
1.41 www 505: # Graphical display after login only
1.174 albertel 506: if ($env{'request.registered'} && !$forcereg) { return ''; }
1.173 albertel 507: $result.=&innerregister($forcereg);
1.66 albertel 508: return $result.$force_title;
1.40 www 509: }
510:
511: sub innerregister {
1.173 albertel 512: my ($forcereg, $titletable) = @_;
1.40 www 513: my $result = '';
1.120 raeburn 514: my ($uname,$thisdisfn);
1.152 albertel 515: my $const_space = ($env{'request.state'} eq 'construct');
1.131 raeburn 516: my $is_const_dir = 0;
1.120 raeburn 517:
1.175 albertel 518: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40 www 519:
1.174 albertel 520: $env{'request.registered'} = 1;
1.40 www 521:
1.267 droeschl 522: my $noremote = ($env{'environment.remote'} eq 'off');
1.49 www 523:
1.177 albertel 524: undef(@inlineremote);
1.56 www 525:
1.38 www 526: my $reopen=&Apache::lonmenu::reopenmenu();
1.40 www 527:
1.38 www 528: my $newmail='';
1.267 droeschl 529:
530: if (&Apache::lonmsg::newmail() && !$noremote) {
531: # We have new mail and remote is up
532: $newmail= 'swmenu.setstatus("you have","messages");';
1.233 www 533: }
1.276 droeschl 534:
1.288 raeburn 535: my ($breadcrumb,$separator);
1.267 droeschl 536: if ($noremote
1.177 albertel 537: && ($env{'request.symb'})
538: && ($env{'request.course.id'})) {
1.267 droeschl 539:
540: my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
541: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
542:
543: my $maptitle = &Apache::lonnet::gettitle($mapurl);
544: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.289 raeburn 545: my @crumbs = ({text => "Course Contents",
546: href => "Javascript:gonav('/adm/navmaps')"});
547:
548: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
549: push(@crumbs, {text => '...',
550: no_mt => 1});
551: }
1.268 droeschl 552:
553: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
554: && $maptitle ne 'default.sequence'
555: && $maptitle ne $coursetitle);
556:
557: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
558:
1.291 raeburn 559: &Apache::lonhtmlcommon::clear_breadcrumbs();
560: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
561: $breadcrumb .= &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
1.288 raeburn 562: unless (($env{'request.state'} eq 'edit') || ($newmail) ||
563: ($env{'request.state'} eq 'construct') ||
564: ($env{'form.register'})) {
565: $separator = &Apache::loncommon::head_subbox();
566: }
1.267 droeschl 567: #
1.65 www 568: }
1.152 albertel 569: if ($env{'request.state'} eq 'construct') {
1.131 raeburn 570: $newmail = $titletable;
1.267 droeschl 571: }
572: my $timesync = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
573: my $tablestart = ( $noremote ? '<table id="LC_menubuttons">' : '');
574: my $tableend = ( $noremote ? '</table>' : '');
1.41 www 575: # =============================================================================
576: # ============================ This is for URLs that actually can be registered
1.152 albertel 577: if (($env{'request.noversionuri'}!~m|^/(res/)*adm/|) || ($forcereg)) {
1.40 www 578: # -- This applies to homework problems for users with grading privileges
1.152 albertel 579: my $crs='/'.$env{'request.course.id'};
580: if ($env{'request.course.sec'}) {
581: $crs.='_'.$env{'request.course.sec'};
1.107 albertel 582: }
583: $crs=~s/\_/\//g;
584:
1.38 www 585: my $hwkadd='';
1.152 albertel 586: if ($env{'request.symb'} ne '' &&
1.161 albertel 587: $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
1.79 www 588: if (&Apache::lonnet::allowed('mgr',$crs)) {
1.259 bisitz 589: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]',
1.40 www 590: "gocmd('/adm/grades','gradingmenu')",
591: 'Modify user grades for this assessment resource');
1.154 www 592: } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
593: $hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
594: "gocmd('/adm/grades','submission')",
595: 'View user submissions for this assessment resource');
1.38 www 596: }
1.107 albertel 597: }
1.152 albertel 598: if ($env{'request.symb'} ne '' &&
1.145 albertel 599: &Apache::lonnet::allowed('opa',$crs)) {
1.107 albertel 600: $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
601: "gocmd('/adm/parmset','set')",
1.196 www 602: 'Modify parameter settings for this resource');
1.38 www 603: }
1.40 www 604: # -- End Homework
1.38 www 605: ###
606: ### Determine whether or not to display the 'cstr' button for this
607: ### resource
608: ###
609: my $editbutton = '';
1.258 raeburn 610: my $noeditbutton = 1;
611: my ($cnum,$cdom);
612: if ($env{'request.course.id'}) {
613: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
614: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
615: }
1.152 albertel 616: if ($env{'user.author'}) {
1.234 raeburn 617: if ($env{'request.role'}=~/^(aa|ca|au)/) {
1.274 www 618: #
619: # We have the role of an author
620: #
1.38 www 621: # Set defaults for authors
622: my ($top,$bottom) = ('con-','struct');
1.152 albertel 623: my $action = "go('/priv/".$env{'user.name'}."');";
624: my $cadom = $env{'request.role.domain'};
625: my $caname = $env{'user.name'};
1.236 bisitz 626: my $desc = "Enter my construction space";
1.38 www 627: # Set defaults for co-authors
1.152 albertel 628: if ($env{'request.role'} =~ /^ca/) {
1.206 albertel 629: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.38 www 630: ($top,$bottom) = ('co con-','struct');
631: $action = "go('/priv/".$caname."');";
632: $desc = "Enter construction space as co-author";
1.234 raeburn 633: } elsif ($env{'request.role'} =~ /^aa/) {
634: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
635: ($top,$bottom) = ('co con-','struct');
636: $action = "go('/priv/".$caname."');";
637: $desc = "Enter construction space as assistant co-author";
1.38 www 638: }
639: # Check that we are on the correct machine
640: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 641: my $allowed=0;
642: my @ids=&Apache::lonnet::current_machine_ids();
643: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
644: if (!$allowed) {
645: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
1.258 raeburn 646: $noeditbutton = 0;
1.38 www 647: }
648: }
1.274 www 649: #
650: # We are an author for some stuff, but currently do not have the role of author.
651: # Figure out if we have authoring privileges for the resource we are looking at.
652: # This should maybe become a privilege check in lonnet
653: #
1.38 www 654: ##
655: ## Determine if user can edit url.
656: ##
657: my $cfile='';
658: my $cfuname='';
659: my $cfudom='';
1.258 raeburn 660: my $uploaded;
1.152 albertel 661: if ($env{'request.filename'}) {
662: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.258 raeburn 663: if (defined($cnum) && defined($cdom)) {
664: $uploaded = &is_course_upload($file,$cnum,$cdom);
665: }
666: if (!$uploaded) {
667: $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
668: # Check that the user has permission to edit this resource
669: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
670: if (defined($cfudom)) {
671: my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
672: my $allowed=0;
673: my @ids=&Apache::lonnet::current_machine_ids();
674: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
675: if ($allowed) {
676: $cfile=$file;
677: }
1.38 www 678: }
679: }
1.258 raeburn 680: }
1.38 www 681: # Finally, turn the button on or off
1.120 raeburn 682: if ($cfile && !$const_space) {
1.40 www 683: $editbutton=&switch
1.212 www 684: ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
1.38 www 685: "go('".$cfile."');","Edit this resource");
1.258 raeburn 686: $noeditbutton = 0;
1.38 www 687: } elsif ($editbutton eq '') {
1.191 www 688: $editbutton=&clear(6,1);
1.38 www 689: }
690: }
1.258 raeburn 691: if (($noeditbutton) && ($env{'request.filename'})) {
692: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
693: my $file=&Apache::lonnet::declutter($env{'request.filename'});
694: if (defined($cnum) && defined($cdom)) {
695: if (&is_course_upload($file,$cnum,$cdom)) {
696: my $cfile = &edit_course_upload($file,$cnum,$cdom);
697: if ($cfile) {
698: $editbutton=&switch
699: ('','',6,1,'pcstr.gif','edit[_1]',
700: 'resource[_2]',"go('".$cfile."');",
701: 'Edit this resource');
702: }
703: }
704: }
705: }
706: }
1.38 www 707: ###
708: ###
1.41 www 709: # Prepare the rest of the buttons
1.120 raeburn 710: my $menuitems;
711: if ($const_space) {
1.274 www 712: #
713: # We are in construction space
714: #
1.128 albertel 715: my ($uname,$thisdisfn) =
1.152 albertel 716: ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
1.121 raeburn 717: my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
1.131 raeburn 718: if ($currdir =~ m-/$-) {
719: $is_const_dir = 1;
720: } else {
1.267 droeschl 721: $currdir =~ s|[^/]+$||;
1.200 foxr 722: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208 albertel 723: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274 www 724: #
725: # Probably should be in mydesk.tab
726: #
1.131 raeburn 727: $menuitems=(<<ENDMENUITEMS);
1.208 albertel 728: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
1.200 foxr 729: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
1.259 bisitz 730: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
1.200 foxr 731: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
732: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
1.120 raeburn 733: ENDMENUITEMS
1.131 raeburn 734: }
1.203 foxr 735: } elsif ( defined($env{'request.course.id'}) &&
736: $env{'request.symb'} ne '' ) {
1.274 www 737: #
738: # We are in a course and looking at a registred URL
739: # Should probably be in mydesk.tab
740: #
1.120 raeburn 741: $menuitems=(<<ENDMENUITEMS);
1.41 www 742: c&3&1
1.209 www 743: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
744: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
1.77 www 745: c&6&3
746: c&8&1
747: c&8&2
1.106 www 748: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.209 www 749: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
1.41 www 750: ENDMENUITEMS
1.216 albertel 751:
1.243 tempelho 752: my $currentURL = &Apache::loncommon::get_symb();
753: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
754: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
755: $menuitems.="s&9&3&";
756: if(length($annotation) > 0){
757: $menuitems.="anot2.gif";
758: }else{
759: $menuitems.="anot.gif";
760: }
761: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
762: $menuitems.="Make notes and annotations about this resource&&1\n";
763:
1.279 raeburn 764: unless ($noremote) {
765: my $showreqcrs = &check_for_rcrs();
766: if ($showreqcrs) {
767: $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]".
768: "&go('/adm/requestcourse')&Course requests\n";
769: }
770: }
1.193 raeburn 771: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
1.216 albertel 772: if (!$env{'request.enc'}) {
773: $menuitems.=(<<ENDREALRES);
1.259 bisitz 774: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
1.216 albertel 775: ENDREALRES
776: }
1.120 raeburn 777: $menuitems.=(<<ENDREALRES);
1.106 www 778: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
779: 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
1.77 www 780: ENDREALRES
1.120 raeburn 781: }
782: }
1.203 foxr 783: if ($env{'request.uri'} =~ /^\/res/) {
784: $menuitems .= (<<ENDMENUITEMS);
785: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
786: ENDMENUITEMS
787: }
1.41 www 788: my $buttons='';
789: foreach (split(/\n/,$menuitems)) {
790: my ($command,@rest)=split(/\&/,$_);
1.220 raeburn 791: my $idx=10*$rest[0]+$rest[1];
792: if (&hidden_button_check() eq 'yes') {
793: if ($idx == 21 ||$idx == 23) {
794: $buttons.=&switch('','',@rest);
795: } else {
796: $buttons.=&clear(@rest);
797: }
798: } else {
799: if ($command eq 's') {
800: $buttons.=&switch('','',@rest);
801: } else {
802: $buttons.=&clear(@rest);
803: }
1.41 www 804: }
805: }
1.148 albertel 806:
1.267 droeschl 807: if ($noremote) {
1.148 albertel 808: my $addremote=0;
1.267 droeschl 809: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.148 albertel 810: my $inlinebuttons='';
811: if ($addremote) {
1.267 droeschl 812: # Registered, textual output
1.218 www 813: if ($env{'environment.icons'} eq 'iconsonly') {
1.220 raeburn 814: $inlinebuttons=(<<ENDARROWSINLINE);
1.218 www 815: <tr><td>
816: $inlineremote[21] $inlineremote[23]
1.220 raeburn 817: ENDARROWSINLINE
818: if (&hidden_button_check() ne 'yes') {
819: $inlinebuttons .= (<<ENDINLINEICONS);
1.218 www 820: $inlineremote[61] $inlineremote[63]
821: $inlineremote[71] $inlineremote[72] $inlineremote[73]
822: $inlineremote[81] $inlineremote[82] $inlineremote[83]
823: $inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
824: ENDINLINEICONS
1.220 raeburn 825: }
1.218 www 826: } else {
1.223 albertel 827: if ($inlineremote[21] ne '' || $inlineremote[23] ne '') {
828: $inlinebuttons=(<<ENDFIRSTLINE);
1.129 albertel 829: <tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr>
1.220 raeburn 830: ENDFIRSTLINE
1.223 albertel 831: }
1.220 raeburn 832: if (&hidden_button_check() ne 'yes') {
1.223 albertel 833: foreach my $row (6..9) {
834: if ($inlineremote[${row}.'1'] ne ''
835: || $inlineremote[$row.'2'] ne ''
836: || $inlineremote[$row.'3'] ne '') {
837: $inlinebuttons .= <<"ENDLINE";
838: <tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
839: ENDLINE
840: }
841: }
842: }
843: }
1.103 www 844: }
1.41 www 845: $result =(<<ENDREGTEXT);
1.129 albertel 846: <script type="text/javascript">
1.42 www 847: // BEGIN LON-CAPA Internal
848: </script>
1.41 www 849: $timesync
1.267 droeschl 850: $breadcrumb
1.58 www 851: $tablestart
1.56 www 852: $inlinebuttons
1.227 albertel 853: $tableend
1.224 albertel 854: $newmail
1.288 raeburn 855: $separator
1.129 albertel 856: <script type="text/javascript">
1.64 www 857: // END LON-CAPA Internal
1.42 www 858: </script>
859:
1.41 www 860: ENDREGTEXT
861: # Registered, graphical output
862: } else {
1.152 albertel 863: my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.183 www 864: $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
1.152 albertel 865: my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.113 albertel 866: my $navstatus=&get_nav_status();
1.140 albertel 867: my $clearcstr;
1.148 albertel 868:
1.152 albertel 869: if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1.41 www 870: $result = (<<ENDREGTHIS);
1.38 www 871:
1.129 albertel 872: <script type="text/javascript">
1.277 bisitz 873: // <![CDATA[
1.150 albertel 874: // BEGIN LON-CAPA Internal
1.42 www 875: var swmenu=null;
1.38 www 876:
877: function LONCAPAreg() {
878: swmenu=$reopen;
879: swmenu.clearTimeout(swmenu.menucltim);
880: $timesync
881: $newmail
1.41 www 882: $buttons
1.84 www 883: swmenu.currentURL="$requri";
1.85 www 884: swmenu.reloadURL=swmenu.currentURL+window.location.search;
1.125 albertel 885: swmenu.currentSymb="$cursymb";
886: swmenu.reloadSymb="$cursymb";
1.38 www 887: swmenu.currentStale=0;
1.113 albertel 888: $navstatus
1.38 www 889: $hwkadd
890: $editbutton
891: }
892:
893: function LONCAPAstale() {
894: swmenu=$reopen
895: swmenu.currentStale=1;
896: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
897: swmenu.switchbutton
898: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
899: }
900: swmenu.clearbut(7,2);
901: swmenu.clearbut(7,3);
902: swmenu.menucltim=swmenu.setTimeout(
903: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.140 albertel 904: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1.38 www 905: 2000);
906: }
907:
1.150 albertel 908: // END LON-CAPA Internal
1.277 bisitz 909: // ]]>
1.38 www 910: </script>
911: ENDREGTHIS
1.41 www 912: }
913: # =============================================================================
1.38 www 914: } else {
1.41 www 915: # ========================================== This can or will not be registered
1.267 droeschl 916: if ($noremote) {
1.269 droeschl 917: # Not registered
1.267 droeschl 918: $result= (<<ENDDONOTREGTEXT);
1.41 www 919: ENDDONOTREGTEXT
920: } else {
921: # Not registered, graphical
922: $result = (<<ENDDONOTREGTHIS);
1.38 www 923:
1.129 albertel 924: <script type="text/javascript">
1.277 bisitz 925: // <![CDATA[
1.38 www 926: // BEGIN LON-CAPA Internal
1.42 www 927: var swmenu=null;
1.38 www 928:
929: function LONCAPAreg() {
930: swmenu=$reopen
931: $timesync
932: swmenu.currentStale=1;
933: swmenu.clearbut(2,1);
934: swmenu.clearbut(2,3);
935: swmenu.clearbut(8,1);
936: swmenu.clearbut(8,2);
937: swmenu.clearbut(8,3);
938: if (swmenu.currentURL) {
939: swmenu.switchbutton
940: (3,1,'reload.gif','return','location','go(currentURL)');
941: } else {
942: swmenu.clearbut(3,1);
943: }
944: }
945:
946: function LONCAPAstale() {
947: }
948:
949: // END LON-CAPA Internal
1.277 bisitz 950: // ]]>
1.38 www 951: </script>
952: ENDDONOTREGTHIS
1.41 www 953: }
954: # =============================================================================
1.38 www 955: }
956: return $result;
957: }
958:
1.258 raeburn 959: sub is_course_upload {
960: my ($file,$cnum,$cdom) = @_;
961: my $uploadpath = &LONCAPA::propath($cdom,$cnum);
962: $uploadpath =~ s{^\/}{};
963: if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
964: ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
965: return 1;
966: }
967: return;
968: }
969:
970: sub edit_course_upload {
971: my ($file,$cnum,$cdom) = @_;
972: my $cfile;
973: if ($file =~/\.(htm|html|css|js|txt)$/) {
974: my $ext = $1;
975: my $url = &Apache::lonnet::hreflocation('',$file);
976: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
977: my @ids=&Apache::lonnet::current_machine_ids();
978: my $dest;
979: if ($home && grep(/^\Q$home\E$/,@ids)) {
980: $dest = $url.'?forceedit=1';
981: } else {
982: unless (&Apache::lonnet::get_locks()) {
983: $dest = '/adm/switchserver?otherserver='.
984: $home.'&role='.$env{'request.role'}.
985: '&url='.$url.'&forceedit=1';
986: }
987: }
988: if ($dest) {
989: $cfile = &HTML::Entities::encode($dest,'"<>&');
990: }
991: }
992: return $cfile;
993: }
994:
1.38 www 995: sub loadevents() {
1.152 albertel 996: if ($env{'request.state'} eq 'construct' ||
1.175 albertel 997: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38 www 998: return 'LONCAPAreg();';
999: }
1000:
1001: sub unloadevents() {
1.152 albertel 1002: if ($env{'request.state'} eq 'construct' ||
1.175 albertel 1003: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38 www 1004: return 'LONCAPAstale();';
1005: }
1.30 www 1006:
1.32 www 1007:
1008: sub startupremote {
1009: my ($lowerurl)=@_;
1.269 droeschl 1010: if ($env{'environment.remote'} eq 'off') {
1.34 www 1011: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
1012: }
1.49 www 1013: #
1014: # The Remote actually gets launched!
1015: #
1.32 www 1016: my $configmenu=&rawconfig();
1.183 www 1017: my $esclowerurl=&escape($lowerurl);
1.119 www 1018: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1.32 www 1019: return(<<ENDREMOTESTARTUP);
1.129 albertel 1020: <script type="text/javascript">
1.277 bisitz 1021: // <![CDATA[
1.118 albertel 1022: var timestart;
1.35 www 1023: function wheelswitch() {
1.118 albertel 1024: if (typeof(document.wheel) != 'undefined') {
1025: if (typeof(document.wheel.spin) != 'undefined') {
1026: var date=new Date();
1027: var waited=Math.round(30-((date.getTime()-timestart)/1000));
1028: document.wheel.spin.value=$message;
1029: }
1030: }
1.35 www 1031: if (window.status=='|') {
1032: window.status='/';
1033: } else {
1034: if (window.status=='/') {
1035: window.status='-';
1036: } else {
1037: if (window.status=='-') {
1038: window.status='\\\\';
1039: } else {
1040: if (window.status=='\\\\') { window.status='|'; }
1041: }
1042: }
1043: }
1044: }
1045:
1.32 www 1046: // ---------------------------------------------------------- The wait function
1047: var canceltim;
1048: function wait() {
1049: if ((menuloaded==1) || (tim==1)) {
1.35 www 1050: window.status='Done.';
1.32 www 1051: if (tim==0) {
1052: clearTimeout(canceltim);
1053: $configmenu
1054: window.location='$lowerurl';
1055: } else {
1.52 www 1056: window.location='/adm/remote?action=collapse&url=$esclowerurl';
1.32 www 1057: }
1058: } else {
1.35 www 1059: wheelswitch();
1060: setTimeout('wait();',200);
1.32 www 1061: }
1062: }
1063:
1064: function main() {
1.52 www 1065: canceltim=setTimeout('tim=1;',30000);
1.35 www 1066: window.status='-';
1.118 albertel 1067: var date=new Date();
1068: timestart=date.getTime();
1.32 www 1069: wait();
1070: }
1071:
1.277 bisitz 1072: // ]]>
1.32 www 1073: </script>
1074: ENDREMOTESTARTUP
1075: }
1076:
1077: sub setflags() {
1078: return(<<ENDSETFLAGS);
1.129 albertel 1079: <script type="text/javascript">
1.277 bisitz 1080: // <![CDATA[
1.32 www 1081: menuloaded=0;
1082: tim=0;
1.277 bisitz 1083: // ]]>
1.32 www 1084: </script>
1085: ENDSETFLAGS
1086: }
1087:
1088: sub maincall() {
1.269 droeschl 1089: if ($env{'environment.remote'} eq 'off') { return ''; }
1.32 www 1090: return(<<ENDMAINCALL);
1.129 albertel 1091: <script type="text/javascript">
1.277 bisitz 1092: // <![CDATA[
1.32 www 1093: main();
1.277 bisitz 1094: // ]]>
1.32 www 1095: </script>
1096: ENDMAINCALL
1097: }
1.118 albertel 1098:
1099: sub load_remote_msg {
1100: my ($lowerurl)=@_;
1101:
1.269 droeschl 1102: if ($env{'environment.remote'} eq 'off') { return ''; }
1.118 albertel 1103:
1.183 www 1104: my $esclowerurl=&escape($lowerurl);
1.261 bisitz 1105: my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
1106: ,'<a href="/adm/remote?action=collapse&url='.$esclowerurl.'">'
1107: ,'</a>');
1.118 albertel 1108: return(<<ENDREMOTEFORM);
1109: <p>
1110: <form name="wheel">
1.119 www 1111: <input name="spin" type="text" size="60" />
1.118 albertel 1112: </form>
1113: </p>
1114: <p>$link</p>
1115: ENDREMOTEFORM
1116: }
1.230 albertel 1117:
1118: sub get_menu_name {
1119: my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
1120: $hostid =~ s/\W//g;
1121: return 'LCmenu'.$hostid;
1122: }
1123:
1.30 www 1124:
1125: sub reopenmenu {
1.269 droeschl 1126: if ($env{'environment.remote'} eq 'off') { return ''; }
1.230 albertel 1127: my $menuname = &get_menu_name();
1.47 matthew 1128: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1129: return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30 www 1130: }
1131:
1.1 www 1132:
1133: sub open {
1.22 www 1134: my $returnval='';
1.269 droeschl 1135: if ($env{'environment.remote'} eq 'off') {
1.277 bisitz 1136: return
1137: '<script type="text/javascript">'."\n"
1138: .'// <![CDATA['."\n"
1139: .'self.name="loncapaclient";'."\n"
1140: .'// ]]>'."\n"
1141: .'</script>';
1.111 albertel 1142: }
1.230 albertel 1143: my $menuname = &get_menu_name();
1.222 albertel 1144:
1145: # unless (shift eq 'unix') {
1.22 www 1146: # resizing does not work on linux because of virtual desktop sizes
1.222 albertel 1147: # $returnval.=(<<ENDRESIZE);
1148: #if (window.screen) {
1149: # self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1150: # self.moveTo(190,15);
1151: #}
1152: #ENDRESIZE
1153: # }
1.277 bisitz 1154: $returnval=(<<ENDOPEN);
1155: // <![CDATA[
1.35 www 1156: window.status='Opening LON-CAPA Remote Control';
1.272 droeschl 1157: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
1.191 www 1158: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.71 www 1159: self.name='loncapaclient';
1.277 bisitz 1160: // ]]>
1.1 www 1161: ENDOPEN
1.129 albertel 1162: return '<script type="text/javascript">'.$returnval.'</script>';
1.1 www 1163: }
1164:
1.2 www 1165:
1166: # ================================================================== Raw Config
1167:
1.3 www 1168: sub clear {
1169: my ($row,$col)=@_;
1.269 droeschl 1170: unless ($env{'environment.remote'} eq 'off') {
1.275 www 1171: if (($row<1) || ($row>13)) { return ''; }
1.35 www 1172: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.56 www 1173: } else {
1174: $inlineremote[10*$row+$col]='';
1175: return '';
1176: }
1.3 www 1177: }
1178:
1.40 www 1179: # ============================================ Switch a button or create a link
1.25 matthew 1180: # Switch acts on the javascript that is executed when a button is clicked.
1181: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 1182:
1.2 www 1183: sub switch {
1.209 www 1184: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2 www 1185: $act=~s/\$uname/$uname/g;
1186: $act=~s/\$udom/$udom/g;
1.88 www 1187: $top=&mt($top);
1188: $bot=&mt($bot);
1189: $desc=&mt($desc);
1.238 www 1190: if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
1191: $img=&mt($img);
1192: }
1.209 www 1193: my $idx=10*$row+$col;
1194: $category_members{$cat}.=':'.$idx;
1195:
1.269 droeschl 1196: unless ($env{'environment.remote'} eq 'off') {
1.275 www 1197: if (($row<1) || ($row>13)) { return ''; }
1.50 www 1198: # Remote
1.34 www 1199: return "\n".
1.35 www 1200: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.34 www 1201: } else {
1.50 www 1202: # Inline Remote
1.213 www 1203: if ($env{'environment.icons'} ne 'classic') {
1204: $img=~s/\.gif$/\.png/;
1205: }
1.41 www 1206: if ($nobreak==2) { return ''; }
1.34 www 1207: my $text=$top.' '.$bot;
1.78 www 1208: $text=~s/\s*\-\s*//gs;
1.105 www 1209:
1.99 www 1210: my $pic=
1.225 albertel 1211: '<img alt="'.$text.'" src="'.
1212: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.250 harmsja 1213: '" align="'.($nobreak==3?'right':'left').'" class="LC_noBorder" />';
1.177 albertel 1214: if ($env{'browser.interface'} eq 'faketextual') {
1.274 www 1215: # Main Menu
1.103 www 1216: if ($nobreak==3) {
1.209 www 1217: $inlineremote[$idx]="\n".
1.177 albertel 1218: '<td class="LC_menubuttons_text" align="right">'.$text.
1.247 harmsja 1219: '</td><td align="left">'.
1.103 www 1220: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1221: } elsif ($nobreak) {
1.209 www 1222: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1223: '<td align="left">'.
1.177 albertel 1224: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215 www 1225: <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>';
1.103 www 1226: } else {
1.209 www 1227: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1228: '<td align="left">'.
1.103 www 1229: '<a href="javascript:'.$act.';">'.$pic.
1.177 albertel 1230: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215 www 1231: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103 www 1232: }
1.94 www 1233: } else {
1.103 www 1234: # Inline Menu
1.218 www 1235: if ($env{'environment.icons'} eq 'iconsonly') {
1236: $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
1237: } else {
1238: $inlineremote[$idx]=
1.215 www 1239: '<a class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1240: '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
1.218 www 1241: }
1.94 www 1242: }
1.34 www 1243: }
1.56 www 1244: return '';
1.2 www 1245: }
1246:
1247: sub secondlevel {
1248: my $output='';
1249: my
1.209 www 1250: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2 www 1251: if ($prt eq 'any') {
1.209 www 1252: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1253: } elsif ($prt=~/^r(\w+)/) {
1254: if ($rol eq $1) {
1.209 www 1255: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1256: }
1257: }
1258: return $output;
1259: }
1260:
1.18 www 1261: sub openmenu {
1.230 albertel 1262: my $menuname = &get_menu_name();
1.269 droeschl 1263: if ($env{'environment.remote'} eq 'off') { return ''; }
1.47 matthew 1264: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1265: return "window.open(".$nothing.",'".$menuname."');";
1.18 www 1266: }
1267:
1.56 www 1268: sub inlinemenu {
1.210 albertel 1269: undef(@inlineremote);
1270: undef(%category_members);
1.275 www 1271: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56 www 1272: &rawconfig(1);
1.214 albertel 1273: my $output='<table id="LC_mainmenu"><tr>';
1.209 www 1274: for (my $col=1; $col<=2; $col++) {
1.241 riegler 1275: $output.='<td class="LC_mainmenu_col_fieldset">';
1.209 www 1276: for (my $row=1; $row<=8; $row++) {
1277: foreach my $cat (keys(%category_members)) {
1278: if ($category_positions{$cat} ne "$col,$row") { next; }
1.247 harmsja 1279: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.270 bisitz 1280: $output.='<div class="LC_Box">';
1.250 harmsja 1281: $output.='<h4 class="LC_hcell">'.&mt($category_names{$cat}).'</h4>';
1.247 harmsja 1282: $output.='<table>';
1.240 riegler 1283: my %active=();
1284: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1285: if ($inlineremote[$menu_item]) {
1286: $active{$menu_item}=1;
1287: }
1288: }
1289: foreach my $item (sort(keys(%active))) {
1290: $output.=$inlineremote[$item];
1291: }
1292: $output.='</table>';
1.245 harmsja 1293: $output.='</div>';
1.240 riegler 1294: }
1295: }
1296: $output.="</td>";
1297: }
1298: $output.="</tr></table>";
1299: return $output;
1300: }
1301:
1.2 www 1302: sub rawconfig {
1.274 www 1303: #
1304: # This evaluates mydesk.tab
1305: # Need to add more positions and more privileges to deal with all
1306: # menu items.
1307: #
1.34 www 1308: my $textualoverride=shift;
1309: my $output='';
1.269 droeschl 1310: unless ($env{'environment.remote'} eq 'off') {
1.35 www 1311: $output.=
1312: "window.status='Opening Remote Control';var swmenu=".&openmenu().
1313: "\nwindow.status='Configuring Remote Control ';";
1.34 www 1314: } else {
1315: unless ($textualoverride) { return ''; }
1316: }
1.152 albertel 1317: my $uname=$env{'user.name'};
1318: my $udom=$env{'user.domain'};
1319: my $adv=$env{'user.adv'};
1.266 raeburn 1320: my $show_course=&Apache::loncommon::show_course();
1.152 albertel 1321: my $author=$env{'user.author'};
1.5 www 1322: my $crs='';
1.152 albertel 1323: if ($env{'request.course.id'}) {
1324: $crs='/'.$env{'request.course.id'};
1325: if ($env{'request.course.sec'}) {
1326: $crs.='_'.$env{'request.course.sec'};
1.7 www 1327: }
1.8 www 1328: $crs=~s/\_/\//g;
1.5 www 1329: }
1.152 albertel 1330: my $pub=($env{'request.state'} eq 'published');
1331: my $con=($env{'request.state'} eq 'construct');
1332: my $rol=$env{'request.role'};
1333: my $requested_domain = $env{'request.role.domain'};
1.184 raeburn 1334: foreach my $line (@desklines) {
1.209 www 1335: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3 www 1336: $prt=~s/\$uname/$uname/g;
1337: $prt=~s/\$udom/$udom/g;
1.5 www 1338: $prt=~s/\$crs/$crs/g;
1.25 matthew 1339: $prt=~s/\$requested_domain/$requested_domain/g;
1.211 www 1340: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.186 albertel 1341: my $type = &Apache::loncommon::course_type();
1.3 www 1342: if ($pro eq 'clear') {
1.4 www 1343: $output.=&clear($row,$col);
1.3 www 1344: } elsif ($pro eq 'any') {
1.2 www 1345: $output.=&secondlevel(
1.209 www 1346: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1347: } elsif ($pro eq 'smp') {
1348: unless ($adv) {
1349: $output.=&secondlevel(
1.209 www 1350: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1351: }
1352: } elsif ($pro eq 'adv') {
1353: if ($adv) {
1354: $output.=&secondlevel(
1.209 www 1355: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1356: }
1.231 albertel 1357: } elsif ($pro eq 'shc') {
1358: if ($show_course) {
1359: $output.=&secondlevel(
1360: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1361: }
1362: } elsif ($pro eq 'nsc') {
1363: if (!$show_course) {
1364: $output.=&secondlevel(
1365: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1366: }
1.81 matthew 1367: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.2 www 1368: if (&Apache::lonnet::allowed($1,$prt)) {
1.209 www 1369: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4 www 1370: }
1.26 www 1371: } elsif ($pro eq 'course') {
1.152 albertel 1372: if ($env{'request.course.fn'}) {
1.209 www 1373: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81 matthew 1374: }
1.124 matthew 1375: } elsif ($pro =~ /^courseenv_(.*)$/) {
1376: my $key = $1;
1.152 albertel 1377: if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
1.209 www 1378: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.124 matthew 1379: }
1.81 matthew 1380: } elsif ($pro =~ /^course_(.*)$/) {
1381: # Check for permissions inside of a course
1.152 albertel 1382: if (($env{'request.course.id'}) &&
1383: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1384: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81 matthew 1385: )) {
1.209 www 1386: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26 www 1387: }
1.4 www 1388: } elsif ($pro eq 'author') {
1389: if ($author) {
1.152 albertel 1390: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234 raeburn 1391: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1.152 albertel 1392: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19 matthew 1393: # Check that we are on the correct machine
1.29 matthew 1394: my $cadom=$requested_domain;
1.152 albertel 1395: my $caname=$env{'user.name'};
1.234 raeburn 1396: if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29 matthew 1397: ($cadom,$caname)=
1.206 albertel 1398: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29 matthew 1399: }
1400: $act =~ s/\$caname/$caname/g;
1.19 matthew 1401: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 1402: my $allowed=0;
1403: my @ids=&Apache::lonnet::current_machine_ids();
1404: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1405: if ($allowed) {
1.209 www 1406: $output.=&switch($caname,$cadom,
1407: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19 matthew 1408: }
1.6 www 1409: }
1.2 www 1410: }
1.248 raeburn 1411: } elsif ($pro eq 'tools') {
1412: my @tools = ('aboutme','blog','portfolio');
1413: if (grep(/^\Q$prt\E$/,@tools)) {
1.249 raeburn 1414: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251 raeburn 1415: $env{'user.domain'},
1416: $prt,undef,'tools')) {
1417: $output.=&clear($row,$col);
1418: next;
1419: }
1.278 raeburn 1420: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1421: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1422: next;
1423: }
1424: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1425: next;
1426: }
1.279 raeburn 1427: my $showreqcrs = &check_for_rcrs();
1.251 raeburn 1428: if (!$showreqcrs) {
1.248 raeburn 1429: $output.=&clear($row,$col);
1430: next;
1431: }
1432: }
1433: $prt='any';
1434: $output.=&secondlevel(
1435: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1436: }
1.13 harris41 1437: }
1.269 droeschl 1438: unless ($env{'environment.remote'} eq 'off') {
1.35 www 1439: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.123 www 1440: if (&Apache::lonmsg::newmail()) {
1441: $output.='swmenu.setstatus("you have","messages");';
1442: }
1.34 www 1443: }
1.123 www 1444:
1.2 www 1445: return $output;
1446: }
1447:
1.279 raeburn 1448: sub check_for_rcrs {
1449: my $showreqcrs = 0;
1.280 raeburn 1450: my @reqtypes = ('official','unofficial','community');
1451: foreach my $type (@reqtypes) {
1.279 raeburn 1452: if (&Apache::lonnet::usertools_access($env{'user.name'},
1453: $env{'user.domain'},
1454: $type,undef,'requestcourses')) {
1455: $showreqcrs = 1;
1456: last;
1457: }
1458: }
1.280 raeburn 1459: if (!$showreqcrs) {
1460: foreach my $type (@reqtypes) {
1461: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1462: $showreqcrs = 1;
1463: last;
1464: }
1465: }
1466: }
1.279 raeburn 1467: return $showreqcrs;
1468: }
1469:
1.2 www 1470: # ======================================================================= Close
1.1 www 1471:
1472: sub close {
1.269 droeschl 1473: if ($env{'environment.remote'} eq 'off') { return ''; }
1.230 albertel 1474: my $menuname = &get_menu_name();
1.1 www 1475: return(<<ENDCLOSE);
1.129 albertel 1476: <script type="text/javascript">
1.277 bisitz 1477: // <![CDATA[
1.35 www 1478: window.status='Accessing Remote Control';
1.30 www 1479: menu=window.open("/adm/rat/empty.html","$menuname",
1.1 www 1480: "height=350,width=150,scrollbars=no,menubar=no");
1.35 www 1481: window.status='Disabling Remote Control';
1482: menu.active=0;
1.31 www 1483: menu.autologout=0;
1.35 www 1484: window.status='Closing Remote Control';
1.1 www 1485: menu.close();
1.35 www 1486: window.status='Done.';
1.277 bisitz 1487: // ]]>
1.1 www 1488: </script>
1489: ENDCLOSE
1490: }
1491:
1492: # ====================================================================== Footer
1493:
1494: sub footer {
1495:
1.33 www 1496: }
1497:
1.122 albertel 1498: sub nav_control_js {
1.152 albertel 1499: my $nav=($env{'environment.remotenavmap'} eq 'on');
1.122 albertel 1500: return (<<NAVCONTROL);
1501: var w_loncapanav_flag="$nav";
1502:
1503:
1504: function gonav(url) {
1505: if (w_loncapanav_flag != 1) {
1506: gopost(url,'');
1507: } else {
1508: navwindow=window.open(url,
1509: "loncapanav","height=600,width=400,scrollbars=1");
1510: }
1511: }
1512: NAVCONTROL
1513: }
1514:
1.42 www 1515: sub utilityfunctions {
1.132 raeburn 1516: my $caller = shift;
1.269 droeschl 1517: unless ($env{'environment.remote'} eq 'off' ||
1518: $caller eq '/adm/menu') {
1519: return ''; }
1520:
1.152 albertel 1521: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.293 ! raeburn 1522: if ($currenturl =~ m{^/adm/wrapper/ext/}) {
! 1523: if ($env{'request.external.querystring'}) {
! 1524: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
! 1525: }
! 1526: }
1.183 www 1527: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125 albertel 1528:
1.152 albertel 1529: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.122 albertel 1530: my $nav_control=&nav_control_js();
1.175 albertel 1531:
1532: my $start_page_annotate =
1533: &Apache::loncommon::start_page('Annotator',undef,
1534: {'only_body' => 1,
1535: 'js_ready' => 1,
1536: 'bgcolor' => '#BBBBBB',
1537: 'add_entries' => {
1538: 'onload' => 'javascript:document.goannotate.submit();'}});
1539:
1.205 albertel 1540: my $end_page_annotate =
1541: &Apache::loncommon::end_page({'js_ready' => 1});
1542:
1.175 albertel 1543: my $start_page_bookmark =
1544: &Apache::loncommon::start_page('Bookmarks',undef,
1545: {'only_body' => 1,
1546: 'js_ready' => 1,
1547: 'bgcolor' => '#BBBBBB',});
1548:
1.205 albertel 1549: my $end_page_bookmark =
1.175 albertel 1550: &Apache::loncommon::end_page({'js_ready' => 1});
1551:
1.42 www 1552: return (<<ENDUTILITY)
1553:
1554: var currentURL="$currenturl";
1555: var reloadURL="$currenturl";
1556: var currentSymb="$currentsymb";
1557:
1.114 albertel 1558: $nav_control
1559:
1.42 www 1560: function go(url) {
1561: if (url!='' && url!= null) {
1562: currentURL = null;
1563: currentSymb= null;
1564: window.location.href=url;
1565: }
1566: }
1567:
1568: function gopost(url,postdata) {
1569: if (url!='') {
1570: this.document.server.action=url;
1571: this.document.server.postdata.value=postdata;
1572: this.document.server.command.value='';
1573: this.document.server.url.value='';
1574: this.document.server.symb.value='';
1575: this.document.server.submit();
1576: }
1577: }
1578:
1579: function gocmd(url,cmd) {
1580: if (url!='') {
1581: this.document.server.action=url;
1582: this.document.server.postdata.value='';
1583: this.document.server.command.value=cmd;
1584: this.document.server.url.value=currentURL;
1585: this.document.server.symb.value=currentSymb;
1586: this.document.server.submit();
1587: }
1.57 www 1588: }
1589:
1.121 raeburn 1590: function gocstr(url,filename) {
1591: if (url == '/adm/cfile?action=delete') {
1592: this.document.cstrdelete.filename.value = filename
1593: this.document.cstrdelete.submit();
1594: return;
1595: }
1.137 raeburn 1596: if (url == '/adm/printout') {
1597: this.document.cstrprint.postdata.value = filename
1598: this.document.cstrprint.curseed.value = 0;
1599: this.document.cstrprint.problemtype.value = 0;
1.138 raeburn 1600: if (this.document.lonhomework) {
1601: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1602: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1603: }
1604: if (this.document.lonhomework.problemtype) {
1.164 albertel 1605: if (this.document.lonhomework.problemtype.value) {
1606: this.document.cstrprint.problemtype.value =
1607: this.document.lonhomework.problemtype.value;
1608: } else if (this.document.lonhomework.problemtype.options) {
1609: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1610: if (this.document.lonhomework.problemtype.options[i].selected) {
1611: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1612: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1613: }
1614: }
1615: }
1616: }
1617: }
1618: }
1.137 raeburn 1619: this.document.cstrprint.submit();
1620: return;
1621: }
1.121 raeburn 1622: if (url !='') {
1623: this.document.constspace.filename.value = filename;
1624: this.document.constspace.action = url;
1625: this.document.constspace.submit();
1626: }
1627: }
1628:
1.131 raeburn 1629: function golist(url) {
1630: if (url!='' && url!= null) {
1631: currentURL = null;
1632: currentSymb= null;
1633: top.location.href=url;
1634: }
1635: }
1636:
1637:
1.121 raeburn 1638:
1.57 www 1639: function catalog_info() {
1.102 albertel 1640: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.57 www 1641: }
1642:
1643: function chat_win() {
1.290 raeburn 1644: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42 www 1645: }
1.169 raeburn 1646:
1647: function group_chat(group) {
1648: var url = '/adm/groupchat?group='+group;
1649: var winName = 'LONchat_'+group;
1650: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1651: }
1.175 albertel 1652:
1653: function edit_bookmarks() {
1654: go('');
1655: w_BookmarkPal_flag=1;
1656: bookmarkpal=window.open("/adm/bookmarks",
1657: "BookmarkPal", "width=400,height=505,scrollbars=0");
1658: }
1659:
1660: function annotate() {
1661: w_Annotator_flag=1;
1662: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1663: annotator.document.write(
1664: '$start_page_annotate'
1665: +"<form name='goannotate' target='Annotator' method='post' "
1666: +"action='/adm/annotations'>"
1.217 albertel 1667: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181 albertel 1668: +"<\\/form>"
1.205 albertel 1669: +'$end_page_annotate');
1.175 albertel 1670: annotator.document.close();
1671: }
1672:
1673: function set_bookmark() {
1674: go('');
1675: clienttitle=document.title;
1676: clienthref=location.pathname;
1677: w_bmquery_flag=1;
1678: bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
1679: bmquery.document.write(
1680: '$start_page_bookmark'
1.260 bisitz 1681: +'<center><form method="post"'
1682: +' name="newlink" action="/adm/bookmarks" target="bmquery" '
1683: +'> <table width="340" height="150" '
1684: +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
1685: +'type="text" name="title" size="45" value="'+clienttitle+'" />'
1686: +'<br />Address:<br /><input type="text" name="address" size="45" '
1687: +'value="'+clienthref+'" /><br /><center><input type="submit" '
1688: +'value="Save" /> <input type="button" value="Close" '
1689: +'onclick="javascript:window.close();" /></center></td>'
1690: +'</tr></table></form></center>'
1.205 albertel 1691: +'$end_page_bookmark' );
1.175 albertel 1692: bmquery.document.close();
1693: }
1694:
1.42 www 1695: ENDUTILITY
1696: }
1697:
1698: sub serverform {
1699: return(<<ENDSERVERFORM);
1.181 albertel 1700: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 1701: <input type="hidden" name="postdata" value="none" />
1702: <input type="hidden" name="command" value="none" />
1703: <input type="hidden" name="url" value="none" />
1704: <input type="hidden" name="symb" value="none" />
1705: </form>
1706: ENDSERVERFORM
1707: }
1.113 albertel 1708:
1.121 raeburn 1709: sub constspaceform {
1710: return(<<ENDCONSTSPACEFORM);
1.181 albertel 1711: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121 raeburn 1712: <input type="hidden" name="filename" value="" />
1713: </form>
1.181 albertel 1714: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121 raeburn 1715: <input type="hidden" name="action" value="delete" />
1716: <input type="hidden" name="filename" value="" />
1717: </form>
1.181 albertel 1718: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137 raeburn 1719: <input type="hidden" name="postdata" value="" />
1720: <input type="hidden" name="curseed" value="" />
1721: <input type="hidden" name="problemtype" value="" />
1722: </form>
1723:
1.121 raeburn 1724: ENDCONSTSPACEFORM
1725: }
1726:
1727:
1.113 albertel 1728: sub get_nav_status {
1729: my $navstatus="swmenu.w_loncapanav_flag=";
1.152 albertel 1730: if ($env{'environment.remotenavmap'} eq 'on') {
1.113 albertel 1731: $navstatus.="1";
1732: } else {
1733: $navstatus.="-1";
1734: }
1735: return $navstatus;
1736: }
1737:
1.220 raeburn 1738: sub hidden_button_check {
1739: my $hidden;
1740: if ($env{'request.course.id'} eq '') {
1741: return;
1742: }
1743: if ($env{'request.role.adv'}) {
1744: return;
1745: }
1.232 raeburn 1746: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1747: return $buttonshide;
1.220 raeburn 1748: }
1.184 raeburn 1749:
1.235 raeburn 1750: sub roles_selector {
1751: my ($cdom,$cnum) = @_;
1.286 raeburn 1752: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
1753: if ($crstype eq '') {
1754: $crstype = 'Course';
1755: }
1.235 raeburn 1756: my $now = time;
1.262 raeburn 1757: my (%courseroles,%seccount);
1.235 raeburn 1758: my $is_cc;
1759: my $role_selector;
1760: if ($env{'user.role.cc./'.$cdom.'/'.$cnum}) {
1761: my ($start,$end) = split(/\./,$env{'user.role.cc./'.$cdom.'/'.$cnum});
1762:
1763: if ((($start) && ($start<0)) ||
1764: (($end) && ($end<$now)) ||
1765: (($start) && ($now<$start))) {
1766: $is_cc = 0;
1767: } else {
1768: $is_cc = 1;
1769: }
1770: }
1771: if ($is_cc) {
1.264 raeburn 1772: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
1.235 raeburn 1773: } else {
1.262 raeburn 1774: my %gotnosection;
1.235 raeburn 1775: foreach my $item (keys(%env)) {
1.239 raeburn 1776: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235 raeburn 1777: my $role = $1;
1778: my $sec = $2;
1779: next if ($role eq 'gr');
1780: my ($start,$end) = split(/\./,$env{$item});
1781: next if (($start && $start > $now) || ($end && $end < $now));
1782: if ($sec eq '') {
1.239 raeburn 1783: if (!$gotnosection{$role}) {
1784: $seccount{$role} ++;
1785: $gotnosection{$role} = 1;
1786: }
1.235 raeburn 1787: }
1788: if (ref($courseroles{$role}) eq 'ARRAY') {
1.239 raeburn 1789: if ($sec ne '') {
1.264 raeburn 1790: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239 raeburn 1791: push(@{$courseroles{$role}},$sec);
1792: $seccount{$role} ++;
1793: }
1794: }
1795: } else {
1796: @{$courseroles{$role}} = ();
1797: if ($sec ne '') {
1798: $seccount{$role} ++;
1.235 raeburn 1799: push(@{$courseroles{$role}},$sec);
1800: }
1801: }
1802: }
1803: }
1804: }
1.286 raeburn 1805: my $switchtext;
1806: if ($crstype eq 'Community') {
1807: $switchtext = &mt('Switch community role to...')
1808: } else {
1809: $switchtext = &mt('Switch course role to...')
1810: }
1.235 raeburn 1811: my @roles_order = ('cc','in','ta','ep','ad','st');
1812: if (keys(%courseroles) > 1) {
1.239 raeburn 1813: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
1.235 raeburn 1814: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
1815: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1.286 raeburn 1816: $role_selector .= '<option value="">'.$switchtext.'</option>';
1.235 raeburn 1817: foreach my $role (@roles_order) {
1818: if (defined($courseroles{$role})) {
1819: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1820: }
1821: }
1822: foreach my $role (sort(keys(%courseroles))) {
1823: if ($role =~ /^cr/) {
1824: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1825: }
1826: }
1827: $role_selector .= '</select>'."\n".
1828: '<input type="hidden" name="destinationurl" value="'.
1.282 amueller 1829: &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n".
1.235 raeburn 1830: '<input type="hidden" name="gotorole" value="1" />'."\n".
1831: '<input type="hidden" name="selectrole" value="" />'."\n".
1832: '<input type="hidden" name="switch" value="1" />'."\n".
1833: '</form>';
1834: }
1835: return $role_selector;
1836: }
1837:
1.262 raeburn 1838: sub get_all_courseroles {
1839: my ($cdom,$cnum,$courseroles,$seccount) = @_;
1840: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
1841: return;
1842: }
1843: my ($result,$cached) =
1844: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1845: if (defined($cached)) {
1846: if (ref($result) eq 'HASH') {
1847: if ((ref($result->{'roles'}) eq 'HASH') &&
1848: (ref($result->{'seccount'}) eq 'HASH')) {
1849: %{$courseroles} = %{$result->{'roles'}};
1850: %{$seccount} = %{$result->{'seccount'}};
1851: return;
1852: }
1853: }
1854: }
1855: my %gotnosection;
1856: my %adv_roles =
1857: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1858: foreach my $role (keys(%adv_roles)) {
1859: my ($urole,$usec) = split(/:/,$role);
1860: if (!$gotnosection{$urole}) {
1861: $seccount->{$urole} ++;
1862: $gotnosection{$urole} = 1;
1863: }
1864: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1865: if ($usec ne '') {
1866: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1867: push(@{$courseroles->{$urole}},$usec);
1868: $seccount->{$urole} ++;
1869: }
1870: }
1871: } else {
1872: @{$courseroles->{$urole}} = ();
1873: if ($usec ne '') {
1874: $seccount->{$urole} ++;
1875: push(@{$courseroles->{$urole}},$usec);
1876: }
1877: }
1878: }
1879: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1880: @{$courseroles->{'st'}} = ();
1881: if (keys(%sections_count) > 0) {
1882: push(@{$courseroles->{'st'}},keys(%sections_count));
1883: $seccount->{'st'} = scalar(keys(%sections_count));
1884: }
1885: my $rolehash = {
1886: 'roles' => $courseroles,
1887: 'seccount' => $seccount,
1888: };
1889: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1890: return;
1891: }
1892:
1.235 raeburn 1893: sub jump_to_role {
1.239 raeburn 1894: my ($cdom,$cnum,$seccount,$courseroles) = @_;
1895: my %lt = &Apache::lonlocal::texthash(
1896: this => 'This role has section(s) associated with it.',
1897: ente => 'Enter a specific section.',
1898: orlb => 'Enter a specific section, or leave blank for no section.',
1899: avai => 'Available sections are:',
1900: youe => 'You entered an invalid section choice:',
1901: plst => 'Please try again',
1902: );
1903: my $js;
1904: if (ref($courseroles) eq 'HASH') {
1905: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1906: ' var numsec = new Array();'."\n".
1907: ' var rolesections = new Array();'."\n".
1908: ' var rolenames = new Array();'."\n".
1909: ' var roleseclist = new Array();'."\n";
1910: my @items = keys(%{$courseroles});
1911: for (my $i=0; $i<@items; $i++) {
1912: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1913: my ($secs,$secstr);
1914: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1915: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1916: $secs = join('","',@sections);
1917: $secstr = join(', ',@sections);
1918: }
1919: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1920: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1921: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1922: }
1923: }
1.273 droeschl 1924: return <<"END";
1.235 raeburn 1925: <script type="text/javascript">
1.273 droeschl 1926: //<![CDATA[
1.235 raeburn 1927: function adhocRole(roleitem) {
1.239 raeburn 1928: $js
1.235 raeburn 1929: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
1930: if (newrole == '') {
1931: return;
1932: }
1.239 raeburn 1933: var fullrole = newrole+'./$cdom/$cnum';
1934: var selidx = '';
1935: for (var i=0; i<rolenames.length; i++) {
1936: if (rolenames[i] == newrole) {
1937: selidx = i;
1938: }
1939: }
1940: var secok = 1;
1941: var secchoice = '';
1942: if (selidx >= 0) {
1943: if (numsec[selidx] > 1) {
1944: secok = 0;
1945: var numrolesec = rolesections[selidx].length;
1946: var msgidx = numsec[selidx] - numrolesec;
1947: secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1948: if (secchoice == '') {
1949: if (msgidx > 0) {
1950: secok = 1;
1951: }
1952: } else {
1953: for (var j=0; j<rolesections[selidx].length; j++) {
1954: if (rolesections[selidx][j] == secchoice) {
1955: secok = 1;
1956: }
1957: }
1958: }
1959: } else {
1960: if (rolesections[selidx].length == 1) {
1961: secchoice = rolesections[selidx][0];
1962: }
1963: }
1964: }
1965: if (secok == 1) {
1966: if (secchoice != '') {
1967: fullrole += '/'+secchoice;
1968: }
1969: } else {
1970: document.rolechooser.elements[roleitem].selectedIndex = 0;
1971: if (secchoice != null) {
1972: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
1973: }
1974: return;
1975: }
1976: if (fullrole == "$env{'request.role'}") {
1.235 raeburn 1977: return;
1978: }
1979: itemid = retrieveIndex('gotorole');
1980: if (itemid != -1) {
1.239 raeburn 1981: document.rolechooser.elements[itemid].name = fullrole;
1.235 raeburn 1982: }
1.239 raeburn 1983: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1.235 raeburn 1984: document.rolechooser.selectrole.value = '1';
1985: document.rolechooser.submit();
1986: return;
1987: }
1988:
1989: function retrieveIndex(item) {
1990: for (var i=0;i<document.rolechooser.elements.length;i++) {
1991: if (document.rolechooser.elements[i].name == item) {
1992: return i;
1993: }
1994: }
1995: return -1;
1996: }
1.273 droeschl 1997: // ]]>
1.235 raeburn 1998: </script>
1999: END
2000: }
2001:
2002:
1.2 www 2003: # ================================================================ Main Program
2004:
1.16 harris41 2005: BEGIN {
1.166 albertel 2006: if (! defined($readdesk)) {
1.283 droeschl 2007: {
2008: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
2009: if ( CORE::open( my $config,"<$tabfile") ) {
2010: while (my $configline=<$config>) {
2011: $configline=(split(/\#/,$configline))[0];
2012: $configline=~s/^\s+//;
2013: chomp($configline);
1.209 www 2014: if ($configline=~/^cat\:/) {
1.283 droeschl 2015: my @entries=split(/\:/,$configline);
2016: $category_positions{$entries[2]}=$entries[1];
2017: $category_names{$entries[2]}=$entries[3];
2018: } elsif ($configline=~/^prim\:/) {
2019: my @entries = (split(/\:/, $configline))[1..5];
2020: push @primary_menu, \@entries;
2021: } elsif ($configline=~/^scnd\:/) {
2022: my @entries = (split(/\:/, $configline))[1..5];
2023: push @secondary_menu, \@entries;
2024: } elsif ($configline) {
2025: push(@desklines,$configline);
2026: }
2027: }
2028: CORE::close($config);
2029: }
2030: }
2031: $readdesk='done';
1.2 www 2032: }
2033: }
1.30 www 2034:
1.1 www 2035: 1;
2036: __END__
2037:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>