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