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