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