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