Annotation of loncom/interface/lonmenu.pm, revision 1.244.2.6
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.244.2.6! raeburn 4: # $Id: lonmenu.pm,v 1.244.2.5 2009/08/14 12:21:32 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 convert_menu_function()
124:
125: FIXME this needs to move into mydesktab and the other locations
126: the text is generated
127:
128: =item hidden_button_check()
129:
130: =item roles_selector()
131:
132: =item jump_to_role()
133:
134: =back
135:
136: =cut
137:
1.1 www 138: package Apache::lonmenu;
139:
140: use strict;
1.152 albertel 141: use Apache::lonnet;
1.47 matthew 142: use Apache::lonhtmlcommon();
1.115 albertel 143: use Apache::loncommon();
1.127 albertel 144: use Apache::lonenc();
1.88 www 145: use Apache::lonlocal;
1.207 foxr 146: use LONCAPA qw(:DEFAULT :match);
1.88 www 147:
1.209 www 148: use vars qw(@desklines %category_names %category_members %category_positions $readdesk);
1.88 www 149:
150:
1.56 www 151: my @inlineremote;
1.38 www 152:
1.203 foxr 153:
154:
1.231 albertel 155: sub show_course {
156: my $course = !$env{'user.adv'};
157: if (!$env{'user.adv'}) {
158: foreach my $env (keys(%env)) {
159: next if ($env !~ m/^user\.priv\./);
160: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
161: $course = 0;
162: last;
163: }
164: }
165: }
166: return $course;
167: }
1.88 www 168:
169: sub initlittle {
170: return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
171: 'nav' => 'Navigate Contents',
172: 'main' => 'Main Menu',
1.244.2.1 raeburn 173: 'roles' => (&Apache::loncommon::show_course()?
1.231 albertel 174: 'Courses':'Roles'),
1.235 raeburn 175: 'other' => 'Other Roles',
1.219 albertel 176: 'docs' => 'Edit Course',
1.244.2.1 raeburn 177: 'exit' => 'Logout',
1.202 albertel 178: 'login' => 'Log In',
1.165 raeburn 179: 'launch' => 'Launch Remote Control',
1.188 albertel 180: 'groups' => 'Groups',
1.184 raeburn 181: 'gdoc' => 'Group Documents',
182: );
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.152 albertel 249: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.151 www 250: $docs=(<<ENDDOCS);
1.176 albertel 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.228 albertel 316: my $is_group = (&Apache::loncommon::course_type() eq 'Group');
1.152 albertel 317: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.186 albertel 318: my $text = ($is_group) ? $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.40 www 579: $editbutton=&switch
1.212 www 580: ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
1.38 www 581: "go('".$cfile."');","Edit this resource");
1.244.2.1 raeburn 582: $noeditbutton = 0;
1.38 www 583: } elsif ($editbutton eq '') {
1.191 www 584: $editbutton=&clear(6,1);
1.38 www 585: }
586: }
1.244.2.1 raeburn 587: if (($noeditbutton) && ($env{'request.filename'})) {
588: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
589: my $file=&Apache::lonnet::declutter($env{'request.filename'});
590: if (defined($cnum) && defined($cdom)) {
591: if (&is_course_upload($file,$cnum,$cdom)) {
592: my $cfile = &edit_course_upload($file,$cnum,$cdom);
593: if ($cfile) {
594: $editbutton=&switch
595: ('','',6,1,'pcstr.gif','edit[_1]',
596: 'resource[_2]',"go('".$cfile."');",
597: 'Edit this resource');
598: }
599: }
600: }
601: }
602: }
1.38 www 603: ###
604: ###
1.41 www 605: # Prepare the rest of the buttons
1.120 raeburn 606: my $menuitems;
607: if ($const_space) {
1.128 albertel 608: my ($uname,$thisdisfn) =
1.152 albertel 609: ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
1.121 raeburn 610: my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
1.131 raeburn 611: if ($currdir =~ m-/$-) {
612: $is_const_dir = 1;
613: } else {
614: $currdir =~ s#[^/]+$##;
1.200 foxr 615: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208 albertel 616: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.131 raeburn 617: $menuitems=(<<ENDMENUITEMS);
1.208 albertel 618: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
1.200 foxr 619: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
1.244.2.1 raeburn 620: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
1.200 foxr 621: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
622: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
1.120 raeburn 623: ENDMENUITEMS
1.131 raeburn 624: }
1.203 foxr 625: } elsif ( defined($env{'request.course.id'}) &&
626: $env{'request.symb'} ne '' ) {
1.120 raeburn 627: $menuitems=(<<ENDMENUITEMS);
1.41 www 628: c&3&1
1.209 www 629: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
630: 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 631: c&6&3
632: c&8&1
633: c&8&2
1.106 www 634: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.209 www 635: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
1.41 www 636: ENDMENUITEMS
1.216 albertel 637:
1.243 tempelho 638: my $currentURL = &Apache::loncommon::get_symb();
639: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
640: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
641: $menuitems.="s&9&3&";
642: if(length($annotation) > 0){
643: $menuitems.="anot2.gif";
644: }else{
645: $menuitems.="anot.gif";
646: }
647: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
648: $menuitems.="Make notes and annotations about this resource&&1\n";
649:
1.244.2.4 raeburn 650: unless ($noremote) {
651: my $showreqcrs = &check_for_rcrs();
652: if ($showreqcrs) {
653: $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]".
654: "&go('/adm/requestcourse')&Course requests\n";
655: }
656: }
1.193 raeburn 657: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
1.216 albertel 658: if (!$env{'request.enc'}) {
659: $menuitems.=(<<ENDREALRES);
1.244.2.1 raeburn 660: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
1.216 albertel 661: ENDREALRES
662: }
1.120 raeburn 663: $menuitems.=(<<ENDREALRES);
1.106 www 664: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
665: 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 666: ENDREALRES
1.120 raeburn 667: }
668: }
1.203 foxr 669: if ($env{'request.uri'} =~ /^\/res/) {
670: $menuitems .= (<<ENDMENUITEMS);
671: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
672: ENDMENUITEMS
673: }
1.41 www 674: my $buttons='';
675: foreach (split(/\n/,$menuitems)) {
676: my ($command,@rest)=split(/\&/,$_);
1.220 raeburn 677: my $idx=10*$rest[0]+$rest[1];
678: if (&hidden_button_check() eq 'yes') {
679: if ($idx == 21 ||$idx == 23) {
680: $buttons.=&switch('','',@rest);
681: } else {
682: $buttons.=&clear(@rest);
683: }
684: } else {
685: if ($command eq 's') {
686: $buttons.=&switch('','',@rest);
687: } else {
688: $buttons.=&clear(@rest);
689: }
1.41 www 690: }
691: }
1.148 albertel 692:
693: if ($textual) {
694: my $addremote=0;
695: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; } }
696: my $inlinebuttons='';
697: if ($addremote) {
1.41 www 698: # Registered, textual output
1.152 albertel 699: if ($env{'browser.interface'} eq 'textual') {
1.148 albertel 700: $inlinebuttons=
1.56 www 701: join('',map { (defined($_)?$_:'') } @inlineremote);
1.148 albertel 702: } else {
1.218 www 703: if ($env{'environment.icons'} eq 'iconsonly') {
1.220 raeburn 704: $inlinebuttons=(<<ENDARROWSINLINE);
1.218 www 705: <tr><td>
706: $inlineremote[21] $inlineremote[23]
1.220 raeburn 707: ENDARROWSINLINE
708: if (&hidden_button_check() ne 'yes') {
709: $inlinebuttons .= (<<ENDINLINEICONS);
1.218 www 710: $inlineremote[61] $inlineremote[63]
711: $inlineremote[71] $inlineremote[72] $inlineremote[73]
712: $inlineremote[81] $inlineremote[82] $inlineremote[83]
713: $inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
714: ENDINLINEICONS
1.220 raeburn 715: }
1.218 www 716: } else {
1.223 albertel 717: if ($inlineremote[21] ne '' || $inlineremote[23] ne '') {
718: $inlinebuttons=(<<ENDFIRSTLINE);
1.129 albertel 719: <tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr>
1.220 raeburn 720: ENDFIRSTLINE
1.223 albertel 721: }
1.220 raeburn 722: if (&hidden_button_check() ne 'yes') {
1.223 albertel 723: foreach my $row (6..9) {
724: if ($inlineremote[${row}.'1'] ne ''
725: || $inlineremote[$row.'2'] ne ''
726: || $inlineremote[$row.'3'] ne '') {
727: $inlinebuttons .= <<"ENDLINE";
728: <tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
729: ENDLINE
730: }
731: }
732: }
733: }
734: }
1.103 www 735: }
1.41 www 736: $result =(<<ENDREGTEXT);
1.129 albertel 737: <script type="text/javascript">
1.42 www 738: // BEGIN LON-CAPA Internal
739: </script>
1.41 www 740: $timesync
1.58 www 741: $tablestart
1.56 www 742: $inlinebuttons
1.227 albertel 743: $tableend
1.224 albertel 744: $newmail
1.129 albertel 745: <script type="text/javascript">
1.64 www 746: // END LON-CAPA Internal
1.42 www 747: </script>
748:
1.41 www 749: ENDREGTEXT
750: # Registered, graphical output
751: } else {
1.152 albertel 752: my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.183 www 753: $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
1.152 albertel 754: my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.113 albertel 755: my $navstatus=&get_nav_status();
1.140 albertel 756: my $clearcstr;
1.148 albertel 757:
1.152 albertel 758: if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1.41 www 759: $result = (<<ENDREGTHIS);
1.38 www 760:
1.129 albertel 761: <script type="text/javascript">
1.244.2.3 raeburn 762: // <![CDATA[
1.150 albertel 763: // BEGIN LON-CAPA Internal
1.42 www 764: var swmenu=null;
1.38 www 765:
766: function LONCAPAreg() {
767: swmenu=$reopen;
768: swmenu.clearTimeout(swmenu.menucltim);
769: $timesync
770: $newmail
1.41 www 771: $buttons
1.84 www 772: swmenu.currentURL="$requri";
1.85 www 773: swmenu.reloadURL=swmenu.currentURL+window.location.search;
1.125 albertel 774: swmenu.currentSymb="$cursymb";
775: swmenu.reloadSymb="$cursymb";
1.38 www 776: swmenu.currentStale=0;
1.113 albertel 777: $navstatus
1.38 www 778: $hwkadd
779: $editbutton
780: }
781:
782: function LONCAPAstale() {
783: swmenu=$reopen
784: swmenu.currentStale=1;
785: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
786: swmenu.switchbutton
787: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
788: }
789: swmenu.clearbut(7,2);
790: swmenu.clearbut(7,3);
791: swmenu.menucltim=swmenu.setTimeout(
792: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.140 albertel 793: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1.38 www 794: 2000);
795: }
796:
1.150 albertel 797: // END LON-CAPA Internal
1.244.2.3 raeburn 798: // ]]>
1.38 www 799: </script>
800: ENDREGTHIS
1.41 www 801: }
802: # =============================================================================
1.38 www 803: } else {
1.41 www 804: # ========================================== This can or will not be registered
805: if ($textual) {
806: # Not registered, textual
807: $result= (<<ENDDONOTREGTEXT);
808: ENDDONOTREGTEXT
809: } else {
810: # Not registered, graphical
811: $result = (<<ENDDONOTREGTHIS);
1.38 www 812:
1.129 albertel 813: <script type="text/javascript">
1.244.2.3 raeburn 814: // <![CDATA[
1.38 www 815: // BEGIN LON-CAPA Internal
1.42 www 816: var swmenu=null;
1.38 www 817:
818: function LONCAPAreg() {
819: swmenu=$reopen
820: $timesync
821: swmenu.currentStale=1;
822: swmenu.clearbut(2,1);
823: swmenu.clearbut(2,3);
824: swmenu.clearbut(8,1);
825: swmenu.clearbut(8,2);
826: swmenu.clearbut(8,3);
827: if (swmenu.currentURL) {
828: swmenu.switchbutton
829: (3,1,'reload.gif','return','location','go(currentURL)');
830: } else {
831: swmenu.clearbut(3,1);
832: }
833: }
834:
835: function LONCAPAstale() {
836: }
837:
838: // END LON-CAPA Internal
1.244.2.3 raeburn 839: // ]]>
1.38 www 840: </script>
841: ENDDONOTREGTHIS
1.41 www 842: }
843: # =============================================================================
1.38 www 844: }
845: return $result;
846: }
847:
1.244.2.1 raeburn 848: sub is_course_upload {
849: my ($file,$cnum,$cdom) = @_;
850: my $uploadpath = &LONCAPA::propath($cdom,$cnum);
851: $uploadpath =~ s{^\/}{};
852: if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
853: ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
854: return 1;
855: }
856: return;
857: }
858:
859: sub edit_course_upload {
860: my ($file,$cnum,$cdom) = @_;
861: my $cfile;
862: if ($file =~/\.(htm|html|css|js|txt)$/) {
863: my $ext = $1;
864: my $url = &Apache::lonnet::hreflocation('',$file);
865: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
866: my @ids=&Apache::lonnet::current_machine_ids();
867: my $dest;
868: if ($home && grep(/^\Q$home\E$/,@ids)) {
869: $dest = $url.'?forceedit=1';
870: } else {
871: unless (&Apache::lonnet::get_locks()) {
872: $dest = '/adm/switchserver?otherserver='.
873: $home.'&role='.$env{'request.role'}.
874: '&url='.$url.'&forceedit=1';
875: }
876: }
877: if ($dest) {
878: $cfile = &HTML::Entities::encode($dest,'"<>&');
879: }
880: }
881: return $cfile;
882: }
883:
1.38 www 884: sub loadevents() {
1.152 albertel 885: if ($env{'request.state'} eq 'construct' ||
1.175 albertel 886: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38 www 887: return 'LONCAPAreg();';
888: }
889:
890: sub unloadevents() {
1.152 albertel 891: if ($env{'request.state'} eq 'construct' ||
1.175 albertel 892: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38 www 893: return 'LONCAPAstale();';
894: }
1.30 www 895:
1.32 www 896:
897: sub startupremote {
898: my ($lowerurl)=@_;
1.152 albertel 899: if (($env{'browser.interface'} eq 'textual') ||
900: ($env{'environment.remote'} eq 'off')) {
1.34 www 901: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
902: }
1.49 www 903: #
904: # The Remote actually gets launched!
905: #
1.32 www 906: my $configmenu=&rawconfig();
1.183 www 907: my $esclowerurl=&escape($lowerurl);
1.119 www 908: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1.32 www 909: return(<<ENDREMOTESTARTUP);
1.129 albertel 910: <script type="text/javascript">
1.244.2.3 raeburn 911: // <![CDATA[
1.118 albertel 912: var timestart;
1.35 www 913: function wheelswitch() {
1.118 albertel 914: if (typeof(document.wheel) != 'undefined') {
915: if (typeof(document.wheel.spin) != 'undefined') {
916: var date=new Date();
917: var waited=Math.round(30-((date.getTime()-timestart)/1000));
918: document.wheel.spin.value=$message;
919: }
920: }
1.35 www 921: if (window.status=='|') {
922: window.status='/';
923: } else {
924: if (window.status=='/') {
925: window.status='-';
926: } else {
927: if (window.status=='-') {
928: window.status='\\\\';
929: } else {
930: if (window.status=='\\\\') { window.status='|'; }
931: }
932: }
933: }
934: }
935:
1.32 www 936: // ---------------------------------------------------------- The wait function
937: var canceltim;
938: function wait() {
939: if ((menuloaded==1) || (tim==1)) {
1.35 www 940: window.status='Done.';
1.32 www 941: if (tim==0) {
942: clearTimeout(canceltim);
943: $configmenu
944: window.location='$lowerurl';
945: } else {
1.52 www 946: window.location='/adm/remote?action=collapse&url=$esclowerurl';
1.32 www 947: }
948: } else {
1.35 www 949: wheelswitch();
950: setTimeout('wait();',200);
1.32 www 951: }
952: }
953:
954: function main() {
1.52 www 955: canceltim=setTimeout('tim=1;',30000);
1.35 www 956: window.status='-';
1.118 albertel 957: var date=new Date();
958: timestart=date.getTime();
1.32 www 959: wait();
960: }
1.244.2.3 raeburn 961: // ]]>
1.32 www 962: </script>
963: ENDREMOTESTARTUP
964: }
965:
966: sub setflags() {
967: return(<<ENDSETFLAGS);
1.129 albertel 968: <script type="text/javascript">
1.244.2.3 raeburn 969: // <![CDATA[
1.32 www 970: menuloaded=0;
971: tim=0;
1.244.2.3 raeburn 972: // ]]>
1.32 www 973: </script>
974: ENDSETFLAGS
975: }
976:
977: sub maincall() {
1.152 albertel 978: if (($env{'browser.interface'} eq 'textual') ||
979: ($env{'environment.remote'} eq 'off')) { return ''; }
1.32 www 980: return(<<ENDMAINCALL);
1.129 albertel 981: <script type="text/javascript">
1.244.2.3 raeburn 982: // <![CDATA[
1.32 www 983: main();
1.244.2.3 raeburn 984: // ]]>
1.32 www 985: </script>
986: ENDMAINCALL
987: }
1.118 albertel 988:
989: sub load_remote_msg {
990: my ($lowerurl)=@_;
991:
1.152 albertel 992: if (($env{'browser.interface'} eq 'textual') ||
993: ($env{'environment.remote'} eq 'off')) { return ''; }
1.118 albertel 994:
1.183 www 995: my $esclowerurl=&escape($lowerurl);
1.244.2.1 raeburn 996: my $link=&mt('[_1]Continue[_2] on in Inline Menu mode',
997: '<a href="/adm/remote?action=collapse&url='.$esclowerurl.'">',
998: '</a>');
1.118 albertel 999: return(<<ENDREMOTEFORM);
1000: <p>
1001: <form name="wheel">
1.119 www 1002: <input name="spin" type="text" size="60" />
1.118 albertel 1003: </form>
1004: </p>
1005: <p>$link</p>
1006: ENDREMOTEFORM
1007: }
1.230 albertel 1008:
1009: sub get_menu_name {
1010: my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
1011: $hostid =~ s/\W//g;
1012: return 'LCmenu'.$hostid;
1013: }
1014:
1.30 www 1015:
1016: sub reopenmenu {
1.152 albertel 1017: if (($env{'browser.interface'} eq 'textual') ||
1018: ($env{'environment.remote'} eq 'off')) { return ''; }
1.230 albertel 1019: my $menuname = &get_menu_name();
1.47 matthew 1020: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1021: return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30 www 1022: }
1023:
1.1 www 1024:
1025: sub open {
1.22 www 1026: my $returnval='';
1.152 albertel 1027: if (($env{'browser.interface'} eq 'textual') ||
1028: ($env{'environment.remote'} eq 'off')) {
1.244.2.3 raeburn 1029: return
1030: '<script type="text/javascript">'."\n".
1.244.2.5 raeburn 1031: '// <![CDATA['."\n".
1.244.2.3 raeburn 1032: 'self.name="loncapaclient";'."\n".
1.244.2.5 raeburn 1033: '// ]]>'."\n".
1.244.2.3 raeburn 1034: '</script>';
1.111 albertel 1035: }
1.230 albertel 1036: my $menuname = &get_menu_name();
1.222 albertel 1037:
1038: # unless (shift eq 'unix') {
1.22 www 1039: # resizing does not work on linux because of virtual desktop sizes
1.222 albertel 1040: # $returnval.=(<<ENDRESIZE);
1041: #if (window.screen) {
1042: # self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1043: # self.moveTo(190,15);
1044: #}
1045: #ENDRESIZE
1046: # }
1.244.2.3 raeburn 1047: $returnval=(<<ENDOPEN);
1048: // <![CDATA[
1.35 www 1049: window.status='Opening LON-CAPA Remote Control';
1.30 www 1050: var menu=window.open("/res/adm/pages/menu.html","$menuname",
1.191 www 1051: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.71 www 1052: self.name='loncapaclient';
1.244.2.3 raeburn 1053: // ]]>
1.1 www 1054: ENDOPEN
1.129 albertel 1055: return '<script type="text/javascript">'.$returnval.'</script>';
1.1 www 1056: }
1057:
1.2 www 1058:
1059: # ================================================================== Raw Config
1060:
1.3 www 1061: sub clear {
1062: my ($row,$col)=@_;
1.152 albertel 1063: unless (($env{'browser.interface'} eq 'textual') ||
1064: ($env{'environment.remote'} eq 'off')) {
1.35 www 1065: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.56 www 1066: } else {
1067: $inlineremote[10*$row+$col]='';
1068: return '';
1069: }
1.3 www 1070: }
1071:
1.40 www 1072: # ============================================ Switch a button or create a link
1.25 matthew 1073: # Switch acts on the javascript that is executed when a button is clicked.
1074: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 1075:
1.2 www 1076: sub switch {
1.209 www 1077: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2 www 1078: $act=~s/\$uname/$uname/g;
1079: $act=~s/\$udom/$udom/g;
1.88 www 1080: $top=&mt($top);
1081: $bot=&mt($bot);
1082: $desc=&mt($desc);
1.238 www 1083: if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
1084: $img=&mt($img);
1085: }
1.209 www 1086: my $idx=10*$row+$col;
1087: $category_members{$cat}.=':'.$idx;
1088:
1.152 albertel 1089: unless (($env{'browser.interface'} eq 'textual') ||
1090: ($env{'environment.remote'} eq 'off')) {
1.50 www 1091: # Remote
1.34 www 1092: return "\n".
1.35 www 1093: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.152 albertel 1094: } elsif ($env{'browser.interface'} eq 'textual') {
1.50 www 1095: # Accessibility
1096: if ($nobreak==2) { return ''; }
1097: my $text=$top.' '.$bot;
1.78 www 1098: $text=~s/\s*\-\s*//gs;
1.94 www 1099: if ($nobreak) {
1.209 www 1100: $inlineremote[$idx]=
1.94 www 1101: '<a href="javascript:'.$act.';">'.$text.'</a>';
1102: } else {
1.209 www 1103: $inlineremote[$idx]="\n<br />".
1.100 www 1104: $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
1.94 www 1105: }
1.34 www 1106: } else {
1.50 www 1107: # Inline Remote
1.213 www 1108: if ($env{'environment.icons'} ne 'classic') {
1109: $img=~s/\.gif$/\.png/;
1110: }
1.41 www 1111: if ($nobreak==2) { return ''; }
1.34 www 1112: my $text=$top.' '.$bot;
1.78 www 1113: $text=~s/\s*\-\s*//gs;
1.105 www 1114:
1.99 www 1115: my $pic=
1.225 albertel 1116: '<img alt="'.$text.'" src="'.
1117: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1118: '" align="'.($nobreak==3?'right':'left').'" />';
1.177 albertel 1119: if ($env{'browser.interface'} eq 'faketextual') {
1.103 www 1120: # Accessibility
1121: if ($nobreak==3) {
1.209 www 1122: $inlineremote[$idx]="\n".
1.177 albertel 1123: '<td class="LC_menubuttons_text" align="right">'.$text.
1124: '</td><td class="LC_menubuttons_img" align="left">'.
1.103 www 1125: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1126: } elsif ($nobreak) {
1.209 www 1127: $inlineremote[$idx]="\n<tr>".
1.177 albertel 1128: '<td class="LC_menubuttons_img" align="left">'.
1129: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215 www 1130: <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 1131: } else {
1.209 www 1132: $inlineremote[$idx]="\n<tr>".
1.177 albertel 1133: '<td class="LC_menubuttons_img" align="left">'.
1.103 www 1134: '<a href="javascript:'.$act.';">'.$pic.
1.177 albertel 1135: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215 www 1136: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103 www 1137: }
1.94 www 1138: } else {
1.103 www 1139: # Inline Menu
1.218 www 1140: if ($env{'environment.icons'} eq 'iconsonly') {
1141: $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
1142: } else {
1143: $inlineremote[$idx]=
1.215 www 1144: '<a class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1145: '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
1.218 www 1146: }
1.94 www 1147: }
1.34 www 1148: }
1.56 www 1149: return '';
1.2 www 1150: }
1151:
1152: sub secondlevel {
1153: my $output='';
1154: my
1.209 www 1155: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2 www 1156: if ($prt eq 'any') {
1.209 www 1157: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1158: } elsif ($prt=~/^r(\w+)/) {
1159: if ($rol eq $1) {
1.209 www 1160: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1161: }
1162: }
1163: return $output;
1164: }
1165:
1.18 www 1166: sub openmenu {
1.230 albertel 1167: my $menuname = &get_menu_name();
1.152 albertel 1168: if (($env{'browser.interface'} eq 'textual') ||
1169: ($env{'environment.remote'} eq 'off')) { return ''; }
1.47 matthew 1170: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1171: return "window.open(".$nothing.",'".$menuname."');";
1.18 www 1172: }
1173:
1.56 www 1174: sub inlinemenu {
1.210 albertel 1175: undef(@inlineremote);
1176: undef(%category_members);
1.56 www 1177: &rawconfig(1);
1.214 albertel 1178: my $output='<table id="LC_mainmenu"><tr>';
1.209 www 1179: for (my $col=1; $col<=2; $col++) {
1.241 riegler 1180: $output.='<td class="LC_mainmenu_col_fieldset">';
1.209 www 1181: for (my $row=1; $row<=8; $row++) {
1182: foreach my $cat (keys(%category_members)) {
1183: if ($category_positions{$cat} ne "$col,$row") { next; }
1.241 riegler 1184: #$output.='<table id="LC_menubuttons_mainmenu"><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1185: $output.='<fieldset id="LC_mainmenu_fieldset">';
1186: $output.='<legend class="LC_mainmenu_fieldset_category">'.&mt($category_names{$cat}).'</legend>';
1187: $output.='<table id="LC_menubuttons_mainmenu">';
1.240 riegler 1188: my %active=();
1189: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1190: if ($inlineremote[$menu_item]) {
1191: $active{$menu_item}=1;
1192: }
1193: }
1194: foreach my $item (sort(keys(%active))) {
1195: $output.=$inlineremote[$item];
1196: }
1197: $output.='</table>';
1.241 riegler 1198: $output.='</fieldset>';
1.240 riegler 1199: }
1200: }
1201: $output.="</td>";
1202: }
1203: $output.="</tr></table>";
1204: return $output;
1205: }
1206:
1.2 www 1207: sub rawconfig {
1.34 www 1208: my $textualoverride=shift;
1209: my $output='';
1.152 albertel 1210: unless (($env{'browser.interface'} eq 'textual') ||
1211: ($env{'environment.remote'} eq 'off')) {
1.35 www 1212: $output.=
1213: "window.status='Opening Remote Control';var swmenu=".&openmenu().
1214: "\nwindow.status='Configuring Remote Control ';";
1.34 www 1215: } else {
1216: unless ($textualoverride) { return ''; }
1217: }
1.152 albertel 1218: my $uname=$env{'user.name'};
1219: my $udom=$env{'user.domain'};
1220: my $adv=$env{'user.adv'};
1.244.2.1 raeburn 1221: my $show_course=&Apache::loncommon::show_course();
1.152 albertel 1222: my $author=$env{'user.author'};
1.5 www 1223: my $crs='';
1.152 albertel 1224: if ($env{'request.course.id'}) {
1225: $crs='/'.$env{'request.course.id'};
1226: if ($env{'request.course.sec'}) {
1227: $crs.='_'.$env{'request.course.sec'};
1.7 www 1228: }
1.8 www 1229: $crs=~s/\_/\//g;
1.5 www 1230: }
1.152 albertel 1231: my $pub=($env{'request.state'} eq 'published');
1232: my $con=($env{'request.state'} eq 'construct');
1233: my $rol=$env{'request.role'};
1234: my $requested_domain = $env{'request.role.domain'};
1.184 raeburn 1235: foreach my $line (@desklines) {
1.209 www 1236: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3 www 1237: $prt=~s/\$uname/$uname/g;
1238: $prt=~s/\$udom/$udom/g;
1.5 www 1239: $prt=~s/\$crs/$crs/g;
1.25 matthew 1240: $prt=~s/\$requested_domain/$requested_domain/g;
1.211 www 1241: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.186 albertel 1242: my $type = &Apache::loncommon::course_type();
1.184 raeburn 1243: if ($type eq 'Group') {
1244: $desc = &convert_menu_function($desc,$type);
1245: }
1.3 www 1246: if ($pro eq 'clear') {
1.4 www 1247: $output.=&clear($row,$col);
1.3 www 1248: } elsif ($pro eq 'any') {
1.2 www 1249: $output.=&secondlevel(
1.209 www 1250: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1251: } elsif ($pro eq 'smp') {
1252: unless ($adv) {
1253: $output.=&secondlevel(
1.209 www 1254: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1255: }
1256: } elsif ($pro eq 'adv') {
1257: if ($adv) {
1258: $output.=&secondlevel(
1.209 www 1259: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1260: }
1.231 albertel 1261: } elsif ($pro eq 'shc') {
1262: if ($show_course) {
1263: $output.=&secondlevel(
1264: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1265: }
1266: } elsif ($pro eq 'nsc') {
1267: if (!$show_course) {
1268: $output.=&secondlevel(
1269: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1270: }
1.81 matthew 1271: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.2 www 1272: if (&Apache::lonnet::allowed($1,$prt)) {
1.209 www 1273: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4 www 1274: }
1.26 www 1275: } elsif ($pro eq 'course') {
1.152 albertel 1276: if ($env{'request.course.fn'}) {
1.209 www 1277: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81 matthew 1278: }
1.124 matthew 1279: } elsif ($pro =~ /^courseenv_(.*)$/) {
1280: my $key = $1;
1.152 albertel 1281: if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
1.209 www 1282: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.124 matthew 1283: }
1.81 matthew 1284: } elsif ($pro =~ /^course_(.*)$/) {
1285: # Check for permissions inside of a course
1.152 albertel 1286: if (($env{'request.course.id'}) &&
1287: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1288: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81 matthew 1289: )) {
1.209 www 1290: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26 www 1291: }
1.4 www 1292: } elsif ($pro eq 'author') {
1293: if ($author) {
1.152 albertel 1294: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234 raeburn 1295: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1.152 albertel 1296: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19 matthew 1297: # Check that we are on the correct machine
1.29 matthew 1298: my $cadom=$requested_domain;
1.152 albertel 1299: my $caname=$env{'user.name'};
1.234 raeburn 1300: if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29 matthew 1301: ($cadom,$caname)=
1.206 albertel 1302: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29 matthew 1303: }
1304: $act =~ s/\$caname/$caname/g;
1.19 matthew 1305: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 1306: my $allowed=0;
1307: my @ids=&Apache::lonnet::current_machine_ids();
1308: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1309: if ($allowed) {
1.209 www 1310: $output.=&switch($caname,$cadom,
1311: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19 matthew 1312: }
1.6 www 1313: }
1.2 www 1314: }
1.244.2.1 raeburn 1315: } elsif ($pro eq 'tools') {
1316: my @tools = ('aboutme','blog','portfolio');
1317: if (grep(/^\Q$prt\E$/,@tools)) {
1318: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1319: $env{'user.domain'},
1320: $prt,undef,'tools')) {
1321: $output.=&clear($row,$col);
1322: next;
1323: }
1.244.2.4 raeburn 1324: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1325: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1326: next;
1327: }
1328: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1329: next;
1.244.2.1 raeburn 1330: }
1.244.2.4 raeburn 1331: my $showreqcrs = &check_for_rcrs();
1.244.2.1 raeburn 1332: if (!$showreqcrs) {
1333: $output.=&clear($row,$col);
1334: next;
1335: }
1336: }
1337: $prt='any';
1338: $output.=&secondlevel(
1339: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1340:
1.2 www 1341: }
1.13 harris41 1342: }
1.152 albertel 1343: unless (($env{'browser.interface'} eq 'textual') ||
1344: ($env{'environment.remote'} eq 'off')) {
1.35 www 1345: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.123 www 1346: if (&Apache::lonmsg::newmail()) {
1347: $output.='swmenu.setstatus("you have","messages");';
1348: }
1.34 www 1349: }
1.123 www 1350:
1.2 www 1351: return $output;
1352: }
1353:
1.244.2.4 raeburn 1354: sub check_for_rcrs {
1355: my $showreqcrs = 0;
1356: foreach my $type ('official','unofficial','community') {
1357: if (&Apache::lonnet::usertools_access($env{'user.name'},
1358: $env{'user.domain'},
1359: $type,undef,'requestcourses')) {
1360: $showreqcrs = 1;
1361: last;
1362: }
1363: }
1364: return $showreqcrs;
1365: }
1366:
1.2 www 1367: # ======================================================================= Close
1.1 www 1368:
1369: sub close {
1.152 albertel 1370: if (($env{'browser.interface'} eq 'textual') ||
1371: ($env{'environment.remote'} eq 'off')) { return ''; }
1.230 albertel 1372: my $menuname = &get_menu_name();
1.1 www 1373: return(<<ENDCLOSE);
1.129 albertel 1374: <script type="text/javascript">
1.244.2.3 raeburn 1375: // <![CDATA[
1.35 www 1376: window.status='Accessing Remote Control';
1.30 www 1377: menu=window.open("/adm/rat/empty.html","$menuname",
1.1 www 1378: "height=350,width=150,scrollbars=no,menubar=no");
1.35 www 1379: window.status='Disabling Remote Control';
1380: menu.active=0;
1.31 www 1381: menu.autologout=0;
1.35 www 1382: window.status='Closing Remote Control';
1.1 www 1383: menu.close();
1.35 www 1384: window.status='Done.';
1.244.2.3 raeburn 1385: // ]]>
1.1 www 1386: </script>
1387: ENDCLOSE
1388: }
1389:
1390: # ====================================================================== Footer
1391:
1392: sub footer {
1393:
1.33 www 1394: }
1395:
1.122 albertel 1396: sub nav_control_js {
1.152 albertel 1397: my $nav=($env{'environment.remotenavmap'} eq 'on');
1.122 albertel 1398: return (<<NAVCONTROL);
1399: var w_loncapanav_flag="$nav";
1400:
1401:
1402: function gonav(url) {
1403: if (w_loncapanav_flag != 1) {
1404: gopost(url,'');
1405: } else {
1406: navwindow=window.open(url,
1407: "loncapanav","height=600,width=400,scrollbars=1");
1408: }
1409: }
1410: NAVCONTROL
1411: }
1412:
1.42 www 1413: sub utilityfunctions {
1.132 raeburn 1414: my $caller = shift;
1.152 albertel 1415: unless (($env{'browser.interface'} eq 'textual') ||
1416: ($env{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
1417: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.183 www 1418: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125 albertel 1419:
1.152 albertel 1420: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.122 albertel 1421: my $nav_control=&nav_control_js();
1.175 albertel 1422:
1423: my $start_page_annotate =
1424: &Apache::loncommon::start_page('Annotator',undef,
1425: {'only_body' => 1,
1426: 'js_ready' => 1,
1427: 'bgcolor' => '#BBBBBB',
1428: 'add_entries' => {
1429: 'onload' => 'javascript:document.goannotate.submit();'}});
1430:
1.205 albertel 1431: my $end_page_annotate =
1432: &Apache::loncommon::end_page({'js_ready' => 1});
1433:
1.175 albertel 1434: my $start_page_bookmark =
1435: &Apache::loncommon::start_page('Bookmarks',undef,
1436: {'only_body' => 1,
1437: 'js_ready' => 1,
1438: 'bgcolor' => '#BBBBBB',});
1439:
1.205 albertel 1440: my $end_page_bookmark =
1.175 albertel 1441: &Apache::loncommon::end_page({'js_ready' => 1});
1442:
1.42 www 1443: return (<<ENDUTILITY)
1444:
1445: var currentURL="$currenturl";
1446: var reloadURL="$currenturl";
1447: var currentSymb="$currentsymb";
1448:
1.114 albertel 1449: $nav_control
1450:
1.42 www 1451: function go(url) {
1452: if (url!='' && url!= null) {
1453: currentURL = null;
1454: currentSymb= null;
1455: window.location.href=url;
1456: }
1457: }
1458:
1459: function gopost(url,postdata) {
1460: if (url!='') {
1461: this.document.server.action=url;
1462: this.document.server.postdata.value=postdata;
1463: this.document.server.command.value='';
1464: this.document.server.url.value='';
1465: this.document.server.symb.value='';
1466: this.document.server.submit();
1467: }
1468: }
1469:
1470: function gocmd(url,cmd) {
1471: if (url!='') {
1472: this.document.server.action=url;
1473: this.document.server.postdata.value='';
1474: this.document.server.command.value=cmd;
1475: this.document.server.url.value=currentURL;
1476: this.document.server.symb.value=currentSymb;
1477: this.document.server.submit();
1478: }
1.57 www 1479: }
1480:
1.121 raeburn 1481: function gocstr(url,filename) {
1482: if (url == '/adm/cfile?action=delete') {
1483: this.document.cstrdelete.filename.value = filename
1484: this.document.cstrdelete.submit();
1485: return;
1486: }
1.137 raeburn 1487: if (url == '/adm/printout') {
1488: this.document.cstrprint.postdata.value = filename
1489: this.document.cstrprint.curseed.value = 0;
1490: this.document.cstrprint.problemtype.value = 0;
1.138 raeburn 1491: if (this.document.lonhomework) {
1492: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1493: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1494: }
1495: if (this.document.lonhomework.problemtype) {
1.164 albertel 1496: if (this.document.lonhomework.problemtype.value) {
1497: this.document.cstrprint.problemtype.value =
1498: this.document.lonhomework.problemtype.value;
1499: } else if (this.document.lonhomework.problemtype.options) {
1500: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1501: if (this.document.lonhomework.problemtype.options[i].selected) {
1502: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1503: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1504: }
1505: }
1506: }
1507: }
1508: }
1509: }
1.137 raeburn 1510: this.document.cstrprint.submit();
1511: return;
1512: }
1.121 raeburn 1513: if (url !='') {
1514: this.document.constspace.filename.value = filename;
1515: this.document.constspace.action = url;
1516: this.document.constspace.submit();
1517: }
1518: }
1519:
1.131 raeburn 1520: function golist(url) {
1521: if (url!='' && url!= null) {
1522: currentURL = null;
1523: currentSymb= null;
1524: top.location.href=url;
1525: }
1526: }
1527:
1528:
1.121 raeburn 1529:
1.57 www 1530: function catalog_info() {
1.102 albertel 1531: 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 1532: }
1533:
1534: function chat_win() {
1.102 albertel 1535: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1.42 www 1536: }
1.169 raeburn 1537:
1538: function group_chat(group) {
1539: var url = '/adm/groupchat?group='+group;
1540: var winName = 'LONchat_'+group;
1541: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1542: }
1.175 albertel 1543:
1544: function edit_bookmarks() {
1545: go('');
1546: w_BookmarkPal_flag=1;
1547: bookmarkpal=window.open("/adm/bookmarks",
1548: "BookmarkPal", "width=400,height=505,scrollbars=0");
1549: }
1550:
1551: function annotate() {
1552: w_Annotator_flag=1;
1553: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1554: annotator.document.write(
1555: '$start_page_annotate'
1556: +"<form name='goannotate' target='Annotator' method='post' "
1557: +"action='/adm/annotations'>"
1.217 albertel 1558: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181 albertel 1559: +"<\\/form>"
1.205 albertel 1560: +'$end_page_annotate');
1.175 albertel 1561: annotator.document.close();
1562: }
1563:
1564: function set_bookmark() {
1565: go('');
1566: clienttitle=document.title;
1567: clienthref=location.pathname;
1568: w_bmquery_flag=1;
1569: bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
1570: bmquery.document.write(
1571: '$start_page_bookmark'
1.244.2.1 raeburn 1572: +'<center><form method="post"'
1573: +' name="newlink" action="/adm/bookmarks" target="bmquery" '
1574: +'> <table width="340" height="150" '
1575: +'bgcolor="ffffff" align="center"><tr><td>Link Name:<br /><input '
1576: +'type="text" name="title" size="45" value="'+clienttitle+'" />'
1577: +'<br />Address:<br /><input type="text" name="address" size="45" '
1578: +'value="'+clienthref+'" /><br /><center><input type="submit" '
1579: +'value="Save" /> <input type="button" value="Close" '
1580: +'onclick="javascript:window.close();" /></center></td>'
1581: +'</tr></table></form></center>'
1.205 albertel 1582: +'$end_page_bookmark' );
1.175 albertel 1583: bmquery.document.close();
1584: }
1585:
1.42 www 1586: ENDUTILITY
1587: }
1588:
1589: sub serverform {
1590: return(<<ENDSERVERFORM);
1.181 albertel 1591: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 1592: <input type="hidden" name="postdata" value="none" />
1593: <input type="hidden" name="command" value="none" />
1594: <input type="hidden" name="url" value="none" />
1595: <input type="hidden" name="symb" value="none" />
1596: </form>
1597: ENDSERVERFORM
1598: }
1.113 albertel 1599:
1.121 raeburn 1600: sub constspaceform {
1601: return(<<ENDCONSTSPACEFORM);
1.181 albertel 1602: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121 raeburn 1603: <input type="hidden" name="filename" value="" />
1604: </form>
1.181 albertel 1605: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121 raeburn 1606: <input type="hidden" name="action" value="delete" />
1607: <input type="hidden" name="filename" value="" />
1608: </form>
1.181 albertel 1609: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137 raeburn 1610: <input type="hidden" name="postdata" value="" />
1611: <input type="hidden" name="curseed" value="" />
1612: <input type="hidden" name="problemtype" value="" />
1613: </form>
1614:
1.121 raeburn 1615: ENDCONSTSPACEFORM
1616: }
1617:
1618:
1.113 albertel 1619: sub get_nav_status {
1620: my $navstatus="swmenu.w_loncapanav_flag=";
1.152 albertel 1621: if ($env{'environment.remotenavmap'} eq 'on') {
1.113 albertel 1622: $navstatus.="1";
1623: } else {
1624: $navstatus.="-1";
1625: }
1626: return $navstatus;
1627: }
1628:
1.186 albertel 1629: #FIXME this needs to move into mydesktab and the other locations
1630: # the text is generated
1.184 raeburn 1631: sub convert_menu_function {
1632: my ($rolename,$type) = @_;
1633: if ($type eq 'Group') {
1634: $rolename =~ s/student/member/g;
1635: $rolename =~ s/group/team/g;
1636: $rolename =~ s/course/group/g;
1637: $rolename =~ s/Course/Group/g;
1638: }
1639: return $rolename;
1640: }
1641:
1.220 raeburn 1642: sub hidden_button_check {
1643: my $hidden;
1644: if ($env{'request.course.id'} eq '') {
1645: return;
1646: }
1647: if ($env{'request.role.adv'}) {
1648: return;
1649: }
1.232 raeburn 1650: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1651: return $buttonshide;
1.220 raeburn 1652: }
1.184 raeburn 1653:
1.235 raeburn 1654: sub roles_selector {
1655: my ($cdom,$cnum) = @_;
1656: my $now = time;
1.244.2.1 raeburn 1657: my (%courseroles,%seccount);
1.235 raeburn 1658: my $is_cc;
1659: my $role_selector;
1660: if ($env{'user.role.cc./'.$cdom.'/'.$cnum}) {
1661: my ($start,$end) = split(/\./,$env{'user.role.cc./'.$cdom.'/'.$cnum});
1662:
1663: if ((($start) && ($start<0)) ||
1664: (($end) && ($end<$now)) ||
1665: (($start) && ($now<$start))) {
1666: $is_cc = 0;
1667: } else {
1668: $is_cc = 1;
1669: }
1670: }
1671: if ($is_cc) {
1.244.2.1 raeburn 1672: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
1.235 raeburn 1673: } else {
1.244.2.1 raeburn 1674: my %gotnosection;
1.235 raeburn 1675: foreach my $item (keys(%env)) {
1.239 raeburn 1676: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235 raeburn 1677: my $role = $1;
1678: my $sec = $2;
1679: next if ($role eq 'gr');
1680: my ($start,$end) = split(/\./,$env{$item});
1681: next if (($start && $start > $now) || ($end && $end < $now));
1682: if ($sec eq '') {
1.239 raeburn 1683: if (!$gotnosection{$role}) {
1684: $seccount{$role} ++;
1685: $gotnosection{$role} = 1;
1686: }
1.235 raeburn 1687: }
1688: if (ref($courseroles{$role}) eq 'ARRAY') {
1.239 raeburn 1689: if ($sec ne '') {
1690: if (!grep(/^Q$sec\E$/,@{$courseroles{$role}})) {
1691: push(@{$courseroles{$role}},$sec);
1692: $seccount{$role} ++;
1693: }
1694: }
1695: } else {
1696: @{$courseroles{$role}} = ();
1697: if ($sec ne '') {
1698: $seccount{$role} ++;
1.235 raeburn 1699: push(@{$courseroles{$role}},$sec);
1700: }
1701: }
1702: }
1703: }
1704: }
1705: my @roles_order = ('cc','in','ta','ep','ad','st');
1706: if (keys(%courseroles) > 1) {
1.239 raeburn 1707: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
1.235 raeburn 1708: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
1709: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1.237 bisitz 1710: $role_selector .= '<option value="">'.&mt('Switch course role to...').'</option>';
1.235 raeburn 1711: foreach my $role (@roles_order) {
1712: if (defined($courseroles{$role})) {
1713: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1714: }
1715: }
1716: foreach my $role (sort(keys(%courseroles))) {
1717: if ($role =~ /^cr/) {
1718: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1719: }
1720: }
1721: $role_selector .= '</select>'."\n".
1722: '<input type="hidden" name="destinationurl" value="'.
1723: $ENV{'REQUEST_URI'}.'" />'."\n".
1724: '<input type="hidden" name="gotorole" value="1" />'."\n".
1725: '<input type="hidden" name="selectrole" value="" />'."\n".
1726: '<input type="hidden" name="switch" value="1" />'."\n".
1727: '</form>';
1728: }
1729: return $role_selector;
1730: }
1731:
1.244.2.1 raeburn 1732: sub get_all_courseroles {
1733: my ($cdom,$cnum,$courseroles,$seccount) = @_;
1734: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
1735: return;
1736: }
1737: my ($result,$cached) =
1738: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1739: if (defined($cached)) {
1740: if (ref($result) eq 'HASH') {
1741: if ((ref($result->{'roles'}) eq 'HASH') &&
1742: (ref($result->{'seccount'}) eq 'HASH')) {
1743: %{$courseroles} = %{$result->{'roles'}};
1744: %{$seccount} = %{$result->{'seccount'}};
1745: return;
1746: }
1747: }
1748: }
1749: my %gotnosection;
1750: my %adv_roles =
1751: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1752: foreach my $role (keys(%adv_roles)) {
1753: my ($urole,$usec) = split(/:/,$role);
1754: if (!$gotnosection{$urole}) {
1755: $seccount->{$urole} ++;
1756: $gotnosection{$urole} = 1;
1757: }
1758: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1759: if ($usec ne '') {
1760: if (!grep(/^\Q$usec\E$/,@{$courseroles->{$urole}})) {
1761: push(@{$courseroles->{$urole}},$usec);
1762: $seccount->{$urole} ++;
1763: }
1764: }
1765: } else {
1766: @{$courseroles->{$urole}} = ();
1767: if ($usec ne '') {
1768: $seccount->{$urole} ++;
1769: push(@{$courseroles->{$urole}},$usec);
1770: }
1771: }
1772: }
1773: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1774: @{$courseroles->{'st'}} = ();
1775: if (keys(%sections_count) > 0) {
1776: push(@{$courseroles->{'st'}},keys(%sections_count));
1777: $seccount->{'st'} = scalar(keys(%sections_count));
1778: }
1779: my $rolehash = {
1780: 'roles' => $courseroles,
1781: 'seccount' => $seccount,
1782: };
1783: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1784: return;
1785: }
1786:
1.235 raeburn 1787: sub jump_to_role {
1.239 raeburn 1788: my ($cdom,$cnum,$seccount,$courseroles) = @_;
1789: my %lt = &Apache::lonlocal::texthash(
1790: this => 'This role has section(s) associated with it.',
1791: ente => 'Enter a specific section.',
1792: orlb => 'Enter a specific section, or leave blank for no section.',
1793: avai => 'Available sections are:',
1794: youe => 'You entered an invalid section choice:',
1795: plst => 'Please try again',
1796: );
1797: my $js;
1798: if (ref($courseroles) eq 'HASH') {
1799: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1800: ' var numsec = new Array();'."\n".
1801: ' var rolesections = new Array();'."\n".
1802: ' var rolenames = new Array();'."\n".
1803: ' var roleseclist = new Array();'."\n";
1804: my @items = keys(%{$courseroles});
1805: for (my $i=0; $i<@items; $i++) {
1806: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1807: my ($secs,$secstr);
1808: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1809: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1810: $secs = join('","',@sections);
1811: $secstr = join(', ',@sections);
1812: }
1813: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1814: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1815: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1816: }
1817: }
1.244.2.2 raeburn 1818: return <<"END";
1.235 raeburn 1819: <script type="text/javascript">
1.244.2.2 raeburn 1820: //<![CDATA[
1.235 raeburn 1821: function adhocRole(roleitem) {
1.239 raeburn 1822: $js
1.235 raeburn 1823: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
1824: if (newrole == '') {
1825: return;
1826: }
1.239 raeburn 1827: var fullrole = newrole+'./$cdom/$cnum';
1828: var selidx = '';
1829: for (var i=0; i<rolenames.length; i++) {
1830: if (rolenames[i] == newrole) {
1831: selidx = i;
1832: }
1833: }
1834: var secok = 1;
1835: var secchoice = '';
1836: if (selidx >= 0) {
1837: if (numsec[selidx] > 1) {
1838: secok = 0;
1839: var numrolesec = rolesections[selidx].length;
1840: var msgidx = numsec[selidx] - numrolesec;
1841: secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1842: if (secchoice == '') {
1843: if (msgidx > 0) {
1844: secok = 1;
1845: }
1846: } else {
1847: for (var j=0; j<rolesections[selidx].length; j++) {
1848: if (rolesections[selidx][j] == secchoice) {
1849: secok = 1;
1850: }
1851: }
1852: }
1853: } else {
1854: if (rolesections[selidx].length == 1) {
1855: secchoice = rolesections[selidx][0];
1856: }
1857: }
1858: }
1859: if (secok == 1) {
1860: if (secchoice != '') {
1861: fullrole += '/'+secchoice;
1862: }
1863: } else {
1864: document.rolechooser.elements[roleitem].selectedIndex = 0;
1865: if (secchoice != null) {
1866: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
1867: }
1868: return;
1869: }
1870: if (fullrole == "$env{'request.role'}") {
1.235 raeburn 1871: return;
1872: }
1873: itemid = retrieveIndex('gotorole');
1874: if (itemid != -1) {
1.239 raeburn 1875: document.rolechooser.elements[itemid].name = fullrole;
1.235 raeburn 1876: }
1.239 raeburn 1877: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1.235 raeburn 1878: document.rolechooser.selectrole.value = '1';
1879: document.rolechooser.submit();
1880: return;
1881: }
1882:
1883: function retrieveIndex(item) {
1884: for (var i=0;i<document.rolechooser.elements.length;i++) {
1885: if (document.rolechooser.elements[i].name == item) {
1886: return i;
1887: }
1888: }
1889: return -1;
1890: }
1.244.2.2 raeburn 1891: // ]]>
1.235 raeburn 1892: </script>
1893: END
1894: }
1895:
1896:
1.2 www 1897: # ================================================================ Main Program
1898:
1.16 harris41 1899: BEGIN {
1.166 albertel 1900: if (! defined($readdesk)) {
1901: {
1902: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
1903: if ( CORE::open( my $config,"<$tabfile") ) {
1904: while (my $configline=<$config>) {
1905: $configline=(split(/\#/,$configline))[0];
1906: $configline=~s/^\s+//;
1907: chomp($configline);
1.209 www 1908: if ($configline=~/^cat\:/) {
1909: my @entries=split(/\:/,$configline);
1910: $category_positions{$entries[2]}=$entries[1];
1911: $category_names{$entries[2]}=$entries[3];
1912: } elsif ($configline) {
1.166 albertel 1913: push(@desklines,$configline);
1914: }
1915: }
1916: CORE::close($config);
1917: }
1918: }
1919: $readdesk='done';
1.2 www 1920: }
1921: }
1.30 www 1922:
1.1 www 1923: 1;
1924: __END__
1925:
1926:
1927:
1928:
1929:
1930:
1931:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>