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