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