--- loncom/interface/londocs.pm 2018/04/14 02:29:44 1.653 +++ loncom/interface/londocs.pm 2019/08/16 14:21:43 1.664 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.653 2018/04/14 02:29:44 raeburn Exp $ +# $Id: londocs.pm,v 1.664 2019/08/16 14:21:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1790,7 +1790,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.', ); @@ -1819,14 +1819,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) { @@ -1844,6 +1837,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); @@ -1909,7 +1909,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; } } @@ -2005,7 +2005,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'; @@ -2558,7 +2558,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; @@ -2803,9 +2803,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'}; @@ -2815,15 +2813,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); } @@ -4171,7 +4172,9 @@ 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()) { + $url .= '?usehttp=1'; + } $nomodal = 1; } } @@ -4181,9 +4184,8 @@ END if ($url =~ /^([^#]+)#([^#]+)$/) { $url = $1; $anchor = $2; - if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) { - $shownsymb = $1.&escape('#').$anchor; - } + my $escan = &escape('#'); + $shownsymb =~ s/^([^\#]+)#([^\#]+)$/$1$escan$2/; } } unless ($env{'request.role.adv'}) { @@ -4237,8 +4239,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()) { + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; + } + $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; } $nomodal = 1; } @@ -4246,10 +4251,12 @@ 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()) { + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; + } + $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; } - $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; $nomodal = 1; } } @@ -4430,8 +4437,7 @@ $form_end; } else { $link = $url; } - $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. - (($anchor ne '')?$anchor:'')); + $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor); if ($nomodal) { $line.=''. ''; @@ -5460,6 +5466,8 @@ sub handler { $r->internal_redirect($redirect); return OK; } + } else { + $r->internal_redirect($redirect); } } } @@ -5721,7 +5729,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'); @@ -5960,8 +5968,8 @@ sub handler { my $fileupload=(< - - + + FIUP my $checkbox=(< - + $pathitem @@ -6186,7 +6194,7 @@ HIDDENFORM NNFORM my $newsmppageform=(< - + $pathitem $lt{'sipa'} @@ -6196,7 +6204,7 @@ NSPFORM my $newsmpproblemform=(< - + $pathitem $lt{'sipr'} @@ -6207,7 +6215,7 @@ NSPROBFORM my $newdropboxform=(< - + $pathitem $lt{'drbx'} @@ -6217,7 +6225,7 @@ NDBFORM my $newexuploadform=(< - + $pathitem $lt{'scuf'} @@ -6227,7 +6235,7 @@ NEXUFORM my $newbulform=(< - + $pathitem $lt{'bull'} @@ -6237,7 +6245,7 @@ NBFORM my $newaboutmeform=(< - + $pathitem @@ -6248,7 +6256,7 @@ NAMFORM my $newaboutsomeoneform=(< - + $pathitem $lt{'abou'} @@ -6257,7 +6265,7 @@ NASOFORM my $newrosterform=(< - + $pathitem @@ -6278,7 +6286,7 @@ NROSTFORM } my $newwebpageform =(< - + $pathitem $lt{'webp'} @@ -6461,7 +6469,7 @@ NWEBFORM $lt{'stpr'} - + $pickdir $lt{'news'}? @@ -6549,7 +6557,7 @@ NSYLFORM my $newgroupfileform=(< - + $pathitem @@ -6566,15 +6574,17 @@ NGFFORM ); $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma)); - - my @importdoc = ( - {''=>$extresourcesform} + my @external = ( + {''=>$extresourcesform} ); if (keys(%ltitools)) { - push(@importdoc, - {''=>$exttoolform}, - ); + push(@external, + {''=>$exttoolform}, + ); } + my $externalform = &create_form_ul(&create_list_elements(@external)); + + my @importdoc = (); unless ($container eq 'page') { push(@importdoc, {''=>$imspform} @@ -6605,12 +6615,13 @@ NGFFORM my %orderhash = ( 'aa' => ['Upload',$fileuploadform], 'bb' => ['Import',$importpubform], - 'cc' => ['Grading',$gradingform], + 'cc' => ['External',$externalform], + 'dd' => ['Grading',$gradingform], ); unless ($container eq 'page') { $orderhash{'00'} = ['Newfolder',$newfolderform]; - $orderhash{'dd'} = ['Collaboration',$communityform]; - $orderhash{'ee'} = ['Other',$specialdocumentsform]; + $orderhash{'ee'} = ['Collaboration',$communityform]; + $orderhash{'ff'} = ['Other',$specialdocumentsform]; } $hadchanges=0; @@ -6746,15 +6757,15 @@ my @specialdocs = ( {''=>$supwebpageform}, ); -my @supimportdoc = ( - {'' - =>$supextform}); + my @supexternal = ( + {'' + =>$supextform}); if (keys(%ltitools)) { - push(@supimportdoc, - {'' + push(@supexternal, + {'' =>$supexttoolform}); } - push(@supimportdoc, + my @supimportdoc = ( {'' =>$supupdocform}, ); @@ -6762,7 +6773,8 @@ my @supimportdoc = ( $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc)); my %suporderhash = ( '00' => ['Supnewfolder', $supnewfolderform], - 'ee' => ['Upload',$supupdocform], + 'dd' => ['Upload',$supupdocform], + 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))], 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))] ); if ($supplementalflag) { @@ -7266,14 +7278,21 @@ sub editing_js { if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { if (($ENV{'SERVER_PORT'} == 443) && ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { - if ($hostname ne '') { - $backtourl = 'http://'.$hostname.$backtourl; + unless (&Apache::lonnet::uses_sts()) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; } - $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; } } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) { if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) { - $backtourl = 'http://'.$hostname.$backtourl; + unless (&Apache::lonnet::uses_sts()) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; + } } } if ($anchor ne '') { @@ -7292,20 +7311,22 @@ sub editing_js { $backtourl = '/adm/navmaps'; } - my $fieldsets = "'ext','doc'"; - if ($posslti) { - $fieldsets .= ",'tool'"; - } + my $fieldsets = "'doc'"; unless ($main_container_page) { $fieldsets .=",'ims'"; } + my $extfieldsets = "'ext'"; + if ($posslti) { + $extfieldsets .= ",'tool'"; + } if ($supplementalflag) { - $fieldsets = "'suppext','suppdoc'"; + $fieldsets = "'suppdoc'"; + $extfieldsets = "'suppext'"; if ($posslti) { - $fieldsets .= ",'supptool'"; + $extfieldsets .= ",'supptool'"; } } - + my $jsmakefunctions; if ($canedit) { $jsmakefunctions = < END - close($fh); - } - if ((-e $sourcerights) && (-e "$sourcerights.meta")) { - if (!-e "$docroot/res/$coursedom") { - mkdir("$docroot/res/$coursedom",0755); - } - if (!-e "$docroot/res/$coursedom/$coursenum") { - mkdir("$docroot/res/$coursedom/$coursenum",0755); - } - if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) { - my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes')); - my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1); - } + close($fh); } } - if ($env{'form.newresourceadd'}) { - my $template = $env{'form.template'}; - my $source = $docroot.$redirect; - my $target = $redirect; - $target =~ s{^/priv/}{/res/}; - $target = $docroot.$target; - if (!-e $source) { - my $copyfrom; - if ($template) { - my %templates; - my @files = &Apache::lonhomework::get_template_list('problem'); - foreach my $poss (@files) { - if (ref($poss) eq 'ARRAY') { - if ($template eq $poss->[0]) { - $templates{$template} = 1; - last; - } - } - } - if ($templates{$template}) { - $copyfrom = $template; - } - } - unless ($copyfrom) { - $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem'; - } - &File::Copy::copy($copyfrom,$source); + if ((-e $sourcerights) && (-e "$sourcerights.meta")) { + if (!-e "$docroot/res/$coursedom") { + mkdir("$docroot/res/$coursedom",0755); } - if (!-e "$source.meta") { - my $cid = $coursedom.'_'.$coursenum; - my $now = time; - if (open(my $fh,">$source.meta")) { - my $author=$env{'environment.firstname'}.' '. - $env{'environment.middlename'}.' '. - $env{'environment.lastname'}.' '. - $env{'environment.generation'}; - $author =~ s/\s+$//; - my $title = $env{'form.newresourcetitle'}; - $title =~ s/^\s+|\s+$//g; - print $fh <dir_config('lonIncludes')); + my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1); + } + } + my $source = $docroot.$redirect; + if (!-e "$source.meta") { + my $cid = $coursedom.'_'.$coursenum; + my $now = time; + if (open(my $fh,">$source.meta")) { + my $author=$env{'environment.firstname'}.' '. + $env{'environment.middlename'}.' '. + $env{'environment.lastname'}.' '. + $env{'environment.generation'}; + $author =~ s/\s+$//; + my $title = $env{'form.newresourcetitle'}; + $title =~ s/^\s+|\s+$//g; + print $fh < $author @@ -8800,8 +8812,7 @@ END $title END - close($fh); - } + close($fh); } } } @@ -8829,7 +8840,7 @@ END } sub finishnewprob { - my ($url,$path,$subdir,$newsubdir,$filename) = @_; + my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_; unless (-d $path) { unless (mkdir($path,02770)) { return; @@ -8872,6 +8883,31 @@ sub finishnewprob { $redirect = "$url/$filename"; } } + if ((!-e $dest) && ($context ne 'upload')) { + my $template = $env{'form.template'}; + my $copyfrom; + if ($template ne '') { + my %templates; + my @files = &Apache::lonhomework::get_template_list('problem'); + foreach my $poss (@files) { + if (ref($poss) eq 'ARRAY') { + if ($template eq $poss->[0]) { + $templates{$template} = 1; + last; + } + } + } + if ($templates{$template}) { + $copyfrom = $template; + } + } + if ($filename =~ /\.problem$/) { + unless ($copyfrom) { + $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem'; + } + &File::Copy::copy($copyfrom,$dest); + } + } return $redirect; }
$pickdir $lt{'news'}? @@ -6549,7 +6557,7 @@ NSYLFORM my $newgroupfileform=(< - + $pathitem @@ -6566,15 +6574,17 @@ NGFFORM ); $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma)); - - my @importdoc = ( - {''=>$extresourcesform} + my @external = ( + {''=>$extresourcesform} ); if (keys(%ltitools)) { - push(@importdoc, - {''=>$exttoolform}, - ); + push(@external, + {''=>$exttoolform}, + ); } + my $externalform = &create_form_ul(&create_list_elements(@external)); + + my @importdoc = (); unless ($container eq 'page') { push(@importdoc, {''=>$imspform} @@ -6605,12 +6615,13 @@ NGFFORM my %orderhash = ( 'aa' => ['Upload',$fileuploadform], 'bb' => ['Import',$importpubform], - 'cc' => ['Grading',$gradingform], + 'cc' => ['External',$externalform], + 'dd' => ['Grading',$gradingform], ); unless ($container eq 'page') { $orderhash{'00'} = ['Newfolder',$newfolderform]; - $orderhash{'dd'} = ['Collaboration',$communityform]; - $orderhash{'ee'} = ['Other',$specialdocumentsform]; + $orderhash{'ee'} = ['Collaboration',$communityform]; + $orderhash{'ff'} = ['Other',$specialdocumentsform]; } $hadchanges=0; @@ -6746,15 +6757,15 @@ my @specialdocs = ( {''=>$supwebpageform}, ); -my @supimportdoc = ( - {'' - =>$supextform}); + my @supexternal = ( + {'' + =>$supextform}); if (keys(%ltitools)) { - push(@supimportdoc, - {'' + push(@supexternal, + {'' =>$supexttoolform}); } - push(@supimportdoc, + my @supimportdoc = ( {'' =>$supupdocform}, ); @@ -6762,7 +6773,8 @@ my @supimportdoc = ( $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc)); my %suporderhash = ( '00' => ['Supnewfolder', $supnewfolderform], - 'ee' => ['Upload',$supupdocform], + 'dd' => ['Upload',$supupdocform], + 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))], 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))] ); if ($supplementalflag) { @@ -7266,14 +7278,21 @@ sub editing_js { if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { if (($ENV{'SERVER_PORT'} == 443) && ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { - if ($hostname ne '') { - $backtourl = 'http://'.$hostname.$backtourl; + unless (&Apache::lonnet::uses_sts()) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; } - $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; } } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) { if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) { - $backtourl = 'http://'.$hostname.$backtourl; + unless (&Apache::lonnet::uses_sts()) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; + } } } if ($anchor ne '') { @@ -7292,20 +7311,22 @@ sub editing_js { $backtourl = '/adm/navmaps'; } - my $fieldsets = "'ext','doc'"; - if ($posslti) { - $fieldsets .= ",'tool'"; - } + my $fieldsets = "'doc'"; unless ($main_container_page) { $fieldsets .=",'ims'"; } + my $extfieldsets = "'ext'"; + if ($posslti) { + $extfieldsets .= ",'tool'"; + } if ($supplementalflag) { - $fieldsets = "'suppext','suppdoc'"; + $fieldsets = "'suppdoc'"; + $extfieldsets = "'suppext'"; if ($posslti) { - $fieldsets .= ",'supptool'"; + $extfieldsets .= ",'supptool'"; } } - + my $jsmakefunctions; if ($canedit) { $jsmakefunctions = < END - close($fh); - } - if ((-e $sourcerights) && (-e "$sourcerights.meta")) { - if (!-e "$docroot/res/$coursedom") { - mkdir("$docroot/res/$coursedom",0755); - } - if (!-e "$docroot/res/$coursedom/$coursenum") { - mkdir("$docroot/res/$coursedom/$coursenum",0755); - } - if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) { - my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes')); - my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1); - } + close($fh); } } - if ($env{'form.newresourceadd'}) { - my $template = $env{'form.template'}; - my $source = $docroot.$redirect; - my $target = $redirect; - $target =~ s{^/priv/}{/res/}; - $target = $docroot.$target; - if (!-e $source) { - my $copyfrom; - if ($template) { - my %templates; - my @files = &Apache::lonhomework::get_template_list('problem'); - foreach my $poss (@files) { - if (ref($poss) eq 'ARRAY') { - if ($template eq $poss->[0]) { - $templates{$template} = 1; - last; - } - } - } - if ($templates{$template}) { - $copyfrom = $template; - } - } - unless ($copyfrom) { - $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem'; - } - &File::Copy::copy($copyfrom,$source); + if ((-e $sourcerights) && (-e "$sourcerights.meta")) { + if (!-e "$docroot/res/$coursedom") { + mkdir("$docroot/res/$coursedom",0755); } - if (!-e "$source.meta") { - my $cid = $coursedom.'_'.$coursenum; - my $now = time; - if (open(my $fh,">$source.meta")) { - my $author=$env{'environment.firstname'}.' '. - $env{'environment.middlename'}.' '. - $env{'environment.lastname'}.' '. - $env{'environment.generation'}; - $author =~ s/\s+$//; - my $title = $env{'form.newresourcetitle'}; - $title =~ s/^\s+|\s+$//g; - print $fh <dir_config('lonIncludes')); + my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1); + } + } + my $source = $docroot.$redirect; + if (!-e "$source.meta") { + my $cid = $coursedom.'_'.$coursenum; + my $now = time; + if (open(my $fh,">$source.meta")) { + my $author=$env{'environment.firstname'}.' '. + $env{'environment.middlename'}.' '. + $env{'environment.lastname'}.' '. + $env{'environment.generation'}; + $author =~ s/\s+$//; + my $title = $env{'form.newresourcetitle'}; + $title =~ s/^\s+|\s+$//g; + print $fh < $author @@ -8800,8 +8812,7 @@ END $title END - close($fh); - } + close($fh); } } } @@ -8829,7 +8840,7 @@ END } sub finishnewprob { - my ($url,$path,$subdir,$newsubdir,$filename) = @_; + my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_; unless (-d $path) { unless (mkdir($path,02770)) { return; @@ -8872,6 +8883,31 @@ sub finishnewprob { $redirect = "$url/$filename"; } } + if ((!-e $dest) && ($context ne 'upload')) { + my $template = $env{'form.template'}; + my $copyfrom; + if ($template ne '') { + my %templates; + my @files = &Apache::lonhomework::get_template_list('problem'); + foreach my $poss (@files) { + if (ref($poss) eq 'ARRAY') { + if ($template eq $poss->[0]) { + $templates{$template} = 1; + last; + } + } + } + if ($templates{$template}) { + $copyfrom = $template; + } + } + if ($filename =~ /\.problem$/) { + unless ($copyfrom) { + $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem'; + } + &File::Copy::copy($copyfrom,$dest); + } + } return $redirect; }