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