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