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