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