--- loncom/interface/londocs.pm 2017/05/10 20:32:27 1.629 +++ loncom/interface/londocs.pm 2017/08/31 20:02:35 1.639 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.629 2017/05/10 20:32:27 raeburn Exp $ +# $Id: londocs.pm,v 1.639 2017/08/31 20:02:35 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -603,9 +603,9 @@ sub recurse_html { } else { $relfile = $dependency; $depurl = $currurlpath; - $depurl =~ s{[^/]+$}{}; + $depurl =~ s{[^/]+$}{}; $depurl .= $dependency; - ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$}); + ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$}); } next if ($relfile eq ''); my $newname = $replacehash->{$container}; @@ -697,7 +697,7 @@ sub group_import { } elsif ($residx) { $toolhash{'target'} = $toolsettings{'target'}; if ($toolhash{'target'} eq 'window') { - foreach my $item ('width','height') { + foreach my $item ('width','height') { $toolhash{$item} = $toolsettings{$item}; } } @@ -812,7 +812,7 @@ $initialtext END $env{'form.output'}=$newhtml; - my $result = + my $result = &Apache::lonnet::finishuserfileupload($coursenum,$coursedom, 'output', "$filepath/$residx/$fname.html"); @@ -971,7 +971,7 @@ sub docs_change_log { if ($supplementalflag) { $tid = 2; } - my ($breadcrumbtrail) = + my ($breadcrumbtrail) = &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1); $r->print($breadcrumbtrail. &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto, @@ -1170,7 +1170,7 @@ sub update_paste_buffer { 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}; + my $mapidx = $env{'docs.markedcopy_map_'.$suffix}; if (($cid =~ /^$match_domain(?:_)$match_courseid$/) && ($url ne '')) { $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1; @@ -1672,8 +1672,8 @@ sub do_paste_from_buffer { $srcdom{$suffix} = $srcd; $srcnum{$suffix} = $srcn; } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) || - ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg|ext\.tool)$})) { - my $srctype= $1; + ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) || + ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) { my ($srcd,$srcn) = split(/_/,$cid); # When paste buffer was populated using an active role in a different course # check for mdc privilege in the course from which the resource was pasted @@ -1683,7 +1683,9 @@ sub do_paste_from_buffer { next; } } - if (($srctype eq 'ext.tool') && ($srcd ne $coursedom)) { +# When buffer was populated using an active role in a different course +# disallow pasting of External Tool if course is in a different domain. + if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) { $notindom{$suffix} = 1; next; } @@ -1865,7 +1867,7 @@ sub do_paste_from_buffer { } } unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) { - my (%lockerr,$msg); + my (%lockerr,$msg); my ($newurl,$result,$errtext) = &dbcopy(\%info,$coursedom,$coursenum,\%lockerr); if ($result eq 'ok') { @@ -1924,8 +1926,8 @@ sub do_paste_from_buffer { if ($newdocsdir eq '') { $newdocsdir = 'default'; } - if (($prefixchg{$suffix}) || - ($srcdom{$suffix} ne $coursedom) || + if (($prefixchg{$suffix}) || + ($srcdom{$suffix} ne $coursedom) || ($srcnum{$suffix} ne $coursenum) || ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) { my $newpath = "$newprefix/$newdocsdir/$newidx/$rem"; @@ -2164,6 +2166,8 @@ sub dbcopy { if (!$suffix) { if ($prefix eq 'smppg') { $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url); + } elsif ($prefix eq 'exttool') { + $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url); } else { $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url); } @@ -2911,7 +2915,7 @@ sub update_parameter { 'randomorder' => {}, ); foreach my $which (keys(%allchecked)) { - $env{'form.all'.$which} =~ s/,$//; + $env{'form.all'.$which} =~ s/,$//; if ($which eq 'randompick') { foreach my $item (split(/,/,$env{'form.all'.$which})) { my ($res,$value) = split(/:/,$item); @@ -3014,8 +3018,9 @@ sub update_parameter { sub handle_edit_cmd { my ($coursenum,$coursedom) =@_; + my $haschanges = 0; if ($env{'form.cmd'} eq '') { - return 0; + return $haschanges; } my ($cmd,$idx)=split('_',$env{'form.cmd'}); @@ -3030,19 +3035,19 @@ sub handle_edit_cmd { &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]); } splice(@LONCAPA::map::order, $idx, 1); - + $haschanges = 1; } elsif ($cmd eq 'cut') { &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]); splice(@LONCAPA::map::order, $idx, 1); - + $haschanges = 1; } elsif ($cmd eq 'up' && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) { @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1]; - + $haschanges = 1; } elsif ($cmd eq 'down' && defined($LONCAPA::map::order[$idx+1])) { @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1]; - + $haschanges = 1; } elsif ($cmd eq 'rename') { my $comment = &LONCAPA::map::qtunescape($env{'form.title'}); if ($comment=~/\S/) { @@ -3052,11 +3057,26 @@ sub handle_edit_cmd { # Devalidate title cache my $renamed_url=&LONCAPA::map::qtescape($url); &Apache::lonnet::devalidate_title_cache($renamed_url); - - } else { - return 0; + $haschanges = 1; + } elsif ($cmd eq 'setalias') { + my $newvalue = $env{'form.alias'}; + if ($newvalue ne '') { + unless (Apache::lonnet::get_symb_from_alias($newvalue)) { + &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue, + 'string'); + &remember_parms($idx,'mapalias','set',$newvalue); + $haschanges = 1; + } + } + } elsif ($cmd eq 'delalias') { + my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0]; + if ($current ne '') { + &LONCAPA::map::delparameter($idx,'parameter_0_mapalias'); + &remember_parms($idx,'mapalias','del'); + $haschanges = 1; + } } - return 1; + return $haschanges; } sub editor { @@ -3180,7 +3200,7 @@ sub editor { # Rename, cut, copy or remove a single resource if (&handle_edit_cmd($coursenum,$coursedom)) { my $contentchg; - if ($env{'form.cmd'} =~ m{^(remove|cut)_}) { + if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) { $contentchg = 1; } ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg); @@ -3420,10 +3440,10 @@ sub editor { .&Apache::loncommon::start_data_table(undef,'contentlist') .&Apache::loncommon::start_data_table_header_row() .''.&mt('Move').'' - .''.&mt('Actions').'' + .''.&mt('Actions').'' .''.&mt('Document').''; if ($folder !~ /^supplemental/) { - $to_show .= ''.&mt('Settings').''; + $to_show .= ''.&mt('Settings').''; } $to_show .= &Apache::loncommon::end_data_table_header_row(); if ($folder !~ /^supplemental/) { @@ -3441,19 +3461,18 @@ sub editor { if (@allidx > 0) { my $path; if ($env{'form.folderpath'}) { - $path = + $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); } if (@allidx > 1) { - $to_show .= + $to_show .= &Apache::loncommon::continue_data_table_row(). ' '. ''. &multiple_check_form('actions',\%lists,$canedit). ''. - ' '. - ' '. - ''. + ' '. + ''. &multiple_check_form('settings',\%lists,$canedit). ''. &Apache::loncommon::end_data_table_row(); @@ -3693,7 +3712,7 @@ sub process_file_upload { my $uploadphase = 'upload_embedded'; my $primaryurl = &HTML::Entities::encode($url,'<>&"'); my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx); - my ($embedded,$num) = + my ($embedded,$num) = &Apache::loncommon::ask_for_embedded_content( '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url}); if ($embedded) { @@ -3801,7 +3820,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); + my ($esc_path, $path, $symb, $curralias); if ($env{'form.folderpath'}) { $esc_path=&escape($env{'form.folderpath'}); $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); @@ -3870,6 +3889,8 @@ END 'ct' => 'Cut', 'rn' => 'Rename', 'cp' => 'Copy', + 'da' => 'Unset alias', + 'sa' => 'Set alias', 'ex' => 'External Resource', 'et' => 'External Tool', 'ed' => 'Edit', @@ -3900,6 +3921,9 @@ END ($url!~/$LONCAPA::assess_page_seq_re/)) { $confirm_removal = 1; } + if ($url =~ /$LONCAPA::assess_re/) { + $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0]; + } if ($denied{'copy'}) { $copylink=(<'.$editlink.$renamelink; + if ($url =~ /$LONCAPA::assess_re/) { + $line.= '
'; + if ($curralias ne '') { + $line.=''. + $lt{'da'}.''; + } else { + $line.=''. + $lt{'sa'}.''; + } + } + $line.=''; my $link; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { $line.=''; @@ -4326,11 +4361,16 @@ $form_end; $line.=&Apache::loncommon::modal_link($link,$title,600,500); } } elsif (($hiddenfolder) || ($hiddenres)) { - $line.=$title.' '.&mt('(Hidden)').''; + $line.=$title.' ('.&mt('Hidden').')'; } else { $line.=$title.' '.$reinit.''; } - $line.="$extresform"; + if (($allowed) && ($curralias ne '')) { + $line .= '
('.$curralias.')'; + } else { + $line .= $extresform; + } + $line .= ''; $rand_pick_text = ' ' if ($rand_pick_text eq ''); $rand_order_text = ' ' if ($rand_order_text eq ''); if (($allowed) && ($folder!~/^supplemental/)) { @@ -4475,7 +4515,7 @@ sub new_timebased_suffix { } } if ($freedlock ne 'ok') { - $locknotfreed = + $locknotfreed = '
'. &mt('There was a problem removing a lockfile.').' '; if ($type eq 'paste') { @@ -4548,7 +4588,7 @@ sub untiehash { sub checkonthis { - my ($r,$url,$level,$title)=@_; + my ($r,$url,$level,$title,$checkstale)=@_; $url=&unescape($url); $alreadyseen{$url}=1; $r->rflush(); @@ -4563,10 +4603,22 @@ sub checkonthis { $r->print(''. ($title?$title:$url).' '); if ($url=~/^\/res\//) { + my $updated; + if (($checkstale) && ($url !~ m{^/res/lib/templates/}) && + ($url !~ /\.\d+\.\w+$/)) { + $updated = &Apache::lonnet::remove_stale_resfile($url); + } my $result=&Apache::lonnet::repcopy( &Apache::lonnet::filelocation('',$url)); if ($result eq 'ok') { $r->print(''.&mt('ok').''); + if ($updated) { + $r->print('
'); + for (my $i=0;$i<=$level*5;$i++) { + $r->print(' '); + } + $r->print('- '.&mt('Outdated copy removed')); + } $r->rflush(); &Apache::lonnet::countacc($url); $url=~/\.(\w+)$/; @@ -4600,7 +4652,7 @@ sub checkonthis { &Apache::lonnet::metadata($url,'dependencies'); foreach my $dep (split(/\,/,$dependencies)) { if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) { - &checkonthis($r,$dep,$level+1); + &checkonthis($r,$dep,$level+1,'',$checkstale); } } } elsif ($result eq 'unavailable') { @@ -4614,6 +4666,9 @@ sub checkonthis { } else { $r->print(''.&mt('access denied').''); } + if (($updated) && ($result ne 'ok')) { + $r->print('
'.&mt('Outdated copy removed')); + } } } } @@ -4666,9 +4721,29 @@ sub list_symbs { $r->print(&endContentScreen()); } +sub contentverifyform { + my ($r) = @_; + my $crstype = &Apache::loncommon::course_type(); + $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content')); + $r->print(&startContentScreen('tools')); + $r->print('

'.&mt($crstype.' content verification').'

'); + $r->print('

'. + &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?'). + ' '. + ''.(' 'x2). + '

