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