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