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