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