--- loncom/interface/lonmenu.pm 2006/08/14 09:28:56 1.204 +++ loncom/interface/lonmenu.pm 2007/04/28 23:13:56 1.218 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.204 2006/08/14 09:28:56 foxr Exp $ +# $Id: lonmenu.pm,v 1.218 2007/04/28 23:13:56 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,10 +44,9 @@ use Apache::lonhtmlcommon(); use Apache::loncommon(); use Apache::lonenc(); use Apache::lonlocal; -use lib '/home/httpd/lib/perl/'; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); -use vars qw(@desklines $readdesk); +use vars qw(@desklines %category_names %category_members %category_positions $readdesk); my @inlineremote; @@ -408,7 +407,7 @@ sub innerregister { my $desc = "Enter my resource construction space"; # Set defaults for co-authors if ($env{'request.role'} =~ /^ca/) { - ($cadom,$caname)=($env{'request.role'}=~/(\w+)\/(\w+)$/); + ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/); ($top,$bottom) = ('co con-','struct'); $action = "go('/priv/".$caname."');"; $desc = "Enter construction space as co-author"; @@ -430,7 +429,7 @@ sub innerregister { my $cfudom=''; if ($env{'request.filename'}) { my $file=&Apache::lonnet::declutter($env{'request.filename'}); - $file=~s/^(\w+)\/(\w+)/\/priv\/$2/; + $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/; # Check that the user has permission to edit this resource ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1); if (defined($cfudom)) { @@ -446,7 +445,7 @@ sub innerregister { # Finally, turn the button on or off if ($cfile && !$const_space) { $editbutton=&switch - ('','',6,1,'cstr.gif','edit[_1]','resource[_2]', + ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]', "go('".$cfile."');","Edit this resource"); } elsif ($editbutton eq '') { $editbutton=&clear(6,1); @@ -465,8 +464,9 @@ sub innerregister { } else { $currdir =~ s#[^/]+$##; my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn); + my $esc_currdir = &Apache::loncommon::escape_single($currdir); $menuitems=(<<ENDMENUITEMS); -s&6&1&list.gif&list[_1]&dir[_1]&golist('$currdir')&List current directory +s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version s&6&3&pub.gif&publish[_1]&resource[_1]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource @@ -477,18 +477,23 @@ ENDMENUITEMS $env{'request.symb'} ne '' ) { $menuitems=(<<ENDMENUITEMS); c&3&1 -s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1 -s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&3 +s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1 +s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3 c&6&3 c&8&1 c&8&2 s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document -s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&1 -s&9&3&anot.gif&anno-[_1]&tations[_1]&annotate()&Make notes and annotations about this resource&1 +s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1 +s&9&3&anot.gif&anno-[_1]&tations[_1]&annotate()&Make notes and annotations about this resource&&1 ENDMENUITEMS + unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) { - $menuitems.=(<<ENDREALRES); + if (!$env{'request.enc'}) { + $menuitems.=(<<ENDREALRES); s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information +ENDREALRES + } + $menuitems.=(<<ENDREALRES); s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource s&8&2&fdbk.gif&feedback[_1]&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource ENDREALRES @@ -520,13 +525,24 @@ ENDMENUITEMS $inlinebuttons= join('',map { (defined($_)?$_:'') } @inlineremote); } else { - $inlinebuttons=(<<ENDINLINE); + if ($env{'environment.icons'} eq 'iconsonly') { + $inlinebuttons=(<<ENDINLINEICONS); +<tr><td> +$inlineremote[21] $inlineremote[23] +$inlineremote[61] $inlineremote[63] +$inlineremote[71] $inlineremote[72] $inlineremote[73] +$inlineremote[81] $inlineremote[82] $inlineremote[83] +$inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr> +ENDINLINEICONS + } else { + $inlinebuttons=(<<ENDINLINE); <tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr> <tr><td>$inlineremote[61]</td><td>$inlineremote[62]</td><td>$inlineremote[63]</td></tr> <tr><td>$inlineremote[71]</td><td>$inlineremote[72]</td><td>$inlineremote[73]</td></tr> <tr><td>$inlineremote[81]</td><td>$inlineremote[82]</td><td>$inlineremote[83]</td></tr> <tr><td>$inlineremote[91]</td><td>$inlineremote[92]</td><td>$inlineremote[93]</td></tr> ENDINLINE + } } } $result =(<<ENDREGTEXT); @@ -812,7 +828,7 @@ sub clear { # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)". sub switch { - my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_; + my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_; $act=~s/\$uname/$uname/g; $act=~s/\$udom/$udom/g; $top=&mt($top); @@ -820,6 +836,9 @@ sub switch { $desc=&mt($desc); $img=&mt($img); + my $idx=10*$row+$col; + $category_members{$cat}.=':'.$idx; + unless (($env{'browser.interface'} eq 'textual') || ($env{'environment.remote'} eq 'off')) { # Remote @@ -831,14 +850,17 @@ sub switch { my $text=$top.' '.$bot; $text=~s/\s*\-\s*//gs; if ($nobreak) { - $inlineremote[10*$row+$col]= + $inlineremote[$idx]= '<a href="javascript:'.$act.';">'.$text.'</a>'; } else { - $inlineremote[10*$row+$col]="\n<br />". + $inlineremote[$idx]="\n<br />". $desc.' <a href="javascript:'.$act.';">'.$text.'</a>'; } } else { # Inline Remote + if ($env{'environment.icons'} ne 'classic') { + $img=~s/\.gif$/\.png/; + } if ($nobreak==2) { return ''; } my $text=$top.' '.$bot; $text=~s/\s*\-\s*//gs; @@ -852,27 +874,31 @@ sub switch { if ($env{'browser.interface'} eq 'faketextual') { # Accessibility if ($nobreak==3) { - $inlineremote[10*$row+$col]="\n". + $inlineremote[$idx]="\n". '<td class="LC_menubuttons_text" align="right">'.$text. '</td><td class="LC_menubuttons_img" align="left">'. '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>'; } elsif ($nobreak) { - $inlineremote[10*$row+$col]="\n<tr>". + $inlineremote[$idx]="\n<tr>". '<td class="LC_menubuttons_img" align="left">'. '<a href="javascript:'.$act.';">'.$pic.'</a></td> - <td class="LC_menubuttons_text" align="left">'.$text.'</td>'; + <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>'; } else { - $inlineremote[10*$row+$col]="\n<tr>". + $inlineremote[$idx]="\n<tr>". '<td class="LC_menubuttons_img" align="left">'. '<a href="javascript:'.$act.';">'.$pic. '</a></td><td class="LC_menubuttons_text" colspan="3">'. - $desc.'</td></tr>'; + '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>'; } } else { # Inline Menu - $inlineremote[10*$row+$col]= - '<a href="javascript:'.$act.';">'.$pic. - '</a><span class="LC_menubuttons_inline_text">'.$desc.'</span>'; + if ($env{'environment.icons'} eq 'iconsonly') { + $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>'; + } else { + $inlineremote[$idx]= + '<a class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic. + '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>'; + } } } return ''; @@ -881,12 +907,12 @@ sub switch { sub secondlevel { my $output=''; my - ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_; + ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_; if ($prt eq 'any') { - $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); + $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); } elsif ($prt=~/^r(\w+)/) { if ($rol eq $1) { - $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); + $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); } } return $output; @@ -901,10 +927,32 @@ sub openmenu { } sub inlinemenu { - @inlineremote=(); - undef @inlineremote; + undef(@inlineremote); + undef(%category_members); &rawconfig(1); - return join('',map { (defined($_)?$_:'') } @inlineremote); + my $output='<table id="LC_mainmenu"><tr>'; + for (my $col=1; $col<=2; $col++) { + $output.='<td class="LC_mainmenu_column">'; + for (my $row=1; $row<=8; $row++) { + foreach my $cat (keys(%category_members)) { + if ($category_positions{$cat} ne "$col,$row") { next; } + $output.='<table id="LC_menubuttons_mainmenu"><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>'; + my %active=(); + foreach my $menu_item (split(/\:/,$category_members{$cat})) { + if ($inlineremote[$menu_item]) { + $active{$menu_item}=1; + } + } + foreach my $item (sort(keys(%active))) { + $output.=$inlineremote[$item]; + } + $output.='</table>'; + } + } + $output.="</td>"; + } + $output.="</tr></table>"; + return $output; } sub rawconfig { @@ -935,11 +983,12 @@ sub rawconfig { my $rol=$env{'request.role'}; my $requested_domain = $env{'request.role.domain'}; foreach my $line (@desklines) { - my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$line); + my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line); $prt=~s/\$uname/$uname/g; $prt=~s/\$udom/$udom/g; $prt=~s/\$crs/$crs/g; $prt=~s/\$requested_domain/$requested_domain/g; + if ($category_names{$cat}!~/\w/) { $cat='oth'; } my $type = &Apache::loncommon::course_type(); if ($type eq 'Group') { $desc = &convert_menu_function($desc,$type); @@ -948,29 +997,29 @@ sub rawconfig { $output.=&clear($row,$col); } elsif ($pro eq 'any') { $output.=&secondlevel( - $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc); + $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); } elsif ($pro eq 'smp') { unless ($adv) { $output.=&secondlevel( - $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc); + $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); } } elsif ($pro eq 'adv') { if ($adv) { $output.=&secondlevel( - $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc); + $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); } } elsif (($pro=~/^p(\w+)/) && ($prt)) { if (&Apache::lonnet::allowed($1,$prt)) { - $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); + $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); } } elsif ($pro eq 'course') { if ($env{'request.course.fn'}) { - $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); + $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); } } elsif ($pro =~ /^courseenv_(.*)$/) { my $key = $1; if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) { - $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); + $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); } } elsif ($pro =~ /^course_(.*)$/) { # Check for permissions inside of a course @@ -978,7 +1027,7 @@ sub rawconfig { (&Apache::lonnet::allowed($1,$env{'request.course.id'}. ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) )) { - $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); + $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); } } elsif ($pro eq 'author') { if ($author) { @@ -989,7 +1038,7 @@ sub rawconfig { my $caname=$env{'user.name'}; if ($prt eq 'rca') { ($cadom,$caname)= - ($env{'request.role'}=~/(\w+)\/(\w+)$/); + ($env{'request.role'}=~/($match_domain)\/($match_username)$/); } $act =~ s/\$caname/$caname/g; my $home = &Apache::lonnet::homeserver($caname,$cadom); @@ -997,8 +1046,8 @@ sub rawconfig { my @ids=&Apache::lonnet::current_machine_ids(); foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } if ($allowed) { - $output.=switch($caname,$cadom, - $row,$col,$img,$top,$bot,$act,$desc); + $output.=&switch($caname,$cadom, + $row,$col,$img,$top,$bot,$act,$desc,$cat); } } } @@ -1077,13 +1126,16 @@ sub utilityfunctions { 'add_entries' => { 'onload' => 'javascript:document.goannotate.submit();'}}); + my $end_page_annotate = + &Apache::loncommon::end_page({'js_ready' => 1}); + my $start_page_bookmark = &Apache::loncommon::start_page('Bookmarks',undef, {'only_body' => 1, 'js_ready' => 1, 'bgcolor' => '#BBBBBB',}); - my $end_page = + my $end_page_bookmark = &Apache::loncommon::end_page({'js_ready' => 1}); return (<<ENDUTILITY) @@ -1201,9 +1253,9 @@ function annotate() { '$start_page_annotate' +"<form name='goannotate' target='Annotator' method='post' " +"action='/adm/annotations'>" - +"<input type='hidden' name='urlnew' value='"+currentURL+"' />" + +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />" +"<\\/form>" - +'$end_page'); + +'$end_page_annotate'); annotator.document.close(); } @@ -1225,7 +1277,7 @@ function set_bookmark() { +"value='Save' /> <input type='button' value='Close (no save)' " +"onclick='javascript:window.close();' /><\\/center><\\/td>" +"<\\/tr><\\/table><\\/form><\\/center>" - +'$end_page' ); + +'$end_page_bookmark' ); bmquery.document.close(); } @@ -1297,7 +1349,11 @@ BEGIN { $configline=(split(/\#/,$configline))[0]; $configline=~s/^\s+//; chomp($configline); - if ($configline) { + if ($configline=~/^cat\:/) { + my @entries=split(/\:/,$configline); + $category_positions{$entries[2]}=$entries[1]; + $category_names{$entries[2]}=$entries[3]; + } elsif ($configline) { push(@desklines,$configline); } }