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