1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.369.2.51 2014/02/23 22:36:16 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:
30: =head1 NAME
31:
32: Apache::lonmenu
33:
34: =head1 SYNOPSIS
35:
36: Loads contents of /home/httpd/lonTabs/mydesk.tab,
37: used to generate inline menu, and Main Menu page.
38:
39: This is part of the LearningOnline Network with CAPA project
40: described at http://www.lon-capa.org.
41:
42: =head1 GLOBAL VARIABLES
43:
44: =over
45:
46: =item @desklines
47:
48: Each element of this array contains a line of mydesk.tab that doesn't start with
49: cat, prim or scnd.
50: It gets filled in the BEGIN block of this module.
51:
52: =item %category_names
53:
54: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
55: start with cat, the values are strings representing titles.
56: It gets filled in the BEGIN block of this module.
57:
58: =item %category_members
59:
60: TODO
61:
62: =item %category_positions
63:
64: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
65: start with cat, its values are position vectors (column, row).
66: It gets filled in the BEGIN block of this module.
67:
68: =item $readdesk
69:
70: Indicates that mydesk.tab has been read.
71: It is set to 'done' in the BEGIN block of this module.
72:
73: =item @primary_menu
74:
75: The elements of this array reference arrays that are made up of the components
76: of those lines of mydesk.tab that start with prim:.
77: It is used by primary_menu() to generate the corresponding menu.
78: It gets filled in the BEGIN block of this module.
79:
80: =item %primary_sub_menu
81:
82: The keys of this hash reference are the names of items in the primary_menu array
83: which have sub-menus. For each key, the corresponding value is a reference to
84: an array containing components extracted from lines in mydesk.tab which begin
85: with primsub:.
86: This hash, which is used by primary_menu to generate sub-menus, is populated in
87: the BEGIN block.
88:
89: =item @secondary_menu
90:
91: The elements of this array reference arrays that are made up of the components
92: of those lines of mydesk.tab that start with scnd.
93: It is used by secondary_menu() to generate the corresponding menu.
94: It gets filled in the BEGIN block of this module.
95:
96: =back
97:
98: =head1 SUBROUTINES
99:
100: =over
101:
102: =item prep_menuitems(\@menuitem)
103:
104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
105: secondary_menu().
106:
107: =item primary_menu()
108:
109: This routine evaluates @primary_menu and returns a two item array,
110: with the array elements containing XHTML for the left and right sides of
111: the menu that contains the following links: About, Message, Roles, Help, Logout
112: @primary_menu is filled within the BEGIN block of this module with
113: entries from mydesk.tab
114:
115: =item secondary_menu()
116:
117: Same as primary_menu() but operates on @secondary_menu.
118:
119: =item create_submenu()
120:
121: Creates XHTML for unordered list of sub-menu items which belong to a
122: particular top-level menu item. Uses hover pseudo class in css to display
123: dropdown list when mouse hovers over top-level item. Support for IE6
124: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
125: level item, which employs jQuery to handle behavior on mouseover.
126:
127: Inputs: 4 - (a) link and (b) target for anchor href in top level item,
128: (c) title for text wrapped by anchor tag in top level item.
129: (d) reference to array of arrays of sub-menu items.
130:
131: =item innerregister()
132:
133: This gets called in order to register a URL in the body of the document
134:
135: =item loadevents()
136:
137: =item unloadevents()
138:
139: =item startupremote()
140:
141: =item setflags()
142:
143: =item maincall()
144:
145: =item load_remote_msg()
146:
147: =item get_menu_name()
148:
149: =item reopenmenu()
150:
151: =item open()
152:
153: Open the menu
154:
155: =item clear()
156:
157: =item switch()
158:
159: Switch a button or create a link
160: Switch acts on the javascript that is executed when a button is clicked.
161: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
162:
163: =item secondlevel()
164:
165: =item openmenu()
166:
167: =item inlinemenu()
168:
169: =item rawconfig()
170:
171: =item utilityfunctions()
172:
173: Output from this routine is a number of javascript functions called by
174: items in the inline menu, and in some cases items in the Main Menu page.
175:
176: =item serverform()
177:
178: =item constspaceform()
179:
180: =item get_nav_status()
181:
182: =item hidden_button_check()
183:
184: =item roles_selector()
185:
186: =item jump_to_role()
187:
188: =back
189:
190: =cut
191:
192: package Apache::lonmenu;
193:
194: use strict;
195: use Apache::lonnet;
196: use Apache::lonhtmlcommon();
197: use Apache::loncommon();
198: use Apache::lonenc();
199: use Apache::lonlocal;
200: use Apache::lonmsg();
201: use LONCAPA qw(:DEFAULT :match);
202: use HTML::Entities();
203: use Apache::lonwishlist();
204:
205: use vars qw(@desklines %category_names %category_members %category_positions
206: $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
207:
208: my @inlineremote;
209:
210: sub prep_menuitem {
211: my ($menuitem) = @_;
212: return '' unless(ref($menuitem) eq 'ARRAY');
213: my $link;
214: if ($$menuitem[1]) { # graphical Link
215: $link = "<img class=\"LC_noBorder\""
216: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
217: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
218: } else { # textual Link
219: $link = &mt($$menuitem[3]);
220: }
221: return '<li><a'
222: # highlighting for new messages
223: . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
224: . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
225: }
226:
227: # primary_menu() evaluates @primary_menu and returns a two item array,
228: # with the array elements containing XHTML for the left and right sides of
229: # the menu that contains the following links:
230: # Personal, About, Message, Roles, Help, Logout
231: # @primary_menu is filled within the BEGIN block of this module with
232: # entries from mydesk.tab
233: sub primary_menu {
234: my %menu;
235: # each element of @primary contains following array:
236: # (link url, icon path, alt text, link text, condition, position)
237: my $public;
238: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
239: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
240: $public = 1;
241: }
242: foreach my $menuitem (@primary_menu) {
243: # evaluate conditions
244: next if ref($menuitem) ne 'ARRAY'; #
245: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
246: && &Apache::lonmsg::mynewmail(); # whether a new msg
247: next if $$menuitem[4] eq 'newmsg' # arrived or not
248: && !&Apache::lonmsg::mynewmail(); #
249: next if $$menuitem[4] !~ /public/ ##we've a public user,
250: && $public; ##who should not see all
251: ##links
252: next if $$menuitem[4] eq 'onlypublic'# hide links which are
253: && !$public; # only visible to public
254: # users
255: next if $$menuitem[4] eq 'roles' ##show links depending on
256: && &Apache::loncommon::show_course(); ##term 'Courses' or
257: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
258: && !&Apache::loncommon::show_course(); ##
259:
260: my $title = $menuitem->[3];
261: my $position = $menuitem->[5];
262: if ($position eq '') {
263: $position = 'right';
264: }
265: if (defined($primary_submenu{$title})) {
266: my ($link,$target);
267: if ($menuitem->[0] ne '') {
268: $link = $menuitem->[0];
269: $target = '_top';
270: } else {
271: $link = '#';
272: }
273: my @primsub;
274: if (ref($primary_submenu{$title}) eq 'ARRAY') {
275: foreach my $item (@{$primary_submenu{$title}}) {
276: next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
277: next if ((($item->[2] eq 'portfolio') ||
278: ($item->[2] eq 'blog')) &&
279: (!&Apache::lonnet::usertools_access('','',$item->[2],
280: undef,'tools')));
281: push(@primsub,$item);
282: }
283: if (@primsub > 0) {
284: $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
285: } elsif ($link) {
286: $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
287: }
288: }
289: } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
290: if ($public) {
291: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
292: my $defdom = &Apache::lonnet::default_login_domain();
293: my $to = &Apache::loncommon::build_recipient_list(undef,
294: 'helpdeskmail',
295: $defdom,$origmail);
296: if ($to ne '') {
297: $menu{$position} .= &prep_menuitem($menuitem);
298: }
299: } else {
300: $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
301: }
302: } else {
303: $menu{$position} .= prep_menuitem($menuitem);
304: }
305: }
306: my @output = ('','');
307: if ($menu{'left'} ne '') {
308: $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
309: }
310: if ($menu{'right'} ne '') {
311: $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
312: }
313: return @output;
314: }
315:
316: #returns hashref {user=>'',dom=>''} containing:
317: # own name, domain if user is au
318: # name, domain of parent author if user is ca or aa
319: #empty return if user is not an author or not on homeserver
320: #
321: #TODO this should probably be moved somewhere more central
322: #since it can be used by different parts of the system
323: sub getauthor{
324: return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
325:
326: #co- or assistent author?
327: my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
328: ? ($1, $2) #domain, username of the parent author
329: : @env{ ('request.role.domain', 'user.name') }; #own domain, username
330:
331: # current server == home server?
332: my $home = &Apache::lonnet::homeserver($user,$dom);
333: foreach (&Apache::lonnet::current_machine_ids()){
334: return {user => $user, dom => $dom} if $_ eq $home;
335: }
336:
337: # if wrong server
338: return;
339: }
340:
341: sub secondary_menu {
342: my ($httphost) = @_;
343: my $menu;
344:
345: my $crstype = &Apache::loncommon::course_type();
346: my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
347: ? "/$env{'request.course.sec'}"
348: : '');
349: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
350: my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
351: if ($canviewroster eq 'disabled') {
352: undef($canviewroster);
353: }
354: my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
355: my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
356: my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
357: my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
358: my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
359: my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
360: my $author = &getauthor();
361:
362: my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv);
363: if ($env{'request.course.id'}) {
364: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
365: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
366: unless ($canedit) {
367: unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
368: if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
369: ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
370: ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
371: ($env{'request.course.syllabustime'})) {
372: $showsyllabus = 1;
373: }
374: }
375: if ($env{'request.course.feeds'}) {
376: $showfeeds = 1;
377: }
378: }
379: unless ($canmgr) {
380: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
381: if (keys(%slots) > 0) {
382: $showresv = 1;
383: }
384: }
385: }
386:
387: my ($canmodifycoauthor);
388: if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
389: my $extent = "$env{'user.domain'}/$env{'user.name'}";
390: if ((&Apache::lonnet::allowed('cca',$extent)) ||
391: (&Apache::lonnet::allowed('caa',$extent))) {
392: $canmodifycoauthor = 1;
393: }
394: }
395:
396: my %groups = &Apache::lonnet::get_active_groups(
397: $env{'user.domain'}, $env{'user.name'},
398: $env{'course.' . $env{'request.course.id'} . '.domain'},
399: $env{'course.' . $env{'request.course.id'} . '.num'});
400:
401: my ($roleswitcher_js,$roleswitcher_form);
402:
403: foreach my $menuitem (@secondary_menu) {
404: # evaluate conditions
405: next if ref($menuitem) ne 'ARRAY';
406: next if $$menuitem[4] ne 'always'
407: && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
408: && !$env{'request.course.id'};
409: next if $$menuitem[4] =~ /^mdc/
410: && !$canedit;
411: next if $$menuitem[4] eq 'mdcCourse'
412: && ($crstype eq 'Community');
413: next if $$menuitem[4] eq 'mdcCommunity'
414: && ($crstype eq 'Course');
415: next if $$menuitem[4] eq 'nvgr'
416: && $canvgr;
417: next if $$menuitem[4] eq 'vgr'
418: && !$canvgr;
419: next if $$menuitem[4] eq 'cst'
420: && !$canmodifyuser;
421: next if $$menuitem[4] eq 'ncst'
422: && ($canmodifyuser || !$canviewroster);
423: next if $$menuitem[4] eq 'mgr'
424: && !$canmgr;
425: next if $$menuitem[4] eq 'showresv'
426: && !$showresv;
427: next if $$menuitem[4] eq 'whn'
428: && !$canviewwnew;
429: next if $$menuitem[4] eq 'opa'
430: && !$canmodpara;
431: next if $$menuitem[4] eq 'nvcg'
432: && ($canviewgrps || !%groups);
433: next if $$menuitem[4] eq 'showsyllabus'
434: && !$showsyllabus;
435: next if $$menuitem[4] eq 'showfeeds'
436: && !$showfeeds;
437: next if $$menuitem[4] eq 'author'
438: && !$author;
439: next if $$menuitem[4] eq 'cca'
440: && !$canmodifycoauthor;
441:
442: my $title = $menuitem->[3];
443: if (defined($secondary_submenu{$title})) {
444: my ($link,$target);
445: if ($menuitem->[0] ne '') {
446: $link = $menuitem->[0];
447: $target = '_top';
448: } else {
449: $link = '#';
450: }
451: my @scndsub;
452: if (ref($secondary_submenu{$title}) eq 'ARRAY') {
453: foreach my $item (@{$secondary_submenu{$title}}) {
454: if (ref($item) eq 'ARRAY') {
455: next if ($item->[2] eq 'vgr' && !$canvgr);
456: next if ($item->[2] eq 'opa' && !$canmodpara);
457: next if ($item->[2] eq 'cst' && !$canmodifyuser);
458: next if ($item->[2] eq 'mgr' && !$canmgr);
459: next if ($item->[2] eq 'vcg' && !$canviewgrps);
460: next if ($item->[2] eq 'mdc' && !$canedit);
461: push(@scndsub,$item);
462: }
463: }
464: if (@scndsub > 0) {
465: $menu .= &create_submenu($link,$target,$title,\@scndsub,1);
466: } elsif ($link ne '#') {
467: $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
468: }
469: }
470: } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
471: # special treatment for role selector
472: ($roleswitcher_js,$roleswitcher_form,my $switcher) =
473: &roles_selector(
474: $env{'course.' . $env{'request.course.id'} . '.domain'},
475: $env{'course.' . $env{'request.course.id'} . '.num'},
476: $httphost
477: );
478: $menu .= $switcher;
479: } else {
480: if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
481: my $url = $$menuitem[0];
482: $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
483: if (&Apache::lonnet::is_on_map($url)) {
484: unless ($$menuitem[0] =~ /\?register=1/) {
485: $$menuitem[0] .= '?register=1';
486: }
487: } else {
488: $$menuitem[0] =~ s{\?register=1}{};
489: }
490: }
491: $menu .= &prep_menuitem(\@$menuitem);
492: }
493: }
494: if ($menu =~ /\[url\].*\[symb\]/) {
495: my $escurl = &escape( &Apache::lonenc::check_encrypt(
496: $env{'request.noversionuri'}));
497:
498: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
499: $env{'request.symb'}));
500:
501: if ( $env{'request.state'} eq 'construct'
502: and ( $env{'request.noversionuri'} eq ''
503: || !defined($env{'request.noversionuri'})))
504: {
505: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
506: ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
507: $escurl = &escape($escurl);
508: }
509: $menu =~ s/\[url\]/$escurl/g;
510: $menu =~ s/\[symb\]/$escsymb/g;
511: }
512: $menu =~ s/\[uname\]/$$author{user}/g;
513: $menu =~ s/\[udom\]/$$author{dom}/g;
514: if ($env{'request.course.id'}) {
515: $menu =~ s/\[cnum\]/$cnum/g;
516: $menu =~ s/\[cdom\]/$cdom/g;
517: }
518: if ($menu) {
519: $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
520: }
521: if ($roleswitcher_form) {
522: $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
523: }
524: return $menu;
525: }
526:
527: sub create_submenu {
528: my ($link,$target,$title,$submenu,$translate) = @_;
529: return unless (ref($submenu) eq 'ARRAY');
530: my $disptarget;
531: if ($target ne '') {
532: $disptarget = ' target="'.$target.'"';
533: }
534: my $name;
535: if ($title eq 'Personal') {
536: if ($env{'user.name'} && $env{'user.domain'}) {
537: $name = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
538: } else {
539: $name = &mt($title);
540: }
541: } else {
542: $name = &mt($title);
543: }
544: my $menu = '<li class="LC_hoverable">'.
545: '<a href="'.$link.'"'.$disptarget.'>'.
546: '<span class="LC_nobreak">'.$name.
547: '<span class="LC_fontsize_small" style="font-weight:normal;">'.
548: ' ▼</span></span></a>'.
549: '<ul>';
550: my $count = 0;
551: my $numsub = scalar(@{$submenu});
552: foreach my $item (@{$submenu}) {
553: $count ++;
554: if (ref($item) eq 'ARRAY') {
555: my $href = $item->[0];
556: if ($href =~ /(aboutme|rss\.html)$/) {
557: next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
558: $href =~ s/\[domain\]/$env{'user.domain'}/g;
559: $href =~ s/\[user\]/$env{'user.name'}/g;
560: }
561: my $borderbot;
562: if ($count == $numsub) {
563: $borderbot = 'border-bottom:1px solid black;';
564: }
565: unless (($href eq '') || ($href =~ /^\#/)) {
566: $target = ' target="_top"';
567: }
568: $menu .= '<li style="margin:0;padding:0;'.
569: $borderbot.'"><a href="'.$href.'"'.$target.'>';
570: if ($translate) {
571: $menu .= &mt($item->[1]);
572: } else {
573: $menu .= $item->[1];
574: }
575: $menu .= '</a></li>';
576: }
577: }
578: $menu .= '</ul></li>';
579: return $menu;
580: }
581:
582: sub registerurl {
583: my ($forcereg) = @_;
584: my $result = '';
585: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
586: my $force_title='';
587: if ($env{'request.state'} eq 'construct') {
588: $force_title=&Apache::lonxml::display_title();
589: }
590: if (($env{'environment.remote'} ne 'on') ||
591: ((($env{'request.publicaccess'}) ||
592: (!&Apache::lonnet::is_on_map(
593: &unescape($env{'request.noversionuri'})))) &&
594: (!$forcereg))) {
595: return
596: $result
597: .'<script type="text/javascript">'."\n"
598: .'// <![CDATA['."\n"
599: .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
600: .'// ]]>'."\n"
601: .'</script>'
602: .$force_title;
603: }
604: # Graphical display after login only
605: if ($env{'request.registered'} && !$forcereg) { return ''; }
606: $result.=&innerregister($forcereg);
607: return $result.$force_title;
608: }
609:
610: sub innerregister {
611: my ($forcereg,$bread_crumbs,$group) = @_;
612: my $const_space = ($env{'request.state'} eq 'construct');
613: my $is_const_dir = 0;
614:
615: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
616:
617: $env{'request.registered'} = 1;
618:
619: my $noremote = ($env{'environment.remote'} ne 'on');
620:
621: undef(@inlineremote);
622:
623: my $reopen=&Apache::lonmenu::reopenmenu();
624:
625: my $newmail='';
626:
627: if (&Apache::lonmsg::newmail() && !$noremote) {
628: # We have new mail and remote is up
629: $newmail= 'swmenu.setstatus("you have","messages");';
630: }
631:
632: my ($mapurl,$resurl);
633:
634: if ($env{'request.course.id'}) {
635: if ($env{'request.symb'}) {
636: ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
637: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
638:
639: my $maptitle = &Apache::lonnet::gettitle($mapurl);
640: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
641:
642:
643: #SD
644: #course_type only Course and Community?
645: #
646: my @crumbs;
647: unless (($forcereg) &&
648: ($env{'request.noversionuri'} eq '/adm/navmaps') &&
649: ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
650: @crumbs = ({text => Apache::loncommon::course_type()
651: . ' Contents',
652: href => "Javascript:gopost('/adm/navmaps','')"});
653: }
654: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
655: push(@crumbs, {text => '...',
656: no_mt => 1});
657: }
658:
659: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
660: && $maptitle ne 'default.sequence'
661: && $maptitle ne $coursetitle);
662:
663: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
664: &Apache::lonhtmlcommon::clear_breadcrumbs();
665: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
666: } else {
667: $resurl = $env{'request.noversionuri'};
668: my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
669: my $crstype = &Apache::loncommon::course_type();
670: my $title = &mt('View Resource');
671: if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
672: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
673: &Apache::lonhtmlcommon::clear_breadcrumbs();
674: if ($env{'form.title'}) {
675: $title = $env{'form.title'};
676: }
677: my $trail;
678: if ($env{'form.folderpath'}) {
679: &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
680: ($trail) =
681: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
682: } else {
683: &Apache::lonhtmlcommon::add_breadcrumb(
684: {text => "Supplemental $crstype Content",
685: href => "javascript:gopost('/adm/supplemental','')"});
686: $title = &mt('View Resource');
687: ($trail) =
688: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
689: }
690: return $trail;
691: } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
692: &Apache::lonhtmlcommon::clear_breadcrumbs();
693: &prepare_functions('/public'.$courseurl."/syllabus",
694: $forcereg,$group,undef,undef,1);
695: $title = &mt('Syllabus File');
696: my ($trail) =
697: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
698: return $trail;
699: }
700: unless ($env{'request.state'} eq 'construct') {
701: &Apache::lonhtmlcommon::clear_breadcrumbs();
702: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
703: }
704: }
705: } elsif (! $const_space){
706: #a situation when we're looking at a resource outside of context of a
707: #course or construction space (e.g. with cumulative rights)
708: &Apache::lonhtmlcommon::clear_breadcrumbs();
709: unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
710: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
711: }
712: }
713: my $timesync = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
714: # =============================================================================
715: # ============================ This is for URLs that actually can be registered
716: if ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
717: || ($forcereg)) {
718:
719: my %swtext;
720: if ($noremote) {
721: %swtext = &get_inline_text();
722: } else {
723: %swtext = &get_rc_text();
724: }
725: my $hwkadd='';
726:
727: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
728: $forceview,$editbutton);
729: if (($resurl =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) ||
730: ($env{'request.role'} !~/^(aa|ca|au)/)) {
731: if (($env{'environment.remote'} eq 'on') && ($env{'request.symb'})) {
732: &Apache::lonhtmlcommon::clear_breadcrumbs();
733: }
734: $editbutton = &prepare_functions($resurl,$forcereg,$group);
735: }
736: if ($editbutton eq '') {
737: $editbutton = &clear(6,1);
738: }
739:
740: #
741: # This applies in course context
742: #
743: if ($env{'request.course.id'}) {
744: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
745: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
746: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
747: my @privs;
748: if ($env{'request.symb'} ne '') {
749: if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
750: push(@privs,('mgr','vgr'));
751: }
752: push(@privs,'opa');
753: }
754: foreach my $priv (@privs) {
755: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
756: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
757: $perms{$priv} =
758: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
759: }
760: }
761: #
762: # Determine whether or not to show Grades and Submissions buttons
763: #
764: if ($env{'request.symb'} ne '' &&
765: $env{'request.filename'}=~/$LONCAPA::assess_re/) {
766: if ($perms{'mgr'}) {
767: $hwkadd.= &switch('','',7,2,'pgrd.png','Content Grades',
768: 'grades[_4]',
769: "gocmd('/adm/grades','gradingmenu')",
770: 'Content Grades');
771: } elsif ($perms{'vgr'}) {
772: $hwkadd .= &switch('','',7,2,'subm.png','Content Submissions',
773: 'missions[_1]',
774: "gocmd('/adm/grades','submission')",
775: 'Content Submissions');
776: }
777: }
778: if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
779: $hwkadd .= &switch('','',7,3,'pparm.png','Content Settings',
780: 'parms[_2]',"gocmd('/adm/parmset','set')",
781: 'Content Settings');
782: }
783: # End grades/submissions check
784:
785: #
786: # This applies to items inside a folder/page modifiable in the course.
787: #
788: if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
789: my $text = 'Edit Folder';
790: if (($mapurl =~ /\.page$/) ||
791: ($env{'request.symb'}=~
792: m{uploaded/$cdom/$cnum/default_\d+\.page$})) {
793: $text = 'Edit Page';
794: }
795: $hwkadd .= &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
796: "gocmd('/adm/coursedocs','direct')",
797: 'Folder/Page Content');
798: }
799: # End modifiable folder/page container check
800: }
801: # End course context
802:
803: # Prepare the rest of the buttons
804: my ($menuitems,$got_prt,$got_wishlist,$cstritems);
805: if ($const_space) {
806: #
807: # We are in construction space
808: #
809:
810: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
811: my ($udom,$uname,$thisdisfn) =
812: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
813: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
814: if ($currdir =~ m-/$-) {
815: $is_const_dir = 1;
816: } else {
817: $currdir =~ s|[^/]+$||;
818: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
819: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
820: #
821: # Probably should be in mydesk.tab
822: #
823: $menuitems=(<<ENDMENUITEMS);
824: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
825: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
826: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
827: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
828: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
829: ENDMENUITEMS
830: unless ($noremote) {
831: $cstritems = $menuitems;
832: undef($menuitems);
833: }
834: }
835: if (ref($bread_crumbs) eq 'ARRAY') {
836: &Apache::lonhtmlcommon::clear_breadcrumbs();
837: foreach my $crumb (@{$bread_crumbs}){
838: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
839: }
840: }
841: } elsif ( defined($env{'request.course.id'}) &&
842: $env{'request.symb'} ne '' ) {
843: #
844: # We are in a course and looking at a registered URL
845: # Should probably be in mydesk.tab
846: #
847:
848: $menuitems=(<<ENDMENUITEMS);
849: c&3&1
850: s&2&1&back.png&$swtext{'back'}&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
851: s&2&3&forw.png&$swtext{'forw'}&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
852: c&6&3
853: c&8&1
854: c&8&2
855: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
856: ENDMENUITEMS
857: $got_prt = 1;
858: if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
859: && (!$env{'request.enc'})) {
860: # wishlist is only available for users with access to resource-pool
861: # and links can only be set for resources within the resource-pool
862: $menuitems .= (<<ENDMENUITEMS);
863: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink()&Save a link for this resource in my personal Stored Links repository&&1
864: ENDMENUITEMS
865: $got_wishlist = 1;
866: }
867:
868: my $currentURL = &Apache::loncommon::get_symb();
869: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
870: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
871: $menuitems.="s&9&3&";
872: if(length($annotation) > 0){
873: $menuitems.="anot2.png";
874: }else{
875: $menuitems.="anot.png";
876: }
877: $menuitems.="&$swtext{'anot'}&tations[_1]&annotate()&";
878: $menuitems.="Make notes and annotations about this resource&&1\n";
879:
880: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
881: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
882: $menuitems.=(<<ENDREALRES);
883: s&6&3&catalog.png&$swtext{'catalog'}&info[_1]&catalog_info()&Show Metadata
884: ENDREALRES
885: }
886: unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
887: ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) {
888: $menuitems.=(<<ENDREALRES);
889: s&8&1&eval.png&$swtext{'eval'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
890: ENDREALRES
891: }
892: unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
893: $menuitems.=(<<ENDREALRES);
894: s&8&2&fdbk.png&$swtext{'fdbk'}&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
895: ENDREALRES
896: }
897: }
898: }
899: if ($env{'request.uri'} =~ /^\/res/) {
900: unless ($got_prt) {
901: $menuitems .= (<<ENDMENUITEMS);
902: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
903: ENDMENUITEMS
904: $got_prt = 1;
905: }
906: unless ($got_wishlist) {
907: if (($env{'user.adv'}) && (!$env{'request.enc'})) {
908: # wishlist is only available for users with access to resource-pool
909: $menuitems .= (<<ENDMENUITEMS);
910: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository&&1
911: ENDMENUITEMS
912: $got_wishlist = 1;
913: }
914: }
915: }
916: unless ($got_prt) {
917: $menuitems .= (<<ENDMENUITEMS);
918: c&8&3
919: ENDMENUITEMS
920: }
921: unless ($got_wishlist) {
922: $menuitems .= (<<ENDMENUITEMS);
923: c&9&1
924: ENDMENUITEMS
925: }
926: my $buttons='';
927: foreach (split(/\n/,$menuitems)) {
928: my ($command,@rest)=split(/\&/,$_);
929: my $idx=10*$rest[0]+$rest[1];
930: if (&hidden_button_check() eq 'yes') {
931: if ($idx == 21 ||$idx == 23) {
932: $buttons.=&switch('','',@rest);
933: } else {
934: $buttons.=&clear(@rest);
935: }
936: } else {
937: if ($command eq 's') {
938: $buttons.=&switch('','',@rest);
939: } else {
940: $buttons.=&clear(@rest);
941: }
942: }
943: }
944: if ($noremote) {
945: my $addremote=0;
946: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
947: if ($addremote) {
948:
949: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
950:
951: &Apache::lonhtmlcommon::add_breadcrumb_tool(
952: 'navigation', @inlineremote[21,23]);
953:
954: my $countdown = &countdown_timer();
955: if (&hidden_button_check() eq 'yes') {
956: if ($countdown) {
957: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
958: }
959: } else {
960: my @tools = @inlineremote[93,91,81,82,83];
961: if ($countdown) {
962: unshift(@tools,$countdown);
963: }
964: &Apache::lonhtmlcommon::add_breadcrumb_tool(
965: 'tools',@tools);
966:
967: #publish button in construction space
968: if ($env{'request.state'} eq 'construct'){
969: &Apache::lonhtmlcommon::add_breadcrumb_tool(
970: 'advtools', $inlineremote[63]);
971: } else {
972: &Apache::lonhtmlcommon::add_breadcrumb_tool(
973: 'tools', $inlineremote[63]);
974: }
975: &advtools_crumbs(@inlineremote);
976: }
977: }
978: return &Apache::lonhtmlcommon::scripttag('', 'start')
979: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
980: . &Apache::lonhtmlcommon::scripttag('', 'end');
981:
982: } else {
983: my $cstrcrumbs;
984: if ($const_space) {
985: foreach (split(/\n/,$cstritems)) {
986: my ($command,@rest)=split(/\&/,$_);
987: my $idx=10*$rest[0]+$rest[1];
988: &switch('','',@rest);
989: }
990: &Apache::lonhtmlcommon::add_breadcrumb_tool('advtools',
991: @inlineremote[63,61,71,72]);
992:
993: $cstrcrumbs = &Apache::lonhtmlcommon::scripttag('', 'start')
994: .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
995: .&Apache::lonhtmlcommon::scripttag('', 'end');
996: }
997: my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
998: $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
999: my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1000: my $navstatus=&get_nav_status();
1001: my $clearcstr;
1002:
1003: if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1004: return <<ENDREGTHIS;
1005:
1006: <script type="text/javascript">
1007: // <![CDATA[
1008: // BEGIN LON-CAPA Internal
1009: var swmenu=null;
1010:
1011: function LONCAPAreg() {
1012: swmenu=$reopen;
1013: swmenu.clearTimeout(swmenu.menucltim);
1014: $timesync
1015: $newmail
1016: $buttons
1017: swmenu.currentURL="$requri";
1018: swmenu.reloadURL=swmenu.currentURL+window.location.search;
1019: swmenu.currentSymb="$cursymb";
1020: swmenu.reloadSymb="$cursymb";
1021: swmenu.currentStale=0;
1022: $navstatus
1023: $hwkadd
1024: $editbutton
1025: }
1026:
1027: function LONCAPAstale() {
1028: swmenu=$reopen
1029: swmenu.currentStale=1;
1030: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
1031: swmenu.switchbutton
1032: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
1033: }
1034: swmenu.clearbut(7,2);
1035: swmenu.clearbut(7,3);
1036: swmenu.menucltim=swmenu.setTimeout(
1037: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1038: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1039: 2000);
1040: }
1041:
1042: // END LON-CAPA Internal
1043: // ]]>
1044: </script>
1045:
1046: $cstrcrumbs
1047: ENDREGTHIS
1048: }
1049: } else {
1050: unless ($noremote) {
1051: # Not registered, graphical
1052: return (<<ENDDONOTREGTHIS);
1053:
1054: <script type="text/javascript">
1055: // <![CDATA[
1056: // BEGIN LON-CAPA Internal
1057: var swmenu=null;
1058:
1059: function LONCAPAreg() {
1060: swmenu=$reopen
1061: $timesync
1062: swmenu.currentStale=1;
1063: swmenu.clearbut(2,1);
1064: swmenu.clearbut(2,3);
1065: swmenu.clearbut(8,1);
1066: swmenu.clearbut(8,2);
1067: swmenu.clearbut(8,3);
1068: swmenu.clearbut(9,1);
1069: if (swmenu.currentURL) {
1070: swmenu.switchbutton
1071: (3,1,'reload.gif','return','location','go(currentURL)');
1072: } else {
1073: swmenu.clearbut(3,1);
1074: }
1075: }
1076:
1077: function LONCAPAstale() {
1078: }
1079:
1080: // END LON-CAPA Internal
1081: // ]]>
1082: </script>
1083: ENDDONOTREGTHIS
1084:
1085: }
1086: return '';
1087: }
1088: }
1089:
1090: sub get_inline_text {
1091: my %text = (
1092: pgrd => 'Content Grades',
1093: subm => 'Content Submissions',
1094: pparm => 'Content Settings',
1095: docs => 'Folder/Page Content',
1096: pcstr => 'Edit',
1097: prt => 'Print',
1098: alnk => 'Stored Links',
1099: anot => 'Notes',
1100: catalog => 'Info',
1101: eval => 'Evaluate',
1102: fdbk => 'Feedback',
1103: );
1104: return %text;
1105: }
1106:
1107: sub get_rc_text {
1108: my %text = (
1109: pgrd => 'problem[_1]',
1110: subm => 'view sub-[_1]',
1111: pparm => 'problem[_2]',
1112: pcstr => 'edit[_1]',
1113: prt => 'prepare[_1]',
1114: back => 'backward[_1]',
1115: forw => 'forward[_1]',
1116: alnk => 'add to[_1]',
1117: anot => 'anno-[_1]',
1118: catalog => 'catalog[_2]',
1119: eval => 'evaluate[_1]',
1120: fdbk => 'feedback[_1]',
1121: );
1122: return %text;
1123: }
1124:
1125: sub loadevents() {
1126: if ($env{'request.state'} eq 'construct' ||
1127: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1128: return 'LONCAPAreg();';
1129: }
1130:
1131: sub unloadevents() {
1132: if ($env{'request.state'} eq 'construct' ||
1133: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1134: return 'LONCAPAstale();';
1135: }
1136:
1137: sub startupremote {
1138: my ($lowerurl)=@_;
1139: unless ($env{'environment.remote'} eq 'on') {
1140: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
1141: }
1142: #
1143: # The Remote actually gets launched!
1144: #
1145: my $configmenu=&rawconfig();
1146: my $esclowerurl=&escape($lowerurl);
1147: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1148: return(<<ENDREMOTESTARTUP);
1149: <script type="text/javascript">
1150: // <![CDATA[
1151: var timestart;
1152: function wheelswitch() {
1153: if (typeof(document.wheel) != 'undefined') {
1154: if (typeof(document.wheel.spin) != 'undefined') {
1155: var date=new Date();
1156: var waited=Math.round(30-((date.getTime()-timestart)/1000));
1157: document.wheel.spin.value=$message;
1158: }
1159: }
1160: if (window.status=='|') {
1161: window.status='/';
1162: } else {
1163: if (window.status=='/') {
1164: window.status='-';
1165: } else {
1166: if (window.status=='-') {
1167: window.status='\\\\';
1168: } else {
1169: if (window.status=='\\\\') { window.status='|'; }
1170: }
1171: }
1172: }
1173: }
1174:
1175: // ---------------------------------------------------------- The wait function
1176: var canceltim;
1177: function wait() {
1178: if ((menuloaded==1) || (tim==1)) {
1179: window.status='Done.';
1180: if (tim==0) {
1181: clearTimeout(canceltim);
1182: $configmenu
1183: window.location='$lowerurl';
1184: } else {
1185: window.location='/adm/remote?action=collapse&url=$esclowerurl';
1186: }
1187: } else {
1188: wheelswitch();
1189: setTimeout('wait();',200);
1190: }
1191: }
1192:
1193: function main() {
1194: canceltim=setTimeout('tim=1;',30000);
1195: window.status='-';
1196: var date=new Date();
1197: timestart=date.getTime();
1198: wait();
1199: }
1200:
1201: // ]]>
1202: </script>
1203: ENDREMOTESTARTUP
1204: }
1205:
1206: sub setflags() {
1207: return(<<ENDSETFLAGS);
1208: <script type="text/javascript">
1209: // <![CDATA[
1210: menuloaded=0;
1211: tim=0;
1212: // ]]>
1213: </script>
1214: ENDSETFLAGS
1215: }
1216:
1217: sub maincall() {
1218: unless ($env{'environment.remote'} eq 'on') { return ''; }
1219: return(<<ENDMAINCALL);
1220: <script type="text/javascript">
1221: // <![CDATA[
1222: main();
1223: // ]]>
1224: </script>
1225: ENDMAINCALL
1226: }
1227:
1228: sub load_remote_msg {
1229: my ($lowerurl)=@_;
1230:
1231: unless ($env{'environment.remote'} eq 'on') { return ''; }
1232:
1233: my $esclowerurl=&escape($lowerurl);
1234: my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
1235: ,'<a href="/adm/remote?action=collapse&url='.$esclowerurl.'">'
1236: ,'</a>');
1237: return(<<ENDREMOTEFORM);
1238: <p>
1239: <form name="wheel">
1240: <input name="spin" type="text" size="60" />
1241: </form>
1242: </p>
1243: <p>$link</p>
1244: ENDREMOTEFORM
1245: }
1246:
1247: sub get_menu_name {
1248: my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
1249: $hostid =~ s/\W//g;
1250: return 'LCmenu'.$hostid;
1251: }
1252:
1253:
1254: sub reopenmenu {
1255: unless ($env{'environment.remote'} eq 'on') { return ''; }
1256: my $menuname = &get_menu_name();
1257: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1258: return('window.open('.$nothing.',"'.$menuname.'","",false);');
1259: }
1260:
1261:
1262: sub open {
1263: my $returnval='';
1264: unless ($env{'environment.remote'} eq 'on') {
1265: return
1266: '<script type="text/javascript">'."\n"
1267: .'// <![CDATA['."\n"
1268: .'self.name="loncapaclient";'."\n"
1269: .'// ]]>'."\n"
1270: .'</script>';
1271: }
1272: my $menuname = &get_menu_name();
1273:
1274: # unless (shift eq 'unix') {
1275: # resizing does not work on linux because of virtual desktop sizes
1276: # $returnval.=(<<ENDRESIZE);
1277: #if (window.screen) {
1278: # self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1279: # self.moveTo(190,15);
1280: #}
1281: #ENDRESIZE
1282: # }
1283: $returnval=(<<ENDOPEN);
1284: // <![CDATA[
1285: window.status='Opening LON-CAPA Remote Control';
1286: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
1287: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1288: self.name='loncapaclient';
1289: // ]]>
1290: ENDOPEN
1291: return '<script type="text/javascript">'.$returnval.'</script>';
1292: }
1293:
1294: sub get_editbutton {
1295: my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
1296: my $jscall;
1297: if (($forceview) && ($env{'form.todocs'})) {
1298: my ($folderpath,$command);
1299: if ($env{'request.symb'}) {
1300: $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
1301: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
1302: $folderpath = $env{'form.folderpath'};
1303: $command = '&forcesupplement=1';
1304: }
1305: $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
1306: $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
1307: } else {
1308: $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1309: $forceedit,$forcereg,$env{'request.symb'},
1310: &escape($env{'form.folderpath'}),
1311: &escape($env{'form.title'}),$env{'form.idx'},
1312: &escape($env{'form.suppurl'},$env{'form.todocs'}));
1313: }
1314: if ($jscall) {
1315: my $icon = 'pcstr.png';
1316: my $label = 'Edit';
1317: if ($forceview) {
1318: $icon = 'tolastloc.png';
1319: $label = 'Exit Editing';
1320: }
1321: my $infunc = 1;
1322: my $clearbutton;
1323: if ($env{'environment.remote'} eq 'on') {
1324: if ($cfile =~ m{^/priv/}) {
1325: undef($infunc);
1326: $label = 'edit';
1327: } else {
1328: $clearbutton = 1;
1329: }
1330: }
1331: my $editor = &switch('','',6,1,$icon,$label,'resource[_2]',
1332: $jscall,"Edit this resource",'','',$infunc);
1333: if ($infunc) {
1334: return 1;
1335: } elsif ($clearbutton) {
1336: return &clear(6,1);
1337: } else {
1338: return $editor;
1339: }
1340: }
1341: return;
1342: }
1343:
1344: sub prepare_functions {
1345: my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$forbodytag) = @_;
1346: unless ($env{'request.registered'}) {
1347: undef(@inlineremote);
1348: }
1349: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
1350: $forceview);
1351:
1352: if ($env{'request.course.id'}) {
1353: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1354: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1355: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1356: }
1357:
1358: my $editbutton = '';
1359: #
1360: # Determine whether or not to display 'Edit' icon/button
1361: #
1362: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1363: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1364: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1365: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1366: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1367: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
1368: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1369: $forceedit,$forceview,$forcereg);
1370: }
1371: } elsif ((!$env{'request.course.id'}) &&
1372: ($env{'user.author'}) && ($env{'request.filename'}) &&
1373: ($env{'request.role'} !~/^(aa|ca|au)/)) {
1374: #
1375: # Currently do not have the role of author or co-author.
1376: # Do we have authoring privileges for the resource?
1377: #
1378: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1379: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1380: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1381: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1382: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
1383: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1384: $forceedit,$forceview,$forcereg);
1385: }
1386: } elsif ($env{'request.course.id'}) {
1387: #
1388: # This applies in course context
1389: #
1390: if (($perms{'mdc'}) &&
1391: (($resurl eq "/public/$cdom/$cnum/syllabus") ||
1392: ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
1393: $cfile = $resurl;
1394: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1395: if ($env{'form.forceedit'}) {
1396: $forceview = 1;
1397: } else {
1398: $forceedit = 1;
1399: }
1400: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1401: $forceedit,$forceview,$forcereg);
1402: } elsif (($resurl eq '/adm/extresedit') &&
1403: (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
1404: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1405: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1406: $env{'form.symb'});
1407: if ($cfile ne '') {
1408: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1409: $forceedit,$forceview,$forcereg,
1410: $env{'form.title'},$env{'form.suppurl'});
1411: }
1412: } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
1413: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
1414: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1415: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1416: $env{'form.symb'});
1417: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1418: $forceedit,$forceview,$forcereg);
1419: } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
1420: ($resurl ne '/cgi-bin/printout.pl')) {
1421: if ($env{'request.filename'}) {
1422: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1423: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1424: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1425: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1426: if ($cfile ne '') {
1427: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1428: $forceedit,$forceview,$forcereg);
1429: }
1430: }
1431: }
1432: }
1433: # End determination of 'Edit' icon/button display
1434:
1435: if ($env{'request.course.id'}) {
1436: # This applies to about me page for users in a course
1437: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1438: my ($sdom,$sname) = ($1,$2);
1439: unless (&Apache::lonnet::is_course($sdom,$sname)) {
1440: &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
1441: '',
1442: "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
1443: 'Send message to specific user','','',1);
1444: }
1445: my $hideprivileged = 1;
1446: if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
1447: $hideprivileged)) {
1448: foreach my $priv ('vsa','vgr','srm') {
1449: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1450: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1451: $perms{$priv} =
1452: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1453: }
1454: }
1455: if ($perms{'vsa'}) {
1456: &switch('','',6,5,'trck-22x22.png','Activity',
1457: '',
1458: "go('/adm/trackstudent?selected_student=$sname:$sdom')",
1459: 'View recent activity by this person','','',1);
1460: }
1461: if ($perms{'vgr'}) {
1462: &switch('','',6,6,'rsrv-22x22.png','Reservations',
1463: '',
1464: "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
1465: 'Slot reservation history','','',1);
1466: }
1467: if ($perms{'srm'}) {
1468: &switch('','',6,7,'contact-new-22x22.png','Records',
1469: '',
1470: "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
1471: 'Add records','','',1);
1472: }
1473: }
1474: }
1475: if (($env{'form.folderpath'} =~ /^supplemental/) &&
1476: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
1477: (($resurl =~ m{^/adm/wrapper/ext/}) ||
1478: ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1479: ($resurl eq '/adm/supplemental') ||
1480: ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
1481: ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1482: my @folders=split('&',$env{'form.folderpath'});
1483: if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1484: my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
1485: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1486: "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path'",
1487: 'Folder/Page Content','','',1);
1488: }
1489: }
1490: }
1491:
1492: # End checking for items for about me page for users in a course
1493: if ($docscrumbs) {
1494: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1495: &advtools_crumbs(@inlineremote);
1496: return $editbutton;
1497: } elsif (($env{'request.registered'}) && (!ref($forbodytag))) {
1498: return $editbutton;
1499: } else {
1500: if (ref($bread_crumbs) eq 'ARRAY') {
1501: if (@inlineremote > 0) {
1502: if (ref($advtools) eq 'ARRAY') {
1503: @{$advtools} = @inlineremote;
1504: }
1505: }
1506: return;
1507: } elsif (@inlineremote > 0) {
1508: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1509: &advtools_crumbs(@inlineremote);
1510: if (ref($forbodytag)) {
1511: $$forbodytag =
1512: &Apache::lonhtmlcommon::scripttag('', 'start')
1513: .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
1514: .&Apache::lonhtmlcommon::scripttag('', 'end');
1515: }
1516: return;
1517: }
1518: }
1519: }
1520:
1521: sub advtools_crumbs {
1522: my @funcs = @_;
1523: if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
1524: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1525: 'advtools', @funcs[61,64,65,66,67,74]);
1526: } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
1527: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1528: 'advtools', @funcs[61,71,72,73,74,92]);
1529: } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
1530: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1531: 'advtools', $funcs[61]);
1532: }
1533: }
1534:
1535: # ================================================================== Raw Config
1536:
1537: sub clear {
1538: my ($row,$col)=@_;
1539: if ($env{'environment.remote'} eq 'on') {
1540: if (($row<1) || ($row>13)) { return ''; }
1541: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1542: } else {
1543: $inlineremote[10*$row+$col]='';
1544: return '';
1545: }
1546: }
1547:
1548: # ============================================ Switch a button or create a link
1549: # Switch acts on the javascript that is executed when a button is clicked.
1550: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1551:
1552: sub switch {
1553: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc)=@_;
1554: $act=~s/\$uname/$uname/g;
1555: $act=~s/\$udom/$udom/g;
1556: $top=&mt($top);
1557: $bot=&mt($bot);
1558: $desc=&mt($desc);
1559: my $idx=10*$row+$col;
1560: $category_members{$cat}.=':'.$idx;
1561:
1562: if (($env{'environment.remote'} eq 'on') && (!$infunc)) {
1563: if (($row<1) || ($row>13)) { return ''; }
1564: if ($env{'request.state'} eq 'construct') {
1565: my $text = $top.' '.$bot;
1566: $text=~s/\s*\-\s*//gs;
1567: my $pic = '<img alt="'.$text.'" src="'.
1568: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1569: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1570: $inlineremote[$idx] =
1571: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.
1572: $pic.'<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
1573: }
1574: # Remote
1575: $img=~s/\.png$/\.gif/;
1576: return "\n".
1577: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1578: }
1579:
1580: # Inline Menu
1581: if ($nobreak==2) { return ''; }
1582: my $text=$top.' '.$bot;
1583: $text=~s/\s*\-\s*//gs;
1584:
1585: my $pic=
1586: '<img alt="'.$text.'" src="'.
1587: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1588: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1589: if ($env{'browser.interface'} eq 'faketextual') {
1590: # Main Menu
1591: if ($nobreak==3) {
1592: $inlineremote[$idx]="\n".
1593: '<td class="LC_menubuttons_text" align="right">'.$text.
1594: '</td><td align="left">'.
1595: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1596: } elsif ($nobreak) {
1597: $inlineremote[$idx]="\n<tr>".
1598: '<td align="left">'.
1599: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1600: <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>';
1601: } else {
1602: $inlineremote[$idx]="\n<tr>".
1603: '<td align="left">'.
1604: '<a href="javascript:'.$act.';">'.$pic.
1605: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1606: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1607: }
1608: } else {
1609: # Inline Menu
1610: my @tools = (93,91,81,82,83);
1611: unless ($env{'request.state'} eq 'construct') {
1612: push(@tools,63);
1613: }
1614: if (($env{'environment.icons'} eq 'iconsonly') &&
1615: (grep(/^$idx$/,@tools))) {
1616: $inlineremote[$idx] =
1617: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
1618: } else {
1619: $inlineremote[$idx] =
1620: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1621: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
1622: }
1623: }
1624: return '';
1625: }
1626:
1627: sub secondlevel {
1628: my $output='';
1629: my
1630: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1631: if ($prt eq 'any') {
1632: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1633: } elsif ($prt=~/^r(\w+)/) {
1634: if ($rol eq $1) {
1635: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1636: }
1637: }
1638: return $output;
1639: }
1640:
1641: sub openmenu {
1642: my $menuname = &get_menu_name();
1643: unless ($env{'environment.remote'} eq 'on') { return ''; }
1644: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1645: return "window.open(".$nothing.",'".$menuname."');";
1646: }
1647:
1648: sub inlinemenu {
1649: undef(@inlineremote);
1650: undef(%category_members);
1651: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1652: &rawconfig(1);
1653: my $output='<table><tr>';
1654: for (my $col=1; $col<=2; $col++) {
1655: $output.='<td class="LC_mainmenu_col_fieldset">';
1656: for (my $row=1; $row<=8; $row++) {
1657: foreach my $cat (keys(%category_members)) {
1658: if ($category_positions{$cat} ne "$col,$row") { next; }
1659: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1660: $output.='<div class="LC_Box LC_400Box">';
1661: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1662: $output.='<table>';
1663: my %active=();
1664: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1665: if ($inlineremote[$menu_item]) {
1666: $active{$menu_item}=1;
1667: }
1668: }
1669: foreach my $item (sort(keys(%active))) {
1670: $output.=$inlineremote[$item];
1671: }
1672: $output.='</table>';
1673: $output.='</div>';
1674: }
1675: }
1676: $output.="</td>";
1677: }
1678: $output.="</tr></table>";
1679: return $output;
1680: }
1681:
1682: sub rawconfig {
1683: #
1684: # This evaluates mydesk.tab
1685: # Need to add more positions and more privileges to deal with all
1686: # menu items.
1687: #
1688: my $textualoverride=shift;
1689: my $output='';
1690: if ($env{'environment.remote'} eq 'on') {
1691: $output.=
1692: "window.status='Opening Remote Control';var swmenu=".&openmenu().
1693: "\nwindow.status='Configuring Remote Control ';";
1694: } else {
1695: unless ($textualoverride) { return ''; }
1696: }
1697: my $uname=$env{'user.name'};
1698: my $udom=$env{'user.domain'};
1699: my $adv=$env{'user.adv'};
1700: my $show_course=&Apache::loncommon::show_course();
1701: my $author=$env{'user.author'};
1702: my $crs='';
1703: my $crstype='';
1704: if ($env{'request.course.id'}) {
1705: $crs='/'.$env{'request.course.id'};
1706: if ($env{'request.course.sec'}) {
1707: $crs.='_'.$env{'request.course.sec'};
1708: }
1709: $crs=~s/\_/\//g;
1710: $crstype = &Apache::loncommon::course_type();
1711: }
1712: my $pub=($env{'request.state'} eq 'published');
1713: my $con=($env{'request.state'} eq 'construct');
1714: my $rol=$env{'request.role'};
1715: my $requested_domain;
1716: if ($rol) {
1717: $requested_domain = $env{'request.role.domain'};
1718: }
1719: foreach my $line (@desklines) {
1720: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1721: $prt=~s/\$uname/$uname/g;
1722: $prt=~s/\$udom/$udom/g;
1723: if ($prt =~ /\$crs/) {
1724: next unless ($env{'request.course.id'});
1725: next if ($crstype eq 'Community');
1726: $prt=~s/\$crs/$crs/g;
1727: } elsif ($prt =~ /\$cmty/) {
1728: next unless ($env{'request.course.id'});
1729: next if ($crstype ne 'Community');
1730: $prt=~s/\$cmty/$crs/g;
1731: }
1732: if ($prt =~ m/\$requested_domain/) {
1733: if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
1734: $prt=~s/\$requested_domain/$env{'user.domain'}/g;
1735: } else {
1736: $prt=~s/\$requested_domain/$requested_domain/g;
1737: }
1738: }
1739: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1740: if ($pro eq 'clear') {
1741: $output.=&clear($row,$col);
1742: } elsif ($pro eq 'any') {
1743: $output.=&secondlevel(
1744: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1745: } elsif ($pro eq 'smp') {
1746: unless ($adv) {
1747: $output.=&secondlevel(
1748: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1749: }
1750: } elsif ($pro eq 'adv') {
1751: if ($adv) {
1752: $output.=&secondlevel(
1753: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1754: }
1755: } elsif ($pro eq 'shc') {
1756: if ($show_course) {
1757: $output.=&secondlevel(
1758: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1759: }
1760: } elsif ($pro eq 'nsc') {
1761: if (!$show_course) {
1762: $output.=&secondlevel(
1763: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1764: }
1765: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1766: my $priv = $1;
1767: if ($priv =~ /^mdc(Course|Community)/) {
1768: if ($crstype eq $1) {
1769: $priv = 'mdc';
1770: } else {
1771: next;
1772: }
1773: }
1774: if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
1775: (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
1776: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1777: }
1778: } elsif ($pro eq 'course') {
1779: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1780: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1781: }
1782: } elsif ($pro eq 'community') {
1783: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1784: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1785: }
1786: } elsif ($pro =~ /^courseenv_(.*)$/) {
1787: my $key = $1;
1788: if ($crstype ne 'Community') {
1789: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1790: if ($key eq 'canuse_pdfforms') {
1791: if ($env{'request.course.id'} && $coursepref eq '') {
1792: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1793: $coursepref = $domdefs{'canuse_pdfforms'};
1794: }
1795: }
1796: if ($coursepref) {
1797: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1798: }
1799: }
1800: } elsif ($pro =~ /^communityenv_(.*)$/) {
1801: my $key = $1;
1802: if ($crstype eq 'Community') {
1803: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1804: if ($key eq 'canuse_pdfforms') {
1805: if ($env{'request.course.id'} && $coursepref eq '') {
1806: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1807: $coursepref = $domdefs{'canuse_pdfforms'};
1808: }
1809: }
1810: if ($coursepref) {
1811: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1812: }
1813: }
1814: } elsif ($pro =~ /^course_(.*)$/) {
1815: # Check for permissions inside of a course
1816: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1817: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1818: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1819: )) {
1820: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1821: }
1822: } elsif ($pro =~ /^community_(.*)$/) {
1823: # Check for permissions inside of a community
1824: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1825: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1826: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1827: )) {
1828: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1829: }
1830: } elsif ($pro eq 'author') {
1831: if ($author) {
1832: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1833: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1834: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1835: # Check that we are on the correct machine
1836: my $cadom=$requested_domain;
1837: my $caname=$env{'user.name'};
1838: if (($prt eq 'rca') || ($prt eq 'raa')) {
1839: ($cadom,$caname)=
1840: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1841: }
1842: $act =~ s/\$caname/$caname/g;
1843: $act =~ s/\$cadom/$cadom/g;
1844: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1845: my $allowed=0;
1846: my @ids=&Apache::lonnet::current_machine_ids();
1847: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1848: if ($allowed) {
1849: $output.=&switch($caname,$cadom,
1850: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1851: }
1852: }
1853: }
1854: } elsif ($pro eq 'tools') {
1855: my @tools = ('aboutme','blog','portfolio');
1856: if (grep(/^\Q$prt\E$/,@tools)) {
1857: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1858: $env{'user.domain'},
1859: $prt,undef,'tools')) {
1860: $output.=&clear($row,$col);
1861: next;
1862: }
1863: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1864: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1865: next;
1866: }
1867: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1868: next;
1869: }
1870: my $showreqcrs = &check_for_rcrs();
1871: if (!$showreqcrs) {
1872: $output.=&clear($row,$col);
1873: next;
1874: }
1875: }
1876: $prt='any';
1877: $output.=&secondlevel(
1878: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1879: }
1880: }
1881: if ($env{'environment.remote'} eq 'on') {
1882: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1883: if (&Apache::lonmsg::newmail()) {
1884: $output.='swmenu.setstatus("you have","messages");';
1885: }
1886: }
1887: return $output;
1888: }
1889:
1890: sub check_for_rcrs {
1891: my $showreqcrs = 0;
1892: my @reqtypes = ('official','unofficial','community','textbook');
1893: foreach my $type (@reqtypes) {
1894: if (&Apache::lonnet::usertools_access($env{'user.name'},
1895: $env{'user.domain'},
1896: $type,undef,'requestcourses')) {
1897: $showreqcrs = 1;
1898: last;
1899: }
1900: }
1901: if (!$showreqcrs) {
1902: foreach my $type (@reqtypes) {
1903: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1904: $showreqcrs = 1;
1905: last;
1906: }
1907: }
1908: }
1909: return $showreqcrs;
1910: }
1911:
1912: # ======================================================================= Close
1913:
1914: sub close {
1915: unless ($env{'environment.remote'} eq 'on') { return ''; }
1916: my $menuname = &get_menu_name();
1917: return(<<ENDCLOSE);
1918: <script type="text/javascript">
1919: // <![CDATA[
1920: window.status='Accessing Remote Control';
1921: menu=window.open("/adm/rat/empty.html","$menuname",
1922: "height=350,width=150,scrollbars=no,menubar=no");
1923: window.status='Disabling Remote Control';
1924: menu.active=0;
1925: menu.autologout=0;
1926: window.status='Closing Remote Control';
1927: menu.close();
1928: window.status='Done.';
1929: // ]]>
1930: </script>
1931: ENDCLOSE
1932: }
1933:
1934: sub dc_popup_js {
1935: my %lt = &Apache::lonlocal::texthash(
1936: more => '(More ...)',
1937: less => '(Less ...)',
1938: );
1939: return <<"END";
1940:
1941: function showCourseID() {
1942: document.getElementById('dccid').style.display='block';
1943: document.getElementById('dccid').style.textAlign='left';
1944: document.getElementById('dccid').style.textFace='normal';
1945: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1946: return;
1947: }
1948:
1949: function hideCourseID() {
1950: document.getElementById('dccid').style.display='none';
1951: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1952: return;
1953: }
1954:
1955: END
1956:
1957: }
1958:
1959: sub countdown_toggle_js {
1960: return <<"END";
1961:
1962: function toggleCountdown() {
1963: var countdownid = document.getElementById('duedatecountdown');
1964: var currstyle = countdownid.style.display;
1965: if (currstyle == 'inline') {
1966: countdownid.style.display = 'none';
1967: document.getElementById('ddcountcollapse').innerHTML='';
1968: document.getElementById('ddcountexpand').innerHTML='◄ ';
1969: } else {
1970: countdownid.style.display = 'inline';
1971: document.getElementById('ddcountcollapse').innerHTML='► ';
1972: document.getElementById('ddcountexpand').innerHTML='';
1973: }
1974: return;
1975: }
1976:
1977: END
1978: }
1979:
1980: sub utilityfunctions {
1981: my ($httphost) = @_;
1982: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1983: if ($currenturl =~ m{^/adm/wrapper/ext/}
1984: && $env{'request.external.querystring'} ) {
1985: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1986: }
1987: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1988:
1989: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1990:
1991: my $dc_popup_cid;
1992: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1993: $env{'course.'.$env{'request.course.id'}.
1994: '.domain'}.'/'})) {
1995: $dc_popup_cid = &dc_popup_js();
1996: }
1997:
1998: my $start_page_annotate =
1999: &Apache::loncommon::start_page('Annotator',undef,
2000: {'only_body' => 1,
2001: 'js_ready' => 1,
2002: 'bgcolor' => '#BBBBBB',
2003: 'add_entries' => {
2004: 'onload' => 'javascript:document.goannotate.submit();'}});
2005:
2006: my $end_page_annotate =
2007: &Apache::loncommon::end_page({'js_ready' => 1});
2008:
2009: my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
2010:
2011: my $esc_url=&escape($currenturl);
2012: my $esc_symb=&escape($currentsymb);
2013:
2014: my $countdown = &countdown_toggle_js();
2015:
2016: return (<<ENDUTILITY)
2017: var host="$httphost";
2018: var currentURL=unescape("$esc_url");
2019: var reloadURL=unescape("$esc_url");
2020: var currentSymb=unescape("$esc_symb");
2021:
2022: $dc_popup_cid
2023:
2024: function go(url) {
2025: if (url!='' && url!= null) {
2026: currentURL = null;
2027: currentSymb= null;
2028: window.location.href=host+url;
2029: }
2030: }
2031:
2032: $jumptores
2033:
2034: function gopost(url,postdata) {
2035: if (url!='') {
2036: this.document.server.action=host+url;
2037: this.document.server.postdata.value=postdata;
2038: this.document.server.command.value='';
2039: this.document.server.url.value='';
2040: this.document.server.symb.value='';
2041: this.document.server.submit();
2042: }
2043: }
2044:
2045: function gocmd(url,cmd) {
2046: if (url!='') {
2047: this.document.server.action=host+url;
2048: this.document.server.postdata.value='';
2049: this.document.server.command.value=cmd;
2050: this.document.server.url.value=currentURL;
2051: this.document.server.symb.value=currentSymb;
2052: this.document.server.submit();
2053: }
2054: }
2055:
2056: function gocstr(url,filename) {
2057: if (url == '/adm/cfile?action=delete') {
2058: this.document.cstrdelete.filename.value = filename
2059: this.document.cstrdelete.submit();
2060: return;
2061: }
2062: if (url == '/adm/printout') {
2063: this.document.cstrprint.postdata.value = filename
2064: this.document.cstrprint.curseed.value = 0;
2065: this.document.cstrprint.problemtype.value = 0;
2066: if (this.document.lonhomework) {
2067: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
2068: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
2069: }
2070: if (this.document.lonhomework.problemtype) {
2071: if (this.document.lonhomework.problemtype.value) {
2072: this.document.cstrprint.problemtype.value =
2073: this.document.lonhomework.problemtype.value;
2074: } else if (this.document.lonhomework.problemtype.options) {
2075: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
2076: if (this.document.lonhomework.problemtype.options[i].selected) {
2077: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
2078: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
2079: }
2080: }
2081: }
2082: }
2083: }
2084: }
2085: this.document.cstrprint.submit();
2086: return;
2087: }
2088: if (url !='') {
2089: this.document.constspace.filename.value = filename;
2090: this.document.constspace.action = url;
2091: this.document.constspace.submit();
2092: }
2093: }
2094:
2095: function golist(url) {
2096: if (url!='' && url!= null) {
2097: currentURL = null;
2098: currentSymb= null;
2099: top.location.href=host+url;
2100: }
2101: }
2102:
2103:
2104:
2105: function catalog_info() {
2106: openMyModal(window.location.pathname+'.meta',500,400,'yes');
2107: }
2108:
2109: function chat_win() {
2110: lonchat=window.open(host+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
2111: }
2112:
2113: function group_chat(group) {
2114: var url = host+'/adm/groupchat?group='+group;
2115: var winName = 'LONchat_'+group;
2116: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
2117: }
2118:
2119: function annotate() {
2120: w_Annotator_flag=1;
2121: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
2122: annotator.document.write(
2123: '$start_page_annotate'
2124: +"<form name='goannotate' target='Annotator' method='post' "
2125: +"action='/adm/annotations'>"
2126: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
2127: +"<\\/form>"
2128: +'$end_page_annotate');
2129: annotator.document.close();
2130: }
2131:
2132: function open_StoredLinks_Import(rat) {
2133: var newWin;
2134: if (rat) {
2135: newWin = window.open(host+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
2136: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
2137: }
2138: else {
2139: newWin = window.open(host+'/adm/wishlist?inhibitmenu=yes&mode=import',
2140: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
2141: }
2142: newWin.focus();
2143: }
2144:
2145: (function (\$) {
2146: \$(document).ready(function () {
2147: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
2148: /*\@cc_on
2149: if (!window.XMLHttpRequest) {
2150: \$('.LC_hoverable').each(function () {
2151: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
2152: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
2153: });
2154: }
2155: \@*/
2156: });
2157: }(jQuery));
2158:
2159: $countdown
2160:
2161: ENDUTILITY
2162: }
2163:
2164: sub serverform {
2165: return(<<ENDSERVERFORM);
2166: <form name="server" action="/adm/logout" method="post" target="_top">
2167: <input type="hidden" name="postdata" value="none" />
2168: <input type="hidden" name="command" value="none" />
2169: <input type="hidden" name="url" value="none" />
2170: <input type="hidden" name="symb" value="none" />
2171: </form>
2172: ENDSERVERFORM
2173: }
2174:
2175: sub constspaceform {
2176: return(<<ENDCONSTSPACEFORM);
2177: <form name="constspace" action="/adm/logout" method="post" target="_top">
2178: <input type="hidden" name="filename" value="" />
2179: </form>
2180: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
2181: <input type="hidden" name="action" value="delete" />
2182: <input type="hidden" name="filename" value="" />
2183: </form>
2184: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
2185: <input type="hidden" name="postdata" value="" />
2186: <input type="hidden" name="curseed" value="" />
2187: <input type="hidden" name="problemtype" value="" />
2188: </form>
2189:
2190: ENDCONSTSPACEFORM
2191: }
2192:
2193: sub get_nav_status {
2194: my $navstatus="swmenu.w_loncapanav_flag=";
2195: if ($env{'environment.remotenavmap'} eq 'on') {
2196: $navstatus.="1";
2197: } else {
2198: $navstatus.="-1";
2199: }
2200: return $navstatus;
2201: }
2202:
2203: sub hidden_button_check {
2204: if ( $env{'request.course.id'} eq ''
2205: || $env{'request.role.adv'} ) {
2206:
2207: return;
2208: }
2209: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
2210: return $buttonshide;
2211: }
2212:
2213: sub roles_selector {
2214: my ($cdom,$cnum,$httphost) = @_;
2215: my $crstype = &Apache::loncommon::course_type();
2216: my $now = time;
2217: my (%courseroles,%seccount,%courseprivs);
2218: my $is_cc;
2219: my ($js,$form,$switcher,$switchtext);
2220: my $ccrole;
2221: if ($crstype eq 'Community') {
2222: $ccrole = 'co';
2223: } else {
2224: $ccrole = 'cc';
2225: }
2226: my ($priv,$gotsymb,$destsymb);
2227: my $destinationurl = $ENV{'REQUEST_URI'};
2228: if ($destinationurl =~ /\?symb=/) {
2229: $gotsymb = 1;
2230: } elsif ($destinationurl =~ m{^/enc/}) {
2231: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
2232: if ($plainurl =~ /\?symb=/) {
2233: $gotsymb = 1;
2234: }
2235: }
2236: unless ($gotsymb) {
2237: $destsymb = &Apache::lonnet::symbread();
2238: if ($destsymb ne '') {
2239: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
2240: }
2241: }
2242: my $reqprivs = &required_privs();
2243: if (ref($reqprivs) eq 'HASH') {
2244: my $destination = $destinationurl;
2245: $destination =~ s/(\?.*)$//;
2246: if (exists($reqprivs->{$destination})) {
2247: $priv = $reqprivs->{$destination};
2248: }
2249: }
2250: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
2251: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
2252:
2253: if ((($start) && ($start<0)) ||
2254: (($end) && ($end<$now)) ||
2255: (($start) && ($now<$start))) {
2256: $is_cc = 0;
2257: } else {
2258: $is_cc = 1;
2259: }
2260: }
2261: if ($is_cc) {
2262: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
2263: } else {
2264: my %gotnosection;
2265: foreach my $item (keys(%env)) {
2266: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
2267: my $role = $1;
2268: my $sec = $2;
2269: next if ($role eq 'gr');
2270: my ($start,$end) = split(/\./,$env{$item});
2271: next if (($start && $start > $now) || ($end && $end < $now));
2272: if ($sec eq '') {
2273: if (!$gotnosection{$role}) {
2274: $seccount{$role} ++;
2275: $gotnosection{$role} = 1;
2276: }
2277: }
2278: if ($priv ne '') {
2279: my $cnumsec = $cnum;
2280: if ($sec ne '') {
2281: $cnumsec .= "/$sec";
2282: }
2283: $courseprivs{"$role./$cdom/$cnumsec./"} =
2284: $env{"user.priv.$role./$cdom/$cnumsec./"};
2285: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
2286: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
2287: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
2288: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
2289: }
2290: if (ref($courseroles{$role}) eq 'ARRAY') {
2291: if ($sec ne '') {
2292: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
2293: push(@{$courseroles{$role}},$sec);
2294: $seccount{$role} ++;
2295: }
2296: }
2297: } else {
2298: @{$courseroles{$role}} = ();
2299: if ($sec ne '') {
2300: $seccount{$role} ++;
2301: push(@{$courseroles{$role}},$sec);
2302: }
2303: }
2304: }
2305: }
2306: }
2307: $switchtext = 'Switch role'; # do not translate here
2308: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
2309: my $numdiffsec;
2310: if (keys(%seccount) == 1) {
2311: foreach my $key (keys(%seccount)) {
2312: $numdiffsec = $seccount{$key};
2313: }
2314: }
2315: if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
2316: my @submenu;
2317: $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
2318: $form =
2319: '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
2320: ' <input type="hidden" name="destinationurl" value="'.
2321: &HTML::Entities::encode($destinationurl).'" />'."\n".
2322: ' <input type="hidden" name="gotorole" value="1" />'."\n".
2323: ' <input type="hidden" name="selectrole" value="" />'."\n".
2324: ' <input type="hidden" name="switchrole" value="" />'."\n";
2325: if ($destsymb ne '') {
2326: $form .= ' <input type="hidden" name="destsymb" value="'.
2327: &HTML::Entities::encode($destsymb).'" />'."\n";
2328: }
2329: $form .= '</form>'."\n";
2330: foreach my $role (@roles_order) {
2331: my $include;
2332: if (defined($courseroles{$role})) {
2333: if ($env{'request.role'} =~ m{^\Q$role\E}) {
2334: if ($seccount{$role} > 1) {
2335: $include = 1;
2336: }
2337: } else {
2338: $include = 1;
2339: }
2340: }
2341: if ($include) {
2342: push(@submenu,['javascript:adhocRole('."'$role'".')',
2343: &Apache::lonnet::plaintext($role,$crstype)]);
2344: }
2345: }
2346: foreach my $role (sort(keys(%courseroles))) {
2347: if ($role =~ /^cr/) {
2348: my $include;
2349: if ($env{'request.role'} =~ m{^\Q$role\E}) {
2350: if ($seccount{$role} > 1) {
2351: $include = 1;
2352: }
2353: } else {
2354: $include = 1;
2355: }
2356: if ($include) {
2357: push(@submenu,['javascript:adhocRole('."'$role'".')',
2358: &Apache::lonnet::plaintext($role)]);
2359: }
2360: }
2361: }
2362: if (@submenu > 0) {
2363: $switcher = &create_submenu('','',$switchtext,\@submenu);
2364: }
2365: }
2366: return ($js,$form,$switcher);
2367: }
2368:
2369: sub get_all_courseroles {
2370: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
2371: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
2372: (ref($courseprivs) eq 'HASH')) {
2373: return;
2374: }
2375: my ($result,$cached) =
2376: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
2377: if (defined($cached)) {
2378: if (ref($result) eq 'HASH') {
2379: if ((ref($result->{'roles'}) eq 'HASH') &&
2380: (ref($result->{'seccount'}) eq 'HASH') &&
2381: (ref($result->{'privs'}) eq 'HASH')) {
2382: %{$courseroles} = %{$result->{'roles'}};
2383: %{$seccount} = %{$result->{'seccount'}};
2384: %{$courseprivs} = %{$result->{'privs'}};
2385: return;
2386: }
2387: }
2388: }
2389: my %gotnosection;
2390: my %adv_roles =
2391: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
2392: foreach my $role (keys(%adv_roles)) {
2393: my ($urole,$usec) = split(/:/,$role);
2394: if (!$gotnosection{$urole}) {
2395: $seccount->{$urole} ++;
2396: $gotnosection{$urole} = 1;
2397: }
2398: if (ref($courseroles->{$urole}) eq 'ARRAY') {
2399: if ($usec ne '') {
2400: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
2401: push(@{$courseroles->{$urole}},$usec);
2402: $seccount->{$urole} ++;
2403: }
2404: }
2405: } else {
2406: @{$courseroles->{$urole}} = ();
2407: if ($usec ne '') {
2408: $seccount->{$urole} ++;
2409: push(@{$courseroles->{$urole}},$usec);
2410: }
2411: }
2412: my $area = '/'.$cdom.'/'.$cnum;
2413: if ($usec ne '') {
2414: $area .= '/'.$usec;
2415: }
2416: if ($role =~ /^cr\//) {
2417: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
2418: } else {
2419: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
2420: }
2421: }
2422: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
2423: @{$courseroles->{'st'}} = ();
2424: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
2425: if (keys(%sections_count) > 0) {
2426: push(@{$courseroles->{'st'}},keys(%sections_count));
2427: $seccount->{'st'} = scalar(keys(%sections_count));
2428: }
2429: $seccount->{'st'} ++; # Increment for a section-less student role.
2430: my $rolehash = {
2431: 'roles' => $courseroles,
2432: 'seccount' => $seccount,
2433: 'privs' => $courseprivs,
2434: };
2435: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
2436: return;
2437: }
2438:
2439: sub jump_to_role {
2440: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
2441: my %lt = &Apache::lonlocal::texthash(
2442: this => 'This role has section(s) associated with it.',
2443: ente => 'Enter a specific section.',
2444: orlb => 'Enter a specific section, or leave blank for no section.',
2445: avai => 'Available sections are:',
2446: youe => 'You entered an invalid section choice:',
2447: plst => 'Please try again.',
2448: role => 'The role you selected is not permitted to view the current page.',
2449: swit => 'Switch role, but display Main Menu page instead?',
2450: );
2451: my $js;
2452: if (ref($courseroles) eq 'HASH') {
2453: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
2454: ' var numsec = new Array();'."\n".
2455: ' var rolesections = new Array();'."\n".
2456: ' var rolenames = new Array();'."\n".
2457: ' var roleseclist = new Array();'."\n";
2458: my @items = keys(%{$courseroles});
2459: for (my $i=0; $i<@items; $i++) {
2460: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
2461: my ($secs,$secstr);
2462: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
2463: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
2464: $secs = join('","',@sections);
2465: $secstr = join(', ',@sections);
2466: }
2467: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
2468: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
2469: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
2470: }
2471: }
2472: my $checkroles = 0;
2473: if ($priv && ref($courseprivs) eq 'HASH') {
2474: my (%disallowed,%allowed,@disallow);
2475: foreach my $role (sort(keys(%{$courseprivs}))) {
2476: my $trole;
2477: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
2478: $trole = $1;
2479: }
2480: if (($trole ne '') && ($trole ne 'cm')) {
2481: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
2482: $allowed{$trole} = 1;
2483: } else {
2484: $disallowed{$trole} = 1;
2485: }
2486: }
2487: }
2488: foreach my $trole (keys(%disallowed)) {
2489: unless ($allowed{$trole}) {
2490: push(@disallow,$trole);
2491: }
2492: }
2493: if (@disallow > 0) {
2494: $checkroles = 1;
2495: $js .= " var disallow = new Array('".join("','",@disallow)."');\n".
2496: " var rolecheck = 1;\n";
2497: }
2498: }
2499: if (!$checkroles) {
2500: $js .= " var disallow = new Array();\n".
2501: " rolecheck = 0;\n";
2502: }
2503: return <<"END";
2504: <script type="text/javascript">
2505: //<![CDATA[
2506: function adhocRole(newrole) {
2507: $js
2508: if (newrole == '') {
2509: return;
2510: }
2511: var fullrole = newrole+'./$cdom/$cnum';
2512: var selidx = '';
2513: for (var i=0; i<rolenames.length; i++) {
2514: if (rolenames[i] == newrole) {
2515: selidx = i;
2516: }
2517: }
2518: if (rolecheck > 0) {
2519: for (var i=0; i<disallow.length; i++) {
2520: if (disallow[i] == newrole) {
2521: if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
2522: document.rolechooser.destinationurl.value = '/adm/menu';
2523: } else {
2524: return;
2525: }
2526: }
2527: }
2528: }
2529: var secok = 1;
2530: var secchoice = '';
2531: if (selidx >= 0) {
2532: if (numsec[selidx] > 1) {
2533: secok = 0;
2534: var numrolesec = rolesections[selidx].length;
2535: var msgidx = numsec[selidx] - numrolesec;
2536: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
2537: if (secchoice == '') {
2538: if (msgidx > 0) {
2539: secok = 1;
2540: }
2541: } else {
2542: for (var j=0; j<rolesections[selidx].length; j++) {
2543: if (rolesections[selidx][j] == secchoice) {
2544: secok = 1;
2545: }
2546: }
2547: }
2548: } else {
2549: if (rolesections[selidx].length == 1) {
2550: secchoice = rolesections[selidx][0];
2551: }
2552: }
2553: }
2554: if (secok == 1) {
2555: if (secchoice != '') {
2556: fullrole += '/'+secchoice;
2557: }
2558: } else {
2559: document.rolechooser.elements[roleitem].selectedIndex = 0;
2560: if (secchoice != null) {
2561: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
2562: }
2563: return;
2564: }
2565: if (fullrole == "$env{'request.role'}") {
2566: return;
2567: }
2568: itemid = retrieveIndex('gotorole');
2569: if (itemid != -1) {
2570: document.rolechooser.elements[itemid].name = fullrole;
2571: }
2572: document.rolechooser.switchrole.value = fullrole;
2573: document.rolechooser.selectrole.value = '1';
2574: document.rolechooser.submit();
2575: return;
2576: }
2577:
2578: function retrieveIndex(item) {
2579: for (var i=0;i<document.rolechooser.elements.length;i++) {
2580: if (document.rolechooser.elements[i].name == item) {
2581: return i;
2582: }
2583: }
2584: return -1;
2585: }
2586: // ]]>
2587: </script>
2588: END
2589: }
2590:
2591: sub required_privs {
2592: my $privs = {
2593: '/adm/parmset' => 'opa',
2594: '/adm/courseprefs' => 'opa',
2595: '/adm/whatsnew' => 'whn',
2596: '/adm/populate' => 'cst',
2597: '/adm/trackstudent' => 'vsa',
2598: '/adm/statistics' => 'vgr',
2599: '/adm/setblock' => 'dcm',
2600: '/adm/coursedocs' => 'mdc',
2601: };
2602: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
2603: $privs->{'/adm/classcalc'} = 'vgr',
2604: $privs->{'/adm/assesscalc'} = 'vgr',
2605: $privs->{'/adm/studentcalc'} = 'vgr';
2606: }
2607: return $privs;
2608: }
2609:
2610: sub countdown_timer {
2611: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
2612: ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
2613: my ($type,$hastimeleft,$slothastime);
2614: my $now = time;
2615: if ($env{'request.filename'} =~ /\.task$/) {
2616: $type = 'Task';
2617: } else {
2618: $type = 'problem';
2619: }
2620: my ($status,$accessmsg,$slot_name,$slot) =
2621: &Apache::lonhomework::check_slot_access('0',$type);
2622: if ($slot_name ne '') {
2623: if (ref($slot) eq 'HASH') {
2624: if (($slot->{'starttime'} < $now) &&
2625: ($slot->{'endtime'} > $now)) {
2626: $slothastime = 1;
2627: }
2628: }
2629: }
2630: if ($status ne 'CAN_ANSWER') {
2631: return;
2632: }
2633: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
2634: my @interval=&Apache::lonnet::EXT("resource.0.interval");
2635: if (@interval > 1) {
2636: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
2637: if ($first_access > 0) {
2638: if ($first_access+$interval[0] > time) {
2639: $hastimeleft = 1;
2640: }
2641: }
2642: }
2643: if (($duedate && $duedate > time) ||
2644: (!$duedate && $hastimeleft) ||
2645: ($slot_name ne '' && $slothastime)) {
2646: my ($collapse,$expand,$alttxt,$title,$currdisp);
2647: if ((@interval > 1 && $hastimeleft) ||
2648: ($type eq 'Task' && $slothastime)) {
2649: $currdisp = 'inline';
2650: $collapse = '► ';
2651: } else {
2652: $currdisp = 'none';
2653: $expand = '◄ ';
2654: }
2655: unless ($env{'environment.icons'} eq 'iconsonly') {
2656: $alttxt = &mt('Timer');
2657: $title = $alttxt.' ';
2658: }
2659: my $desc = &mt('Countdown to due date/time');
2660: return <<END;
2661:
2662: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
2663: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
2664: $collapse
2665: </span></a>
2666: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
2667: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
2668: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
2669: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
2670: END
2671: }
2672: }
2673: return;
2674: }
2675:
2676: # ================================================================ Main Program
2677:
2678: BEGIN {
2679: if (! defined($readdesk)) {
2680: {
2681: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
2682: if ( CORE::open( my $config,"<$tabfile") ) {
2683: while (my $configline=<$config>) {
2684: $configline=(split(/\#/,$configline))[0];
2685: $configline=~s/^\s+//;
2686: chomp($configline);
2687: if ($configline=~/^cat\:/) {
2688: my @entries=split(/\:/,$configline);
2689: $category_positions{$entries[2]}=$entries[1];
2690: $category_names{$entries[2]}=$entries[3];
2691: } elsif ($configline=~/^prim\:/) {
2692: my @entries = (split(/\:/, $configline))[1..6];
2693: push(@primary_menu,\@entries);
2694: } elsif ($configline=~/^primsub\:/) {
2695: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
2696: push(@{$primary_submenu{$parent}},\@entries);
2697: } elsif ($configline=~/^scnd\:/) {
2698: my @entries = (split(/\:/, $configline))[1..5];
2699: push(@secondary_menu,\@entries);
2700: } elsif ($configline=~/^scndsub\:/) {
2701: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
2702: push(@{$secondary_submenu{$parent}},\@entries);
2703: } elsif ($configline) {
2704: push(@desklines,$configline);
2705: }
2706: }
2707: CORE::close($config);
2708: }
2709: }
2710: $readdesk='done';
2711: }
2712: }
2713:
2714: 1;
2715: __END__
2716:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>