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