--- loncom/interface/londocs.pm 2014/01/12 23:13:50 1.484.2.49 +++ loncom/interface/londocs.pm 2014/03/09 15:49:48 1.578 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.484.2.49 2014/01/12 23:13:50 raeburn Exp $ +# $Id: londocs.pm,v 1.578 2014/03/09 15:49:48 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,6 +46,7 @@ use Apache::lonsimplepage(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; +use File::MMagic; use Apache::lonlocal; use Cwd; use LONCAPA qw(:DEFAULT :match); @@ -195,7 +196,7 @@ ENDJS } else { &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles, 'dumpdocs',$cdom,$cnum); - } + } my @todump = &Apache::loncommon::get_env_multiple('form.archive'); my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages, %newcontent,%has_simpleprobs); @@ -206,7 +207,7 @@ ENDJS if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) { $tocopy{$1} = $name; $display{$item} = $1; - $lookup{$1} = $item; + $lookup{$1} = $item; } elsif ($res eq 'lib/templates/simpleproblem.problem') { $simpleproblems{$item} = { symb => $resources{$item}, @@ -301,14 +302,14 @@ ENDJS if ($contents{content}) { $content .= '
-

Content

'. +

'.&mt('Content').'

'. $contents{content}.'
'; } if ($contents{webreferences}) { - $content .= ' + $content .= '
-

Web References

'. +

'.&mt('Web References').'

