--- loncom/interface/londocs.pm 2018/01/12 01:54:56 1.650 +++ loncom/interface/londocs.pm 2022/10/29 18:13:28 1.688 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.650 2018/01/12 01:54:56 raeburn Exp $ +# $Id: londocs.pm,v 1.688 2022/10/29 18:13:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,6 +46,7 @@ use Apache::lonsimplepage(); use Apache::lonhomework(); use Apache::lonpublisher(); use Apache::lonparmset(); +use Apache::loncourserespicker(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; @@ -90,7 +91,7 @@ sub storemap { if ($map =~ /^default/) { $hadchanges=1; - } else { + } elsif ($contentchg) { $suppchanges=1; } return ($errtext,0); @@ -182,6 +183,64 @@ sub default_folderpath { } } +sub validate_supppath { + my ($coursenum,$coursedom) = @_; + my $backto; + if ($env{'form.supppath'} ne '') { + my @items = split(/\&/,$env{'form.supppath'}); + my ($badpath,$got_supp,$supppath,%supphidden,%suppids); + for (my $i=0; $i<@items; $i++) { + my $odd = $i%2; + if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) { + $badpath = 1; + last; + } elsif ($odd) { + my $suffix; + my $idx = $i-1; + if ($items[$i] =~ /^([^:]*)::(|1):::$/) { + $backto .= '&'.$1; + } elsif ($items[$idx] eq 'supplemental') { + $backto .= '&'.$items[$i]; + } else { + $backto .= '&'.$items[$i]; + my $is_hidden; + unless ($got_supp) { + my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom); + if (ref($supplemental) eq 'HASH') { + if (ref($supplemental->{'hidden'}) eq 'HASH') { + %supphidden = %{$supplemental->{'hidden'}}; + } + if (ref($supplemental->{'ids'}) eq 'HASH') { + %suppids = %{$supplemental->{'ids'}}; + } + } + $got_supp = 1; + } + if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') { + my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0]; + if ($supphidden{$mapid}) { + $is_hidden = 1; + } + } + $suffix = '::'.$is_hidden.':::'; + } + $supppath .= '&'.$items[$i].$suffix; + } else { + $supppath .= '&'.$items[$i]; + $backto .= '&'.$items[$i]; + } + } + if ($badpath) { + delete($env{'form.supppath'}); + } else { + $supppath =~ s/^\&//; + $backto =~ s/^\&//; + $env{'form.supppath'} = $supppath; + } + } + return $backto; +} + sub dumpcourse { my ($r) = @_; my $crstype = &Apache::loncommon::course_type(); @@ -832,26 +891,27 @@ sub group_import { } my $ext = 'false'; if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; } - $name = &LONCAPA::map::qtunescape($name); - if ($name eq '') { - $name = &LONCAPA::map::qtunescape(&mt('Web Page')); - } if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) { my $filepath = $1; - my $fname = $name; - if ($fname =~ /^\W+$/) { + my $fname; + if ($name eq '') { + $name = &mt('Web Page'); $fname = 'web'; } else { - $fname =~ s/\W/_/g; - } - if (length($fname) > 15) { - $fname = substr($fname,0,14); + $fname = $name; + $fname=&Apache::lonnet::clean_filename($fname); + if ($fname eq '') { + $fname = 'web'; + } elsif (length($fname) > 15) { + $fname = substr($fname,0,14); + } } + my $title = &Apache::loncommon::cleanup_html($name); my $initialtext = &mt('Replace with your own content.'); my $newhtml = < -$name +$title $initialtext @@ -873,6 +933,7 @@ END return (&mt('Failed to save new web page.'),1); } } + $name = &LONCAPA::map::qtunescape($name); $url = &LONCAPA::map::qtunescape($url); $LONCAPA::map::resources[$residx] = join(':', ($name, $url, $ext, 'normal', 'res')); @@ -913,7 +974,6 @@ END &storemap($coursenum, $coursedom, $folder.'.'.$container,1); unless ($fatal) { if ($folder =~ /^supplemental/) { - &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1); my ($errtext,$fatal) = &mapread($coursenum,$coursedom, $folder.'.'.$container); } @@ -1216,13 +1276,19 @@ sub update_paste_buffer { # Construct identifiers for current contents of user's paste buffer if (@currpaste) { foreach my $suffix (@currpaste) { - my $cid = $env{'docs.markedcopy_crs_'.$suffix}; - my $url = $env{'docs.markedcopy_url_'.$suffix}; - my $mapidx = $env{'docs.markedcopy_map_'.$suffix}; - if (($cid =~ /^$match_domain(?:_)$match_courseid$/) && - ($url ne '')) { - $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1; - } + my $cid = $env{'docs.markedcopy_crs_'.$suffix}; + my $url = $env{'docs.markedcopy_url_'.$suffix}; + my $mapidx = $env{'docs.markedcopy_map_'.$suffix}; + if (($cid =~ /^$match_domain(?:_)$match_courseid$/) && + ($url ne '')) { + if ($url eq '/res/lib/templates/simpleproblem.problem') { + $pasteurls{$cid.'_'.$mapidx} = 1; + } elsif ($url =~ m{^/res/$match_domain/$match_username/}) { + $pasteurls{$url} = 1; + } else { + $pasteurls{$cid.'_'.$url} = 1; + } + } } } @@ -1231,7 +1297,7 @@ sub update_paste_buffer { my @pathitems = split(/\&/,$env{'form.folderpath'}); my @folderconf = split(/\:/,$pathitems[-1]); - my $ispage = $folderconf[4]; + my $ispage = $folderconf[5]; foreach my $item (@possibles) { my ($orderidx,$cmd) = split(/:/,$item); @@ -1244,7 +1310,13 @@ sub update_paste_buffer { $env{'form.folderpath'},\%curr_groups); next if ($denied{'copy'}); $url=~s{http(:|:)//https(:|:)//}{https$2//}; - next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx})); + if ($url eq '/res/lib/templates/simpleproblem.problem') { + next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx})); + } elsif ($url =~ m{^/res/$match_domain/$match_username/}) { + next if (exists($pasteurls{$url})); + } else { + next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url})); + } my ($suffix,$errortxt,$locknotfreed) = &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste'); if ($suffix ne '') { @@ -1441,7 +1513,7 @@ sub print_paste_buffer { } $pasteitems .= ''; if ($nopaste) { - $pasteitems .= $nopaste; + $pasteitems .= ' '.$nopaste.''; } else { if ($othercrs) { $pasteitems .= $othercrs; @@ -1789,7 +1861,7 @@ sub do_paste_from_buffer { %msgs = &Apache::lonlocal::texthash ( notinsupp => 'Paste failed: content type is not supported within Supplemental Content', notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.', - notindom => 'Paste failed: Item is an external tool from a course in a different donain.', + notindom => 'Paste failed: Item is an external tool from a course in a different domain.', duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.', ); @@ -1818,14 +1890,7 @@ sub do_paste_from_buffer { # Retrieve information about all course maps in main content area my $allmaps = {}; - if ($folder =~ /^default/) { - $allmaps = - &Apache::loncommon::allmaps_incourse($coursedom,$coursenum, - $env{"course.$env{'request.course.id'}.home"}, - $env{'request.course.id'}); - } - - my (@toclear,%mapurls,%lockerrs,%msgerrs,%results); + my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk); # Loop over the items to paste foreach my $suffix (@dopaste) { @@ -1843,6 +1908,13 @@ sub do_paste_from_buffer { if ($is_map{$suffix}) { # If pasting a map, check if map contains other maps my (%hierarchy,%titles); + if (($folder =~ /^default/) && (!$donechk)) { + $allmaps = + &Apache::loncommon::allmaps_incourse($coursedom,$coursenum, + $env{"course.$env{'request.course.id'}.home"}, + $env{'request.course.id'}); + $donechk = 1; + } &contained_map_check($url,$folder,$coursenum,$coursedom, \%removefrommap,\%removeparam,\%addedmaps, \%hierarchy,\%titles,$allmaps); @@ -1908,7 +1980,7 @@ sub do_paste_from_buffer { cnum => $coursenum, ); if ($prefix eq 'ext.tool') { - if ($prefixchg{$suffix} eq 'docstosupp') { + if ($prefixchg{$suffix} eq 'docstosupp') { $info{'delgradable'} = 1; } } @@ -2004,7 +2076,7 @@ sub do_paste_from_buffer { $coursedom,$coursenum,$template,$newidx,"$folder.$container"); } } elsif ($url =~ /ext\.tool$/) { - if (($newidx) && ($folder=~/^default/)) { + if (($newidx) && ($folder=~/^default/)) { my $marker = (split(m{/},$url))[4]; my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum); my $val = 'no'; @@ -2328,7 +2400,9 @@ sub copy_templated_files { my @simpleprobqtypes = qw(radio option string essay numerical); my $qtype=$srcparms{$srcprefix.'questiontype'}; if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) { - my %newdata; + my %newdata = ( + $newprefix.'questiontype' => $qtype, + ); foreach my $type (@simpleprobqtypes) { if ($type eq $qtype) { $newdata{"$weightprefix.$type.weight"}=1; @@ -2557,7 +2631,7 @@ sub url_paste_fixups { my $rem = $3; my ($is_exttool,$exttoolchg); if ($rem =~ m{\d+/ext\.tool$}) { - $is_exttool = 1; + $is_exttool = 1; } if (($srcdom ne $cdom) || ($srcnum ne $cnum)) { $rewrites->{$oldurl}{$id} = $ressrc; @@ -2744,6 +2818,15 @@ sub apply_fixups { $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/; } my $mapcontent = &Apache::lonnet::getfile($key); + if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') && + ($after{'map'} eq 'default') && + ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) { + $mapcontent = ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''; + } if ($mapcontent eq '-1') { if (ref($errors) eq 'HASH') { $errors->{$key} = 1; @@ -2802,9 +2885,7 @@ sub apply_fixups { } } if (ref($resdatacopy{$key}) eq 'HASH') { - if ($newsubdir{$key}) { - - } + my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer); foreach my $idx (keys(%{$resdatacopy{$key}})) { if (ref($resdatacopy{$key}{$idx}) eq 'HASH') { my $srcurl = $resdatacopy{$key}{$idx}{'src'}; @@ -2814,15 +2895,18 @@ sub apply_fixups { ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) { my $srcdom = $resdatacopy{$key}{$idx}{'cdom'}; my $srcnum = $resdatacopy{$key}{$idx}{'cnum'}; - my ($newmapname) = ($key =~ m{/([^/]+)$}); - my ($srcfolder,$srccontainer) = split(/\./,$newmapname); + unless ($gotnewmapname) { + ($newmapname) = ($key =~ m{/([^/]+)$}); + ($srcfolder,$srccontainer) = split(/\./,$newmapname); + if ($newsubdir{$key}) { + $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/; + } + $gotnewmapname = 1; + } my $srcmapinfo = $srcfolder.':'.$idx; if ($srccontainer eq 'page') { $srcmapinfo .= ':1'; } - if ($newsubdir{$key}) { - $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/; - } ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom, $cnum,$template,$idx,$newmapname); } @@ -3477,6 +3561,21 @@ sub editor { $r->print(''); } + if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) { + my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom); + if (ref($supplemental) eq 'HASH') { + if ((ref($supplemental->{'hidden'}) eq 'HASH') && + (ref($supplemental->{'ids'}) eq 'HASH')) { + if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') { + my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0]; + if ($supplemental->{'hidden'}->{$mapnum}) { + $ishidden = 1; + } + } + } + } + } + my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups); %filters = ( canremove => [], @@ -3500,11 +3599,17 @@ sub editor { push(@allmapidx,$res); } + if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) { + if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) { + $idx++; + next; + } + } $output .= &entryline($idx,$name,$url,$folder,$allowed,$res, $coursenum,$coursedom,$crstype, $pathitem,$supplementalflag,$container, \%filters,\%curr_groups,$ltitoolsref,$canedit, - $isencrypted,$navmapref,$hostname); + $isencrypted,$ishidden,$navmapref,$hostname); $idx++; $shown++; } @@ -3513,10 +3618,14 @@ sub editor { my $need_save; if ($allowed || ($supplementalflag && $folder eq 'supplemental')) { my $toolslink; - if ($allowed) { + if ($allowed || $canedit) { + my $helpitem = 'Navigation_Screen'; + if (!$allowed) { + $helpitem = 'Supplemental_Navigation'; + } $toolslink = '' .'' - .''; - if ($folder !~ /^supplemental/) { - $to_show .= ''; - } - $to_show .= &Apache::loncommon::end_data_table_header_row(); + .'' + .'' + .&Apache::loncommon::end_data_table_header_row(); if ($folder !~ /^supplemental/) { $lists{'canhide'} = join(',',@allidx); $lists{'canrandomlyorder'} = join(',',@allmapidx); @@ -3884,12 +3991,14 @@ sub is_supplemental_title { sub entryline { my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom, $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups, - $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_; - my ($foldertitle,$renametitle,$oldtitle); + $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_; + my ($foldertitle,$renametitle,$oldtitle,$encodedtitle); if (&is_supplemental_title($title)) { ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title); + $encodedtitle=$title; } else { $title=&HTML::Entities::encode($title,'"<>&\''); + $encodedtitle=$title; $renametitle=$title; $foldertitle=$title; } @@ -3911,7 +4020,7 @@ sub entryline { my $line=&Apache::loncommon::start_data_table_row(); my ($form_start,$form_end,$form_common,$form_param); # Edit commands - my ($esc_path, $path, $symb, $curralias); + my ($esc_path, $path, $symb, $shownsymb, $curralias); if ($env{'form.folderpath'}) { $esc_path=&escape($env{'form.folderpath'}); $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); @@ -4116,6 +4225,7 @@ END my $ispage; my $containerarg; my $folderurl; + my $plainurl; if ($uploaded) { if (($extension eq 'sequence') || ($extension eq 'page')) { $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/; @@ -4134,18 +4244,26 @@ END $url='/adm/supplemental?'; } } else { - &Apache::lonnet::allowuploaded('/adm/coursedoc',$url); + $plainurl = $url; } } my ($editlink,$extresform,$anchor,$hiddenres,$nomodal); my $orig_url = $url; $orig_url=~s{http(:|:)//https(:|:)//}{https$2//}; - $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/}; + if ($container eq 'page') { + $url=~s{^http(|s)(:|:)//}{/ext/}; + } else { + $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/}; + } if (!$supplementalflag && $residx && $symb) { if ((!$isfolder) && (!$ispage)) { (undef,undef,$url)=&Apache::lonnet::decode_symb($symb); - $url=&Apache::lonnet::clutter($url); + if (($url =~ m{^ext/}) && ($container eq 'page')) { + $url=&Apache::lonnet::clutter_with_no_wrapper($url); + } else { + $url=&Apache::lonnet::clutter($url); + } if ($url=~/^\/*uploaded\//) { $url=~/\.(\w+)$/; my $embstyle=&Apache::loncommon::fileembstyle($1); @@ -4159,7 +4277,7 @@ END } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) { my $wrapped = $1; my $exturl = $2; - if ($wrapped eq '') { + if (($wrapped eq '') && ($container ne 'page')) { $url='/adm/wrapper'.$url; } if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) { @@ -4170,37 +4288,16 @@ END } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") { if (($ENV{'SERVER_PORT'} == 443) && ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { - $url .= '?usehttp=1'; + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { + $url .= '?usehttp=1'; + } $nomodal = 1; } } - if (&Apache::lonnet::symbverify($symb,$url)) { - my $shownsymb = $symb; - if ($isexternal) { - if ($url =~ /^([^#]+)#([^#]+)$/) { - $url = $1; - $anchor = $2; - if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) { - $shownsymb = $1.&escape('#').$anchor; - } - } - } - unless ($env{'request.role.adv'}) { - if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { - $url = ''; - } - if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) { - $url = ''; - $hiddenres = 1; - } - } - if ($url ne '') { - $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb); - } - } elsif (!$env{'request.role.adv'}) { - my $checkencrypt; + my ($checkencrypt,$shownurl); + if (!$env{'request.role.adv'}) { if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) || - $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) { + ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) { $checkencrypt = 1; } elsif (ref($navmapref)) { unless (ref($$navmapref)) { @@ -4208,26 +4305,43 @@ END } if (ref($$navmapref)) { if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') { - $checkencrypt = 1; + $checkencrypt = 1; } } } - if ($checkencrypt) { - my $shownsymb = &Apache::lonenc::encrypted($symb); - my $shownurl = &Apache::lonenc::encrypted($url); - if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) { - $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb); - if ($env{'request.enc'} ne '') { - delete($env{'request.enc'}); - } - } else { - $url=''; - } + } + if ($checkencrypt) { + my $currenc = $env{'request.enc'}; + $env{'request.enc'} = 1; + $shownsymb = &Apache::lonenc::encrypted($symb); + $shownurl = &Apache::lonenc::encrypted($url); + if (&Apache::lonnet::symbverify($symb,$url)) { + $url = $shownurl; } else { - $url=''; + $url = ''; } - } else { - $url=''; + $env{'request.enc'} = $currenc; + } elsif (&Apache::lonnet::symbverify($symb,$url)) { + $shownsymb = $symb; + if ($isexternal) { + $url =~ s/\#[^#]+$//; + if ($container eq 'page') { + $url = &Apache::lonnet::clutter($url); + } + } + $shownurl = $url; + } + unless ($env{'request.role.adv'}) { + if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { + $url = ''; + } + if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) { + $url = ''; + $hiddenres = 1; + } + } + if ($url ne '') { + $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb); } } } elsif ($supplementalflag) { @@ -4236,8 +4350,11 @@ END $url = $1; $anchor = $2; if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) { - if ($hostname ne '') { - $url = 'http://'.$hostname.$url; + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; + } + $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; } $nomodal = 1; } @@ -4245,12 +4362,30 @@ END } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { if (($ENV{'SERVER_PORT'} == 443) && ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { - if ($hostname ne '') { - $url = 'http://'.$hostname.$url; + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; + } + $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; } - $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; $nomodal = 1; } + } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) { + my $embstyle=&Apache::loncommon::fileembstyle($extension); + unless ($embstyle eq 'ssi') { + if (($embstyle eq 'img') + || ($embstyle eq 'emb') + || ($embstyle eq 'wrp')) { + $url='/adm/wrapper'.$url; + } elsif ($url !~ /\.(sequence|page)$/) { + $url='/adm/coursedocs/showdoc'.$url; + } + } + } + unless ($allowed && $env{'request.role.adv'}) { + if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { + $hiddenres = 1; + } } } my ($rand_pick_text,$rand_order_text,$hiddenfolder); @@ -4262,6 +4397,9 @@ END if (!$allowed && $supplementalflag) { $folderpath.=$containerarg.'&'.$foldername; $url.='folderpath='.&escape($folderpath); + if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { + $hiddenfolder = 1; + } } else { my $rpicknum = (&LONCAPA::map::getparameter($orderidx, 'parameter_randompick'))[0]; @@ -4347,7 +4485,7 @@ $form_end; $url .= ($url =~ /\?/) ? '&':'?'; $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"'); if ($title) { - $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"'); + $url .= '&title='.$encodedtitle; } if ((($isexternal) || ($isexttool)) && $orderidx) { $url .= '&idx='.$orderidx; @@ -4382,7 +4520,7 @@ $form_end; &Apache::lonhtmlcommon::jump_to_editres($cfile,$home, $switchserver, $forceedit, - undef,$symb, + undef,$symb,$shownsymb, &escape($env{'form.folderpath'}), $renametitle,$hostname, '','',1,$suppanchor); @@ -4413,9 +4551,18 @@ $form_end; } } $line.=''; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { - $line.=''.$title.''; + if ($nolink) { + $line.=$title; + } else { + $line.=''.$title.''; + } + if (!$allowed && $supplementalflag && $canedit && $isfolder) { + my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png'; + my $editurl = $url; + $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&}; + $line .= ' '.''. + ''.&mt('Edit Content').''. + ''; + } + if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) { + $line.= ' ('.&mt('hidden').') '; + } } elsif ($url) { - if ($nomodal) { + if ($nolink) { + $line.=$title; + } elsif ($nomodal) { $line.=''. $title.''; } else { @@ -4464,32 +4634,42 @@ $form_end; $line .= ''; $rand_pick_text = ' ' if ($rand_pick_text eq ''); $rand_order_text = ' ' if ($rand_order_text eq ''); - if (($allowed) && ($folder!~/^supplemental/)) { - my %lt=&Apache::lonlocal::texthash( - 'hd' => 'Hidden', - 'ec' => 'URL hidden'); - my ($enctext,$hidtext); - if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) { - $enctext = ' checked="checked"'; - if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) { - push(@{$filtersref->{'encrypturl'}},$orderidx); - } + if ($uploaded && $url && !$isfolder && !$ispage) { + if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) { + &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl); } + } + if ($allowed) { + my %lt=&Apache::lonlocal::texthash( + 'hd' => 'Hidden', + 'ec' => 'URL hidden'); + my ($enctext,$hidtext,$formhidden,$formurlhidden); if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { $hidtext = ' checked="checked"'; if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) { push(@{$filtersref->{'hiddenresource'}},$orderidx); } } - my $formhidden = 'edit_hiddenresource_'.$orderidx; - my $formurlhidden = 'edit_encrypturl_'.$orderidx; - $line.=(<
$form_param $form_common $form_end +ENDPARMS + if ($folder =~/^supplemental/) { + $line.= "\n
ENDPARMS + } } $line.=&Apache::loncommon::end_data_table_row(); return $line; @@ -4812,6 +4993,48 @@ sub list_symbs { $r->print(&endContentScreen()); } +sub short_urls { + my ($r,$canedit) = @_; + my $crstype = &Apache::loncommon::course_type(); + my $formname = 'shortenurl'; + $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs')); + $r->print(&startContentScreen('tools')); + my ($navmap,$errormsg) = + &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls'); + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my (%maps,%resources,%titles); + if (!ref($navmap)) { + $r->print($errormsg. + &endContentScreen()); + return ''; + } else { + $r->print('

'.&mt('Tiny URLs for deep-linking into course').'

'."\n"); + $r->rflush(); + my $readonly; + if ($canedit) { + my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap); + if ($numnew) { + $r->print('

'.&mt('Created [quant,_1,URL]',$numnew).'

'); + } + if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) { + $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'

'); + } + } else { + $readonly = 1; + } + my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum); + $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef, + undef,undef,undef,undef,undef,\%currtiny,$readonly)); + } + $r->print(&endContentScreen()); +} + sub contentverifyform { my ($r) = @_; my $crstype = &Apache::loncommon::course_type(); @@ -4826,7 +5049,7 @@ sub contentverifyform { &mt('No').''.(' 'x2). '

'. - ''. + ''. ''. '

'); $r->print(&endContentScreen()); @@ -5182,13 +5405,17 @@ sub changewarning { if (!defined($message)) { $message='Changes will become active for your current session after [_1], or the next time you log in.'; } + my $windowname = 'loncapaclient'; + if ($env{'request.lti.login'}) { + $windowname .= 'lti'; + } $r->print("\n\n". ''."\n". -''. +''. '

'. &mt($message,' internal_redirect($redirect); return OK; } + } else { + $r->internal_redirect($redirect); } } } @@ -5419,7 +5654,7 @@ sub handler { # Get the parameters that may be needed # &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['folderpath', + ['folderpath','title', 'forcesupplement','forcestandard', 'tools','symb','command','supppath']); @@ -5466,34 +5701,13 @@ sub handler { if ($env{'form.tools'}) { $toolsflag=1; } if ($env{'form.folderpath'} ne '') { - my @items = split(/\&/,$env{'form.folderpath'}); - my $badpath; - for (my $i=0; $i<@items; $i++) { - my $odd = $i%2; - if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) { - $badpath = 1; - } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) { - $badpath = 1; - } - last if ($badpath); - } - if ($badpath) { - delete($env{'form.folderpath'}); - } + &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom); } + my $backto_supppath; if ($env{'form.supppath'} ne '') { - my @items = split(/\&/,$env{'form.supppath'}); - my $badpath; - for (my $i=0; $i<@items; $i++) { - my $odd = $i%2; - if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) { - $badpath = 1; - } - last if ($badpath); - } - if ($badpath) { - delete($env{'form.supppath'}); + if ($supplementalflag && $allowed) { + $backto_supppath = &validate_supppath($coursenum,$coursedom); } } @@ -5515,10 +5729,10 @@ sub handler { &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap); &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}.'_'.$env{'form.symb'}}); - } elsif ($env{'form.supppath'} ne '') { + } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) { $env{'form.folderpath'}=$env{'form.supppath'}; &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => - $env{'form.command'}.'_'.$env{'form.supppath'}}); + $env{'form.command'}.'_'.$backto_supppath}); } } elsif ($env{'form.command'} eq 'editdocs') { $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap); @@ -5553,6 +5767,9 @@ sub handler { } else { undef($env{'form.folderpath'}); } + if ($env{'form.folderpath'} ne '') { + &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom); + } } # If we are not allowed to make changes, all we can see are supplemental docs @@ -5567,36 +5784,89 @@ sub handler { .'&'. $env{'form.folderpath'}; } -# If allowed and user's role is not advanced check folderpath is not hidden - if (($allowed) && (!$env{'request.role.adv'}) && - ($env{'form.folderpath'} ne '') && (!$supplementalflag)) { - my $folderurl; +# If allowed and user's role is not advanced check folderpath is not hidden + my $hidden_and_empty; + if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) { + my ($folderurl,$foldername,$hiddenfolder); my @pathitems = split(/\&/,$env{'form.folderpath'}); my $folder = $pathitems[-2]; if ($folder eq '') { undef($env{'form.folderpath'}); } else { $folderurl = "uploaded/$coursedom/$coursenum/$folder"; - if ((split(/\:/,$pathitems[-1]))[4]) { + if ((split(/\:/,$pathitems[-1]))[5]) { $folderurl .= '.page'; } else { $folderurl .= '.sequence'; } - unless (ref($navmap)) { - $navmap = Apache::lonnavmaps::navmap->new(); - } - if (ref($navmap)) { - if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') { - my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1); - unless (@resources) { - undef($env{'form.folderpath'}); + if ($supplementalflag) { + ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/); + $foldername = &HTML::Entities::decode(&unescape($foldername)); + my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom); + if (ref($supplemental) eq 'HASH') { + my ($suppmap,$suppmapnum); + if ($folder eq 'supplemental') { + $suppmap = 'default'; + $suppmapnum = 0; + } elsif ($folder =~ /^supplemental_(\d+)$/) { + $suppmap = $1; + $suppmapnum = $suppmap; + } + if ($hiddenfolder) { + my $hascontent; + foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) { + if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) { + $hascontent = 1; + } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') { + foreach my $id (@{$supplemental->{'ids'}->{$key}}) { + if ($id =~ /^$suppmapnum\:/) { + $hascontent = 1; + last; + } + } + } + last if ($hascontent); + } + unless ($hascontent) { + if ($foldername ne '') { + $hidden_and_empty = $foldername; + } else { + $hidden_and_empty = $folder; + } + } } } + } else { + unless (ref($navmap)) { + $navmap = Apache::lonnavmaps::navmap->new(); + } + ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/); + $foldername = &HTML::Entities::decode(&unescape($foldername)); + if (ref($navmap)) { + if ($hiddenfolder || + (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) { + my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1); + unless (@resources) { + if ($foldername ne '') { + $hidden_and_empty = $foldername; + } else { + $hidden_and_empty = $folder; + } + } + } + } + } + if ($hidden_and_empty ne '') { + splice(@pathitems,-2); + if (@pathitems) { + $env{'form.folderpath'} = join('&',@pathitems); + } else { + undef($env{'form.folderpath'}); + } } } } - # If after all of this, we still don't have any paths, make them unless ($env{'form.folderpath'}) { if ($supplementalflag) { @@ -5671,7 +5941,7 @@ sub handler { my $tid = 1; my @tabids; if ($supplementalflag) { - @tabids = ('002','ee2','ff2'); + @tabids = ('002','dd2','ee2','ff2'); $tid = 2; } else { @tabids = ('aa1','bb1','cc1','ff1'); @@ -5690,8 +5960,14 @@ sub handler { &inject_data_js(). &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid). &Apache::lonextresedit::extedit_javascript(\%ltitools); + my $onload = "javascript:resize_scrollbox('contentscroll','1','1');"; + if ($hidden_and_empty ne '') { + my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'", + $hidden_and_empty); + $onload .= "javascript:alert('".&js_escape($alert)."');"; + } $addentries = { - onload => "javascript:resize_scrollbox('contentscroll','1','1');", + onload => $onload, }; } $script .= &paste_popup_js(); @@ -5713,8 +5989,15 @@ sub handler { &Apache::lonhtmlcommon::clear_breadcrumbs(); if ($showdoc) { - $r->print(&Apache::loncommon::start_page("$crstype documents",undef, - {'force_register' => $showdoc,})); + my $args; + if ($supplementalflag) { + my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&'); + my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); + $args = {'bread_crumbs' => $brcrum}; + } else { + $args = {'force_register' => $showdoc}; + } + $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args)); } elsif ($toolsflag) { my ($breadtext,$breadtitle); $breadtext = "$crstype Editor"; @@ -5732,6 +6015,12 @@ sub handler { $breadtitle) ); } elsif ($r->uri eq '/adm/supplemental') { + unless ($env{'request.role.adv'}) { + unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) { + $r->internal_redirect('/adm/navmaps'); + return OK; + } + } my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype); $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef, {'bread_crumbs' => $brcrum,})); @@ -5762,6 +6051,7 @@ sub handler { my %codebase = (); my ($upload_result,$upload_output,$uploadphase); if ($canedit) { + undef($suppchanges); if (($env{'form.uploaddoc.filename'}) && ($env{'form.cmd'}=~/^upload_(\w+)/)) { my $context = $1; @@ -5773,6 +6063,10 @@ sub handler { if ($hadchanges) { &mark_hash_old(); } + if ($suppchanges) { + &Apache::lonnet::update_supp_caches($coursedom,$coursenum); + undef($suppchanges); + } $r->print($upload_output); } elsif ($env{'form.phase'} eq 'upload_embedded') { # Process file upload - phase two - upload embedded objects @@ -5910,8 +6204,8 @@ sub handler { my $fileupload=(< - - + + FIUP my $checkbox=(<print(''."\n" ); @@ -6122,7 +6420,7 @@ HIDDENFORM my $newnavform=(< - + $pathitem @@ -6132,7 +6430,7 @@ HIDDENFORM NNFORM my $newsmppageform=(< - + $pathitem $lt{'sipa'} @@ -6142,7 +6440,7 @@ NSPFORM my $newsmpproblemform=(< - + $pathitem $lt{'sipr'} @@ -6153,7 +6451,7 @@ NSPROBFORM my $newdropboxform=(< - + $pathitem $lt{'drbx'} @@ -6163,7 +6461,7 @@ NDBFORM my $newexuploadform=(< - + $pathitem $lt{'scuf'} @@ -6173,7 +6471,7 @@ NEXUFORM my $newbulform=(< - + $pathitem $lt{'bull'} @@ -6183,7 +6481,7 @@ NBFORM my $newaboutmeform=(< - + $pathitem @@ -6194,7 +6492,7 @@ NAMFORM my $newaboutsomeoneform=(< - + $pathitem $lt{'abou'} @@ -6203,7 +6501,7 @@ NASOFORM my $newrosterform=(< - + $pathitem @@ -6224,7 +6522,7 @@ NROSTFORM } my $newwebpageform =(< - + $pathitem $lt{'webp'} @@ -6407,7 +6705,7 @@ NWEBFORM

' .&Apache::loncommon::help_open_menu('Navigation Screen', - 'Navigation_Screen',undef,'RAT') + $helpitem,undef,'RAT') .''.&mt('Tools:').''.&mt('Actions').''.&mt('Document').''.&mt('Settings').''.&mt('Document').''.&mt('Settings').''; - my $link; + my ($link,$nolink); if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { - $line.=''; + if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) { + if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { + $nolink = 1; + } + } + if ($nolink) { + $line .= ''; + } else { + $line.=''; + } } elsif ($url) { if ($anchor ne '') { if ($supplementalflag) { @@ -4429,9 +4576,15 @@ $form_end; } else { $link = $url; } - $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. - (($anchor ne '')?$anchor:'')); - if ($nomodal) { + $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor); + if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) { + if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { + $nolink = 1; + } + } + if ($nolink) { + $line.=''; + } elsif ($nomodal) { $line.=''. ''; } else { @@ -4443,9 +4596,26 @@ $form_end; } $line.='"; + } else { + if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) { + $enctext = ' checked="checked"'; + if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) { + push(@{$filtersref->{'encrypturl'}},$orderidx); + } + } + $formurlhidden = 'edit_encrypturl_'.$orderidx; + $line.=(< $form_param @@ -4500,6 +4680,7 @@ $form_end; $rand_pick_text
$rand_order_text