--- loncom/interface/londocs.pm 2012/01/29 19:50:53 1.475 +++ loncom/interface/londocs.pm 2012/05/06 22:09:14 1.483 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.475 2012/01/29 19:50:53 raeburn Exp $ +# $Id: londocs.pm,v 1.483 2012/05/06 22:09:14 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -26,8 +26,6 @@ # http://www.lon-capa.org/ # - - package Apache::londocs; use strict; @@ -439,7 +437,13 @@ sub log_docs { sub docs_change_log { my ($r)=@_; my $folder=$env{'form.folder'}; - $r->print(&Apache::loncommon::start_page('Course Document Change Log')); + my $js = ''."\n"; + $r->print(&Apache::loncommon::start_page('Course Document Change Log',$js)); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log')); my %docslog=&Apache::lonnet::dump('nohist_docslog', $env{'course.'.$env{'request.course.id'}.'.domain'}, @@ -463,7 +467,7 @@ sub docs_change_log { 'randomorder' => 'Randomly ordered', 'set' => 'set to', 'del' => 'deleted'); - $r->print(&Apache::loncommon::display_filter(). + $r->print(&Apache::loncommon::display_filter('docslog'). ''. ''); $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row(). @@ -1109,12 +1113,59 @@ sub process_file_upload { $$upload_output .= &mt('No embedded items identified').'
'; } $$upload_output = '
'.$$upload_output.'
'; + } elsif (&Apache::loncommon::is_archive_file($mimetype)) { + $nextphase = 'decompress_uploaded'; + my $position = scalar(@LONCAPA::map::order)-1; + my $noextract = &return_to_editor(); + my $archiveurl = &HTML::Entities::encode($url,'<>&"'); + my %archiveitems = ( + folderpath => $env{'form.folderpath'}, + pagepath => $env{'form.pagepath'}, + cmd => $nextphase, + newidx => $newidx, + position => $position, + phase => $nextphase, + comment => $comment, + ); + my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom); + my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx); + $$upload_output = $showupload. + &Apache::loncommon::decompress_form($mimetype, + $archiveurl,'/adm/coursedocs',$noextract, + \%archiveitems,\@current); } } } return $nextphase; } +sub get_dir_list { + my ($url,$coursenum,$coursedom,$newidx) = @_; + my ($destination,$dir_root) = &embedded_destination(); + my ($dirlistref,$listerror) = + &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1); + my @dir_lines; + my $dirptr=16384; + if (ref($dirlistref) eq 'ARRAY') { + foreach my $dir_line (sort + { + my ($afile)=split('&',$a,2); + my ($bfile)=split('&',$b,2); + return (lc($afile) cmp lc($bfile)); + } (@{$dirlistref})) { + my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16); + $filename =~ s/\s+$//; + next if ($filename =~ /^\.\.?$/); + my $isdir = 0; + if ($dirptr&$testdir) { + $isdir = 1; + } + push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]); + } + } + return @dir_lines; +} + sub is_supplemental_title { my ($title) = @_; return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/); @@ -1165,7 +1216,7 @@ sub entryline { $renametitle=~s/\"\;/\\\"/g; $renametitle=~s/ /%20/g; my $line=&Apache::loncommon::start_data_table_row(); - my ($form_start,$form_end); + my ($form_start,$form_end,$form_common); # Edit commands my ($container, $type, $esc_path, $path, $symb); if ($env{'form.folderpath'}) { @@ -1256,8 +1307,10 @@ ENDCOPY $lt{'ct'} ENDCUT } - $form_start = (< + $form_start = ' +
+'; + $form_common=(< @@ -1279,6 +1332,7 @@ END $form_start + $form_common $selectbox $form_end @@ -1362,7 +1416,7 @@ END $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb); } } - my ($parameterset,$rand_order_text) = (' ', ' '); + my ($rand_pick_text,$rand_order_text); if ($isfolder || $extension eq 'sequence') { my $foldername=&escape($foldertitle); my $folderpath=$env{'form.folderpath'}; @@ -1378,16 +1432,27 @@ END .':'.((&LONCAPA::map::getparameter($orderidx, 'parameter_randomorder'))[0]=~/^yes$/i); $url.='folderpath='.&escape($folderpath).$cpinfo; - $parameterset=''; + my $rpicknum = (&LONCAPA::map::getparameter($orderidx, + 'parameter_randompick'))[0]; + my $rpckchk; + if ($rpicknum) { + $rpckchk = ' checked="checked"'; + } + my $formname = 'edit_rpick_'.$orderidx; + $rand_pick_text = +''."\n". +$form_common."\n". +''; + if ($rpicknum ne '') { + $rand_pick_text .= ': '.$rpicknum.''; + } + $rand_pick_text .= ''; my $ro_set= ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':''); - $rand_order_text =' -'; + $rand_order_text = +$form_start. +$form_common.' +'; } if ($ispage) { my $pagename=&escape($pagetitle); @@ -1438,6 +1503,8 @@ END $line.=$title.' '.$reinit.''; } $line.=$external.""; + $rand_pick_text = ' ' if ($rand_pick_text eq ''); + $rand_order_text = ' ' if ($rand_order_text eq ''); if (($allowed) && ($folder!~/^supplemental/)) { my %lt=&Apache::lonlocal::texthash( 'hd' => 'Hidden', @@ -1449,15 +1516,17 @@ END $line.=(< $form_start + $form_common $form_end
$form_start + $form_common $form_end - $form_start $parameterset $form_end
- $form_start $rand_order_text $form_end + $rand_pick_text
+ $rand_order_text ENDPARMS } $line.=&Apache::loncommon::end_data_table_row(); @@ -1696,9 +1765,11 @@ sub checkversions { if (&Apache::lonnet::put('resourceversions',\%newsetversions, $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { - $r->print('

'.&mt('Your Version Settings have been Saved').'

'); + $r->print(&Apache::loncommon::confirmwrapper( + &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved')))); } else { - $r->print('

'.&mt('An Error Occured while Attempting to Save your Version Settings').'

'); + $r->print(&Apache::loncommon::confirmwrapper( + &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1))); } &mark_hash_old(); } @@ -1764,12 +1835,19 @@ sub checkversions { 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below', 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)', 'sc' => 'Set all Resource Versions to current Version (Fix Versions)', - 'di' => 'Differences'); + 'di' => 'Differences', + 'save' => 'Save', + 'act' => 'Actions'); $r->print(< - -
+
+
+$lt{'act'} +$lt{'sm'}:
+$lt{'sc'}: +
+
-

$header

- +

$header

+ ENDHEADERS + #number of columns for version history + my $num_ver_col = 1; + $r->print( + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ''. + "". + "". + "". + ''. + ''); foreach my $key (sort(keys(%changes))) { if ($changes{$key}>$starttime) { my ($root,$extension)=($key=~/^(.*)\.(\w+)$/); my $currentversion=&Apache::lonnet::getversion($key); if ($currentversion<0) { - $currentversion=&mt('Could not be determined.'); + $currentversion=''.&mt('Could not be determined.').''; } my $linkurl=&Apache::lonnet::clutter($key); - $r->print( - ''. - ''. - ''. - ''. - ''. - ''. - ''. + ''. + ''); my $lastold=1; for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) { my $url=$root.'.'.$prevvers.'.'.$extension; @@ -1841,13 +1920,13 @@ ENDHEADERS # each of the four columns my $entries_per_col = 0; my $num_entries = ($currentversion-$lastold); - if ($num_entries % 4 == 0) { - $entries_per_col = $num_entries/4; + if ($num_entries % $num_ver_col == 0) { + $entries_per_col = $num_entries/$num_ver_col; } else { - $entries_per_col = $num_entries/4 + 1; + $entries_per_col = $num_entries/$num_ver_col + 1; } my $entries_count = 0; - $r->print(''); - if ($cols_output != 4) { - $r->print(''); + if ($cols_output != $num_ver_col) { + $r->print(''."\n"); } } - $r->print('
'.&mt('Resources').'$lt{'mr'}$lt{'ve'}$lt{'vu'}'.&mt('History').'


'. - &Apache::lonnet::gettitle($linkurl). - '
   '. - ''.$linkurl. - '
'. - &Apache::lonlocal::locallocaltime( - &Apache::lonnet::metadata($root.'.'.$extension, - 'lastrevisiondate') - ). - 'Most Recent: '. - ''.$currentversion.''. - 'In '.$crstype.': '. - ''); + $r->print( + &Apache::loncommon::end_data_table_header_row(). + &Apache::loncommon::start_data_table_row(). + ''.&Apache::lonnet::gettitle($linkurl).'
'. + ''.$linkurl.'
'.$currentversion.'
('. + &Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).')
'); # Used in course my $usedversion=$hash{'version_'.$linkurl}; if (($usedversion) && ($usedversion ne 'mostrecent')) { - $r->print($usedversion); + if($usedversion != $currentversion){ + $r->print(''.$usedversion.''); + }else{ + $r->print($usedversion); + } } else { $r->print($currentversion); } - $r->print(''. - 'Use: '); + $r->print(''); # Set version $r->print(&Apache::loncommon::select_form($setversions{$linkurl}, 'set_version_'.$linkurl, @@ -1827,7 +1907,6 @@ ENDHEADERS '' => '', 'mostrecent' => &mt('most recent'), map {$_,$_} (1..$currentversion)})); - $r->print('
'); + $r->print(''); my $cols_output = 1; for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) { my $url=$root.'.'.$prevvers.'.'.$extension; @@ -1866,21 +1945,21 @@ ENDHEADERS } $r->print('
'); if (++$entries_count % $entries_per_col == 0) { - $r->print('
'); + $r->print(''); $cols_output++; } } } - while($cols_output++ < 4) { - $r->print('') + while($cols_output++ < $num_ver_col) { + $r->print(''); } - $r->print('
'); - $r->print('

'.&mt('Done').'

'); + $r->print(''.&Apache::loncommon::end_data_table_row(). + &Apache::loncommon::end_data_table(). + ''); &untiehash(); } @@ -2359,10 +2438,19 @@ 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(); - $r->print(&Apache::loncommon::modify_html_refs('coursedoc',$destination, - $docuname,$docudom,undef, - $dir_root). - &return_to_editor()); + my $result = + &Apache::loncommon::modify_html_refs('coursedoc',$destination, + $docuname,$docudom,undef, + $dir_root); + $r->print($result.&return_to_editor()); + } elsif ($env{'form.phase'} eq 'decompress_uploaded') { + $uploadphase = 'decompress_phase_one'; + $r->print(&decompression_phase_one(). + &return_to_editor()); + } elsif ($env{'form.phase'} eq 'decompress_cleanup') { + $uploadphase = 'decompress_phase_two'; + $r->print(&decompression_phase_two(). + &return_to_editor()); } } @@ -2933,6 +3021,117 @@ sub return_to_editor { '

'; } +sub decompression_info { + my ($destination,$dir_root) = &embedded_destination(); + my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; + my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'}; + my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'}; + my $container='sequence'; + my ($pathitem,$hiddenelem); + my @hiddens = ('newidx','comment','position'); + if ($env{'form.pagepath'}) { + $container='page'; + $pathitem = 'pagepath'; + } else { + $pathitem = 'folderpath'; + } + unshift(@hiddens,$pathitem); + foreach my $item (@hiddens) { + if ($env{'form.'.$item}) { + $hiddenelem .= ''."\n"; + } + } + return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container, + $hiddenelem); +} + +sub decompression_phase_one { + my ($dir,$file,$warning,$error,$output); + my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)= + &decompression_info(); + if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/docs/\E(?:default|supplemental|\d+).*/([^/]+)$}) { + $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'}); + } else { + my $file = $1; + $output = + &Apache::loncommon::process_decompression($docudom,$docuname,$file, + $destination,$dir_root, + $hiddenelem); + if ($env{'form.autoextract_camtasia'}) { + $output .= &remove_archive($docudom,$docuname,$container); + } + } + if ($error) { + $output .= '

'.&mt('Not extracted.').'
'. + $error.'

'."\n"; + } + if ($warning) { + $output .= '

'.$warning.'

'."\n"; + } + return $output; +} + +sub decompression_phase_two { + my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)= + &decompression_info(); + my $output; + if ($env{'form.archivedelete'}) { + $output = &remove_archive($docudom,$docuname,$container); + } + $output .= + &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname, + $destination,$dir_root,$hiddenelem); + return $output; +} + +sub remove_archive { + my ($docudom,$docuname,$container) = @_; + my $map = $env{'form.folder'}.'.'.$container; + my ($output,$delwarning,$delresult,$url); + my ($errtext,$fatal) = &mapread($docuname,$docudom,$map); + if ($fatal) { + if ($container eq 'page') { + $delwarning = &mt('An error occurred retrieving the contents of the current page.'); + } else { + $delwarning = &mt('An error occurred retrieving the contents of the current folder.'); + } + $delwarning .= &mt('As a result the archive file has not been removed.'); + } else { + my $currcmd = $env{'form.cmd'}; + my $position = $env{'form.position'}; + if ($position > 0) { + $env{'form.cmd'} = 'del_'.$position; + my ($title,$url,@rrest) = + split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]); + if (&handle_edit_cmd($docuname,$docudom)) { + ($errtext,$fatal) = &storemap($docuname,$docudom,$map); + if ($fatal) { + if ($container eq 'page') { + $delwarning = &mt('An error occurred updating the contents of the current page.'); + } else { + $delwarning = &mt('An error occurred updating the contents of the current folder.'); + } + } else { + $delresult = &mt('Archive file removed.'); + } + } + } + $env{'form.cmd'} = $currcmd; + } + if ($delwarning) { + $output = '

'. + $delwarning. + '

'; + } + if ($delresult) { + $output .= '

'. + $delresult. + '

'; + } + return $output; +} + sub generate_admin_options { my ($help_ref,$env_ref) = @_; my %lt=&Apache::lonlocal::texthash( @@ -2979,7 +3178,7 @@ sub generate_edit_table { $activetab = $env{'form.active'}; } my $backicon = $iconpath.'clickhere.gif'; - my $backtext = &mt('Back to Overview'); + my $backtext = &mt('To Overview'); $form = '
'. '