Annotation of loncom/interface/lonmenu.pm, revision 1.315.2.1
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.315.2.1! raeburn 4: # $Id: lonmenu.pm,v 1.315 2010/03/03 21:33:15 droeschl 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: #
1.269 droeschl 29: # There is one parameter controlling the action of this module:
1.48 www 30: #
31: # environment.remote - if this is 'on', the routines controll the remote
1.269 droeschl 32: # control, otherwise they render the main window controls;
1.1 www 33:
1.244 jms 34: =head1 NAME
35:
36: Apache::lonmenu
37:
38: =head1 SYNOPSIS
39:
40: Coordinates the response to clicking an image.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
1.314 droeschl 45: =head1 GLOBAL VARIABLES
46:
47: =over
48:
49: =item @desklines
50:
51: Each element of this array contains a line of mydesk.tab that doesn't start with
52: cat, prim or scnd.
53: It gets filled in the BEGIN block of this module.
54:
55: =item %category_names
56:
57: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
58: start with cat, the values are strings representing titles.
59: It gets filled in the BEGIN block of this module.
60:
61: =item %category_members
62:
63: TODO
64:
65: =item %category_positions
66:
67: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
68: start with cat, its values are position vectors (column, row).
69: It gets filled in the BEGIN block of this module.
70:
71: =item $readdesk
72:
73: Indicates that mydesk.tab has been read.
74: It is set to 'done' in the BEGIN block of this module.
75:
76: =item @primary_menu
77:
78: The elements of this array reference arrays that are made up of the components
79: of those lines of mydesk.tab that start with prim.
80: It is used by primary_menu() to generate the corresponding menu.
81: It gets filled in the BEGIN block of this module.
82:
83: =item @secondary_menu
84:
85: The elements of this array reference arrays that are made up of the components
86: of those lines of mydesk.tab that start with scnd.
87: It is used by secondary_menu() to generate the corresponding menu.
88: It gets filled in the BEGIN block of this module.
89:
90: =back
91:
1.244 jms 92: =head1 SUBROUTINES
93:
94: =over
95:
1.314 droeschl 96: =item prep_menuitems(\@menuitem)
97:
98: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
99: secondary_menu().
100:
101: =item primary_menu()
102:
103: This routine evaluates @primary_menu and returns XHTML for the menu
104: that contains following links: About, Message, Roles, Help, Logout
105: @primary_menu is filled within the BEGIN block of this module with
106: entries from mydesk.tab
107:
108: =item secondary_menu()
109:
110: Same as primary_menu() but operates on @secondary_menu.
111:
1.244 jms 112: =item show_return_link()
113:
114: =item registerurl()
115:
116: This gets called in the header section
117:
118: =item innerregister()
119:
120: This gets called in order to register a URL, both with the Remote
121: and in the body of the document
122:
123: =item loadevents()
124:
125: =item unloadevents()
126:
127: =item startupremote()
128:
129: =item setflags()
130:
131: =item maincall()
132:
133: =item load_remote_msg()
134:
135: =item get_menu_name()
136:
137: =item reopenmenu()
138:
139: =item open()
140:
141: Open the menu
142:
143: =item clear()
144:
145: =item switch()
146:
147: Switch a button or create a link
148: Switch acts on the javascript that is executed when a button is clicked.
149: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
150:
151: =item secondlevel()
152:
153: =item openmenu()
154:
155: =item inlinemenu()
156:
157: =item rawconfig()
158:
159: =item close()
160:
161: =item footer()
162:
163: =item utilityfunctions()
164:
165: =item serverform()
166:
167: =item constspaceform()
168:
169: =item get_nav_status()
170:
171: =item hidden_button_check()
172:
173: =item roles_selector()
174:
175: =item jump_to_role()
176:
177: =back
178:
179: =cut
180:
1.1 www 181: package Apache::lonmenu;
182:
183: use strict;
1.152 albertel 184: use Apache::lonnet;
1.47 matthew 185: use Apache::lonhtmlcommon();
1.115 albertel 186: use Apache::loncommon();
1.127 albertel 187: use Apache::lonenc();
1.88 www 188: use Apache::lonlocal;
1.207 foxr 189: use LONCAPA qw(:DEFAULT :match);
1.282 amueller 190: use HTML::Entities();
1.88 www 191:
1.283 droeschl 192: use vars qw(@desklines %category_names %category_members %category_positions
193: $readdesk @primary_menu @secondary_menu);
1.88 www 194:
1.56 www 195: my @inlineremote;
1.38 www 196:
1.283 droeschl 197: sub prep_menuitem {
1.291 raeburn 198: my ($menuitem) = @_;
199: return '' unless(ref($menuitem) eq 'ARRAY');
1.283 droeschl 200: my $link;
201: if ($$menuitem[1]) { # graphical Link
202: $link = "<img class=\"LC_noBorder\""
1.291 raeburn 203: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
204: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283 droeschl 205: } else { # textual Link
1.291 raeburn 206: $link = &mt($$menuitem[3]);
207: }
1.310 wenzelju 208: if($$menuitem[4] eq 'newmsg'){ #special style for New Messages
209: return '<li><a href="'.$$menuitem[0].'"><span class="LC_new_message">'.$link.'</span></a></li>';
210: }
1.299 raeburn 211: return '<li><a href="'.$$menuitem[0].'">'.$link.'</a></li>';
1.283 droeschl 212: }
213:
214: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
215: # that contains following links:
216: # About, Message, Roles, Help, Logout
217: # @primary_menu is filled within the BEGIN block of this module with
218: # entries from mydesk.tab
219: sub primary_menu {
220: my $menu;
221: # each element of @primary contains following array:
222: # (link url, icon path, alt text, link text, condition)
1.315.2.1! raeburn 223: my $public;
! 224: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
! 225: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
! 226: $public = 1;
! 227: }
1.283 droeschl 228: foreach my $menuitem (@primary_menu) {
229: # evaluate conditions
1.296 droeschl 230: next if ref($menuitem) ne 'ARRAY'; #
1.283 droeschl 231: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
1.291 raeburn 232: && &Apache::lonmsg::mynewmail(); # whether a new msg
1.283 droeschl 233: next if $$menuitem[4] eq 'newmsg' # arrived or not
1.291 raeburn 234: && !&Apache::lonmsg::mynewmail(); #
1.315.2.1! raeburn 235: next if $$menuitem[4] !~ /public/ ##we've a public user,
! 236: && $public; ##who should not see all
! 237: ##links
! 238: next if $$menuitem[4] eq 'onlypublic'# hide links which are
! 239: && !$public; # only visible to public
! 240: # users
1.283 droeschl 241: next if $$menuitem[4] eq 'roles' ##show links depending on
1.315.2.1! raeburn 242: && &Apache::loncommon::show_course(); ##term 'Courses' or
1.283 droeschl 243: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
1.291 raeburn 244: && !&Apache::loncommon::show_course(); ##
1.315.2.1! raeburn 245:
! 246:
1.283 droeschl 247: if ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.291 raeburn 248: $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.283 droeschl 249: } else {
1.296 droeschl 250: my @items = @{$menuitem};
251: $items[0] = 'javascript:'.$menuitem->[0].';';
252: $menu .= &prep_menuitem(\@items);
1.283 droeschl 253: }
1.291 raeburn 254: }
1.283 droeschl 255:
1.291 raeburn 256: return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
1.283 droeschl 257: }
258:
259:
260: sub secondary_menu {
261: my $menu;
262:
1.286 raeburn 263: my $crstype = &Apache::loncommon::course_type();
264: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
265: my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'}
266: . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
267: : ''));
268: my $showlink = &show_return_link();
269: my %groups = &Apache::lonnet::get_active_groups(
270: $env{'user.domain'}, $env{'user.name'},
271: $env{'course.' . $env{'request.course.id'} . '.domain'},
272: $env{'course.' . $env{'request.course.id'} . '.num'});
1.283 droeschl 273: foreach my $menuitem (@secondary_menu) {
274: # evaluate conditions
1.296 droeschl 275: next if ref($menuitem) ne 'ARRAY';
1.283 droeschl 276: next if $$menuitem[4] ne 'always'
277: && !$env{'request.course.id'};
278: next if $$menuitem[4] eq 'showreturn'
1.286 raeburn 279: && !$showlink
1.283 droeschl 280: && !($env{'request.state'} eq 'construct');
281: next if $$menuitem[4] =~ /^mdc/
1.286 raeburn 282: && !$canedit;
283: next if $$menuitem[4] eq 'mdcCourse'
284: && $crstype eq 'Community';
285: next if $$menuitem[4] eq 'mdcCommunity'
286: && $crstype ne 'Community';
287: next if $$menuitem[4] =~ /^remotenav/
1.283 droeschl 288: && $env{'environment.remotenavmap'} ne 'on';
1.286 raeburn 289: next if $$menuitem[4] =~ /noremotenav/
1.283 droeschl 290: && $env{'environment.remotenavmap'} eq 'on';
1.295 raeburn 291: next if $$menuitem[4] =~ /^(no|)remotenav$/
292: && $crstype eq 'Community';
293: next if $$menuitem[4] =~ /^(no|)remotenavCommunity$/
294: && $crstype ne 'Community';
1.283 droeschl 295: next if $$menuitem[4] =~ /showgroups$/
1.300 raeburn 296: && !$canviewgrps
1.286 raeburn 297: && !%groups;
1.283 droeschl 298:
1.286 raeburn 299: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283 droeschl 300: # special treatment for role selector
1.298 raeburn 301: my $roles_selector = &roles_selector(
1.283 droeschl 302: $env{'course.' . $env{'request.course.id'} . '.domain'},
303: $env{'course.' . $env{'request.course.id'} . '.num'} );
304:
305: $menu .= $roles_selector ? "<li>$roles_selector</li>"
306: : '';
1.296 droeschl 307: } elsif ($env{'environment.remotenavmap'} eq 'on') {
308: # open link using javascript when remote navmap is activated
309: my @items = @{$menuitem};
310: if ($menuitem->[4] eq 'remotenav') {
311: $items[0] = "javascript:gonav('$menuitem->[0]');";
1.291 raeburn 312: } else {
1.296 droeschl 313: $items[0] = "javascript:go('$menuitem->[0]');";
1.291 raeburn 314: }
1.296 droeschl 315: $menu .= &prep_menuitem(\@items);
316: } else {
317: $menu .= &prep_menuitem(\@$menuitem);
1.283 droeschl 318: }
319: }
320: if ($menu =~ /\[url\].*\[symb\]/) {
1.291 raeburn 321: my $escurl = &escape( &Apache::lonenc::check_encrypt(
322: $env{'request.noversionuri'}));
1.283 droeschl 323:
1.291 raeburn 324: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
325: $env{'request.symb'}));
1.283 droeschl 326:
327: if ( $env{'request.state'} eq 'construct'
328: and ( $env{'request.noversionuri'} eq ''
329: || !defined($env{'request.noversionuri'})))
330: {
331: ($escurl = $env{'request.filename'}) =~
332: s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
333:
1.291 raeburn 334: $escurl = &escape($escurl);
1.283 droeschl 335: }
336: $menu =~ s/\[url\]/$escurl/g;
337: $menu =~ s/\[symb\]/$escsymb/g;
338: }
339:
1.285 wenzelju 340: return "<ul id=\"LC_secondary_menu\">$menu</ul>";
1.283 droeschl 341: }
342:
1.228 albertel 343: sub show_return_link {
1.315.2.1! raeburn 344: if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)})
! 345: || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) {
! 346:
! 347: return if ($env{'form.register'});
! 348: }
1.228 albertel 349: return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
350: $env{'request.symb'} eq '')
351: ||
352: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
353: ||
354: (($env{'request.noversionuri'}=~/^\/adm\//) &&
355: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
356: ($env{'request.noversionuri'}!~
1.315.2.1! raeburn 357: m[^/adm/.*/(smppg|bulletinboard)($|\?)])
1.228 albertel 358: ));
359: }
360:
1.38 www 361:
362: sub registerurl {
1.173 albertel 363: my ($forcereg) = @_;
1.38 www 364: my $result = '';
1.175 albertel 365: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.66 albertel 366: my $force_title='';
1.152 albertel 367: if ($env{'request.state'} eq 'construct') {
1.66 albertel 368: $force_title=&Apache::lonxml::display_title();
369: }
1.269 droeschl 370: if (($env{'environment.remote'} eq 'off') ||
1.152 albertel 371: ((($env{'request.publicaccess'}) ||
1.83 www 372: (!&Apache::lonnet::is_on_map(
1.183 www 373: &unescape($env{'request.noversionuri'})))) &&
1.38 www 374: (!$forcereg))) {
1.277 bisitz 375: return
376: $result
377: .'<script type="text/javascript">'."\n"
378: .'// <![CDATA['."\n"
379: .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
380: .'// ]]>'."\n"
381: .'</script>'
382: .$force_title;
1.38 www 383: }
1.41 www 384: # Graphical display after login only
1.174 albertel 385: if ($env{'request.registered'} && !$forcereg) { return ''; }
1.173 albertel 386: $result.=&innerregister($forcereg);
1.66 albertel 387: return $result.$force_title;
1.40 www 388: }
389:
390: sub innerregister {
1.308 raeburn 391: my ($forcereg,$titletable,$bread_crumbs) = @_;
1.40 www 392: my $result = '';
1.120 raeburn 393: my ($uname,$thisdisfn);
1.152 albertel 394: my $const_space = ($env{'request.state'} eq 'construct');
1.131 raeburn 395: my $is_const_dir = 0;
1.120 raeburn 396:
1.175 albertel 397: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40 www 398:
1.174 albertel 399: $env{'request.registered'} = 1;
1.40 www 400:
1.267 droeschl 401: my $noremote = ($env{'environment.remote'} eq 'off');
1.49 www 402:
1.177 albertel 403: undef(@inlineremote);
1.56 www 404:
1.38 www 405: my $reopen=&Apache::lonmenu::reopenmenu();
1.40 www 406:
1.38 www 407: my $newmail='';
1.267 droeschl 408:
409: if (&Apache::lonmsg::newmail() && !$noremote) {
410: # We have new mail and remote is up
411: $newmail= 'swmenu.setstatus("you have","messages");';
1.233 www 412: }
1.276 droeschl 413:
1.288 raeburn 414: my ($breadcrumb,$separator);
1.267 droeschl 415: if ($noremote
1.177 albertel 416: && ($env{'request.symb'})
417: && ($env{'request.course.id'})) {
1.267 droeschl 418:
419: my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
420: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
421:
422: my $maptitle = &Apache::lonnet::gettitle($mapurl);
423: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.299 raeburn 424: my $contentstext;
425: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Community') {
426: $contentstext = &mt('Community Contents');
427: } else {
428: $contentstext = &mt('Course Contents');
429: }
1.315.2.1! raeburn 430: my @crumbs;
! 431: unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps')
! 432: && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
! 433: @crumbs = ({text => $contentstext,
! 434: href => "Javascript:gopost('/adm/navmaps','')"});
! 435: }
1.289 raeburn 436: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
437: push(@crumbs, {text => '...',
438: no_mt => 1});
439: }
1.268 droeschl 440:
441: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
442: && $maptitle ne 'default.sequence'
443: && $maptitle ne $coursetitle);
444:
445: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
446:
1.291 raeburn 447: &Apache::lonhtmlcommon::clear_breadcrumbs();
448: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
1.301 droeschl 449: #$breadcrumb .= &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
1.288 raeburn 450: unless (($env{'request.state'} eq 'edit') || ($newmail) ||
451: ($env{'request.state'} eq 'construct') ||
452: ($env{'form.register'})) {
453: $separator = &Apache::loncommon::head_subbox();
454: }
1.267 droeschl 455: #
1.65 www 456: }
1.152 albertel 457: if ($env{'request.state'} eq 'construct') {
1.131 raeburn 458: $newmail = $titletable;
1.267 droeschl 459: }
460: my $timesync = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
461: my $tablestart = ( $noremote ? '<table id="LC_menubuttons">' : '');
462: my $tableend = ( $noremote ? '</table>' : '');
1.41 www 463: # =============================================================================
464: # ============================ This is for URLs that actually can be registered
1.296 droeschl 465: if (($env{'request.noversionuri'}!~m{^/(res/)*adm/}) || ($forcereg)) {
1.40 www 466: # -- This applies to homework problems for users with grading privileges
1.152 albertel 467: my $crs='/'.$env{'request.course.id'};
468: if ($env{'request.course.sec'}) {
469: $crs.='_'.$env{'request.course.sec'};
1.107 albertel 470: }
471: $crs=~s/\_/\//g;
472:
1.38 www 473: my $hwkadd='';
1.152 albertel 474: if ($env{'request.symb'} ne '' &&
1.161 albertel 475: $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
1.79 www 476: if (&Apache::lonnet::allowed('mgr',$crs)) {
1.259 bisitz 477: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]',
1.40 www 478: "gocmd('/adm/grades','gradingmenu')",
479: 'Modify user grades for this assessment resource');
1.154 www 480: } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
481: $hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
482: "gocmd('/adm/grades','submission')",
483: 'View user submissions for this assessment resource');
1.38 www 484: }
1.107 albertel 485: }
1.152 albertel 486: if ($env{'request.symb'} ne '' &&
1.145 albertel 487: &Apache::lonnet::allowed('opa',$crs)) {
1.107 albertel 488: $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
489: "gocmd('/adm/parmset','set')",
1.196 www 490: 'Modify parameter settings for this resource');
1.38 www 491: }
1.40 www 492: # -- End Homework
1.38 www 493: ###
494: ### Determine whether or not to display the 'cstr' button for this
495: ### resource
496: ###
497: my $editbutton = '';
1.258 raeburn 498: my $noeditbutton = 1;
499: my ($cnum,$cdom);
500: if ($env{'request.course.id'}) {
501: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
502: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
503: }
1.152 albertel 504: if ($env{'user.author'}) {
1.234 raeburn 505: if ($env{'request.role'}=~/^(aa|ca|au)/) {
1.274 www 506: #
507: # We have the role of an author
508: #
1.38 www 509: # Set defaults for authors
510: my ($top,$bottom) = ('con-','struct');
1.152 albertel 511: my $action = "go('/priv/".$env{'user.name'}."');";
512: my $cadom = $env{'request.role.domain'};
513: my $caname = $env{'user.name'};
1.236 bisitz 514: my $desc = "Enter my construction space";
1.38 www 515: # Set defaults for co-authors
1.152 albertel 516: if ($env{'request.role'} =~ /^ca/) {
1.206 albertel 517: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.38 www 518: ($top,$bottom) = ('co con-','struct');
519: $action = "go('/priv/".$caname."');";
520: $desc = "Enter construction space as co-author";
1.234 raeburn 521: } elsif ($env{'request.role'} =~ /^aa/) {
522: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
523: ($top,$bottom) = ('co con-','struct');
524: $action = "go('/priv/".$caname."');";
525: $desc = "Enter construction space as assistant co-author";
1.38 www 526: }
527: # Check that we are on the correct machine
528: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 529: my $allowed=0;
530: my @ids=&Apache::lonnet::current_machine_ids();
531: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
532: if (!$allowed) {
533: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
1.258 raeburn 534: $noeditbutton = 0;
1.38 www 535: }
536: }
1.274 www 537: #
538: # We are an author for some stuff, but currently do not have the role of author.
539: # Figure out if we have authoring privileges for the resource we are looking at.
540: # This should maybe become a privilege check in lonnet
541: #
1.38 www 542: ##
543: ## Determine if user can edit url.
544: ##
545: my $cfile='';
546: my $cfuname='';
547: my $cfudom='';
1.258 raeburn 548: my $uploaded;
1.152 albertel 549: if ($env{'request.filename'}) {
550: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.258 raeburn 551: if (defined($cnum) && defined($cdom)) {
552: $uploaded = &is_course_upload($file,$cnum,$cdom);
553: }
554: if (!$uploaded) {
555: $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
556: # Check that the user has permission to edit this resource
557: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
558: if (defined($cfudom)) {
559: my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
560: my $allowed=0;
561: my @ids=&Apache::lonnet::current_machine_ids();
562: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
563: if ($allowed) {
564: $cfile=$file;
565: }
1.38 www 566: }
567: }
1.258 raeburn 568: }
1.38 www 569: # Finally, turn the button on or off
1.120 raeburn 570: if ($cfile && !$const_space) {
1.302 raeburn 571: my $nocrsedit;
572: # Suppress display where CC has switched to student role.
573: if ($env{'request.course.id'}) {
574: unless(&Apache::lonnet::allowed('mdc',
575: $env{'request.course.id'})) {
576: $nocrsedit = 1;
577: }
578: }
579: if ($nocrsedit) {
580: $editbutton=&clear(6,1);
581: } else {
582: $editbutton=&switch
583: ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
1.38 www 584: "go('".$cfile."');","Edit this resource");
1.302 raeburn 585: $noeditbutton = 0;
586: }
1.38 www 587: } elsif ($editbutton eq '') {
1.191 www 588: $editbutton=&clear(6,1);
1.38 www 589: }
590: }
1.258 raeburn 591: if (($noeditbutton) && ($env{'request.filename'})) {
592: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
593: my $file=&Apache::lonnet::declutter($env{'request.filename'});
594: if (defined($cnum) && defined($cdom)) {
595: if (&is_course_upload($file,$cnum,$cdom)) {
596: my $cfile = &edit_course_upload($file,$cnum,$cdom);
597: if ($cfile) {
598: $editbutton=&switch
599: ('','',6,1,'pcstr.gif','edit[_1]',
600: 'resource[_2]',"go('".$cfile."');",
601: 'Edit this resource');
602: }
603: }
604: }
605: }
606: }
1.38 www 607: ###
608: ###
1.41 www 609: # Prepare the rest of the buttons
1.120 raeburn 610: my $menuitems;
611: if ($const_space) {
1.274 www 612: #
613: # We are in construction space
614: #
1.128 albertel 615: my ($uname,$thisdisfn) =
1.152 albertel 616: ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
1.121 raeburn 617: my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
1.131 raeburn 618: if ($currdir =~ m-/$-) {
619: $is_const_dir = 1;
620: } else {
1.267 droeschl 621: $currdir =~ s|[^/]+$||;
1.200 foxr 622: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208 albertel 623: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274 www 624: #
625: # Probably should be in mydesk.tab
626: #
1.131 raeburn 627: $menuitems=(<<ENDMENUITEMS);
1.208 albertel 628: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
1.200 foxr 629: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
1.259 bisitz 630: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
1.200 foxr 631: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
632: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
1.120 raeburn 633: ENDMENUITEMS
1.131 raeburn 634: }
1.308 raeburn 635: if ($noremote) {
636: if (ref($bread_crumbs) eq 'ARRAY') {
637: &Apache::lonhtmlcommon::clear_breadcrumbs();
638: foreach my $crumb (@{$bread_crumbs}){
639: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
640: }
641: }
642: }
1.203 foxr 643: } elsif ( defined($env{'request.course.id'}) &&
644: $env{'request.symb'} ne '' ) {
1.274 www 645: #
646: # We are in a course and looking at a registred URL
647: # Should probably be in mydesk.tab
648: #
1.120 raeburn 649: $menuitems=(<<ENDMENUITEMS);
1.41 www 650: c&3&1
1.209 www 651: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
652: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
1.77 www 653: c&6&3
654: c&8&1
655: c&8&2
1.106 www 656: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.209 www 657: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
1.41 www 658: ENDMENUITEMS
1.216 albertel 659:
1.243 tempelho 660: my $currentURL = &Apache::loncommon::get_symb();
661: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
662: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
663: $menuitems.="s&9&3&";
664: if(length($annotation) > 0){
665: $menuitems.="anot2.gif";
666: }else{
667: $menuitems.="anot.gif";
668: }
669: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
670: $menuitems.="Make notes and annotations about this resource&&1\n";
671:
1.279 raeburn 672: unless ($noremote) {
673: my $showreqcrs = &check_for_rcrs();
674: if ($showreqcrs) {
675: $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]".
676: "&go('/adm/requestcourse')&Course requests\n";
677: }
678: }
1.315.2.1! raeburn 679: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1.294 raeburn 680: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
1.216 albertel 681: $menuitems.=(<<ENDREALRES);
1.259 bisitz 682: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
1.216 albertel 683: ENDREALRES
684: }
1.120 raeburn 685: $menuitems.=(<<ENDREALRES);
1.106 www 686: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
687: s&8&2&fdbk.gif&feedback[_1]&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1.77 www 688: ENDREALRES
1.120 raeburn 689: }
690: }
1.203 foxr 691: if ($env{'request.uri'} =~ /^\/res/) {
692: $menuitems .= (<<ENDMENUITEMS);
693: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
694: ENDMENUITEMS
695: }
1.41 www 696: my $buttons='';
697: foreach (split(/\n/,$menuitems)) {
698: my ($command,@rest)=split(/\&/,$_);
1.220 raeburn 699: my $idx=10*$rest[0]+$rest[1];
700: if (&hidden_button_check() eq 'yes') {
701: if ($idx == 21 ||$idx == 23) {
702: $buttons.=&switch('','',@rest);
703: } else {
704: $buttons.=&clear(@rest);
705: }
706: } else {
707: if ($command eq 's') {
708: $buttons.=&switch('','',@rest);
709: } else {
710: $buttons.=&clear(@rest);
711: }
1.41 www 712: }
713: }
1.148 albertel 714:
1.267 droeschl 715: if ($noremote) {
1.148 albertel 716: my $addremote=0;
1.267 droeschl 717: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.148 albertel 718: my $inlinebuttons='';
1.301 droeschl 719: if ($addremote) {
720:
1.304 droeschl 721: Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301 droeschl 722:
1.312 droeschl 723: Apache::lonhtmlcommon::add_breadcrumb_tool(
724: 'navigation', @inlineremote[21,23]);
725:
726: if(hidden_button_check() ne 'yes') {
727: Apache::lonhtmlcommon::add_breadcrumb_tool(
1.313 droeschl 728: 'tools', @inlineremote[93,91,81,82,83]);
729:
730: #publish button in construction space
731: if ($env{'request.state'} eq 'construct'){
732: Apache::lonhtmlcommon::add_breadcrumb_tool(
733: 'advtools', @inlineremote[63]);
734: }else{
735: Apache::lonhtmlcommon::add_breadcrumb_tool(
736: 'tools', @inlineremote[63]);
737: }
1.312 droeschl 738:
1.315.2.1! raeburn 739: unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
! 740: Apache::lonhtmlcommon::add_breadcrumb_tool(
! 741: 'advtools', @inlineremote[61,71,72,73,92]);
! 742: }
1.301 droeschl 743: }
744:
745: # # Registered, textual output
746: # if ( $env{'environment.icons'} eq 'iconsonly' ) {
747: # $inlinebuttons = (<<ENDARROWSINLINE);
748: #<tr><td>
749: #$inlineremote[21] $inlineremote[23]
750: #ENDARROWSINLINE
751: # if ( &hidden_button_check() ne 'yes' ) {
752: # $inlinebuttons .= (<<ENDINLINEICONS);
753: #$inlineremote[61] $inlineremote[63]
754: #$inlineremote[71] $inlineremote[72] $inlineremote[73]
755: #$inlineremote[81] $inlineremote[82] $inlineremote[83]
756: #$inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
757: #ENDINLINEICONS
758: # }
759: # } else { # not iconsonly
760: # if ( $inlineremote[21] ne '' || $inlineremote[23] ne '' ) {
761: # $inlinebuttons = (<<ENDFIRSTLINE);
762: #<tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr>
763: #ENDFIRSTLINE
764: # }
765: # if ( &hidden_button_check() ne 'yes' ) {
766: # foreach my $row ( 6 .. 9 ) {
767: # if ( $inlineremote[ ${row} . '1' ] ne ''
768: # || $inlineremote[ $row . '2' ] ne ''
769: # || $inlineremote[ $row . '3' ] ne '' )
770: # {
771: # $inlinebuttons .= <<"ENDLINE";
772: #<tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
773: #ENDLINE
774: # }
775: # }
776: # }
777: # }
778: }
779: $breadcrumb = &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
1.41 www 780: $result =(<<ENDREGTEXT);
1.129 albertel 781: <script type="text/javascript">
1.42 www 782: // BEGIN LON-CAPA Internal
783: </script>
1.41 www 784: $timesync
1.267 droeschl 785: $breadcrumb
1.305 bisitz 786: <!-- $tablestart -->
787: <!-- $inlinebuttons -->
788: <!-- $tableend -->
1.224 albertel 789: $newmail
1.305 bisitz 790: <!-- $separator -->
1.129 albertel 791: <script type="text/javascript">
1.64 www 792: // END LON-CAPA Internal
1.42 www 793: </script>
794:
1.41 www 795: ENDREGTEXT
796: # Registered, graphical output
797: } else {
1.152 albertel 798: my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.183 www 799: $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
1.152 albertel 800: my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.113 albertel 801: my $navstatus=&get_nav_status();
1.140 albertel 802: my $clearcstr;
1.148 albertel 803:
1.152 albertel 804: if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1.41 www 805: $result = (<<ENDREGTHIS);
1.38 www 806:
1.129 albertel 807: <script type="text/javascript">
1.277 bisitz 808: // <![CDATA[
1.150 albertel 809: // BEGIN LON-CAPA Internal
1.42 www 810: var swmenu=null;
1.38 www 811:
812: function LONCAPAreg() {
813: swmenu=$reopen;
814: swmenu.clearTimeout(swmenu.menucltim);
815: $timesync
816: $newmail
1.41 www 817: $buttons
1.84 www 818: swmenu.currentURL="$requri";
1.85 www 819: swmenu.reloadURL=swmenu.currentURL+window.location.search;
1.125 albertel 820: swmenu.currentSymb="$cursymb";
821: swmenu.reloadSymb="$cursymb";
1.38 www 822: swmenu.currentStale=0;
1.113 albertel 823: $navstatus
1.38 www 824: $hwkadd
825: $editbutton
826: }
827:
828: function LONCAPAstale() {
829: swmenu=$reopen
830: swmenu.currentStale=1;
831: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
832: swmenu.switchbutton
833: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
834: }
835: swmenu.clearbut(7,2);
836: swmenu.clearbut(7,3);
837: swmenu.menucltim=swmenu.setTimeout(
838: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.140 albertel 839: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1.38 www 840: 2000);
841: }
842:
1.150 albertel 843: // END LON-CAPA Internal
1.277 bisitz 844: // ]]>
1.38 www 845: </script>
846: ENDREGTHIS
1.41 www 847: }
848: # =============================================================================
1.38 www 849: } else {
1.41 www 850: # ========================================== This can or will not be registered
1.267 droeschl 851: if ($noremote) {
1.269 droeschl 852: # Not registered
1.267 droeschl 853: $result= (<<ENDDONOTREGTEXT);
1.41 www 854: ENDDONOTREGTEXT
855: } else {
856: # Not registered, graphical
857: $result = (<<ENDDONOTREGTHIS);
1.38 www 858:
1.129 albertel 859: <script type="text/javascript">
1.277 bisitz 860: // <![CDATA[
1.38 www 861: // BEGIN LON-CAPA Internal
1.42 www 862: var swmenu=null;
1.38 www 863:
864: function LONCAPAreg() {
865: swmenu=$reopen
866: $timesync
867: swmenu.currentStale=1;
868: swmenu.clearbut(2,1);
869: swmenu.clearbut(2,3);
870: swmenu.clearbut(8,1);
871: swmenu.clearbut(8,2);
872: swmenu.clearbut(8,3);
873: if (swmenu.currentURL) {
874: swmenu.switchbutton
875: (3,1,'reload.gif','return','location','go(currentURL)');
876: } else {
877: swmenu.clearbut(3,1);
878: }
879: }
880:
881: function LONCAPAstale() {
882: }
883:
884: // END LON-CAPA Internal
1.277 bisitz 885: // ]]>
1.38 www 886: </script>
887: ENDDONOTREGTHIS
1.41 www 888: }
889: # =============================================================================
1.38 www 890: }
891: return $result;
892: }
893:
1.258 raeburn 894: sub is_course_upload {
895: my ($file,$cnum,$cdom) = @_;
896: my $uploadpath = &LONCAPA::propath($cdom,$cnum);
897: $uploadpath =~ s{^\/}{};
898: if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
899: ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
900: return 1;
901: }
902: return;
903: }
904:
905: sub edit_course_upload {
906: my ($file,$cnum,$cdom) = @_;
907: my $cfile;
908: if ($file =~/\.(htm|html|css|js|txt)$/) {
909: my $ext = $1;
910: my $url = &Apache::lonnet::hreflocation('',$file);
911: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
912: my @ids=&Apache::lonnet::current_machine_ids();
913: my $dest;
914: if ($home && grep(/^\Q$home\E$/,@ids)) {
915: $dest = $url.'?forceedit=1';
916: } else {
917: unless (&Apache::lonnet::get_locks()) {
918: $dest = '/adm/switchserver?otherserver='.
919: $home.'&role='.$env{'request.role'}.
920: '&url='.$url.'&forceedit=1';
921: }
922: }
923: if ($dest) {
924: $cfile = &HTML::Entities::encode($dest,'"<>&');
925: }
926: }
927: return $cfile;
928: }
929:
1.38 www 930: sub loadevents() {
1.152 albertel 931: if ($env{'request.state'} eq 'construct' ||
1.175 albertel 932: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38 www 933: return 'LONCAPAreg();';
934: }
935:
936: sub unloadevents() {
1.152 albertel 937: if ($env{'request.state'} eq 'construct' ||
1.175 albertel 938: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38 www 939: return 'LONCAPAstale();';
940: }
1.30 www 941:
1.32 www 942:
943: sub startupremote {
944: my ($lowerurl)=@_;
1.269 droeschl 945: if ($env{'environment.remote'} eq 'off') {
1.34 www 946: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
947: }
1.49 www 948: #
949: # The Remote actually gets launched!
950: #
1.32 www 951: my $configmenu=&rawconfig();
1.183 www 952: my $esclowerurl=&escape($lowerurl);
1.119 www 953: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1.32 www 954: return(<<ENDREMOTESTARTUP);
1.129 albertel 955: <script type="text/javascript">
1.277 bisitz 956: // <![CDATA[
1.118 albertel 957: var timestart;
1.35 www 958: function wheelswitch() {
1.118 albertel 959: if (typeof(document.wheel) != 'undefined') {
960: if (typeof(document.wheel.spin) != 'undefined') {
961: var date=new Date();
962: var waited=Math.round(30-((date.getTime()-timestart)/1000));
963: document.wheel.spin.value=$message;
964: }
965: }
1.35 www 966: if (window.status=='|') {
967: window.status='/';
968: } else {
969: if (window.status=='/') {
970: window.status='-';
971: } else {
972: if (window.status=='-') {
973: window.status='\\\\';
974: } else {
975: if (window.status=='\\\\') { window.status='|'; }
976: }
977: }
978: }
979: }
980:
1.32 www 981: // ---------------------------------------------------------- The wait function
982: var canceltim;
983: function wait() {
984: if ((menuloaded==1) || (tim==1)) {
1.35 www 985: window.status='Done.';
1.32 www 986: if (tim==0) {
987: clearTimeout(canceltim);
988: $configmenu
989: window.location='$lowerurl';
990: } else {
1.52 www 991: window.location='/adm/remote?action=collapse&url=$esclowerurl';
1.32 www 992: }
993: } else {
1.35 www 994: wheelswitch();
995: setTimeout('wait();',200);
1.32 www 996: }
997: }
998:
999: function main() {
1.52 www 1000: canceltim=setTimeout('tim=1;',30000);
1.35 www 1001: window.status='-';
1.118 albertel 1002: var date=new Date();
1003: timestart=date.getTime();
1.32 www 1004: wait();
1005: }
1006:
1.277 bisitz 1007: // ]]>
1.32 www 1008: </script>
1009: ENDREMOTESTARTUP
1010: }
1011:
1012: sub setflags() {
1013: return(<<ENDSETFLAGS);
1.129 albertel 1014: <script type="text/javascript">
1.277 bisitz 1015: // <![CDATA[
1.32 www 1016: menuloaded=0;
1017: tim=0;
1.277 bisitz 1018: // ]]>
1.32 www 1019: </script>
1020: ENDSETFLAGS
1021: }
1022:
1023: sub maincall() {
1.269 droeschl 1024: if ($env{'environment.remote'} eq 'off') { return ''; }
1.32 www 1025: return(<<ENDMAINCALL);
1.129 albertel 1026: <script type="text/javascript">
1.277 bisitz 1027: // <![CDATA[
1.32 www 1028: main();
1.277 bisitz 1029: // ]]>
1.32 www 1030: </script>
1031: ENDMAINCALL
1032: }
1.118 albertel 1033:
1034: sub load_remote_msg {
1035: my ($lowerurl)=@_;
1036:
1.269 droeschl 1037: if ($env{'environment.remote'} eq 'off') { return ''; }
1.118 albertel 1038:
1.183 www 1039: my $esclowerurl=&escape($lowerurl);
1.261 bisitz 1040: my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
1041: ,'<a href="/adm/remote?action=collapse&url='.$esclowerurl.'">'
1042: ,'</a>');
1.118 albertel 1043: return(<<ENDREMOTEFORM);
1044: <p>
1045: <form name="wheel">
1.119 www 1046: <input name="spin" type="text" size="60" />
1.118 albertel 1047: </form>
1048: </p>
1049: <p>$link</p>
1050: ENDREMOTEFORM
1051: }
1.230 albertel 1052:
1053: sub get_menu_name {
1054: my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
1055: $hostid =~ s/\W//g;
1056: return 'LCmenu'.$hostid;
1057: }
1058:
1.30 www 1059:
1060: sub reopenmenu {
1.269 droeschl 1061: if ($env{'environment.remote'} eq 'off') { return ''; }
1.230 albertel 1062: my $menuname = &get_menu_name();
1.47 matthew 1063: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1064: return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30 www 1065: }
1066:
1.1 www 1067:
1068: sub open {
1.22 www 1069: my $returnval='';
1.269 droeschl 1070: if ($env{'environment.remote'} eq 'off') {
1.277 bisitz 1071: return
1072: '<script type="text/javascript">'."\n"
1073: .'// <![CDATA['."\n"
1074: .'self.name="loncapaclient";'."\n"
1075: .'// ]]>'."\n"
1076: .'</script>';
1.111 albertel 1077: }
1.230 albertel 1078: my $menuname = &get_menu_name();
1.222 albertel 1079:
1080: # unless (shift eq 'unix') {
1.22 www 1081: # resizing does not work on linux because of virtual desktop sizes
1.222 albertel 1082: # $returnval.=(<<ENDRESIZE);
1083: #if (window.screen) {
1084: # self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1085: # self.moveTo(190,15);
1086: #}
1087: #ENDRESIZE
1088: # }
1.277 bisitz 1089: $returnval=(<<ENDOPEN);
1090: // <![CDATA[
1.35 www 1091: window.status='Opening LON-CAPA Remote Control';
1.272 droeschl 1092: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
1.191 www 1093: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.71 www 1094: self.name='loncapaclient';
1.277 bisitz 1095: // ]]>
1.1 www 1096: ENDOPEN
1.129 albertel 1097: return '<script type="text/javascript">'.$returnval.'</script>';
1.1 www 1098: }
1099:
1.2 www 1100:
1101: # ================================================================== Raw Config
1102:
1.3 www 1103: sub clear {
1104: my ($row,$col)=@_;
1.269 droeschl 1105: unless ($env{'environment.remote'} eq 'off') {
1.275 www 1106: if (($row<1) || ($row>13)) { return ''; }
1.35 www 1107: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.56 www 1108: } else {
1109: $inlineremote[10*$row+$col]='';
1110: return '';
1111: }
1.3 www 1112: }
1113:
1.40 www 1114: # ============================================ Switch a button or create a link
1.25 matthew 1115: # Switch acts on the javascript that is executed when a button is clicked.
1116: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 1117:
1.2 www 1118: sub switch {
1.209 www 1119: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2 www 1120: $act=~s/\$uname/$uname/g;
1121: $act=~s/\$udom/$udom/g;
1.88 www 1122: $top=&mt($top);
1123: $bot=&mt($bot);
1124: $desc=&mt($desc);
1.238 www 1125: if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
1126: $img=&mt($img);
1127: }
1.209 www 1128: my $idx=10*$row+$col;
1129: $category_members{$cat}.=':'.$idx;
1130:
1.269 droeschl 1131: unless ($env{'environment.remote'} eq 'off') {
1.275 www 1132: if (($row<1) || ($row>13)) { return ''; }
1.50 www 1133: # Remote
1.34 www 1134: return "\n".
1.35 www 1135: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.34 www 1136: } else {
1.50 www 1137: # Inline Remote
1.213 www 1138: if ($env{'environment.icons'} ne 'classic') {
1139: $img=~s/\.gif$/\.png/;
1140: }
1.41 www 1141: if ($nobreak==2) { return ''; }
1.34 www 1142: my $text=$top.' '.$bot;
1.78 www 1143: $text=~s/\s*\-\s*//gs;
1.105 www 1144:
1.99 www 1145: my $pic=
1.225 albertel 1146: '<img alt="'.$text.'" src="'.
1147: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303 droeschl 1148: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.177 albertel 1149: if ($env{'browser.interface'} eq 'faketextual') {
1.274 www 1150: # Main Menu
1.103 www 1151: if ($nobreak==3) {
1.209 www 1152: $inlineremote[$idx]="\n".
1.177 albertel 1153: '<td class="LC_menubuttons_text" align="right">'.$text.
1.247 harmsja 1154: '</td><td align="left">'.
1.103 www 1155: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1156: } elsif ($nobreak) {
1.209 www 1157: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1158: '<td align="left">'.
1.177 albertel 1159: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215 www 1160: <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 1161: } else {
1.209 www 1162: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1163: '<td align="left">'.
1.103 www 1164: '<a href="javascript:'.$act.';">'.$pic.
1.177 albertel 1165: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215 www 1166: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103 www 1167: }
1.94 www 1168: } else {
1.103 www 1169: # Inline Menu
1.218 www 1170: if ($env{'environment.icons'} eq 'iconsonly') {
1171: $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
1172: } else {
1173: $inlineremote[$idx]=
1.301 droeschl 1174: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.215 www 1175: '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
1.218 www 1176: }
1.94 www 1177: }
1.34 www 1178: }
1.56 www 1179: return '';
1.2 www 1180: }
1181:
1182: sub secondlevel {
1183: my $output='';
1184: my
1.209 www 1185: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2 www 1186: if ($prt eq 'any') {
1.209 www 1187: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1188: } elsif ($prt=~/^r(\w+)/) {
1189: if ($rol eq $1) {
1.209 www 1190: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1191: }
1192: }
1193: return $output;
1194: }
1195:
1.18 www 1196: sub openmenu {
1.230 albertel 1197: my $menuname = &get_menu_name();
1.269 droeschl 1198: if ($env{'environment.remote'} eq 'off') { return ''; }
1.47 matthew 1199: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1200: return "window.open(".$nothing.",'".$menuname."');";
1.18 www 1201: }
1202:
1.56 www 1203: sub inlinemenu {
1.210 albertel 1204: undef(@inlineremote);
1205: undef(%category_members);
1.275 www 1206: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56 www 1207: &rawconfig(1);
1.309 bisitz 1208: my $output='<table><tr>';
1.209 www 1209: for (my $col=1; $col<=2; $col++) {
1.241 riegler 1210: $output.='<td class="LC_mainmenu_col_fieldset">';
1.209 www 1211: for (my $row=1; $row<=8; $row++) {
1212: foreach my $cat (keys(%category_members)) {
1213: if ($category_positions{$cat} ne "$col,$row") { next; }
1.247 harmsja 1214: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309 bisitz 1215: $output.='<div class="LC_Box LC_400Box">';
1216: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247 harmsja 1217: $output.='<table>';
1.240 riegler 1218: my %active=();
1219: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1220: if ($inlineremote[$menu_item]) {
1221: $active{$menu_item}=1;
1222: }
1223: }
1224: foreach my $item (sort(keys(%active))) {
1225: $output.=$inlineremote[$item];
1226: }
1227: $output.='</table>';
1.245 harmsja 1228: $output.='</div>';
1.240 riegler 1229: }
1230: }
1231: $output.="</td>";
1232: }
1233: $output.="</tr></table>";
1234: return $output;
1235: }
1236:
1.2 www 1237: sub rawconfig {
1.274 www 1238: #
1239: # This evaluates mydesk.tab
1240: # Need to add more positions and more privileges to deal with all
1241: # menu items.
1242: #
1.34 www 1243: my $textualoverride=shift;
1244: my $output='';
1.269 droeschl 1245: unless ($env{'environment.remote'} eq 'off') {
1.35 www 1246: $output.=
1247: "window.status='Opening Remote Control';var swmenu=".&openmenu().
1248: "\nwindow.status='Configuring Remote Control ';";
1.34 www 1249: } else {
1250: unless ($textualoverride) { return ''; }
1251: }
1.152 albertel 1252: my $uname=$env{'user.name'};
1253: my $udom=$env{'user.domain'};
1254: my $adv=$env{'user.adv'};
1.266 raeburn 1255: my $show_course=&Apache::loncommon::show_course();
1.152 albertel 1256: my $author=$env{'user.author'};
1.5 www 1257: my $crs='';
1.295 raeburn 1258: my $crstype='';
1.152 albertel 1259: if ($env{'request.course.id'}) {
1260: $crs='/'.$env{'request.course.id'};
1261: if ($env{'request.course.sec'}) {
1262: $crs.='_'.$env{'request.course.sec'};
1.7 www 1263: }
1.8 www 1264: $crs=~s/\_/\//g;
1.295 raeburn 1265: $crstype = &Apache::loncommon::course_type();
1.5 www 1266: }
1.152 albertel 1267: my $pub=($env{'request.state'} eq 'published');
1268: my $con=($env{'request.state'} eq 'construct');
1269: my $rol=$env{'request.role'};
1270: my $requested_domain = $env{'request.role.domain'};
1.184 raeburn 1271: foreach my $line (@desklines) {
1.209 www 1272: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3 www 1273: $prt=~s/\$uname/$uname/g;
1274: $prt=~s/\$udom/$udom/g;
1.295 raeburn 1275: if ($prt =~ /\$crs/) {
1276: next unless ($env{'request.course.id'});
1277: next if ($crstype eq 'Community');
1278: $prt=~s/\$crs/$crs/g;
1279: } elsif ($prt =~ /\$cmty/) {
1280: next unless ($env{'request.course.id'});
1281: next if ($crstype ne 'Community');
1282: $prt=~s/\$cmty/$crs/g;
1283: }
1.25 matthew 1284: $prt=~s/\$requested_domain/$requested_domain/g;
1.211 www 1285: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3 www 1286: if ($pro eq 'clear') {
1.4 www 1287: $output.=&clear($row,$col);
1.3 www 1288: } elsif ($pro eq 'any') {
1.2 www 1289: $output.=&secondlevel(
1.209 www 1290: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1291: } elsif ($pro eq 'smp') {
1292: unless ($adv) {
1293: $output.=&secondlevel(
1.209 www 1294: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1295: }
1296: } elsif ($pro eq 'adv') {
1297: if ($adv) {
1298: $output.=&secondlevel(
1.209 www 1299: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1300: }
1.231 albertel 1301: } elsif ($pro eq 'shc') {
1302: if ($show_course) {
1303: $output.=&secondlevel(
1304: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1305: }
1306: } elsif ($pro eq 'nsc') {
1307: if (!$show_course) {
1308: $output.=&secondlevel(
1309: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1310: }
1.81 matthew 1311: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295 raeburn 1312: my $priv = $1;
1313: if ($priv =~ /^mdc(Course|Community)/) {
1314: if ($crstype eq $1) {
1315: $priv = 'mdc';
1316: } else {
1317: next;
1318: }
1319: }
1320: if (&Apache::lonnet::allowed($priv,$prt)) {
1.209 www 1321: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4 www 1322: }
1.295 raeburn 1323: } elsif ($pro eq 'course') {
1324: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209 www 1325: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81 matthew 1326: }
1.295 raeburn 1327: } elsif ($pro eq 'community') {
1328: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1329: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1330: }
1.124 matthew 1331: } elsif ($pro =~ /^courseenv_(.*)$/) {
1332: my $key = $1;
1.307 raeburn 1333: if ($crstype ne 'Community') {
1334: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1335: if ($key eq 'canuse_pdfforms') {
1336: if ($env{'request.course.id'} && $coursepref eq '') {
1337: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1338: $coursepref = $domdefs{'canuse_pdfforms'};
1339: }
1340: }
1341: if ($coursepref) {
1342: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1343: }
1.295 raeburn 1344: }
1345: } elsif ($pro =~ /^communityenv_(.*)$/) {
1346: my $key = $1;
1.307 raeburn 1347: if ($crstype eq 'Community') {
1348: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1349: if ($key eq 'canuse_pdfforms') {
1350: if ($env{'request.course.id'} && $coursepref eq '') {
1351: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1352: $coursepref = $domdefs{'canuse_pdfforms'};
1353: }
1354: }
1355: if ($coursepref) {
1356: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1357: }
1.124 matthew 1358: }
1.81 matthew 1359: } elsif ($pro =~ /^course_(.*)$/) {
1360: # Check for permissions inside of a course
1.295 raeburn 1361: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1.152 albertel 1362: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1363: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81 matthew 1364: )) {
1.209 www 1365: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26 www 1366: }
1.295 raeburn 1367: } elsif ($pro =~ /^community_(.*)$/) {
1368: # Check for permissions inside of a community
1369: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1370: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1371: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1372: )) {
1373: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1374: }
1.4 www 1375: } elsif ($pro eq 'author') {
1376: if ($author) {
1.152 albertel 1377: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234 raeburn 1378: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1.152 albertel 1379: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19 matthew 1380: # Check that we are on the correct machine
1.29 matthew 1381: my $cadom=$requested_domain;
1.152 albertel 1382: my $caname=$env{'user.name'};
1.234 raeburn 1383: if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29 matthew 1384: ($cadom,$caname)=
1.206 albertel 1385: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29 matthew 1386: }
1387: $act =~ s/\$caname/$caname/g;
1.19 matthew 1388: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 1389: my $allowed=0;
1390: my @ids=&Apache::lonnet::current_machine_ids();
1391: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1392: if ($allowed) {
1.209 www 1393: $output.=&switch($caname,$cadom,
1394: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19 matthew 1395: }
1.6 www 1396: }
1.2 www 1397: }
1.248 raeburn 1398: } elsif ($pro eq 'tools') {
1399: my @tools = ('aboutme','blog','portfolio');
1400: if (grep(/^\Q$prt\E$/,@tools)) {
1.249 raeburn 1401: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251 raeburn 1402: $env{'user.domain'},
1403: $prt,undef,'tools')) {
1404: $output.=&clear($row,$col);
1405: next;
1406: }
1.278 raeburn 1407: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1408: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1409: next;
1410: }
1411: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1412: next;
1413: }
1.279 raeburn 1414: my $showreqcrs = &check_for_rcrs();
1.251 raeburn 1415: if (!$showreqcrs) {
1.248 raeburn 1416: $output.=&clear($row,$col);
1417: next;
1418: }
1419: }
1420: $prt='any';
1421: $output.=&secondlevel(
1422: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1423: }
1.13 harris41 1424: }
1.269 droeschl 1425: unless ($env{'environment.remote'} eq 'off') {
1.35 www 1426: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.123 www 1427: if (&Apache::lonmsg::newmail()) {
1428: $output.='swmenu.setstatus("you have","messages");';
1429: }
1.34 www 1430: }
1.123 www 1431:
1.2 www 1432: return $output;
1433: }
1434:
1.279 raeburn 1435: sub check_for_rcrs {
1436: my $showreqcrs = 0;
1.280 raeburn 1437: my @reqtypes = ('official','unofficial','community');
1438: foreach my $type (@reqtypes) {
1.279 raeburn 1439: if (&Apache::lonnet::usertools_access($env{'user.name'},
1440: $env{'user.domain'},
1441: $type,undef,'requestcourses')) {
1442: $showreqcrs = 1;
1443: last;
1444: }
1445: }
1.280 raeburn 1446: if (!$showreqcrs) {
1447: foreach my $type (@reqtypes) {
1448: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1449: $showreqcrs = 1;
1450: last;
1451: }
1452: }
1453: }
1.279 raeburn 1454: return $showreqcrs;
1455: }
1456:
1.2 www 1457: # ======================================================================= Close
1.1 www 1458:
1459: sub close {
1.269 droeschl 1460: if ($env{'environment.remote'} eq 'off') { return ''; }
1.230 albertel 1461: my $menuname = &get_menu_name();
1.1 www 1462: return(<<ENDCLOSE);
1.129 albertel 1463: <script type="text/javascript">
1.277 bisitz 1464: // <![CDATA[
1.35 www 1465: window.status='Accessing Remote Control';
1.30 www 1466: menu=window.open("/adm/rat/empty.html","$menuname",
1.1 www 1467: "height=350,width=150,scrollbars=no,menubar=no");
1.35 www 1468: window.status='Disabling Remote Control';
1469: menu.active=0;
1.31 www 1470: menu.autologout=0;
1.35 www 1471: window.status='Closing Remote Control';
1.1 www 1472: menu.close();
1.35 www 1473: window.status='Done.';
1.277 bisitz 1474: // ]]>
1.1 www 1475: </script>
1476: ENDCLOSE
1477: }
1478:
1479: # ====================================================================== Footer
1480:
1481: sub footer {
1482:
1.33 www 1483: }
1484:
1.122 albertel 1485: sub nav_control_js {
1.152 albertel 1486: my $nav=($env{'environment.remotenavmap'} eq 'on');
1.122 albertel 1487: return (<<NAVCONTROL);
1488: var w_loncapanav_flag="$nav";
1489:
1490:
1491: function gonav(url) {
1492: if (w_loncapanav_flag != 1) {
1493: gopost(url,'');
1494: } else {
1495: navwindow=window.open(url,
1496: "loncapanav","height=600,width=400,scrollbars=1");
1497: }
1498: }
1499: NAVCONTROL
1500: }
1501:
1.306 raeburn 1502: sub dc_popup_js {
1503: my %lt = &Apache::lonlocal::texthash(
1504: more => '(More ...)',
1505: less => '(Less ...)',
1506: );
1507: return <<"END";
1508:
1509: function showCourseID() {
1510: document.getElementById('dccid').style.display='block';
1511: document.getElementById('dccid').style.textAlign='left';
1.307 raeburn 1512: document.getElementById('dccid').style.textFace='normal';
1.306 raeburn 1513: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>';
1514: return;
1515: }
1516:
1517: function hideCourseID() {
1518: document.getElementById('dccid').style.display='none';
1519: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()">$lt{'more'}</a>';
1520: return;
1521: }
1522:
1523: END
1524:
1525: }
1526:
1.42 www 1527: sub utilityfunctions {
1.132 raeburn 1528: my $caller = shift;
1.269 droeschl 1529: unless ($env{'environment.remote'} eq 'off' ||
1530: $caller eq '/adm/menu') {
1531: return ''; }
1532:
1.152 albertel 1533: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.293 raeburn 1534: if ($currenturl =~ m{^/adm/wrapper/ext/}) {
1535: if ($env{'request.external.querystring'}) {
1536: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1537: }
1538: }
1.183 www 1539: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125 albertel 1540:
1.152 albertel 1541: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.122 albertel 1542: my $nav_control=&nav_control_js();
1.175 albertel 1543:
1.306 raeburn 1544: my $dc_popup_cid;
1545: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1546: $env{'course.'.$env{'request.course.id'}.
1547: '.domain'}.'/'})) {
1548: $dc_popup_cid = &dc_popup_js();
1549: }
1550:
1.175 albertel 1551: my $start_page_annotate =
1552: &Apache::loncommon::start_page('Annotator',undef,
1553: {'only_body' => 1,
1554: 'js_ready' => 1,
1555: 'bgcolor' => '#BBBBBB',
1556: 'add_entries' => {
1557: 'onload' => 'javascript:document.goannotate.submit();'}});
1558:
1.205 albertel 1559: my $end_page_annotate =
1560: &Apache::loncommon::end_page({'js_ready' => 1});
1561:
1.175 albertel 1562: my $start_page_bookmark =
1563: &Apache::loncommon::start_page('Bookmarks',undef,
1564: {'only_body' => 1,
1565: 'js_ready' => 1,
1566: 'bgcolor' => '#BBBBBB',});
1567:
1.205 albertel 1568: my $end_page_bookmark =
1.175 albertel 1569: &Apache::loncommon::end_page({'js_ready' => 1});
1570:
1.42 www 1571: return (<<ENDUTILITY)
1572:
1573: var currentURL="$currenturl";
1574: var reloadURL="$currenturl";
1575: var currentSymb="$currentsymb";
1576:
1.114 albertel 1577: $nav_control
1.306 raeburn 1578: $dc_popup_cid
1.114 albertel 1579:
1.42 www 1580: function go(url) {
1581: if (url!='' && url!= null) {
1582: currentURL = null;
1583: currentSymb= null;
1584: window.location.href=url;
1585: }
1586: }
1587:
1.297 raeburn 1588: function gotop(url) {
1589: if (url!='' && url!= null) {
1590: top.location.href = url;
1591: }
1592: }
1593:
1.42 www 1594: function gopost(url,postdata) {
1595: if (url!='') {
1596: this.document.server.action=url;
1597: this.document.server.postdata.value=postdata;
1598: this.document.server.command.value='';
1599: this.document.server.url.value='';
1600: this.document.server.symb.value='';
1601: this.document.server.submit();
1602: }
1603: }
1604:
1605: function gocmd(url,cmd) {
1606: if (url!='') {
1607: this.document.server.action=url;
1608: this.document.server.postdata.value='';
1609: this.document.server.command.value=cmd;
1610: this.document.server.url.value=currentURL;
1611: this.document.server.symb.value=currentSymb;
1612: this.document.server.submit();
1613: }
1.57 www 1614: }
1615:
1.121 raeburn 1616: function gocstr(url,filename) {
1617: if (url == '/adm/cfile?action=delete') {
1618: this.document.cstrdelete.filename.value = filename
1619: this.document.cstrdelete.submit();
1620: return;
1621: }
1.137 raeburn 1622: if (url == '/adm/printout') {
1623: this.document.cstrprint.postdata.value = filename
1624: this.document.cstrprint.curseed.value = 0;
1625: this.document.cstrprint.problemtype.value = 0;
1.138 raeburn 1626: if (this.document.lonhomework) {
1627: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1628: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1629: }
1630: if (this.document.lonhomework.problemtype) {
1.164 albertel 1631: if (this.document.lonhomework.problemtype.value) {
1632: this.document.cstrprint.problemtype.value =
1633: this.document.lonhomework.problemtype.value;
1634: } else if (this.document.lonhomework.problemtype.options) {
1635: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1636: if (this.document.lonhomework.problemtype.options[i].selected) {
1637: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1638: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1639: }
1640: }
1641: }
1642: }
1643: }
1644: }
1.137 raeburn 1645: this.document.cstrprint.submit();
1646: return;
1647: }
1.121 raeburn 1648: if (url !='') {
1649: this.document.constspace.filename.value = filename;
1650: this.document.constspace.action = url;
1651: this.document.constspace.submit();
1652: }
1653: }
1654:
1.131 raeburn 1655: function golist(url) {
1656: if (url!='' && url!= null) {
1657: currentURL = null;
1658: currentSymb= null;
1659: top.location.href=url;
1660: }
1661: }
1662:
1663:
1.121 raeburn 1664:
1.57 www 1665: function catalog_info() {
1.102 albertel 1666: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.57 www 1667: }
1668:
1669: function chat_win() {
1.290 raeburn 1670: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42 www 1671: }
1.169 raeburn 1672:
1673: function group_chat(group) {
1674: var url = '/adm/groupchat?group='+group;
1675: var winName = 'LONchat_'+group;
1676: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1677: }
1.175 albertel 1678:
1679: function edit_bookmarks() {
1680: go('');
1681: w_BookmarkPal_flag=1;
1682: bookmarkpal=window.open("/adm/bookmarks",
1.315.2.1! raeburn 1683: "BookmarkPal", "width=500,height=505,scrollbars=0");
1.175 albertel 1684: }
1685:
1686: function annotate() {
1687: w_Annotator_flag=1;
1688: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1689: annotator.document.write(
1690: '$start_page_annotate'
1691: +"<form name='goannotate' target='Annotator' method='post' "
1692: +"action='/adm/annotations'>"
1.217 albertel 1693: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181 albertel 1694: +"<\\/form>"
1.205 albertel 1695: +'$end_page_annotate');
1.175 albertel 1696: annotator.document.close();
1697: }
1698:
1699: function set_bookmark() {
1700: go('');
1701: clienttitle=document.title;
1702: clienthref=location.pathname;
1703: w_bmquery_flag=1;
1704: bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
1705: bmquery.document.write(
1706: '$start_page_bookmark'
1.260 bisitz 1707: +'<center><form method="post"'
1708: +' name="newlink" action="/adm/bookmarks" target="bmquery" '
1709: +'> <table width="340" height="150" '
1710: +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
1711: +'type="text" name="title" size="45" value="'+clienttitle+'" />'
1712: +'<br />Address:<br /><input type="text" name="address" size="45" '
1713: +'value="'+clienthref+'" /><br /><center><input type="submit" '
1714: +'value="Save" /> <input type="button" value="Close" '
1715: +'onclick="javascript:window.close();" /></center></td>'
1716: +'</tr></table></form></center>'
1.205 albertel 1717: +'$end_page_bookmark' );
1.175 albertel 1718: bmquery.document.close();
1719: }
1720:
1.42 www 1721: ENDUTILITY
1722: }
1723:
1724: sub serverform {
1725: return(<<ENDSERVERFORM);
1.181 albertel 1726: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 1727: <input type="hidden" name="postdata" value="none" />
1728: <input type="hidden" name="command" value="none" />
1729: <input type="hidden" name="url" value="none" />
1730: <input type="hidden" name="symb" value="none" />
1731: </form>
1732: ENDSERVERFORM
1733: }
1.113 albertel 1734:
1.121 raeburn 1735: sub constspaceform {
1736: return(<<ENDCONSTSPACEFORM);
1.181 albertel 1737: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121 raeburn 1738: <input type="hidden" name="filename" value="" />
1739: </form>
1.181 albertel 1740: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121 raeburn 1741: <input type="hidden" name="action" value="delete" />
1742: <input type="hidden" name="filename" value="" />
1743: </form>
1.181 albertel 1744: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137 raeburn 1745: <input type="hidden" name="postdata" value="" />
1746: <input type="hidden" name="curseed" value="" />
1747: <input type="hidden" name="problemtype" value="" />
1748: </form>
1749:
1.121 raeburn 1750: ENDCONSTSPACEFORM
1751: }
1752:
1753:
1.113 albertel 1754: sub get_nav_status {
1755: my $navstatus="swmenu.w_loncapanav_flag=";
1.152 albertel 1756: if ($env{'environment.remotenavmap'} eq 'on') {
1.113 albertel 1757: $navstatus.="1";
1758: } else {
1759: $navstatus.="-1";
1760: }
1761: return $navstatus;
1762: }
1763:
1.220 raeburn 1764: sub hidden_button_check {
1765: my $hidden;
1766: if ($env{'request.course.id'} eq '') {
1767: return;
1768: }
1769: if ($env{'request.role.adv'}) {
1770: return;
1771: }
1.232 raeburn 1772: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1773: return $buttonshide;
1.220 raeburn 1774: }
1.184 raeburn 1775:
1.235 raeburn 1776: sub roles_selector {
1777: my ($cdom,$cnum) = @_;
1.298 raeburn 1778: my $crstype = &Apache::loncommon::course_type();
1.235 raeburn 1779: my $now = time;
1.262 raeburn 1780: my (%courseroles,%seccount);
1.235 raeburn 1781: my $is_cc;
1782: my $role_selector;
1.298 raeburn 1783: my $ccrole;
1784: if ($crstype eq 'Community') {
1785: $ccrole = 'co';
1786: } else {
1787: $ccrole = 'cc';
1788: }
1789: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
1790: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235 raeburn 1791:
1792: if ((($start) && ($start<0)) ||
1793: (($end) && ($end<$now)) ||
1794: (($start) && ($now<$start))) {
1795: $is_cc = 0;
1796: } else {
1797: $is_cc = 1;
1798: }
1799: }
1800: if ($is_cc) {
1.264 raeburn 1801: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
1.235 raeburn 1802: } else {
1.262 raeburn 1803: my %gotnosection;
1.235 raeburn 1804: foreach my $item (keys(%env)) {
1.239 raeburn 1805: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235 raeburn 1806: my $role = $1;
1807: my $sec = $2;
1808: next if ($role eq 'gr');
1809: my ($start,$end) = split(/\./,$env{$item});
1810: next if (($start && $start > $now) || ($end && $end < $now));
1811: if ($sec eq '') {
1.239 raeburn 1812: if (!$gotnosection{$role}) {
1813: $seccount{$role} ++;
1814: $gotnosection{$role} = 1;
1815: }
1.235 raeburn 1816: }
1817: if (ref($courseroles{$role}) eq 'ARRAY') {
1.239 raeburn 1818: if ($sec ne '') {
1.264 raeburn 1819: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239 raeburn 1820: push(@{$courseroles{$role}},$sec);
1821: $seccount{$role} ++;
1822: }
1823: }
1824: } else {
1825: @{$courseroles{$role}} = ();
1826: if ($sec ne '') {
1827: $seccount{$role} ++;
1.235 raeburn 1828: push(@{$courseroles{$role}},$sec);
1829: }
1830: }
1831: }
1832: }
1833: }
1.286 raeburn 1834: my $switchtext;
1835: if ($crstype eq 'Community') {
1836: $switchtext = &mt('Switch community role to...')
1837: } else {
1838: $switchtext = &mt('Switch course role to...')
1839: }
1.298 raeburn 1840: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.235 raeburn 1841: if (keys(%courseroles) > 1) {
1.239 raeburn 1842: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
1.235 raeburn 1843: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
1844: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1.286 raeburn 1845: $role_selector .= '<option value="">'.$switchtext.'</option>';
1.235 raeburn 1846: foreach my $role (@roles_order) {
1847: if (defined($courseroles{$role})) {
1.298 raeburn 1848: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>';
1.235 raeburn 1849: }
1850: }
1851: foreach my $role (sort(keys(%courseroles))) {
1852: if ($role =~ /^cr/) {
1853: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1854: }
1855: }
1856: $role_selector .= '</select>'."\n".
1857: '<input type="hidden" name="destinationurl" value="'.
1.282 amueller 1858: &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n".
1.235 raeburn 1859: '<input type="hidden" name="gotorole" value="1" />'."\n".
1860: '<input type="hidden" name="selectrole" value="" />'."\n".
1861: '<input type="hidden" name="switch" value="1" />'."\n".
1862: '</form>';
1863: }
1864: return $role_selector;
1865: }
1866:
1.262 raeburn 1867: sub get_all_courseroles {
1868: my ($cdom,$cnum,$courseroles,$seccount) = @_;
1869: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
1870: return;
1871: }
1872: my ($result,$cached) =
1873: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1874: if (defined($cached)) {
1875: if (ref($result) eq 'HASH') {
1876: if ((ref($result->{'roles'}) eq 'HASH') &&
1877: (ref($result->{'seccount'}) eq 'HASH')) {
1878: %{$courseroles} = %{$result->{'roles'}};
1879: %{$seccount} = %{$result->{'seccount'}};
1880: return;
1881: }
1882: }
1883: }
1884: my %gotnosection;
1885: my %adv_roles =
1886: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1887: foreach my $role (keys(%adv_roles)) {
1888: my ($urole,$usec) = split(/:/,$role);
1889: if (!$gotnosection{$urole}) {
1890: $seccount->{$urole} ++;
1891: $gotnosection{$urole} = 1;
1892: }
1893: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1894: if ($usec ne '') {
1895: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1896: push(@{$courseroles->{$urole}},$usec);
1897: $seccount->{$urole} ++;
1898: }
1899: }
1900: } else {
1901: @{$courseroles->{$urole}} = ();
1902: if ($usec ne '') {
1903: $seccount->{$urole} ++;
1904: push(@{$courseroles->{$urole}},$usec);
1905: }
1906: }
1907: }
1908: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1909: @{$courseroles->{'st'}} = ();
1910: if (keys(%sections_count) > 0) {
1911: push(@{$courseroles->{'st'}},keys(%sections_count));
1912: $seccount->{'st'} = scalar(keys(%sections_count));
1913: }
1914: my $rolehash = {
1915: 'roles' => $courseroles,
1916: 'seccount' => $seccount,
1917: };
1918: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1919: return;
1920: }
1921:
1.235 raeburn 1922: sub jump_to_role {
1.239 raeburn 1923: my ($cdom,$cnum,$seccount,$courseroles) = @_;
1924: my %lt = &Apache::lonlocal::texthash(
1925: this => 'This role has section(s) associated with it.',
1926: ente => 'Enter a specific section.',
1927: orlb => 'Enter a specific section, or leave blank for no section.',
1928: avai => 'Available sections are:',
1929: youe => 'You entered an invalid section choice:',
1930: plst => 'Please try again',
1931: );
1932: my $js;
1933: if (ref($courseroles) eq 'HASH') {
1934: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1935: ' var numsec = new Array();'."\n".
1936: ' var rolesections = new Array();'."\n".
1937: ' var rolenames = new Array();'."\n".
1938: ' var roleseclist = new Array();'."\n";
1939: my @items = keys(%{$courseroles});
1940: for (my $i=0; $i<@items; $i++) {
1941: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1942: my ($secs,$secstr);
1943: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1944: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1945: $secs = join('","',@sections);
1946: $secstr = join(', ',@sections);
1947: }
1948: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1949: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1950: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1951: }
1952: }
1.273 droeschl 1953: return <<"END";
1.235 raeburn 1954: <script type="text/javascript">
1.273 droeschl 1955: //<![CDATA[
1.235 raeburn 1956: function adhocRole(roleitem) {
1.239 raeburn 1957: $js
1.235 raeburn 1958: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
1959: if (newrole == '') {
1960: return;
1961: }
1.239 raeburn 1962: var fullrole = newrole+'./$cdom/$cnum';
1963: var selidx = '';
1964: for (var i=0; i<rolenames.length; i++) {
1965: if (rolenames[i] == newrole) {
1966: selidx = i;
1967: }
1968: }
1969: var secok = 1;
1970: var secchoice = '';
1971: if (selidx >= 0) {
1972: if (numsec[selidx] > 1) {
1973: secok = 0;
1974: var numrolesec = rolesections[selidx].length;
1975: var msgidx = numsec[selidx] - numrolesec;
1976: secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1977: if (secchoice == '') {
1978: if (msgidx > 0) {
1979: secok = 1;
1980: }
1981: } else {
1982: for (var j=0; j<rolesections[selidx].length; j++) {
1983: if (rolesections[selidx][j] == secchoice) {
1984: secok = 1;
1985: }
1986: }
1987: }
1988: } else {
1989: if (rolesections[selidx].length == 1) {
1990: secchoice = rolesections[selidx][0];
1991: }
1992: }
1993: }
1994: if (secok == 1) {
1995: if (secchoice != '') {
1996: fullrole += '/'+secchoice;
1997: }
1998: } else {
1999: document.rolechooser.elements[roleitem].selectedIndex = 0;
2000: if (secchoice != null) {
2001: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
2002: }
2003: return;
2004: }
2005: if (fullrole == "$env{'request.role'}") {
1.235 raeburn 2006: return;
2007: }
2008: itemid = retrieveIndex('gotorole');
2009: if (itemid != -1) {
1.239 raeburn 2010: document.rolechooser.elements[itemid].name = fullrole;
1.235 raeburn 2011: }
1.239 raeburn 2012: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1.235 raeburn 2013: document.rolechooser.selectrole.value = '1';
2014: document.rolechooser.submit();
2015: return;
2016: }
2017:
2018: function retrieveIndex(item) {
2019: for (var i=0;i<document.rolechooser.elements.length;i++) {
2020: if (document.rolechooser.elements[i].name == item) {
2021: return i;
2022: }
2023: }
2024: return -1;
2025: }
1.273 droeschl 2026: // ]]>
1.235 raeburn 2027: </script>
2028: END
2029: }
2030:
2031:
1.2 www 2032: # ================================================================ Main Program
2033:
1.16 harris41 2034: BEGIN {
1.166 albertel 2035: if (! defined($readdesk)) {
1.283 droeschl 2036: {
2037: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
2038: if ( CORE::open( my $config,"<$tabfile") ) {
2039: while (my $configline=<$config>) {
2040: $configline=(split(/\#/,$configline))[0];
2041: $configline=~s/^\s+//;
2042: chomp($configline);
1.209 www 2043: if ($configline=~/^cat\:/) {
1.283 droeschl 2044: my @entries=split(/\:/,$configline);
2045: $category_positions{$entries[2]}=$entries[1];
2046: $category_names{$entries[2]}=$entries[3];
2047: } elsif ($configline=~/^prim\:/) {
2048: my @entries = (split(/\:/, $configline))[1..5];
2049: push @primary_menu, \@entries;
2050: } elsif ($configline=~/^scnd\:/) {
2051: my @entries = (split(/\:/, $configline))[1..5];
2052: push @secondary_menu, \@entries;
2053: } elsif ($configline) {
2054: push(@desklines,$configline);
2055: }
2056: }
2057: CORE::close($config);
2058: }
2059: }
2060: $readdesk='done';
1.2 www 2061: }
2062: }
1.30 www 2063:
1.1 www 2064: 1;
2065: __END__
2066:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>