1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.315.2.2 2010/08/14 21:38:08 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 GLOBAL VARIABLES
46:
47: =over
48:
49: =item @desklines
50:
51: Each element of this array contains a line of mydesk.tab that doesn't start with
52: cat, prim or scnd.
53: It gets filled in the BEGIN block of this module.
54:
55: =item %category_names
56:
57: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
58: start with cat, the values are strings representing titles.
59: It gets filled in the BEGIN block of this module.
60:
61: =item %category_members
62:
63: TODO
64:
65: =item %category_positions
66:
67: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
68: start with cat, its values are position vectors (column, row).
69: It gets filled in the BEGIN block of this module.
70:
71: =item $readdesk
72:
73: Indicates that mydesk.tab has been read.
74: It is set to 'done' in the BEGIN block of this module.
75:
76: =item @primary_menu
77:
78: The elements of this array reference arrays that are made up of the components
79: of those lines of mydesk.tab that start with prim.
80: It is used by primary_menu() to generate the corresponding menu.
81: It gets filled in the BEGIN block of this module.
82:
83: =item @secondary_menu
84:
85: The elements of this array reference arrays that are made up of the components
86: of those lines of mydesk.tab that start with scnd.
87: It is used by secondary_menu() to generate the corresponding menu.
88: It gets filled in the BEGIN block of this module.
89:
90: =back
91:
92: =head1 SUBROUTINES
93:
94: =over
95:
96: =item prep_menuitems(\@menuitem)
97:
98: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
99: secondary_menu().
100:
101: =item primary_menu()
102:
103: This routine evaluates @primary_menu and returns XHTML for the menu
104: that contains following links: About, Message, Roles, Help, Logout
105: @primary_menu is filled within the BEGIN block of this module with
106: entries from mydesk.tab
107:
108: =item secondary_menu()
109:
110: Same as primary_menu() but operates on @secondary_menu.
111:
112: =item show_return_link()
113:
114: =item registerurl()
115:
116: This gets called in the header section
117:
118: =item innerregister()
119:
120: This gets called in order to register a URL, both with the Remote
121: and in the body of the document
122:
123: =item loadevents()
124:
125: =item unloadevents()
126:
127: =item startupremote()
128:
129: =item setflags()
130:
131: =item maincall()
132:
133: =item load_remote_msg()
134:
135: =item get_menu_name()
136:
137: =item reopenmenu()
138:
139: =item open()
140:
141: Open the menu
142:
143: =item clear()
144:
145: =item switch()
146:
147: Switch a button or create a link
148: Switch acts on the javascript that is executed when a button is clicked.
149: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
150:
151: =item secondlevel()
152:
153: =item openmenu()
154:
155: =item inlinemenu()
156:
157: =item rawconfig()
158:
159: =item close()
160:
161: =item footer()
162:
163: =item utilityfunctions()
164:
165: =item serverform()
166:
167: =item constspaceform()
168:
169: =item get_nav_status()
170:
171: =item hidden_button_check()
172:
173: =item roles_selector()
174:
175: =item jump_to_role()
176:
177: =back
178:
179: =cut
180:
181: package Apache::lonmenu;
182:
183: use strict;
184: use Apache::lonnet;
185: use Apache::lonhtmlcommon();
186: use Apache::loncommon();
187: use Apache::lonenc();
188: use Apache::lonlocal;
189: use LONCAPA qw(:DEFAULT :match);
190: use HTML::Entities();
191:
192: use vars qw(@desklines %category_names %category_members %category_positions
193: $readdesk @primary_menu @secondary_menu);
194:
195: my @inlineremote;
196:
197: sub prep_menuitem {
198: my ($menuitem) = @_;
199: return '' unless(ref($menuitem) eq 'ARRAY');
200: my $link;
201: if ($$menuitem[1]) { # graphical Link
202: $link = "<img class=\"LC_noBorder\""
203: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
204: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
205: } else { # textual Link
206: $link = &mt($$menuitem[3]);
207: }
208: if($$menuitem[4] eq 'newmsg'){ #special style for New Messages
209: return '<li><a href="'.$$menuitem[0].'"><span class="LC_new_message">'.$link.'</span></a></li>';
210: }
211: return '<li><a href="'.$$menuitem[0].'">'.$link.'</a></li>';
212: }
213:
214: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
215: # that contains following links:
216: # About, Message, Roles, Help, Logout
217: # @primary_menu is filled within the BEGIN block of this module with
218: # entries from mydesk.tab
219: sub primary_menu {
220: my $menu;
221: # each element of @primary contains following array:
222: # (link url, icon path, alt text, link text, condition)
223: my $public;
224: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
225: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
226: $public = 1;
227: }
228: foreach my $menuitem (@primary_menu) {
229: # evaluate conditions
230: next if ref($menuitem) ne 'ARRAY'; #
231: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
232: && &Apache::lonmsg::mynewmail(); # whether a new msg
233: next if $$menuitem[4] eq 'newmsg' # arrived or not
234: && !&Apache::lonmsg::mynewmail(); #
235: next if $$menuitem[4] !~ /public/ ##we've a public user,
236: && $public; ##who should not see all
237: ##links
238: next if $$menuitem[4] eq 'onlypublic'# hide links which are
239: && !$public; # only visible to public
240: # users
241: next if $$menuitem[4] eq 'roles' ##show links depending on
242: && &Apache::loncommon::show_course(); ##term 'Courses' or
243: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
244: && !&Apache::loncommon::show_course(); ##
245:
246:
247: if ($$menuitem[3] eq 'Help') { # special treatment for helplink
248: $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
249: } else {
250: my @items = @{$menuitem};
251: $items[0] = 'javascript:'.$menuitem->[0].';';
252: $menu .= &prep_menuitem(\@items);
253: }
254: }
255:
256: return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
257: }
258:
259: #returns hashref {user=>'',dom=>''} containing:
260: # own name, domain if user is au
261: # name, domain of parent author if user is ca or aa
262: #empty return if user is not an author or not on homeserver
263: #
264: #TODO this should probably be moved somewhere more central
265: #since it can be used by different parts of the system
266: sub getauthor{
267: return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
268:
269: #co- or assistent author?
270: my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
271: ? ($1, $2) #domain, username of the parent author
272: : @env{ ('request.role.domain', 'user.name') }; #own domain, username
273:
274: # current server == home server?
275: my $home = &Apache::lonnet::homeserver($user,$dom);
276: foreach (&Apache::lonnet::current_machine_ids()){
277: return {user => $user, dom => $dom} if $_ eq $home;
278: }
279:
280: # if wrong server
281: return;
282: }
283:
284:
285: sub secondary_menu {
286: my $menu;
287:
288: my $crstype = &Apache::loncommon::course_type();
289: my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
290: ? "/$env{'request.course.sec'}"
291: : '');
292: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
293: my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
294: my $author = getauthor();
295:
296: my $showlink = &show_return_link();
297: my %groups = &Apache::lonnet::get_active_groups(
298: $env{'user.domain'}, $env{'user.name'},
299: $env{'course.' . $env{'request.course.id'} . '.domain'},
300: $env{'course.' . $env{'request.course.id'} . '.num'});
301: foreach my $menuitem (@secondary_menu) {
302: # evaluate conditions
303: next if ref($menuitem) ne 'ARRAY';
304: next if $$menuitem[4] ne 'always'
305: && $$menuitem[4] ne 'author'
306: && !$env{'request.course.id'};
307: next if $$menuitem[4] eq 'showreturn'
308: && !$showlink
309: && !($env{'request.state'} eq 'construct');
310: next if $$menuitem[4] =~ /^mdc/
311: && !$canedit;
312: next if $$menuitem[4] eq 'mdcCourse'
313: && $crstype eq 'Community';
314: next if $$menuitem[4] eq 'mdcCommunity'
315: && $crstype ne 'Community';
316: next if $$menuitem[4] =~ /^remotenav/
317: && $env{'environment.remotenavmap'} ne 'on';
318: next if $$menuitem[4] =~ /noremotenav/
319: && $env{'environment.remotenavmap'} eq 'on';
320: next if $$menuitem[4] =~ /^(no|)remotenav$/
321: && $crstype eq 'Community';
322: next if $$menuitem[4] =~ /^(no|)remotenavCommunity$/
323: && $crstype ne 'Community';
324: next if $$menuitem[4] =~ /showgroups$/
325: && !$canviewgrps
326: && !%groups;
327: next if $$menuitem[4] eq 'author'
328: && !$author;
329:
330: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
331: # special treatment for role selector
332: my $roles_selector = &roles_selector(
333: $env{'course.' . $env{'request.course.id'} . '.domain'},
334: $env{'course.' . $env{'request.course.id'} . '.num'} );
335:
336: $menu .= $roles_selector ? "<li>$roles_selector</li>"
337: : '';
338: } elsif ($env{'environment.remotenavmap'} eq 'on') {
339: # open link using javascript when remote navmap is activated
340: my @items = @{$menuitem};
341: if ($menuitem->[4] eq 'remotenav') {
342: $items[0] = "javascript:gonav('$menuitem->[0]');";
343: } else {
344: $items[0] = "javascript:go('$menuitem->[0]');";
345: }
346: $menu .= &prep_menuitem(\@items);
347: } else {
348: $menu .= &prep_menuitem(\@$menuitem);
349: }
350: }
351: if ($menu =~ /\[url\].*\[symb\]/) {
352: my $escurl = &escape( &Apache::lonenc::check_encrypt(
353: $env{'request.noversionuri'}));
354:
355: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
356: $env{'request.symb'}));
357:
358: if ( $env{'request.state'} eq 'construct'
359: and ( $env{'request.noversionuri'} eq ''
360: || !defined($env{'request.noversionuri'})))
361: {
362: ($escurl = $env{'request.filename'}) =~
363: s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
364:
365: $escurl = &escape($escurl);
366: }
367: $menu =~ s/\[url\]/$escurl/g;
368: $menu =~ s/\[symb\]/$escsymb/g;
369: }
370: $menu =~ s/\[uname\]/$$author{user}/g;
371: $menu =~ s/\[udom\]/$$author{dom}/g;
372:
373: return "<ul id=\"LC_secondary_menu\">$menu</ul>";
374: }
375:
376: sub show_return_link {
377: if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)})
378: || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) {
379:
380: return if ($env{'form.register'});
381: }
382: return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
383: $env{'request.symb'} eq '')
384: ||
385: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
386: ||
387: (($env{'request.noversionuri'}=~/^\/adm\//) &&
388: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
389: ($env{'request.noversionuri'}!~
390: m[^/adm/.*/(smppg|bulletinboard)($|\?)])
391: ));
392: }
393:
394:
395: sub registerurl {
396: my ($forcereg) = @_;
397: my $result = '';
398: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
399: my $force_title='';
400: if ($env{'request.state'} eq 'construct') {
401: $force_title=&Apache::lonxml::display_title();
402: }
403: if (($env{'environment.remote'} eq 'off') ||
404: ((($env{'request.publicaccess'}) ||
405: (!&Apache::lonnet::is_on_map(
406: &unescape($env{'request.noversionuri'})))) &&
407: (!$forcereg))) {
408: return
409: $result
410: .'<script type="text/javascript">'."\n"
411: .'// <![CDATA['."\n"
412: .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
413: .'// ]]>'."\n"
414: .'</script>'
415: .$force_title;
416: }
417: # Graphical display after login only
418: if ($env{'request.registered'} && !$forcereg) { return ''; }
419: $result.=&innerregister($forcereg);
420: return $result.$force_title;
421: }
422:
423: sub innerregister {
424: my ($forcereg,$titletable,$bread_crumbs) = @_;
425: my $result = '';
426: my ($uname,$thisdisfn);
427: my $const_space = ($env{'request.state'} eq 'construct');
428: my $is_const_dir = 0;
429:
430: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
431:
432: $env{'request.registered'} = 1;
433:
434: my $noremote = ($env{'environment.remote'} eq 'off');
435:
436: undef(@inlineremote);
437:
438: my $reopen=&Apache::lonmenu::reopenmenu();
439:
440: my $newmail='';
441:
442: if (&Apache::lonmsg::newmail() && !$noremote) {
443: # We have new mail and remote is up
444: $newmail= 'swmenu.setstatus("you have","messages");';
445: }
446:
447: my ($breadcrumb,$separator);
448: if ($noremote
449: && ($env{'request.symb'})
450: && ($env{'request.course.id'})) {
451:
452: my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
453: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
454:
455: my $maptitle = &Apache::lonnet::gettitle($mapurl);
456: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
457: my $contentstext;
458: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Community') {
459: $contentstext = &mt('Community Contents');
460: } else {
461: $contentstext = &mt('Course Contents');
462: }
463: my @crumbs;
464: unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps')
465: && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
466: @crumbs = ({text => $contentstext,
467: href => "Javascript:gopost('/adm/navmaps','')"});
468: }
469: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
470: push(@crumbs, {text => '...',
471: no_mt => 1});
472: }
473:
474: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
475: && $maptitle ne 'default.sequence'
476: && $maptitle ne $coursetitle);
477:
478: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
479:
480: &Apache::lonhtmlcommon::clear_breadcrumbs();
481: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
482:
483: #$breadcrumb .= &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
484: unless (($env{'request.state'} eq 'edit') || ($newmail) ||
485: ($env{'request.state'} eq 'construct') ||
486: ($env{'form.register'})) {
487: $separator = &Apache::loncommon::head_subbox();
488: }
489: #
490: } elsif (!$const_space){
491: #a situation when we're looking at a resource outside of context of a
492: #course or construction space (e.g. with cumulative rights)
493: &Apache::lonhtmlcommon::clear_breadcrumbs();
494: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
495: }
496: if ($env{'request.state'} eq 'construct') {
497: $newmail = $titletable;
498: }
499: my $timesync = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
500: my $tablestart = ( $noremote ? '<table id="LC_menubuttons">' : '');
501: my $tableend = ( $noremote ? '</table>' : '');
502: # =============================================================================
503: # ============================ This is for URLs that actually can be registered
504: if (($env{'request.noversionuri'}!~m{^/(res/)*adm/}) || ($forcereg)) {
505: # -- This applies to homework problems for users with grading privileges
506: my $crs='/'.$env{'request.course.id'};
507: if ($env{'request.course.sec'}) {
508: $crs.='_'.$env{'request.course.sec'};
509: }
510: $crs=~s/\_/\//g;
511:
512: my $hwkadd='';
513: if ($env{'request.symb'} ne '' &&
514: $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
515: if (&Apache::lonnet::allowed('mgr',$crs)) {
516: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]',
517: "gocmd('/adm/grades','gradingmenu')",
518: 'Modify user grades for this assessment resource');
519: } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
520: $hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
521: "gocmd('/adm/grades','submission')",
522: 'View user submissions for this assessment resource');
523: }
524: }
525: if ($env{'request.symb'} ne '' &&
526: &Apache::lonnet::allowed('opa',$crs)) {
527: $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
528: "gocmd('/adm/parmset','set')",
529: 'Modify parameter settings for this resource');
530: }
531: # -- End Homework
532: ###
533: ### Determine whether or not to display the 'cstr' button for this
534: ### resource
535: ###
536: my $editbutton = '';
537: my $noeditbutton = 1;
538: my ($cnum,$cdom);
539: if ($env{'request.course.id'}) {
540: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
541: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
542: }
543: if ($env{'user.author'}) {
544: if ($env{'request.role'}=~/^(aa|ca|au)/) {
545: #
546: # We have the role of an author
547: #
548: # Set defaults for authors
549: my ($top,$bottom) = ('con-','struct');
550: my $action = "go('/priv/".$env{'user.name'}."');";
551: my $cadom = $env{'request.role.domain'};
552: my $caname = $env{'user.name'};
553: my $desc = "Enter my construction space";
554: # Set defaults for co-authors
555: if ($env{'request.role'} =~ /^ca/) {
556: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
557: ($top,$bottom) = ('co con-','struct');
558: $action = "go('/priv/".$caname."');";
559: $desc = "Enter construction space as co-author";
560: } elsif ($env{'request.role'} =~ /^aa/) {
561: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
562: ($top,$bottom) = ('co con-','struct');
563: $action = "go('/priv/".$caname."');";
564: $desc = "Enter construction space as assistant co-author";
565: }
566: # Check that we are on the correct machine
567: my $home = &Apache::lonnet::homeserver($caname,$cadom);
568: my $allowed=0;
569: my @ids=&Apache::lonnet::current_machine_ids();
570: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
571: if (!$allowed) {
572: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
573: $noeditbutton = 0;
574: }
575: }
576: #
577: # We are an author for some stuff, but currently do not have the role of author.
578: # Figure out if we have authoring privileges for the resource we are looking at.
579: # This should maybe become a privilege check in lonnet
580: #
581: ##
582: ## Determine if user can edit url.
583: ##
584: my $cfile='';
585: my $cfuname='';
586: my $cfudom='';
587: my $uploaded;
588: my $switchserver='';
589: my $home;
590: if ($env{'request.filename'}) {
591: my $file=&Apache::lonnet::declutter($env{'request.filename'});
592: if (defined($cnum) && defined($cdom)) {
593: $uploaded = &is_course_upload($file,$cnum,$cdom);
594: }
595: if (!$uploaded) {
596: $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
597: # Check that the user has permission to edit this resource
598: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
599: if (defined($cfudom)) {
600: $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
601: my $allowed=0;
602: my @ids=&Apache::lonnet::current_machine_ids();
603: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
604: if ($allowed) {
605: $cfile=$file;
606: } else {
607: $switchserver=$file;
608: }
609: }
610: }
611: }
612: # Finally, turn the button on or off
613: if (($cfile || $switchserver) && !$const_space) {
614: my $nocrsedit;
615: # Suppress display where CC has switched to student role.
616: if ($env{'request.course.id'}) {
617: unless(&Apache::lonnet::allowed('mdc',
618: $env{'request.course.id'})) {
619: $nocrsedit = 1;
620: }
621: }
622: if ($nocrsedit) {
623: $editbutton=&clear(6,1);
624: } else {
625: if ($switchserver) {
626: if ( $env{'request.symb'} && $env{'request.course.id'} ) {
627: my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
628: $cfile = '/adm/switchserver?otherserver='.$home.'&role='.$env{'request.role'}.'&symb='.$env{'request.symb'}.'&origurl='.$resurl;
629: }
630: }
631: $editbutton=&switch
632: ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
633: "go('".$cfile."');","Edit this resource");
634: $noeditbutton = 0;
635: }
636: } elsif ($editbutton eq '') {
637: $editbutton=&clear(6,1);
638: }
639: }
640: if (($noeditbutton) && ($env{'request.filename'})) {
641: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
642: my $file=&Apache::lonnet::declutter($env{'request.filename'});
643: if (defined($cnum) && defined($cdom)) {
644: if (&is_course_upload($file,$cnum,$cdom)) {
645: my $cfile = &edit_course_upload($file,$cnum,$cdom);
646: if ($cfile) {
647: $editbutton=&switch
648: ('','',6,1,'pcstr.gif','edit[_1]',
649: 'resource[_2]',"go('".$cfile."');",
650: 'Edit this resource');
651: }
652: }
653: }
654: }
655: }
656: ###
657: ###
658: # Prepare the rest of the buttons
659: my $menuitems;
660: if ($const_space) {
661: #
662: # We are in construction space
663: #
664: my ($uname,$thisdisfn) =
665: ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
666: my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
667: if ($currdir =~ m-/$-) {
668: $is_const_dir = 1;
669: } else {
670: $currdir =~ s|[^/]+$||;
671: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
672: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
673: #
674: # Probably should be in mydesk.tab
675: #
676: $menuitems=(<<ENDMENUITEMS);
677: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
678: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
679: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
680: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
681: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
682: ENDMENUITEMS
683: }
684: if ($noremote) {
685: if (ref($bread_crumbs) eq 'ARRAY') {
686: &Apache::lonhtmlcommon::clear_breadcrumbs();
687: foreach my $crumb (@{$bread_crumbs}){
688: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
689: }
690: }
691: }
692: } elsif ( defined($env{'request.course.id'}) &&
693: $env{'request.symb'} ne '' ) {
694: #
695: # We are in a course and looking at a registred URL
696: # Should probably be in mydesk.tab
697: #
698: $menuitems=(<<ENDMENUITEMS);
699: c&3&1
700: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
701: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
702: c&6&3
703: c&8&1
704: c&8&2
705: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
706: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
707: ENDMENUITEMS
708:
709: my $currentURL = &Apache::loncommon::get_symb();
710: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
711: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
712: $menuitems.="s&9&3&";
713: if(length($annotation) > 0){
714: $menuitems.="anot2.gif";
715: }else{
716: $menuitems.="anot.gif";
717: }
718: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
719: $menuitems.="Make notes and annotations about this resource&&1\n";
720:
721: unless ($noremote) {
722: my $showreqcrs = &check_for_rcrs();
723: if ($showreqcrs) {
724: $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]".
725: "&go('/adm/requestcourse')&Course requests\n";
726: }
727: }
728: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
729: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
730: $menuitems.=(<<ENDREALRES);
731: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
732: ENDREALRES
733: }
734: $menuitems.=(<<ENDREALRES);
735: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
736: 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
737: ENDREALRES
738: }
739: }
740: if ($env{'request.uri'} =~ /^\/res/) {
741: $menuitems .= (<<ENDMENUITEMS);
742: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
743: ENDMENUITEMS
744: }
745: my $buttons='';
746: foreach (split(/\n/,$menuitems)) {
747: my ($command,@rest)=split(/\&/,$_);
748: my $idx=10*$rest[0]+$rest[1];
749: if (&hidden_button_check() eq 'yes') {
750: if ($idx == 21 ||$idx == 23) {
751: $buttons.=&switch('','',@rest);
752: } else {
753: $buttons.=&clear(@rest);
754: }
755: } else {
756: if ($command eq 's') {
757: $buttons.=&switch('','',@rest);
758: } else {
759: $buttons.=&clear(@rest);
760: }
761: }
762: }
763:
764: if ($noremote) {
765: my $addremote=0;
766: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
767: my $inlinebuttons='';
768: if ($addremote) {
769:
770: Apache::lonhtmlcommon::clear_breadcrumb_tools();
771:
772: Apache::lonhtmlcommon::add_breadcrumb_tool(
773: 'navigation', @inlineremote[21,23]);
774:
775: if(hidden_button_check() ne 'yes') {
776: Apache::lonhtmlcommon::add_breadcrumb_tool(
777: 'tools', @inlineremote[93,91,81,82,83]);
778:
779: #publish button in construction space
780: if ($env{'request.state'} eq 'construct'){
781: Apache::lonhtmlcommon::add_breadcrumb_tool(
782: 'advtools', @inlineremote[63]);
783: }else{
784: Apache::lonhtmlcommon::add_breadcrumb_tool(
785: 'tools', @inlineremote[63]);
786: }
787:
788: unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
789: Apache::lonhtmlcommon::add_breadcrumb_tool(
790: 'advtools', @inlineremote[61,71,72,73,92]);
791: }
792: }
793:
794: # # Registered, textual output
795: # if ( $env{'environment.icons'} eq 'iconsonly' ) {
796: # $inlinebuttons = (<<ENDARROWSINLINE);
797: #<tr><td>
798: #$inlineremote[21] $inlineremote[23]
799: #ENDARROWSINLINE
800: # if ( &hidden_button_check() ne 'yes' ) {
801: # $inlinebuttons .= (<<ENDINLINEICONS);
802: #$inlineremote[61] $inlineremote[63]
803: #$inlineremote[71] $inlineremote[72] $inlineremote[73]
804: #$inlineremote[81] $inlineremote[82] $inlineremote[83]
805: #$inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
806: #ENDINLINEICONS
807: # }
808: # } else { # not iconsonly
809: # if ( $inlineremote[21] ne '' || $inlineremote[23] ne '' ) {
810: # $inlinebuttons = (<<ENDFIRSTLINE);
811: #<tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr>
812: #ENDFIRSTLINE
813: # }
814: # if ( &hidden_button_check() ne 'yes' ) {
815: # foreach my $row ( 6 .. 9 ) {
816: # if ( $inlineremote[ ${row} . '1' ] ne ''
817: # || $inlineremote[ $row . '2' ] ne ''
818: # || $inlineremote[ $row . '3' ] ne '' )
819: # {
820: # $inlinebuttons .= <<"ENDLINE";
821: #<tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
822: #ENDLINE
823: # }
824: # }
825: # }
826: # }
827: }
828: $breadcrumb = &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
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_icon" />';
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 title="'.$desc.'" 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><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 LC_400Box">';
1265: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
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: my $crstype='';
1308: if ($env{'request.course.id'}) {
1309: $crs='/'.$env{'request.course.id'};
1310: if ($env{'request.course.sec'}) {
1311: $crs.='_'.$env{'request.course.sec'};
1312: }
1313: $crs=~s/\_/\//g;
1314: $crstype = &Apache::loncommon::course_type();
1315: }
1316: my $pub=($env{'request.state'} eq 'published');
1317: my $con=($env{'request.state'} eq 'construct');
1318: my $rol=$env{'request.role'};
1319: my $requested_domain = $env{'request.role.domain'};
1320: foreach my $line (@desklines) {
1321: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1322: $prt=~s/\$uname/$uname/g;
1323: $prt=~s/\$udom/$udom/g;
1324: if ($prt =~ /\$crs/) {
1325: next unless ($env{'request.course.id'});
1326: next if ($crstype eq 'Community');
1327: $prt=~s/\$crs/$crs/g;
1328: } elsif ($prt =~ /\$cmty/) {
1329: next unless ($env{'request.course.id'});
1330: next if ($crstype ne 'Community');
1331: $prt=~s/\$cmty/$crs/g;
1332: }
1333: $prt=~s/\$requested_domain/$requested_domain/g;
1334: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1335: if ($pro eq 'clear') {
1336: $output.=&clear($row,$col);
1337: } elsif ($pro eq 'any') {
1338: $output.=&secondlevel(
1339: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1340: } elsif ($pro eq 'smp') {
1341: unless ($adv) {
1342: $output.=&secondlevel(
1343: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1344: }
1345: } elsif ($pro eq 'adv') {
1346: if ($adv) {
1347: $output.=&secondlevel(
1348: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1349: }
1350: } elsif ($pro eq 'shc') {
1351: if ($show_course) {
1352: $output.=&secondlevel(
1353: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1354: }
1355: } elsif ($pro eq 'nsc') {
1356: if (!$show_course) {
1357: $output.=&secondlevel(
1358: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1359: }
1360: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1361: my $priv = $1;
1362: if ($priv =~ /^mdc(Course|Community)/) {
1363: if ($crstype eq $1) {
1364: $priv = 'mdc';
1365: } else {
1366: next;
1367: }
1368: }
1369: if (&Apache::lonnet::allowed($priv,$prt)) {
1370: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1371: }
1372: } elsif ($pro eq 'course') {
1373: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1374: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1375: }
1376: } elsif ($pro eq 'community') {
1377: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1378: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1379: }
1380: } elsif ($pro =~ /^courseenv_(.*)$/) {
1381: my $key = $1;
1382: if ($crstype ne 'Community') {
1383: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1384: if ($key eq 'canuse_pdfforms') {
1385: if ($env{'request.course.id'} && $coursepref eq '') {
1386: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1387: $coursepref = $domdefs{'canuse_pdfforms'};
1388: }
1389: }
1390: if ($coursepref) {
1391: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1392: }
1393: }
1394: } elsif ($pro =~ /^communityenv_(.*)$/) {
1395: my $key = $1;
1396: if ($crstype eq 'Community') {
1397: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1398: if ($key eq 'canuse_pdfforms') {
1399: if ($env{'request.course.id'} && $coursepref eq '') {
1400: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1401: $coursepref = $domdefs{'canuse_pdfforms'};
1402: }
1403: }
1404: if ($coursepref) {
1405: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1406: }
1407: }
1408: } elsif ($pro =~ /^course_(.*)$/) {
1409: # Check for permissions inside of a course
1410: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1411: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1412: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1413: )) {
1414: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1415: }
1416: } elsif ($pro =~ /^community_(.*)$/) {
1417: # Check for permissions inside of a community
1418: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1419: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1420: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1421: )) {
1422: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1423: }
1424: } elsif ($pro eq 'author') {
1425: if ($author) {
1426: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1427: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1428: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1429: # Check that we are on the correct machine
1430: my $cadom=$requested_domain;
1431: my $caname=$env{'user.name'};
1432: if (($prt eq 'rca') || ($prt eq 'raa')) {
1433: ($cadom,$caname)=
1434: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1435: }
1436: $act =~ s/\$caname/$caname/g;
1437: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1438: my $allowed=0;
1439: my @ids=&Apache::lonnet::current_machine_ids();
1440: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1441: if ($allowed) {
1442: $output.=&switch($caname,$cadom,
1443: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1444: }
1445: }
1446: }
1447: } elsif ($pro eq 'tools') {
1448: my @tools = ('aboutme','blog','portfolio');
1449: if (grep(/^\Q$prt\E$/,@tools)) {
1450: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1451: $env{'user.domain'},
1452: $prt,undef,'tools')) {
1453: $output.=&clear($row,$col);
1454: next;
1455: }
1456: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1457: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1458: next;
1459: }
1460: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1461: next;
1462: }
1463: my $showreqcrs = &check_for_rcrs();
1464: if (!$showreqcrs) {
1465: $output.=&clear($row,$col);
1466: next;
1467: }
1468: }
1469: $prt='any';
1470: $output.=&secondlevel(
1471: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1472: }
1473: }
1474: unless ($env{'environment.remote'} eq 'off') {
1475: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1476: if (&Apache::lonmsg::newmail()) {
1477: $output.='swmenu.setstatus("you have","messages");';
1478: }
1479: }
1480:
1481: return $output;
1482: }
1483:
1484: sub check_for_rcrs {
1485: my $showreqcrs = 0;
1486: my @reqtypes = ('official','unofficial','community');
1487: foreach my $type (@reqtypes) {
1488: if (&Apache::lonnet::usertools_access($env{'user.name'},
1489: $env{'user.domain'},
1490: $type,undef,'requestcourses')) {
1491: $showreqcrs = 1;
1492: last;
1493: }
1494: }
1495: if (!$showreqcrs) {
1496: foreach my $type (@reqtypes) {
1497: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1498: $showreqcrs = 1;
1499: last;
1500: }
1501: }
1502: }
1503: return $showreqcrs;
1504: }
1505:
1506: # ======================================================================= Close
1507:
1508: sub close {
1509: if ($env{'environment.remote'} eq 'off') { return ''; }
1510: my $menuname = &get_menu_name();
1511: return(<<ENDCLOSE);
1512: <script type="text/javascript">
1513: // <![CDATA[
1514: window.status='Accessing Remote Control';
1515: menu=window.open("/adm/rat/empty.html","$menuname",
1516: "height=350,width=150,scrollbars=no,menubar=no");
1517: window.status='Disabling Remote Control';
1518: menu.active=0;
1519: menu.autologout=0;
1520: window.status='Closing Remote Control';
1521: menu.close();
1522: window.status='Done.';
1523: // ]]>
1524: </script>
1525: ENDCLOSE
1526: }
1527:
1528: # ====================================================================== Footer
1529:
1530: sub footer {
1531:
1532: }
1533:
1534: sub nav_control_js {
1535: my $nav=($env{'environment.remotenavmap'} eq 'on');
1536: return (<<NAVCONTROL);
1537: var w_loncapanav_flag="$nav";
1538:
1539:
1540: function gonav(url) {
1541: if (w_loncapanav_flag != 1) {
1542: gopost(url,'');
1543: } else {
1544: navwindow=window.open(url,
1545: "loncapanav","height=600,width=400,scrollbars=1");
1546: }
1547: }
1548: NAVCONTROL
1549: }
1550:
1551: sub dc_popup_js {
1552: my %lt = &Apache::lonlocal::texthash(
1553: more => '(More ...)',
1554: less => '(Less ...)',
1555: );
1556: return <<"END";
1557:
1558: function showCourseID() {
1559: document.getElementById('dccid').style.display='block';
1560: document.getElementById('dccid').style.textAlign='left';
1561: document.getElementById('dccid').style.textFace='normal';
1562: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>';
1563: return;
1564: }
1565:
1566: function hideCourseID() {
1567: document.getElementById('dccid').style.display='none';
1568: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()">$lt{'more'}</a>';
1569: return;
1570: }
1571:
1572: END
1573:
1574: }
1575:
1576: sub utilityfunctions {
1577: my $caller = shift;
1578: unless ($env{'environment.remote'} eq 'off' ||
1579: $caller eq '/adm/menu') {
1580: return ''; }
1581:
1582: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1583: if ($currenturl =~ m{^/adm/wrapper/ext/}) {
1584: if ($env{'request.external.querystring'}) {
1585: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1586: }
1587: }
1588: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1589:
1590: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1591: my $nav_control=&nav_control_js();
1592:
1593: my $dc_popup_cid;
1594: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1595: $env{'course.'.$env{'request.course.id'}.
1596: '.domain'}.'/'})) {
1597: $dc_popup_cid = &dc_popup_js();
1598: }
1599:
1600: my $start_page_annotate =
1601: &Apache::loncommon::start_page('Annotator',undef,
1602: {'only_body' => 1,
1603: 'js_ready' => 1,
1604: 'bgcolor' => '#BBBBBB',
1605: 'add_entries' => {
1606: 'onload' => 'javascript:document.goannotate.submit();'}});
1607:
1608: my $end_page_annotate =
1609: &Apache::loncommon::end_page({'js_ready' => 1});
1610:
1611: my $start_page_bookmark =
1612: &Apache::loncommon::start_page('Bookmarks',undef,
1613: {'only_body' => 1,
1614: 'js_ready' => 1,
1615: 'bgcolor' => '#BBBBBB',});
1616:
1617: my $end_page_bookmark =
1618: &Apache::loncommon::end_page({'js_ready' => 1});
1619:
1620: return (<<ENDUTILITY)
1621:
1622: var currentURL="$currenturl";
1623: var reloadURL="$currenturl";
1624: var currentSymb="$currentsymb";
1625:
1626: $nav_control
1627: $dc_popup_cid
1628:
1629: function go(url) {
1630: if (url!='' && url!= null) {
1631: currentURL = null;
1632: currentSymb= null;
1633: window.location.href=url;
1634: }
1635: }
1636:
1637: function gotop(url) {
1638: if (url!='' && url!= null) {
1639: top.location.href = url;
1640: }
1641: }
1642:
1643: function gopost(url,postdata) {
1644: if (url!='') {
1645: this.document.server.action=url;
1646: this.document.server.postdata.value=postdata;
1647: this.document.server.command.value='';
1648: this.document.server.url.value='';
1649: this.document.server.symb.value='';
1650: this.document.server.submit();
1651: }
1652: }
1653:
1654: function gocmd(url,cmd) {
1655: if (url!='') {
1656: this.document.server.action=url;
1657: this.document.server.postdata.value='';
1658: this.document.server.command.value=cmd;
1659: this.document.server.url.value=currentURL;
1660: this.document.server.symb.value=currentSymb;
1661: this.document.server.submit();
1662: }
1663: }
1664:
1665: function gocstr(url,filename) {
1666: if (url == '/adm/cfile?action=delete') {
1667: this.document.cstrdelete.filename.value = filename
1668: this.document.cstrdelete.submit();
1669: return;
1670: }
1671: if (url == '/adm/printout') {
1672: this.document.cstrprint.postdata.value = filename
1673: this.document.cstrprint.curseed.value = 0;
1674: this.document.cstrprint.problemtype.value = 0;
1675: if (this.document.lonhomework) {
1676: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1677: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1678: }
1679: if (this.document.lonhomework.problemtype) {
1680: if (this.document.lonhomework.problemtype.value) {
1681: this.document.cstrprint.problemtype.value =
1682: this.document.lonhomework.problemtype.value;
1683: } else if (this.document.lonhomework.problemtype.options) {
1684: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1685: if (this.document.lonhomework.problemtype.options[i].selected) {
1686: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1687: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1688: }
1689: }
1690: }
1691: }
1692: }
1693: }
1694: this.document.cstrprint.submit();
1695: return;
1696: }
1697: if (url !='') {
1698: this.document.constspace.filename.value = filename;
1699: this.document.constspace.action = url;
1700: this.document.constspace.submit();
1701: }
1702: }
1703:
1704: function golist(url) {
1705: if (url!='' && url!= null) {
1706: currentURL = null;
1707: currentSymb= null;
1708: top.location.href=url;
1709: }
1710: }
1711:
1712:
1713:
1714: function catalog_info() {
1715: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1716: }
1717:
1718: function chat_win() {
1719: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1720: }
1721:
1722: function group_chat(group) {
1723: var url = '/adm/groupchat?group='+group;
1724: var winName = 'LONchat_'+group;
1725: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1726: }
1727:
1728: function edit_bookmarks() {
1729: go('');
1730: w_BookmarkPal_flag=1;
1731: bookmarkpal=window.open("/adm/bookmarks",
1732: "BookmarkPal", "width=500,height=505,scrollbars=0");
1733: }
1734:
1735: function annotate() {
1736: w_Annotator_flag=1;
1737: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1738: annotator.document.write(
1739: '$start_page_annotate'
1740: +"<form name='goannotate' target='Annotator' method='post' "
1741: +"action='/adm/annotations'>"
1742: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1743: +"<\\/form>"
1744: +'$end_page_annotate');
1745: annotator.document.close();
1746: }
1747:
1748: function set_bookmark() {
1749: go('');
1750: clienttitle=document.title;
1751: clienthref=location.pathname;
1752: w_bmquery_flag=1;
1753: bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
1754: bmquery.document.write(
1755: '$start_page_bookmark'
1756: +'<center><form method="post"'
1757: +' name="newlink" action="/adm/bookmarks" target="bmquery" '
1758: +'> <table width="340" height="150" '
1759: +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
1760: +'type="text" name="title" size="45" value="'+clienttitle+'" />'
1761: +'<br />Address:<br /><input type="text" name="address" size="45" '
1762: +'value="'+clienthref+'" /><br /><center><input type="submit" '
1763: +'value="Save" /> <input type="button" value="Close" '
1764: +'onclick="javascript:window.close();" /></center></td>'
1765: +'</tr></table></form></center>'
1766: +'$end_page_bookmark' );
1767: bmquery.document.close();
1768: }
1769:
1770: ENDUTILITY
1771: }
1772:
1773: sub serverform {
1774: return(<<ENDSERVERFORM);
1775: <form name="server" action="/adm/logout" method="post" target="_top">
1776: <input type="hidden" name="postdata" value="none" />
1777: <input type="hidden" name="command" value="none" />
1778: <input type="hidden" name="url" value="none" />
1779: <input type="hidden" name="symb" value="none" />
1780: </form>
1781: ENDSERVERFORM
1782: }
1783:
1784: sub constspaceform {
1785: return(<<ENDCONSTSPACEFORM);
1786: <form name="constspace" action="/adm/logout" method="post" target="_top">
1787: <input type="hidden" name="filename" value="" />
1788: </form>
1789: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1790: <input type="hidden" name="action" value="delete" />
1791: <input type="hidden" name="filename" value="" />
1792: </form>
1793: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1794: <input type="hidden" name="postdata" value="" />
1795: <input type="hidden" name="curseed" value="" />
1796: <input type="hidden" name="problemtype" value="" />
1797: </form>
1798:
1799: ENDCONSTSPACEFORM
1800: }
1801:
1802:
1803: sub get_nav_status {
1804: my $navstatus="swmenu.w_loncapanav_flag=";
1805: if ($env{'environment.remotenavmap'} eq 'on') {
1806: $navstatus.="1";
1807: } else {
1808: $navstatus.="-1";
1809: }
1810: return $navstatus;
1811: }
1812:
1813: sub hidden_button_check {
1814: my $hidden;
1815: if ($env{'request.course.id'} eq '') {
1816: return;
1817: }
1818: if ($env{'request.role.adv'}) {
1819: return;
1820: }
1821: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1822: return $buttonshide;
1823: }
1824:
1825: sub roles_selector {
1826: my ($cdom,$cnum) = @_;
1827: my $crstype = &Apache::loncommon::course_type();
1828: my $now = time;
1829: my (%courseroles,%seccount);
1830: my $is_cc;
1831: my $role_selector;
1832: my $ccrole;
1833: if ($crstype eq 'Community') {
1834: $ccrole = 'co';
1835: } else {
1836: $ccrole = 'cc';
1837: }
1838: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
1839: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1840:
1841: if ((($start) && ($start<0)) ||
1842: (($end) && ($end<$now)) ||
1843: (($start) && ($now<$start))) {
1844: $is_cc = 0;
1845: } else {
1846: $is_cc = 1;
1847: }
1848: }
1849: if ($is_cc) {
1850: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
1851: } else {
1852: my %gotnosection;
1853: foreach my $item (keys(%env)) {
1854: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1855: my $role = $1;
1856: my $sec = $2;
1857: next if ($role eq 'gr');
1858: my ($start,$end) = split(/\./,$env{$item});
1859: next if (($start && $start > $now) || ($end && $end < $now));
1860: if ($sec eq '') {
1861: if (!$gotnosection{$role}) {
1862: $seccount{$role} ++;
1863: $gotnosection{$role} = 1;
1864: }
1865: }
1866: if (ref($courseroles{$role}) eq 'ARRAY') {
1867: if ($sec ne '') {
1868: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1869: push(@{$courseroles{$role}},$sec);
1870: $seccount{$role} ++;
1871: }
1872: }
1873: } else {
1874: @{$courseroles{$role}} = ();
1875: if ($sec ne '') {
1876: $seccount{$role} ++;
1877: push(@{$courseroles{$role}},$sec);
1878: }
1879: }
1880: }
1881: }
1882: }
1883: my $switchtext;
1884: if ($crstype eq 'Community') {
1885: $switchtext = &mt('Switch community role to...')
1886: } else {
1887: $switchtext = &mt('Switch course role to...')
1888: }
1889: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1890: if (keys(%courseroles) > 1) {
1891: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
1892: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
1893: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1894: $role_selector .= '<option value="">'.$switchtext.'</option>';
1895: foreach my $role (@roles_order) {
1896: if (defined($courseroles{$role})) {
1897: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>';
1898: }
1899: }
1900: foreach my $role (sort(keys(%courseroles))) {
1901: if ($role =~ /^cr/) {
1902: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1903: }
1904: }
1905: $role_selector .= '</select>'."\n".
1906: '<input type="hidden" name="destinationurl" value="'.
1907: &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n".
1908: '<input type="hidden" name="gotorole" value="1" />'."\n".
1909: '<input type="hidden" name="selectrole" value="" />'."\n".
1910: '<input type="hidden" name="switch" value="1" />'."\n".
1911: '</form>';
1912: }
1913: return $role_selector;
1914: }
1915:
1916: sub get_all_courseroles {
1917: my ($cdom,$cnum,$courseroles,$seccount) = @_;
1918: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
1919: return;
1920: }
1921: my ($result,$cached) =
1922: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1923: if (defined($cached)) {
1924: if (ref($result) eq 'HASH') {
1925: if ((ref($result->{'roles'}) eq 'HASH') &&
1926: (ref($result->{'seccount'}) eq 'HASH')) {
1927: %{$courseroles} = %{$result->{'roles'}};
1928: %{$seccount} = %{$result->{'seccount'}};
1929: return;
1930: }
1931: }
1932: }
1933: my %gotnosection;
1934: my %adv_roles =
1935: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1936: foreach my $role (keys(%adv_roles)) {
1937: my ($urole,$usec) = split(/:/,$role);
1938: if (!$gotnosection{$urole}) {
1939: $seccount->{$urole} ++;
1940: $gotnosection{$urole} = 1;
1941: }
1942: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1943: if ($usec ne '') {
1944: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1945: push(@{$courseroles->{$urole}},$usec);
1946: $seccount->{$urole} ++;
1947: }
1948: }
1949: } else {
1950: @{$courseroles->{$urole}} = ();
1951: if ($usec ne '') {
1952: $seccount->{$urole} ++;
1953: push(@{$courseroles->{$urole}},$usec);
1954: }
1955: }
1956: }
1957: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1958: @{$courseroles->{'st'}} = ();
1959: if (keys(%sections_count) > 0) {
1960: push(@{$courseroles->{'st'}},keys(%sections_count));
1961: $seccount->{'st'} = scalar(keys(%sections_count));
1962: }
1963: my $rolehash = {
1964: 'roles' => $courseroles,
1965: 'seccount' => $seccount,
1966: };
1967: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1968: return;
1969: }
1970:
1971: sub jump_to_role {
1972: my ($cdom,$cnum,$seccount,$courseroles) = @_;
1973: my %lt = &Apache::lonlocal::texthash(
1974: this => 'This role has section(s) associated with it.',
1975: ente => 'Enter a specific section.',
1976: orlb => 'Enter a specific section, or leave blank for no section.',
1977: avai => 'Available sections are:',
1978: youe => 'You entered an invalid section choice:',
1979: plst => 'Please try again',
1980: );
1981: my $js;
1982: if (ref($courseroles) eq 'HASH') {
1983: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1984: ' var numsec = new Array();'."\n".
1985: ' var rolesections = new Array();'."\n".
1986: ' var rolenames = new Array();'."\n".
1987: ' var roleseclist = new Array();'."\n";
1988: my @items = keys(%{$courseroles});
1989: for (my $i=0; $i<@items; $i++) {
1990: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1991: my ($secs,$secstr);
1992: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1993: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1994: $secs = join('","',@sections);
1995: $secstr = join(', ',@sections);
1996: }
1997: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1998: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1999: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
2000: }
2001: }
2002: return <<"END";
2003: <script type="text/javascript">
2004: //<![CDATA[
2005: function adhocRole(roleitem) {
2006: $js
2007: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
2008: if (newrole == '') {
2009: return;
2010: }
2011: var fullrole = newrole+'./$cdom/$cnum';
2012: var selidx = '';
2013: for (var i=0; i<rolenames.length; i++) {
2014: if (rolenames[i] == newrole) {
2015: selidx = i;
2016: }
2017: }
2018: var secok = 1;
2019: var secchoice = '';
2020: if (selidx >= 0) {
2021: if (numsec[selidx] > 1) {
2022: secok = 0;
2023: var numrolesec = rolesections[selidx].length;
2024: var msgidx = numsec[selidx] - numrolesec;
2025: secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
2026: if (secchoice == '') {
2027: if (msgidx > 0) {
2028: secok = 1;
2029: }
2030: } else {
2031: for (var j=0; j<rolesections[selidx].length; j++) {
2032: if (rolesections[selidx][j] == secchoice) {
2033: secok = 1;
2034: }
2035: }
2036: }
2037: } else {
2038: if (rolesections[selidx].length == 1) {
2039: secchoice = rolesections[selidx][0];
2040: }
2041: }
2042: }
2043: if (secok == 1) {
2044: if (secchoice != '') {
2045: fullrole += '/'+secchoice;
2046: }
2047: } else {
2048: document.rolechooser.elements[roleitem].selectedIndex = 0;
2049: if (secchoice != null) {
2050: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
2051: }
2052: return;
2053: }
2054: if (fullrole == "$env{'request.role'}") {
2055: return;
2056: }
2057: itemid = retrieveIndex('gotorole');
2058: if (itemid != -1) {
2059: document.rolechooser.elements[itemid].name = fullrole;
2060: }
2061: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
2062: document.rolechooser.selectrole.value = '1';
2063: document.rolechooser.submit();
2064: return;
2065: }
2066:
2067: function retrieveIndex(item) {
2068: for (var i=0;i<document.rolechooser.elements.length;i++) {
2069: if (document.rolechooser.elements[i].name == item) {
2070: return i;
2071: }
2072: }
2073: return -1;
2074: }
2075: // ]]>
2076: </script>
2077: END
2078: }
2079:
2080:
2081: # ================================================================ Main Program
2082:
2083: BEGIN {
2084: if (! defined($readdesk)) {
2085: {
2086: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
2087: if ( CORE::open( my $config,"<$tabfile") ) {
2088: while (my $configline=<$config>) {
2089: $configline=(split(/\#/,$configline))[0];
2090: $configline=~s/^\s+//;
2091: chomp($configline);
2092: if ($configline=~/^cat\:/) {
2093: my @entries=split(/\:/,$configline);
2094: $category_positions{$entries[2]}=$entries[1];
2095: $category_names{$entries[2]}=$entries[3];
2096: } elsif ($configline=~/^prim\:/) {
2097: my @entries = (split(/\:/, $configline))[1..5];
2098: push @primary_menu, \@entries;
2099: } elsif ($configline=~/^scnd\:/) {
2100: my @entries = (split(/\:/, $configline))[1..5];
2101: push @secondary_menu, \@entries;
2102: } elsif ($configline) {
2103: push(@desklines,$configline);
2104: }
2105: }
2106: CORE::close($config);
2107: }
2108: }
2109: $readdesk='done';
2110: }
2111: }
2112:
2113: 1;
2114: __END__
2115:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>