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