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