--- loncom/interface/lonmenu.pm 2012/05/24 22:56:30 1.375 +++ loncom/interface/lonmenu.pm 2012/10/31 12:54:13 1.389 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.375 2012/05/24 22:56:30 raeburn Exp $ +# $Id: lonmenu.pm,v 1.389 2012/10/31 12:54:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -247,9 +247,7 @@ sub primary_menu { my @primsub; if (ref($primary_submenu{$title}) eq 'ARRAY') { foreach my $item (@{$primary_submenu{$title}}) { - next if (($item->[2] eq 'wishlist') && - ((!&Apache::lonnet::allowed('bre',"/res/$env{'user.domain'}/")) && - (!&Apache::lonnet::allowed('bro',"/res/$env{'user.domain'}/")))); + 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')) && @@ -260,7 +258,7 @@ sub primary_menu { if (@primsub > 0) { $menu .= &create_submenu($link,$target,$title,\@primsub); } elsif ($link) { - $menu .= '
  • '.$title.'
  • '; + $menu .= '
  • '.&mt($title).'
  • '; } } } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink @@ -319,6 +317,7 @@ sub secondary_menu { ? "/$env{'request.course.sec'}" : ''); my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'}); + 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); @@ -347,7 +346,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' @@ -394,16 +393,22 @@ sub secondary_menu { } $menu =~ s/\[uname\]/$$author{user}/g; $menu =~ s/\[udom\]/$$author{dom}/g; - - return ""; + if ($menu) { + $menu = ""; + } + return $menu; } sub create_submenu { my ($link,$target,$title,$submenu) = @_; return unless (ref($submenu) eq 'ARRAY'); + my $disptarget; + if ($target ne '') { + $disptarget = ' target="'.$target.'"'; + } my $menu = '
  • '. - ''. - ''.$title. + ''. + ''.&mt($title). ''. ' ▼'. '
  • '; @@ -518,7 +523,7 @@ sub innerregister { ### my $editbutton = ''; my $noeditbutton = 1; - my ($cnum,$cdom); + my ($cnum,$cdom,$cfile,$switchserver,$home,$uploaded); if ($env{'request.course.id'}) { $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; @@ -550,95 +555,50 @@ sub innerregister { my $home = &Apache::lonnet::homeserver($caname,$cadom); my $allowed=0; my @ids=&Apache::lonnet::current_machine_ids(); - foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } - if (!$allowed) { + if (($home ne 'no_host') && (grep(/^\Q$home\E$/,@ids))) { $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc); - $noeditbutton = 0; } - } + } else { # # We are an author for some stuff, but currently do not have the role of author. # Figure out if we have authoring privileges for the resource we are looking at. -# This should maybe become a privilege check in lonnet # - ## - ## Determine if user can edit url. - ## - my $cfile=''; - my $cfuname=''; - my $cfudom=''; - my $uploaded; - my $switchserver=''; - my $home; - if ($env{'request.filename'}) { - my $file=&Apache::lonnet::declutter($env{'request.filename'}); - if (defined($cnum) && defined($cdom)) { - $uploaded = &is_course_upload($file,$cnum,$cdom); - } - if (!$uploaded) { - - $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 - my $setpriv = 1; - ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$setpriv); - if (defined($cfudom)) { - $home=&Apache::lonnet::homeserver($cfuname,$cfudom); - my $allowed=0; - my @ids=&Apache::lonnet::current_machine_ids(); - foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } - if ($allowed) { - $cfile=$file; - } else { - $switchserver=$file; + my ($cfile,$switchserver,$home,$uploaded); + if ($env{'request.filename'}) { + my $file=&Apache::lonnet::declutter($env{'request.filename'}); + ## + ## Determine if user can edit url. + ## + ($cfile,$home,$switchserver,$uploaded) = + &Apache::lonnet::can_edit_resource($file,$cnum,$cdom); + } + # Turn the button on or off + if (($cfile) && ($home ne '') && ($home ne 'no_host')) { + my $nocrsedit; + # Suppress display where CC has switched to student role. + if ($env{'request.course.id'}) { + unless(&Apache::lonnet::allowed('mdc', + $env{'request.course.id'})) { + $nocrsedit = 1; } } - } - } - # Finally, turn the button on or off - if (($cfile || $switchserver) && !$const_space) { - my $nocrsedit; - # Suppress display where CC has switched to student role. - if ($env{'request.course.id'}) { - unless(&Apache::lonnet::allowed('mdc', - $env{'request.course.id'})) { - $nocrsedit = 1; + if ($nocrsedit) { + $editbutton=&clear(6,1); + } else { + $editbutton = &get_editbutton($cfile,$home,$switchserver,$uploaded); } - } - if ($nocrsedit) { + } elsif ($editbutton eq '') { $editbutton=&clear(6,1); - } else { - my $bot = "go('$cfile')"; - if ($switchserver) { - if ( $env{'request.symb'} && $env{'request.course.id'} ) { - $cfile = '/adm/switchserver?otherserver='.$home.'&role='. - &HTML::Entities::encode($env{'request.role'},'"<>&').'&symb='. - &HTML::Entities::encode($env{'request.symb'},'"<>&'); - $bot = "need_switchserver('$cfile');"; - } - } - $editbutton=&switch - ('','',6,1,'pcstr.png','Edit','resource[_2]', - $bot,"Edit this resource"); - $noeditbutton = 0; } - } elsif ($editbutton eq '') { - $editbutton=&clear(6,1); } - } - if (($noeditbutton) && ($env{'request.filename'})) { + } elsif (($env{'request.filename'}) && $env{'request.course.id'}) { if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { my $file=&Apache::lonnet::declutter($env{'request.filename'}); - if (defined($cnum) && defined($cdom)) { - if (&is_course_upload($file,$cnum,$cdom)) { - my $cfile = &edit_course_upload($file,$cnum,$cdom); - if ($cfile) { - $editbutton=&switch - ('','',6,1,'pcstr.png','Edit', - 'resource[_2]',"go('".$cfile."');", - 'Edit this resource'); - } + if (($cnum =~ /$match_courseid/) && ($cdom =~ /$match_domain/)) { + my ($cfile,$home,$switchserver,$uploaded) = + &Apache::lonnet::can_edit_resource($file,$cnum,$cdom); + if (($uploaded) && ($cfile ne '')) { + $editbutton = &get_editbutton($cfile,$home,$switchserver,$uploaded); } } } @@ -658,7 +618,7 @@ sub innerregister { ### ### # Prepare the rest of the buttons - my $menuitems; + my ($menuitems,$got_prt,$got_wishlist); if ($const_space) { # # We are in construction space @@ -694,7 +654,7 @@ ENDMENUITEMS } elsif ( defined($env{'request.course.id'}) && $env{'request.symb'} ne '' ) { # -# We are in a course and looking at a registred URL +# We are in a course and looking at a registered URL # Should probably be in mydesk.tab # $menuitems=(<&'); - } - } - return $cfile; } # ================================================================== Raw Config @@ -890,9 +846,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 ''; } @@ -1178,6 +1144,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/} @@ -1206,12 +1193,13 @@ sub utilityfunctions { my $end_page_annotate = &Apache::loncommon::end_page({'js_ready' => 1}); - my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'. - &mt('Switch server?'); + my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource(); my $esc_url=&escape($currenturl); my $esc_symb=&escape($currentsymb); + my $countdown = &countdown_toggle_js(); + return (<'.&Apache::lonnet::plaintext($role).''; } } - $role_selector .= ''."\n". + $role_selector .= ''."\n"; + if ($destsymb ne '') { + $role_selector .= ''."\n"; + } + $role_selector .= ''."\n". ''."\n". @@ -1760,6 +1754,73 @@ sub required_privs { return $privs; } +sub countdown_timer { + if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') && + ($env{'request.filename'}=~/$LONCAPA::assess_re/)) { + my ($type,$hastimeleft,$slothastime); + my $now = time; + if ($env{'request.filename'} =~ /\.task$/) { + $type = 'Task'; + } else { + $type = 'problem'; + } + my ($status,$accessmsg,$slot_name,$slot) = + &Apache::lonhomework::check_slot_access('0',$type); + if ($slot_name ne '') { + if (ref($slot) eq 'HASH') { + if (($slot->{'starttime'} < $now) && + ($slot->{'endtime'} > $now)) { + $slothastime = 1; + } + } + } + if ($status ne 'CAN_ANSWER') { + return; + } + my $duedate = &Apache::lonnet::EXT("resource.0.duedate"); + my @interval=&Apache::lonnet::EXT("resource.0.interval"); + my $hastimeleft; + if (@interval > 1) { + my $first_access=&Apache::lonnet::get_first_access($interval[1]); + if ($first_access > 0) { + if ($first_access+$interval[0] > time) { + $hastimeleft = 1; + } + } + } + if (($duedate && $duedate > time) || + (!$duedate && $hastimeleft) || + ($slot_name ne '' && $slothastime)) { + my ($collapse,$expand,$alttxt,$title,$currdisp); + if ((@interval > 1 && $hastimeleft) || + ($type eq 'Task' && $slothastime)) { + $currdisp = 'inline'; + $collapse = '► '; + } else { + $currdisp = 'none'; + $expand = '◄ '; + } + unless ($env{'environment.icons'} eq 'iconsonly') { + $alttxt = &mt('Timer'); + $title = $alttxt.' '; + } + my $desc = &mt('Countdown to due date/time'); + return < + +$collapse + + + +$expand +$alttxt$title +END + } + } + return; +} + # ================================================================ Main Program BEGIN {