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