added only_increment param to all action=browse links
[BackupPC.git] / lib / BackupPC / CGI / Browse.pm
index 3eb7f30..aa52543 100644 (file)
@@ -10,7 +10,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2003  Craig Barratt
+#   Copyright (C) 2003-2009  Craig Barratt
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0_CVS, released 3 Jul 2003.
+# Version 3.2.0, released 31 Jul 2010.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -37,6 +37,7 @@
 package BackupPC::CGI::Browse;
 
 use strict;
+use Encode qw/decode_utf8/;
 use BackupPC::CGI::Lib qw(:all);
 use BackupPC::View;
 use BackupPC::Attrib qw(:all);
@@ -64,7 +65,7 @@ sub action
     #
     # default to the newest backup
     #
-    if ( !defined($In{num}) && defined(@Backups) ) {
+    if ( !defined($In{num}) && defined(@Backups) && @Backups > 0 ) {
         $i = @Backups - 1;
         $num = $Backups[$i]{num};
     }
@@ -79,7 +80,7 @@ sub action
     my $backupTime = timeStamp2($Backups[$i]{startTime});
     my $backupAge = sprintf("%.1f", (time - $Backups[$i]{startTime})
                                     / (24 * 3600));
-    my $view = BackupPC::View->new($bpc, $host, \@Backups);
+    my $view = BackupPC::View->new($bpc, $host, \@Backups, {nlink => 1, only_increment => $In{only_increment}});
 
     if ( $dir eq "" || $dir eq "." || $dir eq ".." ) {
        $attr = $view->dirAttrib($num, "", "");
@@ -106,6 +107,7 @@ sub action
 
        $attr = $view->dirAttrib($num, $share, $relDir);
         if ( !defined($attr) ) {
+            $relDir = decode_utf8($relDir);
             ErrorExit(eval("qq{$Lang->{Can_t_browse_bad_directory_name2}}"));
         }
 
@@ -156,10 +158,11 @@ sub action
                }
                my $dirName = $f;
                $dirName =~ s/ /&nbsp;/g;
+                $dirName = decode_utf8($dirName);
                push(@DirStr, {needTick => 1,
                                tdArgs   => " class=\"$tdStyle\"",
                               link     => <<EOF});
-<a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$imgStr</a><a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path" class="$linkStyle">&nbsp;$dirName</a></td></tr>
+<a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path&only_increment=$In{only_increment}">$imgStr</a><a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path&only_increment=$In{only_increment}" class="$linkStyle">&nbsp;$dirName</a></td></tr>
 EOF
                 $fileCnt++;
                 $gotDir = 1;
@@ -201,7 +204,7 @@ EOF
                                                                   $a->{type});
                     my $modeStr  = sprintf("0%o", $a->{mode} & 07777);
                     $iconStr = <<EOF;
-<img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" align="center">
+<img src="$Conf{CgiImageDirURL}/icon-$typeStr.png" valign="top">
 EOF
                     $attrStr .= <<EOF;
     <td align="center" class="fviewborder">$typeStr</td>
@@ -215,14 +218,11 @@ EOF
                     $attrStr .= "<td colspan=\"5\" align=\"center\" class=\"fviewborder\"> </td>\n";
                 }
                (my $fDisp = "${EscHTML($f)}") =~ s/ /&nbsp;/g;
+                $fDisp = decode_utf8($fDisp);
                 if ( $gotDir ) {
                     $fileStr .= <<EOF;
 <tr><td class="fviewborder">
-    <table cellpadding="0" cellspacing="0" border="0"><tr><td>
-    <input type="checkbox" name="fcb$checkBoxCnt" value="$path">&nbsp;$iconStr
-    </td><td>
-        &nbsp;<a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$fDisp</a>
-    </td></tr></table>
+    <input type="checkbox" name="fcb$checkBoxCnt" value="$path">&nbsp;$iconStr&nbsp;<a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path&only_increment=$In{only_increment}">$fDisp</a>
 </td>
 $attrStr
 </tr>
@@ -230,11 +230,7 @@ EOF
                 } else {
                     $fileStr .= <<EOF;
 <tr><td class="fviewborder">
-    <table cellpadding="0" cellspacing="0" border="0"><tr><td>
-    <input type="checkbox" name="fcb$checkBoxCnt" value="$path">&nbsp;$iconStr
-    </td><td>
-        &nbsp;<a href="$MyURL?action=RestoreFile&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$fDisp</a>
-    </td></tr></table>
+    <input type="checkbox" name="fcb$checkBoxCnt" value="$path">&nbsp;$iconStr&nbsp;<a href="$MyURL?action=RestoreFile&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$fDisp</a>
 </td>
 $attrStr
 </tr>
@@ -259,7 +255,7 @@ EOF
        }
     }
     $share = $currDir;
-    my $dirDisplay = "$share/$dir";
+    my $dirDisplay = decode_utf8("$share/$dir");
     $dirDisplay =~ s{//+}{/}g;
     $dirDisplay =~ s{/+$}{}g;
     $dirDisplay = "/" if ( $dirDisplay eq "" );
@@ -290,26 +286,27 @@ EOF
     } else {
        $fileStr = eval("qq{$Lang->{The_directory_is_empty}}");
     }
-    my @otherDirs;
     my $pathURI  = $dir;
     my $shareURI = $share;
     $pathURI  =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
     $shareURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
-    foreach my $i ( $view->backupList($share, $dir) ) {
-        push(@otherDirs, $i);
-    }
-    if ( @otherDirs ) {
-       my $otherDirs  = join(",\n", @otherDirs);
-        my $inc = 0;
-        foreach my $value (@otherDirs) {
-            my $selected = undef;
-            my $showDate = timeStamp2($Backups[$inc]{startTime});
-            $selected = " selected" if ($value == $num);
-            $otherDirs .= "<option value=\"$MyURL?action=browse&host=${EscURI($host)}&num=$value\"$selected>#$value - ($showDate)</option>\n";
-            $inc++;
+    if ( my @otherDirs = $view->backupList($share, $dir) ) {
+        my $otherDirs;
+        foreach my $i ( @otherDirs ) {
+            my $selected;
+            my $showDate  = timeStamp2($Backups[$i]{startTime});
+           my $backupNum = $Backups[$i]{num};
+            $selected   = " selected" if ( $backupNum == $num );
+            $otherDirs .= "<option value=\"$MyURL?action=browse&host=${EscURI($host)}&num=$backupNum&share=$shareURI&dir=$pathURI&only_increment=$In{only_increment}\"$selected>#$backupNum - ($showDate)</option>\n";
         }
         $filledBackup .= eval("qq{$Lang->{Visit_this_directory_in_backup}}");
     }
+
+       # XXX ASA
+       $filledBackup .= "<li><input type=checkbox name=only_increment value=checked $In{only_increment}> show only this increment";
+
+    $dir   = decode_utf8($dir);
+    $share = decode_utf8($share);
     my $content = eval("qq{$Lang->{Backup_browse_for__host}}");
     Header(eval("qq{$Lang->{Browse_backup__num_for__host}}"), $content);
     Trailer();