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