1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.326 2010/04/19 09:22:14 bisitz Exp $
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: #
28: #
29: # There is one parameter controlling the action of this module:
30: #
31:
32: =head1 NAME
33:
34: Apache::lonmenu
35:
36: =head1 SYNOPSIS
37:
38: Coordinates the response to clicking an image.
39:
40: This is part of the LearningOnline Network with CAPA project
41: described at http://www.lon-capa.org.
42:
43: =head1 GLOBAL VARIABLES
44:
45: =over
46:
47: =item @desklines
48:
49: Each element of this array contains a line of mydesk.tab that doesn't start with
50: cat, prim or scnd.
51: It gets filled in the BEGIN block of this module.
52:
53: =item %category_names
54:
55: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
56: start with cat, the values are strings representing titles.
57: It gets filled in the BEGIN block of this module.
58:
59: =item %category_members
60:
61: TODO
62:
63: =item %category_positions
64:
65: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
66: start with cat, its values are position vectors (column, row).
67: It gets filled in the BEGIN block of this module.
68:
69: =item $readdesk
70:
71: Indicates that mydesk.tab has been read.
72: It is set to 'done' in the BEGIN block of this module.
73:
74: =item @primary_menu
75:
76: The elements of this array reference arrays that are made up of the components
77: of those lines of mydesk.tab that start with prim.
78: It is used by primary_menu() to generate the corresponding menu.
79: It gets filled in the BEGIN block of this module.
80:
81: =item @secondary_menu
82:
83: The elements of this array reference arrays that are made up of the components
84: of those lines of mydesk.tab that start with scnd.
85: It is used by secondary_menu() to generate the corresponding menu.
86: It gets filled in the BEGIN block of this module.
87:
88: =back
89:
90: =head1 SUBROUTINES
91:
92: =over
93:
94: =item prep_menuitems(\@menuitem)
95:
96: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
97: secondary_menu().
98:
99: =item primary_menu()
100:
101: This routine evaluates @primary_menu and returns XHTML for the menu
102: that contains following links: About, Message, Roles, Help, Logout
103: @primary_menu is filled within the BEGIN block of this module with
104: entries from mydesk.tab
105:
106: =item secondary_menu()
107:
108: Same as primary_menu() but operates on @secondary_menu.
109:
110: =item show_return_link()
111:
112: =item innerregister()
113:
114: This gets called in order to register a URL in the body of the document
115:
116: =item clear()
117:
118: =item switch()
119:
120: Switch a button or create a link
121: Switch acts on the javascript that is executed when a button is clicked.
122: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
123:
124: =item secondlevel()
125:
126: =item openmenu()
127:
128: =item inlinemenu()
129:
130: =item rawconfig()
131:
132: =item utilityfunctions()
133:
134: =item serverform()
135:
136: =item constspaceform()
137:
138: =item get_nav_status()
139:
140: =item hidden_button_check()
141:
142: =item roles_selector()
143:
144: =item jump_to_role()
145:
146: =back
147:
148: =cut
149:
150: package Apache::lonmenu;
151:
152: use strict;
153: use Apache::lonnet;
154: use Apache::lonhtmlcommon();
155: use Apache::loncommon();
156: use Apache::lonenc();
157: use Apache::lonlocal;
158: use LONCAPA qw(:DEFAULT :match);
159: use HTML::Entities();
160:
161: use vars qw(@desklines %category_names %category_members %category_positions
162: $readdesk @primary_menu @secondary_menu);
163:
164: my @inlineremote;
165:
166: sub prep_menuitem {
167: my ($menuitem) = @_;
168: return '' unless(ref($menuitem) eq 'ARRAY');
169: my $link;
170: if ($$menuitem[1]) { # graphical Link
171: $link = "<img class=\"LC_noBorder\""
172: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
173: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
174: } else { # textual Link
175: $link = &mt($$menuitem[3]);
176: }
177: return '<li><a'
178: # highlighting for new messages
179: . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
180: . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
181: }
182:
183: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
184: # that contains following links:
185: # About, Message, Roles, Help, Logout
186: # @primary_menu is filled within the BEGIN block of this module with
187: # entries from mydesk.tab
188: sub primary_menu {
189: my $menu;
190: # each element of @primary contains following array:
191: # (link url, icon path, alt text, link text, condition)
192: my $public;
193: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
194: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
195: $public = 1;
196: }
197: foreach my $menuitem (@primary_menu) {
198: # evaluate conditions
199: next if ref($menuitem) ne 'ARRAY'; #
200: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
201: && &Apache::lonmsg::mynewmail(); # whether a new msg
202: next if $$menuitem[4] eq 'newmsg' # arrived or not
203: && !&Apache::lonmsg::mynewmail(); #
204: next if $$menuitem[4] !~ /public/ ##we've a public user,
205: && $public; ##who should not see all
206: ##links
207: next if $$menuitem[4] eq 'onlypublic'# hide links which are
208: && !$public; # only visible to public
209: # users
210: next if $$menuitem[4] eq 'roles' ##show links depending on
211: && &Apache::loncommon::show_course(); ##term 'Courses' or
212: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
213: && !&Apache::loncommon::show_course(); ##
214:
215:
216: if ($$menuitem[3] eq 'Help') { # special treatment for helplink
217: $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
218: } else {
219: $menu .= prep_menuitem($menuitem);
220: }
221: }
222: $menu =~ s/\[domain\]/$env{'user.domain'}/g;
223: $menu =~ s/\[user\]/$env{'user.name'}/g;
224:
225: return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
226: }
227:
228:
229: sub secondary_menu {
230: my $menu;
231:
232: my $crstype = &Apache::loncommon::course_type();
233: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
234: my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'}
235: . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
236: : ''));
237: my $showlink = &show_return_link();
238: my %groups = &Apache::lonnet::get_active_groups(
239: $env{'user.domain'}, $env{'user.name'},
240: $env{'course.' . $env{'request.course.id'} . '.domain'},
241: $env{'course.' . $env{'request.course.id'} . '.num'});
242: foreach my $menuitem (@secondary_menu) {
243: # evaluate conditions
244: next if ref($menuitem) ne 'ARRAY';
245: next if $$menuitem[4] ne 'always'
246: && !$env{'request.course.id'};
247: next if $$menuitem[4] eq 'showreturn'
248: && !$showlink
249: && !($env{'request.state'} eq 'construct');
250: next if $$menuitem[4] =~ /^mdc/
251: && !$canedit;
252: next if $$menuitem[4] eq 'mdcCourse'
253: && $crstype eq 'Community';
254: next if $$menuitem[4] eq 'mdcCommunity'
255: && $crstype ne 'Community';
256: next if $$menuitem[4] =~ /^Course$/
257: && $crstype eq 'Community';
258: next if $$menuitem[4] =~ /^Community$/
259: && $crstype ne 'Community';
260: next if $$menuitem[4] =~ /showgroups$/
261: && !$canviewgrps
262: && !%groups;
263:
264: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
265: # special treatment for role selector
266: my $roles_selector = &roles_selector(
267: $env{'course.' . $env{'request.course.id'} . '.domain'},
268: $env{'course.' . $env{'request.course.id'} . '.num'} );
269:
270: $menu .= $roles_selector ? "<li>$roles_selector</li>"
271: : '';
272: } else {
273: $menu .= &prep_menuitem(\@$menuitem);
274: }
275: }
276: if ($menu =~ /\[url\].*\[symb\]/) {
277: my $escurl = &escape( &Apache::lonenc::check_encrypt(
278: $env{'request.noversionuri'}));
279:
280: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
281: $env{'request.symb'}));
282:
283: if ( $env{'request.state'} eq 'construct'
284: and ( $env{'request.noversionuri'} eq ''
285: || !defined($env{'request.noversionuri'})))
286: {
287: ($escurl = $env{'request.filename'}) =~
288: s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
289:
290: $escurl = &escape($escurl);
291: }
292: $menu =~ s/\[url\]/$escurl/g;
293: $menu =~ s/\[symb\]/$escsymb/g;
294: }
295:
296: return "<ul id=\"LC_secondary_menu\">$menu</ul>";
297: }
298:
299: sub show_return_link {
300: if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)})
301: || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) {
302:
303: return if ($env{'form.register'});
304: }
305: return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
306: $env{'request.symb'} eq '')
307: ||
308: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
309: ||
310: (($env{'request.noversionuri'}=~/^\/adm\//) &&
311: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
312: ($env{'request.noversionuri'}!~
313: m{^/adm/.*/(smppg|bulletinboard)($|\?)})
314: ));
315: }
316:
317: sub innerregister {
318: my ($forcereg,$bread_crumbs) = @_;
319: my $const_space = ($env{'request.state'} eq 'construct');
320: my $is_const_dir = 0;
321:
322: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
323:
324: $env{'request.registered'} = 1;
325:
326: undef(@inlineremote);
327:
328: if ( $env{'request.symb'} && $env{'request.course.id'} ) {
329:
330: my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
331: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
332:
333: my $maptitle = &Apache::lonnet::gettitle($mapurl);
334: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
335:
336: #SD
337: #course_type only Course and Community?
338: #
339: my @crumbs;
340: unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps')
341: && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
342: @crumbs = ({text => Apache::loncommon::course_type()
343: . ' Contents',
344: href => "Javascript:gopost('/adm/navmaps','')"});
345: }
346: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
347: push(@crumbs, {text => '...',
348: no_mt => 1});
349: }
350:
351: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
352: && $maptitle ne 'default.sequence'
353: && $maptitle ne $coursetitle);
354:
355: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
356:
357: &Apache::lonhtmlcommon::clear_breadcrumbs();
358: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
359: }
360: # =============================================================================
361: # ============================ This is for URLs that actually can be registered
362: return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
363: || $forcereg );
364:
365: # -- This applies to homework problems for users with grading privileges
366: my $crs='/'.$env{'request.course.id'};
367: if ($env{'request.course.sec'}) {
368: $crs.='_'.$env{'request.course.sec'};
369: }
370: $crs=~s/\_/\//g;
371:
372: my $hwkadd='';
373: if ($env{'request.symb'} ne '' &&
374: $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
375: if (&Apache::lonnet::allowed('mgr',$crs)) {
376: $hwkadd.=&switch('','',7,2,'pgrd.png','problem[_1]','grades[_4]',
377: "gocmd('/adm/grades','gradingmenu')",
378: 'Modify user grades for this assessment resource');
379: } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
380: $hwkadd.=&switch('','',7,2,'subm.png','view sub-[_1]','missions[_1]',
381: "gocmd('/adm/grades','submission')",
382: 'View user submissions for this assessment resource');
383: }
384: }
385: if ($env{'request.symb'} ne '' &&
386: &Apache::lonnet::allowed('opa',$crs)) {
387: $hwkadd.=&switch('','',7,3,'pparm.png','problem[_2]','parms[_2]',
388: "gocmd('/adm/parmset','set')",
389: 'Modify parameter settings for this resource');
390: }
391: # -- End Homework
392: ###
393: ### Determine whether or not to display the 'cstr' button for this
394: ### resource
395: ###
396: my $editbutton = '';
397: my $noeditbutton = 1;
398: my ($cnum,$cdom);
399: if ($env{'request.course.id'}) {
400: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
401: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
402: }
403: if ($env{'user.author'}) {
404: if ($env{'request.role'}=~/^(aa|ca|au)/) {
405: #
406: # We have the role of an author
407: #
408: # Set defaults for authors
409: my ($top,$bottom) = ('con-','struct');
410: my $action = "go('/priv/".$env{'user.name'}."');";
411: my $cadom = $env{'request.role.domain'};
412: my $caname = $env{'user.name'};
413: my $desc = "Enter my construction space";
414: # Set defaults for co-authors
415: if ($env{'request.role'} =~ /^ca/) {
416: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
417: ($top,$bottom) = ('co con-','struct');
418: $action = "go('/priv/".$caname."');";
419: $desc = "Enter construction space as co-author";
420: } elsif ($env{'request.role'} =~ /^aa/) {
421: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
422: ($top,$bottom) = ('co con-','struct');
423: $action = "go('/priv/".$caname."');";
424: $desc = "Enter construction space as assistant co-author";
425: }
426: # Check that we are on the correct machine
427: my $home = &Apache::lonnet::homeserver($caname,$cadom);
428: my $allowed=0;
429: my @ids=&Apache::lonnet::current_machine_ids();
430: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
431: if (!$allowed) {
432: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
433: $noeditbutton = 0;
434: }
435: }
436: #
437: # We are an author for some stuff, but currently do not have the role of author.
438: # Figure out if we have authoring privileges for the resource we are looking at.
439: # This should maybe become a privilege check in lonnet
440: #
441: ##
442: ## Determine if user can edit url.
443: ##
444: my $cfile='';
445: my $cfuname='';
446: my $cfudom='';
447: my $uploaded;
448: if ($env{'request.filename'}) {
449: my $file=&Apache::lonnet::declutter($env{'request.filename'});
450: if (defined($cnum) && defined($cdom)) {
451: $uploaded = &is_course_upload($file,$cnum,$cdom);
452: }
453: if (!$uploaded) {
454: $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
455: # Check that the user has permission to edit this resource
456: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
457: if (defined($cfudom)) {
458: my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
459: my $allowed=0;
460: my @ids=&Apache::lonnet::current_machine_ids();
461: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
462: if ($allowed) {
463: $cfile=$file;
464: }
465: }
466: }
467: }
468: # Finally, turn the button on or off
469: if ($cfile && !$const_space) {
470: my $nocrsedit;
471: # Suppress display where CC has switched to student role.
472: if ($env{'request.course.id'}) {
473: unless(&Apache::lonnet::allowed('mdc',
474: $env{'request.course.id'})) {
475: $nocrsedit = 1;
476: }
477: }
478: if ($nocrsedit) {
479: $editbutton=&clear(6,1);
480: } else {
481: $editbutton=&switch
482: ('','',6,1,'pcstr.png','edit[_1]','resource[_2]',
483: "go('".$cfile."');","Edit this resource");
484: $noeditbutton = 0;
485: }
486: } elsif ($editbutton eq '') {
487: $editbutton=&clear(6,1);
488: }
489: }
490: if (($noeditbutton) && ($env{'request.filename'})) {
491: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
492: my $file=&Apache::lonnet::declutter($env{'request.filename'});
493: if (defined($cnum) && defined($cdom)) {
494: if (&is_course_upload($file,$cnum,$cdom)) {
495: my $cfile = &edit_course_upload($file,$cnum,$cdom);
496: if ($cfile) {
497: $editbutton=&switch
498: ('','',6,1,'pcstr.png','edit[_1]',
499: 'resource[_2]',"go('".$cfile."');",
500: 'Edit this resource');
501: }
502: }
503: }
504: }
505: }
506: ###
507: ###
508: # Prepare the rest of the buttons
509: my $menuitems;
510: if ($const_space) {
511: #
512: # We are in construction space
513: #
514: my ($uname,$thisdisfn) =
515: ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
516: my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
517: if ($currdir =~ m-/$-) {
518: $is_const_dir = 1;
519: } else {
520: $currdir =~ s|[^/]+$||;
521: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
522: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
523: #
524: # Probably should be in mydesk.tab
525: #
526: $menuitems=(<<ENDMENUITEMS);
527: s&6&1&list.png&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
528: s&6&2&rtrv.png&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
529: s&6&3&pub.png&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
530: s&7&1&del.png&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
531: s&7&2&prt.png&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
532: ENDMENUITEMS
533: }
534: if (ref($bread_crumbs) eq 'ARRAY') {
535: &Apache::lonhtmlcommon::clear_breadcrumbs();
536: foreach my $crumb (@{$bread_crumbs}){
537: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
538: }
539: }
540: } elsif ( defined($env{'request.course.id'}) &&
541: $env{'request.symb'} ne '' ) {
542: #
543: # We are in a course and looking at a registred URL
544: # Should probably be in mydesk.tab
545: #
546: $menuitems=(<<ENDMENUITEMS);
547: c&3&1
548: s&2&1&back.png&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
549: s&2&3&forw.png&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
550: c&6&3
551: c&8&1
552: c&8&2
553: s&8&3&prt.png&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
554: s&9&1&sbkm.png&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
555: ENDMENUITEMS
556:
557: my $currentURL = &Apache::loncommon::get_symb();
558: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
559: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
560: $menuitems.="s&9&3&";
561: if(length($annotation) > 0){
562: $menuitems.="anot2.png";
563: }else{
564: $menuitems.="anot.png";
565: }
566: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
567: $menuitems.="Make notes and annotations about this resource&&1\n";
568:
569: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
570: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
571: $menuitems.=(<<ENDREALRES);
572: s&6&3&catalog.png&catalog[_2]&info[_1]&catalog_info()&Show Metadata
573: ENDREALRES
574: }
575: $menuitems.=(<<ENDREALRES);
576: s&8&1&eval.png&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
577: s&8&2&fdbk.png&feedback[_1]&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
578: ENDREALRES
579: }
580: }
581: if ($env{'request.uri'} =~ /^\/res/) {
582: $menuitems .= (<<ENDMENUITEMS);
583: s&8&3&prt.png&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
584: ENDMENUITEMS
585: }
586: my $buttons='';
587: foreach (split(/\n/,$menuitems)) {
588: my ($command,@rest)=split(/\&/,$_);
589: my $idx=10*$rest[0]+$rest[1];
590: if (&hidden_button_check() eq 'yes') {
591: if ($idx == 21 ||$idx == 23) {
592: $buttons.=&switch('','',@rest);
593: } else {
594: $buttons.=&clear(@rest);
595: }
596: } else {
597: if ($command eq 's') {
598: $buttons.=&switch('','',@rest);
599: } else {
600: $buttons.=&clear(@rest);
601: }
602: }
603: }
604:
605: my $addremote=0;
606: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
607: if ($addremote) {
608:
609: Apache::lonhtmlcommon::clear_breadcrumb_tools();
610:
611: Apache::lonhtmlcommon::add_breadcrumb_tool(
612: 'navigation', @inlineremote[21,23]);
613:
614: if(hidden_button_check() ne 'yes') {
615: Apache::lonhtmlcommon::add_breadcrumb_tool(
616: 'tools', @inlineremote[93,91,81,82,83]);
617:
618: #publish button in construction space
619: if ($env{'request.state'} eq 'construct'){
620: Apache::lonhtmlcommon::add_breadcrumb_tool(
621: 'advtools', @inlineremote[63]);
622: }else{
623: Apache::lonhtmlcommon::add_breadcrumb_tool(
624: 'tools', @inlineremote[63]);
625: }
626:
627: unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
628: Apache::lonhtmlcommon::add_breadcrumb_tool(
629: 'advtools', @inlineremote[61,71,72,73,92]);
630: }
631: }
632: }
633:
634: return Apache::lonhtmlcommon::scripttag('', 'start')
635: . Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
636: . Apache::lonhtmlcommon::scripttag('', 'end');
637: }
638:
639: sub is_course_upload {
640: my ($file,$cnum,$cdom) = @_;
641: my $uploadpath = &LONCAPA::propath($cdom,$cnum);
642: $uploadpath =~ s{^\/}{};
643: if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
644: ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
645: return 1;
646: }
647: return;
648: }
649:
650: sub edit_course_upload {
651: my ($file,$cnum,$cdom) = @_;
652: my $cfile;
653: if ($file =~/\.(htm|html|css|js|txt)$/) {
654: my $ext = $1;
655: my $url = &Apache::lonnet::hreflocation('',$file);
656: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
657: my @ids=&Apache::lonnet::current_machine_ids();
658: my $dest;
659: if ($home && grep(/^\Q$home\E$/,@ids)) {
660: $dest = $url.'?forceedit=1';
661: } else {
662: unless (&Apache::lonnet::get_locks()) {
663: $dest = '/adm/switchserver?otherserver='.
664: $home.'&role='.$env{'request.role'}.
665: '&url='.$url.'&forceedit=1';
666: }
667: }
668: if ($dest) {
669: $cfile = &HTML::Entities::encode($dest,'"<>&');
670: }
671: }
672: return $cfile;
673: }
674:
675: # ================================================================== Raw Config
676:
677: sub clear {
678: my ($row,$col)=@_;
679: $inlineremote[10*$row+$col]='';
680: return '';
681: }
682:
683: # ============================================ Switch a button or create a link
684: # Switch acts on the javascript that is executed when a button is clicked.
685: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
686:
687: sub switch {
688: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
689: $act=~s/\$uname/$uname/g;
690: $act=~s/\$udom/$udom/g;
691: $top=&mt($top);
692: $bot=&mt($bot);
693: $desc=&mt($desc);
694: my $idx=10*$row+$col;
695: $category_members{$cat}.=':'.$idx;
696:
697: # Inline Menu
698: if ($nobreak==2) { return ''; }
699: my $text=$top.' '.$bot;
700: $text=~s/\s*\-\s*//gs;
701:
702: my $pic=
703: '<img alt="'.$text.'" src="'.
704: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
705: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
706: if ($env{'browser.interface'} eq 'faketextual') {
707: # Main Menu
708: if ($nobreak==3) {
709: $inlineremote[$idx]="\n".
710: '<td class="LC_menubuttons_text" align="right">'.$text.
711: '</td><td align="left">'.
712: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
713: } elsif ($nobreak) {
714: $inlineremote[$idx]="\n<tr>".
715: '<td align="left">'.
716: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
717: <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>';
718: } else {
719: $inlineremote[$idx]="\n<tr>".
720: '<td align="left">'.
721: '<a href="javascript:'.$act.';">'.$pic.
722: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
723: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
724: }
725: } else {
726: # Inline Menu
727: $inlineremote[$idx]=
728: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
729: '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
730: }
731: return '';
732: }
733:
734: sub secondlevel {
735: my $output='';
736: my
737: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
738: if ($prt eq 'any') {
739: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
740: } elsif ($prt=~/^r(\w+)/) {
741: if ($rol eq $1) {
742: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
743: }
744: }
745: return $output;
746: }
747:
748: sub inlinemenu {
749: undef(@inlineremote);
750: undef(%category_members);
751: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
752: &rawconfig(1);
753: my $output='<table><tr>';
754: for (my $col=1; $col<=2; $col++) {
755: $output.='<td class="LC_mainmenu_col_fieldset">';
756: for (my $row=1; $row<=8; $row++) {
757: foreach my $cat (keys(%category_members)) {
758: if ($category_positions{$cat} ne "$col,$row") { next; }
759: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
760: $output.='<div class="LC_Box LC_400Box">';
761: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
762: $output.='<table>';
763: my %active=();
764: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
765: if ($inlineremote[$menu_item]) {
766: $active{$menu_item}=1;
767: }
768: }
769: foreach my $item (sort(keys(%active))) {
770: $output.=$inlineremote[$item];
771: }
772: $output.='</table>';
773: $output.='</div>';
774: }
775: }
776: $output.="</td>";
777: }
778: $output.="</tr></table>";
779: return $output;
780: }
781:
782: sub rawconfig {
783: #
784: # This evaluates mydesk.tab
785: # Need to add more positions and more privileges to deal with all
786: # menu items.
787: #
788: my $textualoverride=shift;
789: my $output='';
790: return '' unless $textualoverride;
791: my $uname=$env{'user.name'};
792: my $udom=$env{'user.domain'};
793: my $adv=$env{'user.adv'};
794: my $show_course=&Apache::loncommon::show_course();
795: my $author=$env{'user.author'};
796: my $crs='';
797: my $crstype='';
798: if ($env{'request.course.id'}) {
799: $crs='/'.$env{'request.course.id'};
800: if ($env{'request.course.sec'}) {
801: $crs.='_'.$env{'request.course.sec'};
802: }
803: $crs=~s/\_/\//g;
804: $crstype = &Apache::loncommon::course_type();
805: }
806: my $pub=($env{'request.state'} eq 'published');
807: my $con=($env{'request.state'} eq 'construct');
808: my $rol=$env{'request.role'};
809: my $requested_domain = $env{'request.role.domain'};
810: foreach my $line (@desklines) {
811: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
812: $prt=~s/\$uname/$uname/g;
813: $prt=~s/\$udom/$udom/g;
814: if ($prt =~ /\$crs/) {
815: next unless ($env{'request.course.id'});
816: next if ($crstype eq 'Community');
817: $prt=~s/\$crs/$crs/g;
818: } elsif ($prt =~ /\$cmty/) {
819: next unless ($env{'request.course.id'});
820: next if ($crstype ne 'Community');
821: $prt=~s/\$cmty/$crs/g;
822: }
823: $prt=~s/\$requested_domain/$requested_domain/g;
824: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
825: if ($pro eq 'clear') {
826: $output.=&clear($row,$col);
827: } elsif ($pro eq 'any') {
828: $output.=&secondlevel(
829: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
830: } elsif ($pro eq 'smp') {
831: unless ($adv) {
832: $output.=&secondlevel(
833: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
834: }
835: } elsif ($pro eq 'adv') {
836: if ($adv) {
837: $output.=&secondlevel(
838: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
839: }
840: } elsif ($pro eq 'shc') {
841: if ($show_course) {
842: $output.=&secondlevel(
843: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
844: }
845: } elsif ($pro eq 'nsc') {
846: if (!$show_course) {
847: $output.=&secondlevel(
848: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
849: }
850: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
851: my $priv = $1;
852: if ($priv =~ /^mdc(Course|Community)/) {
853: if ($crstype eq $1) {
854: $priv = 'mdc';
855: } else {
856: next;
857: }
858: }
859: if (&Apache::lonnet::allowed($priv,$prt)) {
860: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
861: }
862: } elsif ($pro eq 'course') {
863: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
864: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
865: }
866: } elsif ($pro eq 'community') {
867: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
868: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
869: }
870: } elsif ($pro =~ /^courseenv_(.*)$/) {
871: my $key = $1;
872: if ($crstype ne 'Community') {
873: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
874: if ($key eq 'canuse_pdfforms') {
875: if ($env{'request.course.id'} && $coursepref eq '') {
876: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
877: $coursepref = $domdefs{'canuse_pdfforms'};
878: }
879: }
880: if ($coursepref) {
881: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
882: }
883: }
884: } elsif ($pro =~ /^communityenv_(.*)$/) {
885: my $key = $1;
886: if ($crstype eq 'Community') {
887: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
888: if ($key eq 'canuse_pdfforms') {
889: if ($env{'request.course.id'} && $coursepref eq '') {
890: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
891: $coursepref = $domdefs{'canuse_pdfforms'};
892: }
893: }
894: if ($coursepref) {
895: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
896: }
897: }
898: } elsif ($pro =~ /^course_(.*)$/) {
899: # Check for permissions inside of a course
900: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
901: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
902: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
903: )) {
904: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
905: }
906: } elsif ($pro =~ /^community_(.*)$/) {
907: # Check for permissions inside of a community
908: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
909: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
910: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
911: )) {
912: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
913: }
914: } elsif ($pro eq 'author') {
915: if ($author) {
916: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
917: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
918: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
919: # Check that we are on the correct machine
920: my $cadom=$requested_domain;
921: my $caname=$env{'user.name'};
922: if (($prt eq 'rca') || ($prt eq 'raa')) {
923: ($cadom,$caname)=
924: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
925: }
926: $act =~ s/\$caname/$caname/g;
927: my $home = &Apache::lonnet::homeserver($caname,$cadom);
928: my $allowed=0;
929: my @ids=&Apache::lonnet::current_machine_ids();
930: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
931: if ($allowed) {
932: $output.=&switch($caname,$cadom,
933: $row,$col,$img,$top,$bot,$act,$desc,$cat);
934: }
935: }
936: }
937: } elsif ($pro eq 'tools') {
938: my @tools = ('aboutme','blog','portfolio');
939: if (grep(/^\Q$prt\E$/,@tools)) {
940: if (!&Apache::lonnet::usertools_access($env{'user.name'},
941: $env{'user.domain'},
942: $prt,undef,'tools')) {
943: $output.=&clear($row,$col);
944: next;
945: }
946: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
947: if (($prt eq 'reqcrsnsc') && ($show_course)) {
948: next;
949: }
950: if (($prt eq 'reqcrsshc') && (!$show_course)) {
951: next;
952: }
953: my $showreqcrs = &check_for_rcrs();
954: if (!$showreqcrs) {
955: $output.=&clear($row,$col);
956: next;
957: }
958: }
959: $prt='any';
960: $output.=&secondlevel(
961: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
962: }
963: }
964: return $output;
965: }
966:
967: sub check_for_rcrs {
968: my $showreqcrs = 0;
969: my @reqtypes = ('official','unofficial','community');
970: foreach my $type (@reqtypes) {
971: if (&Apache::lonnet::usertools_access($env{'user.name'},
972: $env{'user.domain'},
973: $type,undef,'requestcourses')) {
974: $showreqcrs = 1;
975: last;
976: }
977: }
978: if (!$showreqcrs) {
979: foreach my $type (@reqtypes) {
980: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
981: $showreqcrs = 1;
982: last;
983: }
984: }
985: }
986: return $showreqcrs;
987: }
988:
989: sub dc_popup_js {
990: my %lt = &Apache::lonlocal::texthash(
991: more => '(More ...)',
992: less => '(Less ...)',
993: );
994: return <<"END";
995:
996: function showCourseID() {
997: document.getElementById('dccid').style.display='block';
998: document.getElementById('dccid').style.textAlign='left';
999: document.getElementById('dccid').style.textFace='normal';
1000: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>';
1001: return;
1002: }
1003:
1004: function hideCourseID() {
1005: document.getElementById('dccid').style.display='none';
1006: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()">$lt{'more'}</a>';
1007: return;
1008: }
1009:
1010: END
1011:
1012: }
1013:
1014: sub utilityfunctions {
1015: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1016: if ($currenturl =~ m{^/adm/wrapper/ext/}
1017: && $env{'request.external.querystring'} ) {
1018: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1019: }
1020: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1021:
1022: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1023:
1024: my $dc_popup_cid;
1025: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1026: $env{'course.'.$env{'request.course.id'}.
1027: '.domain'}.'/'})) {
1028: $dc_popup_cid = &dc_popup_js();
1029: }
1030:
1031: my $start_page_annotate =
1032: &Apache::loncommon::start_page('Annotator',undef,
1033: {'only_body' => 1,
1034: 'js_ready' => 1,
1035: 'bgcolor' => '#BBBBBB',
1036: 'add_entries' => {
1037: 'onload' => 'javascript:document.goannotate.submit();'}});
1038:
1039: my $end_page_annotate =
1040: &Apache::loncommon::end_page({'js_ready' => 1});
1041:
1042: my $start_page_bookmark =
1043: &Apache::loncommon::start_page('Bookmarks',undef,
1044: {'only_body' => 1,
1045: 'js_ready' => 1,
1046: 'bgcolor' => '#BBBBBB',});
1047:
1048: my $end_page_bookmark =
1049: &Apache::loncommon::end_page({'js_ready' => 1});
1050:
1051: return (<<ENDUTILITY)
1052:
1053: var currentURL="$currenturl";
1054: var reloadURL="$currenturl";
1055: var currentSymb="$currentsymb";
1056:
1057: $dc_popup_cid
1058:
1059: function go(url) {
1060: if (url!='' && url!= null) {
1061: currentURL = null;
1062: currentSymb= null;
1063: window.location.href=url;
1064: }
1065: }
1066:
1067: function gopost(url,postdata) {
1068: if (url!='') {
1069: this.document.server.action=url;
1070: this.document.server.postdata.value=postdata;
1071: this.document.server.command.value='';
1072: this.document.server.url.value='';
1073: this.document.server.symb.value='';
1074: this.document.server.submit();
1075: }
1076: }
1077:
1078: function gocmd(url,cmd) {
1079: if (url!='') {
1080: this.document.server.action=url;
1081: this.document.server.postdata.value='';
1082: this.document.server.command.value=cmd;
1083: this.document.server.url.value=currentURL;
1084: this.document.server.symb.value=currentSymb;
1085: this.document.server.submit();
1086: }
1087: }
1088:
1089: function gocstr(url,filename) {
1090: if (url == '/adm/cfile?action=delete') {
1091: this.document.cstrdelete.filename.value = filename
1092: this.document.cstrdelete.submit();
1093: return;
1094: }
1095: if (url == '/adm/printout') {
1096: this.document.cstrprint.postdata.value = filename
1097: this.document.cstrprint.curseed.value = 0;
1098: this.document.cstrprint.problemtype.value = 0;
1099: if (this.document.lonhomework) {
1100: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1101: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1102: }
1103: if (this.document.lonhomework.problemtype) {
1104: if (this.document.lonhomework.problemtype.value) {
1105: this.document.cstrprint.problemtype.value =
1106: this.document.lonhomework.problemtype.value;
1107: } else if (this.document.lonhomework.problemtype.options) {
1108: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1109: if (this.document.lonhomework.problemtype.options[i].selected) {
1110: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1111: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1112: }
1113: }
1114: }
1115: }
1116: }
1117: }
1118: this.document.cstrprint.submit();
1119: return;
1120: }
1121: if (url !='') {
1122: this.document.constspace.filename.value = filename;
1123: this.document.constspace.action = url;
1124: this.document.constspace.submit();
1125: }
1126: }
1127:
1128: function golist(url) {
1129: if (url!='' && url!= null) {
1130: currentURL = null;
1131: currentSymb= null;
1132: top.location.href=url;
1133: }
1134: }
1135:
1136:
1137:
1138: function catalog_info() {
1139: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1140: }
1141:
1142: function chat_win() {
1143: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1144: }
1145:
1146: function group_chat(group) {
1147: var url = '/adm/groupchat?group='+group;
1148: var winName = 'LONchat_'+group;
1149: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1150: }
1151:
1152: function edit_bookmarks() {
1153: go('');
1154: w_BookmarkPal_flag=1;
1155: bookmarkpal=window.open("/adm/bookmarks",
1156: "BookmarkPal", "width=500,height=505,scrollbars=0");
1157: }
1158:
1159: function annotate() {
1160: w_Annotator_flag=1;
1161: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1162: annotator.document.write(
1163: '$start_page_annotate'
1164: +"<form name='goannotate' target='Annotator' method='post' "
1165: +"action='/adm/annotations'>"
1166: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1167: +"<\\/form>"
1168: +'$end_page_annotate');
1169: annotator.document.close();
1170: }
1171:
1172: function set_bookmark() {
1173: go('');
1174: clienttitle=document.title;
1175: clienthref=location.pathname;
1176: w_bmquery_flag=1;
1177: bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
1178: bmquery.document.write(
1179: '$start_page_bookmark'
1180: +'<center><form method="post"'
1181: +' name="newlink" action="/adm/bookmarks" target="bmquery" '
1182: +'> <table width="340" height="150" '
1183: +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
1184: +'type="text" name="title" size="45" value="'+clienttitle+'" />'
1185: +'<br />Address:<br /><input type="text" name="address" size="45" '
1186: +'value="'+clienthref+'" /><br /><center><input type="submit" '
1187: +'value="Save" /> <input type="button" value="Close" '
1188: +'onclick="javascript:window.close();" /></center></td>'
1189: +'</tr></table></form></center>'
1190: +'$end_page_bookmark' );
1191: bmquery.document.close();
1192: }
1193:
1194: ENDUTILITY
1195: }
1196:
1197: sub serverform {
1198: return(<<ENDSERVERFORM);
1199: <form name="server" action="/adm/logout" method="post" target="_top">
1200: <input type="hidden" name="postdata" value="none" />
1201: <input type="hidden" name="command" value="none" />
1202: <input type="hidden" name="url" value="none" />
1203: <input type="hidden" name="symb" value="none" />
1204: </form>
1205: ENDSERVERFORM
1206: }
1207:
1208: sub constspaceform {
1209: return(<<ENDCONSTSPACEFORM);
1210: <form name="constspace" action="/adm/logout" method="post" target="_top">
1211: <input type="hidden" name="filename" value="" />
1212: </form>
1213: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1214: <input type="hidden" name="action" value="delete" />
1215: <input type="hidden" name="filename" value="" />
1216: </form>
1217: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1218: <input type="hidden" name="postdata" value="" />
1219: <input type="hidden" name="curseed" value="" />
1220: <input type="hidden" name="problemtype" value="" />
1221: </form>
1222:
1223: ENDCONSTSPACEFORM
1224: }
1225:
1226: sub hidden_button_check {
1227: if ( $env{'request.course.id'} eq ''
1228: || $env{'request.role.adv'} ) {
1229:
1230: return;
1231: }
1232: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1233: return $buttonshide;
1234: }
1235:
1236: sub roles_selector {
1237: my ($cdom,$cnum) = @_;
1238: my $crstype = &Apache::loncommon::course_type();
1239: my $now = time;
1240: my (%courseroles,%seccount);
1241: my $is_cc;
1242: my $role_selector;
1243: my $ccrole;
1244: if ($crstype eq 'Community') {
1245: $ccrole = 'co';
1246: } else {
1247: $ccrole = 'cc';
1248: }
1249: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
1250: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1251:
1252: if ((($start) && ($start<0)) ||
1253: (($end) && ($end<$now)) ||
1254: (($start) && ($now<$start))) {
1255: $is_cc = 0;
1256: } else {
1257: $is_cc = 1;
1258: }
1259: }
1260: if ($is_cc) {
1261: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
1262: } else {
1263: my %gotnosection;
1264: foreach my $item (keys(%env)) {
1265: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1266: my $role = $1;
1267: my $sec = $2;
1268: next if ($role eq 'gr');
1269: my ($start,$end) = split(/\./,$env{$item});
1270: next if (($start && $start > $now) || ($end && $end < $now));
1271: if ($sec eq '') {
1272: if (!$gotnosection{$role}) {
1273: $seccount{$role} ++;
1274: $gotnosection{$role} = 1;
1275: }
1276: }
1277: if (ref($courseroles{$role}) eq 'ARRAY') {
1278: if ($sec ne '') {
1279: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1280: push(@{$courseroles{$role}},$sec);
1281: $seccount{$role} ++;
1282: }
1283: }
1284: } else {
1285: @{$courseroles{$role}} = ();
1286: if ($sec ne '') {
1287: $seccount{$role} ++;
1288: push(@{$courseroles{$role}},$sec);
1289: }
1290: }
1291: }
1292: }
1293: }
1294: my $switchtext;
1295: if ($crstype eq 'Community') {
1296: $switchtext = &mt('Switch community role to...')
1297: } else {
1298: $switchtext = &mt('Switch course role to...')
1299: }
1300: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1301: if (keys(%courseroles) > 1) {
1302: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
1303: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
1304: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1305: $role_selector .= '<option value="">'.$switchtext.'</option>';
1306: foreach my $role (@roles_order) {
1307: if (defined($courseroles{$role})) {
1308: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>';
1309: }
1310: }
1311: foreach my $role (sort(keys(%courseroles))) {
1312: if ($role =~ /^cr/) {
1313: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1314: }
1315: }
1316: $role_selector .= '</select>'."\n".
1317: '<input type="hidden" name="destinationurl" value="'.
1318: &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n".
1319: '<input type="hidden" name="gotorole" value="1" />'."\n".
1320: '<input type="hidden" name="selectrole" value="" />'."\n".
1321: '<input type="hidden" name="switch" value="1" />'."\n".
1322: '</form>';
1323: }
1324: return $role_selector;
1325: }
1326:
1327: sub get_all_courseroles {
1328: my ($cdom,$cnum,$courseroles,$seccount) = @_;
1329: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
1330: return;
1331: }
1332: my ($result,$cached) =
1333: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1334: if (defined($cached)) {
1335: if (ref($result) eq 'HASH') {
1336: if ((ref($result->{'roles'}) eq 'HASH') &&
1337: (ref($result->{'seccount'}) eq 'HASH')) {
1338: %{$courseroles} = %{$result->{'roles'}};
1339: %{$seccount} = %{$result->{'seccount'}};
1340: return;
1341: }
1342: }
1343: }
1344: my %gotnosection;
1345: my %adv_roles =
1346: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1347: foreach my $role (keys(%adv_roles)) {
1348: my ($urole,$usec) = split(/:/,$role);
1349: if (!$gotnosection{$urole}) {
1350: $seccount->{$urole} ++;
1351: $gotnosection{$urole} = 1;
1352: }
1353: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1354: if ($usec ne '') {
1355: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1356: push(@{$courseroles->{$urole}},$usec);
1357: $seccount->{$urole} ++;
1358: }
1359: }
1360: } else {
1361: @{$courseroles->{$urole}} = ();
1362: if ($usec ne '') {
1363: $seccount->{$urole} ++;
1364: push(@{$courseroles->{$urole}},$usec);
1365: }
1366: }
1367: }
1368: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1369: @{$courseroles->{'st'}} = ();
1370: if (keys(%sections_count) > 0) {
1371: push(@{$courseroles->{'st'}},keys(%sections_count));
1372: $seccount->{'st'} = scalar(keys(%sections_count));
1373: }
1374: my $rolehash = {
1375: 'roles' => $courseroles,
1376: 'seccount' => $seccount,
1377: };
1378: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1379: return;
1380: }
1381:
1382: sub jump_to_role {
1383: my ($cdom,$cnum,$seccount,$courseroles) = @_;
1384: my %lt = &Apache::lonlocal::texthash(
1385: this => 'This role has section(s) associated with it.',
1386: ente => 'Enter a specific section.',
1387: orlb => 'Enter a specific section, or leave blank for no section.',
1388: avai => 'Available sections are:',
1389: youe => 'You entered an invalid section choice:',
1390: plst => 'Please try again',
1391: );
1392: my $js;
1393: if (ref($courseroles) eq 'HASH') {
1394: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1395: ' var numsec = new Array();'."\n".
1396: ' var rolesections = new Array();'."\n".
1397: ' var rolenames = new Array();'."\n".
1398: ' var roleseclist = new Array();'."\n";
1399: my @items = keys(%{$courseroles});
1400: for (my $i=0; $i<@items; $i++) {
1401: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1402: my ($secs,$secstr);
1403: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1404: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1405: $secs = join('","',@sections);
1406: $secstr = join(', ',@sections);
1407: }
1408: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1409: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1410: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1411: }
1412: }
1413: return <<"END";
1414: <script type="text/javascript">
1415: //<![CDATA[
1416: function adhocRole(roleitem) {
1417: $js
1418: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
1419: if (newrole == '') {
1420: return;
1421: }
1422: var fullrole = newrole+'./$cdom/$cnum';
1423: var selidx = '';
1424: for (var i=0; i<rolenames.length; i++) {
1425: if (rolenames[i] == newrole) {
1426: selidx = i;
1427: }
1428: }
1429: var secok = 1;
1430: var secchoice = '';
1431: if (selidx >= 0) {
1432: if (numsec[selidx] > 1) {
1433: secok = 0;
1434: var numrolesec = rolesections[selidx].length;
1435: var msgidx = numsec[selidx] - numrolesec;
1436: secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1437: if (secchoice == '') {
1438: if (msgidx > 0) {
1439: secok = 1;
1440: }
1441: } else {
1442: for (var j=0; j<rolesections[selidx].length; j++) {
1443: if (rolesections[selidx][j] == secchoice) {
1444: secok = 1;
1445: }
1446: }
1447: }
1448: } else {
1449: if (rolesections[selidx].length == 1) {
1450: secchoice = rolesections[selidx][0];
1451: }
1452: }
1453: }
1454: if (secok == 1) {
1455: if (secchoice != '') {
1456: fullrole += '/'+secchoice;
1457: }
1458: } else {
1459: document.rolechooser.elements[roleitem].selectedIndex = 0;
1460: if (secchoice != null) {
1461: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
1462: }
1463: return;
1464: }
1465: if (fullrole == "$env{'request.role'}") {
1466: return;
1467: }
1468: itemid = retrieveIndex('gotorole');
1469: if (itemid != -1) {
1470: document.rolechooser.elements[itemid].name = fullrole;
1471: }
1472: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1473: document.rolechooser.selectrole.value = '1';
1474: document.rolechooser.submit();
1475: return;
1476: }
1477:
1478: function retrieveIndex(item) {
1479: for (var i=0;i<document.rolechooser.elements.length;i++) {
1480: if (document.rolechooser.elements[i].name == item) {
1481: return i;
1482: }
1483: }
1484: return -1;
1485: }
1486: // ]]>
1487: </script>
1488: END
1489: }
1490:
1491:
1492: # ================================================================ Main Program
1493:
1494: BEGIN {
1495: if (! defined($readdesk)) {
1496: {
1497: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
1498: if ( CORE::open( my $config,"<$tabfile") ) {
1499: while (my $configline=<$config>) {
1500: $configline=(split(/\#/,$configline))[0];
1501: $configline=~s/^\s+//;
1502: chomp($configline);
1503: if ($configline=~/^cat\:/) {
1504: my @entries=split(/\:/,$configline);
1505: $category_positions{$entries[2]}=$entries[1];
1506: $category_names{$entries[2]}=$entries[3];
1507: } elsif ($configline=~/^prim\:/) {
1508: my @entries = (split(/\:/, $configline))[1..5];
1509: push @primary_menu, \@entries;
1510: } elsif ($configline=~/^scnd\:/) {
1511: my @entries = (split(/\:/, $configline))[1..5];
1512: push @secondary_menu, \@entries;
1513: } elsif ($configline) {
1514: push(@desklines,$configline);
1515: }
1516: }
1517: CORE::close($config);
1518: }
1519: }
1520: $readdesk='done';
1521: }
1522: }
1523:
1524: 1;
1525: __END__
1526:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>