Annotation of loncom/interface/lonmenu.pm, revision 1.405
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.405 ! raeburn 4: # $Id: lonmenu.pm,v 1.404 2012/12/28 17:08:44 raeburn Exp $
1.11 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 www 28: #
29:
1.244 jms 30: =head1 NAME
31:
32: Apache::lonmenu
33:
34: =head1 SYNOPSIS
35:
1.371 raeburn 36: Loads contents of /home/httpd/lonTabs/mydesk.tab,
37: used to generate inline menu, and Main Menu page.
1.244 jms 38:
39: This is part of the LearningOnline Network with CAPA project
40: described at http://www.lon-capa.org.
41:
1.314 droeschl 42: =head1 GLOBAL VARIABLES
43:
44: =over
45:
46: =item @desklines
47:
48: Each element of this array contains a line of mydesk.tab that doesn't start with
49: cat, prim or scnd.
50: It gets filled in the BEGIN block of this module.
51:
52: =item %category_names
53:
54: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
55: start with cat, the values are strings representing titles.
56: It gets filled in the BEGIN block of this module.
57:
58: =item %category_members
59:
60: TODO
61:
62: =item %category_positions
63:
64: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
65: start with cat, its values are position vectors (column, row).
66: It gets filled in the BEGIN block of this module.
67:
68: =item $readdesk
69:
70: Indicates that mydesk.tab has been read.
71: It is set to 'done' in the BEGIN block of this module.
72:
73: =item @primary_menu
74:
75: The elements of this array reference arrays that are made up of the components
1.371 raeburn 76: of those lines of mydesk.tab that start with prim:.
1.314 droeschl 77: It is used by primary_menu() to generate the corresponding menu.
78: It gets filled in the BEGIN block of this module.
79:
1.371 raeburn 80: =item %primary_sub_menu
81:
82: The keys of this hash reference are the names of items in the primary_menu array
83: which have sub-menus. For each key, the corresponding value is a reference to
84: an array containing components extracted from lines in mydesk.tab which begin
85: with primsub:.
86: This hash, which is used by primary_menu to generate sub-menus, is populated in
87: the BEGIN block.
88:
1.314 droeschl 89: =item @secondary_menu
90:
91: The elements of this array reference arrays that are made up of the components
92: of those lines of mydesk.tab that start with scnd.
93: It is used by secondary_menu() to generate the corresponding menu.
94: It gets filled in the BEGIN block of this module.
95:
96: =back
97:
1.244 jms 98: =head1 SUBROUTINES
99:
100: =over
101:
1.314 droeschl 102: =item prep_menuitems(\@menuitem)
103:
104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
105: secondary_menu().
106:
107: =item primary_menu()
108:
109: This routine evaluates @primary_menu and returns XHTML for the menu
110: that contains following links: About, Message, Roles, Help, Logout
111: @primary_menu is filled within the BEGIN block of this module with
112: entries from mydesk.tab
113:
114: =item secondary_menu()
115:
116: Same as primary_menu() but operates on @secondary_menu.
117:
1.375 raeburn 118: =item create_submenu()
119:
120: Creates XHTML for unordered list of sub-menu items which belong to a
121: particular top-level menu item. Uses hover pseudo class in css to display
122: dropdown list when mouse hovers over top-level item. Support for IE6
123: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
124: level item, which employs jQuery to handle behavior on mouseover.
125:
126: Inputs: 4 - (a) link and (b) target for anchor href in top level item,
127: (c) title for text wrapped by anchor tag in top level item.
128: (d) reference to array of arrays of sub-menu items.
129:
1.244 jms 130: =item innerregister()
131:
1.320 droeschl 132: This gets called in order to register a URL in the body of the document
1.244 jms 133:
134: =item clear()
135:
136: =item switch()
137:
138: Switch a button or create a link
139: Switch acts on the javascript that is executed when a button is clicked.
140: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
141:
142: =item secondlevel()
143:
144: =item openmenu()
145:
146: =item inlinemenu()
147:
148: =item rawconfig()
149:
150: =item utilityfunctions()
151:
1.371 raeburn 152: Output from this routine is a number of javascript functions called by
153: items in the inline menu, and in some cases items in the Main Menu page.
154:
1.244 jms 155: =item serverform()
156:
157: =item constspaceform()
158:
159: =item get_nav_status()
160:
161: =item hidden_button_check()
162:
163: =item roles_selector()
164:
165: =item jump_to_role()
166:
167: =back
168:
169: =cut
170:
1.1 www 171: package Apache::lonmenu;
172:
173: use strict;
1.152 albertel 174: use Apache::lonnet;
1.47 matthew 175: use Apache::lonhtmlcommon();
1.115 albertel 176: use Apache::loncommon();
1.127 albertel 177: use Apache::lonenc();
1.88 www 178: use Apache::lonlocal;
1.361 raeburn 179: use Apache::lonmsg();
1.207 foxr 180: use LONCAPA qw(:DEFAULT :match);
1.282 amueller 181: use HTML::Entities();
1.346 wenzelju 182: use Apache::lonwishlist();
1.88 www 183:
1.283 droeschl 184: use vars qw(@desklines %category_names %category_members %category_positions
1.371 raeburn 185: $readdesk @primary_menu %primary_submenu @secondary_menu);
1.88 www 186:
1.56 www 187: my @inlineremote;
1.38 www 188:
1.283 droeschl 189: sub prep_menuitem {
1.291 raeburn 190: my ($menuitem) = @_;
191: return '' unless(ref($menuitem) eq 'ARRAY');
1.283 droeschl 192: my $link;
193: if ($$menuitem[1]) { # graphical Link
194: $link = "<img class=\"LC_noBorder\""
1.291 raeburn 195: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
196: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283 droeschl 197: } else { # textual Link
1.291 raeburn 198: $link = &mt($$menuitem[3]);
199: }
1.316 droeschl 200: return '<li><a'
201: # highlighting for new messages
202: . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
1.325 droeschl 203: . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
1.283 droeschl 204: }
205:
206: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
207: # that contains following links:
1.371 raeburn 208: # About, Message, Personal, Roles, Help, Logout
1.283 droeschl 209: # @primary_menu is filled within the BEGIN block of this module with
210: # entries from mydesk.tab
211: sub primary_menu {
212: my $menu;
213: # each element of @primary contains following array:
214: # (link url, icon path, alt text, link text, condition)
1.319 raeburn 215: my $public;
216: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
217: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
218: $public = 1;
219: }
1.283 droeschl 220: foreach my $menuitem (@primary_menu) {
221: # evaluate conditions
1.296 droeschl 222: next if ref($menuitem) ne 'ARRAY'; #
1.283 droeschl 223: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
1.291 raeburn 224: && &Apache::lonmsg::mynewmail(); # whether a new msg
1.283 droeschl 225: next if $$menuitem[4] eq 'newmsg' # arrived or not
1.291 raeburn 226: && !&Apache::lonmsg::mynewmail(); #
1.319 raeburn 227: next if $$menuitem[4] !~ /public/ ##we've a public user,
228: && $public; ##who should not see all
229: ##links
1.283 droeschl 230: next if $$menuitem[4] eq 'onlypublic'# hide links which are
1.319 raeburn 231: && !$public; # only visible to public
232: # users
1.283 droeschl 233: next if $$menuitem[4] eq 'roles' ##show links depending on
1.291 raeburn 234: && &Apache::loncommon::show_course(); ##term 'Courses' or
1.283 droeschl 235: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
1.291 raeburn 236: && !&Apache::loncommon::show_course(); ##
237:
1.371 raeburn 238: my $title = $menuitem->[3];
239: if (defined($primary_submenu{$title})) {
1.375 raeburn 240: my ($link,$target);
1.371 raeburn 241: if ($menuitem->[0] ne '') {
242: $link = $menuitem->[0];
243: $target = '_top';
244: } else {
245: $link = '#';
246: }
1.375 raeburn 247: my @primsub;
1.371 raeburn 248: if (ref($primary_submenu{$title}) eq 'ARRAY') {
1.375 raeburn 249: foreach my $item (@{$primary_submenu{$title}}) {
1.383 raeburn 250: next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
1.375 raeburn 251: next if (($item->[2] eq 'reqcrs') && (!&check_for_rcrs()));
252: next if ((($item->[2] eq 'portfolio') ||
253: ($item->[2] eq 'blog')) &&
254: (!&Apache::lonnet::usertools_access('','',$item->[2],
255: undef,'tools')));
256: push(@primsub,$item);
257: }
258: if (@primsub > 0) {
259: $menu .= &create_submenu($link,$target,$title,\@primsub);
260: } elsif ($link) {
1.377 raeburn 261: $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
1.371 raeburn 262: }
263: }
264: } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.340 raeburn 265: if ($public) {
266: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
267: my $defdom = &Apache::lonnet::default_login_domain();
268: my $to = &Apache::loncommon::build_recipient_list(undef,
269: 'helpdeskmail',
270: $defdom,$origmail);
271: if ($to ne '') {
272: $menu .= &prep_menuitem($menuitem);
273: }
274: } else {
275: $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
276: }
1.283 droeschl 277: } else {
1.325 droeschl 278: $menu .= prep_menuitem($menuitem);
1.283 droeschl 279: }
1.291 raeburn 280: }
1.325 droeschl 281: $menu =~ s/\[domain\]/$env{'user.domain'}/g;
282: $menu =~ s/\[user\]/$env{'user.name'}/g;
1.283 droeschl 283:
1.291 raeburn 284: return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
1.283 droeschl 285: }
286:
1.329 droeschl 287: #returns hashref {user=>'',dom=>''} containing:
288: # own name, domain if user is au
289: # name, domain of parent author if user is ca or aa
290: #empty return if user is not an author or not on homeserver
291: #
292: #TODO this should probably be moved somewhere more central
293: #since it can be used by different parts of the system
294: sub getauthor{
295: return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
296:
297: #co- or assistent author?
298: my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
299: ? ($1, $2) #domain, username of the parent author
300: : @env{ ('request.role.domain', 'user.name') }; #own domain, username
301:
302: # current server == home server?
303: my $home = &Apache::lonnet::homeserver($user,$dom);
304: foreach (&Apache::lonnet::current_machine_ids()){
305: return {user => $user, dom => $dom} if $_ eq $home;
306: }
307:
308: # if wrong server
309: return;
310: }
1.283 droeschl 311:
312: sub secondary_menu {
313: my $menu;
314:
1.286 raeburn 315: my $crstype = &Apache::loncommon::course_type();
1.327 droeschl 316: my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
317: ? "/$env{'request.course.sec'}"
318: : '');
319: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
1.376 raeburn 320: my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
1.327 droeschl 321: my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
322: my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
323: my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
1.341 www 324: my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
1.343 www 325: my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
326: my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
327: my $author = &getauthor();
1.327 droeschl 328:
1.404 raeburn 329: my ($canmodifycoauthor);
330: if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
331: my $extent = "$env{'user.domain'}/$env{'user.name'}";
332: if ((&Apache::lonnet::allowed('cca',$extent)) ||
333: (&Apache::lonnet::allowed('caa',$extent))) {
334: $canmodifycoauthor = 1;
335: }
336: }
337:
1.286 raeburn 338: my %groups = &Apache::lonnet::get_active_groups(
339: $env{'user.domain'}, $env{'user.name'},
340: $env{'course.' . $env{'request.course.id'} . '.domain'},
341: $env{'course.' . $env{'request.course.id'} . '.num'});
1.327 droeschl 342:
1.401 raeburn 343: my ($roleswitcher_js,$roleswitcher_form);
344:
1.283 droeschl 345: foreach my $menuitem (@secondary_menu) {
346: # evaluate conditions
1.296 droeschl 347: next if ref($menuitem) ne 'ARRAY';
1.283 droeschl 348: next if $$menuitem[4] ne 'always'
1.404 raeburn 349: && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
1.283 droeschl 350: && !$env{'request.course.id'};
351: next if $$menuitem[4] =~ /^mdc/
1.286 raeburn 352: && !$canedit;
1.341 www 353: next if $$menuitem[4] eq 'nvgr'
354: && $canvgr;
355: next if $$menuitem[4] eq 'vgr'
356: && !$canvgr;
1.327 droeschl 357: next if $$menuitem[4] eq 'cst'
358: && !$canmodifyuser;
1.343 www 359: next if $$menuitem[4] eq 'ncst'
1.376 raeburn 360: && ($canmodifyuser || !$canviewroster);
1.343 www 361: next if $$menuitem[4] eq 'mgr'
362: && !$canmgr;
363: next if $$menuitem[4] eq 'nmgr'
364: && $canmgr;
1.327 droeschl 365: next if $$menuitem[4] eq 'whn'
366: && !$canviewwnew;
367: next if $$menuitem[4] eq 'opa'
368: && !$canmodpara;
1.283 droeschl 369: next if $$menuitem[4] =~ /showgroups$/
1.300 raeburn 370: && !$canviewgrps
1.286 raeburn 371: && !%groups;
1.329 droeschl 372: next if $$menuitem[4] eq 'author'
373: && !$author;
1.404 raeburn 374: next if $$menuitem[4] eq 'cca'
375: && !$canmodifycoauthor;
1.283 droeschl 376:
1.286 raeburn 377: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283 droeschl 378: # special treatment for role selector
1.401 raeburn 379: ($roleswitcher_js,$roleswitcher_form,my $switcher) =
380: &roles_selector(
1.283 droeschl 381: $env{'course.' . $env{'request.course.id'} . '.domain'},
1.401 raeburn 382: $env{'course.' . $env{'request.course.id'} . '.num'}
383: );
384: $menu .= $switcher;
1.296 droeschl 385: } else {
386: $menu .= &prep_menuitem(\@$menuitem);
1.283 droeschl 387: }
388: }
389: if ($menu =~ /\[url\].*\[symb\]/) {
1.291 raeburn 390: my $escurl = &escape( &Apache::lonenc::check_encrypt(
391: $env{'request.noversionuri'}));
1.283 droeschl 392:
1.291 raeburn 393: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
394: $env{'request.symb'}));
1.283 droeschl 395:
396: if ( $env{'request.state'} eq 'construct'
397: and ( $env{'request.noversionuri'} eq ''
398: || !defined($env{'request.noversionuri'})))
399: {
1.359 raeburn 400: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
401: ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
1.291 raeburn 402: $escurl = &escape($escurl);
1.283 droeschl 403: }
404: $menu =~ s/\[url\]/$escurl/g;
405: $menu =~ s/\[symb\]/$escsymb/g;
406: }
1.329 droeschl 407: $menu =~ s/\[uname\]/$$author{user}/g;
408: $menu =~ s/\[udom\]/$$author{dom}/g;
1.385 raeburn 409: if ($menu) {
410: $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
411: }
1.401 raeburn 412: if ($roleswitcher_form) {
413: $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
414: }
1.385 raeburn 415: return $menu;
1.283 droeschl 416: }
417:
1.375 raeburn 418: sub create_submenu {
419: my ($link,$target,$title,$submenu) = @_;
420: return unless (ref($submenu) eq 'ARRAY');
1.379 raeburn 421: my $disptarget;
422: if ($target ne '') {
423: $disptarget = ' target="'.$target.'"';
424: }
1.375 raeburn 425: my $menu = '<li class="LC_hoverable">'.
1.379 raeburn 426: '<a href="'.$link.'"'.$disptarget.'>'.
1.377 raeburn 427: '<span class="LC_nobreak">'.&mt($title).
1.375 raeburn 428: '<span class="LC_fontsize_small" style="font-weight:normal;">'.
429: ' ▼</span></span></a>'.
430: '<ul>';
431: my $count = 0;
432: my $numsub = scalar(@{$submenu});
433: foreach my $item (@{$submenu}) {
434: $count ++;
435: if (ref($item) eq 'ARRAY') {
436: my $borderbot;
437: if ($count == $numsub) {
438: $borderbot = 'border-bottom:1px solid black;';
439: }
440: $menu .= '<li style="margin:0;padding:0;'.
441: $borderbot.'"><a href="'.$item->[0].'">'.
1.377 raeburn 442: &mt($item->[1]).'</a></li>';
1.375 raeburn 443: }
444: }
445: $menu .= '</ul></li>';
446: return $menu;
447: }
448:
1.40 www 449: sub innerregister {
1.390 raeburn 450: my ($forcereg,$bread_crumbs,$group) = @_;
1.152 albertel 451: my $const_space = ($env{'request.state'} eq 'construct');
1.131 raeburn 452: my $is_const_dir = 0;
1.120 raeburn 453:
1.175 albertel 454: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40 www 455:
1.174 albertel 456: $env{'request.registered'} = 1;
1.40 www 457:
1.177 albertel 458: undef(@inlineremote);
1.56 www 459:
1.393 raeburn 460: my ($mapurl,$resurl);
1.390 raeburn 461:
1.393 raeburn 462: if ($env{'request.course.id'}) {
463: if ($env{'request.symb'}) {
464: ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
465: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
1.267 droeschl 466:
1.393 raeburn 467: my $maptitle = &Apache::lonnet::gettitle($mapurl);
468: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.318 droeschl 469:
470: #SD
471: #course_type only Course and Community?
472: #
1.393 raeburn 473: my @crumbs;
474: unless (($forcereg) &&
475: ($env{'request.noversionuri'} eq '/adm/navmaps') &&
476: ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
477: @crumbs = ({text => Apache::loncommon::course_type()
478: . ' Contents',
479: href => "Javascript:gopost('/adm/navmaps','')"});
480: }
481: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
482: push(@crumbs, {text => '...',
483: no_mt => 1});
484: }
485:
486: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
487: && $maptitle ne 'default.sequence'
488: && $maptitle ne $coursetitle);
1.268 droeschl 489:
1.393 raeburn 490: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
491: &Apache::lonhtmlcommon::clear_breadcrumbs();
492: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
493: } else {
494: $resurl = $env{'request.noversionuri'};
495: my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
496: my $crstype = &Apache::loncommon::course_type();
497: my $title = &mt('View Resource');
498: if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
499: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
1.392 raeburn 500: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.393 raeburn 501: if ($env{'form.title'}) {
502: $title = $env{'form.title'};
503: }
1.394 raeburn 504: my $trail;
1.393 raeburn 505: if ($env{'form.folderpath'}) {
1.399 raeburn 506: &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
1.394 raeburn 507: ($trail) =
1.393 raeburn 508: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
509: } else {
510: &Apache::lonhtmlcommon::add_breadcrumb(
1.392 raeburn 511: {text => "Supplemental $crstype Content",
512: href => "javascript:gopost('/adm/supplemental','')"});
1.393 raeburn 513: $title = &mt('View Resource');
1.394 raeburn 514: ($trail) =
515: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.392 raeburn 516: }
1.394 raeburn 517: return $trail;
1.392 raeburn 518: }
1.395 raeburn 519: unless ($env{'request.state'} eq 'construct') {
520: &Apache::lonhtmlcommon::clear_breadcrumbs();
521: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
522: }
1.392 raeburn 523: }
1.390 raeburn 524: } elsif (! $const_space){
1.328 droeschl 525: #a situation when we're looking at a resource outside of context of a
526: #course or construction space (e.g. with cumulative rights)
527: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.390 raeburn 528: unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
529: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
530: }
1.65 www 531: }
1.41 www 532: # =============================================================================
533: # ============================ This is for URLs that actually can be registered
1.316 droeschl 534: return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
535: || $forcereg );
1.390 raeburn 536: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
537: $forceview,$editbutton);
1.391 raeburn 538: if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
539: ($env{'request.role'} !~/^(aa|ca|au)/)) {
1.390 raeburn 540: $editbutton = &prepare_functions($resurl,$forcereg,$group);
541: }
542: if ($editbutton eq '') {
1.399 raeburn 543: $editbutton = &clear(6,1);
1.390 raeburn 544: }
1.317 droeschl 545:
1.390 raeburn 546: #
547: # This applies in course context
548: #
549: if ($env{'request.course.id'}) {
550: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
551: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
552: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
553: my @privs;
554: if ($env{'request.symb'} ne '') {
555: if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
556: push(@privs,('mgr','vgr'));
557: }
558: push(@privs,'opa');
559: }
560: foreach my $priv (@privs) {
561: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
562: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
563: $perms{$priv} =
564: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
565: }
566: }
567: #
568: # Determine whether or not to show Grades and Submissions buttons
569: #
570: if ($env{'request.symb'} ne '' &&
571: $env{'request.filename'}=~/$LONCAPA::assess_re/) {
572: if ($perms{'mgr'}) {
573: &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
574: "gocmd('/adm/grades','gradingmenu')",
575: 'Content Grades');
576: } elsif ($perms{'vgr'}) {
577: &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
578: "gocmd('/adm/grades','submission')",
579: 'Content Submissions');
580: }
581: }
582: if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
583: &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
584: "gocmd('/adm/parmset','set')",
585: 'Content Settings');
1.107 albertel 586: }
1.393 raeburn 587: # End grades/submissions check
1.107 albertel 588:
1.274 www 589: #
1.393 raeburn 590: # This applies to items inside a folder/page modifiable in the course.
1.274 www 591: #
1.390 raeburn 592: if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
1.393 raeburn 593: my $text = 'Edit Folder';
1.395 raeburn 594: if (($mapurl =~ /\.page$/) ||
595: ($env{'request.symb'}=~
1.396 raeburn 596: m{uploaded/$cdom/$cnum/default_\d+\.page$})) {
1.393 raeburn 597: $text = 'Edit Page';
598: }
599: &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
1.390 raeburn 600: "gocmd('/adm/coursedocs','direct')",
601: 'Folder/Page Content');
1.258 raeburn 602: }
1.390 raeburn 603: # End modifiable folder/page container check
604: }
605: # End course context
606:
1.41 www 607: # Prepare the rest of the buttons
1.383 raeburn 608: my ($menuitems,$got_prt,$got_wishlist);
1.120 raeburn 609: if ($const_space) {
1.274 www 610: #
611: # We are in construction space
612: #
1.353 www 613:
1.355 raeburn 614: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.353 www 615: my ($udom,$uname,$thisdisfn) =
1.355 raeburn 616: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1.353 www 617: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1.131 raeburn 618: if ($currdir =~ m-/$-) {
619: $is_const_dir = 1;
620: } else {
1.267 droeschl 621: $currdir =~ s|[^/]+$||;
1.200 foxr 622: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208 albertel 623: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274 www 624: #
625: # Probably should be in mydesk.tab
626: #
1.131 raeburn 627: $menuitems=(<<ENDMENUITEMS);
1.344 www 628: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1.353 www 629: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
630: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
631: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
632: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1.120 raeburn 633: ENDMENUITEMS
1.131 raeburn 634: }
1.308 raeburn 635: if (ref($bread_crumbs) eq 'ARRAY') {
636: &Apache::lonhtmlcommon::clear_breadcrumbs();
637: foreach my $crumb (@{$bread_crumbs}){
638: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
639: }
640: }
1.203 foxr 641: } elsif ( defined($env{'request.course.id'}) &&
642: $env{'request.symb'} ne '' ) {
1.274 www 643: #
1.383 raeburn 644: # We are in a course and looking at a registered URL
1.274 www 645: # Should probably be in mydesk.tab
646: #
1.120 raeburn 647: $menuitems=(<<ENDMENUITEMS);
1.41 www 648: c&3&1
1.344 www 649: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
650: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
1.77 www 651: c&6&3
652: c&8&1
653: c&8&2
1.344 www 654: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.41 www 655: ENDMENUITEMS
1.383 raeburn 656: $got_prt = 1;
657: if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
658: && (!$env{'request.enc'})) {
1.332 wenzelju 659: # wishlist is only available for users with access to resource-pool
660: # and links can only be set for resources within the resource-pool
661: $menuitems .= (<<ENDMENUITEMS);
1.370 raeburn 662: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository&&1
1.332 wenzelju 663: ENDMENUITEMS
1.383 raeburn 664: $got_wishlist = 1;
1.332 wenzelju 665: }
1.216 albertel 666:
1.243 tempelho 667: my $currentURL = &Apache::loncommon::get_symb();
668: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
669: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
670: $menuitems.="s&9&3&";
671: if(length($annotation) > 0){
1.317 droeschl 672: $menuitems.="anot2.png";
1.243 tempelho 673: }else{
1.317 droeschl 674: $menuitems.="anot.png";
1.243 tempelho 675: }
1.344 www 676: $menuitems.="&Notes&&annotate()&";
1.243 tempelho 677: $menuitems.="Make notes and annotations about this resource&&1\n";
678:
1.323 raeburn 679: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1.382 raeburn 680: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
1.216 albertel 681: $menuitems.=(<<ENDREALRES);
1.344 www 682: s&6&3&catalog.png&Info&info[_1]&catalog_info()&Show Metadata
1.216 albertel 683: ENDREALRES
684: }
1.382 raeburn 685: unless ($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) {
686: $menuitems.=(<<ENDREALRES);
1.344 www 687: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1.382 raeburn 688: ENDREALRES
689: }
690: $menuitems.=(<<ENDREALRES);
1.344 www 691: s&8&2&fdbk.png&Communicate&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1.77 www 692: ENDREALRES
1.120 raeburn 693: }
694: }
1.203 foxr 695: if ($env{'request.uri'} =~ /^\/res/) {
1.383 raeburn 696: unless ($got_prt) {
697: $menuitems .= (<<ENDMENUITEMS);
1.344 www 698: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.203 foxr 699: ENDMENUITEMS
1.384 raeburn 700: $got_prt = 1;
1.383 raeburn 701: }
702: unless ($got_wishlist) {
703: if (($env{'user.adv'}) && (!$env{'request.enc'})) {
704: # wishlist is only available for users with access to resource-pool
705: $menuitems .= (<<ENDMENUITEMS);
1.374 bisitz 706: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository&&1
1.332 wenzelju 707: ENDMENUITEMS
1.383 raeburn 708: $got_wishlist = 1;
709: }
710: }
711: }
1.41 www 712: my $buttons='';
713: foreach (split(/\n/,$menuitems)) {
714: my ($command,@rest)=split(/\&/,$_);
1.220 raeburn 715: my $idx=10*$rest[0]+$rest[1];
716: if (&hidden_button_check() eq 'yes') {
717: if ($idx == 21 ||$idx == 23) {
718: $buttons.=&switch('','',@rest);
719: } else {
720: $buttons.=&clear(@rest);
721: }
722: } else {
723: if ($command eq 's') {
724: $buttons.=&switch('','',@rest);
725: } else {
726: $buttons.=&clear(@rest);
727: }
1.41 www 728: }
729: }
1.148 albertel 730:
731: my $addremote=0;
1.267 droeschl 732: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.301 droeschl 733: if ($addremote) {
734:
1.342 www 735: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301 droeschl 736:
1.342 www 737: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.312 droeschl 738: 'navigation', @inlineremote[21,23]);
739:
1.378 raeburn 740: my $countdown = &countdown_timer();
741: if (&hidden_button_check() eq 'yes') {
742: if ($countdown) {
743: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
744: }
745: } else {
746: my @tools = @inlineremote[93,91,81,82,83];
747: if ($countdown) {
748: unshift(@tools,$countdown);
749: }
1.342 www 750: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.378 raeburn 751: 'tools',@tools);
1.313 droeschl 752:
753: #publish button in construction space
754: if ($env{'request.state'} eq 'construct'){
1.342 www 755: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349 raeburn 756: 'advtools', $inlineremote[63]);
1.342 www 757: } else {
758: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349 raeburn 759: 'tools', $inlineremote[63]);
1.313 droeschl 760: }
1.390 raeburn 761: &advtools_crumbs(@inlineremote);
1.301 droeschl 762: }
1.38 www 763: }
764:
1.342 www 765: return &Apache::lonhtmlcommon::scripttag('', 'start')
766: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
767: . &Apache::lonhtmlcommon::scripttag('', 'end');
1.38 www 768: }
769:
1.389 raeburn 770: sub get_editbutton {
1.390 raeburn 771: my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
1.398 raeburn 772: my $jscall;
773: if (($forceview) && ($env{'form.todocs'})) {
774: my ($folderpath,$command);
775: if ($env{'request.symb'}) {
776: $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
777: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
778: $folderpath = $env{'form.folderpath'};
779: $command = '&forcesupplement=1';
780: }
781: $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
782: $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
783: } else {
784: $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1.393 raeburn 785: $forceedit,$forcereg,$env{'request.symb'},
786: &escape($env{'form.folderpath'}),
787: &escape($env{'form.title'}),$env{'form.idx'},
1.398 raeburn 788: &escape($env{'form.suppurl'},$env{'form.todocs'}));
789: }
1.389 raeburn 790: if ($jscall) {
1.390 raeburn 791: my $icon = 'pcstr.png';
792: my $label = 'Edit';
793: if ($forceview) {
794: $icon = 'tolastloc.png';
795: $label = 'Exit Editing';
796: }
797: &switch('','',6,1,$icon,$label,'resource[_2]',
798: $jscall,"Edit this resource");
799: return 1;
800: }
801: return;
802: }
803:
804: sub prepare_functions {
1.393 raeburn 805: my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_;
1.390 raeburn 806: unless ($env{'request.registered'}) {
807: undef(@inlineremote);
808: }
809: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
810: $forceview);
811:
812: if ($env{'request.course.id'}) {
813: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
814: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
815: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
816: }
817:
818: my $editbutton = '';
819: #
820: # Determine whether or not to display 'Edit' icon/button
821: #
822: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
823: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.391 raeburn 824: ($cfile,$home,$switchserver,$forceedit,$forceview) =
825: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
826: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
827: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
828: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.390 raeburn 829: $forceedit,$forceview,$forcereg);
830: }
1.391 raeburn 831: } elsif ((!$env{'request.course.id'}) &&
1.390 raeburn 832: ($env{'user.author'}) && ($env{'request.filename'}) &&
833: ($env{'request.role'} !~/^(aa|ca|au)/)) {
834: #
835: # Currently do not have the role of author or co-author.
836: # Do we have authoring privileges for the resource?
837: #
838: my $file=&Apache::lonnet::declutter($env{'request.filename'});
839: ($cfile,$home,$switchserver,$forceedit,$forceview) =
840: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
841: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
842: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
843: $editbutton = &get_editbutton($cfile,$home,$switchserver,
844: $forceedit,$forceview,$forcereg);
845: }
846: } elsif ($env{'request.course.id'}) {
847: #
848: # This applies in course context
849: #
850: if (($resurl eq "/public/$cdom/$cnum/syllabus") && ($perms{'mdc'})) {
851: if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ /\w/) {
852: &switch('','',6,1,'pcstr.png','Edit',
853: 'resource[_2]',
854: "go('/adm/courseprefs?phase=display&actions=courseinfo')",
855: 'Edit this resource');
856: $editbutton = 1;
857: } else {
858: $cfile = $resurl;
859: $home = &Apache::lonnet::homeserver($cnum,$cdom);
860: if ($env{'form.forceedit'}) {
861: $forceview = 1;
862: } else {
863: $forceedit = 1;
864: }
865: $editbutton = &get_editbutton($cfile,$home,$switchserver,
866: $forceedit,$forceview,$forcereg);
867: }
1.393 raeburn 868: } elsif (($resurl eq '/adm/extresedit') &&
869: (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
870: ($cfile,$home,$switchserver,$forceedit,$forceview) =
871: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
872: $env{'form.symb'});
873: if ($cfile ne '') {
874: $editbutton = &get_editbutton($cfile,$home,$switchserver,
875: $forceedit,$forceview,$forcereg,
876: $env{'form.title'},$env{'form.suppurl'});
877: }
1.405 ! raeburn 878: } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
! 879: ($resurl ne '/cgi-bin/printout.pl')) {
1.390 raeburn 880: if ($env{'request.filename'}) {
881: my $file=&Apache::lonnet::declutter($env{'request.filename'});
882: ($cfile,$home,$switchserver,$forceedit,$forceview) =
883: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
884: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
885: if ($cfile ne '') {
886: $editbutton = &get_editbutton($cfile,$home,$switchserver,
887: $forceedit,$forceview,$forcereg);
888: }
889: }
890: }
891: }
892: # End determination of 'Edit' icon/button display
893:
1.393 raeburn 894: if ($env{'request.course.id'}) {
1.390 raeburn 895: # This applies to about me page for users in a course
1.391 raeburn 896: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.390 raeburn 897: my ($sdom,$sname) = ($1,$2);
898: unless (&Apache::lonnet::is_course($sdom,$sname)) {
899: &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
900: '',
901: "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
902: 'Send message to specific user');
903: }
1.391 raeburn 904: my $hideprivileged = 1;
905: if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
906: $hideprivileged)) {
1.390 raeburn 907: foreach my $priv ('vsa','vgr','srm') {
908: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
909: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
910: $perms{$priv} =
911: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
912: }
913: }
914: if ($perms{'vsa'}) {
915: &switch('','',6,5,'trck-22x22.png','Activity',
916: '',
917: "go('/adm/trackstudent?selected_student=$sname:$sdom')",
918: 'View recent activity by this person');
919: }
920: if ($perms{'vgr'}) {
921: &switch('','',6,6,'rsrv-22x22.png','Reservations',
922: '',
923: "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
924: 'Slot reservation history');
925: }
926: if ($perms{'srm'}) {
927: &switch('','',6,7,'contact-new-22x22.png','Records',
928: '',
929: "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
930: 'Add records');
931: }
932: }
1.393 raeburn 933: } elsif ($resurl =~ m{^/?adm/viewclasslist}) {
934: # This applies to viewclasslist page for users in a course
935: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
936: &switch('','',6,4,'pparm.png','Settings',
937: '',
938: "go('/adm/courseprefs?actions=classlists&phase=display')",
939: 'Student-viewable classlist options');
940: }
941: }
942: if (($env{'form.folderpath'} =~ /^supplemental/) &&
943: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
944: (($resurl =~ m{^/adm/wrapper/ext/}) ||
945: ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1.397 raeburn 946: ($resurl eq '/adm/supplemental') ||
947: ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
948: ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1.393 raeburn 949: my @folders=split('&',$env{'form.folderpath'});
1.394 raeburn 950: if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1.393 raeburn 951: my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
952: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
953: "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path'",
954: 'Folder/Page Content');
955: }
1.390 raeburn 956: }
957: }
958:
959: # End checking for items for about me page for users in a course
1.393 raeburn 960: if ($docscrumbs) {
961: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
962: &advtools_crumbs(@inlineremote);
963: return $editbutton;
964: } elsif ($env{'request.registered'}) {
1.390 raeburn 965: return $editbutton;
966: } else {
967: if (ref($bread_crumbs) eq 'ARRAY') {
968: if (@inlineremote > 0) {
969: if (ref($advtools) eq 'ARRAY') {
970: @{$advtools} = @inlineremote;
971: }
972: }
973: return;
974: } elsif (@inlineremote > 0) {
975: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
976: &advtools_crumbs(@inlineremote);
977: return &Apache::lonhtmlcommon::scripttag('', 'start')
978: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
979: . &Apache::lonhtmlcommon::scripttag('', 'end');
980: }
981: }
982: }
983:
984: sub advtools_crumbs {
985: my @funcs = @_;
986: if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
987: &Apache::lonhtmlcommon::add_breadcrumb_tool(
988: 'advtools', @funcs[61,64,65,66,67,74]);
989: } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
990: &Apache::lonhtmlcommon::add_breadcrumb_tool(
991: 'advtools', @funcs[61,71,72,73,74,92]);
1.393 raeburn 992: } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
993: &Apache::lonhtmlcommon::add_breadcrumb_tool(
994: 'advtools', @funcs[64]);
995: }
1.258 raeburn 996: }
997:
1.2 www 998: # ================================================================== Raw Config
999:
1.3 www 1000: sub clear {
1001: my ($row,$col)=@_;
1.316 droeschl 1002: $inlineremote[10*$row+$col]='';
1003: return '';
1.3 www 1004: }
1005:
1.40 www 1006: # ============================================ Switch a button or create a link
1.25 matthew 1007: # Switch acts on the javascript that is executed when a button is clicked.
1008: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 1009:
1.2 www 1010: sub switch {
1.209 www 1011: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2 www 1012: $act=~s/\$uname/$uname/g;
1013: $act=~s/\$udom/$udom/g;
1.88 www 1014: $top=&mt($top);
1015: $bot=&mt($bot);
1016: $desc=&mt($desc);
1.209 www 1017: my $idx=10*$row+$col;
1018: $category_members{$cat}.=':'.$idx;
1019:
1.320 droeschl 1020: # Inline Menu
1.317 droeschl 1021: if ($nobreak==2) { return ''; }
1022: my $text=$top.' '.$bot;
1023: $text=~s/\s*\-\s*//gs;
1.105 www 1024:
1.317 droeschl 1025: my $pic=
1.225 albertel 1026: '<img alt="'.$text.'" src="'.
1027: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303 droeschl 1028: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317 droeschl 1029: if ($env{'browser.interface'} eq 'faketextual') {
1.274 www 1030: # Main Menu
1.103 www 1031: if ($nobreak==3) {
1.209 www 1032: $inlineremote[$idx]="\n".
1.177 albertel 1033: '<td class="LC_menubuttons_text" align="right">'.$text.
1.247 harmsja 1034: '</td><td align="left">'.
1.103 www 1035: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1036: } elsif ($nobreak) {
1.209 www 1037: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1038: '<td align="left">'.
1.177 albertel 1039: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215 www 1040: <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 1041: } else {
1.209 www 1042: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1043: '<td align="left">'.
1.103 www 1044: '<a href="javascript:'.$act.';">'.$pic.
1.177 albertel 1045: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215 www 1046: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103 www 1047: }
1.317 droeschl 1048: } else {
1.103 www 1049: # Inline Menu
1.378 raeburn 1050: my @tools = (93,91,81,82,83);
1051: unless ($env{'request.state'} eq 'construct') {
1052: push(@tools,63);
1053: }
1054: if (($env{'environment.icons'} eq 'iconsonly') &&
1055: (grep(/^$idx$/,@tools))) {
1056: $inlineremote[$idx] =
1057: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
1058: } else {
1059: $inlineremote[$idx] =
1.317 droeschl 1060: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344 www 1061: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
1.378 raeburn 1062: }
1.317 droeschl 1063: }
1.56 www 1064: return '';
1.2 www 1065: }
1066:
1067: sub secondlevel {
1068: my $output='';
1069: my
1.209 www 1070: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2 www 1071: if ($prt eq 'any') {
1.209 www 1072: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1073: } elsif ($prt=~/^r(\w+)/) {
1074: if ($rol eq $1) {
1.209 www 1075: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1076: }
1077: }
1078: return $output;
1079: }
1080:
1.56 www 1081: sub inlinemenu {
1.210 albertel 1082: undef(@inlineremote);
1083: undef(%category_members);
1.275 www 1084: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56 www 1085: &rawconfig(1);
1.309 bisitz 1086: my $output='<table><tr>';
1.209 www 1087: for (my $col=1; $col<=2; $col++) {
1.241 riegler 1088: $output.='<td class="LC_mainmenu_col_fieldset">';
1.209 www 1089: for (my $row=1; $row<=8; $row++) {
1090: foreach my $cat (keys(%category_members)) {
1091: if ($category_positions{$cat} ne "$col,$row") { next; }
1.247 harmsja 1092: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309 bisitz 1093: $output.='<div class="LC_Box LC_400Box">';
1094: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247 harmsja 1095: $output.='<table>';
1.240 riegler 1096: my %active=();
1097: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1098: if ($inlineremote[$menu_item]) {
1099: $active{$menu_item}=1;
1100: }
1101: }
1102: foreach my $item (sort(keys(%active))) {
1103: $output.=$inlineremote[$item];
1104: }
1105: $output.='</table>';
1.245 harmsja 1106: $output.='</div>';
1.240 riegler 1107: }
1108: }
1109: $output.="</td>";
1110: }
1111: $output.="</tr></table>";
1112: return $output;
1113: }
1114:
1.2 www 1115: sub rawconfig {
1.274 www 1116: #
1117: # This evaluates mydesk.tab
1118: # Need to add more positions and more privileges to deal with all
1119: # menu items.
1120: #
1.34 www 1121: my $textualoverride=shift;
1122: my $output='';
1.316 droeschl 1123: return '' unless $textualoverride;
1.152 albertel 1124: my $uname=$env{'user.name'};
1125: my $udom=$env{'user.domain'};
1126: my $adv=$env{'user.adv'};
1.266 raeburn 1127: my $show_course=&Apache::loncommon::show_course();
1.152 albertel 1128: my $author=$env{'user.author'};
1.5 www 1129: my $crs='';
1.295 raeburn 1130: my $crstype='';
1.152 albertel 1131: if ($env{'request.course.id'}) {
1132: $crs='/'.$env{'request.course.id'};
1133: if ($env{'request.course.sec'}) {
1134: $crs.='_'.$env{'request.course.sec'};
1.7 www 1135: }
1.8 www 1136: $crs=~s/\_/\//g;
1.295 raeburn 1137: $crstype = &Apache::loncommon::course_type();
1.5 www 1138: }
1.152 albertel 1139: my $pub=($env{'request.state'} eq 'published');
1140: my $con=($env{'request.state'} eq 'construct');
1141: my $rol=$env{'request.role'};
1142: my $requested_domain = $env{'request.role.domain'};
1.184 raeburn 1143: foreach my $line (@desklines) {
1.209 www 1144: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3 www 1145: $prt=~s/\$uname/$uname/g;
1146: $prt=~s/\$udom/$udom/g;
1.295 raeburn 1147: if ($prt =~ /\$crs/) {
1148: next unless ($env{'request.course.id'});
1149: next if ($crstype eq 'Community');
1150: $prt=~s/\$crs/$crs/g;
1151: } elsif ($prt =~ /\$cmty/) {
1152: next unless ($env{'request.course.id'});
1153: next if ($crstype ne 'Community');
1154: $prt=~s/\$cmty/$crs/g;
1155: }
1.25 matthew 1156: $prt=~s/\$requested_domain/$requested_domain/g;
1.211 www 1157: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3 www 1158: if ($pro eq 'clear') {
1.4 www 1159: $output.=&clear($row,$col);
1.3 www 1160: } elsif ($pro eq 'any') {
1.2 www 1161: $output.=&secondlevel(
1.209 www 1162: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1163: } elsif ($pro eq 'smp') {
1164: unless ($adv) {
1165: $output.=&secondlevel(
1.209 www 1166: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1167: }
1168: } elsif ($pro eq 'adv') {
1169: if ($adv) {
1170: $output.=&secondlevel(
1.209 www 1171: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1172: }
1.231 albertel 1173: } elsif ($pro eq 'shc') {
1174: if ($show_course) {
1175: $output.=&secondlevel(
1176: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1177: }
1178: } elsif ($pro eq 'nsc') {
1179: if (!$show_course) {
1180: $output.=&secondlevel(
1181: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1182: }
1.81 matthew 1183: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295 raeburn 1184: my $priv = $1;
1185: if ($priv =~ /^mdc(Course|Community)/) {
1186: if ($crstype eq $1) {
1187: $priv = 'mdc';
1188: } else {
1189: next;
1190: }
1191: }
1192: if (&Apache::lonnet::allowed($priv,$prt)) {
1.209 www 1193: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4 www 1194: }
1.295 raeburn 1195: } elsif ($pro eq 'course') {
1196: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209 www 1197: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81 matthew 1198: }
1.295 raeburn 1199: } elsif ($pro eq 'community') {
1200: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1201: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1202: }
1.124 matthew 1203: } elsif ($pro =~ /^courseenv_(.*)$/) {
1204: my $key = $1;
1.307 raeburn 1205: if ($crstype ne 'Community') {
1206: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1207: if ($key eq 'canuse_pdfforms') {
1208: if ($env{'request.course.id'} && $coursepref eq '') {
1209: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1210: $coursepref = $domdefs{'canuse_pdfforms'};
1211: }
1212: }
1213: if ($coursepref) {
1214: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1215: }
1.295 raeburn 1216: }
1217: } elsif ($pro =~ /^communityenv_(.*)$/) {
1218: my $key = $1;
1.307 raeburn 1219: if ($crstype eq 'Community') {
1220: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1221: if ($key eq 'canuse_pdfforms') {
1222: if ($env{'request.course.id'} && $coursepref eq '') {
1223: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1224: $coursepref = $domdefs{'canuse_pdfforms'};
1225: }
1226: }
1227: if ($coursepref) {
1228: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1229: }
1.124 matthew 1230: }
1.81 matthew 1231: } elsif ($pro =~ /^course_(.*)$/) {
1232: # Check for permissions inside of a course
1.295 raeburn 1233: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1.152 albertel 1234: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1235: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81 matthew 1236: )) {
1.209 www 1237: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26 www 1238: }
1.295 raeburn 1239: } elsif ($pro =~ /^community_(.*)$/) {
1240: # Check for permissions inside of a community
1241: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1242: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1243: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1244: )) {
1245: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1246: }
1.4 www 1247: } elsif ($pro eq 'author') {
1248: if ($author) {
1.152 albertel 1249: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234 raeburn 1250: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1.152 albertel 1251: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19 matthew 1252: # Check that we are on the correct machine
1.29 matthew 1253: my $cadom=$requested_domain;
1.152 albertel 1254: my $caname=$env{'user.name'};
1.234 raeburn 1255: if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29 matthew 1256: ($cadom,$caname)=
1.206 albertel 1257: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29 matthew 1258: }
1259: $act =~ s/\$caname/$caname/g;
1.353 www 1260: $act =~ s/\$cadom/$cadom/g;
1.19 matthew 1261: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 1262: my $allowed=0;
1263: my @ids=&Apache::lonnet::current_machine_ids();
1264: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1265: if ($allowed) {
1.209 www 1266: $output.=&switch($caname,$cadom,
1267: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19 matthew 1268: }
1.6 www 1269: }
1.2 www 1270: }
1.248 raeburn 1271: } elsif ($pro eq 'tools') {
1272: my @tools = ('aboutme','blog','portfolio');
1273: if (grep(/^\Q$prt\E$/,@tools)) {
1.249 raeburn 1274: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251 raeburn 1275: $env{'user.domain'},
1276: $prt,undef,'tools')) {
1277: $output.=&clear($row,$col);
1278: next;
1279: }
1.278 raeburn 1280: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1281: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1282: next;
1283: }
1284: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1285: next;
1286: }
1.279 raeburn 1287: my $showreqcrs = &check_for_rcrs();
1.251 raeburn 1288: if (!$showreqcrs) {
1.248 raeburn 1289: $output.=&clear($row,$col);
1290: next;
1291: }
1292: }
1293: $prt='any';
1294: $output.=&secondlevel(
1295: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1296: }
1.13 harris41 1297: }
1.2 www 1298: return $output;
1299: }
1300:
1.279 raeburn 1301: sub check_for_rcrs {
1302: my $showreqcrs = 0;
1.280 raeburn 1303: my @reqtypes = ('official','unofficial','community');
1304: foreach my $type (@reqtypes) {
1.279 raeburn 1305: if (&Apache::lonnet::usertools_access($env{'user.name'},
1306: $env{'user.domain'},
1307: $type,undef,'requestcourses')) {
1308: $showreqcrs = 1;
1309: last;
1310: }
1311: }
1.280 raeburn 1312: if (!$showreqcrs) {
1313: foreach my $type (@reqtypes) {
1314: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1315: $showreqcrs = 1;
1316: last;
1317: }
1318: }
1319: }
1.279 raeburn 1320: return $showreqcrs;
1321: }
1322:
1.306 raeburn 1323: sub dc_popup_js {
1324: my %lt = &Apache::lonlocal::texthash(
1325: more => '(More ...)',
1326: less => '(Less ...)',
1327: );
1328: return <<"END";
1329:
1330: function showCourseID() {
1331: document.getElementById('dccid').style.display='block';
1332: document.getElementById('dccid').style.textAlign='left';
1.307 raeburn 1333: document.getElementById('dccid').style.textFace='normal';
1.369 raeburn 1334: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306 raeburn 1335: return;
1336: }
1337:
1338: function hideCourseID() {
1339: document.getElementById('dccid').style.display='none';
1.369 raeburn 1340: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306 raeburn 1341: return;
1342: }
1343:
1344: END
1345:
1346: }
1347:
1.378 raeburn 1348: sub countdown_toggle_js {
1349: return <<"END";
1350:
1351: function toggleCountdown() {
1352: var countdownid = document.getElementById('duedatecountdown');
1353: var currstyle = countdownid.style.display;
1354: if (currstyle == 'inline') {
1355: countdownid.style.display = 'none';
1356: document.getElementById('ddcountcollapse').innerHTML='';
1357: document.getElementById('ddcountexpand').innerHTML='◄ ';
1358: } else {
1359: countdownid.style.display = 'inline';
1360: document.getElementById('ddcountcollapse').innerHTML='► ';
1361: document.getElementById('ddcountexpand').innerHTML='';
1362: }
1363: return;
1364: }
1365:
1366: END
1367: }
1368:
1.42 www 1369: sub utilityfunctions {
1.152 albertel 1370: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.316 droeschl 1371: if ($currenturl =~ m{^/adm/wrapper/ext/}
1372: && $env{'request.external.querystring'} ) {
1.293 raeburn 1373: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1374: }
1.183 www 1375: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125 albertel 1376:
1.152 albertel 1377: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.175 albertel 1378:
1.306 raeburn 1379: my $dc_popup_cid;
1380: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1381: $env{'course.'.$env{'request.course.id'}.
1382: '.domain'}.'/'})) {
1383: $dc_popup_cid = &dc_popup_js();
1384: }
1385:
1.175 albertel 1386: my $start_page_annotate =
1387: &Apache::loncommon::start_page('Annotator',undef,
1388: {'only_body' => 1,
1389: 'js_ready' => 1,
1390: 'bgcolor' => '#BBBBBB',
1391: 'add_entries' => {
1392: 'onload' => 'javascript:document.goannotate.submit();'}});
1393:
1.205 albertel 1394: my $end_page_annotate =
1395: &Apache::loncommon::end_page({'js_ready' => 1});
1396:
1.389 raeburn 1397: my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336 raeburn 1398:
1.368 www 1399: my $esc_url=&escape($currenturl);
1400: my $esc_symb=&escape($currentsymb);
1.332 wenzelju 1401:
1.378 raeburn 1402: my $countdown = &countdown_toggle_js();
1403:
1.42 www 1404: return (<<ENDUTILITY)
1405:
1.368 www 1406: var currentURL=unescape("$esc_url");
1407: var reloadURL=unescape("$esc_url");
1408: var currentSymb=unescape("$esc_symb");
1.42 www 1409:
1.306 raeburn 1410: $dc_popup_cid
1.114 albertel 1411:
1.389 raeburn 1412: $jumptores
1.336 raeburn 1413:
1.42 www 1414: function gopost(url,postdata) {
1415: if (url!='') {
1416: this.document.server.action=url;
1417: this.document.server.postdata.value=postdata;
1418: this.document.server.command.value='';
1419: this.document.server.url.value='';
1420: this.document.server.symb.value='';
1421: this.document.server.submit();
1422: }
1423: }
1424:
1425: function gocmd(url,cmd) {
1426: if (url!='') {
1427: this.document.server.action=url;
1428: this.document.server.postdata.value='';
1429: this.document.server.command.value=cmd;
1430: this.document.server.url.value=currentURL;
1431: this.document.server.symb.value=currentSymb;
1432: this.document.server.submit();
1433: }
1.57 www 1434: }
1435:
1.121 raeburn 1436: function gocstr(url,filename) {
1437: if (url == '/adm/cfile?action=delete') {
1438: this.document.cstrdelete.filename.value = filename
1439: this.document.cstrdelete.submit();
1440: return;
1441: }
1.137 raeburn 1442: if (url == '/adm/printout') {
1443: this.document.cstrprint.postdata.value = filename
1444: this.document.cstrprint.curseed.value = 0;
1445: this.document.cstrprint.problemtype.value = 0;
1.138 raeburn 1446: if (this.document.lonhomework) {
1447: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1448: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1449: }
1450: if (this.document.lonhomework.problemtype) {
1.164 albertel 1451: if (this.document.lonhomework.problemtype.value) {
1452: this.document.cstrprint.problemtype.value =
1453: this.document.lonhomework.problemtype.value;
1454: } else if (this.document.lonhomework.problemtype.options) {
1455: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1456: if (this.document.lonhomework.problemtype.options[i].selected) {
1457: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1458: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1459: }
1460: }
1461: }
1462: }
1463: }
1464: }
1.137 raeburn 1465: this.document.cstrprint.submit();
1466: return;
1467: }
1.121 raeburn 1468: if (url !='') {
1469: this.document.constspace.filename.value = filename;
1470: this.document.constspace.action = url;
1471: this.document.constspace.submit();
1472: }
1473: }
1474:
1.131 raeburn 1475: function golist(url) {
1476: if (url!='' && url!= null) {
1477: currentURL = null;
1478: currentSymb= null;
1479: top.location.href=url;
1480: }
1481: }
1482:
1483:
1.121 raeburn 1484:
1.57 www 1485: function catalog_info() {
1.365 www 1486: openMyModal(window.location.pathname+'.meta',500,400,'yes');
1.57 www 1487: }
1488:
1489: function chat_win() {
1.290 raeburn 1490: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42 www 1491: }
1.169 raeburn 1492:
1493: function group_chat(group) {
1494: var url = '/adm/groupchat?group='+group;
1495: var winName = 'LONchat_'+group;
1496: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1497: }
1.175 albertel 1498:
1499: function annotate() {
1500: w_Annotator_flag=1;
1501: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1502: annotator.document.write(
1503: '$start_page_annotate'
1504: +"<form name='goannotate' target='Annotator' method='post' "
1505: +"action='/adm/annotations'>"
1.217 albertel 1506: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181 albertel 1507: +"<\\/form>"
1.205 albertel 1508: +'$end_page_annotate');
1.175 albertel 1509: annotator.document.close();
1510: }
1511:
1.370 raeburn 1512: function open_StoredLinks_Import(rat) {
1.335 wenzelju 1513: var newWin;
1514: if (rat) {
1515: newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.334 wenzelju 1516: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1.335 wenzelju 1517: }
1518: else {
1519: newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import',
1520: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1521: }
1.334 wenzelju 1522: newWin.focus();
1523: }
1524:
1.372 raeburn 1525: (function (\$) {
1526: \$(document).ready(function () {
1527: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
1528: /*\@cc_on
1529: if (!window.XMLHttpRequest) {
1530: \$('.LC_hoverable').each(function () {
1531: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
1532: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
1533: });
1534: }
1535: \@*/
1536: });
1537: }(jQuery));
1538:
1.378 raeburn 1539: $countdown
1540:
1.42 www 1541: ENDUTILITY
1542: }
1543:
1544: sub serverform {
1545: return(<<ENDSERVERFORM);
1.181 albertel 1546: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 1547: <input type="hidden" name="postdata" value="none" />
1548: <input type="hidden" name="command" value="none" />
1549: <input type="hidden" name="url" value="none" />
1550: <input type="hidden" name="symb" value="none" />
1551: </form>
1552: ENDSERVERFORM
1553: }
1.113 albertel 1554:
1.121 raeburn 1555: sub constspaceform {
1556: return(<<ENDCONSTSPACEFORM);
1.181 albertel 1557: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121 raeburn 1558: <input type="hidden" name="filename" value="" />
1559: </form>
1.181 albertel 1560: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121 raeburn 1561: <input type="hidden" name="action" value="delete" />
1562: <input type="hidden" name="filename" value="" />
1563: </form>
1.181 albertel 1564: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137 raeburn 1565: <input type="hidden" name="postdata" value="" />
1566: <input type="hidden" name="curseed" value="" />
1567: <input type="hidden" name="problemtype" value="" />
1568: </form>
1569:
1.121 raeburn 1570: ENDCONSTSPACEFORM
1571: }
1572:
1.220 raeburn 1573: sub hidden_button_check {
1.317 droeschl 1574: if ( $env{'request.course.id'} eq ''
1575: || $env{'request.role.adv'} ) {
1576:
1.220 raeburn 1577: return;
1578: }
1.232 raeburn 1579: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1580: return $buttonshide;
1.220 raeburn 1581: }
1.184 raeburn 1582:
1.235 raeburn 1583: sub roles_selector {
1584: my ($cdom,$cnum) = @_;
1.298 raeburn 1585: my $crstype = &Apache::loncommon::course_type();
1.235 raeburn 1586: my $now = time;
1.350 raeburn 1587: my (%courseroles,%seccount,%courseprivs);
1.235 raeburn 1588: my $is_cc;
1.401 raeburn 1589: my ($js,$form,$switcher,$switchtext);
1.298 raeburn 1590: my $ccrole;
1591: if ($crstype eq 'Community') {
1592: $ccrole = 'co';
1593: } else {
1594: $ccrole = 'cc';
1.350 raeburn 1595: }
1.386 raeburn 1596: my ($priv,$gotsymb,$destsymb);
1.350 raeburn 1597: my $destinationurl = $ENV{'REQUEST_URI'};
1.386 raeburn 1598: if ($destinationurl =~ /\?symb=/) {
1599: $gotsymb = 1;
1600: } elsif ($destinationurl =~ m{^/enc/}) {
1601: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
1602: if ($plainurl =~ /\?symb=/) {
1603: $gotsymb = 1;
1604: }
1605: }
1606: unless ($gotsymb) {
1607: $destsymb = &Apache::lonnet::symbread();
1608: if ($destsymb ne '') {
1609: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
1610: }
1611: }
1.350 raeburn 1612: my $reqprivs = &required_privs();
1613: if (ref($reqprivs) eq 'HASH') {
1614: my $destination = $destinationurl;
1615: $destination =~ s/(\?.*)$//;
1616: if (exists($reqprivs->{$destination})) {
1617: $priv = $reqprivs->{$destination};
1618: }
1619: }
1.298 raeburn 1620: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
1621: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235 raeburn 1622:
1623: if ((($start) && ($start<0)) ||
1624: (($end) && ($end<$now)) ||
1625: (($start) && ($now<$start))) {
1626: $is_cc = 0;
1627: } else {
1628: $is_cc = 1;
1629: }
1630: }
1631: if ($is_cc) {
1.350 raeburn 1632: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1.235 raeburn 1633: } else {
1.262 raeburn 1634: my %gotnosection;
1.235 raeburn 1635: foreach my $item (keys(%env)) {
1.239 raeburn 1636: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235 raeburn 1637: my $role = $1;
1638: my $sec = $2;
1639: next if ($role eq 'gr');
1640: my ($start,$end) = split(/\./,$env{$item});
1641: next if (($start && $start > $now) || ($end && $end < $now));
1642: if ($sec eq '') {
1.239 raeburn 1643: if (!$gotnosection{$role}) {
1644: $seccount{$role} ++;
1645: $gotnosection{$role} = 1;
1646: }
1.235 raeburn 1647: }
1.350 raeburn 1648: if ($priv ne '') {
1649: my $cnumsec = $cnum;
1650: if ($sec ne '') {
1651: $cnumsec .= "/$sec";
1652: }
1653: $courseprivs{"$role./$cdom/$cnumsec./"} =
1654: $env{"user.priv.$role./$cdom/$cnumsec./"};
1655: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
1656: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
1657: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
1658: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
1659: }
1.235 raeburn 1660: if (ref($courseroles{$role}) eq 'ARRAY') {
1.239 raeburn 1661: if ($sec ne '') {
1.264 raeburn 1662: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239 raeburn 1663: push(@{$courseroles{$role}},$sec);
1664: $seccount{$role} ++;
1665: }
1666: }
1667: } else {
1668: @{$courseroles{$role}} = ();
1669: if ($sec ne '') {
1670: $seccount{$role} ++;
1.235 raeburn 1671: push(@{$courseroles{$role}},$sec);
1672: }
1673: }
1674: }
1675: }
1676: }
1.286 raeburn 1677: if ($crstype eq 'Community') {
1.402 raeburn 1678: $switchtext = &mt('Switch community role')
1.286 raeburn 1679: } else {
1.402 raeburn 1680: $switchtext = &mt('Switch course role')
1.286 raeburn 1681: }
1.298 raeburn 1682: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.402 raeburn 1683: my $numdiffsec;
1684: if (keys(%seccount) == 1) {
1685: foreach my $key (keys(%seccount)) {
1686: $numdiffsec = $seccount{$key};
1687: }
1688: }
1689: if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
1.401 raeburn 1690: my @submenu;
1691: $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
1692: $form =
1693: '<form name="rolechooser" method="post" action="/adm/roles">'."\n".
1694: ' <input type="hidden" name="destinationurl" value="'.
1695: &HTML::Entities::encode($destinationurl).'" />'."\n".
1696: ' <input type="hidden" name="gotorole" value="1" />'."\n".
1697: ' <input type="hidden" name="selectrole" value="" />'."\n".
1.402 raeburn 1698: ' <input type="hidden" name="switchrole" value="" />'."\n";
1699: if ($destsymb ne '') {
1700: $form .= ' <input type="hidden" name="destsymb" value="'.
1701: &HTML::Entities::encode($destsymb).'" />'."\n";
1702: }
1703: $form .= '</form>'."\n";
1.235 raeburn 1704: foreach my $role (@roles_order) {
1.402 raeburn 1705: my $include;
1.235 raeburn 1706: if (defined($courseroles{$role})) {
1.402 raeburn 1707: if ($env{'request.role'} =~ m{^\Q$role\E}) {
1708: if ($seccount{$role} > 1) {
1709: $include = 1;
1710: }
1711: } else {
1712: $include = 1;
1713: }
1714: }
1715: if ($include) {
1.401 raeburn 1716: push(@submenu,['javascript:adhocRole('."'$role'".')',
1717: &Apache::lonnet::plaintext($role,$crstype)]);
1.235 raeburn 1718: }
1719: }
1720: foreach my $role (sort(keys(%courseroles))) {
1721: if ($role =~ /^cr/) {
1.403 raeburn 1722: my $include;
1723: if ($env{'request.role'} =~ m{^\Q$role\E}) {
1.402 raeburn 1724: if ($seccount{$role} > 1) {
1725: $include = 1;
1726: }
1.403 raeburn 1727: } else {
1728: $include = 1;
1729: }
1730: if ($include) {
1731: push(@submenu,['javascript:adhocRole('."'$role'".')',
1732: &Apache::lonnet::plaintext($role)]);
1733: }
1.235 raeburn 1734: }
1735: }
1.401 raeburn 1736: if (@submenu > 0) {
1737: $switcher = &create_submenu('','',$switchtext,\@submenu);
1.386 raeburn 1738: }
1.235 raeburn 1739: }
1.401 raeburn 1740: return ($js,$form,$switcher);
1.235 raeburn 1741: }
1742:
1.262 raeburn 1743: sub get_all_courseroles {
1.350 raeburn 1744: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351 raeburn 1745: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350 raeburn 1746: (ref($courseprivs) eq 'HASH')) {
1.262 raeburn 1747: return;
1748: }
1749: my ($result,$cached) =
1750: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1751: if (defined($cached)) {
1752: if (ref($result) eq 'HASH') {
1753: if ((ref($result->{'roles'}) eq 'HASH') &&
1.350 raeburn 1754: (ref($result->{'seccount'}) eq 'HASH') &&
1755: (ref($result->{'privs'}) eq 'HASH')) {
1.262 raeburn 1756: %{$courseroles} = %{$result->{'roles'}};
1757: %{$seccount} = %{$result->{'seccount'}};
1.350 raeburn 1758: %{$courseprivs} = %{$result->{'privs'}};
1.262 raeburn 1759: return;
1760: }
1761: }
1762: }
1763: my %gotnosection;
1764: my %adv_roles =
1765: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1766: foreach my $role (keys(%adv_roles)) {
1767: my ($urole,$usec) = split(/:/,$role);
1768: if (!$gotnosection{$urole}) {
1769: $seccount->{$urole} ++;
1770: $gotnosection{$urole} = 1;
1771: }
1772: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1773: if ($usec ne '') {
1774: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1775: push(@{$courseroles->{$urole}},$usec);
1776: $seccount->{$urole} ++;
1777: }
1778: }
1779: } else {
1780: @{$courseroles->{$urole}} = ();
1781: if ($usec ne '') {
1782: $seccount->{$urole} ++;
1783: push(@{$courseroles->{$urole}},$usec);
1784: }
1785: }
1.350 raeburn 1786: my $area = '/'.$cdom.'/'.$cnum;
1787: if ($usec ne '') {
1788: $area .= '/'.$usec;
1789: }
1790: if ($role =~ /^cr\//) {
1791: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
1792: } else {
1793: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
1794: }
1.262 raeburn 1795: }
1796: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1797: @{$courseroles->{'st'}} = ();
1.350 raeburn 1798: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262 raeburn 1799: if (keys(%sections_count) > 0) {
1800: push(@{$courseroles->{'st'}},keys(%sections_count));
1.350 raeburn 1801: $seccount->{'st'} = scalar(keys(%sections_count));
1.262 raeburn 1802: }
1803: my $rolehash = {
1804: 'roles' => $courseroles,
1805: 'seccount' => $seccount,
1.350 raeburn 1806: 'privs' => $courseprivs,
1.262 raeburn 1807: };
1808: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1809: return;
1810: }
1811:
1.235 raeburn 1812: sub jump_to_role {
1.350 raeburn 1813: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
1.239 raeburn 1814: my %lt = &Apache::lonlocal::texthash(
1815: this => 'This role has section(s) associated with it.',
1816: ente => 'Enter a specific section.',
1817: orlb => 'Enter a specific section, or leave blank for no section.',
1818: avai => 'Available sections are:',
1819: youe => 'You entered an invalid section choice:',
1.352 raeburn 1820: plst => 'Please try again.',
1.350 raeburn 1821: role => 'The role you selected is not permitted to view the current page.',
1822: swit => 'Switch role, but display Main Menu page instead?',
1.239 raeburn 1823: );
1824: my $js;
1825: if (ref($courseroles) eq 'HASH') {
1826: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1827: ' var numsec = new Array();'."\n".
1828: ' var rolesections = new Array();'."\n".
1829: ' var rolenames = new Array();'."\n".
1830: ' var roleseclist = new Array();'."\n";
1831: my @items = keys(%{$courseroles});
1832: for (my $i=0; $i<@items; $i++) {
1833: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1834: my ($secs,$secstr);
1835: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1836: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1837: $secs = join('","',@sections);
1838: $secstr = join(', ',@sections);
1839: }
1840: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1841: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1842: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1843: }
1844: }
1.350 raeburn 1845: my $checkroles = 0;
1846: if ($priv && ref($courseprivs) eq 'HASH') {
1847: my (%disallowed,%allowed,@disallow);
1848: foreach my $role (sort(keys(%{$courseprivs}))) {
1849: my $trole;
1850: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
1851: $trole = $1;
1852: }
1853: if (($trole ne '') && ($trole ne 'cm')) {
1854: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
1855: $allowed{$trole} = 1;
1856: } else {
1857: $disallowed{$trole} = 1;
1858: }
1859: }
1860: }
1861: foreach my $trole (keys(%disallowed)) {
1862: unless ($allowed{$trole}) {
1863: push(@disallow,$trole);
1864: }
1865: }
1866: if (@disallow > 0) {
1867: $checkroles = 1;
1868: $js .= " var disallow = new Array('".join("','",@disallow)."');\n".
1869: " var rolecheck = 1;\n";
1870: }
1871: }
1872: if (!$checkroles) {
1873: $js .= " var disallow = new Array();\n".
1874: " rolecheck = 0;\n";
1875: }
1.273 droeschl 1876: return <<"END";
1.235 raeburn 1877: <script type="text/javascript">
1.273 droeschl 1878: //<![CDATA[
1.401 raeburn 1879: function adhocRole(newrole) {
1.239 raeburn 1880: $js
1.235 raeburn 1881: if (newrole == '') {
1.350 raeburn 1882: return;
1.235 raeburn 1883: }
1.239 raeburn 1884: var fullrole = newrole+'./$cdom/$cnum';
1885: var selidx = '';
1886: for (var i=0; i<rolenames.length; i++) {
1887: if (rolenames[i] == newrole) {
1888: selidx = i;
1889: }
1890: }
1.350 raeburn 1891: if (rolecheck > 0) {
1892: for (var i=0; i<disallow.length; i++) {
1893: if (disallow[i] == newrole) {
1894: if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
1895: document.rolechooser.destinationurl.value = '/adm/menu';
1896: } else {
1897: return;
1898: }
1899: }
1900: }
1901: }
1.239 raeburn 1902: var secok = 1;
1903: var secchoice = '';
1904: if (selidx >= 0) {
1905: if (numsec[selidx] > 1) {
1906: secok = 0;
1907: var numrolesec = rolesections[selidx].length;
1908: var msgidx = numsec[selidx] - numrolesec;
1.339 raeburn 1909: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239 raeburn 1910: if (secchoice == '') {
1911: if (msgidx > 0) {
1912: secok = 1;
1913: }
1914: } else {
1915: for (var j=0; j<rolesections[selidx].length; j++) {
1916: if (rolesections[selidx][j] == secchoice) {
1917: secok = 1;
1918: }
1919: }
1920: }
1921: } else {
1922: if (rolesections[selidx].length == 1) {
1923: secchoice = rolesections[selidx][0];
1924: }
1925: }
1926: }
1927: if (secok == 1) {
1928: if (secchoice != '') {
1929: fullrole += '/'+secchoice;
1930: }
1931: } else {
1932: if (secchoice != null) {
1933: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
1934: }
1935: return;
1936: }
1937: if (fullrole == "$env{'request.role'}") {
1.235 raeburn 1938: return;
1939: }
1940: itemid = retrieveIndex('gotorole');
1941: if (itemid != -1) {
1.239 raeburn 1942: document.rolechooser.elements[itemid].name = fullrole;
1.235 raeburn 1943: }
1.401 raeburn 1944: document.rolechooser.switchrole.value = fullrole;
1.235 raeburn 1945: document.rolechooser.selectrole.value = '1';
1946: document.rolechooser.submit();
1947: return;
1948: }
1949:
1950: function retrieveIndex(item) {
1951: for (var i=0;i<document.rolechooser.elements.length;i++) {
1952: if (document.rolechooser.elements[i].name == item) {
1953: return i;
1954: }
1955: }
1956: return -1;
1957: }
1.273 droeschl 1958: // ]]>
1.235 raeburn 1959: </script>
1960: END
1961: }
1962:
1.350 raeburn 1963: sub required_privs {
1964: my $privs = {
1965: '/adm/parmset' => 'opa',
1966: '/adm/courseprefs' => 'opa',
1967: '/adm/whatsnew' => 'whn',
1968: '/adm/populate' => 'cst',
1969: '/adm/trackstudent' => 'vsa',
1970: '/adm/statistics' => 'vgr',
1.366 raeburn 1971: '/adm/setblock' => 'dcm',
1.367 raeburn 1972: '/adm/coursedocs' => 'mdc',
1.350 raeburn 1973: };
1974: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364 raeburn 1975: $privs->{'/adm/classcalc'} = 'vgr',
1976: $privs->{'/adm/assesscalc'} = 'vgr',
1977: $privs->{'/adm/studentcalc'} = 'vgr';
1.350 raeburn 1978: }
1979: return $privs;
1980: }
1.235 raeburn 1981:
1.378 raeburn 1982: sub countdown_timer {
1983: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.387 raeburn 1984: ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
1985: my ($type,$hastimeleft,$slothastime);
1986: my $now = time;
1987: if ($env{'request.filename'} =~ /\.task$/) {
1988: $type = 'Task';
1989: } else {
1990: $type = 'problem';
1991: }
1992: my ($status,$accessmsg,$slot_name,$slot) =
1993: &Apache::lonhomework::check_slot_access('0',$type);
1994: if ($slot_name ne '') {
1995: if (ref($slot) eq 'HASH') {
1996: if (($slot->{'starttime'} < $now) &&
1997: ($slot->{'endtime'} > $now)) {
1998: $slothastime = 1;
1999: }
2000: }
2001: }
2002: if ($status ne 'CAN_ANSWER') {
2003: return;
2004: }
1.378 raeburn 2005: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.380 raeburn 2006: my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.381 raeburn 2007: my $hastimeleft;
2008: if (@interval > 1) {
2009: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
2010: if ($first_access > 0) {
2011: if ($first_access+$interval[0] > time) {
2012: $hastimeleft = 1;
2013: }
2014: }
2015: }
1.380 raeburn 2016: if (($duedate && $duedate > time) ||
1.387 raeburn 2017: (!$duedate && $hastimeleft) ||
2018: ($slot_name ne '' && $slothastime)) {
1.379 raeburn 2019: my ($collapse,$expand,$alttxt,$title,$currdisp);
1.387 raeburn 2020: if ((@interval > 1 && $hastimeleft) ||
2021: ($type eq 'Task' && $slothastime)) {
1.378 raeburn 2022: $currdisp = 'inline';
2023: $collapse = '► ';
2024: } else {
2025: $currdisp = 'none';
2026: $expand = '◄ ';
2027: }
2028: unless ($env{'environment.icons'} eq 'iconsonly') {
1.379 raeburn 2029: $alttxt = &mt('Timer');
2030: $title = $alttxt.' ';
1.378 raeburn 2031: }
2032: my $desc = &mt('Countdown to due date/time');
2033: return <<END;
2034:
2035: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
2036: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
2037: $collapse
1.379 raeburn 2038: </span></a>
1.378 raeburn 2039: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
2040: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
2041: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.379 raeburn 2042: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
1.378 raeburn 2043: END
2044: }
2045: }
2046: return;
2047: }
2048:
1.2 www 2049: # ================================================================ Main Program
2050:
1.16 harris41 2051: BEGIN {
1.166 albertel 2052: if (! defined($readdesk)) {
1.283 droeschl 2053: {
2054: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
2055: if ( CORE::open( my $config,"<$tabfile") ) {
2056: while (my $configline=<$config>) {
2057: $configline=(split(/\#/,$configline))[0];
2058: $configline=~s/^\s+//;
2059: chomp($configline);
1.209 www 2060: if ($configline=~/^cat\:/) {
1.283 droeschl 2061: my @entries=split(/\:/,$configline);
2062: $category_positions{$entries[2]}=$entries[1];
2063: $category_names{$entries[2]}=$entries[3];
2064: } elsif ($configline=~/^prim\:/) {
2065: my @entries = (split(/\:/, $configline))[1..5];
1.400 raeburn 2066: push(@primary_menu,\@entries);
1.371 raeburn 2067: } elsif ($configline=~/^primsub\:/) {
2068: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.400 raeburn 2069: push(@{$primary_submenu{$parent}},\@entries);
1.283 droeschl 2070: } elsif ($configline=~/^scnd\:/) {
2071: my @entries = (split(/\:/, $configline))[1..5];
1.401 raeburn 2072: push(@secondary_menu,\@entries);
1.283 droeschl 2073: } elsif ($configline) {
2074: push(@desklines,$configline);
2075: }
2076: }
2077: CORE::close($config);
2078: }
2079: }
2080: $readdesk='done';
1.2 www 2081: }
2082: }
1.30 www 2083:
1.1 www 2084: 1;
2085: __END__
2086:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>