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