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