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