Annotation of loncom/interface/lonmenu.pm, revision 1.369.2.83.4.1
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.369.2.83.4. (raeburn 4:): # $Id: lonmenu.pm,v 1.369.2.83 2021/12/13 23:26:32 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.369.2.83.4. (raeburn 2228:): # This creates a "done button" for timed events. The confirmation box is a jQuery
2229:): # dialog widget. If the interval parameter requires a proctor key for the timed
2230:): # event to be marked done, there will also be a textbox where that can be entered.
2231:): # Clicking OK will set the value of LC_interval_done to 'true', and, if needed will
2232:): # set the value of LC_interval_done_proctorpass to the text entered in that box,
2233:): # and submit the corresponding form.
2234:): #
2235:): # The &zero_time() routine in lonhomework.pm is called when a page is rendered if
2236:): # LC_interval_done is true.
2237:): #
2238:): sub done_button_js {
2239:): my ($type,$width,$height,$proctor,$donebuttontext) = @_;
2240:): return unless (($type eq 'map') || ($type eq 'resource'));
2241:): my %lt = &Apache::lonlocal::texthash(
2242:): title => 'WARNING!',
2243:): preamble => 'You are trying to end this timed event early.',
2244:): map => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
2245:): resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
2246:): okdone => 'Click "OK" if you are completely finished.',
2247:): cancel => 'Click "Cancel" to continue working.',
2248:): proctor => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
2249:): ok => 'OK',
2250:): exit => 'Cancel',
2251:): key => 'Key:',
2252:): nokey => 'A proctor key is required',
2253:): );
2254:): my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
2255:): my $navmap = Apache::lonnavmaps::navmap->new();
2256:): my ($missing,$tried) = (0,0);
2257:): if (ref($navmap)) {
2258:): my @resources=();
2259:): if ($type eq 'map') {
2260:): my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
2261:): if ($env{'request.symb'} =~ /\.page$/) {
2262:): @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
2263:): } else {
2264:): @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
2265:): }
2266:): } else {
2267:): my $res = $navmap->getBySymb($env{'request.symb'});
2268:): if (ref($res)) {
2269:): if ($res->is_problem()) {
2270:): push(@resources,$res);
2271:): }
2272:): }
2273:): }
2274:): foreach my $res (@resources) {
2275:): if (ref($res->parts()) eq 'ARRAY') {
2276:): foreach my $part (@{$res->parts()}) {
2277:): if (!$res->tries($part)) {
2278:): $missing++;
2279:): } else {
2280:): $tried++;
2281:): }
2282:): }
2283:): }
2284:): }
2285:): }
2286:): if ($missing) {
2287:): $lt{'miss'} .= '<p class="LC_error">';
2288:): if ($type eq 'map') {
2289:): $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
2290:): } else {
2291:): $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
2292:): }
2293:): if ($missing > 1) {
2294:): $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
2295:): } else {
2296:): $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
2297:): }
2298:): }
2299:): $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
2300:): if ($proctor) {
2301:): if ($height !~ /^\d+$/) {
2302:): $height = 400;
2303:): if ($missing) {
2304:): $height += 60;
2305:): }
2306:): }
2307:): if ($width !~ /^\d+$/) {
2308:): $width = 400;
2309:): if ($missing) {
2310:): $width += 60;
2311:): }
2312:): }
2313:): return <<END;
2314:): <form method="post" name="LCdoneButton" action="">
2315:): <input type="hidden" name="LC_interval_done" value="" />
2316:): <input type="hidden" name="LC_interval_done_proctorpass" value="" />
2317:): <input type="hidden" name="symb" value="$shownsymb" />
2318:): <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
2319:): </form>
2320:):
2321:): <div id="LC_done-confirm" title="$lt{'title'}">
2322:): <p>$lt{'preamble'} $lt{$type}</p>
2323:): $lt{'miss'}
2324:): <p>$lt{'proctor'}</p>
2325:): <form name="LCdoneButtonProctor" action="">
2326:): <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
2327:): <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
2328:): </form>
2329:): <p>$lt{'cancel'}</p>
2330:): </div>
2331:):
2332:): <script type="text/javascript">
2333:): // <![CDATA[
2334:): \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
2335:): \$( "#LC_done-confirm-opener" ).on("click", function() {
2336:): \$( "#LC_done-confirm" ).dialog("open");
2337:): \$( "#LC_done-confirm" ).dialog({
2338:): height: $height,
2339:): width: $width,
2340:): modal: true,
2341:): resizable: false,
2342:): buttons: [
2343:): {
2344:): text: "$lt{'ok'}",
2345:): click: function() {
2346:): var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
2347:): if ((proctorkey == '') || (proctorkey == null)) {
2348:): alert("$lt{'nokey'}");
2349:): } else {
2350:): \$( '[name="LC_interval_done"]' )[0].value = 'true';
2351:): \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
2352:): \$( '[name="LCdoneButton"]' )[0].submit();
2353:): }
2354:): },
2355:): },
2356:): {
2357:): text: "$lt{'exit'}",
2358:): click: function() {
2359:): \$("#LC_done-confirm").dialog( "close" );
2360:): }
2361:): }
2362:): ],
2363:): close: function() {
2364:): \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
2365:): }
2366:): });
2367:): \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
2368:): event.preventDefault();
2369:): \$( '[name="LC_interval_done"]' )[0].value = 'true';
2370:): \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
2371:): \$( '[name="LCdoneButton"]' )[0].submit();
2372:): });
2373:): });
2374:):
2375:): // ]]>
2376:): </script>
2377:):
2378:): END
2379:): } else {
2380:): if ($height !~ /^\d+$/) {
2381:): $height = 320;
2382:): if ($missing) {
2383:): $height += 60;
2384:): }
2385:): }
2386:): if ($width !~ /^\d+$/) {
2387:): $width = 320;
2388:): if ($missing) {
2389:): $width += 60;
2390:): }
2391:): }
2392:): if ($missing) {
2393:): $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
2394:): }
2395:): return <<END;
2396:):
2397:): <form method="post" name="LCdoneButton" action="">
2398:): <input type="hidden" name="LC_interval_done" value="" />
2399:): <input type="hidden" name="symb" value="$shownsymb" />
2400:): <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
2401:): </form>
2402:):
2403:): <div id="LC_done-confirm" title="$lt{'title'}">
2404:): <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
2405:): </div>
2406:):
2407:): <script type="text/javascript">
2408:): // <![CDATA[
2409:): \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
2410:): \$( "#LC_done-confirm-opener" ).click(function() {
2411:): \$( "#LC_done-confirm" ).dialog( "open" );
2412:): \$( "#LC_done-confirm" ).dialog({
2413:): resizable: false,
2414:): height: $height,
2415:): width: $width,
2416:): modal: true,
2417:): buttons: [
2418:): {
2419:): text: "$lt{'ok'}",
2420:): click: function() {
2421:): \$( this ).dialog( "close" );
2422:): \$( '[name="LC_interval_done"]' )[0].value = 'true';
2423:): \$( '[name="LCdoneButton"]' )[0].submit();
2424:): },
2425:): },
2426:): {
2427:): text: "$lt{'exit'}",
2428:): click: function() {
2429:): \$( this ).dialog( "close" );
2430:): },
2431:): },
2432:): ],
2433:): });
2434:): });
2435:): // ]]>
2436:): </script>
2437:):
2438:): END
2439:): }
2440:): }
2441:):
1.42 www 2442: sub utilityfunctions {
1.369.2.47 raeburn 2443: my ($httphost) = @_;
1.152 albertel 2444: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.369.2.75 raeburn 2445: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
2446: if ($currenturl =~ m{^/adm/wrapper/ext/}) {
2447: if ($env{'request.external.querystring'}) {
1.293 raeburn 2448: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1.369.2.75 raeburn 2449: }
2450: my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
2451: if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
2452: $currenturl .= $1;
2453: }
1.293 raeburn 2454: }
1.183 www 2455: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125 albertel 2456:
1.306 raeburn 2457: my $dc_popup_cid;
2458: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
2459: $env{'course.'.$env{'request.course.id'}.
2460: '.domain'}.'/'})) {
2461: $dc_popup_cid = &dc_popup_js();
2462: }
2463:
1.175 albertel 2464: my $start_page_annotate =
2465: &Apache::loncommon::start_page('Annotator',undef,
2466: {'only_body' => 1,
2467: 'js_ready' => 1,
2468: 'bgcolor' => '#BBBBBB',
2469: 'add_entries' => {
2470: 'onload' => 'javascript:document.goannotate.submit();'}});
2471:
1.205 albertel 2472: my $end_page_annotate =
2473: &Apache::loncommon::end_page({'js_ready' => 1});
2474:
1.369.2.26 raeburn 2475: my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336 raeburn 2476:
1.368 www 2477: my $esc_url=&escape($currenturl);
2478: my $esc_symb=&escape($currentsymb);
1.332 wenzelju 2479:
1.369.2.10 raeburn 2480: my $countdown = &countdown_toggle_js();
2481:
1.369.2.75 raeburn 2482: my $annotateurl = '/adm/annotation';
2483: if ($httphost) {
2484: $annotateurl = '/adm/annotations';
2485: }
1.369.2.53 raeburn 2486: my $hostvar = '
2487: function setLCHost() {
2488: var lcHostname="";
2489: ';
2490: if ($httphost =~ m{^https?\://}) {
2491: $hostvar .= ' var lcServer="'.$httphost.'";'."\n".
2492: ' var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
2493: ' var match = hostReg.exec(lcServer);'."\n".
2494: ' if (match.length) {'."\n".
2495: ' if (match[1] == location.hostname) {'."\n".
2496: ' lcHostname=lcServer;'."\n".
2497: ' }'."\n".
2498: ' }'."\n";
2499: }
2500:
2501: $hostvar .= ' return lcHostname;'."\n".
2502: '}'."\n";
2503:
1.42 www 2504: return (<<ENDUTILITY)
1.369.2.53 raeburn 2505: $hostvar
1.368 www 2506: var currentURL=unescape("$esc_url");
2507: var reloadURL=unescape("$esc_url");
2508: var currentSymb=unescape("$esc_symb");
1.42 www 2509:
1.306 raeburn 2510: $dc_popup_cid
1.114 albertel 2511:
1.369.2.26 raeburn 2512: $jumptores
1.336 raeburn 2513:
1.42 www 2514: function gopost(url,postdata) {
2515: if (url!='') {
1.369.2.53 raeburn 2516: var lcHostname = setLCHost();
2517: this.document.server.action=lcHostname+url;
1.42 www 2518: this.document.server.postdata.value=postdata;
2519: this.document.server.command.value='';
2520: this.document.server.url.value='';
2521: this.document.server.symb.value='';
2522: this.document.server.submit();
2523: }
2524: }
2525:
2526: function gocmd(url,cmd) {
2527: if (url!='') {
1.369.2.53 raeburn 2528: var lcHostname = setLCHost();
2529: this.document.server.action=lcHostname+url;
1.42 www 2530: this.document.server.postdata.value='';
2531: this.document.server.command.value=cmd;
2532: this.document.server.url.value=currentURL;
2533: this.document.server.symb.value=currentSymb;
2534: this.document.server.submit();
2535: }
1.57 www 2536: }
2537:
1.121 raeburn 2538: function gocstr(url,filename) {
2539: if (url == '/adm/cfile?action=delete') {
2540: this.document.cstrdelete.filename.value = filename
2541: this.document.cstrdelete.submit();
2542: return;
2543: }
1.137 raeburn 2544: if (url == '/adm/printout') {
2545: this.document.cstrprint.postdata.value = filename
2546: this.document.cstrprint.curseed.value = 0;
2547: this.document.cstrprint.problemtype.value = 0;
1.138 raeburn 2548: if (this.document.lonhomework) {
2549: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
2550: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
2551: }
2552: if (this.document.lonhomework.problemtype) {
1.164 albertel 2553: if (this.document.lonhomework.problemtype.value) {
2554: this.document.cstrprint.problemtype.value =
2555: this.document.lonhomework.problemtype.value;
2556: } else if (this.document.lonhomework.problemtype.options) {
2557: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
2558: if (this.document.lonhomework.problemtype.options[i].selected) {
2559: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
2560: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
2561: }
2562: }
2563: }
2564: }
2565: }
2566: }
1.137 raeburn 2567: this.document.cstrprint.submit();
2568: return;
2569: }
1.121 raeburn 2570: if (url !='') {
2571: this.document.constspace.filename.value = filename;
2572: this.document.constspace.action = url;
2573: this.document.constspace.submit();
2574: }
2575: }
2576:
1.131 raeburn 2577: function golist(url) {
2578: if (url!='' && url!= null) {
2579: currentURL = null;
2580: currentSymb= null;
1.369.2.53 raeburn 2581: var lcHostname = setLCHost();
2582: top.location.href=lcHostname+url;
1.131 raeburn 2583: }
2584: }
2585:
2586:
1.121 raeburn 2587:
1.369.2.52 raeburn 2588: function catalog_info(isMobile) {
2589: if (isMobile == 1) {
2590: openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
2591: } else {
2592: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
2593: }
1.57 www 2594: }
2595:
2596: function chat_win() {
1.369.2.53 raeburn 2597: var lcHostname = setLCHost();
2598: 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 2599: }
1.169 raeburn 2600:
2601: function group_chat(group) {
1.369.2.53 raeburn 2602: var lcHostname = setLCHost();
2603: var url = lcHostname+'/adm/groupchat?group='+group;
1.169 raeburn 2604: var winName = 'LONchat_'+group;
2605: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
2606: }
1.175 albertel 2607:
2608: function annotate() {
2609: w_Annotator_flag=1;
2610: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
2611: annotator.document.write(
2612: '$start_page_annotate'
2613: +"<form name='goannotate' target='Annotator' method='post' "
1.369.2.75 raeburn 2614: +"action='$annotateurl'>"
1.217 albertel 2615: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181 albertel 2616: +"<\\/form>"
1.205 albertel 2617: +'$end_page_annotate');
1.175 albertel 2618: annotator.document.close();
2619: }
2620:
1.369.2.8 raeburn 2621: function open_StoredLinks_Import(rat) {
2622: var newWin;
1.369.2.53 raeburn 2623: var lcHostname = setLCHost();
1.369.2.8 raeburn 2624: if (rat) {
1.369.2.53 raeburn 2625: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.369.2.8 raeburn 2626: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
2627: }
2628: else {
1.369.2.53 raeburn 2629: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
1.369.2.8 raeburn 2630: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
2631: }
2632: newWin.focus();
2633: }
2634:
1.369.2.79 raeburn 2635: function open_source() {
2636: sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
2637: 'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
2638: }
2639:
1.369.2.4 raeburn 2640: (function (\$) {
2641: \$(document).ready(function () {
2642: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
2643: /*\@cc_on
2644: if (!window.XMLHttpRequest) {
2645: \$('.LC_hoverable').each(function () {
2646: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
2647: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
2648: });
2649: }
2650: \@*/
2651: });
2652: }(jQuery));
2653:
1.369.2.10 raeburn 2654: $countdown
2655:
1.42 www 2656: ENDUTILITY
2657: }
2658:
2659: sub serverform {
2660: return(<<ENDSERVERFORM);
1.181 albertel 2661: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 2662: <input type="hidden" name="postdata" value="none" />
2663: <input type="hidden" name="command" value="none" />
2664: <input type="hidden" name="url" value="none" />
2665: <input type="hidden" name="symb" value="none" />
2666: </form>
2667: ENDSERVERFORM
2668: }
1.113 albertel 2669:
1.121 raeburn 2670: sub constspaceform {
2671: return(<<ENDCONSTSPACEFORM);
1.181 albertel 2672: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121 raeburn 2673: <input type="hidden" name="filename" value="" />
2674: </form>
1.181 albertel 2675: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121 raeburn 2676: <input type="hidden" name="action" value="delete" />
2677: <input type="hidden" name="filename" value="" />
2678: </form>
1.181 albertel 2679: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137 raeburn 2680: <input type="hidden" name="postdata" value="" />
2681: <input type="hidden" name="curseed" value="" />
2682: <input type="hidden" name="problemtype" value="" />
2683: </form>
2684:
1.121 raeburn 2685: ENDCONSTSPACEFORM
2686: }
2687:
1.369.2.17 raeburn 2688: sub get_nav_status {
2689: my $navstatus="swmenu.w_loncapanav_flag=";
2690: if ($env{'environment.remotenavmap'} eq 'on') {
2691: $navstatus.="1";
2692: } else {
2693: $navstatus.="-1";
2694: }
2695: return $navstatus;
2696: }
2697:
1.220 raeburn 2698: sub hidden_button_check {
1.317 droeschl 2699: if ( $env{'request.course.id'} eq ''
2700: || $env{'request.role.adv'} ) {
2701:
1.220 raeburn 2702: return;
2703: }
1.232 raeburn 2704: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
2705: return $buttonshide;
1.220 raeburn 2706: }
1.184 raeburn 2707:
1.235 raeburn 2708: sub roles_selector {
1.369.2.47 raeburn 2709: my ($cdom,$cnum,$httphost) = @_;
1.298 raeburn 2710: my $crstype = &Apache::loncommon::course_type();
1.235 raeburn 2711: my $now = time;
1.369.2.68 raeburn 2712: my (%courseroles,%seccount,%courseprivs,%roledesc);
1.235 raeburn 2713: my $is_cc;
1.369.2.58 raeburn 2714: my ($js,$form,$switcher);
1.298 raeburn 2715: my $ccrole;
2716: if ($crstype eq 'Community') {
2717: $ccrole = 'co';
2718: } else {
2719: $ccrole = 'cc';
1.350 raeburn 2720: }
1.369.2.61 raeburn 2721: my ($privref,$gotsymb,$destsymb);
1.350 raeburn 2722: my $destinationurl = $ENV{'REQUEST_URI'};
1.369.2.75 raeburn 2723: if ($destinationurl =~ /(\?|\&)symb=/) {
1.369.2.23 raeburn 2724: $gotsymb = 1;
2725: } elsif ($destinationurl =~ m{^/enc/}) {
2726: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
1.369.2.75 raeburn 2727: if ($plainurl =~ /(\?|\&)symb=/) {
1.369.2.23 raeburn 2728: $gotsymb = 1;
2729: }
2730: }
2731: unless ($gotsymb) {
2732: $destsymb = &Apache::lonnet::symbread();
2733: if ($destsymb ne '') {
2734: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
2735: }
2736: }
1.350 raeburn 2737: my $reqprivs = &required_privs();
2738: if (ref($reqprivs) eq 'HASH') {
2739: my $destination = $destinationurl;
2740: $destination =~ s/(\?.*)$//;
2741: if (exists($reqprivs->{$destination})) {
1.369.2.61 raeburn 2742: if ($reqprivs->{$destination} =~ /,/) {
2743: @{$privref} = split(/,/,$reqprivs->{$destination});
2744: } else {
2745: $privref = [$reqprivs->{$destination}];
2746: }
1.350 raeburn 2747: }
2748: }
1.298 raeburn 2749: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
2750: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235 raeburn 2751: if ((($start) && ($start<0)) ||
2752: (($end) && ($end<$now)) ||
2753: (($start) && ($now<$start))) {
2754: $is_cc = 0;
2755: } else {
2756: $is_cc = 1;
2757: }
2758: }
2759: if ($is_cc) {
1.369.2.61 raeburn 2760: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
2761: } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
1.369.2.68 raeburn 2762: &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref);
1.235 raeburn 2763: } else {
1.262 raeburn 2764: my %gotnosection;
1.235 raeburn 2765: foreach my $item (keys(%env)) {
1.239 raeburn 2766: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235 raeburn 2767: my $role = $1;
2768: my $sec = $2;
2769: next if ($role eq 'gr');
2770: my ($start,$end) = split(/\./,$env{$item});
2771: next if (($start && $start > $now) || ($end && $end < $now));
2772: if ($sec eq '') {
1.239 raeburn 2773: if (!$gotnosection{$role}) {
2774: $seccount{$role} ++;
2775: $gotnosection{$role} = 1;
2776: }
1.235 raeburn 2777: }
1.369.2.61 raeburn 2778: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
1.350 raeburn 2779: my $cnumsec = $cnum;
2780: if ($sec ne '') {
2781: $cnumsec .= "/$sec";
2782: }
2783: $courseprivs{"$role./$cdom/$cnumsec./"} =
2784: $env{"user.priv.$role./$cdom/$cnumsec./"};
2785: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
2786: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
2787: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
2788: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
2789: }
1.235 raeburn 2790: if (ref($courseroles{$role}) eq 'ARRAY') {
1.239 raeburn 2791: if ($sec ne '') {
1.264 raeburn 2792: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239 raeburn 2793: push(@{$courseroles{$role}},$sec);
2794: $seccount{$role} ++;
2795: }
2796: }
2797: } else {
2798: @{$courseroles{$role}} = ();
2799: if ($sec ne '') {
2800: $seccount{$role} ++;
1.235 raeburn 2801: push(@{$courseroles{$role}},$sec);
2802: }
2803: }
2804: }
2805: }
2806: }
1.298 raeburn 2807: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.369.2.30 raeburn 2808: my $numdiffsec;
2809: if (keys(%seccount) == 1) {
2810: foreach my $key (keys(%seccount)) {
2811: $numdiffsec = $seccount{$key};
2812: }
2813: }
2814: if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
2815: my @submenu;
1.369.2.68 raeburn 2816: $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,\%roledesc,$privref);
1.369.2.30 raeburn 2817: $form =
1.369.2.47 raeburn 2818: '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
1.369.2.30 raeburn 2819: ' <input type="hidden" name="destinationurl" value="'.
2820: &HTML::Entities::encode($destinationurl).'" />'."\n".
2821: ' <input type="hidden" name="gotorole" value="1" />'."\n".
2822: ' <input type="hidden" name="selectrole" value="" />'."\n".
2823: ' <input type="hidden" name="switchrole" value="" />'."\n";
2824: if ($destsymb ne '') {
2825: $form .= ' <input type="hidden" name="destsymb" value="'.
2826: &HTML::Entities::encode($destsymb).'" />'."\n";
2827: }
2828: $form .= '</form>'."\n";
1.235 raeburn 2829: foreach my $role (@roles_order) {
1.369.2.30 raeburn 2830: my $include;
1.235 raeburn 2831: if (defined($courseroles{$role})) {
1.369.2.30 raeburn 2832: if ($env{'request.role'} =~ m{^\Q$role\E}) {
2833: if ($seccount{$role} > 1) {
2834: $include = 1;
2835: }
2836: } else {
2837: $include = 1;
2838: }
2839: }
2840: if ($include) {
2841: push(@submenu,['javascript:adhocRole('."'$role'".')',
2842: &Apache::lonnet::plaintext($role,$crstype)]);
1.235 raeburn 2843: }
2844: }
2845: foreach my $role (sort(keys(%courseroles))) {
2846: if ($role =~ /^cr/) {
1.369.2.30 raeburn 2847: my $include;
2848: if ($env{'request.role'} =~ m{^\Q$role\E}) {
2849: if ($seccount{$role} > 1) {
2850: $include = 1;
2851: }
2852: } else {
2853: $include = 1;
2854: }
2855: if ($include) {
1.369.2.65 raeburn 2856: my $rolename;
2857: if ($role =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)(?:/\w+|$)}) {
1.369.2.68 raeburn 2858: $rolename = $roledesc{$role};
2859: if ($rolename eq '') {
2860: $rolename = &mt('Helpdesk [_1]',$1);
2861: }
1.369.2.65 raeburn 2862: } else {
2863: $rolename = &Apache::lonnet::plaintext($role);
2864: }
1.369.2.30 raeburn 2865: push(@submenu,['javascript:adhocRole('."'$role'".')',
1.369.2.65 raeburn 2866: $rolename]);
1.369.2.30 raeburn 2867: }
1.235 raeburn 2868: }
2869: }
1.369.2.30 raeburn 2870: if (@submenu > 0) {
1.369.2.58 raeburn 2871: $switcher = &create_submenu('','',&mt('Switch role'),\@submenu);
1.369.2.23 raeburn 2872: }
1.235 raeburn 2873: }
1.369.2.30 raeburn 2874: return ($js,$form,$switcher);
1.235 raeburn 2875: }
2876:
1.262 raeburn 2877: sub get_all_courseroles {
1.350 raeburn 2878: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351 raeburn 2879: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350 raeburn 2880: (ref($courseprivs) eq 'HASH')) {
1.262 raeburn 2881: return;
2882: }
2883: my ($result,$cached) =
2884: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
2885: if (defined($cached)) {
2886: if (ref($result) eq 'HASH') {
2887: if ((ref($result->{'roles'}) eq 'HASH') &&
1.350 raeburn 2888: (ref($result->{'seccount'}) eq 'HASH') &&
2889: (ref($result->{'privs'}) eq 'HASH')) {
1.262 raeburn 2890: %{$courseroles} = %{$result->{'roles'}};
2891: %{$seccount} = %{$result->{'seccount'}};
1.350 raeburn 2892: %{$courseprivs} = %{$result->{'privs'}};
1.262 raeburn 2893: return;
2894: }
2895: }
2896: }
2897: my %gotnosection;
2898: my %adv_roles =
2899: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
2900: foreach my $role (keys(%adv_roles)) {
2901: my ($urole,$usec) = split(/:/,$role);
2902: if (!$gotnosection{$urole}) {
2903: $seccount->{$urole} ++;
2904: $gotnosection{$urole} = 1;
2905: }
2906: if (ref($courseroles->{$urole}) eq 'ARRAY') {
2907: if ($usec ne '') {
2908: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
2909: push(@{$courseroles->{$urole}},$usec);
2910: $seccount->{$urole} ++;
2911: }
2912: }
2913: } else {
2914: @{$courseroles->{$urole}} = ();
2915: if ($usec ne '') {
2916: $seccount->{$urole} ++;
2917: push(@{$courseroles->{$urole}},$usec);
2918: }
2919: }
1.350 raeburn 2920: my $area = '/'.$cdom.'/'.$cnum;
2921: if ($usec ne '') {
2922: $area .= '/'.$usec;
2923: }
2924: if ($role =~ /^cr\//) {
2925: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
2926: } else {
2927: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
2928: }
1.262 raeburn 2929: }
2930: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
2931: @{$courseroles->{'st'}} = ();
1.350 raeburn 2932: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262 raeburn 2933: if (keys(%sections_count) > 0) {
2934: push(@{$courseroles->{'st'}},keys(%sections_count));
1.350 raeburn 2935: $seccount->{'st'} = scalar(keys(%sections_count));
1.262 raeburn 2936: }
1.369.2.38 raeburn 2937: $seccount->{'st'} ++; # Increment for a section-less student role.
1.262 raeburn 2938: my $rolehash = {
2939: 'roles' => $courseroles,
2940: 'seccount' => $seccount,
1.350 raeburn 2941: 'privs' => $courseprivs,
1.262 raeburn 2942: };
2943: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
2944: return;
2945: }
2946:
1.369.2.61 raeburn 2947: sub get_customadhoc_roles {
1.369.2.68 raeburn 2948: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_;
1.369.2.61 raeburn 2949: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.369.2.68 raeburn 2950: (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) {
1.369.2.61 raeburn 2951: return;
2952: }
1.369.2.69 raeburn 2953: my $is_helpdesk = 0;
2954: my $now = time;
2955: foreach my $role ('dh','da') {
2956: if ($env{"user.role.$role./$cdom/"}) {
2957: my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"});
2958: if (!($start && ($now<$start)) && !($end && ($now>$end))) {
2959: $is_helpdesk = 1;
2960: last;
2961: }
2962: }
2963: }
2964: if ($is_helpdesk) {
2965: my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum);
2966: my %available;
2967: if (ref($possroles) eq 'ARRAY') {
2968: map { $available{$_} = 1; } @{$possroles};
2969: }
2970: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
2971: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
2972: if (keys(%{$domdefaults{'adhocroles'}})) {
2973: my $numsec = 1;
2974: my @sections;
2975: my ($allseclist,$cached) =
2976: &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
2977: if (defined($cached)) {
2978: if ($allseclist ne '') {
2979: @sections = split(/,/,$allseclist);
1.369.2.68 raeburn 2980: $numsec += scalar(@sections);
1.369.2.61 raeburn 2981: }
1.369.2.69 raeburn 2982: } else {
2983: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2984: @sections = sort(keys(%sections_count));
2985: $numsec += scalar(@sections);
2986: $allseclist = join(',',@sections);
2987: &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
2988: }
2989: my (%adhoc,$gotprivs);
2990: my $prefix = "cr/$cdom/$cdom".'-domainconfig';
2991: foreach my $role (keys(%{$domdefaults{'adhocroles'}})) {
2992: next if (($role eq '') || ($role =~ /\W/));
2993: $seccount->{"$prefix/$role"} = $numsec;
2994: $roledesc->{"$prefix/$role"} = $description->{$role};
2995: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
2996: if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
2997: $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
2998: $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
2999: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
3000: $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
3001: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
3002: $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
3003: } else {
3004: unless ($gotprivs) {
3005: my ($adhocroles,$privscached) =
3006: &Apache::lonnet::is_cached_new('adhocroles',$cdom);
3007: if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
3008: %adhoc = %{$adhocroles};
3009: } else {
3010: my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
3011: my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
3012: foreach my $key (keys(%roledefs)) {
3013: (undef,my $rolename) = split(/_/,$key);
3014: if ($rolename ne '') {
3015: my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key});
3016: $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv);
3017: $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv));
1.369.2.61 raeburn 3018: }
3019: }
1.369.2.69 raeburn 3020: &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
1.369.2.61 raeburn 3021: }
1.369.2.69 raeburn 3022: $gotprivs = 1;
1.369.2.61 raeburn 3023: }
1.369.2.69 raeburn 3024: ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
3025: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
3026: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
3027: split(/\_/,$adhoc{$role});
1.369.2.61 raeburn 3028: }
1.369.2.69 raeburn 3029: }
3030: if ($available{$role}) {
3031: $courseroles->{"$prefix/$role"} = \@sections;
1.369.2.61 raeburn 3032: }
3033: }
3034: }
3035: }
3036: }
3037: return;
3038: }
3039:
1.235 raeburn 3040: sub jump_to_role {
1.369.2.68 raeburn 3041: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref) = @_;
1.239 raeburn 3042: my %lt = &Apache::lonlocal::texthash(
3043: this => 'This role has section(s) associated with it.',
3044: ente => 'Enter a specific section.',
3045: orlb => 'Enter a specific section, or leave blank for no section.',
3046: avai => 'Available sections are:',
3047: youe => 'You entered an invalid section choice:',
1.352 raeburn 3048: plst => 'Please try again.',
1.350 raeburn 3049: role => 'The role you selected is not permitted to view the current page.',
3050: swit => 'Switch role, but display Main Menu page instead?',
1.239 raeburn 3051: );
3052: my $js;
3053: if (ref($courseroles) eq 'HASH') {
3054: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
3055: ' var numsec = new Array();'."\n".
3056: ' var rolesections = new Array();'."\n".
3057: ' var rolenames = new Array();'."\n".
3058: ' var roleseclist = new Array();'."\n";
3059: my @items = keys(%{$courseroles});
3060: for (my $i=0; $i<@items; $i++) {
3061: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
3062: my ($secs,$secstr);
3063: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
3064: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
3065: $secs = join('","',@sections);
3066: $secstr = join(', ',@sections);
3067: }
3068: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
3069: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
3070: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
3071: }
3072: }
1.350 raeburn 3073: my $checkroles = 0;
1.369.2.61 raeburn 3074: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
3075: my %disallowed;
1.350 raeburn 3076: foreach my $role (sort(keys(%{$courseprivs}))) {
3077: my $trole;
3078: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
3079: $trole = $1;
3080: }
3081: if (($trole ne '') && ($trole ne 'cm')) {
1.369.2.61 raeburn 3082: $disallowed{$trole} = 1;
3083: foreach my $priv (@{$privref}) {
3084: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
3085: delete($disallowed{$trole});
3086: last;
3087: }
1.350 raeburn 3088: }
3089: }
3090: }
1.369.2.61 raeburn 3091: if (keys(%disallowed) > 0) {
1.350 raeburn 3092: $checkroles = 1;
1.369.2.61 raeburn 3093: $js .= " var disallow = new Array('".join("','",keys(%disallowed))."');\n".
1.350 raeburn 3094: " var rolecheck = 1;\n";
3095: }
3096: }
3097: if (!$checkroles) {
3098: $js .= " var disallow = new Array();\n".
3099: " rolecheck = 0;\n";
3100: }
1.273 droeschl 3101: return <<"END";
1.235 raeburn 3102: <script type="text/javascript">
1.273 droeschl 3103: //<![CDATA[
1.369.2.30 raeburn 3104: function adhocRole(newrole) {
1.239 raeburn 3105: $js
1.235 raeburn 3106: if (newrole == '') {
1.350 raeburn 3107: return;
1.235 raeburn 3108: }
1.239 raeburn 3109: var fullrole = newrole+'./$cdom/$cnum';
3110: var selidx = '';
3111: for (var i=0; i<rolenames.length; i++) {
3112: if (rolenames[i] == newrole) {
3113: selidx = i;
3114: }
3115: }
1.350 raeburn 3116: if (rolecheck > 0) {
3117: for (var i=0; i<disallow.length; i++) {
3118: if (disallow[i] == newrole) {
3119: if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
3120: document.rolechooser.destinationurl.value = '/adm/menu';
3121: } else {
3122: return;
3123: }
3124: }
3125: }
3126: }
1.239 raeburn 3127: var secok = 1;
3128: var secchoice = '';
3129: if (selidx >= 0) {
3130: if (numsec[selidx] > 1) {
3131: secok = 0;
3132: var numrolesec = rolesections[selidx].length;
3133: var msgidx = numsec[selidx] - numrolesec;
1.339 raeburn 3134: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239 raeburn 3135: if (secchoice == '') {
3136: if (msgidx > 0) {
3137: secok = 1;
3138: }
3139: } else {
3140: for (var j=0; j<rolesections[selidx].length; j++) {
3141: if (rolesections[selidx][j] == secchoice) {
3142: secok = 1;
3143: }
3144: }
3145: }
3146: } else {
3147: if (rolesections[selidx].length == 1) {
3148: secchoice = rolesections[selidx][0];
3149: }
3150: }
3151: }
3152: if (secok == 1) {
3153: if (secchoice != '') {
3154: fullrole += '/'+secchoice;
3155: }
3156: } else {
3157: document.rolechooser.elements[roleitem].selectedIndex = 0;
3158: if (secchoice != null) {
3159: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
3160: }
3161: return;
3162: }
3163: if (fullrole == "$env{'request.role'}") {
1.235 raeburn 3164: return;
3165: }
3166: itemid = retrieveIndex('gotorole');
3167: if (itemid != -1) {
1.239 raeburn 3168: document.rolechooser.elements[itemid].name = fullrole;
1.235 raeburn 3169: }
1.369.2.30 raeburn 3170: document.rolechooser.switchrole.value = fullrole;
1.235 raeburn 3171: document.rolechooser.selectrole.value = '1';
3172: document.rolechooser.submit();
3173: return;
3174: }
3175:
3176: function retrieveIndex(item) {
3177: for (var i=0;i<document.rolechooser.elements.length;i++) {
3178: if (document.rolechooser.elements[i].name == item) {
3179: return i;
3180: }
3181: }
3182: return -1;
3183: }
1.273 droeschl 3184: // ]]>
1.235 raeburn 3185: </script>
3186: END
3187: }
3188:
1.350 raeburn 3189: sub required_privs {
3190: my $privs = {
1.369.2.61 raeburn 3191: '/adm/parmset' => 'opa,vpa',
3192: '/adm/courseprefs' => 'opa,vpa',
1.350 raeburn 3193: '/adm/whatsnew' => 'whn',
1.369.2.65 raeburn 3194: '/adm/populate' => 'cst,vpa,vcl',
1.350 raeburn 3195: '/adm/trackstudent' => 'vsa',
1.369.2.61 raeburn 3196: '/adm/statistics' => 'mgr,vgr',
3197: '/adm/setblock' => 'dcm,vcb',
1.367 raeburn 3198: '/adm/coursedocs' => 'mdc',
1.350 raeburn 3199: };
3200: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364 raeburn 3201: $privs->{'/adm/classcalc'} = 'vgr',
3202: $privs->{'/adm/assesscalc'} = 'vgr',
3203: $privs->{'/adm/studentcalc'} = 'vgr';
1.350 raeburn 3204: }
3205: return $privs;
3206: }
1.235 raeburn 3207:
1.369.2.10 raeburn 3208: sub countdown_timer {
3209: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.369.2.24 raeburn 3210: ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
3211: my ($type,$hastimeleft,$slothastime);
3212: my $now = time;
3213: if ($env{'request.filename'} =~ /\.task$/) {
3214: $type = 'Task';
3215: } else {
3216: $type = 'problem';
3217: }
3218: my ($status,$accessmsg,$slot_name,$slot) =
3219: &Apache::lonhomework::check_slot_access('0',$type);
3220: if ($slot_name ne '') {
3221: if (ref($slot) eq 'HASH') {
3222: if (($slot->{'starttime'} < $now) &&
3223: ($slot->{'endtime'} > $now)) {
3224: $slothastime = 1;
3225: }
3226: }
3227: }
3228: if ($status ne 'CAN_ANSWER') {
3229: return;
3230: }
1.369.2.10 raeburn 3231: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.369.2.12 raeburn 3232: my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.369.2.83.4. (raeburn 3233:): my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
1.369.2.13 raeburn 3234: if (@interval > 1) {
1.369.2.83.4. (raeburn 3235:): ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
3236:): if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
3237:): $usesdone = 'done';
3238:): $donebuttontext = $1;
3239:): (undef,$proctor,$secret) = split(/_/,$2);
3240:): } elsif ($donesuffix =~ /^done(|_.+)$/) {
3241:): $donebuttontext = &mt('Done');
3242:): ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
3243:): }
1.369.2.13 raeburn 3244: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
3245: if ($first_access > 0) {
1.369.2.83.4. (raeburn 3246:): if ($first_access+$timelimit > time) {
1.369.2.13 raeburn 3247: $hastimeleft = 1;
3248: }
3249: }
3250: }
1.369.2.12 raeburn 3251: if (($duedate && $duedate > time) ||
1.369.2.24 raeburn 3252: (!$duedate && $hastimeleft) ||
3253: ($slot_name ne '' && $slothastime)) {
1.369.2.83.4. (raeburn 3254:): my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
1.369.2.24 raeburn 3255: if ((@interval > 1 && $hastimeleft) ||
3256: ($type eq 'Task' && $slothastime)) {
1.369.2.10 raeburn 3257: $currdisp = 'inline';
3258: $collapse = '► ';
1.369.2.83.4. (raeburn 3259:): if ((@interval > 1) && ($hastimeleft)) {
3260:): if ($usesdone eq 'done') {
3261:): $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
3262:): }
3263:): }
1.369.2.10 raeburn 3264: } else {
3265: $currdisp = 'none';
3266: $expand = '◄ ';
3267: }
3268: unless ($env{'environment.icons'} eq 'iconsonly') {
1.369.2.11 raeburn 3269: $alttxt = &mt('Timer');
3270: $title = $alttxt.' ';
1.369.2.10 raeburn 3271: }
3272: my $desc = &mt('Countdown to due date/time');
3273: return <<END;
1.369.2.83.4. (raeburn 3274:): $donebutton
1.369.2.10 raeburn 3275: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
3276: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
3277: $collapse
1.369.2.11 raeburn 3278: </span></a>
1.369.2.10 raeburn 3279: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
3280: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
3281: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.369.2.11 raeburn 3282: <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 3283: END
3284: }
3285: }
3286: return;
3287: }
3288:
1.2 www 3289: # ================================================================ Main Program
3290:
1.16 harris41 3291: BEGIN {
1.166 albertel 3292: if (! defined($readdesk)) {
1.283 droeschl 3293: {
3294: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
3295: if ( CORE::open( my $config,"<$tabfile") ) {
3296: while (my $configline=<$config>) {
3297: $configline=(split(/\#/,$configline))[0];
3298: $configline=~s/^\s+//;
3299: chomp($configline);
1.209 www 3300: if ($configline=~/^cat\:/) {
1.283 droeschl 3301: my @entries=split(/\:/,$configline);
3302: $category_positions{$entries[2]}=$entries[1];
3303: $category_names{$entries[2]}=$entries[3];
3304: } elsif ($configline=~/^prim\:/) {
1.369.2.42 raeburn 3305: my @entries = (split(/\:/, $configline))[1..6];
1.369.2.30 raeburn 3306: push(@primary_menu,\@entries);
1.369.2.3 raeburn 3307: } elsif ($configline=~/^primsub\:/) {
3308: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.369.2.30 raeburn 3309: push(@{$primary_submenu{$parent}},\@entries);
1.283 droeschl 3310: } elsif ($configline=~/^scnd\:/) {
3311: my @entries = (split(/\:/, $configline))[1..5];
1.369.2.30 raeburn 3312: push(@secondary_menu,\@entries);
1.369.2.5 raeburn 3313: } elsif ($configline=~/^scndsub\:/) {
3314: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.369.2.30 raeburn 3315: push(@{$secondary_submenu{$parent}},\@entries);
1.283 droeschl 3316: } elsif ($configline) {
3317: push(@desklines,$configline);
3318: }
3319: }
3320: CORE::close($config);
3321: }
3322: }
3323: $readdesk='done';
1.2 www 3324: }
3325: }
1.30 www 3326:
1.1 www 3327: 1;
3328: __END__
3329:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>