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