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