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