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