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