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