--- loncom/interface/portfolio.pm 2010/10/29 23:19:54 1.228 +++ loncom/interface/portfolio.pm 2010/11/11 23:58:05 1.230 @@ -1,7 +1,7 @@ # The LearningOnline Network # portfolio browser # -# $Id: portfolio.pm,v 1.228 2010/10/29 23:19:54 raeburn Exp $ +# $Id: portfolio.pm,v 1.230 2010/11/11 23:58:05 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -303,7 +303,7 @@ sub display_directory { my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group); my $now = time; if ($env{"form.mode"} eq 'selectfile') { - &select_files($r); + &select_files($r,$dir_list); $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'}); $select_mode = 'true'; } @@ -396,6 +396,7 @@ sub display_directory { push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]); } } + my $zerobyte; foreach my $dir_line (@dir_lines) { my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line; my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename); @@ -455,11 +456,16 @@ sub display_directory { my $css_class = 'LC_browser_file'; my $line; if ($select_mode eq 'true') { - $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"'; - if ($$checked_files{$filename} eq 'selected') { - $line.=' checked="checked" '; + if ($size > 0) { + $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"'; + if ($$checked_files{$filename} eq 'selected') { + $line.=' checked="checked" '; + } + $line.=' /></td>'; + } else { + $line = '<td> </td>'; + $zerobyte ++; } - $line.=' /></td>'; } else { if (exists $locked_files{$fullpath}) { my %anchor_fields = ( @@ -539,7 +545,11 @@ sub display_directory { } } if ($select_mode eq 'true') { - $r->print(&Apache::loncommon::end_data_table().' + $r->print(&Apache::loncommon::end_data_table()); + if ($zerobyte) { + $r->print('<p class="LC_warning">'.&mt('[quant,_1,file] in list not selectable as file size is 0 bytes.',$zerobyte).'</p>'); + } + $r->print(' <input type="hidden" name="continue" value="true" /> <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'" /> <input type="hidden" name="mode" value="selectfile" /> @@ -1854,13 +1864,24 @@ END_SCRIPT } sub select_files { - my ($r) = @_; + my ($r,$dir_list) = @_; if ($env{'form.continue'} eq 'true') { # here we update the selections for the currentpath # eventually, have to handle removing those not checked, but . . . my @items=&Apache::loncommon::get_env_multiple('form.checkfile'); if (scalar(@items)){ - &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items); + my @ok_items; + if (ref($dir_list) eq 'ARRAY') { + foreach my $dir_line (@{$dir_list}) { + my ($filename,undef,undef,undef,undef,undef,undef,undef,$size)=split(/\&/,$dir_line,10); + if (grep(/^\Q$filename\E$/,@items)) { + if ($size) { + push(@ok_items,$filename); + } + } + } + } + &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @ok_items); } } else { #empty the file for a fresh start @@ -1977,44 +1998,56 @@ sub upload { conf => 'Are you sure you want to overwrite an existing file?', cont => 'Continue', ); + my $parserflag; + my $hidden = &hidden_elems(); + if ($mode eq 'parse') { + $parserflag = '<input type="hidden" name="parserflag" value="1" />'; + } $r->print(<<"END"); <script type="text/javascript"> // <![CDATA[ function confirmOverwrite() { - if (confirm('$lt{'conf'}')) { - document.existingfile.action.value = "process_overwrite"; - } else { - if (document.existingfile.overwrite.length) { - for (var i=0; i<document.existingfile.overwrite.length; i++) { - if (document.existingfile.overwrite[i].value == "0") { - document.existingfile.overwrite[i].checked = true; + var chosen; + if (document.existingfile.overwrite.length) { + for (var i=0; i<document.existingfile.overwrite.length; i++) { + if (document.existingfile.overwrite[i].checked) { + chosen = document.existingfile.overwrite[i].value; + } + } + } + if (chosen == 1) { + if (confirm('$lt{'conf'}')) { + document.existingfile.action.value = "process_overwrite"; + return true; + } else { + document.existingfile.action.value = "cancel_overwrite"; + if (document.existingfile.overwrite.length) { + for (var i=0; i<document.existingfile.overwrite.length; i++) { + if (document.existingfile.overwrite[i].value == "0") { + document.existingfile.overwrite[i].checked = true; + } } } + return false; } + } else { document.existingfile.action.value = "cancel_overwrite"; + return true; } - document.existingfile.submit(); - return; -} -function cancelOverwrite() { - document.existingfile.action.value = "cancel_overwrite"; - document.existingfile.submit(); } // ]]> </script> $msg -<br /><div class="LC_warning"><form method="post" action="$url" name="existingfile"> +<br /><div class="LC_warning"><form method="post" action="$url" name="existingfile" onsubmit="return confirmOverwrite();"> <span class="LC_nobreak">$lt{'over'} -<label><input type="radio" name="overwrite" value="1" onclick="javascript:confirmOverwrite();" /> +<label><input type="radio" name="overwrite" value="1" /> $lt{'yes'}</label> -<label><input type="radio" name="overwrite" value="0" onclick="javascript:cancelOverwrite()" />$lt{'no'}</label></span> +<label><input type="radio" name="overwrite" value="0" checked="checked" />$lt{'no'}</label></span> <input type="hidden" name="action" value="cancel_overwrite" /> -<input type="hidden" name="currentpath" value="$env{'form.currentpath'}" /> <input type="hidden" name="filename" value="$showfname" /> -<input type="hidden" name="fieldname" value="$env{'form.fieldname'}" /> -<input type="hidden" name="mode" value="$mode" /> <input type="hidden" name="timestamp" value="$timestamp" /> -<input type="hidden" name="showversions" value="$env{'form.showversions'}" /> +$hidden +$parserflag $group_elem <br /><br /> <input type="submit" name="process" value="$lt{'cont'}" /> @@ -2040,6 +2073,20 @@ END } } +sub hidden_elems { + my $contelem; + if ($env{'form.mode'} eq 'selectfile') { + $contelem = '<input type="hidden" name="continue" value="true" />'; + } + return <<END; +<input type="hidden" name="currentpath" value="$env{'form.currentpath'}" /> +<input type="hidden" name="fieldname" value="$env{'form.fieldname'}" /> +<input type="hidden" name="mode" value="$env{'form.mode'}" /> +<input type="hidden" name="showversions" value="$env{'form.showversions'}" /> +$contelem +END +} + sub print_dependency_form { my ($r,$url,$allfiles,$codebase) = @_; my $state = <<STATE; @@ -2072,10 +2119,11 @@ sub overwrite { my $port_path = &get_port_path(); my $fname = &Apache::lonnet::clean_filename($env{'form.filename'}); my (%allfiles,%codebase,$mode); - $mode = $env{'form.mode'}; - if ($mode eq 'parse') { - if ($fname !~ /\.s?html?$/i) { - undef($mode); + unless (&suppress_embed_prompt()) { + if ($env{'form.parserflag'}) { + if ($fname =~ /\.s?html?$/i) { + $mode = 'parse'; + } } } if ($fname eq '') { @@ -2093,21 +2141,44 @@ sub overwrite { if ($result !~ m|^/uploaded/|) { $r->print('<span class="LC_error">'.&mt('An error occurred ([_1]) while trying to overwrite [_2].' ,$result,&display_file(undef,$fname)).'</span><br />'); - $r->print(&done('Back',$url)); + $r->print(&after_overwrite(&mt('Back'),$url)); } else { if (%allfiles) { if (!&suppress_embed_prompt()) { &print_dependency_form($r,$url,\%allfiles,\%codebase); } else { - $r->print(&done(undef,$url)); + $r->print(&after_overwrite(undef,$url)); } } else { - $r->print(&done(undef,$url)); + $r->print(&after_overwrite(undef,$url)); } } return; } +sub after_overwrite { + my ($text,$url) = @_; + my $group_elem; + if (defined($env{'form.group'})) { + $group_elem = '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />'; + if (defined($env{'form.ref'})) { + $group_elem .= '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />'."\n"; + } + } + if ($text eq '') { + $text = &mt('Done'); + } + my $hidden = &hidden_elems(); + return <<END; + +<h3><a href="javascript:document.overwritedone.submit();">$text</a></h3> +<form name="overwritedone" method="post" action="$url" /> +$hidden +$group_elem +</form> +END +} + sub lock_info { my ($r,$url,$group) = @_; my ($uname,$udom) = &get_name_dom($group);