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