Annotation of loncom/interface/lonmenu.pm, revision 1.309.2.2
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.309.2.2! raeburn 4: # $Id: lonmenu.pm,v 1.309.2.1 2009/12/07 20:04:18 raeburn Exp $
1.11 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 www 28: #
1.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 hidden_button_check()
117:
118: =item roles_selector()
119:
120: =item jump_to_role()
121:
122: =back
123:
124: =cut
125:
1.1 www 126: package Apache::lonmenu;
127:
128: use strict;
1.152 albertel 129: use Apache::lonnet;
1.47 matthew 130: use Apache::lonhtmlcommon();
1.115 albertel 131: use Apache::loncommon();
1.127 albertel 132: use Apache::lonenc();
1.88 www 133: use Apache::lonlocal;
1.207 foxr 134: use LONCAPA qw(:DEFAULT :match);
1.282 amueller 135: use HTML::Entities();
1.88 www 136:
1.283 droeschl 137: use vars qw(@desklines %category_names %category_members %category_positions
138: $readdesk @primary_menu @secondary_menu);
1.88 www 139:
1.56 www 140: my @inlineremote;
1.38 www 141:
1.283 droeschl 142: sub prep_menuitem {
1.291 raeburn 143: my ($menuitem) = @_;
144: return '' unless(ref($menuitem) eq 'ARRAY');
1.283 droeschl 145: my $link;
146: if ($$menuitem[1]) { # graphical Link
147: $link = "<img class=\"LC_noBorder\""
1.291 raeburn 148: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
149: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283 droeschl 150: } else { # textual Link
1.291 raeburn 151: $link = &mt($$menuitem[3]);
152: }
1.299 raeburn 153: return '<li><a href="'.$$menuitem[0].'">'.$link.'</a></li>';
1.283 droeschl 154: }
155:
156: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
157: # that contains following links:
158: # About, Message, Roles, Help, Logout
159: # @primary_menu is filled within the BEGIN block of this module with
160: # entries from mydesk.tab
161: sub primary_menu {
162: my $menu;
1.309.2.1 raeburn 163: my $custommenu = &Apache::loncommon::needs_gci_custom();
1.283 droeschl 164: # each element of @primary contains following array:
165: # (link url, icon path, alt text, link text, condition)
166: foreach my $menuitem (@primary_menu) {
167: # evaluate conditions
1.296 droeschl 168: next if ref($menuitem) ne 'ARRAY'; #
1.283 droeschl 169: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
1.291 raeburn 170: && &Apache::lonmsg::mynewmail(); # whether a new msg
1.283 droeschl 171: next if $$menuitem[4] eq 'newmsg' # arrived or not
1.291 raeburn 172: && !&Apache::lonmsg::mynewmail(); #
1.283 droeschl 173: next if $$menuitem[4] !~ /public/ ##we've a public user,
174: && $env{'user.name'} eq 'public' ##who should not see all
175: && $env{'user.domain'} eq 'public'; ##links
176: next if $$menuitem[4] eq 'onlypublic'# hide links which are
177: && $env{'user.name'} ne 'public' # only visible to public
178: && $env{'user.domain'} ne 'public'; # users
1.309.2.1 raeburn 179: next if $$menuitem[4] eq 'roles' # hide links which are
180: && $custommenu; # not visible when GCI
181: next if $$menuitem[4] eq 'courses' # tabbed interface in use
182: && $custommenu; #
1.283 droeschl 183: next if $$menuitem[4] eq 'roles' ##show links depending on
1.291 raeburn 184: && &Apache::loncommon::show_course(); ##term 'Courses' or
1.283 droeschl 185: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
1.291 raeburn 186: && !&Apache::loncommon::show_course(); ##
187:
188:
1.283 droeschl 189: if ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.291 raeburn 190: $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.283 droeschl 191: } else {
1.296 droeschl 192: my @items = @{$menuitem};
193: $items[0] = 'javascript:'.$menuitem->[0].';';
194: $menu .= &prep_menuitem(\@items);
1.283 droeschl 195: }
1.291 raeburn 196: }
1.283 droeschl 197:
1.291 raeburn 198: return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
1.283 droeschl 199: }
200:
201:
202: sub secondary_menu {
203: my $menu;
204:
1.286 raeburn 205: my $crstype = &Apache::loncommon::course_type();
206: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
207: my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'}
208: . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
209: : ''));
210: my $showlink = &show_return_link();
211: my %groups = &Apache::lonnet::get_active_groups(
212: $env{'user.domain'}, $env{'user.name'},
213: $env{'course.' . $env{'request.course.id'} . '.domain'},
214: $env{'course.' . $env{'request.course.id'} . '.num'});
1.283 droeschl 215: foreach my $menuitem (@secondary_menu) {
216: # evaluate conditions
1.296 droeschl 217: next if ref($menuitem) ne 'ARRAY';
1.283 droeschl 218: next if $$menuitem[4] ne 'always'
219: && !$env{'request.course.id'};
220: next if $$menuitem[4] eq 'showreturn'
1.286 raeburn 221: && !$showlink
1.283 droeschl 222: && !($env{'request.state'} eq 'construct');
223: next if $$menuitem[4] =~ /^mdc/
1.286 raeburn 224: && !$canedit;
225: next if $$menuitem[4] eq 'mdcCourse'
226: && $crstype eq 'Community';
227: next if $$menuitem[4] eq 'mdcCommunity'
228: && $crstype ne 'Community';
229: next if $$menuitem[4] =~ /^remotenav/
1.283 droeschl 230: && $env{'environment.remotenavmap'} ne 'on';
1.286 raeburn 231: next if $$menuitem[4] =~ /noremotenav/
1.283 droeschl 232: && $env{'environment.remotenavmap'} eq 'on';
1.295 raeburn 233: next if $$menuitem[4] =~ /^(no|)remotenav$/
234: && $crstype eq 'Community';
235: next if $$menuitem[4] =~ /^(no|)remotenavCommunity$/
236: && $crstype ne 'Community';
1.283 droeschl 237: next if $$menuitem[4] =~ /showgroups$/
1.300 raeburn 238: && !$canviewgrps
1.286 raeburn 239: && !%groups;
1.283 droeschl 240:
1.286 raeburn 241: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283 droeschl 242: # special treatment for role selector
1.298 raeburn 243: my $roles_selector = &roles_selector(
1.283 droeschl 244: $env{'course.' . $env{'request.course.id'} . '.domain'},
245: $env{'course.' . $env{'request.course.id'} . '.num'} );
246:
247: $menu .= $roles_selector ? "<li>$roles_selector</li>"
248: : '';
1.296 droeschl 249: } elsif ($env{'environment.remotenavmap'} eq 'on') {
250: # open link using javascript when remote navmap is activated
251: my @items = @{$menuitem};
252: if ($menuitem->[4] eq 'remotenav') {
253: $items[0] = "javascript:gonav('$menuitem->[0]');";
1.291 raeburn 254: } else {
1.296 droeschl 255: $items[0] = "javascript:go('$menuitem->[0]');";
1.291 raeburn 256: }
1.296 droeschl 257: $menu .= &prep_menuitem(\@items);
258: } else {
259: $menu .= &prep_menuitem(\@$menuitem);
1.283 droeschl 260: }
261: }
262: if ($menu =~ /\[url\].*\[symb\]/) {
1.291 raeburn 263: my $escurl = &escape( &Apache::lonenc::check_encrypt(
264: $env{'request.noversionuri'}));
1.283 droeschl 265:
1.291 raeburn 266: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
267: $env{'request.symb'}));
1.283 droeschl 268:
269: if ( $env{'request.state'} eq 'construct'
270: and ( $env{'request.noversionuri'} eq ''
271: || !defined($env{'request.noversionuri'})))
272: {
273: ($escurl = $env{'request.filename'}) =~
274: s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
275:
1.291 raeburn 276: $escurl = &escape($escurl);
1.283 droeschl 277: }
278: $menu =~ s/\[url\]/$escurl/g;
279: $menu =~ s/\[symb\]/$escsymb/g;
280: }
281:
1.285 wenzelju 282: return "<ul id=\"LC_secondary_menu\">$menu</ul>";
1.283 droeschl 283: }
284:
1.309.2.1 raeburn 285: sub gci_secondary_menu {
286: my %courses = (
287: 'review' => 'gci_9615072b469884921gcil1',
288: 'submit' => 'gci_1H96711d710194bfegcil1',
289: );
290: my %linktext = (
291: 'review' => 'Review Questions',
292: 'submit' => 'Submit Questions',
293: 'createtest' => 'Create a Test',
294: );
295: my (%links,$current);
296: foreach my $key (keys(%courses)) {
297: $links{$key} = "javascript:switchpage('$key');";
298: if ($env{'request.course.id'} eq $courses{$key}) {
299: $links{$key} = '/adm/navmaps';
300: $current = $key;
301: }
302: }
303: $links{'createtest'} = "javascript:switchpage('createtest');";
304: if (($ENV{'REQUEST_URI'} eq '/adm/requestcourse') ||
305: ($env{'form.orgurl'} eq '/adm/requestcourse')) {
306: $current = 'createtest';
307: }
308: my @menutabs = ('review','submit','createtest');
309: if ($env{'user.adv'}) {
310: my $key = 'managetest';
311: push(@menutabs,$key);
312: $linktext{$key} = 'Manage Tests';
313: $links{$key} = "javascript:switchpage('$key');";
314: if (($current eq '') && (($ENV{'REQUEST_URI'} eq '/adm/menu') ||
315: ($env{'form.orgurl'} eq '/adm/menu'))) {
316: $current = $key;
317: }
318: }
319: my $tabs;
320: foreach my $item (@menutabs) {
321: if ($item eq $current) {
322: $tabs .= ' <li id="current"><a href="'.$links{$item}.'">'.
323: $linktext{$item}.'</a></li>';
324: } else {
325: $tabs .= ' <li><a href="'.$links{$item}.'">'.
326: $linktext{$item}.'</a></li>';
327: }
328: }
329: return '<div id="gciheader">'.
330: '<ul>'.$tabs.'</ul></div><br />';
331: }
1.283 droeschl 332:
1.274 www 333: #
334: # This routine returns a translated hash for the menu items in the top inline menu row
335: # Probably should be in mydesk.tab
336:
1.283 droeschl 337: #SD this sub is deprecated - don't use it
1.88 www 338: sub initlittle {
339: return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
1.281 raeburn 340: 'nav' => 'Course Contents',
1.88 www 341: 'main' => 'Main Menu',
1.266 raeburn 342: 'roles' => (&Apache::loncommon::show_course()?
1.231 albertel 343: 'Courses':'Roles'),
1.235 raeburn 344: 'other' => 'Other Roles',
1.219 albertel 345: 'docs' => 'Edit Course',
1.257 hauer 346: 'exit' => 'Logout',
1.202 albertel 347: 'login' => 'Log In',
1.165 raeburn 348: 'launch' => 'Launch Remote Control',
1.188 albertel 349: 'groups' => 'Groups',
1.286 raeburn 350: 'gdoc' => 'Community Documents',
1.184 raeburn 351: );
1.88 www 352: }
353:
1.283 droeschl 354: #SD this sub is deprecated - don't use it
355: #SD functionality is covered by new loncommon::bodytag and primary_menu(), secondary_menu()
1.38 www 356: sub menubuttons {
357: my $forcereg=shift;
1.131 raeburn 358: my $titletable=shift;
1.274 www 359: #
360: # Early-out for pages that should not have a menu, triggered by query string "inhibitmenu=yes"
361: #
1.112 albertel 362: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
363: ['inhibitmenu']);
1.152 albertel 364: if (($env{'form.inhibitmenu'} eq 'yes') ||
1.149 www 365: ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
1.175 albertel 366:
367: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
368:
1.163 www 369: my %lt=&initlittle();
1.55 www 370: my $navmaps='';
1.59 www 371: my $reloadlink='';
1.151 www 372: my $docs='';
1.165 raeburn 373: my $groups='';
1.235 raeburn 374: my $roles='<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
375: my $role_selector;
1.165 raeburn 376: my $showgroups=0;
1.235 raeburn 377: my ($cnum,$cdom);
1.274 www 378: #
379: # if the URL is hidden, symbs and the non-versioned version of the URL would be encrypted
380: #
1.183 www 381: my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
382: my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
1.176 albertel 383:
1.199 albertel 384: my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
1.253 kaisler 385: $logo = '<a href="/adm/about.html"><img src="'.
386: $logo.'" alt="LON-CAPA Logo" class="LC_noBorder" /></a>';
1.199 albertel 387:
1.152 albertel 388: if ($env{'request.state'} eq 'construct') {
1.274 www 389: #
390: # We are in construction space
391: #
1.152 albertel 392: if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
393: my $returnurl = $env{'request.filename'};
1.134 raeburn 394: $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
1.183 www 395: $escurl = &escape($returnurl);
1.134 raeburn 396: }
397: }
1.165 raeburn 398: if ($env{'request.course.id'}) {
1.274 www 399: #
400: # We are in a course
401: #
1.235 raeburn 402: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
403: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.165 raeburn 404: my %coursegroups;
1.188 albertel 405: my $viewgrps_permission =
1.197 raeburn 406: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.165 raeburn 407: if (!$viewgrps_permission) {
1.235 raeburn 408: %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum);
1.188 albertel 409: }
1.165 raeburn 410: if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
411: $showgroups = 1;
412: }
1.235 raeburn 413: $role_selector = &roles_selector($cdom,$cnum);
414: if ($role_selector) {
415: $roles = '<span class="LC_nobreak">'.$role_selector.' <a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></span>';
416: }
1.165 raeburn 417: }
418:
1.267 droeschl 419: if ($env{'environment.remote'} eq 'off') {
1.48 www 420: # Remote Control is switched off
1.58 www 421: # figure out colors
1.267 droeschl 422: my %lt=&initlittle();
1.172 albertel 423:
1.58 www 424: my $domain=&Apache::loncommon::determinedomain();
1.291 raeburn 425: my $function=&Apache::loncommon::get_users_function();
1.58 www 426: my $link=&Apache::loncommon::designparm($function.'.link',$domain);
427: my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
428: my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
429: my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
1.267 droeschl 430:
431: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
432: return (<<ENDINLINEMENU);
1.285 wenzelju 433: <ol class="LC_primary_menu LC_right">
1.271 droeschl 434: <li>$logo</li>
435: <li><a href="/adm/roles" target="_top">$lt{'login'}</a></li>
436: </ol>
437: <hr />
1.156 albertel 438: ENDINLINEMENU
439: }
1.253 kaisler 440: $roles = '<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
1.58 www 441: # Do we have a NAV link?
1.152 albertel 442: if ($env{'request.course.id'}) {
1.141 albertel 443: my $link='/adm/navmaps?postdata='.$escurl.'&postsymb='.
444: $escsymb;
1.152 albertel 445: if ($env{'environment.remotenavmap'} eq 'on') {
1.141 albertel 446: $link="javascript:gonav('".$link."')";
447: }
448: $navmaps=(<<ENDNAV);
1.253 kaisler 449: <li><a href="$link" target="_top">$lt{'nav'}</a></li>
1.114 albertel 450: ENDNAV
1.286 raeburn 451: my $is_community =
452: (&Apache::loncommon::course_type() eq 'Community');
1.152 albertel 453: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.286 raeburn 454: my $text = ($is_community) ? $lt{'gdoc'} : $lt{'docs'};
1.151 www 455: $docs=(<<ENDDOCS);
1.253 kaisler 456: <li><a href="/adm/coursedocs" target="_top">$text</a></li>
1.151 www 457: ENDDOCS
458: }
1.197 raeburn 459: if ($showgroups) {
460: $groups =(<<ENDGROUPS);
1.253 kaisler 461: <li><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></li>
1.197 raeburn 462: ENDGROUPS
463: }
1.228 albertel 464: if (&show_return_link()) {
1.183 www 465: my $escreload=&escape('return:');
1.59 www 466: $reloadlink=(<<ENDRELOAD);
1.253 kaisler 467: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
1.59 www 468: ENDRELOAD
469: }
1.235 raeburn 470: if ($role_selector) {
1.253 kaisler 471: #$roles = '<td>'.$role_selector.'</td><td><a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></td>';
472: $role_selector = '<li>'.$role_selector.'</li>';
1.235 raeburn 473: }
1.55 www 474: }
1.163 www 475: if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
1.183 www 476: my $escreload=&escape('return:');
1.163 www 477: $reloadlink=(<<ENDCRELOAD);
1.253 kaisler 478: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
1.163 www 479: ENDCRELOAD
480: }
1.276 droeschl 481: my $reg = $forcereg ? &innerregister($forcereg,$titletable) : '';
482: my $form = &serverform();
483: my $utility = &utilityfunctions();
484:
485: #Prepare the message link that indicates the arrival of new mail
1.291 raeburn 486: my $messagelink = &Apache::lonmsg::mynewmail() ? "Message (new)" : "Message";
1.276 droeschl 487: $messagelink = '<a href="javascript:go(\'/adm/communicate\');">'
488: . mt($messagelink) .'</a>';
489:
490: my $helplink = &Apache::loncommon::top_nav_help('Help');
1.58 www 491: return (<<ENDINLINEMENU);
1.129 albertel 492: <script type="text/javascript">
1.277 bisitz 493: // <![CDATA[
1.150 albertel 494: // BEGIN LON-CAPA Internal
1.116 albertel 495: $utility
1.150 albertel 496: // ]]>
1.48 www 497: </script>
1.285 wenzelju 498: <ol class="LC_primary_menu LC_right">
1.253 kaisler 499: <li>$logo</li>
1.256 kaisler 500: <li>$messagelink</li>
1.253 kaisler 501: <li>$roles</li>
502: <li>$helplink</li>
503: <li><a href="/adm/logout" target="_top">$lt{'exit'}</a></li>
504: </ol>
1.285 wenzelju 505: <ul id="LC_secondary_menu">
1.253 kaisler 506: <li><a href="/adm/menu" target="_top">$lt{'main'}</a></li>
1.59 www 507: $reloadlink
1.55 www 508: $navmaps
1.151 www 509: $docs
1.165 raeburn 510: $groups
1.253 kaisler 511: $role_selector
1.263 droeschl 512: </ul>
1.168 albertel 513: $form
1.129 albertel 514: <script type="text/javascript">
1.48 www 515: // END LON-CAPA Internal
516: </script>
1.58 www 517: $reg
1.48 www 518: ENDINLINEMENU
519: } else {
520: return '';
521: }
1.72 www 522: }
523:
1.228 albertel 524: sub show_return_link {
525: return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
526: $env{'request.symb'} eq '')
527: ||
528: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
529: ||
530: (($env{'request.noversionuri'}=~/^\/adm\//) &&
531: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
532: ($env{'request.noversionuri'}!~
533: m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
534: ));
535: }
536:
1.38 www 537:
538: sub registerurl {
1.173 albertel 539: my ($forcereg) = @_;
1.38 www 540: my $result = '';
1.175 albertel 541: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.66 albertel 542: my $force_title='';
1.152 albertel 543: if ($env{'request.state'} eq 'construct') {
1.66 albertel 544: $force_title=&Apache::lonxml::display_title();
545: }
1.269 droeschl 546: if (($env{'environment.remote'} eq 'off') ||
1.152 albertel 547: ((($env{'request.publicaccess'}) ||
1.83 www 548: (!&Apache::lonnet::is_on_map(
1.183 www 549: &unescape($env{'request.noversionuri'})))) &&
1.38 www 550: (!$forcereg))) {
1.277 bisitz 551: return
552: $result
553: .'<script type="text/javascript">'."\n"
554: .'// <![CDATA['."\n"
555: .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
556: .'// ]]>'."\n"
557: .'</script>'
558: .$force_title;
1.38 www 559: }
1.41 www 560: # Graphical display after login only
1.174 albertel 561: if ($env{'request.registered'} && !$forcereg) { return ''; }
1.173 albertel 562: $result.=&innerregister($forcereg);
1.66 albertel 563: return $result.$force_title;
1.40 www 564: }
565:
566: sub innerregister {
1.308 raeburn 567: my ($forcereg,$titletable,$bread_crumbs) = @_;
1.40 www 568: my $result = '';
1.120 raeburn 569: my ($uname,$thisdisfn);
1.152 albertel 570: my $const_space = ($env{'request.state'} eq 'construct');
1.131 raeburn 571: my $is_const_dir = 0;
1.120 raeburn 572:
1.175 albertel 573: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40 www 574:
1.174 albertel 575: $env{'request.registered'} = 1;
1.40 www 576:
1.267 droeschl 577: my $noremote = ($env{'environment.remote'} eq 'off');
1.49 www 578:
1.177 albertel 579: undef(@inlineremote);
1.56 www 580:
1.38 www 581: my $reopen=&Apache::lonmenu::reopenmenu();
1.40 www 582:
1.38 www 583: my $newmail='';
1.267 droeschl 584:
585: if (&Apache::lonmsg::newmail() && !$noremote) {
586: # We have new mail and remote is up
587: $newmail= 'swmenu.setstatus("you have","messages");';
1.233 www 588: }
1.276 droeschl 589:
1.288 raeburn 590: my ($breadcrumb,$separator);
1.267 droeschl 591: if ($noremote
1.177 albertel 592: && ($env{'request.symb'})
593: && ($env{'request.course.id'})) {
1.267 droeschl 594:
595: my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
596: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
597:
598: my $maptitle = &Apache::lonnet::gettitle($mapurl);
599: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.299 raeburn 600: my $contentstext;
601: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Community') {
602: $contentstext = &mt('Community Contents');
603: } else {
604: $contentstext = &mt('Course Contents');
605: }
606: my @crumbs = ({text => $contentstext,
1.289 raeburn 607: href => "Javascript:gonav('/adm/navmaps')"});
608:
609: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
610: push(@crumbs, {text => '...',
611: no_mt => 1});
612: }
1.268 droeschl 613:
614: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
615: && $maptitle ne 'default.sequence'
616: && $maptitle ne $coursetitle);
617:
618: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
619:
1.291 raeburn 620: &Apache::lonhtmlcommon::clear_breadcrumbs();
621: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
1.301 droeschl 622: #$breadcrumb .= &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
1.288 raeburn 623: unless (($env{'request.state'} eq 'edit') || ($newmail) ||
624: ($env{'request.state'} eq 'construct') ||
625: ($env{'form.register'})) {
626: $separator = &Apache::loncommon::head_subbox();
627: }
1.267 droeschl 628: #
1.65 www 629: }
1.152 albertel 630: if ($env{'request.state'} eq 'construct') {
1.131 raeburn 631: $newmail = $titletable;
1.267 droeschl 632: }
633: my $timesync = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
634: my $tablestart = ( $noremote ? '<table id="LC_menubuttons">' : '');
635: my $tableend = ( $noremote ? '</table>' : '');
1.41 www 636: # =============================================================================
637: # ============================ This is for URLs that actually can be registered
1.296 droeschl 638: if (($env{'request.noversionuri'}!~m{^/(res/)*adm/}) || ($forcereg)) {
1.40 www 639: # -- This applies to homework problems for users with grading privileges
1.152 albertel 640: my $crs='/'.$env{'request.course.id'};
641: if ($env{'request.course.sec'}) {
642: $crs.='_'.$env{'request.course.sec'};
1.107 albertel 643: }
644: $crs=~s/\_/\//g;
645:
1.38 www 646: my $hwkadd='';
1.152 albertel 647: if ($env{'request.symb'} ne '' &&
1.161 albertel 648: $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
1.79 www 649: if (&Apache::lonnet::allowed('mgr',$crs)) {
1.259 bisitz 650: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]',
1.40 www 651: "gocmd('/adm/grades','gradingmenu')",
652: 'Modify user grades for this assessment resource');
1.154 www 653: } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
654: $hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
655: "gocmd('/adm/grades','submission')",
656: 'View user submissions for this assessment resource');
1.38 www 657: }
1.107 albertel 658: }
1.152 albertel 659: if ($env{'request.symb'} ne '' &&
1.145 albertel 660: &Apache::lonnet::allowed('opa',$crs)) {
1.107 albertel 661: $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
662: "gocmd('/adm/parmset','set')",
1.196 www 663: 'Modify parameter settings for this resource');
1.38 www 664: }
1.40 www 665: # -- End Homework
1.38 www 666: ###
667: ### Determine whether or not to display the 'cstr' button for this
668: ### resource
669: ###
670: my $editbutton = '';
1.258 raeburn 671: my $noeditbutton = 1;
672: my ($cnum,$cdom);
673: if ($env{'request.course.id'}) {
674: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
675: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
676: }
1.152 albertel 677: if ($env{'user.author'}) {
1.234 raeburn 678: if ($env{'request.role'}=~/^(aa|ca|au)/) {
1.274 www 679: #
680: # We have the role of an author
681: #
1.38 www 682: # Set defaults for authors
683: my ($top,$bottom) = ('con-','struct');
1.152 albertel 684: my $action = "go('/priv/".$env{'user.name'}."');";
685: my $cadom = $env{'request.role.domain'};
686: my $caname = $env{'user.name'};
1.236 bisitz 687: my $desc = "Enter my construction space";
1.38 www 688: # Set defaults for co-authors
1.152 albertel 689: if ($env{'request.role'} =~ /^ca/) {
1.206 albertel 690: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.38 www 691: ($top,$bottom) = ('co con-','struct');
692: $action = "go('/priv/".$caname."');";
693: $desc = "Enter construction space as co-author";
1.234 raeburn 694: } elsif ($env{'request.role'} =~ /^aa/) {
695: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
696: ($top,$bottom) = ('co con-','struct');
697: $action = "go('/priv/".$caname."');";
698: $desc = "Enter construction space as assistant co-author";
1.38 www 699: }
700: # Check that we are on the correct machine
701: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 702: my $allowed=0;
703: my @ids=&Apache::lonnet::current_machine_ids();
704: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
705: if (!$allowed) {
706: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
1.258 raeburn 707: $noeditbutton = 0;
1.38 www 708: }
709: }
1.274 www 710: #
711: # We are an author for some stuff, but currently do not have the role of author.
712: # Figure out if we have authoring privileges for the resource we are looking at.
713: # This should maybe become a privilege check in lonnet
714: #
1.38 www 715: ##
716: ## Determine if user can edit url.
717: ##
718: my $cfile='';
719: my $cfuname='';
720: my $cfudom='';
1.258 raeburn 721: my $uploaded;
1.152 albertel 722: if ($env{'request.filename'}) {
723: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.258 raeburn 724: if (defined($cnum) && defined($cdom)) {
725: $uploaded = &is_course_upload($file,$cnum,$cdom);
726: }
727: if (!$uploaded) {
728: $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
729: # Check that the user has permission to edit this resource
730: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
731: if (defined($cfudom)) {
732: my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
733: my $allowed=0;
734: my @ids=&Apache::lonnet::current_machine_ids();
735: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
736: if ($allowed) {
737: $cfile=$file;
738: }
1.38 www 739: }
740: }
1.258 raeburn 741: }
1.38 www 742: # Finally, turn the button on or off
1.120 raeburn 743: if ($cfile && !$const_space) {
1.302 raeburn 744: my $nocrsedit;
745: # Suppress display where CC has switched to student role.
746: if ($env{'request.course.id'}) {
747: unless(&Apache::lonnet::allowed('mdc',
748: $env{'request.course.id'})) {
749: $nocrsedit = 1;
750: }
751: }
752: if ($nocrsedit) {
753: $editbutton=&clear(6,1);
754: } else {
755: $editbutton=&switch
756: ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
1.38 www 757: "go('".$cfile."');","Edit this resource");
1.302 raeburn 758: $noeditbutton = 0;
759: }
1.38 www 760: } elsif ($editbutton eq '') {
1.191 www 761: $editbutton=&clear(6,1);
1.38 www 762: }
763: }
1.258 raeburn 764: if (($noeditbutton) && ($env{'request.filename'})) {
765: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
766: my $file=&Apache::lonnet::declutter($env{'request.filename'});
767: if (defined($cnum) && defined($cdom)) {
768: if (&is_course_upload($file,$cnum,$cdom)) {
769: my $cfile = &edit_course_upload($file,$cnum,$cdom);
770: if ($cfile) {
771: $editbutton=&switch
772: ('','',6,1,'pcstr.gif','edit[_1]',
773: 'resource[_2]',"go('".$cfile."');",
774: 'Edit this resource');
775: }
776: }
777: }
778: }
779: }
1.38 www 780: ###
781: ###
1.41 www 782: # Prepare the rest of the buttons
1.120 raeburn 783: my $menuitems;
784: if ($const_space) {
1.274 www 785: #
786: # We are in construction space
787: #
1.128 albertel 788: my ($uname,$thisdisfn) =
1.152 albertel 789: ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
1.121 raeburn 790: my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
1.131 raeburn 791: if ($currdir =~ m-/$-) {
792: $is_const_dir = 1;
793: } else {
1.267 droeschl 794: $currdir =~ s|[^/]+$||;
1.200 foxr 795: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208 albertel 796: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274 www 797: #
798: # Probably should be in mydesk.tab
799: #
1.131 raeburn 800: $menuitems=(<<ENDMENUITEMS);
1.208 albertel 801: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
1.200 foxr 802: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
1.259 bisitz 803: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
1.200 foxr 804: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
805: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
1.120 raeburn 806: ENDMENUITEMS
1.131 raeburn 807: }
1.308 raeburn 808: if ($noremote) {
809: if (ref($bread_crumbs) eq 'ARRAY') {
810: &Apache::lonhtmlcommon::clear_breadcrumbs();
811: foreach my $crumb (@{$bread_crumbs}){
812: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
813: }
814: }
815: }
1.203 foxr 816: } elsif ( defined($env{'request.course.id'}) &&
817: $env{'request.symb'} ne '' ) {
1.274 www 818: #
819: # We are in a course and looking at a registred URL
820: # Should probably be in mydesk.tab
821: #
1.120 raeburn 822: $menuitems=(<<ENDMENUITEMS);
1.41 www 823: c&3&1
1.209 www 824: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
825: 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 826: c&6&3
827: c&8&1
828: c&8&2
1.106 www 829: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.209 www 830: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
1.41 www 831: ENDMENUITEMS
1.216 albertel 832:
1.243 tempelho 833: my $currentURL = &Apache::loncommon::get_symb();
834: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
835: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
836: $menuitems.="s&9&3&";
837: if(length($annotation) > 0){
838: $menuitems.="anot2.gif";
839: }else{
840: $menuitems.="anot.gif";
841: }
842: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
843: $menuitems.="Make notes and annotations about this resource&&1\n";
844:
1.279 raeburn 845: unless ($noremote) {
846: my $showreqcrs = &check_for_rcrs();
847: if ($showreqcrs) {
848: $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]".
849: "&go('/adm/requestcourse')&Course requests\n";
850: }
851: }
1.193 raeburn 852: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
1.294 raeburn 853: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
1.216 albertel 854: $menuitems.=(<<ENDREALRES);
1.259 bisitz 855: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
1.216 albertel 856: ENDREALRES
857: }
1.120 raeburn 858: $menuitems.=(<<ENDREALRES);
1.106 www 859: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
860: 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 861: ENDREALRES
1.120 raeburn 862: }
863: }
1.203 foxr 864: if ($env{'request.uri'} =~ /^\/res/) {
865: $menuitems .= (<<ENDMENUITEMS);
866: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
867: ENDMENUITEMS
868: }
1.41 www 869: my $buttons='';
870: foreach (split(/\n/,$menuitems)) {
871: my ($command,@rest)=split(/\&/,$_);
1.220 raeburn 872: my $idx=10*$rest[0]+$rest[1];
873: if (&hidden_button_check() eq 'yes') {
874: if ($idx == 21 ||$idx == 23) {
875: $buttons.=&switch('','',@rest);
876: } else {
877: $buttons.=&clear(@rest);
878: }
879: } else {
880: if ($command eq 's') {
881: $buttons.=&switch('','',@rest);
882: } else {
883: $buttons.=&clear(@rest);
884: }
1.41 www 885: }
886: }
1.148 albertel 887:
1.267 droeschl 888: if ($noremote) {
1.148 albertel 889: my $addremote=0;
1.267 droeschl 890: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.148 albertel 891: my $inlinebuttons='';
1.301 droeschl 892: if ($addremote) {
893:
894: #SD START (work in progress!)
1.304 droeschl 895: Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301 droeschl 896: # Arrows for navigation
897: Apache::lonhtmlcommon::add_breadcrumb_tool( 'A', $inlineremote[21] );
898: Apache::lonhtmlcommon::add_breadcrumb_tool( 'A', $inlineremote[23] );
899: if(hidden_button_check() ne 'yes'){
900: # notes
901: Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[93]);
902: # bookmark
903: Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[91]);
904: # evaluate
905: Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[81]);
906: # feedback
907: Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[82]);
908: # print
909: Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[83]);
910: # metadata
911: Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[63]);
912:
913: # ?
914: Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[61]);
915: # ?
916: Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[71]);
917: # ?
918: Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[72]);
919: # ?
920: Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[73]);
921: # ?
922: Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[92]);
923:
924: }
925:
926: #SD END
927: # # Registered, textual output
928: # if ( $env{'environment.icons'} eq 'iconsonly' ) {
929: # $inlinebuttons = (<<ENDARROWSINLINE);
930: #<tr><td>
931: #$inlineremote[21] $inlineremote[23]
932: #ENDARROWSINLINE
933: # if ( &hidden_button_check() ne 'yes' ) {
934: # $inlinebuttons .= (<<ENDINLINEICONS);
935: #$inlineremote[61] $inlineremote[63]
936: #$inlineremote[71] $inlineremote[72] $inlineremote[73]
937: #$inlineremote[81] $inlineremote[82] $inlineremote[83]
938: #$inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
939: #ENDINLINEICONS
940: # }
941: # } else { # not iconsonly
942: # if ( $inlineremote[21] ne '' || $inlineremote[23] ne '' ) {
943: # $inlinebuttons = (<<ENDFIRSTLINE);
944: #<tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr>
945: #ENDFIRSTLINE
946: # }
947: # if ( &hidden_button_check() ne 'yes' ) {
948: # foreach my $row ( 6 .. 9 ) {
949: # if ( $inlineremote[ ${row} . '1' ] ne ''
950: # || $inlineremote[ $row . '2' ] ne ''
951: # || $inlineremote[ $row . '3' ] ne '' )
952: # {
953: # $inlinebuttons .= <<"ENDLINE";
954: #<tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
955: #ENDLINE
956: # }
957: # }
958: # }
959: # }
960: }
961: #SD see below
962: $breadcrumb = &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
1.41 www 963: $result =(<<ENDREGTEXT);
1.129 albertel 964: <script type="text/javascript">
1.42 www 965: // BEGIN LON-CAPA Internal
966: </script>
1.41 www 967: $timesync
1.267 droeschl 968: $breadcrumb
1.305 bisitz 969: <!-- $tablestart -->
970: <!-- $inlinebuttons -->
971: <!-- $tableend -->
1.224 albertel 972: $newmail
1.305 bisitz 973: <!-- $separator -->
1.129 albertel 974: <script type="text/javascript">
1.64 www 975: // END LON-CAPA Internal
1.42 www 976: </script>
977:
1.41 www 978: ENDREGTEXT
979: # Registered, graphical output
980: } else {
1.152 albertel 981: my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.183 www 982: $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
1.152 albertel 983: my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.113 albertel 984: my $navstatus=&get_nav_status();
1.140 albertel 985: my $clearcstr;
1.148 albertel 986:
1.152 albertel 987: if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1.41 www 988: $result = (<<ENDREGTHIS);
1.38 www 989:
1.129 albertel 990: <script type="text/javascript">
1.277 bisitz 991: // <![CDATA[
1.150 albertel 992: // BEGIN LON-CAPA Internal
1.42 www 993: var swmenu=null;
1.38 www 994:
995: function LONCAPAreg() {
996: swmenu=$reopen;
997: swmenu.clearTimeout(swmenu.menucltim);
998: $timesync
999: $newmail
1.41 www 1000: $buttons
1.84 www 1001: swmenu.currentURL="$requri";
1.85 www 1002: swmenu.reloadURL=swmenu.currentURL+window.location.search;
1.125 albertel 1003: swmenu.currentSymb="$cursymb";
1004: swmenu.reloadSymb="$cursymb";
1.38 www 1005: swmenu.currentStale=0;
1.113 albertel 1006: $navstatus
1.38 www 1007: $hwkadd
1008: $editbutton
1009: }
1010:
1011: function LONCAPAstale() {
1012: swmenu=$reopen
1013: swmenu.currentStale=1;
1014: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
1015: swmenu.switchbutton
1016: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
1017: }
1018: swmenu.clearbut(7,2);
1019: swmenu.clearbut(7,3);
1020: swmenu.menucltim=swmenu.setTimeout(
1021: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.140 albertel 1022: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1.38 www 1023: 2000);
1024: }
1025:
1.150 albertel 1026: // END LON-CAPA Internal
1.277 bisitz 1027: // ]]>
1.38 www 1028: </script>
1029: ENDREGTHIS
1.41 www 1030: }
1031: # =============================================================================
1.38 www 1032: } else {
1.41 www 1033: # ========================================== This can or will not be registered
1.267 droeschl 1034: if ($noremote) {
1.269 droeschl 1035: # Not registered
1.267 droeschl 1036: $result= (<<ENDDONOTREGTEXT);
1.41 www 1037: ENDDONOTREGTEXT
1038: } else {
1039: # Not registered, graphical
1040: $result = (<<ENDDONOTREGTHIS);
1.38 www 1041:
1.129 albertel 1042: <script type="text/javascript">
1.277 bisitz 1043: // <![CDATA[
1.38 www 1044: // BEGIN LON-CAPA Internal
1.42 www 1045: var swmenu=null;
1.38 www 1046:
1047: function LONCAPAreg() {
1048: swmenu=$reopen
1049: $timesync
1050: swmenu.currentStale=1;
1051: swmenu.clearbut(2,1);
1052: swmenu.clearbut(2,3);
1053: swmenu.clearbut(8,1);
1054: swmenu.clearbut(8,2);
1055: swmenu.clearbut(8,3);
1056: if (swmenu.currentURL) {
1057: swmenu.switchbutton
1058: (3,1,'reload.gif','return','location','go(currentURL)');
1059: } else {
1060: swmenu.clearbut(3,1);
1061: }
1062: }
1063:
1064: function LONCAPAstale() {
1065: }
1066:
1067: // END LON-CAPA Internal
1.277 bisitz 1068: // ]]>
1.38 www 1069: </script>
1070: ENDDONOTREGTHIS
1.41 www 1071: }
1072: # =============================================================================
1.38 www 1073: }
1074: return $result;
1075: }
1076:
1.258 raeburn 1077: sub is_course_upload {
1078: my ($file,$cnum,$cdom) = @_;
1079: my $uploadpath = &LONCAPA::propath($cdom,$cnum);
1080: $uploadpath =~ s{^\/}{};
1081: if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
1082: ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
1083: return 1;
1084: }
1085: return;
1086: }
1087:
1088: sub edit_course_upload {
1089: my ($file,$cnum,$cdom) = @_;
1090: my $cfile;
1091: if ($file =~/\.(htm|html|css|js|txt)$/) {
1092: my $ext = $1;
1093: my $url = &Apache::lonnet::hreflocation('',$file);
1094: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
1095: my @ids=&Apache::lonnet::current_machine_ids();
1096: my $dest;
1097: if ($home && grep(/^\Q$home\E$/,@ids)) {
1098: $dest = $url.'?forceedit=1';
1099: } else {
1100: unless (&Apache::lonnet::get_locks()) {
1101: $dest = '/adm/switchserver?otherserver='.
1102: $home.'&role='.$env{'request.role'}.
1103: '&url='.$url.'&forceedit=1';
1104: }
1105: }
1106: if ($dest) {
1107: $cfile = &HTML::Entities::encode($dest,'"<>&');
1108: }
1109: }
1110: return $cfile;
1111: }
1112:
1.38 www 1113: sub loadevents() {
1.152 albertel 1114: if ($env{'request.state'} eq 'construct' ||
1.175 albertel 1115: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38 www 1116: return 'LONCAPAreg();';
1117: }
1118:
1119: sub unloadevents() {
1.152 albertel 1120: if ($env{'request.state'} eq 'construct' ||
1.175 albertel 1121: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38 www 1122: return 'LONCAPAstale();';
1123: }
1.30 www 1124:
1.32 www 1125:
1126: sub startupremote {
1127: my ($lowerurl)=@_;
1.269 droeschl 1128: if ($env{'environment.remote'} eq 'off') {
1.34 www 1129: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
1130: }
1.49 www 1131: #
1132: # The Remote actually gets launched!
1133: #
1.32 www 1134: my $configmenu=&rawconfig();
1.183 www 1135: my $esclowerurl=&escape($lowerurl);
1.119 www 1136: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1.32 www 1137: return(<<ENDREMOTESTARTUP);
1.129 albertel 1138: <script type="text/javascript">
1.277 bisitz 1139: // <![CDATA[
1.118 albertel 1140: var timestart;
1.35 www 1141: function wheelswitch() {
1.118 albertel 1142: if (typeof(document.wheel) != 'undefined') {
1143: if (typeof(document.wheel.spin) != 'undefined') {
1144: var date=new Date();
1145: var waited=Math.round(30-((date.getTime()-timestart)/1000));
1146: document.wheel.spin.value=$message;
1147: }
1148: }
1.35 www 1149: if (window.status=='|') {
1150: window.status='/';
1151: } else {
1152: if (window.status=='/') {
1153: window.status='-';
1154: } else {
1155: if (window.status=='-') {
1156: window.status='\\\\';
1157: } else {
1158: if (window.status=='\\\\') { window.status='|'; }
1159: }
1160: }
1161: }
1162: }
1163:
1.32 www 1164: // ---------------------------------------------------------- The wait function
1165: var canceltim;
1166: function wait() {
1167: if ((menuloaded==1) || (tim==1)) {
1.35 www 1168: window.status='Done.';
1.32 www 1169: if (tim==0) {
1170: clearTimeout(canceltim);
1171: $configmenu
1172: window.location='$lowerurl';
1173: } else {
1.52 www 1174: window.location='/adm/remote?action=collapse&url=$esclowerurl';
1.32 www 1175: }
1176: } else {
1.35 www 1177: wheelswitch();
1178: setTimeout('wait();',200);
1.32 www 1179: }
1180: }
1181:
1182: function main() {
1.52 www 1183: canceltim=setTimeout('tim=1;',30000);
1.35 www 1184: window.status='-';
1.118 albertel 1185: var date=new Date();
1186: timestart=date.getTime();
1.32 www 1187: wait();
1188: }
1189:
1.277 bisitz 1190: // ]]>
1.32 www 1191: </script>
1192: ENDREMOTESTARTUP
1193: }
1194:
1195: sub setflags() {
1196: return(<<ENDSETFLAGS);
1.129 albertel 1197: <script type="text/javascript">
1.277 bisitz 1198: // <![CDATA[
1.32 www 1199: menuloaded=0;
1200: tim=0;
1.277 bisitz 1201: // ]]>
1.32 www 1202: </script>
1203: ENDSETFLAGS
1204: }
1205:
1206: sub maincall() {
1.269 droeschl 1207: if ($env{'environment.remote'} eq 'off') { return ''; }
1.32 www 1208: return(<<ENDMAINCALL);
1.129 albertel 1209: <script type="text/javascript">
1.277 bisitz 1210: // <![CDATA[
1.32 www 1211: main();
1.277 bisitz 1212: // ]]>
1.32 www 1213: </script>
1214: ENDMAINCALL
1215: }
1.118 albertel 1216:
1217: sub load_remote_msg {
1218: my ($lowerurl)=@_;
1219:
1.269 droeschl 1220: if ($env{'environment.remote'} eq 'off') { return ''; }
1.118 albertel 1221:
1.183 www 1222: my $esclowerurl=&escape($lowerurl);
1.261 bisitz 1223: my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
1224: ,'<a href="/adm/remote?action=collapse&url='.$esclowerurl.'">'
1225: ,'</a>');
1.118 albertel 1226: return(<<ENDREMOTEFORM);
1227: <p>
1228: <form name="wheel">
1.119 www 1229: <input name="spin" type="text" size="60" />
1.118 albertel 1230: </form>
1231: </p>
1232: <p>$link</p>
1233: ENDREMOTEFORM
1234: }
1.230 albertel 1235:
1236: sub get_menu_name {
1237: my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
1238: $hostid =~ s/\W//g;
1239: return 'LCmenu'.$hostid;
1240: }
1241:
1.30 www 1242:
1243: sub reopenmenu {
1.269 droeschl 1244: if ($env{'environment.remote'} eq 'off') { return ''; }
1.230 albertel 1245: my $menuname = &get_menu_name();
1.47 matthew 1246: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1247: return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30 www 1248: }
1249:
1.1 www 1250:
1251: sub open {
1.22 www 1252: my $returnval='';
1.269 droeschl 1253: if ($env{'environment.remote'} eq 'off') {
1.277 bisitz 1254: return
1255: '<script type="text/javascript">'."\n"
1256: .'// <![CDATA['."\n"
1257: .'self.name="loncapaclient";'."\n"
1258: .'// ]]>'."\n"
1259: .'</script>';
1.111 albertel 1260: }
1.230 albertel 1261: my $menuname = &get_menu_name();
1.222 albertel 1262:
1263: # unless (shift eq 'unix') {
1.22 www 1264: # resizing does not work on linux because of virtual desktop sizes
1.222 albertel 1265: # $returnval.=(<<ENDRESIZE);
1266: #if (window.screen) {
1267: # self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1268: # self.moveTo(190,15);
1269: #}
1270: #ENDRESIZE
1271: # }
1.277 bisitz 1272: $returnval=(<<ENDOPEN);
1273: // <![CDATA[
1.35 www 1274: window.status='Opening LON-CAPA Remote Control';
1.272 droeschl 1275: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
1.191 www 1276: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.71 www 1277: self.name='loncapaclient';
1.277 bisitz 1278: // ]]>
1.1 www 1279: ENDOPEN
1.129 albertel 1280: return '<script type="text/javascript">'.$returnval.'</script>';
1.1 www 1281: }
1282:
1.2 www 1283:
1284: # ================================================================== Raw Config
1285:
1.3 www 1286: sub clear {
1287: my ($row,$col)=@_;
1.269 droeschl 1288: unless ($env{'environment.remote'} eq 'off') {
1.275 www 1289: if (($row<1) || ($row>13)) { return ''; }
1.35 www 1290: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.56 www 1291: } else {
1292: $inlineremote[10*$row+$col]='';
1293: return '';
1294: }
1.3 www 1295: }
1296:
1.40 www 1297: # ============================================ Switch a button or create a link
1.25 matthew 1298: # Switch acts on the javascript that is executed when a button is clicked.
1299: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 1300:
1.2 www 1301: sub switch {
1.209 www 1302: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2 www 1303: $act=~s/\$uname/$uname/g;
1304: $act=~s/\$udom/$udom/g;
1.88 www 1305: $top=&mt($top);
1306: $bot=&mt($bot);
1307: $desc=&mt($desc);
1.238 www 1308: if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
1309: $img=&mt($img);
1310: }
1.209 www 1311: my $idx=10*$row+$col;
1312: $category_members{$cat}.=':'.$idx;
1313:
1.269 droeschl 1314: unless ($env{'environment.remote'} eq 'off') {
1.275 www 1315: if (($row<1) || ($row>13)) { return ''; }
1.50 www 1316: # Remote
1.34 www 1317: return "\n".
1.35 www 1318: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.34 www 1319: } else {
1.50 www 1320: # Inline Remote
1.213 www 1321: if ($env{'environment.icons'} ne 'classic') {
1322: $img=~s/\.gif$/\.png/;
1323: }
1.41 www 1324: if ($nobreak==2) { return ''; }
1.34 www 1325: my $text=$top.' '.$bot;
1.78 www 1326: $text=~s/\s*\-\s*//gs;
1.105 www 1327:
1.99 www 1328: my $pic=
1.225 albertel 1329: '<img alt="'.$text.'" src="'.
1330: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303 droeschl 1331: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.177 albertel 1332: if ($env{'browser.interface'} eq 'faketextual') {
1.274 www 1333: # Main Menu
1.103 www 1334: if ($nobreak==3) {
1.209 www 1335: $inlineremote[$idx]="\n".
1.177 albertel 1336: '<td class="LC_menubuttons_text" align="right">'.$text.
1.247 harmsja 1337: '</td><td align="left">'.
1.103 www 1338: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1339: } elsif ($nobreak) {
1.209 www 1340: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1341: '<td align="left">'.
1.177 albertel 1342: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215 www 1343: <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 1344: } else {
1.209 www 1345: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1346: '<td align="left">'.
1.103 www 1347: '<a href="javascript:'.$act.';">'.$pic.
1.177 albertel 1348: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215 www 1349: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103 www 1350: }
1.94 www 1351: } else {
1.103 www 1352: # Inline Menu
1.218 www 1353: if ($env{'environment.icons'} eq 'iconsonly') {
1354: $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
1355: } else {
1356: $inlineremote[$idx]=
1.301 droeschl 1357: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.215 www 1358: '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
1.218 www 1359: }
1.94 www 1360: }
1.34 www 1361: }
1.56 www 1362: return '';
1.2 www 1363: }
1364:
1365: sub secondlevel {
1366: my $output='';
1367: my
1.209 www 1368: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2 www 1369: if ($prt eq 'any') {
1.209 www 1370: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1371: } elsif ($prt=~/^r(\w+)/) {
1372: if ($rol eq $1) {
1.209 www 1373: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1374: }
1375: }
1376: return $output;
1377: }
1378:
1.18 www 1379: sub openmenu {
1.230 albertel 1380: my $menuname = &get_menu_name();
1.269 droeschl 1381: if ($env{'environment.remote'} eq 'off') { return ''; }
1.47 matthew 1382: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1383: return "window.open(".$nothing.",'".$menuname."');";
1.18 www 1384: }
1385:
1.56 www 1386: sub inlinemenu {
1.309.2.1 raeburn 1387: my ($context,$switcher) = @_;
1.210 albertel 1388: undef(@inlineremote);
1389: undef(%category_members);
1.309.2.1 raeburn 1390: my $output;
1391: if ($context eq 'gcicustom') {
1.309.2.2! raeburn 1392: $output ='<div class="LC_left_float">'.
1.309.2.1 raeburn 1393: '<fieldset id="LC_mainmenu_fieldset">'.
1394: '<legend class="LC_mainmenu_fieldset_category">'.&mt('Utilities').'</legend>'.
1395: '<table id="LC_menubuttons_mainmenu">';
1396: if ($switcher) {
1397: $output .= '<tr><td class="LC_menubuttons_img" align="left"><a href="javascript:courseswitcher('."'icon'".');"><img alt="choose role" src="/res/adm/pages/roles.png" align="left" /></a></td><td class="LC_menubuttons_text" colspan="3"><span class="LC_menubuttons_inline_text">'.$switcher.'</span></td></tr>';
1398: }
1399: $output .= '<tr><td class="LC_menubuttons_img" align="left"><a href="javascript:go('."'/adm/communicate'".');"><img alt="communication" src="/res/adm/pages/com.png" align="left" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:go('."'/adm/communicate'".');"><span class="LC_menubuttons_inline_text">'.&mt('Send and display messages').'</span></a></td></tr></table></fieldset></div>';
1400: if (($env{'request.course.id'}) &&
1401: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
1402: $output.= '<div class="LC_left_float">'.
1403: '<fieldset id="LC_mainmenu_fieldset">'.
1404: '<legend class="LC_mainmenu_fieldset_category">'.&mt('Test Management').'</legend>'.
1405: '<table id="LC_menubuttons_mainmenu">'.
1406: '<tr><td class="LC_menubuttons_img" align="left"><a href="javascript:go('."'/adm/createuser'".');"><img alt="user privs" src="/res/adm/pages/cprv.png" align="left" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:go('."'/adm/createuser'".');"><span class="LC_menubuttons_inline_text">'.&mt('Manage Enrollment').'</span></a></td></tr>'."\n".
1407: '<tr><td class="LC_menubuttons_img" align="left"><a href="javascript:go('."'/adm/whatsnew'".');"><img alt="what is new" src="/res/adm/pages/new.png" align="left" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:go('."'/adm/whatsnew'".');"><span class="LC_menubuttons_inline_text">'.&mt("What's New?").'</span></a></td></tr></table></fieldset></div>';
1408: }
1409: $output.='<br clear="all />';
1.309.2.2! raeburn 1410: } else {
1.309.2.1 raeburn 1411: # calling rawconfig with "1" will evaluate mydesk.tab,
1412: # even if there is no active remote control
1413: &rawconfig(1);
1.309.2.2! raeburn 1414: $output='<table><tr>';
1.309.2.1 raeburn 1415: for (my $col=1; $col<=2; $col++) {
1416: $output.='<td class="LC_mainmenu_col_fieldset">';
1417: for (my $row=1; $row<=8; $row++) {
1418: foreach my $cat (keys(%category_members)) {
1419: if ($category_positions{$cat} ne "$col,$row") { next; }
1420: $output.='<div class="LC_Box LC_400Box">';
1421: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1422: $output.='<table>';
1423: my %active=();
1424: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1425: if ($inlineremote[$menu_item]) {
1426: $active{$menu_item}=1;
1427: }
1428: }
1429: foreach my $item (sort(keys(%active))) {
1430: $output.=$inlineremote[$item];
1431: }
1432: $output.='</table>';
1433: $output.='</div>';
1.309.2.2! raeburn 1434: }
1.240 riegler 1435: }
1.309.2.1 raeburn 1436: $output.="</td>";
1437: }
1438: $output.="</tr></table>";
1.240 riegler 1439: }
1440: return $output;
1441: }
1442:
1.2 www 1443: sub rawconfig {
1.274 www 1444: #
1445: # This evaluates mydesk.tab
1446: # Need to add more positions and more privileges to deal with all
1447: # menu items.
1448: #
1.34 www 1449: my $textualoverride=shift;
1450: my $output='';
1.269 droeschl 1451: unless ($env{'environment.remote'} eq 'off') {
1.35 www 1452: $output.=
1453: "window.status='Opening Remote Control';var swmenu=".&openmenu().
1454: "\nwindow.status='Configuring Remote Control ';";
1.34 www 1455: } else {
1456: unless ($textualoverride) { return ''; }
1457: }
1.152 albertel 1458: my $uname=$env{'user.name'};
1459: my $udom=$env{'user.domain'};
1460: my $adv=$env{'user.adv'};
1.266 raeburn 1461: my $show_course=&Apache::loncommon::show_course();
1.152 albertel 1462: my $author=$env{'user.author'};
1.5 www 1463: my $crs='';
1.295 raeburn 1464: my $crstype='';
1.152 albertel 1465: if ($env{'request.course.id'}) {
1466: $crs='/'.$env{'request.course.id'};
1467: if ($env{'request.course.sec'}) {
1468: $crs.='_'.$env{'request.course.sec'};
1.7 www 1469: }
1.8 www 1470: $crs=~s/\_/\//g;
1.295 raeburn 1471: $crstype = &Apache::loncommon::course_type();
1.5 www 1472: }
1.152 albertel 1473: my $pub=($env{'request.state'} eq 'published');
1474: my $con=($env{'request.state'} eq 'construct');
1475: my $rol=$env{'request.role'};
1476: my $requested_domain = $env{'request.role.domain'};
1.184 raeburn 1477: foreach my $line (@desklines) {
1.209 www 1478: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3 www 1479: $prt=~s/\$uname/$uname/g;
1480: $prt=~s/\$udom/$udom/g;
1.295 raeburn 1481: if ($prt =~ /\$crs/) {
1482: next unless ($env{'request.course.id'});
1483: next if ($crstype eq 'Community');
1484: $prt=~s/\$crs/$crs/g;
1485: } elsif ($prt =~ /\$cmty/) {
1486: next unless ($env{'request.course.id'});
1487: next if ($crstype ne 'Community');
1488: $prt=~s/\$cmty/$crs/g;
1489: }
1.25 matthew 1490: $prt=~s/\$requested_domain/$requested_domain/g;
1.211 www 1491: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3 www 1492: if ($pro eq 'clear') {
1.4 www 1493: $output.=&clear($row,$col);
1.3 www 1494: } elsif ($pro eq 'any') {
1.2 www 1495: $output.=&secondlevel(
1.209 www 1496: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1497: } elsif ($pro eq 'smp') {
1498: unless ($adv) {
1499: $output.=&secondlevel(
1.209 www 1500: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1501: }
1502: } elsif ($pro eq 'adv') {
1503: if ($adv) {
1504: $output.=&secondlevel(
1.209 www 1505: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1506: }
1.231 albertel 1507: } elsif ($pro eq 'shc') {
1508: if ($show_course) {
1509: $output.=&secondlevel(
1510: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1511: }
1512: } elsif ($pro eq 'nsc') {
1513: if (!$show_course) {
1514: $output.=&secondlevel(
1515: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1516: }
1.81 matthew 1517: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295 raeburn 1518: my $priv = $1;
1519: if ($priv =~ /^mdc(Course|Community)/) {
1520: if ($crstype eq $1) {
1521: $priv = 'mdc';
1522: } else {
1523: next;
1524: }
1525: }
1526: if (&Apache::lonnet::allowed($priv,$prt)) {
1.209 www 1527: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4 www 1528: }
1.295 raeburn 1529: } elsif ($pro eq 'course') {
1530: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209 www 1531: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81 matthew 1532: }
1.295 raeburn 1533: } elsif ($pro eq 'community') {
1534: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1535: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1536: }
1.124 matthew 1537: } elsif ($pro =~ /^courseenv_(.*)$/) {
1538: my $key = $1;
1.307 raeburn 1539: if ($crstype ne 'Community') {
1540: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1541: if ($key eq 'canuse_pdfforms') {
1542: if ($env{'request.course.id'} && $coursepref eq '') {
1543: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1544: $coursepref = $domdefs{'canuse_pdfforms'};
1545: }
1546: }
1547: if ($coursepref) {
1548: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1549: }
1.295 raeburn 1550: }
1551: } elsif ($pro =~ /^communityenv_(.*)$/) {
1552: my $key = $1;
1.307 raeburn 1553: if ($crstype eq 'Community') {
1554: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1555: if ($key eq 'canuse_pdfforms') {
1556: if ($env{'request.course.id'} && $coursepref eq '') {
1557: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1558: $coursepref = $domdefs{'canuse_pdfforms'};
1559: }
1560: }
1561: if ($coursepref) {
1562: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1563: }
1.124 matthew 1564: }
1.81 matthew 1565: } elsif ($pro =~ /^course_(.*)$/) {
1566: # Check for permissions inside of a course
1.295 raeburn 1567: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1.152 albertel 1568: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1569: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81 matthew 1570: )) {
1.209 www 1571: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26 www 1572: }
1.295 raeburn 1573: } elsif ($pro =~ /^community_(.*)$/) {
1574: # Check for permissions inside of a community
1575: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1576: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1577: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1578: )) {
1579: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1580: }
1.4 www 1581: } elsif ($pro eq 'author') {
1582: if ($author) {
1.152 albertel 1583: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234 raeburn 1584: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1.152 albertel 1585: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19 matthew 1586: # Check that we are on the correct machine
1.29 matthew 1587: my $cadom=$requested_domain;
1.152 albertel 1588: my $caname=$env{'user.name'};
1.234 raeburn 1589: if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29 matthew 1590: ($cadom,$caname)=
1.206 albertel 1591: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29 matthew 1592: }
1593: $act =~ s/\$caname/$caname/g;
1.19 matthew 1594: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 1595: my $allowed=0;
1596: my @ids=&Apache::lonnet::current_machine_ids();
1597: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1598: if ($allowed) {
1.209 www 1599: $output.=&switch($caname,$cadom,
1600: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19 matthew 1601: }
1.6 www 1602: }
1.2 www 1603: }
1.248 raeburn 1604: } elsif ($pro eq 'tools') {
1605: my @tools = ('aboutme','blog','portfolio');
1606: if (grep(/^\Q$prt\E$/,@tools)) {
1.249 raeburn 1607: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251 raeburn 1608: $env{'user.domain'},
1609: $prt,undef,'tools')) {
1610: $output.=&clear($row,$col);
1611: next;
1612: }
1.278 raeburn 1613: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1614: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1615: next;
1616: }
1617: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1618: next;
1619: }
1.279 raeburn 1620: my $showreqcrs = &check_for_rcrs();
1.251 raeburn 1621: if (!$showreqcrs) {
1.248 raeburn 1622: $output.=&clear($row,$col);
1623: next;
1624: }
1625: }
1626: $prt='any';
1627: $output.=&secondlevel(
1628: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1629: }
1.13 harris41 1630: }
1.269 droeschl 1631: unless ($env{'environment.remote'} eq 'off') {
1.35 www 1632: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.123 www 1633: if (&Apache::lonmsg::newmail()) {
1634: $output.='swmenu.setstatus("you have","messages");';
1635: }
1.34 www 1636: }
1.123 www 1637:
1.2 www 1638: return $output;
1639: }
1640:
1.279 raeburn 1641: sub check_for_rcrs {
1642: my $showreqcrs = 0;
1.280 raeburn 1643: my @reqtypes = ('official','unofficial','community');
1644: foreach my $type (@reqtypes) {
1.279 raeburn 1645: if (&Apache::lonnet::usertools_access($env{'user.name'},
1646: $env{'user.domain'},
1647: $type,undef,'requestcourses')) {
1648: $showreqcrs = 1;
1649: last;
1650: }
1651: }
1.280 raeburn 1652: if (!$showreqcrs) {
1653: foreach my $type (@reqtypes) {
1654: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1655: $showreqcrs = 1;
1656: last;
1657: }
1658: }
1659: }
1.279 raeburn 1660: return $showreqcrs;
1661: }
1662:
1.2 www 1663: # ======================================================================= Close
1.1 www 1664:
1665: sub close {
1.269 droeschl 1666: if ($env{'environment.remote'} eq 'off') { return ''; }
1.230 albertel 1667: my $menuname = &get_menu_name();
1.1 www 1668: return(<<ENDCLOSE);
1.129 albertel 1669: <script type="text/javascript">
1.277 bisitz 1670: // <![CDATA[
1.35 www 1671: window.status='Accessing Remote Control';
1.30 www 1672: menu=window.open("/adm/rat/empty.html","$menuname",
1.1 www 1673: "height=350,width=150,scrollbars=no,menubar=no");
1.35 www 1674: window.status='Disabling Remote Control';
1675: menu.active=0;
1.31 www 1676: menu.autologout=0;
1.35 www 1677: window.status='Closing Remote Control';
1.1 www 1678: menu.close();
1.35 www 1679: window.status='Done.';
1.277 bisitz 1680: // ]]>
1.1 www 1681: </script>
1682: ENDCLOSE
1683: }
1684:
1685: # ====================================================================== Footer
1686:
1687: sub footer {
1688:
1.33 www 1689: }
1690:
1.122 albertel 1691: sub nav_control_js {
1.152 albertel 1692: my $nav=($env{'environment.remotenavmap'} eq 'on');
1.122 albertel 1693: return (<<NAVCONTROL);
1694: var w_loncapanav_flag="$nav";
1695:
1696:
1697: function gonav(url) {
1698: if (w_loncapanav_flag != 1) {
1699: gopost(url,'');
1700: } else {
1701: navwindow=window.open(url,
1702: "loncapanav","height=600,width=400,scrollbars=1");
1703: }
1704: }
1705: NAVCONTROL
1706: }
1707:
1.306 raeburn 1708: sub dc_popup_js {
1709: my %lt = &Apache::lonlocal::texthash(
1710: more => '(More ...)',
1711: less => '(Less ...)',
1712: );
1713: return <<"END";
1714:
1715: function showCourseID() {
1716: document.getElementById('dccid').style.display='block';
1717: document.getElementById('dccid').style.textAlign='left';
1.307 raeburn 1718: document.getElementById('dccid').style.textFace='normal';
1.306 raeburn 1719: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>';
1720: return;
1721: }
1722:
1723: function hideCourseID() {
1724: document.getElementById('dccid').style.display='none';
1725: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()">$lt{'more'}</a>';
1726: return;
1727: }
1728:
1729: END
1730:
1731: }
1732:
1.42 www 1733: sub utilityfunctions {
1.309.2.1 raeburn 1734: my ($caller,$custommenu) = @_;
1.269 droeschl 1735: unless ($env{'environment.remote'} eq 'off' ||
1736: $caller eq '/adm/menu') {
1737: return ''; }
1.309.2.1 raeburn 1738:
1739: my $gcimenujs;
1740: if ($custommenu) {
1741: my %concepttests = &Apache::loncommon::existing_gcitest_courses();
1742: my $managetesturl = '/adm/menu';
1743: my $createtesturl = '/adm/requestcourse';
1744: if (($env{'request.course.id'}) &&
1745: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq 'gci')) {
1746: my @items = keys(%concepttests);
1747: if (@items== 1) {
1748: my $newrole = $items[0];
1749: $newrole =~ s{_}{/};
1750: $managetesturl = '/adm/roles?selectrole=1&cc./'.$newrole.'=1';
1751: } else {
1752: $managetesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu';
1753: }
1754: }
1755: if ($env{'request.course.id'}) {
1756: $createtesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2frequestcourse';
1757: }
1758: $gcimenujs = <<"ENDCUSTOM";
1759:
1760: function switchpage(caller) {
1761: if (caller == 'review') {
1762: document.location.href = '/adm/roles?selectrole=1&st./gci/9615072b469884921gcil1=1';
1763: }
1764: if (caller == 'submit') {
1765: document.location.href = '/adm/roles?selectrole=1&st./gci/1H96711d710194bfegcil1=1';
1766: }
1767: if (caller == 'createtest') {
1768: document.location.href = '$createtesturl';
1769: }
1770: if (caller == 'managetest') {
1771: document.location.href = '$managetesturl';
1772: }
1773: return;
1774: }
1775:
1776: ENDCUSTOM
1777: }
1778:
1.152 albertel 1779: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.293 raeburn 1780: if ($currenturl =~ m{^/adm/wrapper/ext/}) {
1781: if ($env{'request.external.querystring'}) {
1782: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1783: }
1784: }
1.183 www 1785: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125 albertel 1786:
1.152 albertel 1787: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.122 albertel 1788: my $nav_control=&nav_control_js();
1.175 albertel 1789:
1.306 raeburn 1790: my $dc_popup_cid;
1791: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1792: $env{'course.'.$env{'request.course.id'}.
1793: '.domain'}.'/'})) {
1794: $dc_popup_cid = &dc_popup_js();
1795: }
1796:
1.175 albertel 1797: my $start_page_annotate =
1798: &Apache::loncommon::start_page('Annotator',undef,
1799: {'only_body' => 1,
1800: 'js_ready' => 1,
1801: 'bgcolor' => '#BBBBBB',
1802: 'add_entries' => {
1803: 'onload' => 'javascript:document.goannotate.submit();'}});
1804:
1.205 albertel 1805: my $end_page_annotate =
1806: &Apache::loncommon::end_page({'js_ready' => 1});
1807:
1.175 albertel 1808: my $start_page_bookmark =
1809: &Apache::loncommon::start_page('Bookmarks',undef,
1810: {'only_body' => 1,
1811: 'js_ready' => 1,
1812: 'bgcolor' => '#BBBBBB',});
1813:
1.205 albertel 1814: my $end_page_bookmark =
1.175 albertel 1815: &Apache::loncommon::end_page({'js_ready' => 1});
1816:
1.42 www 1817: return (<<ENDUTILITY)
1818:
1819: var currentURL="$currenturl";
1820: var reloadURL="$currenturl";
1821: var currentSymb="$currentsymb";
1822:
1.114 albertel 1823: $nav_control
1.306 raeburn 1824: $dc_popup_cid
1.114 albertel 1825:
1.309.2.1 raeburn 1826: $gcimenujs
1827:
1.42 www 1828: function go(url) {
1829: if (url!='' && url!= null) {
1830: currentURL = null;
1831: currentSymb= null;
1832: window.location.href=url;
1833: }
1834: }
1835:
1.297 raeburn 1836: function gotop(url) {
1837: if (url!='' && url!= null) {
1838: top.location.href = url;
1839: }
1840: }
1841:
1.42 www 1842: function gopost(url,postdata) {
1843: if (url!='') {
1844: this.document.server.action=url;
1845: this.document.server.postdata.value=postdata;
1846: this.document.server.command.value='';
1847: this.document.server.url.value='';
1848: this.document.server.symb.value='';
1849: this.document.server.submit();
1850: }
1851: }
1852:
1853: function gocmd(url,cmd) {
1854: if (url!='') {
1855: this.document.server.action=url;
1856: this.document.server.postdata.value='';
1857: this.document.server.command.value=cmd;
1858: this.document.server.url.value=currentURL;
1859: this.document.server.symb.value=currentSymb;
1860: this.document.server.submit();
1861: }
1.57 www 1862: }
1863:
1.121 raeburn 1864: function gocstr(url,filename) {
1865: if (url == '/adm/cfile?action=delete') {
1866: this.document.cstrdelete.filename.value = filename
1867: this.document.cstrdelete.submit();
1868: return;
1869: }
1.137 raeburn 1870: if (url == '/adm/printout') {
1871: this.document.cstrprint.postdata.value = filename
1872: this.document.cstrprint.curseed.value = 0;
1873: this.document.cstrprint.problemtype.value = 0;
1.138 raeburn 1874: if (this.document.lonhomework) {
1875: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1876: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1877: }
1878: if (this.document.lonhomework.problemtype) {
1.164 albertel 1879: if (this.document.lonhomework.problemtype.value) {
1880: this.document.cstrprint.problemtype.value =
1881: this.document.lonhomework.problemtype.value;
1882: } else if (this.document.lonhomework.problemtype.options) {
1883: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1884: if (this.document.lonhomework.problemtype.options[i].selected) {
1885: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1886: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1887: }
1888: }
1889: }
1890: }
1891: }
1892: }
1.137 raeburn 1893: this.document.cstrprint.submit();
1894: return;
1895: }
1.121 raeburn 1896: if (url !='') {
1897: this.document.constspace.filename.value = filename;
1898: this.document.constspace.action = url;
1899: this.document.constspace.submit();
1900: }
1901: }
1902:
1.131 raeburn 1903: function golist(url) {
1904: if (url!='' && url!= null) {
1905: currentURL = null;
1906: currentSymb= null;
1907: top.location.href=url;
1908: }
1909: }
1910:
1911:
1.121 raeburn 1912:
1.57 www 1913: function catalog_info() {
1.102 albertel 1914: 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 1915: }
1916:
1917: function chat_win() {
1.290 raeburn 1918: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42 www 1919: }
1.169 raeburn 1920:
1921: function group_chat(group) {
1922: var url = '/adm/groupchat?group='+group;
1923: var winName = 'LONchat_'+group;
1924: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1925: }
1.175 albertel 1926:
1927: function edit_bookmarks() {
1928: go('');
1929: w_BookmarkPal_flag=1;
1930: bookmarkpal=window.open("/adm/bookmarks",
1931: "BookmarkPal", "width=400,height=505,scrollbars=0");
1932: }
1933:
1934: function annotate() {
1935: w_Annotator_flag=1;
1936: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1937: annotator.document.write(
1938: '$start_page_annotate'
1939: +"<form name='goannotate' target='Annotator' method='post' "
1940: +"action='/adm/annotations'>"
1.217 albertel 1941: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181 albertel 1942: +"<\\/form>"
1.205 albertel 1943: +'$end_page_annotate');
1.175 albertel 1944: annotator.document.close();
1945: }
1946:
1947: function set_bookmark() {
1948: go('');
1949: clienttitle=document.title;
1950: clienthref=location.pathname;
1951: w_bmquery_flag=1;
1952: bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
1953: bmquery.document.write(
1954: '$start_page_bookmark'
1.260 bisitz 1955: +'<center><form method="post"'
1956: +' name="newlink" action="/adm/bookmarks" target="bmquery" '
1957: +'> <table width="340" height="150" '
1958: +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
1959: +'type="text" name="title" size="45" value="'+clienttitle+'" />'
1960: +'<br />Address:<br /><input type="text" name="address" size="45" '
1961: +'value="'+clienthref+'" /><br /><center><input type="submit" '
1962: +'value="Save" /> <input type="button" value="Close" '
1963: +'onclick="javascript:window.close();" /></center></td>'
1964: +'</tr></table></form></center>'
1.205 albertel 1965: +'$end_page_bookmark' );
1.175 albertel 1966: bmquery.document.close();
1967: }
1968:
1.42 www 1969: ENDUTILITY
1970: }
1971:
1972: sub serverform {
1973: return(<<ENDSERVERFORM);
1.181 albertel 1974: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 1975: <input type="hidden" name="postdata" value="none" />
1976: <input type="hidden" name="command" value="none" />
1977: <input type="hidden" name="url" value="none" />
1978: <input type="hidden" name="symb" value="none" />
1979: </form>
1980: ENDSERVERFORM
1981: }
1.113 albertel 1982:
1.121 raeburn 1983: sub constspaceform {
1984: return(<<ENDCONSTSPACEFORM);
1.181 albertel 1985: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121 raeburn 1986: <input type="hidden" name="filename" value="" />
1987: </form>
1.181 albertel 1988: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121 raeburn 1989: <input type="hidden" name="action" value="delete" />
1990: <input type="hidden" name="filename" value="" />
1991: </form>
1.181 albertel 1992: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137 raeburn 1993: <input type="hidden" name="postdata" value="" />
1994: <input type="hidden" name="curseed" value="" />
1995: <input type="hidden" name="problemtype" value="" />
1996: </form>
1997:
1.121 raeburn 1998: ENDCONSTSPACEFORM
1999: }
2000:
2001:
1.113 albertel 2002: sub get_nav_status {
2003: my $navstatus="swmenu.w_loncapanav_flag=";
1.152 albertel 2004: if ($env{'environment.remotenavmap'} eq 'on') {
1.113 albertel 2005: $navstatus.="1";
2006: } else {
2007: $navstatus.="-1";
2008: }
2009: return $navstatus;
2010: }
2011:
1.220 raeburn 2012: sub hidden_button_check {
2013: my $hidden;
2014: if ($env{'request.course.id'} eq '') {
2015: return;
2016: }
2017: if ($env{'request.role.adv'}) {
2018: return;
2019: }
1.232 raeburn 2020: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
2021: return $buttonshide;
1.220 raeburn 2022: }
1.184 raeburn 2023:
1.235 raeburn 2024: sub roles_selector {
2025: my ($cdom,$cnum) = @_;
1.298 raeburn 2026: my $crstype = &Apache::loncommon::course_type();
1.235 raeburn 2027: my $now = time;
1.262 raeburn 2028: my (%courseroles,%seccount);
1.235 raeburn 2029: my $is_cc;
2030: my $role_selector;
1.298 raeburn 2031: my $ccrole;
2032: if ($crstype eq 'Community') {
2033: $ccrole = 'co';
2034: } else {
2035: $ccrole = 'cc';
2036: }
2037: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
2038: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235 raeburn 2039:
2040: if ((($start) && ($start<0)) ||
2041: (($end) && ($end<$now)) ||
2042: (($start) && ($now<$start))) {
2043: $is_cc = 0;
2044: } else {
2045: $is_cc = 1;
2046: }
2047: }
2048: if ($is_cc) {
1.264 raeburn 2049: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
1.235 raeburn 2050: } else {
1.262 raeburn 2051: my %gotnosection;
1.235 raeburn 2052: foreach my $item (keys(%env)) {
1.239 raeburn 2053: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235 raeburn 2054: my $role = $1;
2055: my $sec = $2;
2056: next if ($role eq 'gr');
2057: my ($start,$end) = split(/\./,$env{$item});
2058: next if (($start && $start > $now) || ($end && $end < $now));
2059: if ($sec eq '') {
1.239 raeburn 2060: if (!$gotnosection{$role}) {
2061: $seccount{$role} ++;
2062: $gotnosection{$role} = 1;
2063: }
1.235 raeburn 2064: }
2065: if (ref($courseroles{$role}) eq 'ARRAY') {
1.239 raeburn 2066: if ($sec ne '') {
1.264 raeburn 2067: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239 raeburn 2068: push(@{$courseroles{$role}},$sec);
2069: $seccount{$role} ++;
2070: }
2071: }
2072: } else {
2073: @{$courseroles{$role}} = ();
2074: if ($sec ne '') {
2075: $seccount{$role} ++;
1.235 raeburn 2076: push(@{$courseroles{$role}},$sec);
2077: }
2078: }
2079: }
2080: }
2081: }
1.286 raeburn 2082: my $switchtext;
2083: if ($crstype eq 'Community') {
2084: $switchtext = &mt('Switch community role to...')
2085: } else {
2086: $switchtext = &mt('Switch course role to...')
2087: }
1.298 raeburn 2088: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.235 raeburn 2089: if (keys(%courseroles) > 1) {
1.239 raeburn 2090: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
1.235 raeburn 2091: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
2092: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1.286 raeburn 2093: $role_selector .= '<option value="">'.$switchtext.'</option>';
1.235 raeburn 2094: foreach my $role (@roles_order) {
2095: if (defined($courseroles{$role})) {
1.298 raeburn 2096: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>';
1.235 raeburn 2097: }
2098: }
2099: foreach my $role (sort(keys(%courseroles))) {
2100: if ($role =~ /^cr/) {
2101: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
2102: }
2103: }
2104: $role_selector .= '</select>'."\n".
2105: '<input type="hidden" name="destinationurl" value="'.
1.282 amueller 2106: &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n".
1.235 raeburn 2107: '<input type="hidden" name="gotorole" value="1" />'."\n".
2108: '<input type="hidden" name="selectrole" value="" />'."\n".
2109: '<input type="hidden" name="switch" value="1" />'."\n".
2110: '</form>';
2111: }
2112: return $role_selector;
2113: }
2114:
1.262 raeburn 2115: sub get_all_courseroles {
2116: my ($cdom,$cnum,$courseroles,$seccount) = @_;
2117: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
2118: return;
2119: }
2120: my ($result,$cached) =
2121: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
2122: if (defined($cached)) {
2123: if (ref($result) eq 'HASH') {
2124: if ((ref($result->{'roles'}) eq 'HASH') &&
2125: (ref($result->{'seccount'}) eq 'HASH')) {
2126: %{$courseroles} = %{$result->{'roles'}};
2127: %{$seccount} = %{$result->{'seccount'}};
2128: return;
2129: }
2130: }
2131: }
2132: my %gotnosection;
2133: my %adv_roles =
2134: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
2135: foreach my $role (keys(%adv_roles)) {
2136: my ($urole,$usec) = split(/:/,$role);
2137: if (!$gotnosection{$urole}) {
2138: $seccount->{$urole} ++;
2139: $gotnosection{$urole} = 1;
2140: }
2141: if (ref($courseroles->{$urole}) eq 'ARRAY') {
2142: if ($usec ne '') {
2143: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
2144: push(@{$courseroles->{$urole}},$usec);
2145: $seccount->{$urole} ++;
2146: }
2147: }
2148: } else {
2149: @{$courseroles->{$urole}} = ();
2150: if ($usec ne '') {
2151: $seccount->{$urole} ++;
2152: push(@{$courseroles->{$urole}},$usec);
2153: }
2154: }
2155: }
2156: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
2157: @{$courseroles->{'st'}} = ();
2158: if (keys(%sections_count) > 0) {
2159: push(@{$courseroles->{'st'}},keys(%sections_count));
2160: $seccount->{'st'} = scalar(keys(%sections_count));
2161: }
2162: my $rolehash = {
2163: 'roles' => $courseroles,
2164: 'seccount' => $seccount,
2165: };
2166: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
2167: return;
2168: }
2169:
1.235 raeburn 2170: sub jump_to_role {
1.239 raeburn 2171: my ($cdom,$cnum,$seccount,$courseroles) = @_;
2172: my %lt = &Apache::lonlocal::texthash(
2173: this => 'This role has section(s) associated with it.',
2174: ente => 'Enter a specific section.',
2175: orlb => 'Enter a specific section, or leave blank for no section.',
2176: avai => 'Available sections are:',
2177: youe => 'You entered an invalid section choice:',
2178: plst => 'Please try again',
2179: );
2180: my $js;
2181: if (ref($courseroles) eq 'HASH') {
2182: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
2183: ' var numsec = new Array();'."\n".
2184: ' var rolesections = new Array();'."\n".
2185: ' var rolenames = new Array();'."\n".
2186: ' var roleseclist = new Array();'."\n";
2187: my @items = keys(%{$courseroles});
2188: for (my $i=0; $i<@items; $i++) {
2189: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
2190: my ($secs,$secstr);
2191: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
2192: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
2193: $secs = join('","',@sections);
2194: $secstr = join(', ',@sections);
2195: }
2196: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
2197: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
2198: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
2199: }
2200: }
1.273 droeschl 2201: return <<"END";
1.235 raeburn 2202: <script type="text/javascript">
1.273 droeschl 2203: //<![CDATA[
1.235 raeburn 2204: function adhocRole(roleitem) {
1.239 raeburn 2205: $js
1.235 raeburn 2206: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
2207: if (newrole == '') {
2208: return;
2209: }
1.239 raeburn 2210: var fullrole = newrole+'./$cdom/$cnum';
2211: var selidx = '';
2212: for (var i=0; i<rolenames.length; i++) {
2213: if (rolenames[i] == newrole) {
2214: selidx = i;
2215: }
2216: }
2217: var secok = 1;
2218: var secchoice = '';
2219: if (selidx >= 0) {
2220: if (numsec[selidx] > 1) {
2221: secok = 0;
2222: var numrolesec = rolesections[selidx].length;
2223: var msgidx = numsec[selidx] - numrolesec;
2224: secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
2225: if (secchoice == '') {
2226: if (msgidx > 0) {
2227: secok = 1;
2228: }
2229: } else {
2230: for (var j=0; j<rolesections[selidx].length; j++) {
2231: if (rolesections[selidx][j] == secchoice) {
2232: secok = 1;
2233: }
2234: }
2235: }
2236: } else {
2237: if (rolesections[selidx].length == 1) {
2238: secchoice = rolesections[selidx][0];
2239: }
2240: }
2241: }
2242: if (secok == 1) {
2243: if (secchoice != '') {
2244: fullrole += '/'+secchoice;
2245: }
2246: } else {
2247: document.rolechooser.elements[roleitem].selectedIndex = 0;
2248: if (secchoice != null) {
2249: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
2250: }
2251: return;
2252: }
2253: if (fullrole == "$env{'request.role'}") {
1.235 raeburn 2254: return;
2255: }
2256: itemid = retrieveIndex('gotorole');
2257: if (itemid != -1) {
1.239 raeburn 2258: document.rolechooser.elements[itemid].name = fullrole;
1.235 raeburn 2259: }
1.239 raeburn 2260: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1.235 raeburn 2261: document.rolechooser.selectrole.value = '1';
2262: document.rolechooser.submit();
2263: return;
2264: }
2265:
2266: function retrieveIndex(item) {
2267: for (var i=0;i<document.rolechooser.elements.length;i++) {
2268: if (document.rolechooser.elements[i].name == item) {
2269: return i;
2270: }
2271: }
2272: return -1;
2273: }
1.273 droeschl 2274: // ]]>
1.235 raeburn 2275: </script>
2276: END
2277: }
2278:
2279:
1.2 www 2280: # ================================================================ Main Program
2281:
1.16 harris41 2282: BEGIN {
1.166 albertel 2283: if (! defined($readdesk)) {
1.283 droeschl 2284: {
2285: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
2286: if ( CORE::open( my $config,"<$tabfile") ) {
2287: while (my $configline=<$config>) {
2288: $configline=(split(/\#/,$configline))[0];
2289: $configline=~s/^\s+//;
2290: chomp($configline);
1.209 www 2291: if ($configline=~/^cat\:/) {
1.283 droeschl 2292: my @entries=split(/\:/,$configline);
2293: $category_positions{$entries[2]}=$entries[1];
2294: $category_names{$entries[2]}=$entries[3];
2295: } elsif ($configline=~/^prim\:/) {
2296: my @entries = (split(/\:/, $configline))[1..5];
2297: push @primary_menu, \@entries;
2298: } elsif ($configline=~/^scnd\:/) {
2299: my @entries = (split(/\:/, $configline))[1..5];
2300: push @secondary_menu, \@entries;
2301: } elsif ($configline) {
2302: push(@desklines,$configline);
2303: }
2304: }
2305: CORE::close($config);
2306: }
2307: }
2308: $readdesk='done';
1.2 www 2309: }
2310: }
1.30 www 2311:
1.1 www 2312: 1;
2313: __END__
2314:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>