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