Annotation of loncom/interface/lonmenu.pm, revision 1.387
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.387 ! raeburn 4: # $Id: lonmenu.pm,v 1.386 2012/09/04 20:47:56 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.321 droeschl 434: my ($forcereg,$bread_crumbs) = @_;
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.348 raeburn 444: my $resurl;
1.316 droeschl 445: if ( $env{'request.symb'} && $env{'request.course.id'} ) {
1.267 droeschl 446:
1.348 raeburn 447: (my $mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
1.267 droeschl 448: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
449:
450: my $maptitle = &Apache::lonnet::gettitle($mapurl);
451: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.318 droeschl 452:
453: #SD
454: #course_type only Course and Community?
455: #
1.324 raeburn 456: my @crumbs;
457: unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps')
458: && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
459: @crumbs = ({text => Apache::loncommon::course_type()
1.318 droeschl 460: . ' Contents',
1.324 raeburn 461: href => "Javascript:gopost('/adm/navmaps','')"});
462: }
1.289 raeburn 463: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
464: push(@crumbs, {text => '...',
465: no_mt => 1});
466: }
1.268 droeschl 467:
468: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
469: && $maptitle ne 'default.sequence'
470: && $maptitle ne $coursetitle);
471:
472: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
473:
1.291 raeburn 474: &Apache::lonhtmlcommon::clear_breadcrumbs();
475: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
1.328 droeschl 476: }elsif (! $const_space){
477: #a situation when we're looking at a resource outside of context of a
478: #course or construction space (e.g. with cumulative rights)
479: &Apache::lonhtmlcommon::clear_breadcrumbs();
480: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
1.65 www 481: }
1.41 www 482: # =============================================================================
483: # ============================ This is for URLs that actually can be registered
1.316 droeschl 484: return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
485: || $forcereg );
1.317 droeschl 486:
1.40 www 487: # -- This applies to homework problems for users with grading privileges
1.152 albertel 488: my $crs='/'.$env{'request.course.id'};
489: if ($env{'request.course.sec'}) {
490: $crs.='_'.$env{'request.course.sec'};
1.107 albertel 491: }
492: $crs=~s/\_/\//g;
493:
1.38 www 494: my $hwkadd='';
1.152 albertel 495: if ($env{'request.symb'} ne '' &&
1.360 www 496: $env{'request.filename'}=~/$LONCAPA::assess_re/) {
1.79 www 497: if (&Apache::lonnet::allowed('mgr',$crs)) {
1.344 www 498: $hwkadd.=&switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
1.40 www 499: "gocmd('/adm/grades','gradingmenu')",
1.344 www 500: 'Content Grades');
1.154 www 501: } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
1.344 www 502: $hwkadd.=&switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
1.154 www 503: "gocmd('/adm/grades','submission')",
1.344 www 504: 'Content Submissions');
1.38 www 505: }
1.107 albertel 506: }
1.152 albertel 507: if ($env{'request.symb'} ne '' &&
1.145 albertel 508: &Apache::lonnet::allowed('opa',$crs)) {
1.344 www 509: $hwkadd.=&switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
1.107 albertel 510: "gocmd('/adm/parmset','set')",
1.344 www 511: 'Content Settings');
1.38 www 512: }
1.363 www 513: if ($env{'request.symb'}=~/^uploaded/ &&
1.362 www 514: &Apache::lonnet::allowed('mdc',$crs)) {
515: $hwkadd.=&switch('','',7,4,'docs.png','Folder/Page Content','parms[_2]',
516: "gocmd('/adm/coursedocs','direct')",
517: 'Folder/Page Content');
518: }
1.40 www 519: # -- End Homework
1.38 www 520: ###
521: ### Determine whether or not to display the 'cstr' button for this
522: ### resource
523: ###
524: my $editbutton = '';
1.258 raeburn 525: my $noeditbutton = 1;
526: my ($cnum,$cdom);
527: if ($env{'request.course.id'}) {
528: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
529: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
530: }
1.152 albertel 531: if ($env{'user.author'}) {
1.234 raeburn 532: if ($env{'request.role'}=~/^(aa|ca|au)/) {
1.274 www 533: #
534: # We have the role of an author
535: #
1.38 www 536: # Set defaults for authors
537: my ($top,$bottom) = ('con-','struct');
1.353 www 538: my $action = "go('/priv/".$env{'user.domain'}.'/'.$env{'user.name'}."');";
1.152 albertel 539: my $cadom = $env{'request.role.domain'};
540: my $caname = $env{'user.name'};
1.236 bisitz 541: my $desc = "Enter my construction space";
1.38 www 542: # Set defaults for co-authors
1.152 albertel 543: if ($env{'request.role'} =~ /^ca/) {
1.206 albertel 544: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.38 www 545: ($top,$bottom) = ('co con-','struct');
1.353 www 546: $action = "go('/priv/".$cadom.'/'.$caname."');";
1.38 www 547: $desc = "Enter construction space as co-author";
1.234 raeburn 548: } elsif ($env{'request.role'} =~ /^aa/) {
549: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
550: ($top,$bottom) = ('co con-','struct');
1.353 www 551: $action = "go('/priv/".$cadom.'/'.$caname."');";
1.234 raeburn 552: $desc = "Enter construction space as assistant co-author";
1.38 www 553: }
554: # Check that we are on the correct machine
555: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 556: my $allowed=0;
557: my @ids=&Apache::lonnet::current_machine_ids();
558: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
559: if (!$allowed) {
560: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
1.258 raeburn 561: $noeditbutton = 0;
1.38 www 562: }
563: }
1.274 www 564: #
565: # We are an author for some stuff, but currently do not have the role of author.
566: # Figure out if we have authoring privileges for the resource we are looking at.
567: # This should maybe become a privilege check in lonnet
568: #
1.38 www 569: ##
570: ## Determine if user can edit url.
571: ##
572: my $cfile='';
573: my $cfuname='';
574: my $cfudom='';
1.258 raeburn 575: my $uploaded;
1.330 raeburn 576: my $switchserver='';
577: my $home;
1.152 albertel 578: if ($env{'request.filename'}) {
579: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.258 raeburn 580: if (defined($cnum) && defined($cdom)) {
581: $uploaded = &is_course_upload($file,$cnum,$cdom);
582: }
583: if (!$uploaded) {
1.357 raeburn 584:
585: $file=~s{^(priv/$match_domain/$match_username)}{/$1};
1.358 raeburn 586: $file=~s{^($match_domain/$match_username)}{/priv/$1};
1.356 raeburn 587:
1.258 raeburn 588: # Check that the user has permission to edit this resource
1.356 raeburn 589: my $setpriv = 1;
590: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$setpriv);
1.258 raeburn 591: if (defined($cfudom)) {
1.330 raeburn 592: $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
1.258 raeburn 593: my $allowed=0;
594: my @ids=&Apache::lonnet::current_machine_ids();
595: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
596: if ($allowed) {
597: $cfile=$file;
1.330 raeburn 598: } else {
599: $switchserver=$file;
1.258 raeburn 600: }
1.38 www 601: }
602: }
1.258 raeburn 603: }
1.38 www 604: # Finally, turn the button on or off
1.330 raeburn 605: if (($cfile || $switchserver) && !$const_space) {
1.302 raeburn 606: my $nocrsedit;
607: # Suppress display where CC has switched to student role.
608: if ($env{'request.course.id'}) {
609: unless(&Apache::lonnet::allowed('mdc',
610: $env{'request.course.id'})) {
611: $nocrsedit = 1;
612: }
613: }
614: if ($nocrsedit) {
615: $editbutton=&clear(6,1);
616: } else {
1.336 raeburn 617: my $bot = "go('$cfile')";
1.330 raeburn 618: if ($switchserver) {
619: if ( $env{'request.symb'} && $env{'request.course.id'} ) {
1.336 raeburn 620: $cfile = '/adm/switchserver?otherserver='.$home.'&role='.
621: &HTML::Entities::encode($env{'request.role'},'"<>&').'&symb='.
622: &HTML::Entities::encode($env{'request.symb'},'"<>&');
623: $bot = "need_switchserver('$cfile');";
1.330 raeburn 624: }
625: }
1.302 raeburn 626: $editbutton=&switch
1.345 www 627: ('','',6,1,'pcstr.png','Edit','resource[_2]',
1.336 raeburn 628: $bot,"Edit this resource");
1.302 raeburn 629: $noeditbutton = 0;
630: }
1.38 www 631: } elsif ($editbutton eq '') {
1.191 www 632: $editbutton=&clear(6,1);
1.38 www 633: }
634: }
1.258 raeburn 635: if (($noeditbutton) && ($env{'request.filename'})) {
636: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
637: my $file=&Apache::lonnet::declutter($env{'request.filename'});
638: if (defined($cnum) && defined($cdom)) {
639: if (&is_course_upload($file,$cnum,$cdom)) {
640: my $cfile = &edit_course_upload($file,$cnum,$cdom);
641: if ($cfile) {
642: $editbutton=&switch
1.345 www 643: ('','',6,1,'pcstr.png','Edit',
1.258 raeburn 644: 'resource[_2]',"go('".$cfile."');",
645: 'Edit this resource');
646: }
647: }
648: }
649: }
650: }
1.348 raeburn 651: if ($env{'request.course.id'}) {
652: if ($resurl eq "public/$cdom/$cnum/syllabus") {
653: if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ /\w/) {
654: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
655: $editbutton=&switch('','',6,1,'pcstr.png','Edit',
656: 'resource[_2]',
657: "go('/adm/courseprefs?phase=display&actions=courseinfo')",
658: 'Edit this resource');
659: }
660: }
661: }
662: }
1.38 www 663: ###
664: ###
1.41 www 665: # Prepare the rest of the buttons
1.383 raeburn 666: my ($menuitems,$got_prt,$got_wishlist);
1.120 raeburn 667: if ($const_space) {
1.274 www 668: #
669: # We are in construction space
670: #
1.353 www 671:
1.355 raeburn 672: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.353 www 673: my ($udom,$uname,$thisdisfn) =
1.355 raeburn 674: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1.353 www 675: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1.131 raeburn 676: if ($currdir =~ m-/$-) {
677: $is_const_dir = 1;
678: } else {
1.267 droeschl 679: $currdir =~ s|[^/]+$||;
1.200 foxr 680: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208 albertel 681: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274 www 682: #
683: # Probably should be in mydesk.tab
684: #
1.131 raeburn 685: $menuitems=(<<ENDMENUITEMS);
1.344 www 686: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1.353 www 687: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
688: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
689: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
690: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1.120 raeburn 691: ENDMENUITEMS
1.131 raeburn 692: }
1.308 raeburn 693: if (ref($bread_crumbs) eq 'ARRAY') {
694: &Apache::lonhtmlcommon::clear_breadcrumbs();
695: foreach my $crumb (@{$bread_crumbs}){
696: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
697: }
698: }
1.203 foxr 699: } elsif ( defined($env{'request.course.id'}) &&
700: $env{'request.symb'} ne '' ) {
1.274 www 701: #
1.383 raeburn 702: # We are in a course and looking at a registered URL
1.274 www 703: # Should probably be in mydesk.tab
704: #
1.120 raeburn 705: $menuitems=(<<ENDMENUITEMS);
1.41 www 706: c&3&1
1.344 www 707: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
708: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
1.77 www 709: c&6&3
710: c&8&1
711: c&8&2
1.344 www 712: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.41 www 713: ENDMENUITEMS
1.383 raeburn 714: $got_prt = 1;
715: if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
716: && (!$env{'request.enc'})) {
1.332 wenzelju 717: # wishlist is only available for users with access to resource-pool
718: # and links can only be set for resources within the resource-pool
719: $menuitems .= (<<ENDMENUITEMS);
1.370 raeburn 720: 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 721: ENDMENUITEMS
1.383 raeburn 722: $got_wishlist = 1;
1.332 wenzelju 723: }
1.216 albertel 724:
1.243 tempelho 725: my $currentURL = &Apache::loncommon::get_symb();
726: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
727: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
728: $menuitems.="s&9&3&";
729: if(length($annotation) > 0){
1.317 droeschl 730: $menuitems.="anot2.png";
1.243 tempelho 731: }else{
1.317 droeschl 732: $menuitems.="anot.png";
1.243 tempelho 733: }
1.344 www 734: $menuitems.="&Notes&&annotate()&";
1.243 tempelho 735: $menuitems.="Make notes and annotations about this resource&&1\n";
736:
1.323 raeburn 737: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1.382 raeburn 738: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
1.216 albertel 739: $menuitems.=(<<ENDREALRES);
1.344 www 740: s&6&3&catalog.png&Info&info[_1]&catalog_info()&Show Metadata
1.216 albertel 741: ENDREALRES
742: }
1.382 raeburn 743: unless ($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) {
744: $menuitems.=(<<ENDREALRES);
1.344 www 745: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1.382 raeburn 746: ENDREALRES
747: }
748: $menuitems.=(<<ENDREALRES);
1.344 www 749: 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 750: ENDREALRES
1.120 raeburn 751: }
752: }
1.203 foxr 753: if ($env{'request.uri'} =~ /^\/res/) {
1.383 raeburn 754: unless ($got_prt) {
755: $menuitems .= (<<ENDMENUITEMS);
1.344 www 756: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.203 foxr 757: ENDMENUITEMS
1.384 raeburn 758: $got_prt = 1;
1.383 raeburn 759: }
760: unless ($got_wishlist) {
761: if (($env{'user.adv'}) && (!$env{'request.enc'})) {
762: # wishlist is only available for users with access to resource-pool
763: $menuitems .= (<<ENDMENUITEMS);
1.374 bisitz 764: 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 765: ENDMENUITEMS
1.383 raeburn 766: $got_wishlist = 1;
767: }
768: }
769: }
1.41 www 770: my $buttons='';
771: foreach (split(/\n/,$menuitems)) {
772: my ($command,@rest)=split(/\&/,$_);
1.220 raeburn 773: my $idx=10*$rest[0]+$rest[1];
774: if (&hidden_button_check() eq 'yes') {
775: if ($idx == 21 ||$idx == 23) {
776: $buttons.=&switch('','',@rest);
777: } else {
778: $buttons.=&clear(@rest);
779: }
780: } else {
781: if ($command eq 's') {
782: $buttons.=&switch('','',@rest);
783: } else {
784: $buttons.=&clear(@rest);
785: }
1.41 www 786: }
787: }
1.148 albertel 788:
789: my $addremote=0;
1.267 droeschl 790: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.301 droeschl 791: if ($addremote) {
792:
1.342 www 793: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301 droeschl 794:
1.342 www 795: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.312 droeschl 796: 'navigation', @inlineremote[21,23]);
797:
1.378 raeburn 798: my $countdown = &countdown_timer();
799: if (&hidden_button_check() eq 'yes') {
800: if ($countdown) {
801: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
802: }
803: } else {
804: my @tools = @inlineremote[93,91,81,82,83];
805: if ($countdown) {
806: unshift(@tools,$countdown);
807: }
1.342 www 808: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.378 raeburn 809: 'tools',@tools);
1.313 droeschl 810:
811: #publish button in construction space
812: if ($env{'request.state'} eq 'construct'){
1.342 www 813: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349 raeburn 814: 'advtools', $inlineremote[63]);
1.342 www 815: } else {
816: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349 raeburn 817: 'tools', $inlineremote[63]);
1.313 droeschl 818: }
819:
1.322 raeburn 820: unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
1.342 www 821: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.362 www 822: 'advtools', @inlineremote[61,71,72,73,74,92]);
1.322 raeburn 823: }
1.301 droeschl 824: }
1.38 www 825: }
826:
1.342 www 827: return &Apache::lonhtmlcommon::scripttag('', 'start')
828: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
829: . &Apache::lonhtmlcommon::scripttag('', 'end');
1.38 www 830: }
831:
1.258 raeburn 832: sub is_course_upload {
833: my ($file,$cnum,$cdom) = @_;
834: my $uploadpath = &LONCAPA::propath($cdom,$cnum);
835: $uploadpath =~ s{^\/}{};
836: if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
837: ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
838: return 1;
839: }
840: return;
841: }
842:
843: sub edit_course_upload {
844: my ($file,$cnum,$cdom) = @_;
845: my $cfile;
846: if ($file =~/\.(htm|html|css|js|txt)$/) {
847: my $ext = $1;
848: my $url = &Apache::lonnet::hreflocation('',$file);
849: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
850: my @ids=&Apache::lonnet::current_machine_ids();
851: my $dest;
852: if ($home && grep(/^\Q$home\E$/,@ids)) {
853: $dest = $url.'?forceedit=1';
854: } else {
855: unless (&Apache::lonnet::get_locks()) {
856: $dest = '/adm/switchserver?otherserver='.
857: $home.'&role='.$env{'request.role'}.
858: '&url='.$url.'&forceedit=1';
859: }
860: }
861: if ($dest) {
862: $cfile = &HTML::Entities::encode($dest,'"<>&');
863: }
864: }
865: return $cfile;
866: }
867:
1.2 www 868: # ================================================================== Raw Config
869:
1.3 www 870: sub clear {
871: my ($row,$col)=@_;
1.316 droeschl 872: $inlineremote[10*$row+$col]='';
873: return '';
1.3 www 874: }
875:
1.40 www 876: # ============================================ Switch a button or create a link
1.25 matthew 877: # Switch acts on the javascript that is executed when a button is clicked.
878: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 879:
1.2 www 880: sub switch {
1.209 www 881: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2 www 882: $act=~s/\$uname/$uname/g;
883: $act=~s/\$udom/$udom/g;
1.88 www 884: $top=&mt($top);
885: $bot=&mt($bot);
886: $desc=&mt($desc);
1.209 www 887: my $idx=10*$row+$col;
888: $category_members{$cat}.=':'.$idx;
889:
1.320 droeschl 890: # Inline Menu
1.317 droeschl 891: if ($nobreak==2) { return ''; }
892: my $text=$top.' '.$bot;
893: $text=~s/\s*\-\s*//gs;
1.105 www 894:
1.317 droeschl 895: my $pic=
1.225 albertel 896: '<img alt="'.$text.'" src="'.
897: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303 droeschl 898: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317 droeschl 899: if ($env{'browser.interface'} eq 'faketextual') {
1.274 www 900: # Main Menu
1.103 www 901: if ($nobreak==3) {
1.209 www 902: $inlineremote[$idx]="\n".
1.177 albertel 903: '<td class="LC_menubuttons_text" align="right">'.$text.
1.247 harmsja 904: '</td><td align="left">'.
1.103 www 905: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
906: } elsif ($nobreak) {
1.209 www 907: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 908: '<td align="left">'.
1.177 albertel 909: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215 www 910: <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 911: } else {
1.209 www 912: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 913: '<td align="left">'.
1.103 www 914: '<a href="javascript:'.$act.';">'.$pic.
1.177 albertel 915: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215 www 916: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103 www 917: }
1.317 droeschl 918: } else {
1.103 www 919: # Inline Menu
1.378 raeburn 920: my @tools = (93,91,81,82,83);
921: unless ($env{'request.state'} eq 'construct') {
922: push(@tools,63);
923: }
924: if (($env{'environment.icons'} eq 'iconsonly') &&
925: (grep(/^$idx$/,@tools))) {
926: $inlineremote[$idx] =
927: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
928: } else {
929: $inlineremote[$idx] =
1.317 droeschl 930: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344 www 931: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
1.378 raeburn 932: }
1.317 droeschl 933: }
1.56 www 934: return '';
1.2 www 935: }
936:
937: sub secondlevel {
938: my $output='';
939: my
1.209 www 940: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2 www 941: if ($prt eq 'any') {
1.209 www 942: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 943: } elsif ($prt=~/^r(\w+)/) {
944: if ($rol eq $1) {
1.209 www 945: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 946: }
947: }
948: return $output;
949: }
950:
1.56 www 951: sub inlinemenu {
1.210 albertel 952: undef(@inlineremote);
953: undef(%category_members);
1.275 www 954: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56 www 955: &rawconfig(1);
1.309 bisitz 956: my $output='<table><tr>';
1.209 www 957: for (my $col=1; $col<=2; $col++) {
1.241 riegler 958: $output.='<td class="LC_mainmenu_col_fieldset">';
1.209 www 959: for (my $row=1; $row<=8; $row++) {
960: foreach my $cat (keys(%category_members)) {
961: if ($category_positions{$cat} ne "$col,$row") { next; }
1.247 harmsja 962: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309 bisitz 963: $output.='<div class="LC_Box LC_400Box">';
964: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247 harmsja 965: $output.='<table>';
1.240 riegler 966: my %active=();
967: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
968: if ($inlineremote[$menu_item]) {
969: $active{$menu_item}=1;
970: }
971: }
972: foreach my $item (sort(keys(%active))) {
973: $output.=$inlineremote[$item];
974: }
975: $output.='</table>';
1.245 harmsja 976: $output.='</div>';
1.240 riegler 977: }
978: }
979: $output.="</td>";
980: }
981: $output.="</tr></table>";
982: return $output;
983: }
984:
1.2 www 985: sub rawconfig {
1.274 www 986: #
987: # This evaluates mydesk.tab
988: # Need to add more positions and more privileges to deal with all
989: # menu items.
990: #
1.34 www 991: my $textualoverride=shift;
992: my $output='';
1.316 droeschl 993: return '' unless $textualoverride;
1.152 albertel 994: my $uname=$env{'user.name'};
995: my $udom=$env{'user.domain'};
996: my $adv=$env{'user.adv'};
1.266 raeburn 997: my $show_course=&Apache::loncommon::show_course();
1.152 albertel 998: my $author=$env{'user.author'};
1.5 www 999: my $crs='';
1.295 raeburn 1000: my $crstype='';
1.152 albertel 1001: if ($env{'request.course.id'}) {
1002: $crs='/'.$env{'request.course.id'};
1003: if ($env{'request.course.sec'}) {
1004: $crs.='_'.$env{'request.course.sec'};
1.7 www 1005: }
1.8 www 1006: $crs=~s/\_/\//g;
1.295 raeburn 1007: $crstype = &Apache::loncommon::course_type();
1.5 www 1008: }
1.152 albertel 1009: my $pub=($env{'request.state'} eq 'published');
1010: my $con=($env{'request.state'} eq 'construct');
1011: my $rol=$env{'request.role'};
1012: my $requested_domain = $env{'request.role.domain'};
1.184 raeburn 1013: foreach my $line (@desklines) {
1.209 www 1014: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3 www 1015: $prt=~s/\$uname/$uname/g;
1016: $prt=~s/\$udom/$udom/g;
1.295 raeburn 1017: if ($prt =~ /\$crs/) {
1018: next unless ($env{'request.course.id'});
1019: next if ($crstype eq 'Community');
1020: $prt=~s/\$crs/$crs/g;
1021: } elsif ($prt =~ /\$cmty/) {
1022: next unless ($env{'request.course.id'});
1023: next if ($crstype ne 'Community');
1024: $prt=~s/\$cmty/$crs/g;
1025: }
1.25 matthew 1026: $prt=~s/\$requested_domain/$requested_domain/g;
1.211 www 1027: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3 www 1028: if ($pro eq 'clear') {
1.4 www 1029: $output.=&clear($row,$col);
1.3 www 1030: } elsif ($pro eq 'any') {
1.2 www 1031: $output.=&secondlevel(
1.209 www 1032: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1033: } elsif ($pro eq 'smp') {
1034: unless ($adv) {
1035: $output.=&secondlevel(
1.209 www 1036: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1037: }
1038: } elsif ($pro eq 'adv') {
1039: if ($adv) {
1040: $output.=&secondlevel(
1.209 www 1041: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1042: }
1.231 albertel 1043: } elsif ($pro eq 'shc') {
1044: if ($show_course) {
1045: $output.=&secondlevel(
1046: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1047: }
1048: } elsif ($pro eq 'nsc') {
1049: if (!$show_course) {
1050: $output.=&secondlevel(
1051: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1052: }
1.81 matthew 1053: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295 raeburn 1054: my $priv = $1;
1055: if ($priv =~ /^mdc(Course|Community)/) {
1056: if ($crstype eq $1) {
1057: $priv = 'mdc';
1058: } else {
1059: next;
1060: }
1061: }
1062: if (&Apache::lonnet::allowed($priv,$prt)) {
1.209 www 1063: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4 www 1064: }
1.295 raeburn 1065: } elsif ($pro eq 'course') {
1066: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209 www 1067: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81 matthew 1068: }
1.295 raeburn 1069: } elsif ($pro eq 'community') {
1070: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1071: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1072: }
1.124 matthew 1073: } elsif ($pro =~ /^courseenv_(.*)$/) {
1074: my $key = $1;
1.307 raeburn 1075: if ($crstype ne 'Community') {
1076: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1077: if ($key eq 'canuse_pdfforms') {
1078: if ($env{'request.course.id'} && $coursepref eq '') {
1079: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1080: $coursepref = $domdefs{'canuse_pdfforms'};
1081: }
1082: }
1083: if ($coursepref) {
1084: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1085: }
1.295 raeburn 1086: }
1087: } elsif ($pro =~ /^communityenv_(.*)$/) {
1088: my $key = $1;
1.307 raeburn 1089: if ($crstype eq 'Community') {
1090: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1091: if ($key eq 'canuse_pdfforms') {
1092: if ($env{'request.course.id'} && $coursepref eq '') {
1093: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1094: $coursepref = $domdefs{'canuse_pdfforms'};
1095: }
1096: }
1097: if ($coursepref) {
1098: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1099: }
1.124 matthew 1100: }
1.81 matthew 1101: } elsif ($pro =~ /^course_(.*)$/) {
1102: # Check for permissions inside of a course
1.295 raeburn 1103: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1.152 albertel 1104: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1105: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81 matthew 1106: )) {
1.209 www 1107: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26 www 1108: }
1.295 raeburn 1109: } elsif ($pro =~ /^community_(.*)$/) {
1110: # Check for permissions inside of a community
1111: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1112: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1113: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1114: )) {
1115: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1116: }
1.4 www 1117: } elsif ($pro eq 'author') {
1118: if ($author) {
1.152 albertel 1119: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234 raeburn 1120: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1.152 albertel 1121: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19 matthew 1122: # Check that we are on the correct machine
1.29 matthew 1123: my $cadom=$requested_domain;
1.152 albertel 1124: my $caname=$env{'user.name'};
1.234 raeburn 1125: if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29 matthew 1126: ($cadom,$caname)=
1.206 albertel 1127: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29 matthew 1128: }
1129: $act =~ s/\$caname/$caname/g;
1.353 www 1130: $act =~ s/\$cadom/$cadom/g;
1.19 matthew 1131: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 1132: my $allowed=0;
1133: my @ids=&Apache::lonnet::current_machine_ids();
1134: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1135: if ($allowed) {
1.209 www 1136: $output.=&switch($caname,$cadom,
1137: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19 matthew 1138: }
1.6 www 1139: }
1.2 www 1140: }
1.248 raeburn 1141: } elsif ($pro eq 'tools') {
1142: my @tools = ('aboutme','blog','portfolio');
1143: if (grep(/^\Q$prt\E$/,@tools)) {
1.249 raeburn 1144: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251 raeburn 1145: $env{'user.domain'},
1146: $prt,undef,'tools')) {
1147: $output.=&clear($row,$col);
1148: next;
1149: }
1.278 raeburn 1150: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1151: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1152: next;
1153: }
1154: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1155: next;
1156: }
1.279 raeburn 1157: my $showreqcrs = &check_for_rcrs();
1.251 raeburn 1158: if (!$showreqcrs) {
1.248 raeburn 1159: $output.=&clear($row,$col);
1160: next;
1161: }
1162: }
1163: $prt='any';
1164: $output.=&secondlevel(
1165: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1166: }
1.13 harris41 1167: }
1.2 www 1168: return $output;
1169: }
1170:
1.279 raeburn 1171: sub check_for_rcrs {
1172: my $showreqcrs = 0;
1.280 raeburn 1173: my @reqtypes = ('official','unofficial','community');
1174: foreach my $type (@reqtypes) {
1.279 raeburn 1175: if (&Apache::lonnet::usertools_access($env{'user.name'},
1176: $env{'user.domain'},
1177: $type,undef,'requestcourses')) {
1178: $showreqcrs = 1;
1179: last;
1180: }
1181: }
1.280 raeburn 1182: if (!$showreqcrs) {
1183: foreach my $type (@reqtypes) {
1184: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1185: $showreqcrs = 1;
1186: last;
1187: }
1188: }
1189: }
1.279 raeburn 1190: return $showreqcrs;
1191: }
1192:
1.306 raeburn 1193: sub dc_popup_js {
1194: my %lt = &Apache::lonlocal::texthash(
1195: more => '(More ...)',
1196: less => '(Less ...)',
1197: );
1198: return <<"END";
1199:
1200: function showCourseID() {
1201: document.getElementById('dccid').style.display='block';
1202: document.getElementById('dccid').style.textAlign='left';
1.307 raeburn 1203: document.getElementById('dccid').style.textFace='normal';
1.369 raeburn 1204: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306 raeburn 1205: return;
1206: }
1207:
1208: function hideCourseID() {
1209: document.getElementById('dccid').style.display='none';
1.369 raeburn 1210: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306 raeburn 1211: return;
1212: }
1213:
1214: END
1215:
1216: }
1217:
1.378 raeburn 1218: sub countdown_toggle_js {
1219: return <<"END";
1220:
1221: function toggleCountdown() {
1222: var countdownid = document.getElementById('duedatecountdown');
1223: var currstyle = countdownid.style.display;
1224: if (currstyle == 'inline') {
1225: countdownid.style.display = 'none';
1226: document.getElementById('ddcountcollapse').innerHTML='';
1227: document.getElementById('ddcountexpand').innerHTML='◄ ';
1228: } else {
1229: countdownid.style.display = 'inline';
1230: document.getElementById('ddcountcollapse').innerHTML='► ';
1231: document.getElementById('ddcountexpand').innerHTML='';
1232: }
1233: return;
1234: }
1235:
1236: END
1237: }
1238:
1.42 www 1239: sub utilityfunctions {
1.152 albertel 1240: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.316 droeschl 1241: if ($currenturl =~ m{^/adm/wrapper/ext/}
1242: && $env{'request.external.querystring'} ) {
1.293 raeburn 1243: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1244: }
1.183 www 1245: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125 albertel 1246:
1.152 albertel 1247: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.175 albertel 1248:
1.306 raeburn 1249: my $dc_popup_cid;
1250: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1251: $env{'course.'.$env{'request.course.id'}.
1252: '.domain'}.'/'})) {
1253: $dc_popup_cid = &dc_popup_js();
1254: }
1255:
1.175 albertel 1256: my $start_page_annotate =
1257: &Apache::loncommon::start_page('Annotator',undef,
1258: {'only_body' => 1,
1259: 'js_ready' => 1,
1260: 'bgcolor' => '#BBBBBB',
1261: 'add_entries' => {
1262: 'onload' => 'javascript:document.goannotate.submit();'}});
1263:
1.205 albertel 1264: my $end_page_annotate =
1265: &Apache::loncommon::end_page({'js_ready' => 1});
1266:
1.336 raeburn 1267: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
1268: &mt('Switch server?');
1269:
1.368 www 1270: my $esc_url=&escape($currenturl);
1271: my $esc_symb=&escape($currentsymb);
1.332 wenzelju 1272:
1.378 raeburn 1273: my $countdown = &countdown_toggle_js();
1274:
1.42 www 1275: return (<<ENDUTILITY)
1276:
1.368 www 1277: var currentURL=unescape("$esc_url");
1278: var reloadURL=unescape("$esc_url");
1279: var currentSymb=unescape("$esc_symb");
1.42 www 1280:
1.306 raeburn 1281: $dc_popup_cid
1.114 albertel 1282:
1.42 www 1283: function go(url) {
1284: if (url!='' && url!= null) {
1285: currentURL = null;
1286: currentSymb= null;
1287: window.location.href=url;
1288: }
1289: }
1290:
1.336 raeburn 1291: function need_switchserver(url) {
1292: if (url!='' && url!= null) {
1293: if (confirm("$confirm_switch")) {
1294: go(url);
1295: }
1296: }
1297: return;
1298: }
1299:
1.42 www 1300: function gopost(url,postdata) {
1301: if (url!='') {
1302: this.document.server.action=url;
1303: this.document.server.postdata.value=postdata;
1304: this.document.server.command.value='';
1305: this.document.server.url.value='';
1306: this.document.server.symb.value='';
1307: this.document.server.submit();
1308: }
1309: }
1310:
1311: function gocmd(url,cmd) {
1312: if (url!='') {
1313: this.document.server.action=url;
1314: this.document.server.postdata.value='';
1315: this.document.server.command.value=cmd;
1316: this.document.server.url.value=currentURL;
1317: this.document.server.symb.value=currentSymb;
1318: this.document.server.submit();
1319: }
1.57 www 1320: }
1321:
1.121 raeburn 1322: function gocstr(url,filename) {
1323: if (url == '/adm/cfile?action=delete') {
1324: this.document.cstrdelete.filename.value = filename
1325: this.document.cstrdelete.submit();
1326: return;
1327: }
1.137 raeburn 1328: if (url == '/adm/printout') {
1329: this.document.cstrprint.postdata.value = filename
1330: this.document.cstrprint.curseed.value = 0;
1331: this.document.cstrprint.problemtype.value = 0;
1.138 raeburn 1332: if (this.document.lonhomework) {
1333: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1334: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1335: }
1336: if (this.document.lonhomework.problemtype) {
1.164 albertel 1337: if (this.document.lonhomework.problemtype.value) {
1338: this.document.cstrprint.problemtype.value =
1339: this.document.lonhomework.problemtype.value;
1340: } else if (this.document.lonhomework.problemtype.options) {
1341: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1342: if (this.document.lonhomework.problemtype.options[i].selected) {
1343: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1344: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1345: }
1346: }
1347: }
1348: }
1349: }
1350: }
1.137 raeburn 1351: this.document.cstrprint.submit();
1352: return;
1353: }
1.121 raeburn 1354: if (url !='') {
1355: this.document.constspace.filename.value = filename;
1356: this.document.constspace.action = url;
1357: this.document.constspace.submit();
1358: }
1359: }
1360:
1.131 raeburn 1361: function golist(url) {
1362: if (url!='' && url!= null) {
1363: currentURL = null;
1364: currentSymb= null;
1365: top.location.href=url;
1366: }
1367: }
1368:
1369:
1.121 raeburn 1370:
1.57 www 1371: function catalog_info() {
1.365 www 1372: openMyModal(window.location.pathname+'.meta',500,400,'yes');
1.57 www 1373: }
1374:
1375: function chat_win() {
1.290 raeburn 1376: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42 www 1377: }
1.169 raeburn 1378:
1379: function group_chat(group) {
1380: var url = '/adm/groupchat?group='+group;
1381: var winName = 'LONchat_'+group;
1382: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1383: }
1.175 albertel 1384:
1385: function annotate() {
1386: w_Annotator_flag=1;
1387: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1388: annotator.document.write(
1389: '$start_page_annotate'
1390: +"<form name='goannotate' target='Annotator' method='post' "
1391: +"action='/adm/annotations'>"
1.217 albertel 1392: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181 albertel 1393: +"<\\/form>"
1.205 albertel 1394: +'$end_page_annotate');
1.175 albertel 1395: annotator.document.close();
1396: }
1397:
1.370 raeburn 1398: function open_StoredLinks_Import(rat) {
1.335 wenzelju 1399: var newWin;
1400: if (rat) {
1401: newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.334 wenzelju 1402: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1.335 wenzelju 1403: }
1404: else {
1405: newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import',
1406: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1407: }
1.334 wenzelju 1408: newWin.focus();
1409: }
1410:
1.372 raeburn 1411: (function (\$) {
1412: \$(document).ready(function () {
1413: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
1414: /*\@cc_on
1415: if (!window.XMLHttpRequest) {
1416: \$('.LC_hoverable').each(function () {
1417: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
1418: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
1419: });
1420: }
1421: \@*/
1422: });
1423: }(jQuery));
1424:
1.378 raeburn 1425: $countdown
1426:
1.42 www 1427: ENDUTILITY
1428: }
1429:
1430: sub serverform {
1431: return(<<ENDSERVERFORM);
1.181 albertel 1432: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 1433: <input type="hidden" name="postdata" value="none" />
1434: <input type="hidden" name="command" value="none" />
1435: <input type="hidden" name="url" value="none" />
1436: <input type="hidden" name="symb" value="none" />
1437: </form>
1438: ENDSERVERFORM
1439: }
1.113 albertel 1440:
1.121 raeburn 1441: sub constspaceform {
1442: return(<<ENDCONSTSPACEFORM);
1.181 albertel 1443: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121 raeburn 1444: <input type="hidden" name="filename" value="" />
1445: </form>
1.181 albertel 1446: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121 raeburn 1447: <input type="hidden" name="action" value="delete" />
1448: <input type="hidden" name="filename" value="" />
1449: </form>
1.181 albertel 1450: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137 raeburn 1451: <input type="hidden" name="postdata" value="" />
1452: <input type="hidden" name="curseed" value="" />
1453: <input type="hidden" name="problemtype" value="" />
1454: </form>
1455:
1.121 raeburn 1456: ENDCONSTSPACEFORM
1457: }
1458:
1.220 raeburn 1459: sub hidden_button_check {
1.317 droeschl 1460: if ( $env{'request.course.id'} eq ''
1461: || $env{'request.role.adv'} ) {
1462:
1.220 raeburn 1463: return;
1464: }
1.232 raeburn 1465: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1466: return $buttonshide;
1.220 raeburn 1467: }
1.184 raeburn 1468:
1.235 raeburn 1469: sub roles_selector {
1470: my ($cdom,$cnum) = @_;
1.298 raeburn 1471: my $crstype = &Apache::loncommon::course_type();
1.235 raeburn 1472: my $now = time;
1.350 raeburn 1473: my (%courseroles,%seccount,%courseprivs);
1.235 raeburn 1474: my $is_cc;
1475: my $role_selector;
1.298 raeburn 1476: my $ccrole;
1477: if ($crstype eq 'Community') {
1478: $ccrole = 'co';
1479: } else {
1480: $ccrole = 'cc';
1.350 raeburn 1481: }
1.386 raeburn 1482: my ($priv,$gotsymb,$destsymb);
1.350 raeburn 1483: my $destinationurl = $ENV{'REQUEST_URI'};
1.386 raeburn 1484: if ($destinationurl =~ /\?symb=/) {
1485: $gotsymb = 1;
1486: } elsif ($destinationurl =~ m{^/enc/}) {
1487: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
1488: if ($plainurl =~ /\?symb=/) {
1489: $gotsymb = 1;
1490: }
1491: }
1492: unless ($gotsymb) {
1493: $destsymb = &Apache::lonnet::symbread();
1494: if ($destsymb ne '') {
1495: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
1496: }
1497: }
1.350 raeburn 1498: my $reqprivs = &required_privs();
1499: if (ref($reqprivs) eq 'HASH') {
1500: my $destination = $destinationurl;
1501: $destination =~ s/(\?.*)$//;
1502: if (exists($reqprivs->{$destination})) {
1503: $priv = $reqprivs->{$destination};
1504: }
1505: }
1.298 raeburn 1506: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
1507: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235 raeburn 1508:
1509: if ((($start) && ($start<0)) ||
1510: (($end) && ($end<$now)) ||
1511: (($start) && ($now<$start))) {
1512: $is_cc = 0;
1513: } else {
1514: $is_cc = 1;
1515: }
1516: }
1517: if ($is_cc) {
1.350 raeburn 1518: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1.235 raeburn 1519: } else {
1.262 raeburn 1520: my %gotnosection;
1.235 raeburn 1521: foreach my $item (keys(%env)) {
1.239 raeburn 1522: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235 raeburn 1523: my $role = $1;
1524: my $sec = $2;
1525: next if ($role eq 'gr');
1526: my ($start,$end) = split(/\./,$env{$item});
1527: next if (($start && $start > $now) || ($end && $end < $now));
1528: if ($sec eq '') {
1.239 raeburn 1529: if (!$gotnosection{$role}) {
1530: $seccount{$role} ++;
1531: $gotnosection{$role} = 1;
1532: }
1.235 raeburn 1533: }
1.350 raeburn 1534: if ($priv ne '') {
1535: my $cnumsec = $cnum;
1536: if ($sec ne '') {
1537: $cnumsec .= "/$sec";
1538: }
1539: $courseprivs{"$role./$cdom/$cnumsec./"} =
1540: $env{"user.priv.$role./$cdom/$cnumsec./"};
1541: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
1542: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
1543: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
1544: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
1545: }
1.235 raeburn 1546: if (ref($courseroles{$role}) eq 'ARRAY') {
1.239 raeburn 1547: if ($sec ne '') {
1.264 raeburn 1548: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239 raeburn 1549: push(@{$courseroles{$role}},$sec);
1550: $seccount{$role} ++;
1551: }
1552: }
1553: } else {
1554: @{$courseroles{$role}} = ();
1555: if ($sec ne '') {
1556: $seccount{$role} ++;
1.235 raeburn 1557: push(@{$courseroles{$role}},$sec);
1558: }
1559: }
1560: }
1561: }
1562: }
1.286 raeburn 1563: my $switchtext;
1564: if ($crstype eq 'Community') {
1565: $switchtext = &mt('Switch community role to...')
1566: } else {
1567: $switchtext = &mt('Switch course role to...')
1568: }
1.298 raeburn 1569: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.235 raeburn 1570: if (keys(%courseroles) > 1) {
1.350 raeburn 1571: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
1.235 raeburn 1572: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
1573: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1.286 raeburn 1574: $role_selector .= '<option value="">'.$switchtext.'</option>';
1.235 raeburn 1575: foreach my $role (@roles_order) {
1576: if (defined($courseroles{$role})) {
1.298 raeburn 1577: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>';
1.235 raeburn 1578: }
1579: }
1580: foreach my $role (sort(keys(%courseroles))) {
1581: if ($role =~ /^cr/) {
1582: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1583: }
1584: }
1.386 raeburn 1585: $role_selector .= '</select>'."\n";
1586: if ($destsymb ne '') {
1587: $role_selector .= '<input type="hidden" name="destsymb" value="'.
1588: &HTML::Entities::encode($destsymb).'" />'."\n";
1589: }
1590: $role_selector .=
1.235 raeburn 1591: '<input type="hidden" name="destinationurl" value="'.
1.350 raeburn 1592: &HTML::Entities::encode($destinationurl).'" />'."\n".
1.235 raeburn 1593: '<input type="hidden" name="gotorole" value="1" />'."\n".
1594: '<input type="hidden" name="selectrole" value="" />'."\n".
1595: '<input type="hidden" name="switch" value="1" />'."\n".
1596: '</form>';
1597: }
1598: return $role_selector;
1599: }
1600:
1.262 raeburn 1601: sub get_all_courseroles {
1.350 raeburn 1602: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351 raeburn 1603: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350 raeburn 1604: (ref($courseprivs) eq 'HASH')) {
1.262 raeburn 1605: return;
1606: }
1607: my ($result,$cached) =
1608: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1609: if (defined($cached)) {
1610: if (ref($result) eq 'HASH') {
1611: if ((ref($result->{'roles'}) eq 'HASH') &&
1.350 raeburn 1612: (ref($result->{'seccount'}) eq 'HASH') &&
1613: (ref($result->{'privs'}) eq 'HASH')) {
1.262 raeburn 1614: %{$courseroles} = %{$result->{'roles'}};
1615: %{$seccount} = %{$result->{'seccount'}};
1.350 raeburn 1616: %{$courseprivs} = %{$result->{'privs'}};
1.262 raeburn 1617: return;
1618: }
1619: }
1620: }
1621: my %gotnosection;
1622: my %adv_roles =
1623: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1624: foreach my $role (keys(%adv_roles)) {
1625: my ($urole,$usec) = split(/:/,$role);
1626: if (!$gotnosection{$urole}) {
1627: $seccount->{$urole} ++;
1628: $gotnosection{$urole} = 1;
1629: }
1630: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1631: if ($usec ne '') {
1632: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1633: push(@{$courseroles->{$urole}},$usec);
1634: $seccount->{$urole} ++;
1635: }
1636: }
1637: } else {
1638: @{$courseroles->{$urole}} = ();
1639: if ($usec ne '') {
1640: $seccount->{$urole} ++;
1641: push(@{$courseroles->{$urole}},$usec);
1642: }
1643: }
1.350 raeburn 1644: my $area = '/'.$cdom.'/'.$cnum;
1645: if ($usec ne '') {
1646: $area .= '/'.$usec;
1647: }
1648: if ($role =~ /^cr\//) {
1649: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
1650: } else {
1651: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
1652: }
1.262 raeburn 1653: }
1654: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1655: @{$courseroles->{'st'}} = ();
1.350 raeburn 1656: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262 raeburn 1657: if (keys(%sections_count) > 0) {
1658: push(@{$courseroles->{'st'}},keys(%sections_count));
1.350 raeburn 1659: $seccount->{'st'} = scalar(keys(%sections_count));
1.262 raeburn 1660: }
1661: my $rolehash = {
1662: 'roles' => $courseroles,
1663: 'seccount' => $seccount,
1.350 raeburn 1664: 'privs' => $courseprivs,
1.262 raeburn 1665: };
1666: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1667: return;
1668: }
1669:
1.235 raeburn 1670: sub jump_to_role {
1.350 raeburn 1671: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
1.239 raeburn 1672: my %lt = &Apache::lonlocal::texthash(
1673: this => 'This role has section(s) associated with it.',
1674: ente => 'Enter a specific section.',
1675: orlb => 'Enter a specific section, or leave blank for no section.',
1676: avai => 'Available sections are:',
1677: youe => 'You entered an invalid section choice:',
1.352 raeburn 1678: plst => 'Please try again.',
1.350 raeburn 1679: role => 'The role you selected is not permitted to view the current page.',
1680: swit => 'Switch role, but display Main Menu page instead?',
1.239 raeburn 1681: );
1682: my $js;
1683: if (ref($courseroles) eq 'HASH') {
1684: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1685: ' var numsec = new Array();'."\n".
1686: ' var rolesections = new Array();'."\n".
1687: ' var rolenames = new Array();'."\n".
1688: ' var roleseclist = new Array();'."\n";
1689: my @items = keys(%{$courseroles});
1690: for (my $i=0; $i<@items; $i++) {
1691: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1692: my ($secs,$secstr);
1693: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1694: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1695: $secs = join('","',@sections);
1696: $secstr = join(', ',@sections);
1697: }
1698: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1699: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1700: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1701: }
1702: }
1.350 raeburn 1703: my $checkroles = 0;
1704: if ($priv && ref($courseprivs) eq 'HASH') {
1705: my (%disallowed,%allowed,@disallow);
1706: foreach my $role (sort(keys(%{$courseprivs}))) {
1707: my $trole;
1708: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
1709: $trole = $1;
1710: }
1711: if (($trole ne '') && ($trole ne 'cm')) {
1712: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
1713: $allowed{$trole} = 1;
1714: } else {
1715: $disallowed{$trole} = 1;
1716: }
1717: }
1718: }
1719: foreach my $trole (keys(%disallowed)) {
1720: unless ($allowed{$trole}) {
1721: push(@disallow,$trole);
1722: }
1723: }
1724: if (@disallow > 0) {
1725: $checkroles = 1;
1726: $js .= " var disallow = new Array('".join("','",@disallow)."');\n".
1727: " var rolecheck = 1;\n";
1728: }
1729: }
1730: if (!$checkroles) {
1731: $js .= " var disallow = new Array();\n".
1732: " rolecheck = 0;\n";
1733: }
1.273 droeschl 1734: return <<"END";
1.235 raeburn 1735: <script type="text/javascript">
1.273 droeschl 1736: //<![CDATA[
1.235 raeburn 1737: function adhocRole(roleitem) {
1.239 raeburn 1738: $js
1.235 raeburn 1739: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
1740: if (newrole == '') {
1.350 raeburn 1741: return;
1.235 raeburn 1742: }
1.239 raeburn 1743: var fullrole = newrole+'./$cdom/$cnum';
1744: var selidx = '';
1745: for (var i=0; i<rolenames.length; i++) {
1746: if (rolenames[i] == newrole) {
1747: selidx = i;
1748: }
1749: }
1.350 raeburn 1750: if (rolecheck > 0) {
1751: for (var i=0; i<disallow.length; i++) {
1752: if (disallow[i] == newrole) {
1753: if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
1754: document.rolechooser.destinationurl.value = '/adm/menu';
1755: } else {
1756: document.rolechooser.elements[roleitem].selectedIndex = 0;
1757: return;
1758: }
1759: }
1760: }
1761: }
1.239 raeburn 1762: var secok = 1;
1763: var secchoice = '';
1764: if (selidx >= 0) {
1765: if (numsec[selidx] > 1) {
1766: secok = 0;
1767: var numrolesec = rolesections[selidx].length;
1768: var msgidx = numsec[selidx] - numrolesec;
1.339 raeburn 1769: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239 raeburn 1770: if (secchoice == '') {
1771: if (msgidx > 0) {
1772: secok = 1;
1773: }
1774: } else {
1775: for (var j=0; j<rolesections[selidx].length; j++) {
1776: if (rolesections[selidx][j] == secchoice) {
1777: secok = 1;
1778: }
1779: }
1780: }
1781: } else {
1782: if (rolesections[selidx].length == 1) {
1783: secchoice = rolesections[selidx][0];
1784: }
1785: }
1786: }
1787: if (secok == 1) {
1788: if (secchoice != '') {
1789: fullrole += '/'+secchoice;
1790: }
1791: } else {
1792: document.rolechooser.elements[roleitem].selectedIndex = 0;
1793: if (secchoice != null) {
1794: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
1795: }
1796: return;
1797: }
1798: if (fullrole == "$env{'request.role'}") {
1.350 raeburn 1799: document.rolechooser.elements[roleitem].selectedIndex = 0;
1.235 raeburn 1800: return;
1801: }
1802: itemid = retrieveIndex('gotorole');
1803: if (itemid != -1) {
1.239 raeburn 1804: document.rolechooser.elements[itemid].name = fullrole;
1.235 raeburn 1805: }
1.239 raeburn 1806: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1.235 raeburn 1807: document.rolechooser.selectrole.value = '1';
1808: document.rolechooser.submit();
1809: return;
1810: }
1811:
1812: function retrieveIndex(item) {
1813: for (var i=0;i<document.rolechooser.elements.length;i++) {
1814: if (document.rolechooser.elements[i].name == item) {
1815: return i;
1816: }
1817: }
1818: return -1;
1819: }
1.273 droeschl 1820: // ]]>
1.235 raeburn 1821: </script>
1822: END
1823: }
1824:
1.350 raeburn 1825: sub required_privs {
1826: my $privs = {
1827: '/adm/parmset' => 'opa',
1828: '/adm/courseprefs' => 'opa',
1829: '/adm/whatsnew' => 'whn',
1830: '/adm/populate' => 'cst',
1831: '/adm/trackstudent' => 'vsa',
1832: '/adm/statistics' => 'vgr',
1.366 raeburn 1833: '/adm/setblock' => 'dcm',
1.367 raeburn 1834: '/adm/coursedocs' => 'mdc',
1.350 raeburn 1835: };
1836: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364 raeburn 1837: $privs->{'/adm/classcalc'} = 'vgr',
1838: $privs->{'/adm/assesscalc'} = 'vgr',
1839: $privs->{'/adm/studentcalc'} = 'vgr';
1.350 raeburn 1840: }
1841: return $privs;
1842: }
1.235 raeburn 1843:
1.378 raeburn 1844: sub countdown_timer {
1845: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.387 ! raeburn 1846: ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
! 1847: my ($type,$hastimeleft,$slothastime);
! 1848: my $now = time;
! 1849: if ($env{'request.filename'} =~ /\.task$/) {
! 1850: $type = 'Task';
! 1851: } else {
! 1852: $type = 'problem';
! 1853: }
! 1854: my ($status,$accessmsg,$slot_name,$slot) =
! 1855: &Apache::lonhomework::check_slot_access('0',$type);
! 1856: if ($slot_name ne '') {
! 1857: if (ref($slot) eq 'HASH') {
! 1858: if (($slot->{'starttime'} < $now) &&
! 1859: ($slot->{'endtime'} > $now)) {
! 1860: $slothastime = 1;
! 1861: }
! 1862: }
! 1863: }
! 1864: if ($status ne 'CAN_ANSWER') {
! 1865: return;
! 1866: }
1.378 raeburn 1867: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.380 raeburn 1868: my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.381 raeburn 1869: my $hastimeleft;
1870: if (@interval > 1) {
1871: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
1872: if ($first_access > 0) {
1873: if ($first_access+$interval[0] > time) {
1874: $hastimeleft = 1;
1875: }
1876: }
1877: }
1.380 raeburn 1878: if (($duedate && $duedate > time) ||
1.387 ! raeburn 1879: (!$duedate && $hastimeleft) ||
! 1880: ($slot_name ne '' && $slothastime)) {
1.379 raeburn 1881: my ($collapse,$expand,$alttxt,$title,$currdisp);
1.387 ! raeburn 1882: if ((@interval > 1 && $hastimeleft) ||
! 1883: ($type eq 'Task' && $slothastime)) {
1.378 raeburn 1884: $currdisp = 'inline';
1885: $collapse = '► ';
1886: } else {
1887: $currdisp = 'none';
1888: $expand = '◄ ';
1889: }
1890: unless ($env{'environment.icons'} eq 'iconsonly') {
1.379 raeburn 1891: $alttxt = &mt('Timer');
1892: $title = $alttxt.' ';
1.378 raeburn 1893: }
1894: my $desc = &mt('Countdown to due date/time');
1895: return <<END;
1896:
1897: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
1898: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
1899: $collapse
1.379 raeburn 1900: </span></a>
1.378 raeburn 1901: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
1902: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
1903: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.379 raeburn 1904: <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 1905: END
1906: }
1907: }
1908: return;
1909: }
1910:
1.2 www 1911: # ================================================================ Main Program
1912:
1.16 harris41 1913: BEGIN {
1.166 albertel 1914: if (! defined($readdesk)) {
1.283 droeschl 1915: {
1916: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
1917: if ( CORE::open( my $config,"<$tabfile") ) {
1918: while (my $configline=<$config>) {
1919: $configline=(split(/\#/,$configline))[0];
1920: $configline=~s/^\s+//;
1921: chomp($configline);
1.209 www 1922: if ($configline=~/^cat\:/) {
1.283 droeschl 1923: my @entries=split(/\:/,$configline);
1924: $category_positions{$entries[2]}=$entries[1];
1925: $category_names{$entries[2]}=$entries[3];
1926: } elsif ($configline=~/^prim\:/) {
1927: my @entries = (split(/\:/, $configline))[1..5];
1928: push @primary_menu, \@entries;
1.371 raeburn 1929: } elsif ($configline=~/^primsub\:/) {
1930: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1931: push (@{$primary_submenu{$parent}},\@entries);
1.283 droeschl 1932: } elsif ($configline=~/^scnd\:/) {
1933: my @entries = (split(/\:/, $configline))[1..5];
1934: push @secondary_menu, \@entries;
1935: } elsif ($configline) {
1936: push(@desklines,$configline);
1937: }
1938: }
1939: CORE::close($config);
1940: }
1941: }
1942: $readdesk='done';
1.2 www 1943: }
1944: }
1.30 www 1945:
1.1 www 1946: 1;
1947: __END__
1948:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>