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