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