--- loncom/interface/londocs.pm 2013/03/17 17:21:34 1.484.2.26 +++ loncom/interface/londocs.pm 2013/03/13 00:29:09 1.536 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.484.2.26 2013/03/17 17:21:34 raeburn Exp $ +# $Id: londocs.pm,v 1.536 2013/03/13 00:29:09 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -289,7 +289,7 @@ sub group_import { $env{'form.output'}=$newmapstr; my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom, 'output',$1.$2); - if ($result != m|^/uploaded/|) { + if ($result !~ m{^/uploaded/}) { $errtext.='Map not saved: A network error occurred when trying to save the new map. '; $fatal = 2; } @@ -300,7 +300,7 @@ sub group_import { if ($url) { if (($caller eq 'londocs') && ($folder =~ /^default/)) { - unless ($donechk) { + if (($url =~ /\.(page|sequence)$/) && (!$donechk)) { my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom); my $cid = $coursedom.'_'.$coursenum; $allmaps = @@ -325,6 +325,48 @@ sub group_import { if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; } $url = &LONCAPA::map::qtunescape($url); $name = &LONCAPA::map::qtunescape($name); + if ($name eq '') { + $name = &mt('Web Page'); + } + if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) { + my $filepath = $1; + my $fname = $name; + if ($fname =~ /^\W+$/) { + $fname = 'web'; + } else { + $fname =~ s/\W/_/g; + } + if (length($fname > 15)) { + $fname = substr($fname,0,14); + } + my $initialtext = &mt('Replace with your own content.'); + my $newhtml = < + + + +$name + + +$initialtext + + +END + $env{'form.output'}=$newhtml; + my $result = + &Apache::lonnet::finishuserfileupload($coursenum,$coursedom, + 'output', + "$filepath/$residx/$fname.html"); + if ($result =~ m{^/uploaded/}) { + $url = $result; + if ($filepath =~ /^supplemental/) { + $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'. + $env{'user.domain'}.'___&&&___'.$name; + } + } else { + return (&mt('Failed to save new web page.'),1); + } + } $LONCAPA::map::resources[$residx] = join(':', ($name, $url, $ext, 'normal', 'res')); } @@ -335,7 +377,7 @@ sub group_import { removefrommap => \%removefrommap, removeparam => \%removeparam, ); - my ($result,$msgsarray,$lockerror) = + my ($result,$msgsarray,$lockerror) = &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated); if (keys(%import_errors) > 0) { $fixuperrors = @@ -762,7 +804,7 @@ sub print_paste_buffer { $r->print('
'.$buffer); if ((!$areachange) && (!$othercourse) && ($env{'docs.markedcopy_cmd'} eq 'cut')) { - if (($is_uploaded_map) || + if (($is_uploaded_map) || ($env{'docs.markedcopy_url'} =~ /(bulletinboard|smppg)$/) || ($env{'docs.markedcopy_url'} =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) { my ($copytext,$movetext); @@ -1007,7 +1049,7 @@ sub do_paste_from_buffer { &url_paste_fixups($url,$folder,$prefixchg,$coursedom,$coursenum, $srcdom,$srcnum,$allmaps,\%rewrites, \%retitles,\%copies,\%dbcopies,\%zombies,\%params,\%mapmoves, - \%mapchanges,\%tomove,\%newsubdir,\%newurls); + \%mapchanges,\%tomove,\%newsubdir,\%newurls); } } elsif ($url=~m {^/res/}) { # published maps can only exists once, so remove it from paste buffer when done @@ -1043,9 +1085,9 @@ sub do_paste_from_buffer { $msg = &mt('Paste failed: An error occurred when copying the bulletin board.').' '.$errtext; } return ($result,undef,[$msg],$lockerr{$prefix}); - } + } if ($lockerr{$prefix}) { - $lockerrors = $lockerr{$prefix}; + $lockerrors = $lockerr{$prefix}; } } } @@ -1074,7 +1116,7 @@ sub do_paste_from_buffer { if ($newdocsdir eq '') { $newdocsdir = 'default'; } - if (($prefixchg) || + if (($prefixchg) || ($srcdom ne $coursedom) || ($srcnum ne $coursenum) || ($env{'form.docs.markedcopy_options'} ne 'move')) { my $newpath = "$newprefix/$newdocsdir/$newidx/$rem"; @@ -1152,7 +1194,7 @@ sub do_paste_from_buffer { $save_err = $errtext; } } - + if ($env{'form.docs.markedcopy_options'} eq 'move') { &Apache::lonnet::delenv('docs.markedcopy'); &Apache::lonnet::delenv('docs.markedcopy_nested'); @@ -1228,7 +1270,7 @@ sub dbcopy { if (ref($dbref) eq 'HASH') { if ($url =~ m{/(smppg|bulletinboard)$}) { my $prefix = $1; - if (($dbref->{'cdom'} =~ /^$match_domain$/) && + if (($dbref->{'cdom'} =~ /^$match_domain$/) && ($dbref->{'cnum'} =~ /^$match_courseid$/)) { my $db_name; my $marker = (split(m{/},$url))[4]; @@ -1263,12 +1305,12 @@ sub dbcopy { my $photo = $contents{'uploaded.photourl'}; my ($subdir,$fname) = ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$}); - my $newphoto; + my $newphoto; if ($fname ne '') { my $content = &Apache::lonnet::getfile($photo); unless ($content eq '-1') { $env{'form.'.$suffix.'.photourl'} = $content; - $newphoto = + $newphoto = &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname"); delete($env{'form.'.$suffix.'.photourl'}); } @@ -1285,11 +1327,11 @@ sub dbcopy { } } if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) { - $lockerrorsref->{$prefix} = + $lockerrorsref->{$prefix} = '
'. &mt('There was a problem removing a lockfile.'); if ($prefix eq 'smppg') { - $lockerrorsref->{$prefix} .= + $lockerrorsref->{$prefix} .= &mt('This will prevent creation of additional simple pages in this course.'); } else { $lockerrorsref->{$prefix} .= &mt('This will prevent creation of additional bulletin boards in this course.'); @@ -1463,7 +1505,7 @@ sub url_paste_fixups { } } } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) { - next if ($skip); + next if ($skip); my $srcdom = $1; my $srcnum = $2; if (($srcdom ne $cdom) || ($srcnum ne $cnum)) { @@ -1975,7 +2017,7 @@ sub editor { \%paste_errors); if (ref($pastemsgarray) eq 'ARRAY') { if (@{$pastemsgarray} > 0) { - + $r->print('

