File:
[LON-CAPA] /
loncom /
interface /
lonmenu.pm
Revision
1.271:
download - view:
text,
annotated -
select for diffs
Wed Jul 8 18:36:26 2009 UTC (15 years, 1 month ago) by
droeschl
Branches:
MAIN
CVS tags:
HEAD
Changes related to modification of LON-CAPA screen header.
- improved public problem and syllabus view
- improved floating behavior of TabMainMenuContent (this fixes a bug regarding the menubuttons table in construction space)
- resource preview popup (i.e. example problems, problems opened from browse resources) doesn't show user info anymore
1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.271 2009/07/08 18:36:26 droeschl 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 convert_menu_function()
117:
118: FIXME this needs to move into mydesktab and the other locations
119: the text is generated
120:
121: =item hidden_button_check()
122:
123: =item roles_selector()
124:
125: =item jump_to_role()
126:
127: =back
128:
129: =cut
130:
131: package Apache::lonmenu;
132:
133: use strict;
134: use Apache::lonnet;
135: use Apache::lonhtmlcommon();
136: use Apache::loncommon();
137: use Apache::lonenc();
138: use Apache::lonlocal;
139: use LONCAPA qw(:DEFAULT :match);
140:
141: use vars qw(@desklines %category_names %category_members %category_positions $readdesk);
142:
143:
144: my @inlineremote;
145:
146: sub initlittle {
147: return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
148: 'nav' => 'Navigate Contents',
149: 'main' => 'Main Menu',
150: 'roles' => (&Apache::loncommon::show_course()?
151: 'Courses':'Roles'),
152: 'other' => 'Other Roles',
153: 'docs' => 'Edit Course',
154: 'exit' => 'Logout',
155: 'login' => 'Log In',
156: 'launch' => 'Launch Remote Control',
157: 'groups' => 'Groups',
158: 'gdoc' => 'Group Documents',
159: );
160: }
161:
162: sub menubuttons {
163: my $forcereg=shift;
164: my $registration=shift;
165: my $titletable=shift;
166: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
167: ['inhibitmenu']);
168: if (($env{'form.inhibitmenu'} eq 'yes') ||
169: ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
170:
171: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
172:
173: my %lt=&initlittle();
174: my $navmaps='';
175: my $reloadlink='';
176: my $docs='';
177: my $groups='';
178: my $roles='<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
179: my $role_selector;
180: my $showgroups=0;
181: my ($cnum,$cdom);
182: my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
183: my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
184:
185: my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
186: $logo = '<a href="/adm/about.html"><img src="'.
187: $logo.'" alt="LON-CAPA Logo" class="LC_noBorder" /></a>';
188:
189: if ($env{'request.state'} eq 'construct') {
190: if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
191: my $returnurl = $env{'request.filename'};
192: $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
193: $escurl = &escape($returnurl);
194: }
195: }
196: if ($env{'request.course.id'}) {
197: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
198: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
199: my %coursegroups;
200: my $viewgrps_permission =
201: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
202: if (!$viewgrps_permission) {
203: %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum);
204: }
205: if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
206: $showgroups = 1;
207: }
208: $role_selector = &roles_selector($cdom,$cnum);
209: if ($role_selector) {
210: $roles = '<span class="LC_nobreak">'.$role_selector.' <a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></span>';
211: }
212: }
213:
214: if ($env{'environment.remote'} eq 'off') {
215: # Remote Control is switched off
216: # figure out colors
217: my %lt=&initlittle();
218:
219: my $domain=&Apache::loncommon::determinedomain();
220: my $function =&Apache::loncommon::get_users_function();
221: my $link=&Apache::loncommon::designparm($function.'.link',$domain);
222: my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
223: my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
224: my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
225:
226: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
227: return (<<ENDINLINEMENU);
228: <ol class="LC_smallMenu LC_right">
229: <li>$logo</li>
230: <li><a href="/adm/roles" target="_top">$lt{'login'}</a></li>
231: </ol>
232: <hr />
233: ENDINLINEMENU
234: }
235: $roles = '<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
236: # Do we have a NAV link?
237: if ($env{'request.course.id'}) {
238: my $link='/adm/navmaps?postdata='.$escurl.'&postsymb='.
239: $escsymb;
240: if ($env{'environment.remotenavmap'} eq 'on') {
241: $link="javascript:gonav('".$link."')";
242: }
243: $navmaps=(<<ENDNAV);
244: <li><a href="$link" target="_top">$lt{'nav'}</a></li>
245: ENDNAV
246: my $is_group = (&Apache::loncommon::course_type() eq 'Group');
247: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
248: my $text = ($is_group) ? $lt{'gdoc'} : $lt{'docs'};
249: $docs=(<<ENDDOCS);
250: <li><a href="/adm/coursedocs" target="_top">$text</a></li>
251: ENDDOCS
252: }
253: if ($showgroups) {
254: $groups =(<<ENDGROUPS);
255: <li><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></li>
256: ENDGROUPS
257: }
258: if (&show_return_link()) {
259: my $escreload=&escape('return:');
260: $reloadlink=(<<ENDRELOAD);
261: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
262: ENDRELOAD
263: }
264: if ($role_selector) {
265: #$roles = '<td>'.$role_selector.'</td><td><a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></td>';
266: $role_selector = '<li>'.$role_selector.'</li>';
267: }
268: }
269: if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
270: my $escreload=&escape('return:');
271: $reloadlink=(<<ENDCRELOAD);
272: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
273: ENDCRELOAD
274: }
275: my $reg='';
276: if ($registration) {
277: $reg=&innerregister($forcereg,$titletable);
278: }
279: my $form=&serverform();
280: my $utility=&utilityfunctions();
281:
282: my $messagelink = "";
283: if(&Apache::lonmsg::mynewmail()){
284: $messagelink = '<a href="javascript:go(\'/adm/communicate\');">Message(new)</a>'
285: }else{
286: $messagelink = '<a href="javascript:go(\'/adm/communicate\');">Message</a>'
287: }
288: my $helplink=&Apache::loncommon::top_nav_help('Help');
289: return (<<ENDINLINEMENU);
290: <script type="text/javascript">
291: // BEGIN LON-CAPA Internal
292: // <![CDATA[
293: $utility
294: // ]]>
295: </script>
296: <ol class="LC_smallMenu LC_right">
297: <li>$logo</li>
298: <li>$messagelink</li>
299: <li>$roles</li>
300: <li>$helplink</li>
301: <li><a href="/adm/logout" target="_top">$lt{'exit'}</a></li>
302: </ol>
303: <ul id="LC_TabMainMenuContent">
304: <li><a href="/adm/menu" target="_top">$lt{'main'}</a></li>
305: $reloadlink
306: $navmaps
307: $docs
308: $groups
309: $role_selector
310: </ul>
311: $form
312: <script type="text/javascript">
313: // END LON-CAPA Internal
314: </script>
315: $reg
316: ENDINLINEMENU
317: } else {
318: return '';
319: }
320: }
321:
322: sub show_return_link {
323: return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
324: $env{'request.symb'} eq '')
325: ||
326: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
327: ||
328: (($env{'request.noversionuri'}=~/^\/adm\//) &&
329: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
330: ($env{'request.noversionuri'}!~
331: m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
332: ));
333: }
334:
335:
336: sub registerurl {
337: my ($forcereg) = @_;
338: my $result = '';
339: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
340: my $force_title='';
341: if ($env{'request.state'} eq 'construct') {
342: $force_title=&Apache::lonxml::display_title();
343: }
344: if (($env{'environment.remote'} eq 'off') ||
345: ((($env{'request.publicaccess'}) ||
346: (!&Apache::lonnet::is_on_map(
347: &unescape($env{'request.noversionuri'})))) &&
348: (!$forcereg))) {
349: return $result.
350: '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title;
351: }
352: # Graphical display after login only
353: if ($env{'request.registered'} && !$forcereg) { return ''; }
354: $result.=&innerregister($forcereg);
355: return $result.$force_title;
356: }
357:
358: sub innerregister {
359: my ($forcereg, $titletable) = @_;
360: my $result = '';
361: my ($uname,$thisdisfn);
362: my $const_space = ($env{'request.state'} eq 'construct');
363: my $is_const_dir = 0;
364:
365: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
366:
367: $env{'request.registered'} = 1;
368:
369: my $noremote = ($env{'environment.remote'} eq 'off');
370:
371: undef(@inlineremote);
372:
373: my $reopen=&Apache::lonmenu::reopenmenu();
374:
375: my $newmail='';
376: my $breadcrumb;
377:
378: if (&Apache::lonmsg::newmail() && !$noremote) {
379: # We have new mail and remote is up
380: $newmail= 'swmenu.setstatus("you have","messages");';
381: }
382: if ($noremote
383: && ($env{'request.symb'})
384: && ($env{'request.course.id'})) {
385:
386: my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
387: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
388:
389: my $maptitle = &Apache::lonnet::gettitle($mapurl);
390: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
391: my @crumbs = ({text => "Course Content",
392: href => "Javascript:gonav('/adm/navmaps')"},
393: {text => '...',
394: no_mt => 1});
395:
396: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
397: && $maptitle ne 'default.sequence'
398: && $maptitle ne $coursetitle);
399:
400: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
401:
402: Apache::lonhtmlcommon::clear_breadcrumbs();
403: Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
404: $breadcrumb .= Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
405: #
406: }
407: if ($env{'request.state'} eq 'construct') {
408: $newmail = $titletable;
409: }
410: my $timesync = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
411: my $tablestart = ( $noremote ? '<table id="LC_menubuttons">' : '');
412: my $tableend = ( $noremote ? '</table>' : '');
413: # =============================================================================
414: # ============================ This is for URLs that actually can be registered
415: if (($env{'request.noversionuri'}!~m|^/(res/)*adm/|) || ($forcereg)) {
416: # -- This applies to homework problems for users with grading privileges
417: my $crs='/'.$env{'request.course.id'};
418: if ($env{'request.course.sec'}) {
419: $crs.='_'.$env{'request.course.sec'};
420: }
421: $crs=~s/\_/\//g;
422:
423: my $hwkadd='';
424: if ($env{'request.symb'} ne '' &&
425: $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
426: if (&Apache::lonnet::allowed('mgr',$crs)) {
427: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]',
428: "gocmd('/adm/grades','gradingmenu')",
429: 'Modify user grades for this assessment resource');
430: } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
431: $hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
432: "gocmd('/adm/grades','submission')",
433: 'View user submissions for this assessment resource');
434: }
435: }
436: if ($env{'request.symb'} ne '' &&
437: &Apache::lonnet::allowed('opa',$crs)) {
438: $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
439: "gocmd('/adm/parmset','set')",
440: 'Modify parameter settings for this resource');
441: }
442: # -- End Homework
443: ###
444: ### Determine whether or not to display the 'cstr' button for this
445: ### resource
446: ###
447: my $editbutton = '';
448: my $noeditbutton = 1;
449: my ($cnum,$cdom);
450: if ($env{'request.course.id'}) {
451: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
452: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
453: }
454: if ($env{'user.author'}) {
455: if ($env{'request.role'}=~/^(aa|ca|au)/) {
456: # Set defaults for authors
457: my ($top,$bottom) = ('con-','struct');
458: my $action = "go('/priv/".$env{'user.name'}."');";
459: my $cadom = $env{'request.role.domain'};
460: my $caname = $env{'user.name'};
461: my $desc = "Enter my construction space";
462: # Set defaults for co-authors
463: if ($env{'request.role'} =~ /^ca/) {
464: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
465: ($top,$bottom) = ('co con-','struct');
466: $action = "go('/priv/".$caname."');";
467: $desc = "Enter construction space as co-author";
468: } elsif ($env{'request.role'} =~ /^aa/) {
469: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
470: ($top,$bottom) = ('co con-','struct');
471: $action = "go('/priv/".$caname."');";
472: $desc = "Enter construction space as assistant co-author";
473: }
474: # Check that we are on the correct machine
475: my $home = &Apache::lonnet::homeserver($caname,$cadom);
476: my $allowed=0;
477: my @ids=&Apache::lonnet::current_machine_ids();
478: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
479: if (!$allowed) {
480: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
481: $noeditbutton = 0;
482: }
483: }
484: ##
485: ## Determine if user can edit url.
486: ##
487: my $cfile='';
488: my $cfuname='';
489: my $cfudom='';
490: my $uploaded;
491: if ($env{'request.filename'}) {
492: my $file=&Apache::lonnet::declutter($env{'request.filename'});
493: if (defined($cnum) && defined($cdom)) {
494: $uploaded = &is_course_upload($file,$cnum,$cdom);
495: }
496: if (!$uploaded) {
497: $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
498: # Check that the user has permission to edit this resource
499: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
500: if (defined($cfudom)) {
501: my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
502: my $allowed=0;
503: my @ids=&Apache::lonnet::current_machine_ids();
504: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
505: if ($allowed) {
506: $cfile=$file;
507: }
508: }
509: }
510: }
511: # Finally, turn the button on or off
512: if ($cfile && !$const_space) {
513: $editbutton=&switch
514: ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
515: "go('".$cfile."');","Edit this resource");
516: $noeditbutton = 0;
517: } elsif ($editbutton eq '') {
518: $editbutton=&clear(6,1);
519: }
520: }
521: if (($noeditbutton) && ($env{'request.filename'})) {
522: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
523: my $file=&Apache::lonnet::declutter($env{'request.filename'});
524: if (defined($cnum) && defined($cdom)) {
525: if (&is_course_upload($file,$cnum,$cdom)) {
526: my $cfile = &edit_course_upload($file,$cnum,$cdom);
527: if ($cfile) {
528: $editbutton=&switch
529: ('','',6,1,'pcstr.gif','edit[_1]',
530: 'resource[_2]',"go('".$cfile."');",
531: 'Edit this resource');
532: }
533: }
534: }
535: }
536: }
537: ###
538: ###
539: # Prepare the rest of the buttons
540: my $menuitems;
541: if ($const_space) {
542: my ($uname,$thisdisfn) =
543: ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
544: my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
545: if ($currdir =~ m-/$-) {
546: $is_const_dir = 1;
547: } else {
548: $currdir =~ s|[^/]+$||;
549: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
550: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
551: $menuitems=(<<ENDMENUITEMS);
552: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
553: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
554: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
555: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
556: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
557: ENDMENUITEMS
558: }
559: } elsif ( defined($env{'request.course.id'}) &&
560: $env{'request.symb'} ne '' ) {
561: $menuitems=(<<ENDMENUITEMS);
562: c&3&1
563: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
564: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
565: c&6&3
566: c&8&1
567: c&8&2
568: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
569: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
570: ENDMENUITEMS
571:
572: my $currentURL = &Apache::loncommon::get_symb();
573: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
574: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
575: $menuitems.="s&9&3&";
576: if(length($annotation) > 0){
577: $menuitems.="anot2.gif";
578: }else{
579: $menuitems.="anot.gif";
580: }
581: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
582: $menuitems.="Make notes and annotations about this resource&&1\n";
583:
584: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
585: if (!$env{'request.enc'}) {
586: $menuitems.=(<<ENDREALRES);
587: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
588: ENDREALRES
589: }
590: $menuitems.=(<<ENDREALRES);
591: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
592: 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
593: ENDREALRES
594: }
595: }
596: if ($env{'request.uri'} =~ /^\/res/) {
597: $menuitems .= (<<ENDMENUITEMS);
598: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
599: ENDMENUITEMS
600: }
601: my $buttons='';
602: foreach (split(/\n/,$menuitems)) {
603: my ($command,@rest)=split(/\&/,$_);
604: my $idx=10*$rest[0]+$rest[1];
605: if (&hidden_button_check() eq 'yes') {
606: if ($idx == 21 ||$idx == 23) {
607: $buttons.=&switch('','',@rest);
608: } else {
609: $buttons.=&clear(@rest);
610: }
611: } else {
612: if ($command eq 's') {
613: $buttons.=&switch('','',@rest);
614: } else {
615: $buttons.=&clear(@rest);
616: }
617: }
618: }
619:
620: if ($noremote) {
621: my $addremote=0;
622: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
623: my $inlinebuttons='';
624: if ($addremote) {
625: # Registered, textual output
626: if ($env{'environment.icons'} eq 'iconsonly') {
627: $inlinebuttons=(<<ENDARROWSINLINE);
628: <tr><td>
629: $inlineremote[21] $inlineremote[23]
630: ENDARROWSINLINE
631: if (&hidden_button_check() ne 'yes') {
632: $inlinebuttons .= (<<ENDINLINEICONS);
633: $inlineremote[61] $inlineremote[63]
634: $inlineremote[71] $inlineremote[72] $inlineremote[73]
635: $inlineremote[81] $inlineremote[82] $inlineremote[83]
636: $inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
637: ENDINLINEICONS
638: }
639: } else {
640: if ($inlineremote[21] ne '' || $inlineremote[23] ne '') {
641: $inlinebuttons=(<<ENDFIRSTLINE);
642: <tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr>
643: ENDFIRSTLINE
644: }
645: if (&hidden_button_check() ne 'yes') {
646: foreach my $row (6..9) {
647: if ($inlineremote[${row}.'1'] ne ''
648: || $inlineremote[$row.'2'] ne ''
649: || $inlineremote[$row.'3'] ne '') {
650: $inlinebuttons .= <<"ENDLINE";
651: <tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
652: ENDLINE
653: }
654: }
655: }
656: }
657: }
658: $result =(<<ENDREGTEXT);
659: <script type="text/javascript">
660: // BEGIN LON-CAPA Internal
661: </script>
662: $timesync
663: $breadcrumb
664: $tablestart
665: $inlinebuttons
666: $tableend
667: $newmail
668: <script type="text/javascript">
669: // END LON-CAPA Internal
670: </script>
671:
672: ENDREGTEXT
673: # Registered, graphical output
674: } else {
675: my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
676: $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
677: my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
678: my $navstatus=&get_nav_status();
679: my $clearcstr;
680:
681: if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
682: $result = (<<ENDREGTHIS);
683:
684: <script type="text/javascript">
685: // BEGIN LON-CAPA Internal
686: var swmenu=null;
687:
688: function LONCAPAreg() {
689: swmenu=$reopen;
690: swmenu.clearTimeout(swmenu.menucltim);
691: $timesync
692: $newmail
693: $buttons
694: swmenu.currentURL="$requri";
695: swmenu.reloadURL=swmenu.currentURL+window.location.search;
696: swmenu.currentSymb="$cursymb";
697: swmenu.reloadSymb="$cursymb";
698: swmenu.currentStale=0;
699: $navstatus
700: $hwkadd
701: $editbutton
702: }
703:
704: function LONCAPAstale() {
705: swmenu=$reopen
706: swmenu.currentStale=1;
707: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
708: swmenu.switchbutton
709: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
710: }
711: swmenu.clearbut(7,2);
712: swmenu.clearbut(7,3);
713: swmenu.menucltim=swmenu.setTimeout(
714: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
715: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
716: 2000);
717: }
718:
719: // END LON-CAPA Internal
720: </script>
721: ENDREGTHIS
722: }
723: # =============================================================================
724: } else {
725: # ========================================== This can or will not be registered
726: if ($noremote) {
727: # Not registered
728: $result= (<<ENDDONOTREGTEXT);
729: ENDDONOTREGTEXT
730: } else {
731: # Not registered, graphical
732: $result = (<<ENDDONOTREGTHIS);
733:
734: <script type="text/javascript">
735: // BEGIN LON-CAPA Internal
736: var swmenu=null;
737:
738: function LONCAPAreg() {
739: swmenu=$reopen
740: $timesync
741: swmenu.currentStale=1;
742: swmenu.clearbut(2,1);
743: swmenu.clearbut(2,3);
744: swmenu.clearbut(8,1);
745: swmenu.clearbut(8,2);
746: swmenu.clearbut(8,3);
747: if (swmenu.currentURL) {
748: swmenu.switchbutton
749: (3,1,'reload.gif','return','location','go(currentURL)');
750: } else {
751: swmenu.clearbut(3,1);
752: }
753: }
754:
755: function LONCAPAstale() {
756: }
757:
758: // END LON-CAPA Internal
759: </script>
760: ENDDONOTREGTHIS
761: }
762: # =============================================================================
763: }
764: return $result;
765: }
766:
767: sub is_course_upload {
768: my ($file,$cnum,$cdom) = @_;
769: my $uploadpath = &LONCAPA::propath($cdom,$cnum);
770: $uploadpath =~ s{^\/}{};
771: if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
772: ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
773: return 1;
774: }
775: return;
776: }
777:
778: sub edit_course_upload {
779: my ($file,$cnum,$cdom) = @_;
780: my $cfile;
781: if ($file =~/\.(htm|html|css|js|txt)$/) {
782: my $ext = $1;
783: my $url = &Apache::lonnet::hreflocation('',$file);
784: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
785: my @ids=&Apache::lonnet::current_machine_ids();
786: my $dest;
787: if ($home && grep(/^\Q$home\E$/,@ids)) {
788: $dest = $url.'?forceedit=1';
789: } else {
790: unless (&Apache::lonnet::get_locks()) {
791: $dest = '/adm/switchserver?otherserver='.
792: $home.'&role='.$env{'request.role'}.
793: '&url='.$url.'&forceedit=1';
794: }
795: }
796: if ($dest) {
797: $cfile = &HTML::Entities::encode($dest,'"<>&');
798: }
799: }
800: return $cfile;
801: }
802:
803: sub loadevents() {
804: if ($env{'request.state'} eq 'construct' ||
805: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
806: return 'LONCAPAreg();';
807: }
808:
809: sub unloadevents() {
810: if ($env{'request.state'} eq 'construct' ||
811: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
812: return 'LONCAPAstale();';
813: }
814:
815:
816: sub startupremote {
817: my ($lowerurl)=@_;
818: if ($env{'environment.remote'} eq 'off') {
819: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
820: }
821: #
822: # The Remote actually gets launched!
823: #
824: my $configmenu=&rawconfig();
825: my $esclowerurl=&escape($lowerurl);
826: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
827: return(<<ENDREMOTESTARTUP);
828: <script type="text/javascript">
829: var timestart;
830: function wheelswitch() {
831: if (typeof(document.wheel) != 'undefined') {
832: if (typeof(document.wheel.spin) != 'undefined') {
833: var date=new Date();
834: var waited=Math.round(30-((date.getTime()-timestart)/1000));
835: document.wheel.spin.value=$message;
836: }
837: }
838: if (window.status=='|') {
839: window.status='/';
840: } else {
841: if (window.status=='/') {
842: window.status='-';
843: } else {
844: if (window.status=='-') {
845: window.status='\\\\';
846: } else {
847: if (window.status=='\\\\') { window.status='|'; }
848: }
849: }
850: }
851: }
852:
853: // ---------------------------------------------------------- The wait function
854: var canceltim;
855: function wait() {
856: if ((menuloaded==1) || (tim==1)) {
857: window.status='Done.';
858: if (tim==0) {
859: clearTimeout(canceltim);
860: $configmenu
861: window.location='$lowerurl';
862: } else {
863: window.location='/adm/remote?action=collapse&url=$esclowerurl';
864: }
865: } else {
866: wheelswitch();
867: setTimeout('wait();',200);
868: }
869: }
870:
871: function main() {
872: canceltim=setTimeout('tim=1;',30000);
873: window.status='-';
874: var date=new Date();
875: timestart=date.getTime();
876: wait();
877: }
878:
879: </script>
880: ENDREMOTESTARTUP
881: }
882:
883: sub setflags() {
884: return(<<ENDSETFLAGS);
885: <script type="text/javascript">
886: menuloaded=0;
887: tim=0;
888: </script>
889: ENDSETFLAGS
890: }
891:
892: sub maincall() {
893: if ($env{'environment.remote'} eq 'off') { return ''; }
894: return(<<ENDMAINCALL);
895: <script type="text/javascript">
896: main();
897: </script>
898: ENDMAINCALL
899: }
900:
901: sub load_remote_msg {
902: my ($lowerurl)=@_;
903:
904: if ($env{'environment.remote'} eq 'off') { return ''; }
905:
906: my $esclowerurl=&escape($lowerurl);
907: my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
908: ,'<a href="/adm/remote?action=collapse&url='.$esclowerurl.'">'
909: ,'</a>');
910: return(<<ENDREMOTEFORM);
911: <p>
912: <form name="wheel">
913: <input name="spin" type="text" size="60" />
914: </form>
915: </p>
916: <p>$link</p>
917: ENDREMOTEFORM
918: }
919:
920: sub get_menu_name {
921: my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
922: $hostid =~ s/\W//g;
923: return 'LCmenu'.$hostid;
924: }
925:
926:
927: sub reopenmenu {
928: if ($env{'environment.remote'} eq 'off') { return ''; }
929: my $menuname = &get_menu_name();
930: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
931: return('window.open('.$nothing.',"'.$menuname.'","",false);');
932: }
933:
934:
935: sub open {
936: my $returnval='';
937: if ($env{'environment.remote'} eq 'off') {
938: return '<script type="text/javascript">self.name="loncapaclient";</script>';
939: }
940: my $menuname = &get_menu_name();
941:
942: # unless (shift eq 'unix') {
943: # resizing does not work on linux because of virtual desktop sizes
944: # $returnval.=(<<ENDRESIZE);
945: #if (window.screen) {
946: # self.resizeTo(screen.availWidth-215,screen.availHeight-55);
947: # self.moveTo(190,15);
948: #}
949: #ENDRESIZE
950: # }
951: $returnval.=(<<ENDOPEN);
952: window.status='Opening LON-CAPA Remote Control';
953: var menu=window.open("/res/adm/pages/menu.html","$menuname",
954: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
955: self.name='loncapaclient';
956: ENDOPEN
957: return '<script type="text/javascript">'.$returnval.'</script>';
958: }
959:
960:
961: # ================================================================== Raw Config
962:
963: sub clear {
964: my ($row,$col)=@_;
965: unless ($env{'environment.remote'} eq 'off') {
966: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
967: } else {
968: $inlineremote[10*$row+$col]='';
969: return '';
970: }
971: }
972:
973: # ============================================ Switch a button or create a link
974: # Switch acts on the javascript that is executed when a button is clicked.
975: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
976:
977: sub switch {
978: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
979: $act=~s/\$uname/$uname/g;
980: $act=~s/\$udom/$udom/g;
981: $top=&mt($top);
982: $bot=&mt($bot);
983: $desc=&mt($desc);
984: if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
985: $img=&mt($img);
986: }
987: my $idx=10*$row+$col;
988: $category_members{$cat}.=':'.$idx;
989:
990: unless ($env{'environment.remote'} eq 'off') {
991: # Remote
992: return "\n".
993: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
994: } else {
995: # Inline Remote
996: if ($env{'environment.icons'} ne 'classic') {
997: $img=~s/\.gif$/\.png/;
998: }
999: if ($nobreak==2) { return ''; }
1000: my $text=$top.' '.$bot;
1001: $text=~s/\s*\-\s*//gs;
1002:
1003: my $pic=
1004: '<img alt="'.$text.'" src="'.
1005: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1006: '" align="'.($nobreak==3?'right':'left').'" class="LC_noBorder" />';
1007: if ($env{'browser.interface'} eq 'faketextual') {
1008: # Accessibility
1009: if ($nobreak==3) {
1010: $inlineremote[$idx]="\n".
1011: '<td class="LC_menubuttons_text" align="right">'.$text.
1012: '</td><td align="left">'.
1013: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1014: } elsif ($nobreak) {
1015: $inlineremote[$idx]="\n<tr>".
1016: '<td align="left">'.
1017: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1018: <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>';
1019: } else {
1020: $inlineremote[$idx]="\n<tr>".
1021: '<td align="left">'.
1022: '<a href="javascript:'.$act.';">'.$pic.
1023: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1024: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1025: }
1026: } else {
1027: # Inline Menu
1028: if ($env{'environment.icons'} eq 'iconsonly') {
1029: $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
1030: } else {
1031: $inlineremote[$idx]=
1032: '<a class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1033: '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
1034: }
1035: }
1036: }
1037: return '';
1038: }
1039:
1040: sub secondlevel {
1041: my $output='';
1042: my
1043: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1044: if ($prt eq 'any') {
1045: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1046: } elsif ($prt=~/^r(\w+)/) {
1047: if ($rol eq $1) {
1048: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1049: }
1050: }
1051: return $output;
1052: }
1053:
1054: sub openmenu {
1055: my $menuname = &get_menu_name();
1056: if ($env{'environment.remote'} eq 'off') { return ''; }
1057: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1058: return "window.open(".$nothing.",'".$menuname."');";
1059: }
1060:
1061: sub inlinemenu {
1062: undef(@inlineremote);
1063: undef(%category_members);
1064: &rawconfig(1);
1065: my $output='<table id="LC_mainmenu"><tr>';
1066: for (my $col=1; $col<=2; $col++) {
1067: $output.='<td class="LC_mainmenu_col_fieldset">';
1068: for (my $row=1; $row<=8; $row++) {
1069: foreach my $cat (keys(%category_members)) {
1070: if ($category_positions{$cat} ne "$col,$row") { next; }
1071: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1072: $output.='<div class="LC_Box">';
1073: $output.='<h4 class="LC_hcell">'.&mt($category_names{$cat}).'</h4>';
1074: $output.='<table>';
1075: my %active=();
1076: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1077: if ($inlineremote[$menu_item]) {
1078: $active{$menu_item}=1;
1079: }
1080: }
1081: foreach my $item (sort(keys(%active))) {
1082: $output.=$inlineremote[$item];
1083: }
1084: $output.='</table>';
1085: $output.='</div>';
1086: }
1087: }
1088: $output.="</td>";
1089: }
1090: $output.="</tr></table>";
1091: return $output;
1092: }
1093:
1094: sub rawconfig {
1095: my $textualoverride=shift;
1096: my $output='';
1097: unless ($env{'environment.remote'} eq 'off') {
1098: $output.=
1099: "window.status='Opening Remote Control';var swmenu=".&openmenu().
1100: "\nwindow.status='Configuring Remote Control ';";
1101: } else {
1102: unless ($textualoverride) { return ''; }
1103: }
1104: my $uname=$env{'user.name'};
1105: my $udom=$env{'user.domain'};
1106: my $adv=$env{'user.adv'};
1107: my $show_course=&Apache::loncommon::show_course();
1108: my $author=$env{'user.author'};
1109: my $crs='';
1110: if ($env{'request.course.id'}) {
1111: $crs='/'.$env{'request.course.id'};
1112: if ($env{'request.course.sec'}) {
1113: $crs.='_'.$env{'request.course.sec'};
1114: }
1115: $crs=~s/\_/\//g;
1116: }
1117: my $pub=($env{'request.state'} eq 'published');
1118: my $con=($env{'request.state'} eq 'construct');
1119: my $rol=$env{'request.role'};
1120: my $requested_domain = $env{'request.role.domain'};
1121: foreach my $line (@desklines) {
1122: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1123: $prt=~s/\$uname/$uname/g;
1124: $prt=~s/\$udom/$udom/g;
1125: $prt=~s/\$crs/$crs/g;
1126: $prt=~s/\$requested_domain/$requested_domain/g;
1127: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1128: my $type = &Apache::loncommon::course_type();
1129: if ($type eq 'Group') {
1130: $desc = &convert_menu_function($desc,$type);
1131: }
1132: if ($pro eq 'clear') {
1133: $output.=&clear($row,$col);
1134: } elsif ($pro eq 'any') {
1135: $output.=&secondlevel(
1136: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1137: } elsif ($pro eq 'smp') {
1138: unless ($adv) {
1139: $output.=&secondlevel(
1140: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1141: }
1142: } elsif ($pro eq 'adv') {
1143: if ($adv) {
1144: $output.=&secondlevel(
1145: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1146: }
1147: } elsif ($pro eq 'shc') {
1148: if ($show_course) {
1149: $output.=&secondlevel(
1150: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1151: }
1152: } elsif ($pro eq 'nsc') {
1153: if (!$show_course) {
1154: $output.=&secondlevel(
1155: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1156: }
1157: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1158: if (&Apache::lonnet::allowed($1,$prt)) {
1159: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1160: }
1161: } elsif ($pro eq 'course') {
1162: if ($env{'request.course.fn'}) {
1163: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1164: }
1165: } elsif ($pro =~ /^courseenv_(.*)$/) {
1166: my $key = $1;
1167: if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
1168: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1169: }
1170: } elsif ($pro =~ /^course_(.*)$/) {
1171: # Check for permissions inside of a course
1172: if (($env{'request.course.id'}) &&
1173: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1174: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1175: )) {
1176: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1177: }
1178: } elsif ($pro eq 'author') {
1179: if ($author) {
1180: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1181: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1182: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1183: # Check that we are on the correct machine
1184: my $cadom=$requested_domain;
1185: my $caname=$env{'user.name'};
1186: if (($prt eq 'rca') || ($prt eq 'raa')) {
1187: ($cadom,$caname)=
1188: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1189: }
1190: $act =~ s/\$caname/$caname/g;
1191: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1192: my $allowed=0;
1193: my @ids=&Apache::lonnet::current_machine_ids();
1194: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1195: if ($allowed) {
1196: $output.=&switch($caname,$cadom,
1197: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1198: }
1199: }
1200: }
1201: } elsif ($pro eq 'tools') {
1202: my @tools = ('aboutme','blog','portfolio');
1203: if (grep(/^\Q$prt\E$/,@tools)) {
1204: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1205: $env{'user.domain'},
1206: $prt,undef,'tools')) {
1207: $output.=&clear($row,$col);
1208: next;
1209: }
1210: } elsif ($prt eq 'reqcrs') {
1211: my $showreqcrs = 0;
1212: foreach my $type ('official','unofficial') {
1213: if (&Apache::lonnet::usertools_access($env{'user.name'},
1214: $env{'user.domain'},
1215: $type,undef,'requestcourses')) {
1216: $showreqcrs = 1;
1217: last;
1218: }
1219: }
1220: if (!$showreqcrs) {
1221: $output.=&clear($row,$col);
1222: next;
1223: }
1224: }
1225: $prt='any';
1226: $output.=&secondlevel(
1227: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1228: }
1229: }
1230: unless ($env{'environment.remote'} eq 'off') {
1231: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1232: if (&Apache::lonmsg::newmail()) {
1233: $output.='swmenu.setstatus("you have","messages");';
1234: }
1235: }
1236:
1237: return $output;
1238: }
1239:
1240: # ======================================================================= Close
1241:
1242: sub close {
1243: if ($env{'environment.remote'} eq 'off') { return ''; }
1244: my $menuname = &get_menu_name();
1245: return(<<ENDCLOSE);
1246: <script type="text/javascript">
1247: window.status='Accessing Remote Control';
1248: menu=window.open("/adm/rat/empty.html","$menuname",
1249: "height=350,width=150,scrollbars=no,menubar=no");
1250: window.status='Disabling Remote Control';
1251: menu.active=0;
1252: menu.autologout=0;
1253: window.status='Closing Remote Control';
1254: menu.close();
1255: window.status='Done.';
1256: </script>
1257: ENDCLOSE
1258: }
1259:
1260: # ====================================================================== Footer
1261:
1262: sub footer {
1263:
1264: }
1265:
1266: sub nav_control_js {
1267: my $nav=($env{'environment.remotenavmap'} eq 'on');
1268: return (<<NAVCONTROL);
1269: var w_loncapanav_flag="$nav";
1270:
1271:
1272: function gonav(url) {
1273: if (w_loncapanav_flag != 1) {
1274: gopost(url,'');
1275: } else {
1276: navwindow=window.open(url,
1277: "loncapanav","height=600,width=400,scrollbars=1");
1278: }
1279: }
1280: NAVCONTROL
1281: }
1282:
1283: sub utilityfunctions {
1284: my $caller = shift;
1285: unless ($env{'environment.remote'} eq 'off' ||
1286: $caller eq '/adm/menu') {
1287: return ''; }
1288:
1289: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1290: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1291:
1292: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1293: my $nav_control=&nav_control_js();
1294:
1295: my $start_page_annotate =
1296: &Apache::loncommon::start_page('Annotator',undef,
1297: {'only_body' => 1,
1298: 'js_ready' => 1,
1299: 'bgcolor' => '#BBBBBB',
1300: 'add_entries' => {
1301: 'onload' => 'javascript:document.goannotate.submit();'}});
1302:
1303: my $end_page_annotate =
1304: &Apache::loncommon::end_page({'js_ready' => 1});
1305:
1306: my $start_page_bookmark =
1307: &Apache::loncommon::start_page('Bookmarks',undef,
1308: {'only_body' => 1,
1309: 'js_ready' => 1,
1310: 'bgcolor' => '#BBBBBB',});
1311:
1312: my $end_page_bookmark =
1313: &Apache::loncommon::end_page({'js_ready' => 1});
1314:
1315: return (<<ENDUTILITY)
1316:
1317: var currentURL="$currenturl";
1318: var reloadURL="$currenturl";
1319: var currentSymb="$currentsymb";
1320:
1321: $nav_control
1322:
1323: function go(url) {
1324: if (url!='' && url!= null) {
1325: currentURL = null;
1326: currentSymb= null;
1327: window.location.href=url;
1328: }
1329: }
1330:
1331: function gopost(url,postdata) {
1332: if (url!='') {
1333: this.document.server.action=url;
1334: this.document.server.postdata.value=postdata;
1335: this.document.server.command.value='';
1336: this.document.server.url.value='';
1337: this.document.server.symb.value='';
1338: this.document.server.submit();
1339: }
1340: }
1341:
1342: function gocmd(url,cmd) {
1343: if (url!='') {
1344: this.document.server.action=url;
1345: this.document.server.postdata.value='';
1346: this.document.server.command.value=cmd;
1347: this.document.server.url.value=currentURL;
1348: this.document.server.symb.value=currentSymb;
1349: this.document.server.submit();
1350: }
1351: }
1352:
1353: function gocstr(url,filename) {
1354: if (url == '/adm/cfile?action=delete') {
1355: this.document.cstrdelete.filename.value = filename
1356: this.document.cstrdelete.submit();
1357: return;
1358: }
1359: if (url == '/adm/printout') {
1360: this.document.cstrprint.postdata.value = filename
1361: this.document.cstrprint.curseed.value = 0;
1362: this.document.cstrprint.problemtype.value = 0;
1363: if (this.document.lonhomework) {
1364: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1365: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1366: }
1367: if (this.document.lonhomework.problemtype) {
1368: if (this.document.lonhomework.problemtype.value) {
1369: this.document.cstrprint.problemtype.value =
1370: this.document.lonhomework.problemtype.value;
1371: } else if (this.document.lonhomework.problemtype.options) {
1372: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1373: if (this.document.lonhomework.problemtype.options[i].selected) {
1374: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1375: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1376: }
1377: }
1378: }
1379: }
1380: }
1381: }
1382: this.document.cstrprint.submit();
1383: return;
1384: }
1385: if (url !='') {
1386: this.document.constspace.filename.value = filename;
1387: this.document.constspace.action = url;
1388: this.document.constspace.submit();
1389: }
1390: }
1391:
1392: function golist(url) {
1393: if (url!='' && url!= null) {
1394: currentURL = null;
1395: currentSymb= null;
1396: top.location.href=url;
1397: }
1398: }
1399:
1400:
1401:
1402: function catalog_info() {
1403: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1404: }
1405:
1406: function chat_win() {
1407: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1408: }
1409:
1410: function group_chat(group) {
1411: var url = '/adm/groupchat?group='+group;
1412: var winName = 'LONchat_'+group;
1413: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1414: }
1415:
1416: function edit_bookmarks() {
1417: go('');
1418: w_BookmarkPal_flag=1;
1419: bookmarkpal=window.open("/adm/bookmarks",
1420: "BookmarkPal", "width=400,height=505,scrollbars=0");
1421: }
1422:
1423: function annotate() {
1424: w_Annotator_flag=1;
1425: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1426: annotator.document.write(
1427: '$start_page_annotate'
1428: +"<form name='goannotate' target='Annotator' method='post' "
1429: +"action='/adm/annotations'>"
1430: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1431: +"<\\/form>"
1432: +'$end_page_annotate');
1433: annotator.document.close();
1434: }
1435:
1436: function set_bookmark() {
1437: go('');
1438: clienttitle=document.title;
1439: clienthref=location.pathname;
1440: w_bmquery_flag=1;
1441: bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
1442: bmquery.document.write(
1443: '$start_page_bookmark'
1444: +'<center><form method="post"'
1445: +' name="newlink" action="/adm/bookmarks" target="bmquery" '
1446: +'> <table width="340" height="150" '
1447: +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
1448: +'type="text" name="title" size="45" value="'+clienttitle+'" />'
1449: +'<br />Address:<br /><input type="text" name="address" size="45" '
1450: +'value="'+clienthref+'" /><br /><center><input type="submit" '
1451: +'value="Save" /> <input type="button" value="Close" '
1452: +'onclick="javascript:window.close();" /></center></td>'
1453: +'</tr></table></form></center>'
1454: +'$end_page_bookmark' );
1455: bmquery.document.close();
1456: }
1457:
1458: ENDUTILITY
1459: }
1460:
1461: sub serverform {
1462: return(<<ENDSERVERFORM);
1463: <form name="server" action="/adm/logout" method="post" target="_top">
1464: <input type="hidden" name="postdata" value="none" />
1465: <input type="hidden" name="command" value="none" />
1466: <input type="hidden" name="url" value="none" />
1467: <input type="hidden" name="symb" value="none" />
1468: </form>
1469: ENDSERVERFORM
1470: }
1471:
1472: sub constspaceform {
1473: return(<<ENDCONSTSPACEFORM);
1474: <form name="constspace" action="/adm/logout" method="post" target="_top">
1475: <input type="hidden" name="filename" value="" />
1476: </form>
1477: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1478: <input type="hidden" name="action" value="delete" />
1479: <input type="hidden" name="filename" value="" />
1480: </form>
1481: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1482: <input type="hidden" name="postdata" value="" />
1483: <input type="hidden" name="curseed" value="" />
1484: <input type="hidden" name="problemtype" value="" />
1485: </form>
1486:
1487: ENDCONSTSPACEFORM
1488: }
1489:
1490:
1491: sub get_nav_status {
1492: my $navstatus="swmenu.w_loncapanav_flag=";
1493: if ($env{'environment.remotenavmap'} eq 'on') {
1494: $navstatus.="1";
1495: } else {
1496: $navstatus.="-1";
1497: }
1498: return $navstatus;
1499: }
1500:
1501: #FIXME this needs to move into mydesktab and the other locations
1502: # the text is generated
1503: sub convert_menu_function {
1504: my ($rolename,$type) = @_;
1505: if ($type eq 'Group') {
1506: $rolename =~ s/student/member/g;
1507: $rolename =~ s/group/team/g;
1508: $rolename =~ s/course/group/g;
1509: $rolename =~ s/Course/Group/g;
1510: }
1511: return $rolename;
1512: }
1513:
1514: sub hidden_button_check {
1515: my $hidden;
1516: if ($env{'request.course.id'} eq '') {
1517: return;
1518: }
1519: if ($env{'request.role.adv'}) {
1520: return;
1521: }
1522: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1523: return $buttonshide;
1524: }
1525:
1526: sub roles_selector {
1527: my ($cdom,$cnum) = @_;
1528: my $now = time;
1529: my (%courseroles,%seccount);
1530: my $is_cc;
1531: my $role_selector;
1532: if ($env{'user.role.cc./'.$cdom.'/'.$cnum}) {
1533: my ($start,$end) = split(/\./,$env{'user.role.cc./'.$cdom.'/'.$cnum});
1534:
1535: if ((($start) && ($start<0)) ||
1536: (($end) && ($end<$now)) ||
1537: (($start) && ($now<$start))) {
1538: $is_cc = 0;
1539: } else {
1540: $is_cc = 1;
1541: }
1542: }
1543: if ($is_cc) {
1544: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
1545: } else {
1546: my %gotnosection;
1547: foreach my $item (keys(%env)) {
1548: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1549: my $role = $1;
1550: my $sec = $2;
1551: next if ($role eq 'gr');
1552: my ($start,$end) = split(/\./,$env{$item});
1553: next if (($start && $start > $now) || ($end && $end < $now));
1554: if ($sec eq '') {
1555: if (!$gotnosection{$role}) {
1556: $seccount{$role} ++;
1557: $gotnosection{$role} = 1;
1558: }
1559: }
1560: if (ref($courseroles{$role}) eq 'ARRAY') {
1561: if ($sec ne '') {
1562: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1563: push(@{$courseroles{$role}},$sec);
1564: $seccount{$role} ++;
1565: }
1566: }
1567: } else {
1568: @{$courseroles{$role}} = ();
1569: if ($sec ne '') {
1570: $seccount{$role} ++;
1571: push(@{$courseroles{$role}},$sec);
1572: }
1573: }
1574: }
1575: }
1576: }
1577: my @roles_order = ('cc','in','ta','ep','ad','st');
1578: if (keys(%courseroles) > 1) {
1579: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
1580: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
1581: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1582: $role_selector .= '<option value="">'.&mt('Switch course role to...').'</option>';
1583: foreach my $role (@roles_order) {
1584: if (defined($courseroles{$role})) {
1585: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1586: }
1587: }
1588: foreach my $role (sort(keys(%courseroles))) {
1589: if ($role =~ /^cr/) {
1590: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1591: }
1592: }
1593: $role_selector .= '</select>'."\n".
1594: '<input type="hidden" name="destinationurl" value="'.
1595: $ENV{'REQUEST_URI'}.'" />'."\n".
1596: '<input type="hidden" name="gotorole" value="1" />'."\n".
1597: '<input type="hidden" name="selectrole" value="" />'."\n".
1598: '<input type="hidden" name="switch" value="1" />'."\n".
1599: '</form>';
1600: }
1601: return $role_selector;
1602: }
1603:
1604: sub get_all_courseroles {
1605: my ($cdom,$cnum,$courseroles,$seccount) = @_;
1606: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
1607: return;
1608: }
1609: my ($result,$cached) =
1610: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1611: if (defined($cached)) {
1612: if (ref($result) eq 'HASH') {
1613: if ((ref($result->{'roles'}) eq 'HASH') &&
1614: (ref($result->{'seccount'}) eq 'HASH')) {
1615: %{$courseroles} = %{$result->{'roles'}};
1616: %{$seccount} = %{$result->{'seccount'}};
1617: return;
1618: }
1619: }
1620: }
1621: my %gotnosection;
1622: my %adv_roles =
1623: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1624: foreach my $role (keys(%adv_roles)) {
1625: my ($urole,$usec) = split(/:/,$role);
1626: if (!$gotnosection{$urole}) {
1627: $seccount->{$urole} ++;
1628: $gotnosection{$urole} = 1;
1629: }
1630: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1631: if ($usec ne '') {
1632: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1633: push(@{$courseroles->{$urole}},$usec);
1634: $seccount->{$urole} ++;
1635: }
1636: }
1637: } else {
1638: @{$courseroles->{$urole}} = ();
1639: if ($usec ne '') {
1640: $seccount->{$urole} ++;
1641: push(@{$courseroles->{$urole}},$usec);
1642: }
1643: }
1644: }
1645: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1646: @{$courseroles->{'st'}} = ();
1647: if (keys(%sections_count) > 0) {
1648: push(@{$courseroles->{'st'}},keys(%sections_count));
1649: $seccount->{'st'} = scalar(keys(%sections_count));
1650: }
1651: my $rolehash = {
1652: 'roles' => $courseroles,
1653: 'seccount' => $seccount,
1654: };
1655: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1656: return;
1657: }
1658:
1659: sub jump_to_role {
1660: my ($cdom,$cnum,$seccount,$courseroles) = @_;
1661: my %lt = &Apache::lonlocal::texthash(
1662: this => 'This role has section(s) associated with it.',
1663: ente => 'Enter a specific section.',
1664: orlb => 'Enter a specific section, or leave blank for no section.',
1665: avai => 'Available sections are:',
1666: youe => 'You entered an invalid section choice:',
1667: plst => 'Please try again',
1668: );
1669: my $js;
1670: if (ref($courseroles) eq 'HASH') {
1671: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1672: ' var numsec = new Array();'."\n".
1673: ' var rolesections = new Array();'."\n".
1674: ' var rolenames = new Array();'."\n".
1675: ' var roleseclist = new Array();'."\n";
1676: my @items = keys(%{$courseroles});
1677: for (my $i=0; $i<@items; $i++) {
1678: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1679: my ($secs,$secstr);
1680: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1681: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1682: $secs = join('","',@sections);
1683: $secstr = join(', ',@sections);
1684: }
1685: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1686: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1687: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1688: }
1689: }
1690: my $output = <<"END";
1691: <script type="text/javascript">
1692: function adhocRole(roleitem) {
1693: $js
1694: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
1695: if (newrole == '') {
1696: return;
1697: }
1698: var fullrole = newrole+'./$cdom/$cnum';
1699: var selidx = '';
1700: for (var i=0; i<rolenames.length; i++) {
1701: if (rolenames[i] == newrole) {
1702: selidx = i;
1703: }
1704: }
1705: var secok = 1;
1706: var secchoice = '';
1707: if (selidx >= 0) {
1708: if (numsec[selidx] > 1) {
1709: secok = 0;
1710: var numrolesec = rolesections[selidx].length;
1711: var msgidx = numsec[selidx] - numrolesec;
1712: secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1713: if (secchoice == '') {
1714: if (msgidx > 0) {
1715: secok = 1;
1716: }
1717: } else {
1718: for (var j=0; j<rolesections[selidx].length; j++) {
1719: if (rolesections[selidx][j] == secchoice) {
1720: secok = 1;
1721: }
1722: }
1723: }
1724: } else {
1725: if (rolesections[selidx].length == 1) {
1726: secchoice = rolesections[selidx][0];
1727: }
1728: }
1729: }
1730: if (secok == 1) {
1731: if (secchoice != '') {
1732: fullrole += '/'+secchoice;
1733: }
1734: } else {
1735: document.rolechooser.elements[roleitem].selectedIndex = 0;
1736: if (secchoice != null) {
1737: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
1738: }
1739: return;
1740: }
1741: if (fullrole == "$env{'request.role'}") {
1742: return;
1743: }
1744: itemid = retrieveIndex('gotorole');
1745: if (itemid != -1) {
1746: document.rolechooser.elements[itemid].name = fullrole;
1747: }
1748: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1749: document.rolechooser.selectrole.value = '1';
1750: document.rolechooser.submit();
1751: return;
1752: }
1753:
1754: function retrieveIndex(item) {
1755: for (var i=0;i<document.rolechooser.elements.length;i++) {
1756: if (document.rolechooser.elements[i].name == item) {
1757: return i;
1758: }
1759: }
1760: return -1;
1761: }
1762:
1763:
1764: </script>
1765: END
1766: return $output;
1767: }
1768:
1769:
1770: # ================================================================ Main Program
1771:
1772: BEGIN {
1773: if (! defined($readdesk)) {
1774: {
1775: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
1776: if ( CORE::open( my $config,"<$tabfile") ) {
1777: while (my $configline=<$config>) {
1778: $configline=(split(/\#/,$configline))[0];
1779: $configline=~s/^\s+//;
1780: chomp($configline);
1781: if ($configline=~/^cat\:/) {
1782: my @entries=split(/\:/,$configline);
1783: $category_positions{$entries[2]}=$entries[1];
1784: $category_names{$entries[2]}=$entries[3];
1785: } elsif ($configline) {
1786: push(@desklines,$configline);
1787: }
1788: }
1789: CORE::close($config);
1790: }
1791: }
1792: $readdesk='done';
1793: }
1794: }
1795:
1796: 1;
1797: __END__
1798:
1799:
1800:
1801:
1802:
1803:
1804:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>