--- loncom/interface/londocs.pm 2017/02/18 14:16:47 1.620 +++ loncom/interface/londocs.pm 2017/11/10 15:47:49 1.641 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.620 2017/02/18 14:16:47 raeburn Exp $ +# $Id: londocs.pm,v 1.641 2017/11/10 15:47:49 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}; @@ -654,11 +654,12 @@ sub group_import { } } if ($url) { - if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) { + if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) { $url = $1; my $marker = $2; my $info = $3; my ($toolid,%toolhash,%toolsettings); + my @extras = ('linktext','explanation','crslabel','crstitle'); my @toolinfo = split(/:/,$info); if ($residx) { %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum); @@ -668,28 +669,37 @@ sub group_import { } $toolid =~ s/\D//g; ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'}, + $toolhash{'linktext'},$toolhash{'explanation'}, $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo; - $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'}); - $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'}); + foreach my $item (@extras) { + $toolhash{$item} = &unescape($toolhash{$item}); + } if (ref($ltitoolsref) eq 'HASH') { my @deleted; if (ref($ltitoolsref->{$toolid}) eq 'HASH') { - if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) { - $url =~ s/exttool$/exttools/; - } $toolhash{'id'} = $toolid; - if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) { + if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') || + ($toolhash{'target'} eq 'window')) { if ($toolhash{'target'} eq 'window') { foreach my $item ('width','height') { $toolhash{$item} =~ s/^\s+//; $toolhash{$item} =~ s/\s+$//; + if ($toolhash{$item} =~ /\D/) { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } + } + } } } } elsif ($residx) { $toolhash{'target'} = $toolsettings{'target'}; if ($toolhash{'target'} eq 'window') { - $toolhash{'width'} = $toolsettings{'width'}; - $toolhash{'height'} = $toolsettings{'height'}; + foreach my $item ('width','height') { + $toolhash{$item} = $toolsettings{$item}; + } } } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') { $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'}; @@ -699,31 +709,44 @@ sub group_import { } } if ($toolhash{'target'} eq 'iframe') { - delete($toolhash{'width'}); - delete($toolhash{'height'}); - if ($residx) { - if ($toolsettings{'width'}) { - push(@deleted,'width'); + foreach my $item ('width','height','linktext','explanation') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } } - if ($toolsettings{'height'}) { - push(@deleted,'height'); + } + } elsif ($toolhash{'target'} eq 'tab') { + foreach my $item ('width','height') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } } } } if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') { - foreach my $item ('label','title') { + foreach my $item ('label','title','linktext','explanation') { + my $crsitem; + if (($item eq 'label') || ($item eq 'title')) { + $crsitem = 'crs'.$item; + } else { + $crsitem = $item; + } if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) { - $toolhash{'crs'.$item} =~ s/^\s+//; - $toolhash{'crs'.$item} =~ s/\s+$//; - if ($toolhash{'crs'.$item} eq '') { - delete($toolhash{'crs'.$item}); + $toolhash{$crsitem} =~ s/^\s+//; + $toolhash{$crsitem} =~ s/\s+$//; + if ($toolhash{$crsitem} eq '') { + delete($toolhash{$crsitem}); } } else { - delete($toolhash{'crs'.$item}); + delete($toolhash{$crsitem}); } - if (($residx) && (exists($toolsettings{'crs'.$item}))) { - unless (exists($toolhash{'crs'.$item})) { - push(@deleted,'crs'.$item); + if (($residx) && (exists($toolsettings{$crsitem}))) { + unless (exists($toolhash{$crsitem})) { + push(@deleted,$crsitem); } } } @@ -748,8 +771,8 @@ sub group_import { $donechk = 1; } if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) { - &contained_map_check($url,$folder,\%removefrommap,\%removeparam, - \%addedmaps,\%hierarchy,\%titles,$allmaps); + &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap, + \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps); $importuploaded = 1; } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) { next if ($allmaps->{$url}); @@ -789,7 +812,7 @@ $initialtext END $env{'form.output'}=$newhtml; - my $result = + my $result = &Apache::lonnet::finishuserfileupload($coursenum,$coursedom, 'output', "$filepath/$residx/$fname.html"); @@ -920,7 +943,7 @@ sub docs_change_log { '// '."\n". @@ -948,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, @@ -1147,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; @@ -1200,8 +1223,8 @@ sub update_paste_buffer { $subdir = $prefix; } my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps); - &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps, - \%hierarchy,\%titles,\%allmaps); + &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap, + \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps); if (ref($hierarchy{$url}) eq 'HASH') { my ($nested,$nestednames); &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames); @@ -1279,7 +1302,7 @@ sub print_paste_buffer { my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1]; if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) { $is_external = 1; - } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) { + } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) { $is_exttool = 1; } if ($folder =~ /^supplemental/) { @@ -1313,26 +1336,34 @@ sub print_paste_buffer { $is_uploaded_map = 1; } } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) || - ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) { + ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) { if ($cid ne $env{'request.course.id'}) { my ($srcdom,$srcnum) = split(/_/,$cid); if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) { - $othercrs = '
'.&mt('(from another course)'); + if (($is_exttool) && ($srcdom ne $coursedom)) { + $canpaste = 0; + $nopaste = &mt('Paste from another domain unavailable.'); + } else { + $othercrs = '
'.&mt('(from another course)'); + } } else { $canpaste = 0; $nopaste = &mt('Paste from another course unavailable.'); - } + } } } if ($canpaste) { push(@pasteable,$suffix); - } + } } my $buffer; - if (($is_external) || ($is_exttool)) { + if ($is_external) { $buffer = &mt('External Resource').': '. &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('. &LONCAPA::map::qtescape($url).')'; + } elsif ($is_exttool) { + $buffer = &mt('External Tool').': '. + &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}); } else { my $icon = &Apache::loncommon::icon($extension); if ($extension eq 'sequence' && @@ -1490,7 +1521,7 @@ sub supp_pasteable { ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) || ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) || ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) || - ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) { + ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) { return 1; } return; @@ -1612,7 +1643,7 @@ sub do_paste_from_buffer { return(); } - my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate, + my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate, %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult); foreach my $suffix (@topaste) { @@ -1641,7 +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)$})) { + ($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 @@ -1651,6 +1683,12 @@ sub do_paste_from_buffer { next; } } +# 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; + } $srcdom{$suffix} = $srcd; $srcnum{$suffix} = $srcn; } @@ -1659,7 +1697,6 @@ sub do_paste_from_buffer { if ($url=~/\.(page|sequence)$/) { $is_map{$suffix} = 1; } - if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) { my $oldprefix = $1; # When pasting content from Main Content to Supplemental Content and vice versa @@ -1704,6 +1741,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.', duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.', ); @@ -1757,8 +1795,9 @@ sub do_paste_from_buffer { if ($is_map{$suffix}) { # If pasting a map, check if map contains other maps my (%hierarchy,%titles); - &contained_map_check($url,$folder,\%removefrommap,\%removeparam, - \%addedmaps,\%hierarchy,\%titles,$allmaps); + &contained_map_check($url,$folder,$coursenum,$coursedom, + \%removefrommap,\%removeparam,\%addedmaps, + \%hierarchy,\%titles,$allmaps); if ($url=~ m{^/uploaded/}) { my $newurl; unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') { @@ -1811,7 +1850,7 @@ sub do_paste_from_buffer { } } } - if ($url=~ m{/(bulletinboard|smppg)$}) { + if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) { my $prefix = $1; my $fromothercrs; #need to copy the db contents to a new one, unless this is a move. @@ -1828,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') { @@ -1839,6 +1878,8 @@ sub do_paste_from_buffer { $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext; } elsif ($prefix eq 'bulletinboard') { $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext; + } elsif ($prefix eq 'ext.tool') { + $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext; } $results{$suffix} = $result; $msgerrs{$suffix} = $msg; @@ -1885,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"; @@ -2098,8 +2139,11 @@ sub dbcopy { my ($url,$result,$errtext); if (ref($dbref) eq 'HASH') { $url = $dbref->{'src'}; - if ($url =~ m{/(smppg|bulletinboard)$}) { + if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) { my $prefix = $1; + if ($prefix eq 'ext.tool') { + $prefix = 'exttool'; + } if (($dbref->{'cdom'} =~ /^$match_domain$/) && ($dbref->{'cnum'} =~ /^$match_courseid$/)) { my $db_name; @@ -2110,6 +2154,8 @@ sub dbcopy { &Apache::lonsimplepage::get_db_name($url,$marker, $dbref->{'cdom'}, $dbref->{'cnum'}); + } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) { + $db_name = 'exttool_'.$marker; } else { $db_name = 'bulletinpage_'.$marker; } @@ -2120,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); } @@ -2153,7 +2201,7 @@ sub dbcopy { $result=&Apache::lonnet::put($db_name,\%contents, $coursedom,$coursenum); if ($result eq 'ok') { - $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x; + $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x; } } if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) { @@ -2163,6 +2211,9 @@ sub dbcopy { if ($prefix eq 'smppg') { $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional simple pages in this course.'); + } elsif ($prefix eq 'exttool') { + $lockerrorsref->{$prefix} .= + ' '.&mt('This will prevent addition of more external tools to this course.'); } else { $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.'); } @@ -2292,8 +2343,8 @@ sub uniqueness_check { } sub contained_map_check { - my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles, - $allmaps) = @_; + my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps, + $hierarchy,$titles,$allmaps) = @_; my $content = &Apache::lonnet::getfile($url); unless ($content eq '-1') { my $parser = HTML::TokeParser->new(\$content); @@ -2303,7 +2354,13 @@ sub contained_map_check { if ($token->[1] eq 'resource') { next if ($token->[2]->{'type'} eq 'zombie'); my $ressrc = $token->[2]->{'src'}; - if ($folder =~ /^supplemental/) { + if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) { + my $srcdom = $1; + unless ($srcdom eq $coursedom) { + $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc; + next; + } + } elsif ($folder =~ /^supplemental/) { unless (&supp_pasteable($ressrc)) { $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc; next; @@ -2322,8 +2379,8 @@ sub contained_map_check { $addedmaps->{$ressrc} = [$url]; } } - &contained_map_check($ressrc,$folder,$removefrommap,$removeparam, - $addedmaps,$hierarchy,$titles,$allmaps); + &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap, + $removeparam,$addedmaps,$hierarchy,$titles,$allmaps); } } elsif ($token->[1] eq 'param') { if ($folder =~ /^supplemental/) { @@ -2858,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); @@ -2961,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'}); @@ -2977,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/) { @@ -2999,17 +3057,32 @@ 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 { my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype, $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref, - $canedit,$navmapref,$hiddentop)=@_; + $canedit,$hostname,$navmapref,$hiddentop)=@_; my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container); if ($allowed) { (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain, @@ -3127,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); @@ -3220,7 +3293,7 @@ sub editor { } else { return $errortxt; } - } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) { + } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) { my ($suffix,$errortxt,$locknotfreed) = &new_timebased_suffix($coursedom,$coursenum,'exttool'); if ($locknotfreed) { @@ -3340,7 +3413,7 @@ sub editor { $coursenum,$coursedom,$crstype, $pathitem,$supplementalflag,$container, \%filters,\%curr_groups,$ltitoolsref,$canedit, - $isencrypted,$navmapref); + $isencrypted,$navmapref,$hostname); $idx++; $shown++; } @@ -3367,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/) { @@ -3388,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(); @@ -3640,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) { @@ -3721,7 +3793,7 @@ 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)=@_; + $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_; my ($foldertitle,$renametitle,$oldtitle); if (&is_supplemental_title($title)) { ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title); @@ -3748,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'},'<>&"'); @@ -3817,6 +3889,8 @@ END 'ct' => 'Cut', 'rn' => 'Rename', 'cp' => 'Copy', + 'da' => 'Unset alias', + 'sa' => 'Set alias', 'ex' => 'External Resource', 'et' => 'External Tool', 'ed' => 'Edit', @@ -3838,7 +3912,7 @@ END |/aboutme$ |/navmaps$ |/bulletinboard$ - |/exttools?$ + |/ext\.tool$ |\.html$)}x) || $isexternal) { $skip_confirm = 1; @@ -3847,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=(<&'); + $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb); } } elsif (!$env{'request.role.adv'}) { my $checkencrypt; @@ -4035,7 +4125,7 @@ END my $shownsymb = &Apache::lonenc::encrypted($symb); my $shownurl = &Apache::lonenc::encrypted($url); if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) { - $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&'); + $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb); if ($env{'request.enc'} ne '') { delete($env{'request.enc'}); } @@ -4049,11 +4139,26 @@ END $url=''; } } - } elsif ($supplementalflag) { + } elsif ($supplementalflag) { if ($isexternal) { if ($url =~ /^([^#]+)#([^#]+)$/) { $url = $1; $anchor = $2; + if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) { + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; + } + $nomodal = 1; + } + } + } 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; + } + $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; + $nomodal = 1; } } } @@ -4101,7 +4206,7 @@ END } } } - + # Append randompick number, hidden, and encrypted with ":" to foldername, # so it gets transferred between levels $folderpath.=$containerarg.'&'.$foldername. @@ -4144,7 +4249,7 @@ $form_end; } } elsif ($supplementalflag && !$allowed) { my $isexttool; - if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) { + if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) { $url='/adm/wrapper'.$url; $isexttool = 1; } @@ -4162,14 +4267,14 @@ $form_end; } my ($tdalign,$tdwidth); if ($allowed) { - my $fileloc = + my $fileloc = &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url)); if ($isexternal) { - ($editlink,$extresform) = + ($editlink,$extresform) = &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem, undef,undef,undef,undef,undef,undef, undef,$disabled); - } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) { + } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) { ($editlink,$extresform) = &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem, undef,undef,undef,'tool',$coursedom, @@ -4182,13 +4287,14 @@ $form_end; if ($supplementalflag) { $suppanchor = $anchor; } - my $jscall = + my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home, $switchserver, $forceedit, undef,$symb, &escape($env{'form.folderpath'}), - $renametitle,'','',1,$suppanchor); + $renametitle,$hostname, + '','',1,$suppanchor); if ($jscall) { $editlink = ''.&mt('Edit').' '."\n"; @@ -4205,6 +4311,18 @@ $form_end; $reinit = &mt('(re-initialize course to access)'); } $line.=''.$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.=''; } elsif ($url) { @@ -4215,9 +4333,20 @@ $form_end; $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&'); } } - $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. - (($anchor ne '')?$anchor:'')), - '',600,500); + if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) { + $link = 'http://'.$hostname.$url; + } else { + $link = $url; + } + $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. + (($anchor ne '')?$anchor:'')); + if ($nomodal) { + $line.=''. + ''; + } else { + $line.=&Apache::loncommon::modal_link($link, + '',600,500); + } } else { $line.=''; } @@ -4225,15 +4354,23 @@ $form_end; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { $line.=''.$title.''; } elsif ($url) { - $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. - (($anchor ne '')?$anchor:'')), - $title,600,500); + if ($nomodal) { + $line.=''. + $title.''; + } else { + $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/)) { @@ -4368,6 +4505,8 @@ sub new_timebased_suffix { $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.'); } elsif ($type eq 'smppg') { $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.'); + } elsif ($type eq 'exttool') { + $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.'); } else { $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.'); } @@ -4376,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') { @@ -4396,6 +4535,9 @@ sub new_timebased_suffix { } elsif ($type eq 'smppg') { $locknotfreed .= &mt('This will prevent creation of additional simple pages in this course.'); + } elsif ($type eq 'exttool') { + $locknotfreed .= + &mt('This will prevent creation of additional external tools in this course.'); } else { $locknotfreed .= &mt('This will prevent creation of additional discussion boards in this course.'); @@ -4446,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(); @@ -4461,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+)$/; @@ -4498,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') { @@ -4512,6 +4666,9 @@ sub checkonthis { } else { $r->print(''.&mt('access denied').''); } + if (($updated) && ($result ne 'ok')) { + $r->print('
'.&mt('Outdated copy removed')); + } } } } @@ -4564,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')); @@ -4587,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(); @@ -4595,7 +4772,6 @@ sub verifycontent { $r->print(&endContentScreen()); } - sub devalidateversioncache { my $src=shift; &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'. @@ -5021,12 +5197,12 @@ sub handler { # # --------------------------------------------- Initialize help topics for this foreach my $topic ('Adding_Course_Doc','Main_Course_Documents', - 'Adding_External_Resource','Navigate_Content', - 'Adding_Folders','Docs_Overview', 'Load_Map', - 'Supplemental','Score_Upload_Form','Adding_Pages', - 'Importing_LON-CAPA_Resource','Importing_IMS_Course', - 'Uploading_From_Harddrive','Course_Roster','Web_Page', - 'Dropbox','Simple_Problem') { + 'Adding_External_Resource','Adding_External_Tool', + 'Navigate_Content','Adding_Folders','Docs_Overview', + 'Load_Map','Supplemental','Score_Upload_Form', + 'Adding_Pages','Importing_LON-CAPA_Resource', + 'Importing_IMS_Course','Uploading_From_Harddrive', + 'Course_Roster','Web_Page','Dropbox','Simple_Problem') { $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic); } # Composite help files @@ -5058,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); @@ -5140,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 @@ -5162,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 = {}; @@ -5348,8 +5592,9 @@ sub handler { my $tabidstr = join("','",@tabids); %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom); my $posslti = keys(%ltitools); + my $hostname = $r->hostname(); $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, - $londocroot,$canedit,\$navmap). + $londocroot,$canedit,$hostname,\$navmap). &history_tab_js(). &inject_data_js(). &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid). @@ -5433,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(); } @@ -5448,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); @@ -5459,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(). @@ -5489,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', @@ -5500,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', @@ -5729,6 +5975,11 @@ CRSFORM $containertag +
+ + + $containertag +
HIDDENFORM $r->print(&makesimpleeditform($pathitem)."\n". @@ -5751,7 +6002,7 @@ HIDDENFORM } # - + my $hostname = $r->hostname(); my $savefolderpath; if ($allowed) { @@ -5949,7 +6200,7 @@ NWEBFORM $numauthor ++; } } - my ($pickdir,$showtitle);; + my ($pickdir,$showtitle); if ($numauthor) { my @order; my $defrole; @@ -6176,7 +6427,7 @@ NGFFORM ); if (keys(%ltitools)) { push(@importdoc, - {''.$lt{extt}.''=>$exttoolform}, + {''.$lt{extt}.''=>$exttoolform}, ); } unless ($container eq 'page') { @@ -6221,14 +6472,16 @@ unless ($container eq 'page') { unless (($supplementalflag || $toolsflag)) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, $supplementalflag,\%orderhash,$iconpath,$pathitem, - \%ltitools,$canedit,\$navmap,$hiddentop); + \%ltitools,$canedit,$hostname,\$navmap,$hiddentop); undef($navmap); if ($error) { $r->print('

'.$error.'

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