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