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