--- loncom/interface/lonmenu.pm 2011/01/18 19:52:46 1.344 +++ loncom/interface/lonmenu.pm 2012/09/25 23:01:00 1.369.2.23 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.344 2011/01/18 19:52:46 www Exp $ +# $Id: lonmenu.pm,v 1.369.2.23 2012/09/25 23:01:00 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -26,8 +26,6 @@ # http://www.lon-capa.org/ # # -# There is one parameter controlling the action of this module: -# =head1 NAME @@ -35,7 +33,8 @@ Apache::lonmenu =head1 SYNOPSIS -Coordinates the response to clicking an image. +Loads contents of /home/httpd/lonTabs/mydesk.tab, +used to generate inline menu, and Main Menu page. This is part of the LearningOnline Network with CAPA project described at http://www.lon-capa.org. @@ -74,10 +73,19 @@ It is set to 'done' in the BEGIN block o =item @primary_menu The elements of this array reference arrays that are made up of the components -of those lines of mydesk.tab that start with prim. +of those lines of mydesk.tab that start with prim:. It is used by primary_menu() to generate the corresponding menu. It gets filled in the BEGIN block of this module. +=item %primary_sub_menu + +The keys of this hash reference are the names of items in the primary_menu array +which have sub-menus. For each key, the corresponding value is a reference to +an array containing components extracted from lines in mydesk.tab which begin +with primsub:. +This hash, which is used by primary_menu to generate sub-menus, is populated in +the BEGIN block. + =item @secondary_menu The elements of this array reference arrays that are made up of the components @@ -107,10 +115,42 @@ entries from mydesk.tab Same as primary_menu() but operates on @secondary_menu. +=item create_submenu() + +Creates XHTML for unordered list of sub-menu items which belong to a +particular top-level menu item. Uses hover pseudo class in css to display +dropdown list when mouse hovers over top-level item. Support for IE6 +(no hover psuedo class) via LC_hoverable class for
  • tag for top- +level item, which employs jQuery to handle behavior on mouseover. + +Inputs: 4 - (a) link and (b) target for anchor href in top level item, + (c) title for text wrapped by anchor tag in top level item. + (d) reference to array of arrays of sub-menu items. + =item innerregister() This gets called in order to register a URL in the body of the document +=item loadevents() + +=item unloadevents() + +=item startupremote() + +=item setflags() + +=item maincall() + +=item load_remote_msg() + +=item get_menu_name() + +=item reopenmenu() + +=item open() + +Open the menu + =item clear() =item switch() @@ -129,6 +169,9 @@ The javascript is usually similar to "go =item utilityfunctions() +Output from this routine is a number of javascript functions called by +items in the inline menu, and in some cases items in the Main Menu page. + =item serverform() =item constspaceform() @@ -153,11 +196,13 @@ use Apache::lonhtmlcommon(); use Apache::loncommon(); use Apache::lonenc(); use Apache::lonlocal; +use Apache::lonmsg(); use LONCAPA qw(:DEFAULT :match); use HTML::Entities(); +use Apache::lonwishlist(); use vars qw(@desklines %category_names %category_members %category_positions - $readdesk @primary_menu @secondary_menu); + $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu); my @inlineremote; @@ -180,7 +225,7 @@ sub prep_menuitem { # primary_menu() evaluates @primary_menu and returns XHTML for the menu # that contains following links: -# About, Message, Roles, Help, Logout +# About, Message, Personal, Roles, Help, Logout # @primary_menu is filled within the BEGIN block of this module with # entries from mydesk.tab sub primary_menu { @@ -210,8 +255,33 @@ sub primary_menu { next if $$menuitem[4] eq 'courses' ##'Roles' wanted && !&Apache::loncommon::show_course(); ## - - if ($$menuitem[3] eq 'Help') { # special treatment for helplink + my $title = $menuitem->[3]; + if (defined($primary_submenu{$title})) { + my ($link,$target); + if ($menuitem->[0] ne '') { + $link = $menuitem->[0]; + $target = '_top'; + } else { + $link = '#'; + } + my @primsub; + if (ref($primary_submenu{$title}) eq 'ARRAY') { + foreach my $item (@{$primary_submenu{$title}}) { + next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'})); + next if (($item->[2] eq 'reqcrs') && (!&check_for_rcrs())); + next if ((($item->[2] eq 'portfolio') || + ($item->[2] eq 'blog')) && + (!&Apache::lonnet::usertools_access('','',$item->[2], + undef,'tools'))); + push(@primsub,$item); + } + if (@primsub > 0) { + $menu .= &create_submenu($link,$target,$title,\@primsub); + } elsif ($link) { + $menu .= '
  • '.&mt($title).'
  • '; + } + } + } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink if ($public) { my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; my $defdom = &Apache::lonnet::default_login_domain(); @@ -267,12 +337,13 @@ sub secondary_menu { ? "/$env{'request.course.sec'}" : ''); my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'}); - my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec); - my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec); - my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec); + my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'}; + my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec); + my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec); + my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec); my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec); my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec); - my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec); + my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec); my $author = &getauthor(); my %groups = &Apache::lonnet::get_active_groups( @@ -288,6 +359,10 @@ sub secondary_menu { && !$env{'request.course.id'}; next if $$menuitem[4] =~ /^mdc/ && !$canedit; + next if $$menuitem[4] eq 'mdcCourse' + && ($crstype eq 'Community'); + next if $$menuitem[4] eq 'mdcCommunity' + && ($crstype eq 'Course'); next if $$menuitem[4] eq 'nvgr' && $canvgr; next if $$menuitem[4] eq 'vgr' @@ -295,7 +370,7 @@ sub secondary_menu { next if $$menuitem[4] eq 'cst' && !$canmodifyuser; next if $$menuitem[4] eq 'ncst' - && $canmodifyuser; + && ($canmodifyuser || !$canviewroster); next if $$menuitem[4] eq 'mgr' && !$canmgr; next if $$menuitem[4] eq 'nmgr' @@ -304,19 +379,45 @@ sub secondary_menu { && !$canviewwnew; next if $$menuitem[4] eq 'opa' && !$canmodpara; - next if $$menuitem[4] =~ /showgroups$/ - && !$canviewgrps - && !%groups; + next if $$menuitem[4] eq 'nvcg' + && ($canviewgrps || !%groups); next if $$menuitem[4] eq 'author' && !$author; - if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { + my $title = $menuitem->[3]; + if (defined($secondary_submenu{$title})) { + my ($link,$target); + if ($menuitem->[0] ne '') { + $link = $menuitem->[0]; + $target = '_top'; + } else { + $link = '#'; + } + my @scndsub; + if (ref($secondary_submenu{$title}) eq 'ARRAY') { + foreach my $item (@{$secondary_submenu{$title}}) { + if (ref($item) eq 'ARRAY') { + next if ($item->[2] eq 'vgr' && !$canvgr); + next if ($item->[2] eq 'opa' && !$canmodpara); + next if ($item->[2] eq 'cst' && !$canmodifyuser); + next if ($item->[2] eq 'mgr' && !$canmgr); + next if ($item->[2] eq 'vcg' && !$canviewgrps); + push(@scndsub,$item); + } + } + if (@scndsub > 0) { + $menu .= &create_submenu($link,$target,$title,\@scndsub); + } elsif ($link) { + $menu .= '
  • '.&mt($title).'
  • '; + } + } + } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { # special treatment for role selector my $roles_selector = &roles_selector( $env{'course.' . $env{'request.course.id'} . '.domain'}, $env{'course.' . $env{'request.course.id'} . '.num'} ); - $menu .= $roles_selector ? "
  • $roles_selector
  • " + $menu .= $roles_selector ? "
  • $roles_selector
  • " : ''; } else { $menu .= &prep_menuitem(\@$menuitem); @@ -333,9 +434,8 @@ sub secondary_menu { and ( $env{'request.noversionuri'} eq '' || !defined($env{'request.noversionuri'}))) { - ($escurl = $env{'request.filename'}) =~ - s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2}; - + my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; + ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{}; $escurl = &escape($escurl); } $menu =~ s/\[url\]/$escurl/g; @@ -343,8 +443,69 @@ sub secondary_menu { } $menu =~ s/\[uname\]/$$author{user}/g; $menu =~ s/\[udom\]/$$author{dom}/g; + if ($menu) { + $menu = ""; + } + return $menu; +} - return ""; +sub create_submenu { + my ($link,$target,$title,$submenu) = @_; + return unless (ref($submenu) eq 'ARRAY'); + my $disptarget; + if ($target ne '') { + $disptarget = ' target="'.$target.'"'; + } + my $menu = '
  • '. + ''. + ''.&mt($title). + ''. + ' ▼'. + '
  • '; + return $menu; +} + +sub registerurl { + my ($forcereg) = @_; + my $result = ''; + if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } + my $force_title=''; + if ($env{'request.state'} eq 'construct') { + $force_title=&Apache::lonxml::display_title(); + } + if (($env{'environment.remote'} eq 'off') || + ((($env{'request.publicaccess'}) || + (!&Apache::lonnet::is_on_map( + &unescape($env{'request.noversionuri'})))) && + (!$forcereg))) { + return + $result + .'' + .$force_title; + } +# Graphical display after login only + if ($env{'request.registered'} && !$forcereg) { return ''; } + $result.=&innerregister($forcereg); + return $result.$force_title; } sub innerregister { @@ -356,11 +517,23 @@ sub innerregister { $env{'request.registered'} = 1; + my $noremote = ($env{'environment.remote'} eq 'off'); + undef(@inlineremote); + my $reopen=&Apache::lonmenu::reopenmenu(); + + my $newmail=''; + + if (&Apache::lonmsg::newmail() && !$noremote) { + # We have new mail and remote is up + $newmail= 'swmenu.setstatus("you have","messages");'; + } + + my $resurl; if ( $env{'request.symb'} && $env{'request.course.id'} ) { - my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread()); + (my $mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread()); my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'}; my $maptitle = &Apache::lonnet::gettitle($mapurl); @@ -395,11 +568,11 @@ sub innerregister { &Apache::lonhtmlcommon::clear_breadcrumbs(); &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'}); } + my $timesync = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' ); # ============================================================================= # ============================ This is for URLs that actually can be registered - return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/}) - || $forcereg ); - + if ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/}) + || ($forcereg)) { # -- This applies to homework problems for users with grading privileges my $crs='/'.$env{'request.course.id'}; if ($env{'request.course.sec'}) { @@ -407,25 +580,39 @@ sub innerregister { } $crs=~s/\_/\//g; + my %swtext; + if ($noremote) { + %swtext = &get_inline_text(); + } else { + %swtext = &get_rc_text(); + } my $hwkadd=''; if ($env{'request.symb'} ne '' && - $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) { + $env{'request.filename'}=~/$LONCAPA::assess_re/) { if (&Apache::lonnet::allowed('mgr',$crs)) { - $hwkadd.=&switch('','',7,2,'pgrd.png','Content Grades','grades[_4]', + $hwkadd.=&switch('','',7,2,'pgrd.png',$swtext{'pgrd'},'grades[_4]', "gocmd('/adm/grades','gradingmenu')", 'Content Grades'); } elsif (&Apache::lonnet::allowed('vgr',$crs)) { - $hwkadd.=&switch('','',7,2,'subm.png','Content Submissions','missions[_1]', + $hwkadd.=&switch('','',7,2,'subm.png',$swtext{'subm'},'missions[_1]', "gocmd('/adm/grades','submission')", 'Content Submissions'); } } if ($env{'request.symb'} ne '' && &Apache::lonnet::allowed('opa',$crs)) { - $hwkadd.=&switch('','',7,3,'pparm.png','Content Settings','parms[_2]', + $hwkadd.=&switch('','',7,3,'pparm.png',$swtext{'pparm'},'parms[_2]', "gocmd('/adm/parmset','set')", 'Content Settings'); } + if ($noremote) { + if ($env{'request.symb'}=~/^uploaded/ && + &Apache::lonnet::allowed('mdc',$crs)) { + $hwkadd.=&switch('','',7,4,'docs.png',$swtext{'docs'},'parms[_2]', + "gocmd('/adm/coursedocs','direct')", + 'Folder/Page Content'); + } + } # -- End Homework ### ### Determine whether or not to display the 'cstr' button for this @@ -445,7 +632,7 @@ sub innerregister { # # Set defaults for authors my ($top,$bottom) = ('con-','struct'); - my $action = "go('/priv/".$env{'user.name'}."');"; + my $action = "go('/priv/".$env{'user.domain'}.'/'.$env{'user.name'}."');"; my $cadom = $env{'request.role.domain'}; my $caname = $env{'user.name'}; my $desc = "Enter my construction space"; @@ -453,12 +640,12 @@ sub innerregister { if ($env{'request.role'} =~ /^ca/) { ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/); ($top,$bottom) = ('co con-','struct'); - $action = "go('/priv/".$caname."');"; + $action = "go('/priv/".$cadom.'/'.$caname."');"; $desc = "Enter construction space as co-author"; } elsif ($env{'request.role'} =~ /^aa/) { ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/); ($top,$bottom) = ('co con-','struct'); - $action = "go('/priv/".$caname."');"; + $action = "go('/priv/".$cadom.'/'.$caname."');"; $desc = "Enter construction space as assistant co-author"; } # Check that we are on the correct machine @@ -467,7 +654,7 @@ sub innerregister { my @ids=&Apache::lonnet::current_machine_ids(); foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } if (!$allowed) { - $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc); + $editbutton=&switch('','',6,1,,$top,$bottom,$action,$desc); $noeditbutton = 0; } } @@ -491,9 +678,13 @@ sub innerregister { $uploaded = &is_course_upload($file,$cnum,$cdom); } if (!$uploaded) { - $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/; + + $file=~s{^(priv/$match_domain/$match_username)}{/$1}; + $file=~s{^($match_domain/$match_username)}{/priv/$1}; + # Check that the user has permission to edit this resource - ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1); + my $setpriv = 1; + ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$setpriv); if (defined($cfudom)) { $home=&Apache::lonnet::homeserver($cfuname,$cfudom); my $allowed=0; @@ -530,7 +721,7 @@ sub innerregister { } } $editbutton=&switch - ('','',6,1,'pcstr.png','edit[_1]','resource[_2]', + ('','',6,1,'pcstr.png',$swtext{'pcstr'},'resource[_2]', $bot,"Edit this resource"); $noeditbutton = 0; } @@ -546,7 +737,7 @@ sub innerregister { my $cfile = &edit_course_upload($file,$cnum,$cdom); if ($cfile) { $editbutton=&switch - ('','',6,1,'pcstr.png','edit[_1]', + ('','',6,1,'pcstr.png',$swtext{'pcstr'}, 'resource[_2]',"go('".$cfile."');", 'Edit this resource'); } @@ -554,17 +745,31 @@ sub innerregister { } } } + if ($env{'request.course.id'}) { + if ($resurl eq "public/$cdom/$cnum/syllabus") { + if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ /\w/) { + if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { + $editbutton=&switch('','',6,1,'pcstr.png',$swtext{'pcstr'}, + 'resource[_2]', + "go('/adm/courseprefs?phase=display&actions=courseinfo')", + 'Edit this resource'); + } + } + } + } ### ### # Prepare the rest of the buttons - my $menuitems; + my ($menuitems,$got_prt,$got_wishlist,$cstritems); if ($const_space) { # # We are in construction space # - my ($uname,$thisdisfn) = - ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|); - my $currdir = '/priv/'.$uname.'/'.$thisdisfn; + + my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; + my ($udom,$uname,$thisdisfn) = + ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$}); + my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn; if ($currdir =~ m-/$-) { $is_const_dir = 1; } else { @@ -576,11 +781,15 @@ sub innerregister { # $menuitems=(< 0){ }else{ $menuitems.="anot.png"; } -$menuitems.="&Notes&&annotate()&"; +$menuitems.="&$swtext{'anot'}&tations[_1]&annotate()&"; $menuitems.="Make notes and annotations about this resource&&1\n"; unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) { - if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) { + if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) { $menuitems.=(< +// + + +$cstrcrumbs +ENDREGTHIS } + } else { + unless ($noremote) { +# Not registered, graphical + return (< +// + +ENDDONOTREGTHIS + + } + return ''; + } +} + +sub get_inline_text { + my %text = ( + pgrd => 'Content Grades', + subm => 'Content Submissions', + pparm => 'Content Settings', + docs => 'Folder/Page Content', + pcstr => 'Edit', + prt => 'Print', + alnk => 'Stored Links', + anot => 'Notes', + catalog => 'Info', + eval => 'Evaluate', + fdbk => 'Feedback', + ); + return %text; +} + +sub get_rc_text { + my %text = ( + pgrd => 'problem[_1]', + subm => 'view sub-[_1]', + pparm => 'problem[_2]', + pcstr => 'edit[_1]', + prt => 'prepare[_1]', + back => 'backward[_1]', + forw => 'forward[_1]', + alnk => 'add to[_1]', + anot => 'anno-[_1]', + catalog => 'catalog[_2]', + eval => 'evaluate[_1]', + fdbk => 'feedback[_1]', + ); + return %text; } sub is_course_upload { @@ -735,12 +1117,187 @@ sub edit_course_upload { return $cfile; } +sub loadevents() { + if ($env{'request.state'} eq 'construct' || + $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } + return 'LONCAPAreg();'; +} + +sub unloadevents() { + if ($env{'request.state'} eq 'construct' || + $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } + return 'LONCAPAstale();'; +} + +sub startupremote { + my ($lowerurl)=@_; + unless ($env{'environment.remote'} eq 'on') { + return (''); + } +# +# The Remote actually gets launched! +# + my $configmenu=&rawconfig(); + my $esclowerurl=&escape($lowerurl); + my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited'); + return(< +// + +ENDREMOTESTARTUP +} + +sub setflags() { + return(< +// + +ENDSETFLAGS +} + +sub maincall() { + unless ($env{'environment.remote'} eq 'on') { return ''; } + return(< +// + +ENDMAINCALL +} + +sub load_remote_msg { + my ($lowerurl)=@_; + + unless ($env{'environment.remote'} eq 'on') { return ''; } + + my $esclowerurl=&escape($lowerurl); + my $link=&mt('[_1]Continue[_2] on in Inline Menu mode' + ,'' + ,''); + return(< +
    + +
    +

    +

    $link

    +ENDREMOTEFORM +} + +sub get_menu_name { + my $hostid = $Apache::lonnet::perlvar{'lonHostID'}; + $hostid =~ s/\W//g; + return 'LCmenu'.$hostid; +} + + +sub reopenmenu { + unless ($env{'environment.remote'} eq 'on') { return ''; } + my $menuname = &get_menu_name(); + my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); + return('window.open('.$nothing.',"'.$menuname.'","",false);'); +} + + +sub open { + my $returnval=''; + unless ($env{'environment.remote'} eq 'on') { + return + ''; + } + my $menuname = &get_menu_name(); + +# unless (shift eq 'unix') { +# resizing does not work on linux because of virtual desktop sizes +# $returnval.=(< +ENDOPEN + return ''; +} + + # ================================================================== Raw Config sub clear { my ($row,$col)=@_; - $inlineremote[10*$row+$col]=''; - return ''; + if ($env{'environment.remote'} eq 'on') { + if (($row<1) || ($row>13)) { return ''; } + return "\n".qq(window.status+='.';swmenu.clearbut($row,$col);); + } else { + $inlineremote[10*$row+$col]=''; + return ''; + } } # ============================================ Switch a button or create a link @@ -757,6 +1314,24 @@ sub switch { my $idx=10*$row+$col; $category_members{$cat}.=':'.$idx; + if ($env{'environment.remote'} eq 'on') { + if (($row<1) || ($row>13)) { return ''; } + if ($env{'request.state'} eq 'construct') { + my $text = $top.' '.$bot; + $text=~s/\s*\-\s*//gs; + my $pic = ''.$text.''; + $inlineremote[$idx] = + ''. + $pic.''.$top.' '; + } +# Remote + $img=~s/\.png$/\.gif/; + return "\n". + qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc");); + } + # Inline Menu if ($nobreak==2) { return ''; } my $text=$top.' '.$bot; @@ -787,9 +1362,19 @@ sub switch { } } else { # Inline Menu - $inlineremote[$idx]= + my @tools = (93,91,81,82,83); + unless ($env{'request.state'} eq 'construct') { + push(@tools,63); + } + if (($env{'environment.icons'} eq 'iconsonly') && + (grep(/^$idx$/,@tools))) { + $inlineremote[$idx] = + ''.$pic.''; + } else { + $inlineremote[$idx] = ''.$pic. ''.$top.' '; + } } return ''; } @@ -808,6 +1393,13 @@ sub secondlevel { return $output; } +sub openmenu { + my $menuname = &get_menu_name(); + unless ($env{'environment.remote'} eq 'on') { return ''; } + my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); + return "window.open(".$nothing.",'".$menuname."');"; +} + sub inlinemenu { undef(@inlineremote); undef(%category_members); @@ -850,7 +1442,13 @@ sub rawconfig { # my $textualoverride=shift; my $output=''; - return '' unless $textualoverride; + if ($env{'environment.remote'} eq 'on') { + $output.= + "window.status='Opening Remote Control';var swmenu=".&openmenu(). +"\nwindow.status='Configuring Remote Control ';"; + } else { + unless ($textualoverride) { return ''; } + } my $uname=$env{'user.name'}; my $udom=$env{'user.domain'}; my $adv=$env{'user.adv'}; @@ -987,6 +1585,7 @@ sub rawconfig { ($env{'request.role'}=~/($match_domain)\/($match_username)$/); } $act =~ s/\$caname/$caname/g; + $act =~ s/\$cadom/$cadom/g; my $home = &Apache::lonnet::homeserver($caname,$cadom); my $allowed=0; my @ids=&Apache::lonnet::current_machine_ids(); @@ -1024,6 +1623,12 @@ sub rawconfig { $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); } } + if ($env{'environment.remote'} eq 'on') { + $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';"; + if (&Apache::lonmsg::newmail()) { + $output.='swmenu.setstatus("you have","messages");'; + } + } return $output; } @@ -1049,6 +1654,28 @@ sub check_for_rcrs { return $showreqcrs; } +# ======================================================================= Close + +sub close { + unless ($env{'environment.remote'} eq 'on') { return ''; } + my $menuname = &get_menu_name(); + return(< +// + +ENDCLOSE +} + sub dc_popup_js { my %lt = &Apache::lonlocal::texthash( more => '(More ...)', @@ -1060,13 +1687,13 @@ function showCourseID() { document.getElementById('dccid').style.display='block'; document.getElementById('dccid').style.textAlign='left'; document.getElementById('dccid').style.textFace='normal'; - document.getElementById('dccidtext').innerHTML ='$lt{'less'}'; + document.getElementById('dccidtext').innerHTML ='$lt{'less'}'; return; } function hideCourseID() { document.getElementById('dccid').style.display='none'; - document.getElementById('dccidtext').innerHTML ='$lt{'more'}'; + document.getElementById('dccidtext').innerHTML ='$lt{'more'}'; return; } @@ -1074,6 +1701,27 @@ END } +sub countdown_toggle_js { + return <<"END"; + +function toggleCountdown() { + var countdownid = document.getElementById('duedatecountdown'); + var currstyle = countdownid.style.display; + if (currstyle == 'inline') { + countdownid.style.display = 'none'; + document.getElementById('ddcountcollapse').innerHTML=''; + document.getElementById('ddcountexpand').innerHTML='◄ '; + } else { + countdownid.style.display = 'inline'; + document.getElementById('ddcountcollapse').innerHTML='► '; + document.getElementById('ddcountexpand').innerHTML=''; + } + return; +} + +END +} + sub utilityfunctions { my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0])); if ($currenturl =~ m{^/adm/wrapper/ext/} @@ -1105,58 +1753,16 @@ sub utilityfunctions { my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'. &mt('Switch server?'); - my $start_page_wishlistlink = - &Apache::loncommon::start_page('Set link to wishlist',undef, - {'only_body' => 1, - 'js_ready' => 1, - 'bgcolor' => '#FFFFFF',}); - - my $warningLink = &mt('You must insert a title!'); - - # HTML-Markup for 'Set a link for this resource to wishlist' - # this is written via JavaScript document.write (function set_wishlistlink) - # it is split into 3 parts and the inputfields for title and path are left out - # these fields are inserted later to set the values for title and path - # automatically via JavaScript (document.title and location.pathname) - my %folders = &Apache::lonnet::get('wishlist',['folders']); - if ($folders{'folders'} eq '') { - $folders{'folders'} = ''; - } - my $in_page_wishlistlink1 = '

    '.&mt('Set a link to wishlist').'

    '. - '
    '. - &Apache::lonhtmlcommon::start_pick_box(). - &Apache::lonhtmlcommon::row_title(&mt('Link Title')); - - my $in_page_wishlistlink2 = &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title(&mt('Path')); - - my $in_page_wishlistlink3 = &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title(&mt('Note')). - ''. - &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::end_pick_box(). - '

    '. - ''. - ''. - ''. - '
    '; - - # remove all \n for inserting on javascript document.write - $in_page_wishlistlink1 =~ s/\n//g; - $in_page_wishlistlink2 =~ s/\n//g; - $in_page_wishlistlink3 =~ s/\n//g; + my $esc_url=&escape($currenturl); + my $esc_symb=&escape($currentsymb); - my $end_page_wishlistlink = - &Apache::loncommon::end_page({'js_ready' => 1}); + my $countdown = &countdown_toggle_js(); return (<' - +'function newlinksubmit(){' - +'var title = document.getElementsByName("title")[0].value;' - +'if (!title) {' - +'alert("$warningLink");' - +'return false;}' - +'return true;}' - +'<\/scr'+'ipt>' - +'$in_page_wishlistlink1' - +'' - +'$in_page_wishlistlink2' - +'' - +'$in_page_wishlistlink3' - +'$end_page_wishlistlink' ); - wishlistlink.document.close(); -} - -function open_Wishlist_Import(rat) { +function open_StoredLinks_Import(rat) { var newWin; if (rat) { newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat, @@ -1317,6 +1894,22 @@ function open_Wishlist_Import(rat) { newWin.focus(); } +(function (\$) { + \$(document).ready(function () { + \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1])); + /*\@cc_on + if (!window.XMLHttpRequest) { + \$('.LC_hoverable').each(function () { + this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); }); + this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); }); + }); + } + \@*/ + }); +}(jQuery)); + +$countdown + ENDUTILITY } @@ -1349,6 +1942,16 @@ sub constspaceform { ENDCONSTSPACEFORM } +sub get_nav_status { + my $navstatus="swmenu.w_loncapanav_flag="; + if ($env{'environment.remotenavmap'} eq 'on') { + $navstatus.="1"; + } else { + $navstatus.="-1"; + } + return $navstatus; +} + sub hidden_button_check { if ( $env{'request.course.id'} eq '' || $env{'request.role.adv'} ) { @@ -1363,7 +1966,7 @@ sub roles_selector { my ($cdom,$cnum) = @_; my $crstype = &Apache::loncommon::course_type(); my $now = time; - my (%courseroles,%seccount); + my (%courseroles,%seccount,%courseprivs); my $is_cc; my $role_selector; my $ccrole; @@ -1371,7 +1974,31 @@ sub roles_selector { $ccrole = 'co'; } else { $ccrole = 'cc'; - } + } + my ($priv,$gotsymb,$destsymb); + my $destinationurl = $ENV{'REQUEST_URI'}; + if ($destinationurl =~ /\?symb=/) { + $gotsymb = 1; + } elsif ($destinationurl =~ m{^/enc/}) { + my $plainurl = &Apache::lonenc::unencrypted($destinationurl); + if ($plainurl =~ /\?symb=/) { + $gotsymb = 1; + } + } + unless ($gotsymb) { + $destsymb = &Apache::lonnet::symbread(); + if ($destsymb ne '') { + $destsymb = &Apache::lonenc::check_encrypt($destsymb); + } + } + my $reqprivs = &required_privs(); + if (ref($reqprivs) eq 'HASH') { + my $destination = $destinationurl; + $destination =~ s/(\?.*)$//; + if (exists($reqprivs->{$destination})) { + $priv = $reqprivs->{$destination}; + } + } if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) { my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}); @@ -1384,7 +2011,7 @@ sub roles_selector { } } if ($is_cc) { - &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount); + &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv); } else { my %gotnosection; foreach my $item (keys(%env)) { @@ -1400,6 +2027,18 @@ sub roles_selector { $gotnosection{$role} = 1; } } + if ($priv ne '') { + my $cnumsec = $cnum; + if ($sec ne '') { + $cnumsec .= "/$sec"; + } + $courseprivs{"$role./$cdom/$cnumsec./"} = + $env{"user.priv.$role./$cdom/$cnumsec./"}; + $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} = + $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"}; + $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} = + $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"}; + } if (ref($courseroles{$role}) eq 'ARRAY') { if ($sec ne '') { if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) { @@ -1425,7 +2064,7 @@ sub roles_selector { } my @roles_order = ($ccrole,'in','ta','ep','ad','st'); if (keys(%courseroles) > 1) { - $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles); + $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv); $role_selector .= '
    '."\n". + $role_selector .= ''."\n"; + if ($destsymb ne '') { + $role_selector .= ''."\n"; + } + $role_selector .= ''."\n". + &HTML::Entities::encode($destinationurl).'" />'."\n". ''."\n". ''."\n". ''."\n". @@ -1451,8 +2095,9 @@ sub roles_selector { } sub get_all_courseroles { - my ($cdom,$cnum,$courseroles,$seccount) = @_; - unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) { + my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_; + unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') && + (ref($courseprivs) eq 'HASH')) { return; } my ($result,$cached) = @@ -1460,9 +2105,11 @@ sub get_all_courseroles { if (defined($cached)) { if (ref($result) eq 'HASH') { if ((ref($result->{'roles'}) eq 'HASH') && - (ref($result->{'seccount'}) eq 'HASH')) { + (ref($result->{'seccount'}) eq 'HASH') && + (ref($result->{'privs'}) eq 'HASH')) { %{$courseroles} = %{$result->{'roles'}}; %{$seccount} = %{$result->{'seccount'}}; + %{$courseprivs} = %{$result->{'privs'}}; return; } } @@ -1490,30 +2137,43 @@ sub get_all_courseroles { push(@{$courseroles->{$urole}},$usec); } } + my $area = '/'.$cdom.'/'.$cnum; + if ($usec ne '') { + $area .= '/'.$usec; + } + if ($role =~ /^cr\//) { + &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area); + } else { + &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area); + } } my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']); @{$courseroles->{'st'}} = (); + &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum"); if (keys(%sections_count) > 0) { push(@{$courseroles->{'st'}},keys(%sections_count)); - $seccount->{'st'} = scalar(keys(%sections_count)); + $seccount->{'st'} = scalar(keys(%sections_count)); } my $rolehash = { 'roles' => $courseroles, 'seccount' => $seccount, + 'privs' => $courseprivs, }; &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash); return; } sub jump_to_role { - my ($cdom,$cnum,$seccount,$courseroles) = @_; + my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_; my %lt = &Apache::lonlocal::texthash( this => 'This role has section(s) associated with it.', ente => 'Enter a specific section.', orlb => 'Enter a specific section, or leave blank for no section.', avai => 'Available sections are:', youe => 'You entered an invalid section choice:', - plst => 'Please try again', + plst => 'Please try again.', + role => 'The role you selected is not permitted to view the current page.', + swit => 'Switch role, but display Main Menu page instead?', ); my $js; if (ref($courseroles) eq 'HASH') { @@ -1536,6 +2196,37 @@ sub jump_to_role { ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n"; } } + my $checkroles = 0; + if ($priv && ref($courseprivs) eq 'HASH') { + my (%disallowed,%allowed,@disallow); + foreach my $role (sort(keys(%{$courseprivs}))) { + my $trole; + if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) { + $trole = $1; + } + if (($trole ne '') && ($trole ne 'cm')) { + if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) { + $allowed{$trole} = 1; + } else { + $disallowed{$trole} = 1; + } + } + } + foreach my $trole (keys(%disallowed)) { + unless ($allowed{$trole}) { + push(@disallow,$trole); + } + } + if (@disallow > 0) { + $checkroles = 1; + $js .= " var disallow = new Array('".join("','",@disallow)."');\n". + " var rolecheck = 1;\n"; + } + } + if (!$checkroles) { + $js .= " var disallow = new Array();\n". + " rolecheck = 0;\n"; + } return <<"END";