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