'. join('
',@{$pastemsgarray}). '

'); @@ -2021,7 +2063,7 @@ sub editor { my ($name,$url,$residx)= map { &unescape($_); } split(/\=/,$item); if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) { - my ($suffix,$errortxt,$locknotfreed) = + my ($suffix,$errortxt,$locknotfreed) = &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2); if ($locknotfreed) { $r->print($locknotfreed); @@ -2043,6 +2085,22 @@ sub editor { } else { return $errortxt; } + } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) { + if ($supplementalflag) { + next unless ($1 eq 'supplemental'); + if ($folder eq 'supplemental') { + next unless ($2 eq 'default'); + } else { + next unless ($folder eq 'supplemental_'.$2); + } + } else { + next unless ($1 eq 'docs'); + if ($folder eq 'default') { + next unless ($2 eq 'default'); + } else { + next unless ($folder eq 'default_'.$2); + } + } } push(@imports, [$name, $url, $residx]); } @@ -2216,15 +2274,11 @@ sub process_file_upload { $container='page'; } ($errtext,$fatal)= - &mapread($coursenum,$coursedom,$folder.'.'.$container); + &mapread($coursenum,$coursedom,$folder.'.'.$container); if ($#LONCAPA::map::order<1) { $LONCAPA::map::order[0]=1; $LONCAPA::map::resources[1]=''; } - if ($fatal) { - $$upload_output = '
'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'
'; - return; - } my $destination = 'docs/'; if ($folder =~ /^supplemental/) { $destination = 'supplemental/'; @@ -2234,6 +2288,10 @@ sub process_file_upload { } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) { $destination .= $2.'/'; } + if ($fatal) { + $$upload_output = '
'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'
'; + return; + } # this is for a course, not a user, so set context to coursedoc. my $newidx=&LONCAPA::map::getresidx(); $destination .= $newidx; @@ -2374,12 +2432,7 @@ sub entryline { my $line=&Apache::loncommon::start_data_table_row(); my ($form_start,$form_end,$form_common); # Edit commands - my ($type, $esc_path, $path, $symb); - if ($container eq 'page') { - $type = 'page'; - } else { - $type = 'folder'; - } + my ($esc_path, $path, $symb); if ($env{'form.folderpath'}) { $esc_path=&escape($env{'form.folderpath'}); $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); @@ -2547,8 +2600,8 @@ ENDREN '; $form_common=(< - + + END @@ -2556,12 +2609,12 @@ END $line.=(<
- + $lt{'up'}
- + $lt{'dw'}
@@ -2804,7 +2857,7 @@ sub new_timebased_suffix { } } if ($freedlock ne 'ok') { - $locknotfreed = + $locknotfreed = '
'. &mt('There was a problem removing a lockfile.').' '; if ($type eq 'map') { @@ -3359,6 +3412,7 @@ sub startContentScreen { if (($mode eq 'navmaps') || ($mode eq 'supplemental')) { $output .= '    '.&mt('Content Overview').'    '."\n"; $output .= '     '.&mt('Content Search').'     '."\n"; + $output .= '      '.&mt('Content Index').'      '."\n"; $output .= '
  • '.&mt('Supplemental Content').'
  • '; } else { $output .= '
  •       '.&mt('Content Editor').'      
  • '."\n"; @@ -3423,8 +3477,9 @@ sub handler { 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages'); $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files'); $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching'); - - + $help{'Course Roster'} = &Apache::loncommon::help_open_topic('Docs_Course_Roster'); + $help{'Web Page'} = &Apache::loncommon::help_open_topic('Docs_Web_Page'); + my $allowed; # URI is /adm/supplemental when viewing supplemental docs in non-edit mode. unless ($r->uri eq '/adm/supplemental') { @@ -3758,6 +3813,7 @@ sub handler { 'navc' => 'Table of Contents', 'sipa' => 'Simple Course Page', 'sipr' => 'Simple Problem', + 'webp' => 'Blank Web Page (editable)', 'drbx' => 'Drop Box', 'scuf' => 'External Scores (handgrade, upload, clicker)', 'bull' => 'Discussion Board', @@ -4010,7 +4066,6 @@ NAMFORM NASOFORM - my $newrosterform=(< @@ -4022,6 +4077,27 @@ NASOFORM NROSTFORM + my $newwebpage; + if ($folder =~ /^default_?(\d*)$/) { + $newwebpage = "/uploaded/$coursedom/$coursenum/docs/"; + if ($1) { + $newwebpage .= $1; + } else { + $newwebpage .= 'default'; + } + $newwebpage .= '/new.html'; + } + my $newwebpageform =(< + + $pathitem + + $lt{'webp'} + $help{'Web Page'} + +NWEBFORM + + my $specialdocumentsform; my @specialdocumentsforma; my $gradingform; @@ -4080,6 +4156,7 @@ NGFFORM {''.$lt{syll}.''=>$newsylform}, {''.$lt{navc}.''=>$newnavform}, {''.$lt{sipa}.''=>$newsmppageform}, + {''.$lt{webp}.''=>$newwebpageform}, ); $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma)); @@ -4217,12 +4294,34 @@ SNSFORM SNAMFORM + my $supwebpage; + if ($folder =~ /^supplemental_?(\d*)$/) { + $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/"; + if ($1) { + $supwebpage .= $1; + } else { + $supwebpage .= 'default'; + } + $supwebpage .= '/new.html'; + } + my $supwebpageform =(< + + $pathitem + + $lt{'webp'} + $help{'Web Page'} + +SWEBFORM + my @specialdocs = ( {''.$lt{syll}.'' =>$supnewsylform}, {''.$lt{mypi}.'' =>$supnewaboutmeform}, + {''.$lt{webp}.''=>$supwebpageform}, + ); my @supimportdoc = ( {''.$lt{extr}.'' @@ -4587,6 +4686,7 @@ sub editing_js { p_msb => 'Title for the Problem', p_mdb => 'Title for the Drop Box', p_mbb => 'Title for the Discussion Board', + p_mwp => 'Title for Web Page', p_mab => "Enter user:domain for User's Personal Information Page", p_mab2 => 'Personal Information Page of ', p_mab_alrt1 => 'Not a valid user:domain', @@ -4679,6 +4779,21 @@ function makesmppage() { } } +function makewebpage(type) { + var title=prompt('$lt{"p_mwp"}'); + var formname; + if (type == 'supp') { + formname = this.document.forms.supwebpage; + } else { + formname = this.document.forms.newwebpage; + } + if (title) { + var webpage = formname.importdetail.value; + formname.importdetail.value = escape(title)+'='+webpage; + formname.submit(); + } +} + function makesmpproblem() { var title=prompt('$lt{"p_msb"}'); if (title) {