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