'. + ''. + ''. + '

'); + $r->print(&endContentScreen()); + return; +} sub verifycontent { - my ($r) = @_; + my ($r,$checkstale) = @_; my $crstype = &Apache::loncommon::course_type(); $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content')); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content')); @@ -4689,7 +4764,7 @@ sub verifycontent { } } if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) { - &checkonthis($r,$hash{$key},0,$hash{'title_'.$1}); + &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale); } } &untiehash(); @@ -4697,7 +4772,6 @@ sub verifycontent { $r->print(&endContentScreen()); } - sub devalidateversioncache { my $src=shift; &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'. @@ -5160,9 +5234,25 @@ sub handler { $disabled = ' disabled="disabled"'; } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']); + if ($env{'form.inhibitmenu'}) { + unless ($env{'form.inhibitmenu'} eq 'yes') { + delete($env{'form.inhibitmenu'}); + } + } + if ($allowed && $env{'form.verify'}) { &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content'); - &verifycontent($r); + if (!$canedit) { + &verifycontent($r); + } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) { + &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}", + text=>'Results', + faq=>273, + bug=>'Instructor Interface'}); + &verifycontent($r,$env{'form.checkstale'}); + } else { + &contentverifyform($r); + } } elsif ($allowed && $env{'form.listsymbs'}) { &init_breadcrumbs('listsymbs','List Content IDs'); &list_symbs($r); @@ -5242,6 +5332,26 @@ sub handler { 'forcesupplement','forcestandard', 'tools','symb','command','supppath']); + foreach my $item ('forcesupplement','forcestandard','tools') { + next if ($env{'form.'.$item} eq ''); + unless ($env{'form.'.$item} eq '1') { + delete($env{'form.'.$item}); + } + } + + if ($env{'form.command'}) { + unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) { + delete($env{'form.command'}); + } + } + + if ($env{'form.symb'}) { + my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'}); + unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { + delete($env{'form.symb'}); + } + } + # standard=1: this is a "new-style" course with an uploaded map as top level # standard=2: this is a "old-style" course, and there is nothing we can do @@ -5264,6 +5374,38 @@ sub handler { my $toolsflag=0; 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'}); + } + } + + 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'}); + } + } + my $script=''; my $showdoc=0; my $addentries = {}; @@ -5536,6 +5678,7 @@ sub handler { undef($hadchanges); $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom, \%allfiles,\%codebase,$context,$crstype); + undef($navmap); if ($hadchanges) { &mark_hash_old(); } @@ -5551,7 +5694,7 @@ sub handler { my ($destination,$dir_root) = &embedded_destination(); my $url_root = '/uploaded/'.$docudom.'/'.$docuname; my $actionurl = '/adm/coursedocs'; - my ($result,$flag) = + my ($result,$flag) = &Apache::loncommon::upload_embedded('coursedoc',$destination, $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state, $actionurl); @@ -5562,11 +5705,11 @@ sub handler { my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'}; my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'}; my ($destination,$dir_root) = &embedded_destination(); - my $result = + my $result = &Apache::loncommon::modify_html_refs('coursedoc',$destination, $docuname,$docudom,undef, $dir_root); - $r->print($result.&return_to_editor()); + $r->print($result.&return_to_editor()); } elsif ($env{'form.phase'} eq 'decompress_uploaded') { $uploadphase = 'decompress_phase_one'; $r->print(&decompression_phase_one(). @@ -5592,7 +5735,7 @@ sub handler { 'impo' => 'Import', 'lnks' => 'Import from Stored Links', 'impm' => 'Import from Assembled Map', - 'imcr' => 'Import from Course Resources', + 'imcr' => 'Import from Course Resources', 'extr' => 'External Resource', 'extt' => 'External Tool', 'selm' => 'Select Map', @@ -5603,7 +5746,7 @@ sub handler { 'navc' => 'Table of Contents', 'sipa' => 'Simple Course Page', 'sipr' => 'Simple Problem', - 'webp' => 'Blank Web Page (editable)', + 'webp' => 'Blank Web Page (editable)', 'stpr' => 'Standard Problem', 'news' => 'New sub-directory', 'crpr' => 'Create Problem', @@ -5832,6 +5975,11 @@ CRSFORM $containertag +
+ + + $containertag +
HIDDENFORM $r->print(&makesimpleeditform($pathitem)."\n". @@ -6052,7 +6200,7 @@ NWEBFORM $numauthor ++; } } - my ($pickdir,$showtitle);; + my ($pickdir,$showtitle); if ($numauthor) { my @order; my $defrole; @@ -6330,8 +6478,10 @@ unless ($container eq 'page') { $r->print('

'.$error.'

'); } if ($hadchanges) { - &mark_hash_old(); - } + unless (&is_hash_old()) { + &mark_hash_old(); + } + } &changewarning($r,''); } @@ -6361,7 +6511,7 @@ unless ($container eq 'page') {