'. $contents{webreferences}.'
'; } @@ -316,10 +317,10 @@ $contents{webreferences}.' '; - $newcontent{'/'.$simplepages{$item}{res}} = $content; + $newcontent{'/'.$simplepages{$item}{res}} = $content; } } - foreach my $item (keys(%tocopy)) { + foreach my $item (keys(%tocopy)) { unless ($item=~/\.(sequence|page)$/) { my $currurlpath = $prefix.$item; my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath); @@ -350,39 +351,39 @@ $contents{webreferences}.' if ($simpleproblems{$num}) { $newfilename=$title.'/'.$simpleproblems{$num}{'name'}; } else { - $newfilename=$title.'/'.$replacehash{$item}; + $newfilename=$title.'/'.$replacehash{$item}; } - $newfilename=~s/\.(\w+)$//; - my $ext=$1; - $newfilename=&clean($newfilename); - $newfilename.='.'.$ext; - my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); + $newfilename=~s/\.(\w+)$//; + my $ext=$1; + $newfilename=&clean($newfilename); + $newfilename.='.'.$ext; + my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); if ($newrelpath ne $replacehash{$item}) { $replacehash{$item} = $newrelpath; } - my @dirs=split(/\//,$newfilename); - my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca"; - my $makepath=$path; - my $fail; + my @dirs=split(/\//,$newfilename); + my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca"; + my $makepath=$path; + my $fail; my $origin; - for (my $i=0;$i<$#dirs;$i++) { - $makepath.='/'.$dirs[$i]; - unless (-e $makepath) { - unless(mkdir($makepath,0755)) { + for (my $i=0;$i<$#dirs;$i++) { + $makepath.='/'.$dirs[$i]; + unless (-e $makepath) { + unless(mkdir($makepath,0755)) { $fail = &mt('Directory creation failed.'); } - } - } + } + } if ($i == 0) { - $result = '
'.$item.' => '.$newfilename.': '; + $result = '
'.$item.' => '.$newfilename.': '; } else { $depresult .= '
  • '.$item.' => '.$newfilename.' '. ''. &mt('(dependency)').': '; } if (-e $path.'/'.$newfilename) { - $fail = &mt('Destination already exists -- not overwriting.'); - } else { + $fail = &mt('Destination already exists -- not overwriting.'); + } else { if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) { if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) || ($item =~ /^simpleproblem_/)) { @@ -404,18 +405,18 @@ $contents{webreferences}.' while (my $token = $parser->get_token) { if ($token->[0] eq 'S') { if (($token->[1] eq 'resource') && - ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && + ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && ($changes{$token->[2]->{'id'}})) { my $id = $token->[2]->{'id'}; $updatedcontent .= '<'.$token->[1]; foreach my $attrib (@{$token->[3]}) { - next unless ($attrib =~ /^(src|type|title|id)$/); + next unless ($attrib =~ /^(src|type|title|id)$/); if ($attrib eq 'src') { - my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); + my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); if ($file) { $updatedcontent .= ' '.$attrib.'="'.$file.'"'; } else { - $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; + $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; } } else { $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; @@ -430,36 +431,36 @@ $contents{webreferences}.' } } print $fh $updatedcontent; - } else { - print $fh &Apache::lonclonecourse::rewritefile( + } else { + print $fh &Apache::lonclonecourse::rewritefile( &Apache::lonclonecourse::readfile($env{'request.course.id'},$item), - (%replacehash,$crs => '') - ); + (%replacehash,$crs => '') + ); } } else { - print $fh + print $fh &Apache::lonclonecourse::readfile($env{'request.course.id'},$item); - } + } } else { - $fail = &mt('Source does not exist.'); + $fail = &mt('Source does not exist.'); } } $fh->close(); - } else { - $fail = &mt('Could not write to destination.'); + } else { + $fail = &mt('Could not write to destination.'); } - } + } my $text; - if ($fail) { + if ($fail) { $text = ''.&mt('fail').(' 'x3).$fail.''; - } else { + } else { $text = ''.&mt('ok').''; } if ($i == 0) { $result .= $text; } else { $depresult .= $text.'
  • '; - } + } } $r->print($result); if ($depresult) { @@ -476,63 +477,63 @@ $contents{webreferences}.' $r->rflush(); my ($preamble,$formname); $formname = 'dumpdoc'; - unless ($home==1) { - $preamble = '
    '. - '
    '. + unless ($home==1) { + $preamble = '
    '. + '
    '. &mt('Select the Authoring Space'). ''; - } else { - $preamble .= ''; - } - } - unless ($home==1) { - $preamble .= '
    '."\n"; - } - my $title=$origcrsdata{'description'}; - $title=~s/[\/\s]+/\_/gs; - $title=&clean($title); - $preamble .= '
    '. + if ($home==1) { + $preamble .= ''; + } else { + $preamble .= ''; + } + } + unless ($home==1) { + $preamble .= '
    '."\n"; + } + my $title=$origcrsdata{'description'}; + $title=~s/[\/\s]+/\_/gs; + $title=&clean($title); + $preamble .= '
    '. '
    '.&mt('Folder in Authoring Space').''. ''. '
    '."\n"; my %uploadedfiles; - &tiehash(); - foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) { - my ($ext)=($file=~/\.(\w+)$/); + &tiehash(); + foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) { + my ($ext)=($file=~/\.(\w+)$/); # FIXME Check supplemental here - my $title=$hash{'title_'.$hash{ - 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}}; - if (!$title) { - $title=$file; - } else { - $title=~s|/|_|g; - } - $title=~s/\.(\w+)$//; - $title=&clean($title); - $title.='.'.$ext; -# $r->print("\n" + my $title=$hash{'title_'.$hash{ + 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}}; + if (!$title) { + $title=$file; + } else { + $title=~s|/|_|g; + } + $title=~s/\.(\w+)$//; + $title=&clean($title); + $title.='.'.$ext; +# $r->print("\n" $uploadedfiles{$file} = $title; - } - &untiehash(); + } + &untiehash(); $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef, undef,undef,$preamble,$home,\%uploadedfiles)); } @@ -563,16 +564,16 @@ 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}; $newname =~ s{[^/]+$}{}; $replacehash->{$newcontainer} = $newname.$relfile; $deps->{$item}{$newcontainer} = 1; - my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$}); + my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$}); my $depfile = &Apache::lonnet::filelocation('',$depurl); my $type = $mm->checktype_filename($depfile); if ($type eq 'text/html') { @@ -666,7 +667,7 @@ $initialtext END $env{'form.output'}=$newhtml; - my $result = + my $result = &Apache::lonnet::finishuserfileupload($coursenum,$coursedom, 'output', "$filepath/$residx/$fname.html"); @@ -691,7 +692,7 @@ END 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 = @@ -1231,10 +1232,10 @@ sub print_paste_buffer { my $value = &mt('Paste to current folder'); if ($container eq 'page') { $value = &mt('Paste to current page'); - } + } $buttons = ''.(' 'x2); } - $buttons .= ''.(' 'x2); + $buttons .= ''.(' 'x2); if ($clipboardcount > 1) { $buttons .= ''.(' 'x20).''.(' 'x2). @@ -1402,7 +1403,7 @@ function checkClipboard() { if (document.pasteform.pasting.length > 1) { for (var i=0; i{'cdom'} =~ /^$match_domain$/) && + if (($dbref->{'cdom'} =~ /^$match_domain$/) && ($dbref->{'cnum'} =~ /^$match_courseid$/)) { my $db_name; my $marker = (split(m{/},$url))[4]; @@ -1943,12 +1944,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'}); } @@ -2093,7 +2094,7 @@ sub url_paste_fixups { } next if ($token->[2]->{'type'} eq 'external'); if ($token->[2]->{'type'} eq 'zombie') { - next if ($skip); + next if ($skip); $zombies->{$oldurl}{$id} = $ressrc; $changed = 1; } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) { @@ -2539,7 +2540,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); @@ -2566,7 +2567,7 @@ sub update_parameter { foreach my $which (keys(%allchecked)) { if (($which eq 'randompick' || $which eq 'randomorder')) { next if (!$is_map); - } + } my $oldvalue = 0; my $newvalue = 0; if ($allchecked{$which}{$res}) { @@ -3025,11 +3026,11 @@ 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(). ' '. ''. @@ -3173,7 +3174,7 @@ sub process_file_upload { } my $quotatype = 'unofficial'; if ($crstype eq 'Community') { - $quotatype = 'community'; + $quotatype = 'community'; } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.instcode'}) { $quotatype = 'official'; } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) { @@ -3280,7 +3281,8 @@ sub process_file_upload { $$upload_output .= &mt('No embedded items identified').'
    '; } $$upload_output = '
    '.$$upload_output.'
    '; - } elsif (&Apache::loncommon::is_archive_file($mimetype)) { + } elsif ((&Apache::loncommon::is_archive_file($mimetype)) && + ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) { $nextphase = 'decompress_uploaded'; my $position = scalar(@LONCAPA::map::order)-1; my $noextract = &return_to_editor(); @@ -3355,7 +3357,7 @@ sub entryline { $renametitle=~s/\\/\\\\/g; $renametitle=~s/\"\;/\\\"/g; - $renametitle=~s/\'\;/\\\'/g; + $renametitle=~s/\'/\\\'/g; $renametitle=~s/ /%20/g; my $line=&Apache::loncommon::start_data_table_row(); my ($form_start,$form_end,$form_common,$form_param); @@ -3646,7 +3648,7 @@ $form_common."\n". $form_param."\n". $form_common."\n". ''. -$form_end; +$form_end; } } elsif ($supplementalflag && !$allowed) { $url .= ($url =~ /\?/) ? '&':'?'; @@ -3850,7 +3852,7 @@ sub new_timebased_suffix { } } if ($freedlock ne 'ok') { - $locknotfreed = + $locknotfreed = '
    '. &mt('There was a problem removing a lockfile.').' '; if ($type eq 'paste') { @@ -4249,7 +4251,7 @@ ENDHEADERS return; } $r->print( - ''. + ''. &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). ''.&mt('Resources').''. @@ -4292,9 +4294,9 @@ ENDHEADERS $setversions{$linkurl}, 'set_version_'.$linkurl, {'select_form_order' => ['',1..$currentversion,'mostrecent'], - '' => '', - 'mostrecent' => &mt('most recent'), - map {$_,$_} (1..$currentversion)})); + '' => '', + 'mostrecent' => &mt('most recent'), + map {$_,$_} (1..$currentversion)})); my $lastold=1; for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) { my $url=$root.'.'.$prevvers.'.'.$extension; @@ -4431,6 +4433,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('Main Content Editor').'      
  • '."\n"; @@ -4832,7 +4835,7 @@ sub handler { 'navc' => 'Table of Contents', 'sipa' => 'Simple Course Page', 'sipr' => 'Simple Problem', - 'webp' => 'Blank Web Page (editable)', + 'webp' => 'Blank Web Page (editable)', 'drbx' => 'Drop Box', 'scuf' => 'External Scores (handgrade, upload, clicker)', 'bull' => 'Discussion Board', @@ -4848,7 +4851,11 @@ sub handler { 'title' => 'Title', 'comment' => 'Comment', 'parse' => 'Upload embedded images/multimedia files if HTML file', - ); + 'bb5' => 'Blackboard 5', + 'bb6' => 'Blackboard 6', + 'angel5' => 'ANGEL 5.5', + 'webctce4' => 'WebCT 4 Campus Edition', + ); # ----------------------------------------------------------------------------- my $fileupload=(< @@ -4879,10 +4886,10 @@ CHBO $lt{'cms'}: 

    @@ -5376,8 +5383,8 @@ my %suporderhash = ( } &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1); undef($suppchanges); - } - } + } + } } } elsif ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, @@ -5524,7 +5531,7 @@ sub remove_archive { } else { my $currcmd = $env{'form.cmd'}; my $position = $env{'form.position'}; - if ($position > 0) { + if ($position > 0) { $env{'form.cmd'} = 'remove_'.$position; my ($title,$url,@rrest) = split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]); @@ -5751,7 +5758,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_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', @@ -5865,7 +5872,7 @@ function makewebpage(type) { formname = this.document.forms.newwebpage; } if (title) { - var webpage = formname.importdetail.value; + var webpage = formname.importdetail.value; formname.importdetail.value = escape(title)+'='+webpage; formname.submit(); } @@ -6246,11 +6253,11 @@ for (i = 0; i < currentLis.length; i++) function hideAll(current, nav, data) { unselectInactive(nav); -if (current) { +if (current) { if (current.className == 'right'){ - current.className = 'right active' + current.className = 'right active' } else { - current.className = 'active'; + current.className = 'active'; } } currentData = document.getElementById(data); @@ -6288,11 +6295,11 @@ function showPage(current, pageId, nav, unselectInactive(nav); if ((currstate == 'active') || (currstate == 'right active')) { if (currstate == 'active') { - current.className = ''; + current.className = ''; } else { current.className = 'right'; } - activeTab = ''; + activeTab = ''; toggleUpload(); toggleMap(); resize_scrollbox('contentscroll','1','0');