Annotation of loncom/interface/lonmenu.pm, revision 1.423
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.423 ! raeburn 4: # $Id: lonmenu.pm,v 1.422 2013/11/24 15:32:39 raeburn Exp $
1.11 albertel 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: #
1.1 www 28: #
29:
1.244 jms 30: =head1 NAME
31:
32: Apache::lonmenu
33:
34: =head1 SYNOPSIS
35:
1.371 raeburn 36: Loads contents of /home/httpd/lonTabs/mydesk.tab,
37: used to generate inline menu, and Main Menu page.
1.244 jms 38:
39: This is part of the LearningOnline Network with CAPA project
40: described at http://www.lon-capa.org.
41:
1.314 droeschl 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
1.371 raeburn 76: of those lines of mydesk.tab that start with prim:.
1.314 droeschl 77: It is used by primary_menu() to generate the corresponding menu.
78: It gets filled in the BEGIN block of this module.
79:
1.371 raeburn 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:
1.314 droeschl 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:
1.244 jms 98: =head1 SUBROUTINES
99:
100: =over
101:
1.314 droeschl 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:
1.415 raeburn 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
1.314 droeschl 112: @primary_menu is filled within the BEGIN block of this module with
1.415 raeburn 113: entries from mydesk.tab
1.314 droeschl 114:
115: =item secondary_menu()
116:
117: Same as primary_menu() but operates on @secondary_menu.
118:
1.375 raeburn 119: =item create_submenu()
120:
121: Creates XHTML for unordered list of sub-menu items which belong to a
122: particular top-level menu item. Uses hover pseudo class in css to display
123: dropdown list when mouse hovers over top-level item. Support for IE6
124: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
125: level item, which employs jQuery to handle behavior on mouseover.
126:
127: Inputs: 4 - (a) link and (b) target for anchor href in top level item,
128: (c) title for text wrapped by anchor tag in top level item.
129: (d) reference to array of arrays of sub-menu items.
130:
1.244 jms 131: =item innerregister()
132:
1.320 droeschl 133: This gets called in order to register a URL in the body of the document
1.244 jms 134:
135: =item clear()
136:
137: =item switch()
138:
139: Switch a button or create a link
140: Switch acts on the javascript that is executed when a button is clicked.
141: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
142:
143: =item secondlevel()
144:
145: =item openmenu()
146:
147: =item inlinemenu()
148:
149: =item rawconfig()
150:
151: =item utilityfunctions()
152:
1.371 raeburn 153: Output from this routine is a number of javascript functions called by
154: items in the inline menu, and in some cases items in the Main Menu page.
155:
1.244 jms 156: =item serverform()
157:
158: =item constspaceform()
159:
160: =item get_nav_status()
161:
162: =item hidden_button_check()
163:
164: =item roles_selector()
165:
166: =item jump_to_role()
167:
168: =back
169:
170: =cut
171:
1.1 www 172: package Apache::lonmenu;
173:
174: use strict;
1.152 albertel 175: use Apache::lonnet;
1.47 matthew 176: use Apache::lonhtmlcommon();
1.115 albertel 177: use Apache::loncommon();
1.127 albertel 178: use Apache::lonenc();
1.88 www 179: use Apache::lonlocal;
1.361 raeburn 180: use Apache::lonmsg();
1.207 foxr 181: use LONCAPA qw(:DEFAULT :match);
1.282 amueller 182: use HTML::Entities();
1.346 wenzelju 183: use Apache::lonwishlist();
1.88 www 184:
1.283 droeschl 185: use vars qw(@desklines %category_names %category_members %category_positions
1.371 raeburn 186: $readdesk @primary_menu %primary_submenu @secondary_menu);
1.88 www 187:
1.56 www 188: my @inlineremote;
1.38 www 189:
1.283 droeschl 190: sub prep_menuitem {
1.291 raeburn 191: my ($menuitem) = @_;
192: return '' unless(ref($menuitem) eq 'ARRAY');
1.283 droeschl 193: my $link;
194: if ($$menuitem[1]) { # graphical Link
195: $link = "<img class=\"LC_noBorder\""
1.291 raeburn 196: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
197: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283 droeschl 198: } else { # textual Link
1.291 raeburn 199: $link = &mt($$menuitem[3]);
200: }
1.316 droeschl 201: return '<li><a'
202: # highlighting for new messages
203: . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
1.325 droeschl 204: . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
1.283 droeschl 205: }
206:
1.415 raeburn 207: # primary_menu() evaluates @primary_menu and returns a two item array,
208: # with the array elements containing XHTML for the left and right sides of
209: # the menu that contains the following links:
210: # Personal, About, Message, Roles, Help, Logout
1.283 droeschl 211: # @primary_menu is filled within the BEGIN block of this module with
212: # entries from mydesk.tab
213: sub primary_menu {
1.415 raeburn 214: my (%menu);
1.283 droeschl 215: # each element of @primary contains following array:
1.415 raeburn 216: # (link url, icon path, alt text, link text, condition, position)
1.319 raeburn 217: my $public;
218: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
219: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
220: $public = 1;
221: }
1.283 droeschl 222: foreach my $menuitem (@primary_menu) {
223: # evaluate conditions
1.296 droeschl 224: next if ref($menuitem) ne 'ARRAY'; #
1.283 droeschl 225: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
1.291 raeburn 226: && &Apache::lonmsg::mynewmail(); # whether a new msg
1.283 droeschl 227: next if $$menuitem[4] eq 'newmsg' # arrived or not
1.291 raeburn 228: && !&Apache::lonmsg::mynewmail(); #
1.319 raeburn 229: next if $$menuitem[4] !~ /public/ ##we've a public user,
230: && $public; ##who should not see all
231: ##links
1.283 droeschl 232: next if $$menuitem[4] eq 'onlypublic'# hide links which are
1.319 raeburn 233: && !$public; # only visible to public
234: # users
1.283 droeschl 235: next if $$menuitem[4] eq 'roles' ##show links depending on
1.291 raeburn 236: && &Apache::loncommon::show_course(); ##term 'Courses' or
1.283 droeschl 237: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
1.291 raeburn 238: && !&Apache::loncommon::show_course(); ##
239:
1.371 raeburn 240: my $title = $menuitem->[3];
1.415 raeburn 241: my $position = $menuitem->[5];
242: if ($position eq '') {
243: $position = 'right';
244: }
1.371 raeburn 245: if (defined($primary_submenu{$title})) {
1.375 raeburn 246: my ($link,$target);
1.371 raeburn 247: if ($menuitem->[0] ne '') {
248: $link = $menuitem->[0];
249: $target = '_top';
250: } else {
251: $link = '#';
252: }
1.375 raeburn 253: my @primsub;
1.371 raeburn 254: if (ref($primary_submenu{$title}) eq 'ARRAY') {
1.375 raeburn 255: foreach my $item (@{$primary_submenu{$title}}) {
1.383 raeburn 256: next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
1.375 raeburn 257: next if ((($item->[2] eq 'portfolio') ||
258: ($item->[2] eq 'blog')) &&
259: (!&Apache::lonnet::usertools_access('','',$item->[2],
260: undef,'tools')));
261: push(@primsub,$item);
262: }
263: if (@primsub > 0) {
1.419 bisitz 264: $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
1.375 raeburn 265: } elsif ($link) {
1.415 raeburn 266: $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
1.371 raeburn 267: }
268: }
269: } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.340 raeburn 270: if ($public) {
271: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
272: my $defdom = &Apache::lonnet::default_login_domain();
273: my $to = &Apache::loncommon::build_recipient_list(undef,
274: 'helpdeskmail',
275: $defdom,$origmail);
276: if ($to ne '') {
1.415 raeburn 277: $menu{$position} .= &prep_menuitem($menuitem);
1.340 raeburn 278: }
279: } else {
1.415 raeburn 280: $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.340 raeburn 281: }
1.283 droeschl 282: } else {
1.415 raeburn 283: $menu{$position} .= prep_menuitem($menuitem);
1.283 droeschl 284: }
1.291 raeburn 285: }
1.423 ! raeburn 286: my @output = ('','');
! 287: if ($menu{'left'} ne '') {
! 288: $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
! 289: }
! 290: if ($menu{'right'} ne '') {
! 291: $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
! 292: }
! 293: return @output;
1.283 droeschl 294: }
295:
1.329 droeschl 296: #returns hashref {user=>'',dom=>''} containing:
297: # own name, domain if user is au
298: # name, domain of parent author if user is ca or aa
299: #empty return if user is not an author or not on homeserver
300: #
301: #TODO this should probably be moved somewhere more central
302: #since it can be used by different parts of the system
303: sub getauthor{
304: return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
305:
306: #co- or assistent author?
307: my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
308: ? ($1, $2) #domain, username of the parent author
309: : @env{ ('request.role.domain', 'user.name') }; #own domain, username
310:
311: # current server == home server?
312: my $home = &Apache::lonnet::homeserver($user,$dom);
313: foreach (&Apache::lonnet::current_machine_ids()){
314: return {user => $user, dom => $dom} if $_ eq $home;
315: }
316:
317: # if wrong server
318: return;
319: }
1.283 droeschl 320:
321: sub secondary_menu {
1.421 raeburn 322: my ($httphost) = @_;
1.283 droeschl 323: my $menu;
324:
1.286 raeburn 325: my $crstype = &Apache::loncommon::course_type();
1.327 droeschl 326: my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
327: ? "/$env{'request.course.sec'}"
328: : '');
329: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
1.376 raeburn 330: my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
1.418 raeburn 331: if ($canviewroster eq 'disabled') {
332: undef($canviewroster);
333: }
1.327 droeschl 334: my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
335: my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
336: my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
1.341 www 337: my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
1.343 www 338: my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
339: my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
340: my $author = &getauthor();
1.327 droeschl 341:
1.417 raeburn 342: my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv);
1.413 raeburn 343: if ($env{'request.course.id'}) {
344: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
345: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
346: if ($canedit) {
347: $showsyllabus = 1;
348: $showfeeds = 1;
349: } else {
1.414 raeburn 350: unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
351: if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
352: ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
353: ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
354: ($env{'request.course.syllabustime'})) {
355: $showsyllabus = 1;
356: }
357: }
358: if ($env{'request.course.feeds'}) {
359: $showfeeds = 1;
1.413 raeburn 360: }
361: }
1.417 raeburn 362: unless ($canmgr) {
363: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
364: if (keys(%slots) > 0) {
365: $showresv = 1;
366: }
367: }
1.413 raeburn 368: }
369:
1.404 raeburn 370: my ($canmodifycoauthor);
371: if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
372: my $extent = "$env{'user.domain'}/$env{'user.name'}";
373: if ((&Apache::lonnet::allowed('cca',$extent)) ||
374: (&Apache::lonnet::allowed('caa',$extent))) {
375: $canmodifycoauthor = 1;
376: }
377: }
378:
1.286 raeburn 379: my %groups = &Apache::lonnet::get_active_groups(
380: $env{'user.domain'}, $env{'user.name'},
381: $env{'course.' . $env{'request.course.id'} . '.domain'},
382: $env{'course.' . $env{'request.course.id'} . '.num'});
1.327 droeschl 383:
1.401 raeburn 384: my ($roleswitcher_js,$roleswitcher_form);
385:
1.283 droeschl 386: foreach my $menuitem (@secondary_menu) {
387: # evaluate conditions
1.296 droeschl 388: next if ref($menuitem) ne 'ARRAY';
1.283 droeschl 389: next if $$menuitem[4] ne 'always'
1.404 raeburn 390: && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
1.283 droeschl 391: && !$env{'request.course.id'};
392: next if $$menuitem[4] =~ /^mdc/
1.286 raeburn 393: && !$canedit;
1.341 www 394: next if $$menuitem[4] eq 'nvgr'
395: && $canvgr;
396: next if $$menuitem[4] eq 'vgr'
397: && !$canvgr;
1.327 droeschl 398: next if $$menuitem[4] eq 'cst'
399: && !$canmodifyuser;
1.343 www 400: next if $$menuitem[4] eq 'ncst'
1.376 raeburn 401: && ($canmodifyuser || !$canviewroster);
1.343 www 402: next if $$menuitem[4] eq 'mgr'
403: && !$canmgr;
1.417 raeburn 404: next if $$menuitem[4] eq 'showresv'
405: && !$showresv;
1.327 droeschl 406: next if $$menuitem[4] eq 'whn'
407: && !$canviewwnew;
408: next if $$menuitem[4] eq 'opa'
409: && !$canmodpara;
1.283 droeschl 410: next if $$menuitem[4] =~ /showgroups$/
1.300 raeburn 411: && !$canviewgrps
1.286 raeburn 412: && !%groups;
1.413 raeburn 413: next if $$menuitem[4] eq 'showsyllabus'
414: && !$showsyllabus;
415: next if $$menuitem[4] eq 'showfeeds'
416: && !$showfeeds;
1.329 droeschl 417: next if $$menuitem[4] eq 'author'
418: && !$author;
1.404 raeburn 419: next if $$menuitem[4] eq 'cca'
420: && !$canmodifycoauthor;
1.283 droeschl 421:
1.286 raeburn 422: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283 droeschl 423: # special treatment for role selector
1.401 raeburn 424: ($roleswitcher_js,$roleswitcher_form,my $switcher) =
425: &roles_selector(
1.283 droeschl 426: $env{'course.' . $env{'request.course.id'} . '.domain'},
1.421 raeburn 427: $env{'course.' . $env{'request.course.id'} . '.num'},
428: $httphost
1.401 raeburn 429: );
430: $menu .= $switcher;
1.296 droeschl 431: } else {
1.414 raeburn 432: if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
433: my $url = $$menuitem[0];
434: $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
435: if (&Apache::lonnet::is_on_map($url)) {
436: unless ($$menuitem[0] =~ /\?register=1/) {
437: $$menuitem[0] .= '?register=1';
438: }
439: } else {
440: $$menuitem[0] =~ s{\?register=1}{};
441: }
442: }
1.296 droeschl 443: $menu .= &prep_menuitem(\@$menuitem);
1.283 droeschl 444: }
445: }
446: if ($menu =~ /\[url\].*\[symb\]/) {
1.291 raeburn 447: my $escurl = &escape( &Apache::lonenc::check_encrypt(
448: $env{'request.noversionuri'}));
1.283 droeschl 449:
1.291 raeburn 450: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
451: $env{'request.symb'}));
1.283 droeschl 452:
453: if ( $env{'request.state'} eq 'construct'
454: and ( $env{'request.noversionuri'} eq ''
455: || !defined($env{'request.noversionuri'})))
456: {
1.359 raeburn 457: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
458: ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
1.291 raeburn 459: $escurl = &escape($escurl);
1.283 droeschl 460: }
461: $menu =~ s/\[url\]/$escurl/g;
462: $menu =~ s/\[symb\]/$escsymb/g;
463: }
1.329 droeschl 464: $menu =~ s/\[uname\]/$$author{user}/g;
465: $menu =~ s/\[udom\]/$$author{dom}/g;
1.413 raeburn 466: if ($showsyllabus || $showfeeds) {
467: $menu =~ s/\[cnum\]/$cnum/g;
468: $menu =~ s/\[cdom\]/$cdom/g;
469: }
1.385 raeburn 470: if ($menu) {
471: $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
472: }
1.401 raeburn 473: if ($roleswitcher_form) {
474: $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
475: }
1.385 raeburn 476: return $menu;
1.283 droeschl 477: }
478:
1.375 raeburn 479: sub create_submenu {
1.419 bisitz 480: my ($link,$target,$title,$submenu,$translate) = @_;
1.375 raeburn 481: return unless (ref($submenu) eq 'ARRAY');
1.379 raeburn 482: my $disptarget;
483: if ($target ne '') {
484: $disptarget = ' target="'.$target.'"';
485: }
1.415 raeburn 486: my $name;
487: if ($title eq 'Personal') {
488: if ($env{'user.name'} && $env{'user.domain'}) {
489: $name = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
490: } else {
491: $name = &mt($title);
492: }
493: } else {
494: $name = &mt($title);
495: }
1.375 raeburn 496: my $menu = '<li class="LC_hoverable">'.
1.379 raeburn 497: '<a href="'.$link.'"'.$disptarget.'>'.
1.415 raeburn 498: '<span class="LC_nobreak">'.$name.
1.375 raeburn 499: '<span class="LC_fontsize_small" style="font-weight:normal;">'.
500: ' ▼</span></span></a>'.
501: '<ul>';
502: my $count = 0;
503: my $numsub = scalar(@{$submenu});
504: foreach my $item (@{$submenu}) {
505: $count ++;
506: if (ref($item) eq 'ARRAY') {
1.416 raeburn 507: my $href = $item->[0];
508: if ($href =~ /(aboutme|rss\.html)$/) {
509: next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
510: $href =~ s/\[domain\]/$env{'user.domain'}/g;
511: $href =~ s/\[user\]/$env{'user.name'}/g;
512: }
1.375 raeburn 513: my $borderbot;
514: if ($count == $numsub) {
515: $borderbot = 'border-bottom:1px solid black;';
516: }
517: $menu .= '<li style="margin:0;padding:0;'.
1.419 bisitz 518: $borderbot.'"><a href="'.$href.'">';
519: if ($translate) {
520: $menu .= &mt($item->[1]);
521: } else {
522: $menu .= $item->[1];
523: }
1.420 raeburn 524: $menu .= '</a></li>';
1.375 raeburn 525: }
526: }
527: $menu .= '</ul></li>';
528: return $menu;
529: }
530:
1.40 www 531: sub innerregister {
1.390 raeburn 532: my ($forcereg,$bread_crumbs,$group) = @_;
1.152 albertel 533: my $const_space = ($env{'request.state'} eq 'construct');
1.131 raeburn 534: my $is_const_dir = 0;
1.120 raeburn 535:
1.175 albertel 536: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40 www 537:
1.174 albertel 538: $env{'request.registered'} = 1;
1.40 www 539:
1.177 albertel 540: undef(@inlineremote);
1.56 www 541:
1.393 raeburn 542: my ($mapurl,$resurl);
1.390 raeburn 543:
1.393 raeburn 544: if ($env{'request.course.id'}) {
545: if ($env{'request.symb'}) {
546: ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
547: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
1.267 droeschl 548:
1.393 raeburn 549: my $maptitle = &Apache::lonnet::gettitle($mapurl);
550: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.318 droeschl 551:
552: #SD
553: #course_type only Course and Community?
554: #
1.393 raeburn 555: my @crumbs;
556: unless (($forcereg) &&
557: ($env{'request.noversionuri'} eq '/adm/navmaps') &&
558: ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
559: @crumbs = ({text => Apache::loncommon::course_type()
560: . ' Contents',
561: href => "Javascript:gopost('/adm/navmaps','')"});
562: }
563: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
564: push(@crumbs, {text => '...',
565: no_mt => 1});
566: }
567:
568: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
569: && $maptitle ne 'default.sequence'
570: && $maptitle ne $coursetitle);
1.268 droeschl 571:
1.393 raeburn 572: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
573: &Apache::lonhtmlcommon::clear_breadcrumbs();
574: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
575: } else {
576: $resurl = $env{'request.noversionuri'};
577: my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
578: my $crstype = &Apache::loncommon::course_type();
579: my $title = &mt('View Resource');
580: if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
581: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
1.392 raeburn 582: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.393 raeburn 583: if ($env{'form.title'}) {
584: $title = $env{'form.title'};
585: }
1.394 raeburn 586: my $trail;
1.393 raeburn 587: if ($env{'form.folderpath'}) {
1.399 raeburn 588: &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
1.394 raeburn 589: ($trail) =
1.393 raeburn 590: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
591: } else {
592: &Apache::lonhtmlcommon::add_breadcrumb(
1.392 raeburn 593: {text => "Supplemental $crstype Content",
594: href => "javascript:gopost('/adm/supplemental','')"});
1.393 raeburn 595: $title = &mt('View Resource');
1.394 raeburn 596: ($trail) =
597: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.392 raeburn 598: }
1.394 raeburn 599: return $trail;
1.412 raeburn 600: } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
601: &Apache::lonhtmlcommon::clear_breadcrumbs();
602: &prepare_functions('/public'.$courseurl."/syllabus",
603: $forcereg,$group,undef,undef,1);
604: $title = &mt('Syllabus File');
605: my ($trail) =
606: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
607: return $trail;
1.392 raeburn 608: }
1.395 raeburn 609: unless ($env{'request.state'} eq 'construct') {
610: &Apache::lonhtmlcommon::clear_breadcrumbs();
611: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
612: }
1.392 raeburn 613: }
1.390 raeburn 614: } elsif (! $const_space){
1.328 droeschl 615: #a situation when we're looking at a resource outside of context of a
616: #course or construction space (e.g. with cumulative rights)
617: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.390 raeburn 618: unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
619: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
620: }
1.65 www 621: }
1.41 www 622: # =============================================================================
623: # ============================ This is for URLs that actually can be registered
1.316 droeschl 624: return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
625: || $forcereg );
1.390 raeburn 626: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
627: $forceview,$editbutton);
1.391 raeburn 628: if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
629: ($env{'request.role'} !~/^(aa|ca|au)/)) {
1.390 raeburn 630: $editbutton = &prepare_functions($resurl,$forcereg,$group);
631: }
632: if ($editbutton eq '') {
1.399 raeburn 633: $editbutton = &clear(6,1);
1.390 raeburn 634: }
1.317 droeschl 635:
1.390 raeburn 636: #
637: # This applies in course context
638: #
639: if ($env{'request.course.id'}) {
640: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
641: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
642: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
643: my @privs;
644: if ($env{'request.symb'} ne '') {
645: if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
646: push(@privs,('mgr','vgr'));
647: }
648: push(@privs,'opa');
649: }
650: foreach my $priv (@privs) {
651: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
652: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
653: $perms{$priv} =
654: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
655: }
656: }
657: #
658: # Determine whether or not to show Grades and Submissions buttons
659: #
660: if ($env{'request.symb'} ne '' &&
661: $env{'request.filename'}=~/$LONCAPA::assess_re/) {
662: if ($perms{'mgr'}) {
663: &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
664: "gocmd('/adm/grades','gradingmenu')",
665: 'Content Grades');
666: } elsif ($perms{'vgr'}) {
667: &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
668: "gocmd('/adm/grades','submission')",
669: 'Content Submissions');
670: }
671: }
672: if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
673: &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
674: "gocmd('/adm/parmset','set')",
675: 'Content Settings');
1.107 albertel 676: }
1.393 raeburn 677: # End grades/submissions check
1.107 albertel 678:
1.274 www 679: #
1.393 raeburn 680: # This applies to items inside a folder/page modifiable in the course.
1.274 www 681: #
1.390 raeburn 682: if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
1.393 raeburn 683: my $text = 'Edit Folder';
1.395 raeburn 684: if (($mapurl =~ /\.page$/) ||
685: ($env{'request.symb'}=~
1.396 raeburn 686: m{uploaded/$cdom/$cnum/default_\d+\.page$})) {
1.393 raeburn 687: $text = 'Edit Page';
688: }
689: &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
1.390 raeburn 690: "gocmd('/adm/coursedocs','direct')",
691: 'Folder/Page Content');
1.258 raeburn 692: }
1.390 raeburn 693: # End modifiable folder/page container check
694: }
695: # End course context
696:
1.41 www 697: # Prepare the rest of the buttons
1.383 raeburn 698: my ($menuitems,$got_prt,$got_wishlist);
1.120 raeburn 699: if ($const_space) {
1.274 www 700: #
701: # We are in construction space
702: #
1.353 www 703:
1.355 raeburn 704: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.353 www 705: my ($udom,$uname,$thisdisfn) =
1.355 raeburn 706: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1.353 www 707: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1.131 raeburn 708: if ($currdir =~ m-/$-) {
709: $is_const_dir = 1;
710: } else {
1.267 droeschl 711: $currdir =~ s|[^/]+$||;
1.200 foxr 712: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208 albertel 713: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274 www 714: #
715: # Probably should be in mydesk.tab
716: #
1.131 raeburn 717: $menuitems=(<<ENDMENUITEMS);
1.344 www 718: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1.353 www 719: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
720: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
721: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
722: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1.120 raeburn 723: ENDMENUITEMS
1.131 raeburn 724: }
1.308 raeburn 725: if (ref($bread_crumbs) eq 'ARRAY') {
726: &Apache::lonhtmlcommon::clear_breadcrumbs();
727: foreach my $crumb (@{$bread_crumbs}){
728: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
729: }
730: }
1.203 foxr 731: } elsif ( defined($env{'request.course.id'}) &&
732: $env{'request.symb'} ne '' ) {
1.274 www 733: #
1.383 raeburn 734: # We are in a course and looking at a registered URL
1.274 www 735: # Should probably be in mydesk.tab
736: #
1.120 raeburn 737: $menuitems=(<<ENDMENUITEMS);
1.41 www 738: c&3&1
1.344 www 739: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
740: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
1.77 www 741: c&6&3
742: c&8&1
743: c&8&2
1.344 www 744: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.41 www 745: ENDMENUITEMS
1.383 raeburn 746: $got_prt = 1;
747: if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
748: && (!$env{'request.enc'})) {
1.332 wenzelju 749: # wishlist is only available for users with access to resource-pool
750: # and links can only be set for resources within the resource-pool
751: $menuitems .= (<<ENDMENUITEMS);
1.422 raeburn 752: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in my personal Stored Links repository&&1
1.332 wenzelju 753: ENDMENUITEMS
1.383 raeburn 754: $got_wishlist = 1;
1.332 wenzelju 755: }
1.216 albertel 756:
1.243 tempelho 757: my $currentURL = &Apache::loncommon::get_symb();
758: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
759: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
760: $menuitems.="s&9&3&";
761: if(length($annotation) > 0){
1.317 droeschl 762: $menuitems.="anot2.png";
1.243 tempelho 763: }else{
1.317 droeschl 764: $menuitems.="anot.png";
1.243 tempelho 765: }
1.344 www 766: $menuitems.="&Notes&&annotate()&";
1.243 tempelho 767: $menuitems.="Make notes and annotations about this resource&&1\n";
768:
1.323 raeburn 769: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1.382 raeburn 770: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
1.216 albertel 771: $menuitems.=(<<ENDREALRES);
1.344 www 772: s&6&3&catalog.png&Info&info[_1]&catalog_info()&Show Metadata
1.216 albertel 773: ENDREALRES
774: }
1.422 raeburn 775: unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
776: ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) {
1.382 raeburn 777: $menuitems.=(<<ENDREALRES);
1.344 www 778: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1.382 raeburn 779: ENDREALRES
780: }
1.422 raeburn 781: unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
782: $menuitems.=(<<ENDREALRES);
1.344 www 783: s&8&2&fdbk.png&Communicate&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1.77 www 784: ENDREALRES
1.422 raeburn 785: }
1.120 raeburn 786: }
787: }
1.203 foxr 788: if ($env{'request.uri'} =~ /^\/res/) {
1.383 raeburn 789: unless ($got_prt) {
790: $menuitems .= (<<ENDMENUITEMS);
1.344 www 791: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.203 foxr 792: ENDMENUITEMS
1.384 raeburn 793: $got_prt = 1;
1.383 raeburn 794: }
795: unless ($got_wishlist) {
796: if (($env{'user.adv'}) && (!$env{'request.enc'})) {
797: # wishlist is only available for users with access to resource-pool
798: $menuitems .= (<<ENDMENUITEMS);
1.374 bisitz 799: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository&&1
1.332 wenzelju 800: ENDMENUITEMS
1.383 raeburn 801: $got_wishlist = 1;
802: }
803: }
804: }
1.41 www 805: my $buttons='';
806: foreach (split(/\n/,$menuitems)) {
807: my ($command,@rest)=split(/\&/,$_);
1.220 raeburn 808: my $idx=10*$rest[0]+$rest[1];
809: if (&hidden_button_check() eq 'yes') {
810: if ($idx == 21 ||$idx == 23) {
811: $buttons.=&switch('','',@rest);
812: } else {
813: $buttons.=&clear(@rest);
814: }
815: } else {
816: if ($command eq 's') {
817: $buttons.=&switch('','',@rest);
818: } else {
819: $buttons.=&clear(@rest);
820: }
1.41 www 821: }
822: }
1.148 albertel 823:
824: my $addremote=0;
1.267 droeschl 825: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.301 droeschl 826: if ($addremote) {
827:
1.342 www 828: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301 droeschl 829:
1.342 www 830: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.312 droeschl 831: 'navigation', @inlineremote[21,23]);
832:
1.378 raeburn 833: my $countdown = &countdown_timer();
834: if (&hidden_button_check() eq 'yes') {
835: if ($countdown) {
836: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
837: }
838: } else {
839: my @tools = @inlineremote[93,91,81,82,83];
840: if ($countdown) {
841: unshift(@tools,$countdown);
842: }
1.342 www 843: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.378 raeburn 844: 'tools',@tools);
1.313 droeschl 845:
846: #publish button in construction space
847: if ($env{'request.state'} eq 'construct'){
1.342 www 848: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349 raeburn 849: 'advtools', $inlineremote[63]);
1.342 www 850: } else {
851: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349 raeburn 852: 'tools', $inlineremote[63]);
1.313 droeschl 853: }
1.390 raeburn 854: &advtools_crumbs(@inlineremote);
1.301 droeschl 855: }
1.38 www 856: }
857:
1.342 www 858: return &Apache::lonhtmlcommon::scripttag('', 'start')
859: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
860: . &Apache::lonhtmlcommon::scripttag('', 'end');
1.38 www 861: }
862:
1.389 raeburn 863: sub get_editbutton {
1.390 raeburn 864: my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
1.398 raeburn 865: my $jscall;
866: if (($forceview) && ($env{'form.todocs'})) {
867: my ($folderpath,$command);
868: if ($env{'request.symb'}) {
869: $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
870: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
871: $folderpath = $env{'form.folderpath'};
872: $command = '&forcesupplement=1';
873: }
874: $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
875: $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
876: } else {
877: $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1.393 raeburn 878: $forceedit,$forcereg,$env{'request.symb'},
879: &escape($env{'form.folderpath'}),
880: &escape($env{'form.title'}),$env{'form.idx'},
1.398 raeburn 881: &escape($env{'form.suppurl'},$env{'form.todocs'}));
882: }
1.389 raeburn 883: if ($jscall) {
1.390 raeburn 884: my $icon = 'pcstr.png';
885: my $label = 'Edit';
886: if ($forceview) {
887: $icon = 'tolastloc.png';
888: $label = 'Exit Editing';
889: }
890: &switch('','',6,1,$icon,$label,'resource[_2]',
891: $jscall,"Edit this resource");
892: return 1;
893: }
894: return;
895: }
896:
897: sub prepare_functions {
1.393 raeburn 898: my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_;
1.390 raeburn 899: unless ($env{'request.registered'}) {
900: undef(@inlineremote);
901: }
902: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
903: $forceview);
904:
905: if ($env{'request.course.id'}) {
906: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
907: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
908: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
909: }
910:
911: my $editbutton = '';
912: #
913: # Determine whether or not to display 'Edit' icon/button
914: #
915: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
916: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.391 raeburn 917: ($cfile,$home,$switchserver,$forceedit,$forceview) =
918: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
919: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
920: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
921: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.390 raeburn 922: $forceedit,$forceview,$forcereg);
923: }
1.391 raeburn 924: } elsif ((!$env{'request.course.id'}) &&
1.390 raeburn 925: ($env{'user.author'}) && ($env{'request.filename'}) &&
926: ($env{'request.role'} !~/^(aa|ca|au)/)) {
927: #
928: # Currently do not have the role of author or co-author.
929: # Do we have authoring privileges for the resource?
930: #
931: my $file=&Apache::lonnet::declutter($env{'request.filename'});
932: ($cfile,$home,$switchserver,$forceedit,$forceview) =
933: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
934: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
935: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
936: $editbutton = &get_editbutton($cfile,$home,$switchserver,
937: $forceedit,$forceview,$forcereg);
938: }
939: } elsif ($env{'request.course.id'}) {
940: #
941: # This applies in course context
942: #
1.412 raeburn 943: if (($perms{'mdc'}) &&
944: (($resurl eq "/public/$cdom/$cnum/syllabus") ||
945: ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
1.411 raeburn 946: $cfile = $resurl;
947: $home = &Apache::lonnet::homeserver($cnum,$cdom);
948: if ($env{'form.forceedit'}) {
949: $forceview = 1;
1.390 raeburn 950: } else {
1.411 raeburn 951: $forceedit = 1;
1.390 raeburn 952: }
1.411 raeburn 953: $editbutton = &get_editbutton($cfile,$home,$switchserver,
954: $forceedit,$forceview,$forcereg);
1.393 raeburn 955: } elsif (($resurl eq '/adm/extresedit') &&
956: (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
957: ($cfile,$home,$switchserver,$forceedit,$forceview) =
958: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
959: $env{'form.symb'});
960: if ($cfile ne '') {
961: $editbutton = &get_editbutton($cfile,$home,$switchserver,
962: $forceedit,$forceview,$forcereg,
963: $env{'form.title'},$env{'form.suppurl'});
964: }
1.406 raeburn 965: } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
966: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
967: ($cfile,$home,$switchserver,$forceedit,$forceview) =
968: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
969: $env{'form.symb'});
970: $editbutton = &get_editbutton($cfile,$home,$switchserver,
971: $forceedit,$forceview,$forcereg);
1.405 raeburn 972: } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
973: ($resurl ne '/cgi-bin/printout.pl')) {
1.390 raeburn 974: if ($env{'request.filename'}) {
975: my $file=&Apache::lonnet::declutter($env{'request.filename'});
976: ($cfile,$home,$switchserver,$forceedit,$forceview) =
977: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
978: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
979: if ($cfile ne '') {
980: $editbutton = &get_editbutton($cfile,$home,$switchserver,
981: $forceedit,$forceview,$forcereg);
982: }
983: }
984: }
985: }
986: # End determination of 'Edit' icon/button display
987:
1.393 raeburn 988: if ($env{'request.course.id'}) {
1.390 raeburn 989: # This applies to about me page for users in a course
1.391 raeburn 990: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.390 raeburn 991: my ($sdom,$sname) = ($1,$2);
992: unless (&Apache::lonnet::is_course($sdom,$sname)) {
993: &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
994: '',
1.415 raeburn 995: "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
1.390 raeburn 996: 'Send message to specific user');
997: }
1.391 raeburn 998: my $hideprivileged = 1;
999: if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
1000: $hideprivileged)) {
1.390 raeburn 1001: foreach my $priv ('vsa','vgr','srm') {
1002: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1003: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1004: $perms{$priv} =
1005: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1006: }
1007: }
1008: if ($perms{'vsa'}) {
1009: &switch('','',6,5,'trck-22x22.png','Activity',
1010: '',
1011: "go('/adm/trackstudent?selected_student=$sname:$sdom')",
1012: 'View recent activity by this person');
1013: }
1014: if ($perms{'vgr'}) {
1015: &switch('','',6,6,'rsrv-22x22.png','Reservations',
1016: '',
1.415 raeburn 1017: "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
1.390 raeburn 1018: 'Slot reservation history');
1019: }
1020: if ($perms{'srm'}) {
1021: &switch('','',6,7,'contact-new-22x22.png','Records',
1022: '',
1.415 raeburn 1023: "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
1.390 raeburn 1024: 'Add records');
1025: }
1026: }
1.393 raeburn 1027: }
1028: if (($env{'form.folderpath'} =~ /^supplemental/) &&
1029: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
1030: (($resurl =~ m{^/adm/wrapper/ext/}) ||
1031: ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1.397 raeburn 1032: ($resurl eq '/adm/supplemental') ||
1033: ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
1034: ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1.393 raeburn 1035: my @folders=split('&',$env{'form.folderpath'});
1.394 raeburn 1036: if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1.393 raeburn 1037: my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
1038: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1.415 raeburn 1039: "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path'",
1.393 raeburn 1040: 'Folder/Page Content');
1041: }
1.390 raeburn 1042: }
1043: }
1044:
1045: # End checking for items for about me page for users in a course
1.393 raeburn 1046: if ($docscrumbs) {
1047: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1048: &advtools_crumbs(@inlineremote);
1049: return $editbutton;
1050: } elsif ($env{'request.registered'}) {
1.390 raeburn 1051: return $editbutton;
1052: } else {
1053: if (ref($bread_crumbs) eq 'ARRAY') {
1054: if (@inlineremote > 0) {
1055: if (ref($advtools) eq 'ARRAY') {
1056: @{$advtools} = @inlineremote;
1057: }
1058: }
1059: return;
1060: } elsif (@inlineremote > 0) {
1061: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1062: &advtools_crumbs(@inlineremote);
1063: return &Apache::lonhtmlcommon::scripttag('', 'start')
1064: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
1065: . &Apache::lonhtmlcommon::scripttag('', 'end');
1066: }
1067: }
1068: }
1069:
1070: sub advtools_crumbs {
1071: my @funcs = @_;
1072: if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
1073: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1074: 'advtools', @funcs[61,64,65,66,67,74]);
1075: } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
1076: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1077: 'advtools', @funcs[61,71,72,73,74,92]);
1.393 raeburn 1078: } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
1079: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.407 raeburn 1080: 'advtools', $funcs[61]);
1.393 raeburn 1081: }
1.412 raeburn 1082: return;
1.258 raeburn 1083: }
1084:
1.2 www 1085: # ================================================================== Raw Config
1086:
1.3 www 1087: sub clear {
1088: my ($row,$col)=@_;
1.316 droeschl 1089: $inlineremote[10*$row+$col]='';
1090: return '';
1.3 www 1091: }
1092:
1.40 www 1093: # ============================================ Switch a button or create a link
1.25 matthew 1094: # Switch acts on the javascript that is executed when a button is clicked.
1095: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 1096:
1.2 www 1097: sub switch {
1.209 www 1098: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2 www 1099: $act=~s/\$uname/$uname/g;
1100: $act=~s/\$udom/$udom/g;
1.88 www 1101: $top=&mt($top);
1102: $bot=&mt($bot);
1103: $desc=&mt($desc);
1.209 www 1104: my $idx=10*$row+$col;
1105: $category_members{$cat}.=':'.$idx;
1106:
1.320 droeschl 1107: # Inline Menu
1.317 droeschl 1108: if ($nobreak==2) { return ''; }
1109: my $text=$top.' '.$bot;
1110: $text=~s/\s*\-\s*//gs;
1.105 www 1111:
1.317 droeschl 1112: my $pic=
1.225 albertel 1113: '<img alt="'.$text.'" src="'.
1114: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303 droeschl 1115: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317 droeschl 1116: if ($env{'browser.interface'} eq 'faketextual') {
1.274 www 1117: # Main Menu
1.103 www 1118: if ($nobreak==3) {
1.209 www 1119: $inlineremote[$idx]="\n".
1.177 albertel 1120: '<td class="LC_menubuttons_text" align="right">'.$text.
1.247 harmsja 1121: '</td><td align="left">'.
1.103 www 1122: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1123: } elsif ($nobreak) {
1.209 www 1124: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1125: '<td align="left">'.
1.177 albertel 1126: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215 www 1127: <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>';
1.103 www 1128: } else {
1.209 www 1129: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1130: '<td align="left">'.
1.103 www 1131: '<a href="javascript:'.$act.';">'.$pic.
1.177 albertel 1132: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215 www 1133: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103 www 1134: }
1.317 droeschl 1135: } else {
1.103 www 1136: # Inline Menu
1.378 raeburn 1137: my @tools = (93,91,81,82,83);
1138: unless ($env{'request.state'} eq 'construct') {
1139: push(@tools,63);
1140: }
1141: if (($env{'environment.icons'} eq 'iconsonly') &&
1142: (grep(/^$idx$/,@tools))) {
1143: $inlineremote[$idx] =
1144: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
1145: } else {
1146: $inlineremote[$idx] =
1.317 droeschl 1147: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344 www 1148: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
1.378 raeburn 1149: }
1.317 droeschl 1150: }
1.56 www 1151: return '';
1.2 www 1152: }
1153:
1154: sub secondlevel {
1155: my $output='';
1156: my
1.209 www 1157: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2 www 1158: if ($prt eq 'any') {
1.209 www 1159: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1160: } elsif ($prt=~/^r(\w+)/) {
1161: if ($rol eq $1) {
1.209 www 1162: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1163: }
1164: }
1165: return $output;
1166: }
1167:
1.56 www 1168: sub inlinemenu {
1.210 albertel 1169: undef(@inlineremote);
1170: undef(%category_members);
1.275 www 1171: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56 www 1172: &rawconfig(1);
1.309 bisitz 1173: my $output='<table><tr>';
1.209 www 1174: for (my $col=1; $col<=2; $col++) {
1.241 riegler 1175: $output.='<td class="LC_mainmenu_col_fieldset">';
1.209 www 1176: for (my $row=1; $row<=8; $row++) {
1177: foreach my $cat (keys(%category_members)) {
1178: if ($category_positions{$cat} ne "$col,$row") { next; }
1.247 harmsja 1179: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309 bisitz 1180: $output.='<div class="LC_Box LC_400Box">';
1181: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247 harmsja 1182: $output.='<table>';
1.240 riegler 1183: my %active=();
1184: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1185: if ($inlineremote[$menu_item]) {
1186: $active{$menu_item}=1;
1187: }
1188: }
1189: foreach my $item (sort(keys(%active))) {
1190: $output.=$inlineremote[$item];
1191: }
1192: $output.='</table>';
1.245 harmsja 1193: $output.='</div>';
1.240 riegler 1194: }
1195: }
1196: $output.="</td>";
1197: }
1198: $output.="</tr></table>";
1199: return $output;
1200: }
1201:
1.2 www 1202: sub rawconfig {
1.274 www 1203: #
1204: # This evaluates mydesk.tab
1205: # Need to add more positions and more privileges to deal with all
1206: # menu items.
1207: #
1.34 www 1208: my $textualoverride=shift;
1209: my $output='';
1.316 droeschl 1210: return '' unless $textualoverride;
1.152 albertel 1211: my $uname=$env{'user.name'};
1212: my $udom=$env{'user.domain'};
1213: my $adv=$env{'user.adv'};
1.266 raeburn 1214: my $show_course=&Apache::loncommon::show_course();
1.152 albertel 1215: my $author=$env{'user.author'};
1.5 www 1216: my $crs='';
1.295 raeburn 1217: my $crstype='';
1.152 albertel 1218: if ($env{'request.course.id'}) {
1219: $crs='/'.$env{'request.course.id'};
1220: if ($env{'request.course.sec'}) {
1221: $crs.='_'.$env{'request.course.sec'};
1.7 www 1222: }
1.8 www 1223: $crs=~s/\_/\//g;
1.295 raeburn 1224: $crstype = &Apache::loncommon::course_type();
1.5 www 1225: }
1.152 albertel 1226: my $pub=($env{'request.state'} eq 'published');
1227: my $con=($env{'request.state'} eq 'construct');
1228: my $rol=$env{'request.role'};
1229: my $requested_domain = $env{'request.role.domain'};
1.184 raeburn 1230: foreach my $line (@desklines) {
1.209 www 1231: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3 www 1232: $prt=~s/\$uname/$uname/g;
1233: $prt=~s/\$udom/$udom/g;
1.295 raeburn 1234: if ($prt =~ /\$crs/) {
1235: next unless ($env{'request.course.id'});
1236: next if ($crstype eq 'Community');
1237: $prt=~s/\$crs/$crs/g;
1238: } elsif ($prt =~ /\$cmty/) {
1239: next unless ($env{'request.course.id'});
1240: next if ($crstype ne 'Community');
1241: $prt=~s/\$cmty/$crs/g;
1242: }
1.25 matthew 1243: $prt=~s/\$requested_domain/$requested_domain/g;
1.211 www 1244: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3 www 1245: if ($pro eq 'clear') {
1.4 www 1246: $output.=&clear($row,$col);
1.3 www 1247: } elsif ($pro eq 'any') {
1.2 www 1248: $output.=&secondlevel(
1.209 www 1249: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1250: } elsif ($pro eq 'smp') {
1251: unless ($adv) {
1252: $output.=&secondlevel(
1.209 www 1253: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1254: }
1255: } elsif ($pro eq 'adv') {
1256: if ($adv) {
1257: $output.=&secondlevel(
1.209 www 1258: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1259: }
1.231 albertel 1260: } elsif ($pro eq 'shc') {
1261: if ($show_course) {
1262: $output.=&secondlevel(
1263: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1264: }
1265: } elsif ($pro eq 'nsc') {
1266: if (!$show_course) {
1267: $output.=&secondlevel(
1268: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1269: }
1.81 matthew 1270: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295 raeburn 1271: my $priv = $1;
1272: if ($priv =~ /^mdc(Course|Community)/) {
1273: if ($crstype eq $1) {
1274: $priv = 'mdc';
1275: } else {
1276: next;
1277: }
1278: }
1279: if (&Apache::lonnet::allowed($priv,$prt)) {
1.209 www 1280: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4 www 1281: }
1.295 raeburn 1282: } elsif ($pro eq 'course') {
1283: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209 www 1284: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81 matthew 1285: }
1.295 raeburn 1286: } elsif ($pro eq 'community') {
1287: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1288: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1289: }
1.124 matthew 1290: } elsif ($pro =~ /^courseenv_(.*)$/) {
1291: my $key = $1;
1.307 raeburn 1292: if ($crstype ne 'Community') {
1293: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1294: if ($key eq 'canuse_pdfforms') {
1295: if ($env{'request.course.id'} && $coursepref eq '') {
1296: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1297: $coursepref = $domdefs{'canuse_pdfforms'};
1298: }
1299: }
1300: if ($coursepref) {
1301: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1302: }
1.295 raeburn 1303: }
1304: } elsif ($pro =~ /^communityenv_(.*)$/) {
1305: my $key = $1;
1.307 raeburn 1306: if ($crstype eq 'Community') {
1307: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1308: if ($key eq 'canuse_pdfforms') {
1309: if ($env{'request.course.id'} && $coursepref eq '') {
1310: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1311: $coursepref = $domdefs{'canuse_pdfforms'};
1312: }
1313: }
1314: if ($coursepref) {
1315: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1316: }
1.124 matthew 1317: }
1.81 matthew 1318: } elsif ($pro =~ /^course_(.*)$/) {
1319: # Check for permissions inside of a course
1.295 raeburn 1320: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1.152 albertel 1321: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1322: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81 matthew 1323: )) {
1.209 www 1324: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26 www 1325: }
1.295 raeburn 1326: } elsif ($pro =~ /^community_(.*)$/) {
1327: # Check for permissions inside of a community
1328: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1329: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1330: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1331: )) {
1332: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1333: }
1.4 www 1334: } elsif ($pro eq 'author') {
1335: if ($author) {
1.152 albertel 1336: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234 raeburn 1337: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1.152 albertel 1338: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19 matthew 1339: # Check that we are on the correct machine
1.29 matthew 1340: my $cadom=$requested_domain;
1.152 albertel 1341: my $caname=$env{'user.name'};
1.234 raeburn 1342: if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29 matthew 1343: ($cadom,$caname)=
1.206 albertel 1344: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29 matthew 1345: }
1346: $act =~ s/\$caname/$caname/g;
1.353 www 1347: $act =~ s/\$cadom/$cadom/g;
1.19 matthew 1348: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 1349: my $allowed=0;
1350: my @ids=&Apache::lonnet::current_machine_ids();
1351: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1352: if ($allowed) {
1.209 www 1353: $output.=&switch($caname,$cadom,
1354: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19 matthew 1355: }
1.6 www 1356: }
1.2 www 1357: }
1.248 raeburn 1358: } elsif ($pro eq 'tools') {
1359: my @tools = ('aboutme','blog','portfolio');
1360: if (grep(/^\Q$prt\E$/,@tools)) {
1.249 raeburn 1361: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251 raeburn 1362: $env{'user.domain'},
1363: $prt,undef,'tools')) {
1364: $output.=&clear($row,$col);
1365: next;
1366: }
1.278 raeburn 1367: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1368: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1369: next;
1370: }
1371: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1372: next;
1373: }
1.279 raeburn 1374: my $showreqcrs = &check_for_rcrs();
1.251 raeburn 1375: if (!$showreqcrs) {
1.248 raeburn 1376: $output.=&clear($row,$col);
1377: next;
1378: }
1379: }
1380: $prt='any';
1381: $output.=&secondlevel(
1382: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1383: }
1.13 harris41 1384: }
1.2 www 1385: return $output;
1386: }
1387:
1.279 raeburn 1388: sub check_for_rcrs {
1389: my $showreqcrs = 0;
1.280 raeburn 1390: my @reqtypes = ('official','unofficial','community');
1391: foreach my $type (@reqtypes) {
1.279 raeburn 1392: if (&Apache::lonnet::usertools_access($env{'user.name'},
1393: $env{'user.domain'},
1394: $type,undef,'requestcourses')) {
1395: $showreqcrs = 1;
1396: last;
1397: }
1398: }
1.280 raeburn 1399: if (!$showreqcrs) {
1400: foreach my $type (@reqtypes) {
1401: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1402: $showreqcrs = 1;
1403: last;
1404: }
1405: }
1406: }
1.279 raeburn 1407: return $showreqcrs;
1408: }
1409:
1.306 raeburn 1410: sub dc_popup_js {
1411: my %lt = &Apache::lonlocal::texthash(
1412: more => '(More ...)',
1413: less => '(Less ...)',
1414: );
1415: return <<"END";
1416:
1417: function showCourseID() {
1418: document.getElementById('dccid').style.display='block';
1419: document.getElementById('dccid').style.textAlign='left';
1.307 raeburn 1420: document.getElementById('dccid').style.textFace='normal';
1.369 raeburn 1421: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306 raeburn 1422: return;
1423: }
1424:
1425: function hideCourseID() {
1426: document.getElementById('dccid').style.display='none';
1.369 raeburn 1427: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306 raeburn 1428: return;
1429: }
1430:
1431: END
1432:
1433: }
1434:
1.378 raeburn 1435: sub countdown_toggle_js {
1436: return <<"END";
1437:
1438: function toggleCountdown() {
1439: var countdownid = document.getElementById('duedatecountdown');
1440: var currstyle = countdownid.style.display;
1441: if (currstyle == 'inline') {
1442: countdownid.style.display = 'none';
1443: document.getElementById('ddcountcollapse').innerHTML='';
1444: document.getElementById('ddcountexpand').innerHTML='◄ ';
1445: } else {
1446: countdownid.style.display = 'inline';
1447: document.getElementById('ddcountcollapse').innerHTML='► ';
1448: document.getElementById('ddcountexpand').innerHTML='';
1449: }
1450: return;
1451: }
1452:
1453: END
1454: }
1455:
1.42 www 1456: sub utilityfunctions {
1.421 raeburn 1457: my ($httphost) = @_;
1.152 albertel 1458: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.316 droeschl 1459: if ($currenturl =~ m{^/adm/wrapper/ext/}
1460: && $env{'request.external.querystring'} ) {
1.293 raeburn 1461: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1462: }
1.183 www 1463: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125 albertel 1464:
1.152 albertel 1465: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.175 albertel 1466:
1.306 raeburn 1467: my $dc_popup_cid;
1468: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1469: $env{'course.'.$env{'request.course.id'}.
1470: '.domain'}.'/'})) {
1471: $dc_popup_cid = &dc_popup_js();
1472: }
1473:
1.175 albertel 1474: my $start_page_annotate =
1475: &Apache::loncommon::start_page('Annotator',undef,
1476: {'only_body' => 1,
1477: 'js_ready' => 1,
1478: 'bgcolor' => '#BBBBBB',
1479: 'add_entries' => {
1480: 'onload' => 'javascript:document.goannotate.submit();'}});
1481:
1.205 albertel 1482: my $end_page_annotate =
1483: &Apache::loncommon::end_page({'js_ready' => 1});
1484:
1.389 raeburn 1485: my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336 raeburn 1486:
1.368 www 1487: my $esc_url=&escape($currenturl);
1488: my $esc_symb=&escape($currentsymb);
1.332 wenzelju 1489:
1.378 raeburn 1490: my $countdown = &countdown_toggle_js();
1491:
1.42 www 1492: return (<<ENDUTILITY)
1.421 raeburn 1493: var host="$httphost";
1.368 www 1494: var currentURL=unescape("$esc_url");
1495: var reloadURL=unescape("$esc_url");
1496: var currentSymb=unescape("$esc_symb");
1.42 www 1497:
1.306 raeburn 1498: $dc_popup_cid
1.114 albertel 1499:
1.389 raeburn 1500: $jumptores
1.336 raeburn 1501:
1.42 www 1502: function gopost(url,postdata) {
1503: if (url!='') {
1.421 raeburn 1504: this.document.server.action=host+url;
1.42 www 1505: this.document.server.postdata.value=postdata;
1506: this.document.server.command.value='';
1507: this.document.server.url.value='';
1508: this.document.server.symb.value='';
1509: this.document.server.submit();
1510: }
1511: }
1512:
1513: function gocmd(url,cmd) {
1514: if (url!='') {
1.421 raeburn 1515: this.document.server.action=host+url;
1.42 www 1516: this.document.server.postdata.value='';
1517: this.document.server.command.value=cmd;
1518: this.document.server.url.value=currentURL;
1519: this.document.server.symb.value=currentSymb;
1520: this.document.server.submit();
1521: }
1.57 www 1522: }
1523:
1.121 raeburn 1524: function gocstr(url,filename) {
1525: if (url == '/adm/cfile?action=delete') {
1526: this.document.cstrdelete.filename.value = filename
1527: this.document.cstrdelete.submit();
1528: return;
1529: }
1.137 raeburn 1530: if (url == '/adm/printout') {
1531: this.document.cstrprint.postdata.value = filename
1532: this.document.cstrprint.curseed.value = 0;
1533: this.document.cstrprint.problemtype.value = 0;
1.138 raeburn 1534: if (this.document.lonhomework) {
1535: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1536: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1537: }
1538: if (this.document.lonhomework.problemtype) {
1.164 albertel 1539: if (this.document.lonhomework.problemtype.value) {
1540: this.document.cstrprint.problemtype.value =
1541: this.document.lonhomework.problemtype.value;
1542: } else if (this.document.lonhomework.problemtype.options) {
1543: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1544: if (this.document.lonhomework.problemtype.options[i].selected) {
1545: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1546: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1547: }
1548: }
1549: }
1550: }
1551: }
1552: }
1.137 raeburn 1553: this.document.cstrprint.submit();
1554: return;
1555: }
1.121 raeburn 1556: if (url !='') {
1557: this.document.constspace.filename.value = filename;
1558: this.document.constspace.action = url;
1559: this.document.constspace.submit();
1560: }
1561: }
1562:
1.131 raeburn 1563: function golist(url) {
1564: if (url!='' && url!= null) {
1565: currentURL = null;
1566: currentSymb= null;
1.421 raeburn 1567: top.location.href=host+url;
1.131 raeburn 1568: }
1569: }
1570:
1571:
1.121 raeburn 1572:
1.57 www 1573: function catalog_info() {
1.365 www 1574: openMyModal(window.location.pathname+'.meta',500,400,'yes');
1.57 www 1575: }
1576:
1577: function chat_win() {
1.421 raeburn 1578: lonchat=window.open(host+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42 www 1579: }
1.169 raeburn 1580:
1581: function group_chat(group) {
1.421 raeburn 1582: var url = host+'/adm/groupchat?group='+group;
1.169 raeburn 1583: var winName = 'LONchat_'+group;
1584: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1585: }
1.175 albertel 1586:
1587: function annotate() {
1588: w_Annotator_flag=1;
1589: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1590: annotator.document.write(
1591: '$start_page_annotate'
1592: +"<form name='goannotate' target='Annotator' method='post' "
1593: +"action='/adm/annotations'>"
1.217 albertel 1594: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181 albertel 1595: +"<\\/form>"
1.205 albertel 1596: +'$end_page_annotate');
1.175 albertel 1597: annotator.document.close();
1598: }
1599:
1.370 raeburn 1600: function open_StoredLinks_Import(rat) {
1.335 wenzelju 1601: var newWin;
1602: if (rat) {
1.421 raeburn 1603: newWin = window.open(host+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.334 wenzelju 1604: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1.335 wenzelju 1605: }
1606: else {
1.421 raeburn 1607: newWin = window.open(host+'/adm/wishlist?inhibitmenu=yes&mode=import',
1.335 wenzelju 1608: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1609: }
1.334 wenzelju 1610: newWin.focus();
1611: }
1612:
1.372 raeburn 1613: (function (\$) {
1614: \$(document).ready(function () {
1615: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
1616: /*\@cc_on
1617: if (!window.XMLHttpRequest) {
1618: \$('.LC_hoverable').each(function () {
1619: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
1620: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
1621: });
1622: }
1623: \@*/
1624: });
1625: }(jQuery));
1626:
1.378 raeburn 1627: $countdown
1628:
1.42 www 1629: ENDUTILITY
1630: }
1631:
1632: sub serverform {
1633: return(<<ENDSERVERFORM);
1.181 albertel 1634: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 1635: <input type="hidden" name="postdata" value="none" />
1636: <input type="hidden" name="command" value="none" />
1637: <input type="hidden" name="url" value="none" />
1638: <input type="hidden" name="symb" value="none" />
1639: </form>
1640: ENDSERVERFORM
1641: }
1.113 albertel 1642:
1.121 raeburn 1643: sub constspaceform {
1644: return(<<ENDCONSTSPACEFORM);
1.181 albertel 1645: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121 raeburn 1646: <input type="hidden" name="filename" value="" />
1647: </form>
1.181 albertel 1648: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121 raeburn 1649: <input type="hidden" name="action" value="delete" />
1650: <input type="hidden" name="filename" value="" />
1651: </form>
1.181 albertel 1652: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137 raeburn 1653: <input type="hidden" name="postdata" value="" />
1654: <input type="hidden" name="curseed" value="" />
1655: <input type="hidden" name="problemtype" value="" />
1656: </form>
1657:
1.121 raeburn 1658: ENDCONSTSPACEFORM
1659: }
1660:
1.220 raeburn 1661: sub hidden_button_check {
1.317 droeschl 1662: if ( $env{'request.course.id'} eq ''
1663: || $env{'request.role.adv'} ) {
1664:
1.220 raeburn 1665: return;
1666: }
1.232 raeburn 1667: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1668: return $buttonshide;
1.220 raeburn 1669: }
1.184 raeburn 1670:
1.235 raeburn 1671: sub roles_selector {
1.421 raeburn 1672: my ($cdom,$cnum,$httphost) = @_;
1.298 raeburn 1673: my $crstype = &Apache::loncommon::course_type();
1.235 raeburn 1674: my $now = time;
1.350 raeburn 1675: my (%courseroles,%seccount,%courseprivs);
1.235 raeburn 1676: my $is_cc;
1.401 raeburn 1677: my ($js,$form,$switcher,$switchtext);
1.298 raeburn 1678: my $ccrole;
1679: if ($crstype eq 'Community') {
1680: $ccrole = 'co';
1681: } else {
1682: $ccrole = 'cc';
1.350 raeburn 1683: }
1.386 raeburn 1684: my ($priv,$gotsymb,$destsymb);
1.350 raeburn 1685: my $destinationurl = $ENV{'REQUEST_URI'};
1.386 raeburn 1686: if ($destinationurl =~ /\?symb=/) {
1687: $gotsymb = 1;
1688: } elsif ($destinationurl =~ m{^/enc/}) {
1689: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
1690: if ($plainurl =~ /\?symb=/) {
1691: $gotsymb = 1;
1692: }
1693: }
1694: unless ($gotsymb) {
1695: $destsymb = &Apache::lonnet::symbread();
1696: if ($destsymb ne '') {
1697: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
1698: }
1699: }
1.350 raeburn 1700: my $reqprivs = &required_privs();
1701: if (ref($reqprivs) eq 'HASH') {
1702: my $destination = $destinationurl;
1703: $destination =~ s/(\?.*)$//;
1704: if (exists($reqprivs->{$destination})) {
1705: $priv = $reqprivs->{$destination};
1706: }
1707: }
1.298 raeburn 1708: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
1709: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235 raeburn 1710:
1711: if ((($start) && ($start<0)) ||
1712: (($end) && ($end<$now)) ||
1713: (($start) && ($now<$start))) {
1714: $is_cc = 0;
1715: } else {
1716: $is_cc = 1;
1717: }
1718: }
1719: if ($is_cc) {
1.350 raeburn 1720: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1.235 raeburn 1721: } else {
1.262 raeburn 1722: my %gotnosection;
1.235 raeburn 1723: foreach my $item (keys(%env)) {
1.239 raeburn 1724: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235 raeburn 1725: my $role = $1;
1726: my $sec = $2;
1727: next if ($role eq 'gr');
1728: my ($start,$end) = split(/\./,$env{$item});
1729: next if (($start && $start > $now) || ($end && $end < $now));
1730: if ($sec eq '') {
1.239 raeburn 1731: if (!$gotnosection{$role}) {
1732: $seccount{$role} ++;
1733: $gotnosection{$role} = 1;
1734: }
1.235 raeburn 1735: }
1.350 raeburn 1736: if ($priv ne '') {
1737: my $cnumsec = $cnum;
1738: if ($sec ne '') {
1739: $cnumsec .= "/$sec";
1740: }
1741: $courseprivs{"$role./$cdom/$cnumsec./"} =
1742: $env{"user.priv.$role./$cdom/$cnumsec./"};
1743: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
1744: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
1745: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
1746: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
1747: }
1.235 raeburn 1748: if (ref($courseroles{$role}) eq 'ARRAY') {
1.239 raeburn 1749: if ($sec ne '') {
1.264 raeburn 1750: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239 raeburn 1751: push(@{$courseroles{$role}},$sec);
1752: $seccount{$role} ++;
1753: }
1754: }
1755: } else {
1756: @{$courseroles{$role}} = ();
1757: if ($sec ne '') {
1758: $seccount{$role} ++;
1.235 raeburn 1759: push(@{$courseroles{$role}},$sec);
1760: }
1761: }
1762: }
1763: }
1764: }
1.419 bisitz 1765: $switchtext = 'Switch role'; # do not translate here
1.298 raeburn 1766: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.402 raeburn 1767: my $numdiffsec;
1768: if (keys(%seccount) == 1) {
1769: foreach my $key (keys(%seccount)) {
1770: $numdiffsec = $seccount{$key};
1771: }
1772: }
1773: if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
1.401 raeburn 1774: my @submenu;
1775: $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
1776: $form =
1.421 raeburn 1777: '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
1.401 raeburn 1778: ' <input type="hidden" name="destinationurl" value="'.
1779: &HTML::Entities::encode($destinationurl).'" />'."\n".
1780: ' <input type="hidden" name="gotorole" value="1" />'."\n".
1781: ' <input type="hidden" name="selectrole" value="" />'."\n".
1.402 raeburn 1782: ' <input type="hidden" name="switchrole" value="" />'."\n";
1783: if ($destsymb ne '') {
1784: $form .= ' <input type="hidden" name="destsymb" value="'.
1785: &HTML::Entities::encode($destsymb).'" />'."\n";
1786: }
1787: $form .= '</form>'."\n";
1.235 raeburn 1788: foreach my $role (@roles_order) {
1.402 raeburn 1789: my $include;
1.235 raeburn 1790: if (defined($courseroles{$role})) {
1.402 raeburn 1791: if ($env{'request.role'} =~ m{^\Q$role\E}) {
1792: if ($seccount{$role} > 1) {
1793: $include = 1;
1794: }
1795: } else {
1796: $include = 1;
1797: }
1798: }
1799: if ($include) {
1.401 raeburn 1800: push(@submenu,['javascript:adhocRole('."'$role'".')',
1801: &Apache::lonnet::plaintext($role,$crstype)]);
1.235 raeburn 1802: }
1803: }
1804: foreach my $role (sort(keys(%courseroles))) {
1805: if ($role =~ /^cr/) {
1.403 raeburn 1806: my $include;
1807: if ($env{'request.role'} =~ m{^\Q$role\E}) {
1.402 raeburn 1808: if ($seccount{$role} > 1) {
1809: $include = 1;
1810: }
1.403 raeburn 1811: } else {
1812: $include = 1;
1813: }
1814: if ($include) {
1815: push(@submenu,['javascript:adhocRole('."'$role'".')',
1816: &Apache::lonnet::plaintext($role)]);
1817: }
1.235 raeburn 1818: }
1819: }
1.401 raeburn 1820: if (@submenu > 0) {
1821: $switcher = &create_submenu('','',$switchtext,\@submenu);
1.386 raeburn 1822: }
1.235 raeburn 1823: }
1.401 raeburn 1824: return ($js,$form,$switcher);
1.235 raeburn 1825: }
1826:
1.262 raeburn 1827: sub get_all_courseroles {
1.350 raeburn 1828: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351 raeburn 1829: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350 raeburn 1830: (ref($courseprivs) eq 'HASH')) {
1.262 raeburn 1831: return;
1832: }
1833: my ($result,$cached) =
1834: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1835: if (defined($cached)) {
1836: if (ref($result) eq 'HASH') {
1837: if ((ref($result->{'roles'}) eq 'HASH') &&
1.350 raeburn 1838: (ref($result->{'seccount'}) eq 'HASH') &&
1839: (ref($result->{'privs'}) eq 'HASH')) {
1.262 raeburn 1840: %{$courseroles} = %{$result->{'roles'}};
1841: %{$seccount} = %{$result->{'seccount'}};
1.350 raeburn 1842: %{$courseprivs} = %{$result->{'privs'}};
1.262 raeburn 1843: return;
1844: }
1845: }
1846: }
1847: my %gotnosection;
1848: my %adv_roles =
1849: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1850: foreach my $role (keys(%adv_roles)) {
1851: my ($urole,$usec) = split(/:/,$role);
1852: if (!$gotnosection{$urole}) {
1853: $seccount->{$urole} ++;
1854: $gotnosection{$urole} = 1;
1855: }
1856: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1857: if ($usec ne '') {
1858: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1859: push(@{$courseroles->{$urole}},$usec);
1860: $seccount->{$urole} ++;
1861: }
1862: }
1863: } else {
1864: @{$courseroles->{$urole}} = ();
1865: if ($usec ne '') {
1866: $seccount->{$urole} ++;
1867: push(@{$courseroles->{$urole}},$usec);
1868: }
1869: }
1.350 raeburn 1870: my $area = '/'.$cdom.'/'.$cnum;
1871: if ($usec ne '') {
1872: $area .= '/'.$usec;
1873: }
1874: if ($role =~ /^cr\//) {
1875: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
1876: } else {
1877: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
1878: }
1.262 raeburn 1879: }
1880: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1881: @{$courseroles->{'st'}} = ();
1.350 raeburn 1882: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262 raeburn 1883: if (keys(%sections_count) > 0) {
1884: push(@{$courseroles->{'st'}},keys(%sections_count));
1.350 raeburn 1885: $seccount->{'st'} = scalar(keys(%sections_count));
1.262 raeburn 1886: }
1.410 raeburn 1887: $seccount->{'st'} ++; # Increment for a section-less student role.
1.262 raeburn 1888: my $rolehash = {
1889: 'roles' => $courseroles,
1890: 'seccount' => $seccount,
1.350 raeburn 1891: 'privs' => $courseprivs,
1.262 raeburn 1892: };
1893: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1894: return;
1895: }
1896:
1.235 raeburn 1897: sub jump_to_role {
1.350 raeburn 1898: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
1.239 raeburn 1899: my %lt = &Apache::lonlocal::texthash(
1900: this => 'This role has section(s) associated with it.',
1901: ente => 'Enter a specific section.',
1902: orlb => 'Enter a specific section, or leave blank for no section.',
1903: avai => 'Available sections are:',
1904: youe => 'You entered an invalid section choice:',
1.352 raeburn 1905: plst => 'Please try again.',
1.350 raeburn 1906: role => 'The role you selected is not permitted to view the current page.',
1907: swit => 'Switch role, but display Main Menu page instead?',
1.239 raeburn 1908: );
1909: my $js;
1910: if (ref($courseroles) eq 'HASH') {
1911: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1912: ' var numsec = new Array();'."\n".
1913: ' var rolesections = new Array();'."\n".
1914: ' var rolenames = new Array();'."\n".
1915: ' var roleseclist = new Array();'."\n";
1916: my @items = keys(%{$courseroles});
1917: for (my $i=0; $i<@items; $i++) {
1918: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1919: my ($secs,$secstr);
1920: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1921: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1922: $secs = join('","',@sections);
1923: $secstr = join(', ',@sections);
1924: }
1925: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1926: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1927: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1928: }
1929: }
1.350 raeburn 1930: my $checkroles = 0;
1931: if ($priv && ref($courseprivs) eq 'HASH') {
1932: my (%disallowed,%allowed,@disallow);
1933: foreach my $role (sort(keys(%{$courseprivs}))) {
1934: my $trole;
1935: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
1936: $trole = $1;
1937: }
1938: if (($trole ne '') && ($trole ne 'cm')) {
1939: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
1940: $allowed{$trole} = 1;
1941: } else {
1942: $disallowed{$trole} = 1;
1943: }
1944: }
1945: }
1946: foreach my $trole (keys(%disallowed)) {
1947: unless ($allowed{$trole}) {
1948: push(@disallow,$trole);
1949: }
1950: }
1951: if (@disallow > 0) {
1952: $checkroles = 1;
1953: $js .= " var disallow = new Array('".join("','",@disallow)."');\n".
1954: " var rolecheck = 1;\n";
1955: }
1956: }
1957: if (!$checkroles) {
1958: $js .= " var disallow = new Array();\n".
1959: " rolecheck = 0;\n";
1960: }
1.273 droeschl 1961: return <<"END";
1.235 raeburn 1962: <script type="text/javascript">
1.273 droeschl 1963: //<![CDATA[
1.401 raeburn 1964: function adhocRole(newrole) {
1.239 raeburn 1965: $js
1.235 raeburn 1966: if (newrole == '') {
1.350 raeburn 1967: return;
1.235 raeburn 1968: }
1.239 raeburn 1969: var fullrole = newrole+'./$cdom/$cnum';
1970: var selidx = '';
1971: for (var i=0; i<rolenames.length; i++) {
1972: if (rolenames[i] == newrole) {
1973: selidx = i;
1974: }
1975: }
1.350 raeburn 1976: if (rolecheck > 0) {
1977: for (var i=0; i<disallow.length; i++) {
1978: if (disallow[i] == newrole) {
1979: if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
1980: document.rolechooser.destinationurl.value = '/adm/menu';
1981: } else {
1982: return;
1983: }
1984: }
1985: }
1986: }
1.239 raeburn 1987: var secok = 1;
1988: var secchoice = '';
1989: if (selidx >= 0) {
1990: if (numsec[selidx] > 1) {
1991: secok = 0;
1992: var numrolesec = rolesections[selidx].length;
1993: var msgidx = numsec[selidx] - numrolesec;
1.339 raeburn 1994: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239 raeburn 1995: if (secchoice == '') {
1996: if (msgidx > 0) {
1997: secok = 1;
1998: }
1999: } else {
2000: for (var j=0; j<rolesections[selidx].length; j++) {
2001: if (rolesections[selidx][j] == secchoice) {
2002: secok = 1;
2003: }
2004: }
2005: }
2006: } else {
2007: if (rolesections[selidx].length == 1) {
2008: secchoice = rolesections[selidx][0];
2009: }
2010: }
2011: }
2012: if (secok == 1) {
2013: if (secchoice != '') {
2014: fullrole += '/'+secchoice;
2015: }
2016: } else {
2017: if (secchoice != null) {
2018: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
2019: }
2020: return;
2021: }
2022: if (fullrole == "$env{'request.role'}") {
1.235 raeburn 2023: return;
2024: }
2025: itemid = retrieveIndex('gotorole');
2026: if (itemid != -1) {
1.239 raeburn 2027: document.rolechooser.elements[itemid].name = fullrole;
1.235 raeburn 2028: }
1.401 raeburn 2029: document.rolechooser.switchrole.value = fullrole;
1.235 raeburn 2030: document.rolechooser.selectrole.value = '1';
2031: document.rolechooser.submit();
2032: return;
2033: }
2034:
2035: function retrieveIndex(item) {
2036: for (var i=0;i<document.rolechooser.elements.length;i++) {
2037: if (document.rolechooser.elements[i].name == item) {
2038: return i;
2039: }
2040: }
2041: return -1;
2042: }
1.273 droeschl 2043: // ]]>
1.235 raeburn 2044: </script>
2045: END
2046: }
2047:
1.350 raeburn 2048: sub required_privs {
2049: my $privs = {
2050: '/adm/parmset' => 'opa',
2051: '/adm/courseprefs' => 'opa',
2052: '/adm/whatsnew' => 'whn',
2053: '/adm/populate' => 'cst',
2054: '/adm/trackstudent' => 'vsa',
2055: '/adm/statistics' => 'vgr',
1.366 raeburn 2056: '/adm/setblock' => 'dcm',
1.367 raeburn 2057: '/adm/coursedocs' => 'mdc',
1.350 raeburn 2058: };
2059: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364 raeburn 2060: $privs->{'/adm/classcalc'} = 'vgr',
2061: $privs->{'/adm/assesscalc'} = 'vgr',
2062: $privs->{'/adm/studentcalc'} = 'vgr';
1.350 raeburn 2063: }
2064: return $privs;
2065: }
1.235 raeburn 2066:
1.378 raeburn 2067: sub countdown_timer {
2068: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.387 raeburn 2069: ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
2070: my ($type,$hastimeleft,$slothastime);
2071: my $now = time;
2072: if ($env{'request.filename'} =~ /\.task$/) {
2073: $type = 'Task';
2074: } else {
2075: $type = 'problem';
2076: }
2077: my ($status,$accessmsg,$slot_name,$slot) =
2078: &Apache::lonhomework::check_slot_access('0',$type);
2079: if ($slot_name ne '') {
2080: if (ref($slot) eq 'HASH') {
2081: if (($slot->{'starttime'} < $now) &&
2082: ($slot->{'endtime'} > $now)) {
2083: $slothastime = 1;
2084: }
2085: }
2086: }
2087: if ($status ne 'CAN_ANSWER') {
2088: return;
2089: }
1.378 raeburn 2090: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.380 raeburn 2091: my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.381 raeburn 2092: if (@interval > 1) {
2093: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
2094: if ($first_access > 0) {
2095: if ($first_access+$interval[0] > time) {
2096: $hastimeleft = 1;
2097: }
2098: }
2099: }
1.380 raeburn 2100: if (($duedate && $duedate > time) ||
1.387 raeburn 2101: (!$duedate && $hastimeleft) ||
2102: ($slot_name ne '' && $slothastime)) {
1.379 raeburn 2103: my ($collapse,$expand,$alttxt,$title,$currdisp);
1.387 raeburn 2104: if ((@interval > 1 && $hastimeleft) ||
2105: ($type eq 'Task' && $slothastime)) {
1.378 raeburn 2106: $currdisp = 'inline';
2107: $collapse = '► ';
2108: } else {
2109: $currdisp = 'none';
2110: $expand = '◄ ';
2111: }
2112: unless ($env{'environment.icons'} eq 'iconsonly') {
1.379 raeburn 2113: $alttxt = &mt('Timer');
2114: $title = $alttxt.' ';
1.378 raeburn 2115: }
2116: my $desc = &mt('Countdown to due date/time');
2117: return <<END;
2118:
2119: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
2120: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
2121: $collapse
1.379 raeburn 2122: </span></a>
1.378 raeburn 2123: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
2124: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
2125: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.379 raeburn 2126: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
1.378 raeburn 2127: END
2128: }
2129: }
2130: return;
2131: }
2132:
1.2 www 2133: # ================================================================ Main Program
2134:
1.16 harris41 2135: BEGIN {
1.166 albertel 2136: if (! defined($readdesk)) {
1.283 droeschl 2137: {
2138: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
2139: if ( CORE::open( my $config,"<$tabfile") ) {
2140: while (my $configline=<$config>) {
2141: $configline=(split(/\#/,$configline))[0];
2142: $configline=~s/^\s+//;
2143: chomp($configline);
1.209 www 2144: if ($configline=~/^cat\:/) {
1.283 droeschl 2145: my @entries=split(/\:/,$configline);
2146: $category_positions{$entries[2]}=$entries[1];
2147: $category_names{$entries[2]}=$entries[3];
2148: } elsif ($configline=~/^prim\:/) {
1.415 raeburn 2149: my @entries = (split(/\:/, $configline))[1..6];
1.400 raeburn 2150: push(@primary_menu,\@entries);
1.371 raeburn 2151: } elsif ($configline=~/^primsub\:/) {
2152: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.400 raeburn 2153: push(@{$primary_submenu{$parent}},\@entries);
1.283 droeschl 2154: } elsif ($configline=~/^scnd\:/) {
2155: my @entries = (split(/\:/, $configline))[1..5];
1.401 raeburn 2156: push(@secondary_menu,\@entries);
1.283 droeschl 2157: } elsif ($configline) {
2158: push(@desklines,$configline);
2159: }
2160: }
2161: CORE::close($config);
2162: }
2163: }
2164: $readdesk='done';
1.2 www 2165: }
2166: }
1.30 www 2167:
1.1 www 2168: 1;
2169: __END__
2170:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>