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