--- loncom/interface/lonmenu.pm 2023/06/11 20:45:35 1.532 +++ loncom/interface/lonmenu.pm 2023/10/06 02:04:47 1.540 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.532 2023/06/11 20:45:35 raeburn Exp $ +# $Id: lonmenu.pm,v 1.540 2023/10/06 02:04:47 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -210,7 +210,6 @@ use Apache::lonenc(); use Apache::lonlocal; use Apache::lonmsg(); use LONCAPA qw(:DEFAULT :match); -use LONCAPA::ltiutils; use HTML::Entities(); use Apache::lonwishlist(); @@ -969,6 +968,18 @@ sub innerregister { $$showncrumbsref = 1; } return $trail; + } elsif (($resurl eq '/public'.$courseurl.'/syllabus') && + ($env{'form.folderpath'})) { + if ($env{'form.title'}) { + $title = $env{'form.title'}; + } else { + $title = 'Syllabus'; + } + &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname); + $title = &HTML::Entities::encode($title,'\'"<>&'); + my ($trail) = + &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1); + return $trail; } unless ($env{'request.state'} eq 'construct') { &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -1070,11 +1081,30 @@ sub innerregister { if (($env{'request.symb'} ne '') && ($env{'request.filename'}=~/$LONCAPA::assess_re/) && (($perms{'mgr'}) || ($perms{'vgr'}))) { - my ($viewas,$text,$change,$visibility,$vuname,$vudom,$vid,$leftvis,$defdom,$righticon); + my ($viewas,$text,$change,$visibility,$vuname,$vudom,$vid,$leftvis,$defdom, + $domselector,$righticon); my %lt = &Apache::lonlocal::texthash( view => 'View', upda => 'Update', ); + my $possdomstr = $env{'course.'.$env{'request.course.id'}.'.internal.userdomains'}; + if ($possdomstr =~ /,/) { + my @possdoms = split(/,/,$possdomstr); + if ($env{'request.user_in_effect'} =~ /^$match_username:($match_domain)$/) { + $defdom = $1; + } elsif (grep(/^\Q$cdom\E$/,@possdoms)) { + $defdom = $cdom; + } elsif (&Apache::lonnet::domain($possdoms[0]) ne '') { + $defdom = $possdoms[0]; + } + $domselector = &Apache::loncommon::select_dom_form($defdom,'vudom','','','',\@possdoms); + } elsif (($possdomstr ne '') && (&Apache::lonnet::domain($possdomstr) ne '')) { + if ($env{'request.user_in_effect'} =~ /^$match_username:($match_domain)$/) { + $defdom = $1; + } else { + $defdom = $possdomstr; + } + } if ($env{'request.user_in_effect'} =~ /^($match_username):($match_domain)$/) { ($vuname,$vudom) = ($1,$2); unless (&Apache::lonnet::is_advanced_user($vudom,$vuname)) { @@ -1092,17 +1122,29 @@ sub innerregister { $change = 'on'; $visibility = 'none'; $leftvis = 'inline'; - $defdom = $cdom; + if ($defdom eq '') { + $defdom = $cdom; + } } - my $sellink = &Apache::loncommon::selectstudent_link('userview','vuname','vudom'); + my $sellink = &Apache::loncommon::selectstudent_link('userview','vuname','vudom','','','vuidentifier'); my $selscript=&Apache::loncommon::studentbrowser_javascript(); my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}),'<>&"'); - my $input = &mt('User: [_1] or ID: [_2] at: [_3]', - '<input name="vuname" type="text" size="8" value="'.$vuname.'" />', - '<input name="vid" type="text" size="8" value="'.$vid.'" />', - &Apache::loncommon::select_dom_form($defdom,'vudom')). - '<input name="LC_viewas" type="hidden" value="'.$viewas.'" />', - '<input name="symb" type="hidden" value="'.$shownsymb.'" />'; + my $input; + my @items = ( + '<label><input type="radio" name="vuidentifier" value="uname" checked="checked" onclick="javascript:toggleIdentifier(this.form);" />', + '</label><input name="vuname" type="text" size="6" value="'.$vuname.'" id="LC_vuname" />', + '<label><input type="radio" name="vuidentifier" value="uid" onclick="javascript:toggleIdentifier(this.form);" />', + '</label><input name="vid" type="hidden" size="6" value="'.$vid.'" id="LC_vid" />' + ); + if ($domselector) { + push(@items,$domselector); + $input = &mt('[_1]User:[_2] or [_3]ID:[_4] at [_5] | ',@items); + } else { + $input = &mt('[_1]Username:[_2] or [_3]ID:[_4] | ',@items). + '<input name="vudom" type="hidden" value="'.$defdom.'" />'; + } + $input .= '<input name="LC_viewas" type="hidden" value="'.$viewas.'" />', + '<input name="symb" type="hidden" value="'.$shownsymb.'" />'; my $chooser = <<END; $selscript <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link"> @@ -1131,7 +1173,7 @@ END # End course context # Prepare the rest of the buttons - my ($menuitems,$got_prt,$got_wishlist); + my ($menuitems,$got_prt,$got_wishlist,$crsauthor); if ($const_space) { # # We are in construction space @@ -1140,15 +1182,17 @@ END my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; my ($udom,$uname,$thisdisfn) = ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$}); + my $crsauthor; + if (($env{'request.course.id'}) && + ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) && + ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) { + $crsauthor = 1; + } my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn; if ($currdir =~ m-/$-) { $is_const_dir = 1; - if ($thisdisfn eq '') { - unless (($env{'request.course.id'}) && - ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) && - ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) { - $is_const_dir = 2; - } + if (($thisdisfn eq '') && ($crsauthor)) { + $is_const_dir = 2; } my $esc_currdir = &Apache::loncommon::escape_single($currdir); $menuitems=(<<ENDMENUITEMS); @@ -1171,12 +1215,19 @@ ENDMENUITEMS # # Probably should be in mydesk.tab # - $menuitems=(<<ENDMENUITEMS); + if (($crsauthor) && ($pubfile eq "/res/$udom/$uname/default.rights")) { + $menuitems=(<<ENDMENUITEMS); +s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory +s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource +ENDMENUITEMS + } else { + $menuitems=(<<ENDMENUITEMS); s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource s&7&3©.png&Copy&resource[_4]&gocstr('/adm/cfile?action=copy','/priv/$udom/$uname/$cleandisfn')&Copy this resource ENDMENUITEMS + } # # Rename and Delete only available if obsolete or unpublished # @@ -1262,8 +1313,12 @@ ENDMENUITEMS $got_prt = 1; if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/) && (!$env{'request.enc'})) { - my ($cnum,$cdom) = &Apache::loncommon::crsauthor_url($env{'request.uri'}); - unless ($cnum) { + my $privurl = $env{'request.uri'}; + $privurl =~ s{^/res/}{/priv/}; + my ($cnum,$cdom) = &Apache::loncommon::crsauthor_url($privurl); + if ($cnum) { + $crsauthor = 1; + } else { # wishlist is only available for users with access to resource-pool # and links can only be set for resources within the resource-pool $menuitems .= (<<ENDMENUITEMS); @@ -1318,7 +1373,7 @@ s&8&3&prt.png&Print&printout[_1]&gopost( ENDMENUITEMS $got_prt = 1; } - unless ($got_wishlist) { + unless (($got_wishlist) || ($crsauthor)) { if (($env{'user.adv'}) && (!$env{'request.enc'})) { # wishlist is only available for users with access to resource-pool $menuitems .= (<<ENDMENUITEMS); @@ -2337,23 +2392,28 @@ sub view_as_js { return <<"END"; function toggleViewAsUser(change) { - var seluserid = document.getElementById('LC_selectuser'); - var currstyle = seluserid.style.display; - if (change == 'off') { - document.userview.elements['LC_viewas'].value = ''; - document.userview.elements['vuname'].value = ''; - document.userview.elements['vid'].value = ''; - document.userview.submit(); - return; - } - if (currstyle == 'inline') { - seluserid.style.display = 'none'; - document.getElementById('usexpand').innerHTML='► '; - document.getElementById('uscollapse').innerHTML=''; - } else { - seluserid.style.display = 'inline'; - document.getElementById('usexpand').innerHTML=''; - document.getElementById('uscollapse').innerHTML='◄ '; + if (document.getElementById('LC_selectuser')) { + var seluserid = document.getElementById('LC_selectuser'); + var currstyle = seluserid.style.display; + if (change == 'off') { + document.userview.elements['LC_viewas'].value = ''; + document.userview.elements['vuname'].value = ''; + document.userview.elements['vid'].value = ''; + document.userview.submit(); + return; + } + if ((document.getElementById('usexpand')) && (document.getElementById('uscollapse'))) { + if (currstyle == 'inline') { + seluserid.style.display = 'none'; + document.getElementById('usexpand').innerHTML='► '; + document.getElementById('uscollapse').innerHTML=''; + } else { + seluserid.style.display = 'inline'; + document.getElementById('usexpand').innerHTML=''; + document.getElementById('uscollapse').innerHTML='◄ '; + toggleIdentifier(document.userview); + } + } } return; } @@ -2361,7 +2421,13 @@ function toggleViewAsUser(change) { function validCourseUser(form,change) { var possuname = form.elements['vuname'].value; var possuid = form.elements['vid'].value; - var possudom = form.elements['vudom'].options[form.elements['vudom'].selectedIndex].value; + var domelem = form.elements['vudom']; + var possudom = ''; + if ((domelem.tagName === 'INPUT') && ((domelem.type === 'text') || (domelem.type === 'hidden'))) { + possudom = domelem.value; + } else if (domelem.tagName === 'SELECT') { + possudom = domelem.options[domelem.selectedIndex].value; + } if ((possuname == '') && (possuid == '')) { if (change == 'off') { form.elements['LC_viewas'].value = ''; @@ -2397,6 +2463,30 @@ function validCourseUser(form,change) { return false; } +function toggleIdentifier(form) { + if ((document.getElementById('LC_vuname')) && (document.getElementById('LC_vid'))) { + var radioelem = form.elements['vuidentifier']; + if (radioelem.length > 0) { + var i; + for (i=0; i<radioelem.length; i++) { + if (radioelem[i].checked == true) { + if (radioelem[i].value == 'uname') { + document.getElementById('LC_vuname').type = 'text'; + document.getElementById('LC_vid').type = 'hidden'; + document.getElementById('LC_vid').value = ''; + } else { + document.getElementById('LC_vuname').type = 'hidden'; + document.getElementById('LC_vuname').value = ''; + document.getElementById('LC_vid').type = 'text'; + } + break; + } + } + } + } + return; +} + END }