version 1.487, 2012/05/15 01:41:27
|
version 1.488, 2012/06/30 23:11:11
|
Line 40 use Apache::lonxml;
|
Line 40 use Apache::lonxml;
|
use Apache::lonclonecourse; |
use Apache::lonclonecourse; |
use Apache::lonnavmaps; |
use Apache::lonnavmaps; |
use Apache::lonnavdisplay(); |
use Apache::lonnavdisplay(); |
|
use Apache::lonuserstate(); |
use HTML::Entities; |
use HTML::Entities; |
|
use HTML::TokeParser; |
use GDBM_File; |
use GDBM_File; |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Cwd; |
use Cwd; |
Line 529 sub docs_change_log {
|
Line 531 sub docs_change_log {
|
':'.$docslog{$id}{'exe_udom'}.'</tt>'. |
':'.$docslog{$id}{'exe_udom'}.'</tt>'. |
$send_msg_link.'</td><td>'. |
$send_msg_link.'</td><td>'. |
$docslog{$id}{'logentry'}{'folder'}.'</td><td>'); |
$docslog{$id}{'logentry'}{'folder'}.'</td><td>'); |
|
my $is_supp = 0; |
|
if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) { |
|
$is_supp = 1; |
|
} |
# Before |
# Before |
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) { |
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) { |
my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0]; |
my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0]; |
my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0]; |
my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0]; |
if ($oldname ne $newname) { |
if ($oldname ne $newname) { |
$r->print(&LONCAPA::map::qtescape($oldname)); |
my $shown = &LONCAPA::map::qtescape($oldname); |
|
if ($is_supp) { |
|
$shown = &Apache::loncommon::parse_supplemental_title($shown); |
|
} |
|
$r->print($shown); |
} |
} |
} |
} |
$r->print('<ul>'); |
$r->print('<ul>'); |
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) { |
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) { |
if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) { |
if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) { |
$r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>'); |
my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]); |
|
if ($is_supp) { |
|
$shown = &Apache::loncommon::parse_supplemental_title($shown); |
|
} |
|
$r->print('<li>'.$shown.'</li>'); |
} |
} |
} |
} |
$r->print('</ul>'); |
$r->print('</ul>'); |
Line 551 sub docs_change_log {
|
Line 565 sub docs_change_log {
|
my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0]; |
my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0]; |
my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0]; |
my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0]; |
if ($oldname ne '' && $oldname ne $newname) { |
if ($oldname ne '' && $oldname ne $newname) { |
$r->print(&LONCAPA::map::qtescape($newname)); |
my $shown = &LONCAPA::map::qtescape($newname); |
|
if ($is_supp) { |
|
$shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname)); |
|
} |
|
$r->print($shown); |
} |
} |
} |
} |
$r->print('<ul>'); |
$r->print('<ul>'); |
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) { |
for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) { |
if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) { |
if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) { |
$r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>'); |
my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]); |
|
if ($is_supp) { |
|
$shown = &Apache::loncommon::parse_supplemental_title($shown); |
|
} |
|
$r->print('<li>'.$shown.'</li>'); |
} |
} |
} |
} |
$r->print('</ul>'); |
$r->print('</ul>'); |
Line 602 sub update_paste_buffer {
|
Line 624 sub update_paste_buffer {
|
my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]); |
my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]); |
if (&is_supplemental_title($title)) { |
if (&is_supplemental_title($title)) { |
&Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title}); |
&Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title}); |
($title) = &parse_supplemental_title($title); |
($title) = &Apache::loncommon::parse_supplemental_title($title); |
} elsif ($env{'docs.markedcopy_supplemental'}) { |
} elsif ($env{'docs.markedcopy_supplemental'}) { |
&Apache::lonnet::delenv('docs.markedcopy_supplemental'); |
&Apache::lonnet::delenv('docs.markedcopy_supplemental'); |
} |
} |
Line 614 sub update_paste_buffer {
|
Line 636 sub update_paste_buffer {
|
} |
} |
|
|
sub print_paste_buffer { |
sub print_paste_buffer { |
my ($r,$container) = @_; |
my ($r,$container,$folder) = @_; |
return if (!defined($env{'docs.markedcopy_url'})); |
return if (!defined($env{'docs.markedcopy_url'})); |
|
|
|
my $is_external; |
|
my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1]; |
|
if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) { |
|
$is_external = 1; |
|
} |
|
|
|
my $canpaste; |
|
if ($folder =~ /^supplemental/) { |
|
$canpaste = &supp_pasteable($env{'docs.markedcopy_url'}); |
|
} else { |
|
$canpaste = 1; |
|
} |
|
|
|
my $pasteinfo; |
|
if ($canpaste) { |
|
$pasteinfo = '<form name="pasteform" action="/adm/coursedocs" method="post">' |
|
.'<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> '; |
|
} else { |
|
$pasteinfo = &mt('Paste buffer contains:').' '; |
|
} |
|
|
$r->print('<fieldset>' |
$r->print('<fieldset>' |
.'<legend>'.&mt('Clipboard').'</legend>' |
.'<legend>'.&mt('Clipboard').'</legend>' |
.'<form name="pasteform" action="/adm/coursedocs" method="post">' |
.$pasteinfo |
.'<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> ' |
); |
); |
|
|
|
my $type; |
my $type; |
if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) { |
if ($is_external) { |
$type = &mt('External Resource'); |
$type = &mt('External Resource'); |
$r->print($type.': '. |
$r->print($type.': '. |
&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('. |
&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('. |
&LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')'); |
&LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')'); |
} else { |
} else { |
my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1]; |
|
my $icon = &Apache::loncommon::icon($extension); |
my $icon = &Apache::loncommon::icon($extension); |
if ($extension eq 'sequence' && |
if ($extension eq 'sequence' && |
$env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) { |
$env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) { |
Line 638 sub print_paste_buffer {
|
Line 679 sub print_paste_buffer {
|
$icon .= '/navmap.folder.closed.gif'; |
$icon .= '/navmap.folder.closed.gif'; |
} |
} |
$icon = '<img src="'.$icon.'" alt="" class="LC_icon" />'; |
$icon = '<img src="'.$icon.'" alt="" class="LC_icon" />'; |
$r->print($icon.$type.': '. &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}))); |
$r->print($icon.$type.': '. &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}))); |
} |
} |
if ($container eq 'page') { |
if ($canpaste) { |
$r->print(' |
if ($container eq 'page') { |
|
$r->print(' |
<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" /> |
<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" /> |
<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" /> |
<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" /> |
'); |
'); |
} else { |
} else { |
$r->print(' |
$r->print(' |
<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /> |
<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /> |
'); |
'); |
|
} |
|
$r->print('</form>'); |
|
} else { |
|
$r->print('<br /><p class="LC_info">'.&mt('Paste into Supplemental Content unavailable for this type of content.').'</p>'); |
} |
} |
$r->print('</form></fieldset>'); |
$r->print('</fieldset>'); |
|
} |
|
|
|
sub supp_pasteable { |
|
my ($url) = @_; |
|
if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) || |
|
(($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) || |
|
($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})) { |
|
return 1; |
|
} |
|
return; |
} |
} |
|
|
sub do_paste_from_buffer { |
sub do_paste_from_buffer { |
Line 660 sub do_paste_from_buffer {
|
Line 718 sub do_paste_from_buffer {
|
return; |
return; |
} |
} |
|
|
|
# Supplemental content may only include certain types of content |
|
if ($folder =~ /^supplemental/) { |
|
unless (&supp_pasteable($env{'docs.markedcopy_url'})) { |
|
return &mt('Paste failed: content type is not supported within Supplemental Content'); |
|
} |
|
} |
|
|
# paste resource to end of list |
# paste resource to end of list |
my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'}); |
my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'}); |
my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}); |
my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}); |
# Maps need to be copied first |
# Maps need to be copied first |
if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) { |
my ($oldurl,%removefrommap,%addedmaps,%rewrites,%copies,%dbcopies,%zombies,%params); |
$title=&mt('Copy of').' '.$title; |
if ($url=~/\.(page|sequence)$/) { |
|
# If pasting a map, check if map contains other maps |
|
&contained_map_check($url,$folder,\%removefrommap,\%addedmaps); |
|
if (keys(%addedmaps) > 0) { |
|
&reinit_role($coursedom,$coursenum,$env{"course.$env{'request.course.id'}.home"}); |
|
} |
|
my %allmaps; |
|
my $navmap = Apache::lonnavmaps::navmap->new(); |
|
if (defined($navmap)) { |
|
foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) { |
|
$allmaps{$res->src()} = 1; |
|
} |
|
} |
|
if ($url=~ m{^/uploaded/}) { |
|
$title=&mt('Copy of').' '.$title; |
|
} |
my $newid=$$.int(rand(100)).time; |
my $newid=$$.int(rand(100)).time; |
my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/); |
my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/); |
if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) { |
if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) { |
my $path = $1; |
my $path = $1; |
my $prefix = $2; |
my $prefix = $2; |
my $ancestor = $3; |
my $ancestor = $3; |
Line 676 sub do_paste_from_buffer {
|
Line 756 sub do_paste_from_buffer {
|
$ancestor = substr($ancestor,-10,10); |
$ancestor = substr($ancestor,-10,10); |
} |
} |
$oldid = $path.$prefix.$ancestor; |
$oldid = $path.$prefix.$ancestor; |
} |
my $counter = 0; |
my $counter = 0; |
my $newurl=$oldid.$newid.'.'.$ext; |
my $newurl=$oldid.$newid.'.'.$ext; |
my $is_unique = &uniqueness_check($newurl); |
my $is_unique = &uniqueness_check($newurl); |
if ($allmaps{$newurl}) { |
while (!$is_unique && $counter < 100) { |
$is_unique = 0; |
$counter ++; |
|
$newid ++; |
|
$newurl = $oldid.$newid; |
|
$is_unique = &uniqueness_check($newurl); |
|
} |
|
if (!$is_unique) { |
|
if ($url=~/\.page$/) { |
|
return &mt('Paste failed: an error occurred creating a unique URL for the composite page'); |
|
} else { |
|
return &mt('Paste failed: an error occurred creating a unique URL for the folder'); |
|
} |
} |
} |
while (!$is_unique && $allmaps{$newurl} && $counter < 100) { |
my $storefn=$newurl; |
$counter ++; |
$storefn=~s{^/\w+/$match_domain/$match_username/}{}; |
$newid ++; |
my $paste_map_result = |
$newurl = $oldid.$newid; |
&Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn, |
$is_unique = &uniqueness_check($newurl); |
&Apache::lonnet::getfile($url)); |
} |
if ($paste_map_result eq '/adm/notfound.html') { |
if ($is_unique) { |
if ($url=~/\.page$/) { |
if ($path =~ m{^/uploaded/($match_domain)/($match_courseid)/$}) { |
return &mt('Paste failed: an error occurred saving the composite page'); |
my $srcdom = $1; |
|
my $srcnum = $2; |
|
if (($srcdom ne $coursedom) && ($srcnum ne $coursenum)) { |
|
if (&Apache::lonnet::allowed('mdc',$srcdom.'_'.$srcnum)) { |
|
&url_paste_fixups($oldid,$ext,$coursedom,$coursenum, |
|
\%allmaps, \%rewrites,\%copies,\%dbcopies,\%zombies,\%params); |
|
} else { |
|
return &mt('Paste failed: Item is from a different course which you do not have rights to edit'); |
|
} |
|
} |
|
} |
} else { |
} else { |
return &mt('Paste failed: an error occurred saving the folder'); |
if ($url=~/\.page$/) { |
|
return &mt('Paste failed: an error occurred creating a unique URL for the composite page'); |
|
} else { |
|
return &mt('Paste failed: an error occurred creating a unique URL for the folder'); |
|
} |
} |
} |
} |
my $storefn=$newurl; |
$url = $newurl; |
$storefn=~s{^/\w+/$match_domain/$match_username/}{}; |
} |
my $paste_map_result = |
|
&Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn, |
|
&Apache::lonnet::getfile($url)); |
|
if ($paste_map_result eq '/adm/notfound.html') { |
|
if ($url=~/\.page$/) { |
|
return &mt('Paste failed: an error occurred saving the composite page'); |
|
} else { |
|
return &mt('Paste failed: an error occurred saving the folder'); |
|
} |
|
} |
|
$url = $newurl; |
|
} elsif ($url=~m {^/res/}) { |
# published maps can only exists once, so remove it from paste buffer when done |
# published maps can only exists once, so remove it from paste buffer when done |
if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) { |
&Apache::lonnet::delenv('docs.markedcopy'); |
&Apache::lonnet::delenv('docs.markedcopy'); |
if ($allmaps{$url}) { |
|
return &mt('Paste failed: only one instance of a particular published sequence or page is allowed within each course.'); |
|
} |
|
} |
} |
} |
if ($url=~ m{/smppg$}) { |
if ($url=~ m{/smppg$}) { |
my $db_name = &Apache::lonsimplepage::get_db_name($url); |
my $db_name = &Apache::lonsimplepage::get_db_name($url); |
Line 730 sub do_paste_from_buffer {
|
Line 828 sub do_paste_from_buffer {
|
$url = &LONCAPA::map::qtunescape($url); |
$url = &LONCAPA::map::qtunescape($url); |
# Now insert the URL at the bottom |
# Now insert the URL at the bottom |
my $newidx = &LONCAPA::map::getresidx($url); |
my $newidx = &LONCAPA::map::getresidx($url); |
|
my $relpath; |
|
if (($folder =~ /^supplemental/) && |
|
($url =~ m{^/uploaded/$coursedom/$coursenum/docs/(.+)})) { |
|
$relpath = $1; |
|
} elsif (($folder =~ /^default/) && |
|
($url =~ m{^/uploaded/$coursedom/$coursenum/supplemental/(.+)})) { |
|
$relpath = $1; |
|
} |
|
if ($relpath ne '') { |
|
my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$}); |
|
my ($newloc,$newsubdir) = ($folder =~ /^(default|supplemental)_?(\d*)/); |
|
my $newprefix = $newloc; |
|
if ($newloc eq 'default') { |
|
$newprefix = 'docs'; |
|
} |
|
if ($newsubdir eq '') { |
|
$newsubdir = 'default'; |
|
} |
|
my $newpath = "$newprefix/$newsubdir/$newidx/$rem"; |
|
$url = |
|
&Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath, |
|
&Apache::lonnet::getfile($url)); |
|
if ($url eq '/adm/notfound.html') { |
|
return &mt('Paste failed: an error occurred saving the file.'); |
|
} |
|
} |
|
my $noparams = 0; |
|
if ((ref($params{$oldurl}) eq 'HASH') && ($relpath ne '') && ($folder =~ /^supplemental/)) { |
|
$noparams = 1; |
|
} |
|
&apply_fixups($coursedom,$coursenum,$oldurl,$url,$noparams,\%rewrites,\%copies,\%dbcopies,\%zombies,\%params); |
if ($env{'docs.markedcopy_supplemental'}) { |
if ($env{'docs.markedcopy_supplemental'}) { |
if ($folder =~ /^supplemental/) { |
if ($folder =~ /^supplemental/) { |
$title = $env{'docs.markedcopy_supplemental'}; |
$title = $env{'docs.markedcopy_supplemental'}; |
} else { |
} else { |
(undef,undef,$title) = |
(undef,undef,$title) = |
&parse_supplemental_title($env{'docs.markedcopy_supplemental'}); |
&Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental'}); |
} |
} |
} else { |
} else { |
if ($folder=~/^supplemental/) { |
if ($folder=~/^supplemental/) { |
Line 750 sub do_paste_from_buffer {
|
Line 879 sub do_paste_from_buffer {
|
# Store the result |
# Store the result |
} |
} |
|
|
|
sub dbcopy { |
|
my ($url,$coursedom,$coursenum) = @_; |
|
if ($url=~ m{/smppg$}) { |
|
my $db_name = &Apache::lonsimplepage::get_db_name($url); |
|
if ($db_name =~ /^smppage_/) { |
|
#simple pages, need to copy the db contents to a new one. |
|
my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum); |
|
my $now = time(); |
|
$db_name =~ s{_\d*$ }{_$now}x; |
|
my $result=&Apache::lonnet::put($db_name,\%contents, |
|
$coursedom,$coursenum); |
|
$url =~ s{/(\d*)/smppg$ }{/$now/smppg}x; |
|
} |
|
} |
|
return $url; |
|
} |
|
|
sub uniqueness_check { |
sub uniqueness_check { |
my ($newurl) = @_; |
my ($newurl) = @_; |
my $unique = 1; |
my $unique = 1; |
Line 764 sub uniqueness_check {
|
Line 910 sub uniqueness_check {
|
return $unique; |
return $unique; |
} |
} |
|
|
|
sub contained_map_check { |
|
my ($url,$folder,$removefrommap,$addedmaps) = @_; |
|
my $content = &Apache::lonnet::getfile($url); |
|
unless ($content eq '-1') { |
|
my $parser = HTML::TokeParser->new(\$content); |
|
$parser->attr_encoded(1); |
|
while (my $token = $parser->get_token) { |
|
next if ($token->[0] ne 'S'); |
|
if ($token->[1] eq 'resource') { |
|
next if ($token->[2]->{'type'} eq 'zombie'); |
|
my $ressrc = $token->[2]->{'src'}; |
|
if ($folder =~ /^supplemental/) { |
|
unless (&supp_pasteable($ressrc)) { |
|
$removefrommap->{$url}{$token->[2]->{'id'}}; |
|
next; |
|
} |
|
} |
|
if ($ressrc =~ /\.(sequence|page)$/) { |
|
if (ref($addedmaps->{$ressrc}) eq 'ARRAY') { |
|
push(@{$addedmaps->{$ressrc}},$url); |
|
} else { |
|
$addedmaps->{$ressrc} = [$url]; |
|
} |
|
&contained_map_check($ressrc,$folder,$removefrommap,$addedmaps); |
|
} |
|
} elsif ($token->[1] !~ /^resource|map|link$/) { |
|
if ($folder =~ /^supplemental/) { |
|
$removefrommap->{$url}{$token->[1]}; |
|
} |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
sub reinit_role { |
|
my ($cdom,$cnum,$chome) = @_; |
|
my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum"); |
|
unless ($ferr) { |
|
&Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum); |
|
} |
|
return; |
|
} |
|
|
|
sub url_paste_fixups { |
|
my ($oldurl,$ext,$cdom,$cnum,$allmaps,$rewrites,$copies,$dbcopies,$zombies,$params) = @_; |
|
my $file = &Apache::lonnet::getfile("$oldurl.$ext"); |
|
return if ($file eq '-1'); |
|
my $parser = HTML::TokeParser->new(\$file); |
|
$parser->attr_encoded(1); |
|
while (my $token = $parser->get_token) { |
|
next if ($token->[0] ne 'S'); |
|
if ($token->[1] eq 'resource') { |
|
my $ressrc = $token->[2]->{'src'}; |
|
next if ($ressrc eq ''); |
|
next if ($token->[2]->{'type'} eq 'external'); |
|
my $id = $token->[2]->{'id'}; |
|
if ($token->[2]->{'type'} eq 'zombie') { |
|
$zombies->{$oldurl}{$ressrc} = $id; |
|
} elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)}) { |
|
my $srccdom = $1; |
|
my $srccnum = $2; |
|
my $rem = $3; |
|
if (($srccdom ne $cdom) || ($srccnum ne $cnum)) { |
|
if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) { |
|
$rewrites->{$oldurl}{$ressrc} = $id; |
|
&url_paste_fixups($ressrc,$3,$cdom,$cnum,$allmaps,$rewrites,$copies,$dbcopies,$zombies,$params); |
|
} else { |
|
$copies->{$oldurl}{$ressrc} = $id; |
|
} |
|
} |
|
} elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) { |
|
my $srccdom = $1; |
|
my $srccnum = $2; |
|
if (($srccdom ne $cdom) || ($srccnum ne $cnum)) { |
|
$rewrites->{$oldurl}{$ressrc} = $id; |
|
$dbcopies->{$oldurl}{$ressrc} = $id; |
|
} |
|
} elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) { |
|
my $srccdom = $1; |
|
my $srccnum = $2; |
|
if (($srccdom ne $cdom) || ($srccnum ne $cnum)) { |
|
$rewrites->{$oldurl}{$ressrc} = $id; |
|
$dbcopies->{$oldurl}{$ressrc} = $id; |
|
} |
|
} |
|
} elsif ($token->[1] eq 'param') { |
|
my $to = $token->[2]->{'to'}; |
|
if ($to ne '') { |
|
if (ref($params->{$oldurl}{$to}) eq 'ARRAY') { |
|
push (@{$params->{$oldurl}{$to}},$token->[2]->{'name'}); |
|
} else { |
|
@{$params->{$oldurl}{$to}} = ($token->[2]->{'name'}); |
|
} |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
sub apply_fixups { |
|
my ($cdom,$cnum,$oldurl,$url,$noparams,$rewrites,$copies,$dbcopies,$zombies,$params) = @_; |
|
my (%newdb,%newdoc); |
|
if (ref($dbcopies->{$oldurl}) eq 'HASH') { |
|
foreach my $item (keys(%{$dbcopies->{$oldurl}})) { |
|
$newdb{$item} = &dbcopy($item); |
|
} |
|
} |
|
if (ref($copies->{$oldurl}) eq 'HASH') { |
|
foreach my $item (keys(%{$copies->{$oldurl}})) { |
|
my $content = &Apache::lonnet::getfile($item); |
|
my $newcontent; |
|
unless ($content eq '-1') { |
|
my $mm = new File::MMagic; |
|
my $mimetype = $mm->checktype_contents($content); |
|
if ($mimetype eq 'text/html') { |
|
my (%allfiles,%codebase,$state); |
|
my ($embedded,$num,$delnum) = |
|
&Apache::loncommon::ask_for_embedded_content( |
|
'/adm/dependencies',$state,\%allfiles,\%codebase, |
|
{'error_on_invalid_names' => 1, |
|
'ignore_remote_references' => 1, |
|
'docs_url' => $oldurl}); |
|
if ($embedded) { |
|
#FIXME Need to check for dependencies and copy and update refs. |
|
} |
|
$newcontent = $content; |
|
} else { |
|
$newcontent = $content; |
|
} |
|
my $storefn=$item; |
|
$storefn=~s{^/\w+/$match_domain/$match_courseid/}{}; |
|
$newdoc{$item} = &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,$newcontent); |
|
} |
|
} |
|
} |
|
if (((ref($rewrites->{$oldurl}) eq 'HASH') || (ref($zombies->{$oldurl}) eq 'HASH')) || |
|
($noparams) || (keys(%newdb) > 0) || (keys(%newdoc) > 0)) { |
|
my $map = &Apache::lonnet::getfile($url); |
|
my $newcontent; |
|
unless ($map eq '-1') { |
|
my $parser = HTML::TokeParser->new(\$map); |
|
$parser->attr_encoded(1); |
|
while (my $token = $parser->get_token) { |
|
if ($token->[0] eq 'S') { |
|
next if ($token->[2]->{'type'} eq 'zombie'); |
|
next if (($token->[1] eq 'param') && $noparams); |
|
if ($token->[1] eq 'resource') { |
|
my $src = $token->[2]->{'src'}; |
|
my $id = $token->[2]->{'id'}; |
|
if (($rewrites->{$oldurl}{$src} eq $id) || ($newdb{$src} ne '') |
|
|| ($newdoc{$src} ne '')) { |
|
if (ref($rewrites->{$oldurl}) eq 'HASH') { |
|
if ($rewrites->{$oldurl}{$src} eq $id) { |
|
$token->[2]->{'src'} =~ s{^(/uploaded|adm|public)/$match_domain/$match_courseid/}{$1/$cdom/$cnum}; |
|
} |
|
} elsif ($newdb{$src} ne '') { |
|
$token->[2]->{'src'} = $newdb{$src}; |
|
} |
|
$newcontent .= "<$token->[1] "; |
|
foreach my $attr (@{$token->[3]}) { |
|
$newcontent .= ' '.$attr.'="'.$token->[2]->{$attr},'"' |
|
} |
|
$newcontent .= ' />'; |
|
} else { |
|
$newcontent .= $token->[4]."\n"; |
|
} |
|
} |
|
} elsif ($token->[0] eq 'E') { |
|
$newcontent .= $token->[2]."\n"; |
|
} |
|
} |
|
} |
|
my $storefn=$url; |
|
$storefn=~s{^/\w+/$match_domain/$match_courseid/}{}; |
|
my $storeres = |
|
&Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn, |
|
$newcontent); |
|
} |
|
return; |
|
} |
|
|
my %parameter_type = ( 'randompick' => 'int_pos', |
my %parameter_type = ( 'randompick' => 'int_pos', |
'hiddenresource' => 'string_yesno', |
'hiddenresource' => 'string_yesno', |
'encrypturl' => 'string_yesno', |
'encrypturl' => 'string_yesno', |
Line 1016 sub editor {
|
Line 1344 sub editor {
|
my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container"; |
my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container"; |
$r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,$jumpto, |
$r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,$jumpto, |
$readfile)); |
$readfile)); |
&print_paste_buffer($r,$container); |
&print_paste_buffer($r,$container,$folder); |
} else { |
} else { |
if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { |
if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { |
#Function Box for Supplemental Content for users with mdc priv. |
#Function Box for Supplemental Content for users with mdc priv. |
Line 1192 sub is_supplemental_title {
|
Line 1520 sub is_supplemental_title {
|
return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/); |
return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/); |
} |
} |
|
|
sub parse_supplemental_title { |
|
my ($title) = @_; |
|
|
|
my ($foldertitle,$renametitle); |
|
if ($title =~ /&&&/) { |
|
$title = &HTML::Entites::decode($title); |
|
} |
|
if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) { |
|
$renametitle=$4; |
|
my ($time,$uname,$udom) = ($1,$2,$3); |
|
$foldertitle=&Apache::lontexconvert::msgtexconverted($4); |
|
my $name = &Apache::loncommon::plainname($uname,$udom); |
|
$name = &HTML::Entities::encode($name,'"<>&\''); |
|
$renametitle = &HTML::Entities::encode($renametitle,'"<>&\''); |
|
$title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '. |
|
$name.': <br />'.$foldertitle; |
|
} |
|
if (wantarray) { |
|
return ($title,$foldertitle,$renametitle); |
|
} |
|
return $title; |
|
} |
|
|
|
# --------------------------------------------------------------- An entry line |
# --------------------------------------------------------------- An entry line |
|
|
sub entryline { |
sub entryline { |
my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_; |
my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_; |
my ($foldertitle,$pagetitle,$renametitle); |
my ($foldertitle,$pagetitle,$renametitle); |
if (&is_supplemental_title($title)) { |
if (&is_supplemental_title($title)) { |
($title,$foldertitle,$renametitle) = &parse_supplemental_title($title); |
($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title); |
$pagetitle = $foldertitle; |
$pagetitle = $foldertitle; |
} else { |
} else { |
$title=&HTML::Entities::encode($title,'"<>&\''); |
$title=&HTML::Entities::encode($title,'"<>&\''); |
Line 2878 NGFFORM
|
Line 3183 NGFFORM
|
$communityform = &create_form_ul(&create_list_elements(@communityforma)); |
$communityform = &create_form_ul(&create_list_elements(@communityforma)); |
|
|
my %orderhash = ( |
my %orderhash = ( |
'aa' => ['Import Documents',$fileuploadform], |
'aa' => ['Import Content',$fileuploadform], |
'bb' => ['Published Resources',$simpleeditdefaultform], |
'bb' => ['Published Content',$simpleeditdefaultform], |
'cc' => ['Grading Resources',$gradingform], |
'cc' => ['Grading Resources',$gradingform], |
); |
); |
unless ($env{'form.pagepath'}) { |
unless ($env{'form.pagepath'}) { |
Line 2998 my @supimportdoc = (
|
Line 3303 my @supimportdoc = (
|
$supupdocform = &create_form_ul(&create_list_elements(@supimportdoc)) . '<hr id="ee_hrule" style="width:0px;text-align:left;margin-left:0" />' . $supupdocform; |
$supupdocform = &create_form_ul(&create_list_elements(@supimportdoc)) . '<hr id="ee_hrule" style="width:0px;text-align:left;margin-left:0" />' . $supupdocform; |
my %suporderhash = ( |
my %suporderhash = ( |
'00' => ['Supnewfolder', $supnewfolderform], |
'00' => ['Supnewfolder', $supnewfolderform], |
'ee' => ['Import Documents',$supupdocform], |
'ee' => ['Import Content',$supupdocform], |
'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))] |
'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))] |
); |
); |
if ($supplementalflag) { |
if ($supplementalflag) { |
Line 3283 sub generate_edit_table {
|
Line 3588 sub generate_edit_table {
|
my $backicon = $iconpath.'clickhere.gif'; |
my $backicon = $iconpath.'clickhere.gif'; |
my $backtext = &mt('To Overview'); |
my $backtext = &mt('To Overview'); |
$form = '<div class="LC_Box" style="margin:0;">'. |
$form = '<div class="LC_Box" style="margin:0;">'. |
'<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n". |
'<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n". |
'<li class="goback">'. |
'<li class="goback">'. |
'<a href="javascript:toContents('."'$jumpto'".');">'. |
'<a href="javascript:toContents('."'$jumpto'".');">'. |
'<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'. |
'<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'. |
' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n"; |
' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n". |
if ($tid == 1) { |
'<li>'. |
$form .= '<li>'. |
'<a href="javascript:groupopen('."'$readfile'".',1);">'. |
'<a href="javascript:groupopen('."'$readfile'".',1);">'. |
&mt('Undo Delete').'</a></li>'."\n"; |
&mt('Undo Delete').'</a></li>'."\n"; |
if ($env{'form.docslog'}) { |
if ($env{'form.docslog'}) { |
$form .= '<li class="active">'; |
$form .= '<li class="active">'; |
} else { |
} else { |
$form .= '<li>'; |
$form .= '<li>'; |
} |
} |
$form .= '<a href="javascript:toggleHistoryDisp(1);">'. |
$form .= '<a href="javascript:toggleHistoryDisp(1);">'. |
&mt('History').'</a></li>'."\n"; |
&mt('History').'</a></li>'."\n"; |
if ($env{'form.docslog'}) { |
if ($env{'form.docslog'}) { |
$form .= '<li><a href="javascript:toggleHistoryDisp(0);">'. |
$form .= '<li><a href="javascript:toggleHistoryDisp(0);">'. |
&mt('Edit').'</a></li>'."\n"; |
&mt('Edit').'</a></li>'."\n"; |
|
} |
|
} |
} |
foreach my $name (reverse(sort(keys(%orderhash)))) { |
foreach my $name (reverse(sort(keys(%orderhash)))) { |
if($name ne '00'){ |
if($name ne '00'){ |
Line 3889 Return hash with valid author names
|
Line 4192 Return hash with valid author names
|
|
|
=item is_supplemental_title() |
=item is_supplemental_title() |
|
|
=item parse_supplemental_title() |
|
|
|
=item entryline() |
=item entryline() |
|
|
=item tiehash() |
=item tiehash() |