use DateTime;
use vars qw(%In $MyURL);
use Time::HiRes qw/time/;
+use XML::Writer;
+use IO::File;
my $on_page = 100;
my $pager_pages = 10;
my $dsn = $Conf{SearchDSN};
my $db_user = $Conf{SearchUser} || '';
-my $index_path = $Conf{HyperEstraierIndex};
-if ($index_path) {
- $index_path = $TopDir . '/' . $index_path;
- $index_path =~ s#//#/#g;
-}
+my $hest_node_url = $Conf{HyperEstraierIndex};
my $dbh;
sub mk_epoch_date($$) {
my ($name,$suffix) = @_;
- my $yyyy = $param->{ $name . '_year_' . $suffix} || return;
+ my $yyyy = $param->{ $name . '_year_' . $suffix} || return undef;
my $mm .= $param->{ $name . '_month_' . $suffix} ||
( $suffix eq 'from' ? 1 : 12);
my $dd .= $param->{ $name . '_day_' . $suffix} ||
( $suffix eq 'from' ? 1 : 31);
+
+ $yyyy =~ s/\D//g;
+ $mm =~ s/\D//g;
+ $dd =~ s/\D//g;
+
+ my $h = my $m = my $s = 0;
+ if ($suffix eq 'to') {
+ $h = 23;
+ $m = 59;
+ $s = 59;
+ }
+
my $dt = new DateTime(
year => $yyyy,
month => $mm,
- day => $dd
+ day => $dd,
+ hour => $h,
+ minute => $m,
+ second => $s,
);
+ print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";
return $dt->epoch || 'NULL';
}
- return (
+ my @ret = (
mk_epoch_date('search_backup', 'from'),
mk_epoch_date('search_backup', 'to'),
mk_epoch_date('search', 'from'),
mk_epoch_date('search', 'to'),
);
+
+ return @ret;
+
}
push @conditions, qq{ files.date >= $files_from } if ($files_from);
push @conditions, qq{ files.date <= $files_to } if ($files_to);
- print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions);
+ print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" and ",@conditions);
push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});
return join(" and ", @conditions);
}
+my $sort_def = {
+ search => {
+ default => 'date_a',
+ sql => {
+ share_d => 'shares.name DESC',
+ share_a => 'shares.name ASC',
+ path_d => 'files.path DESC',
+ path_a => 'files.path ASC',
+ num_d => 'files.backupnum DESC',
+ num_a => 'files.backupnum ASC',
+ size_d => 'files.size DESC',
+ size_a => 'files.size ASC',
+ date_d => 'files.date DESC',
+ date_a => 'files.date ASC',
+ },
+ est => {
+ share_d => 'sname STRD',
+ share_a => 'sname STRA',
+ path_d => 'filepath STRD',
+ path_a => 'filepath STRA',
+ num_d => 'backupnum NUMD',
+ num_a => 'backupnum NUMA',
+ size_d => 'size NUMD',
+ size_a => 'size NUMA',
+ date_d => 'date NUMD',
+ date_a => 'date NUMA',
+ }
+ }, burn => {
+ default => 'date_a',
+ sql => {
+ share_d => 'host DESC, share DESC',
+ share_a => 'host ASC, share ASC',
+ num_d => 'backupnum DESC',
+ num_a => 'backupnum ASC',
+ date_d => 'date DESC',
+ date_a => 'date ASC',
+ age_d => 'age DESC',
+ age_a => 'age ASC',
+ size_d => 'size DESC',
+ size_a => 'size ASC',
+ incsize_d => 'inc_size DESC',
+ incsize_a => 'inc_size ASC',
+ }
+ }
+};
+
+sub getSort($$$) {
+ my ($part,$type, $sort_order) = @_;
+
+ die "unknown part: $part" unless ($sort_def->{$part});
+ die "unknown type: $type" unless ($sort_def->{$part}->{$type});
+
+ $sort_order ||= $sort_def->{$part}->{'default'};
+
+ if (my $ret = $sort_def->{$part}->{$type}->{$sort_order}) {
+ return $ret;
+ } else {
+ # fallback to default sort order
+ return $sort_def->{$part}->{$type}->{ $sort_def->{$part}->{'default'} };
+ }
+}
+
+sub getFiles($) {
+ my ($param) = @_;
-sub getFiles($$) {
- my ($param, $offset) = @_;
+ my $offset = $param->{'offset'} || 0;
+ $offset *= $on_page;
my $dbh = get_dbh();
files.id AS fid,
hosts.name AS hname,
shares.name AS sname,
- -- shares.share AS sharename,
files.backupnum AS backupnum,
- -- files.name AS filename,
files.path AS filepath,
files.date AS date,
files.type AS type,
- files.size AS size,
- -- dvds.name AS dvd
- null AS dvd
+ files.size AS size
};
my $sql_from = qq{
FROM files
INNER JOIN shares ON files.shareID=shares.ID
INNER JOIN hosts ON hosts.ID = shares.hostID
- INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = shares.ID
- };
-
- my $sql_dvd_from = qq{
- -- LEFT JOIN dvds ON dvds.ID = files.dvdid
+ INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = files.shareID
};
my $sql_where;
my $where = getWhere($param);
$sql_where = " WHERE ". $where if ($where);
+ my $order = getSort('search', 'sql', $param->{'sort'});
+
my $sql_order = qq{
- ORDER BY files.date
+ ORDER BY $order
LIMIT $on_page
OFFSET ?
};
my $sql_count = qq{ select count(files.id) $sql_from $sql_where };
- my $sql_results = qq{ select $sql_cols $sql_from $sql_dvd_from $sql_where $sql_order };
-
- $offset ||= 0;
- $offset = ($offset * $on_page);
+ my $sql_results = qq{ select $sql_cols $sql_from $sql_where $sql_order };
my $sth = $dbh->prepare($sql_count);
$sth->execute();
return ($results, \@ret);
}
-sub getFilesHyperEstraier($$) {
- my ($param, $offset) = @_;
+sub getHyperEstraier_url($) {
+ my ($use_hest) = @_;
+
+ return unless $use_hest;
+
+ use Search::Estraier 0.04;
+ die "direct access to Hyper Estraier datatase is no longer supported. Please use estmaster\n"
+ unless ($use_hest =~ m#^http://#);
+
+ return $use_hest;
+}
+
+sub getFilesHyperEstraier($) {
+ my ($param) = @_;
- die "no index_path?" unless ($index_path);
+ my $offset = $param->{'offset'} || 0;
+ $offset *= $on_page;
- use HyperEstraier;
+ die "no Hyper Estraier node URL?" unless ($hest_node_url);
# open the database
- my $db = HyperEstraier::Database->new();
- $db->open($index_path, $HyperEstraier::ESTDBREADER);
+ my $db;
+ if ($hest_node_url) {
+ $db ||= Search::Estraier::Node->new($hest_node_url);
+ $db->set_auth('admin', 'admin');
+ } else {
+ die "BUG: unimplemented";
+ }
# create a search condition object
- my $cond = HyperEstraier::Condition->new();
+ my $cond = Search::Estraier::Condition->new();
my $q = $param->{'search_filename'};
my $shareid = $param->{'search_share'};
- if ($q) {
- $q =~ s/(.)/$1 /g;
+ if (length($q) > 0) {
+ # exact match
+ $cond->add_attr("filepath ISTRINC $q");
+ $q =~ s/(.)/$1 /g;
# set the search phrase to the search condition object
$cond->set_phrase($q);
+ }
- my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
-
- $cond->add_attr("backup_date NUMGE $backup_from") if ($backup_from);
- $cond->add_attr("backup_date NUMLE $backup_to") if ($backup_to);
+ my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param);
- $cond->add_attr("date NUMGE $files_from") if ($files_from);
- $cond->add_attr("date NUMLE $files_to") if ($files_to);
+ $cond->add_attr("backup_date NUMGE $backup_from") if ($backup_from);
+ $cond->add_attr("backup_date NUMLE $backup_to") if ($backup_to);
- $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);
- }
+ $cond->add_attr("date NUMGE $files_from") if ($files_from);
+ $cond->add_attr("date NUMLE $files_to") if ($files_to);
- $offset ||= 0;
- $offset = ($offset * $on_page);
+ $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);
-# $cond->set_max( $offset + $on_page );
- $cond->set_options( $HyperEstraier::Condition::SURE );
- $cond->set_order( 'date NUMA' );
+ $cond->set_max( $offset + $on_page );
+ $cond->set_options( 'SURE' );
+ $cond->set_order( getSort('search', 'est', $param->{'sort'} ) );
# get the result of search
- my $result = $db->search($cond, 0);
- $result->get(0);
-
my @res;
- my $hits = $result->size;
+ my ($result, $hits);
+
+ if ($hest_node_url) {
+ $result = $db->search($cond, 0);
+ if ($result) {
+ $hits = $result->hits;
+ } else {
+ $hits = 0;
+ return ($hits,[]);
+ }
+ } else {
+ die "BUG: unimplemented";
+ }
# for each document in result
- for my $i ($offset .. $result->size-1) {
- my $id = $result->get($i);
- my $doc = $db->get_doc($id, 0);
+ for my $i ($offset .. ($offset + $on_page - 1)) {
+ last if ($i >= $result->doc_num);
+
+ my $doc;
+ if ($hest_node_url) {
+ $doc = $result->get_doc($i);
+ } else {
+ die "BUG: unimplemented";
+ }
my $row;
- foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) {
+ foreach my $c (qw/fid hname sname backupnum filepath date type size/) {
$row->{$c} = $doc->attr($c);
}
push @res, $row;
return ($hits, \@res);
}
-sub getBackupsNotBurned() {
+sub getGzipName($$$)
+{
+ my ($host, $share, $backupnum) = @_;
+ my $ret = $Conf{GzipSchema};
+
+ $share =~ s/\//_/g;
+ $ret =~ s/\\h/$host/ge;
+ $ret =~ s/\\s/$share/ge;
+ $ret =~ s/\\n/$backupnum/ge;
+
+ $ret =~ s/__+/_/g;
+
+ return $ret;
+
+}
+
+sub get_tgz_size_by_name($) {
+ my $name = shift;
+
+ my $tgz = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.$name;
+
+ my $size = -1;
+
+ if (-f "${tgz}.tar.gz") {
+ $size = (stat("${tgz}.tar.gz"))[7];
+ } elsif (-d $tgz) {
+ opendir(my $dir, $tgz) || die "can't opendir $tgz: $!";
+ my @parts = grep { !/^\./ && !/md5/ && -f "$tgz/$_" } readdir($dir);
+ $size = 0;
+ foreach my $part (@parts) {
+ $size += (stat("$tgz/$part"))[7] || die "can't stat $tgz/$part: $!";
+ }
+ closedir $dir;
+ } else {
+ return -1;
+ }
+
+ return $size;
+}
+sub getGzipSize($$)
+{
+ my ($hostID, $backupNum) = @_;
+ my $sql;
my $dbh = get_dbh();
- my $sql = q{
- SELECT
- backups.hostID AS hostid,
- min(hosts.name) AS host,
- backups.num AS backupnum,
- min(backups.type) AS type,
- min(backups.date) AS date,
- min(backups.size) AS size
- FROM files
- INNER JOIN shares ON files.shareID=shares.ID
- INNER JOIN hosts ON hosts.ID = shares.hostID
- INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = shares.ID
- WHERE
- files.dvdid IS NULL
- GROUP BY
- backups.hostID, backups.num
- ORDER BY min(backups.date)
+
+ $sql = q{
+ SELECT hosts.name as host,
+ shares.name as share,
+ backups.num as backupnum
+ FROM hosts, backups, shares
+ WHERE shares.id=backups.shareid AND
+ hosts.id =backups.hostid AND
+ hosts.id=? AND
+ backups.num=?
+ };
+ my $sth = $dbh->prepare($sql);
+ $sth->execute($hostID, $backupNum);
+
+ my $row = $sth->fetchrow_hashref();
+
+ return get_tgz_size_by_name(
+ getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})
+ );
+}
+
+sub getVolumes($) {
+ my $id = shift;
+
+ my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
+
+ my $sth = $dbh->prepare(qq{
+ select
+ size
+ from backup_parts
+ where backup_id = ?
+ order by part_nr asc
+ });
+
+ $sth->execute($id);
+
+ my $cumulative_size = 0;
+ my $volumes = 1;
+
+ while(my ($size) = $sth->fetchrow_array) {
+ if ($cumulative_size + $size > $max_archive_size) {
+ $volumes++;
+ $cumulative_size = $size;
+ } else {
+ $cumulative_size += $size;
+ }
+ }
+
+ return ($volumes,$cumulative_size);
+}
+
+sub getBackupsNotBurned($) {
+
+ my $param = shift;
+ my $dbh = get_dbh();
+
+ my $order = getSort('burn', 'sql', $param->{'sort'});
+
+print STDERR "## sort=". ($param->{'sort'} || 'no sort param') . " burn sql order: $order\n";
+
+ my $sql = qq{
+ SELECT
+ backups.hostID AS hostID,
+ hosts.name AS host,
+ shares.name AS share,
+ backups.num AS backupnum,
+ backups.type AS type,
+ backups.date AS date,
+ date_part('epoch',now()) - backups.date as age,
+ backups.size AS size,
+ backups.id AS id,
+ backups.inc_size AS inc_size,
+ backups.parts AS parts
+ FROM backups
+ INNER JOIN shares ON backups.shareID=shares.ID
+ INNER JOIN hosts ON backups.hostID = hosts.ID
+ LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id
+ WHERE backups.inc_size > 0 AND backups.size > 0 AND backups.inc_deleted is false AND archive_backup.backup_id IS NULL AND backups.parts > 0
+ GROUP BY
+ backups.hostID,
+ hosts.name,
+ shares.name,
+ backups.num,
+ backups.shareid,
+ backups.id,
+ backups.type,
+ backups.date,
+ backups.size,
+ backups.inc_size,
+ backups.parts
+ ORDER BY $order
};
my $sth = $dbh->prepare( $sql );
my @ret;
$sth->execute();
while ( my $row = $sth->fetchrow_hashref() ) {
- $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
- $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
+ $row->{'age'} = sprintf("%0.1f", ( $row->{'age'} / 86400 ) );
+ #$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
+
+ my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
+ if ($row->{size} > $max_archive_size) {
+ ($row->{volumes}, $row->{inc_size_calc}) = getVolumes($row->{id});
+ }
+
+ $row->{size} = sprintf("%0.2f", $row->{size} / 1024 / 1024);
+
+ # do some cluster calculation (approximate)
+ $row->{inc_size} = int(( ($row->{inc_size} + 1023 ) / 2 ) * 2);
+ $row->{inc_size_calc} ||= $row->{inc_size};
push @ret, $row;
}
- return @ret;
+ return @ret;
}
-sub displayBackupsGrid()
- {
- my $retHTML = "";
- my $addForm = 1;
-
- if ($addForm) {
+sub displayBackupsGrid($) {
+
+ my $param = shift;
+
+ my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
+ my $max_archive_file_size = $Conf{MaxArchiveFileSize} || die "no MaxFileInSize";
+
+ my $retHTML .= q{
+ <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
+ };
+
+ $retHTML .= <<'EOF3';
+<style type="text/css">
+<!--
+DIV#fixedBox {
+ position: absolute;
+ top: 50em;
+ left: -24%;
+ padding: 0.5em;
+ width: 20%;
+ background-color: #E0F0E0;
+ border: 1px solid #00C000;
+}
+
+DIV#fixedBox, DIV#fixedBox INPUT, DIV#fixedBox TEXTAREA {
+ font-size: 10pt;
+}
+
+FORM>DIV#fixedBox {
+ position: fixed !important;
+ left: 0.5em !important;
+ top: auto !important;
+ bottom: 1em !important;
+ width: 15% !important;
+}
+
+DIV#fixedBox INPUT[type=text], DIV#fixedBox TEXTAREA {
+ border: 1px solid #00C000;
+}
+
+DIV#fixedBox #note {
+ display: block;
+ width: 100%;
+}
+
+DIV#fixedBox #submitBurner {
+ display: block;
+ width: 100%;
+ margin-top: 0.5em;
+ cursor: pointer;
+}
+
+* HTML {
+ overflow-y: hidden;
+}
+
+* HTML BODY {
+ overflow-y: auto;
+ height: 100%;
+ font-size: 100%;
+}
+
+* HTML DIV#fixedBox {
+ position: absolute;
+}
- $retHTML .= <<EOF3;
-<script language="javascript" type="text/javascript">
+#mContainer, #gradient, #mask, #progressIndicator {
+ display: block;
+ width: 100%;
+ font-size: 10pt;
+ font-weight: bold;
+ text-align: center;
+ vertical-align: middle;
+ padding: 1px;
+}
+
+#gradient, #mask, #progressIndicator {
+ left: 0;
+ border-width: 1px;
+ border-style: solid;
+ border-color: #000000;
+ color: #404040;
+ margin: 0.4em;
+ position: absolute;
+ margin-left: -1px;
+ margin-top: -1px;
+ margin-bottom: -1px;
+ overflow: hidden;
+}
+
+#mContainer {
+ display: block;
+ position: relative;
+ padding: 0px;
+ margin-top: 0.4em;
+ margin-bottom: 0.5em;
+}
+
+#gradient {
+ z-index: 1;
+ background-color: #FFFF00;
+}
+
+#mask {
+ z-index: 2;
+ background-color: #FFFFFF;
+}
+
+#progressIndicator {
+ z-index: 3;
+ background-color: transparent;
+}
+
+#volumes {
+ padding: 0.4em;
+ display: none;
+ width: 100%;
+ font-size: 80%;
+ color: #ff0000;
+ text-align: center;
+}
+-->
+</style>
+<script type="text/javascript">
<!--
- function checkAll(location)
- {
- for (var i=0;i<document.forma.elements.length;i++)
- {
- var e = document.forma.elements[i];
- if ((e.checked || !e.checked) && e.name != \'all\') {
- if (eval("document.forma."+location+".checked")) {
- e.checked = true;
- } else {
- e.checked = false;
- }
- }
- }
- }
-//-->
-</script>
+var debug_div = null;
EOF3
- $retHTML .= q{<form name="forma" method="GET" action="}."$MyURL"."?action=burn\"";
- $retHTML.= q{<input type="hidden" value="burn" name="action">};
- $retHTML .= q{<input type="hidden" value="results" name="search_results">};
- }
+
+ # take maximum archive size from configuration
$retHTML .= qq{
- <table style="fview" border="1" cellspacing="0" cellpadding="3">
- <tr class="tableheader">
- };
+var media_size = $max_archive_size ;
+var max_file_size = $max_archive_file_size;
+
+};
+
+ $retHTML .= <<'EOF3';
- if ($addForm) {
- $retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>";
+function debug(msg) {
+ return; // Disable debugging
+
+ if (! debug_div) debug_div = document.getElementById('debug');
+
+ // this will create debug div if it doesn't exist.
+ if (! debug_div) {
+ debug_div = document.createElement('div');
+ if (document.body) document.body.appendChild(debug_div);
+ else debug_div = null;
}
- $retHTML .= qq{
- <td align="center">Host</td>
- <td align="center">Backup no</td>
- <td align="center">Type</td>
- <td align="center">date</td>
- <td align="center">age/days</td>
- <td align="center">size/MB</td>
- </tr>
- };
+ if (debug_div) {
+ debug_div.appendChild(document.createTextNode(msg));
+ debug_div.appendChild(document.createElement("br"));
+ }
+}
- my @backups = getBackupsNotBurned();
- my $backup;
- if ($addForm) {
- $retHTML .= qq{
- <tr><td colspan=7 style="tableheader">
- <input type="submit" value="Burn selected backups on medium" name="submitBurner">
- </td></tr>
- };
+var element_id_cache = Array();
+
+function element_id(name,element) {
+ if (! element_id_cache[name]) {
+ element_id_cache[name] = self.document.getElementById(name);
}
+ return element_id_cache[name];
+}
- foreach $backup(@backups) {
+function checkAll(location) {
+ var f = element_id('forma') || null;
+ if (!f) return false;
+
+ var len = f.elements.length;
+ var check_all = element_id('allFiles');
+ var suma = check_all.checked ? (parseInt(f.elements['totalsize'].value) || 0) : 0;
+
+ for (var i = 0; i < len; i++) {
+ var e = f.elements[i];
+ if (e.name != 'all' && e.name.substr(0, 3) == 'fcb') {
+ if (check_all.checked) {
+ if (e.checked) continue;
+ var el = element_id("fss" + e.name.substr(3));
+ var size = parseInt(el.value) || 0;
+ debug('suma: '+suma+' size: '+size);
+ if ((suma + size) < media_size) {
+ suma += size;
+ e.checked = true;
+ } else {
+ break;
+ }
+ } else {
+ e.checked = false;
+ }
+ }
+ }
+ update_sum(suma);
+}
- my $ftype = "";
-
- $retHTML .= "<tr>";
- if ($addForm) {
- $retHTML .= '<td class="fview"><input type="checkbox" name="fcb' .
- $backup->{'hostid'}.'_'.$backup->{'backupnum'} .
- '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} .
- '"></td>';
- }
-
- $retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' .
- '<td class="fviewborder">' . $backup->{'backupnum'} . '</td>' .
- '<td class="fviewborder">' . $backup->{'type'} . '</td>' .
- '<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
- '<td class="fviewborder">' . $backup->{'age'} . '</td>' .
- '<td class="fviewborder">' . $backup->{'size'} . '</td>' .
- '</tr>';
+function update_sum(suma, suma_disp) {
+ if (! suma_disp) suma_disp = suma;
+ suma_disp = Math.floor(suma_disp / 1024);
+ element_id('forma').elements['totalsize_kb'].value = suma_disp;
+ element_id('forma').elements['totalsize'].value = suma;
+ pbar_set(suma, media_size);
+ debug('total size: ' + suma);
+}
+
+function update_size(name, checked, suma) {
+ var size = parseInt( element_id("fss" + name).value);
+
+ if (checked) {
+ suma += size;
+ } else {
+ suma -= size;
}
- $retHTML .= "</table>";
+ var volumes = parseInt( element_id("prt" + name).value);
+ debug('update_size('+name+','+checked+') suma: '+suma+' volumes: '+volumes);
+ if (volumes > 1) {
+ if (checked) {
+ element_id("volumes").innerHTML = "This will take "+volumes+" mediums!";
+ element_id("volumes").style.display = 'block';
+ suma = size;
+ update_sum(suma);
+ } else {
+ suma -= size;
+ element_id("volumes").style.display = 'none';
+ }
+ }
+
+ return suma;
+}
+
+function sumiraj(e) {
+ var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
+ var len = element_id('forma').elements.length;
+ if (e) {
+ suma = update_size(e.name.substr(3), e.checked, suma);
+ if (suma < 0) suma = 0;
+ } else {
+ suma = 0;
+ for (var i = 0; i < len; i++) {
+ var fel = element_id('forma').elements[i];
+ if (fel.name != 'all' && fel.checked && fel.name.substr(0,3) == 'fcb') {
+ suma = update_size(fel.name.substr(3), fel.checked, suma);
+ }
+ }
+ }
+ update_sum(suma);
+ return suma;
+}
+
+/* progress bar */
+
+var _pbar_width = null;
+var _pbar_warn = 10; // change color in last 10%
+
+function pbar_reset() {
+ element_id("mask").style.left = "0px";
+ _pbar_width = element_id("mContainer").offsetWidth - 2;
+ element_id("mask").style.width = _pbar_width + "px";
+ element_id("mask").style.display = "block";
+ element_id("progressIndicator").style.zIndex = 10;
+ element_id("progressIndicator").innerHTML = "0";
+}
+
+function dec2hex(d) {
+ var hch = '0123456789ABCDEF';
+ var a = d % 16;
+ var q = (d - a) / 16;
+ return hch.charAt(q) + hch.charAt(a);
+}
+
+function pbar_set(amount, max) {
+ debug('pbar_set('+amount+', '+max+')');
+
+ if (_pbar_width == null) {
+ var _mc = element_id("mContainer");
+ if (_pbar_width == null) _pbar_width = parseInt(_mc.offsetWidth ? (_mc.offsetWidth - 2) : 0) || null;
+ if (_pbar_width == null) _pbar_width = parseInt(_mc.clientWidth ? (_mc.clientWidth + 2) : 0) || null;
+ if (_pbar_width == null) _pbar_width = 0;
+ }
+
+ var pcnt = Math.floor(amount * 100 / max);
+ var p90 = 100 - _pbar_warn;
+ var pcol = pcnt - p90;
+ if (Math.round(pcnt) <= 100) {
+ if (pcol < 0) pcol = 0;
+ var e = element_id("submitBurner");
+ debug('enable_button');
+ e.disabled = false;
+ var a = e.getAttributeNode('disabled') || null;
+ if (a) e.removeAttributeNode(a);
+ } else {
+ debug('disable button');
+ pcol = _pbar_warn;
+ var e = element_id("submitBurner");
+ if (!e.disabled) e.disabled = true;
+ }
+ var col_g = Math.floor((_pbar_warn - pcol) * 255 / _pbar_warn);
+ var col = '#FF' + dec2hex(col_g) + '00';
+
+ //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);
+ element_id("gradient").style.backgroundColor = col;
+
+ element_id("progressIndicator").innerHTML = pcnt + '%';
+ //element_id("progressIndicator").innerHTML = amount;
+
+ element_id("mask").style.clip = 'rect(' + Array(
+ '0px',
+ element_id("mask").offsetWidth + 'px',
+ element_id("mask").offsetHeight + 'px',
+ Math.round(_pbar_width * amount / max) + 'px'
+ ).join(' ') + ')';
+}
+
+if (!self.body) self.body = new Object();
+self.onload = self.document.onload = self.body.onload = function() {
+ //pbar_reset();
+ sumiraj();
+};
+
+// -->
+</script>
+<div id="fixedBox">
+
+<input type="hidden" name="totalsize"/>
+Size: <input type="text" name="totalsize_kb" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB
+
+<div id="mContainer">
+ <div id="gradient"> </div>
+ <div id="mask"> </div>
+ <div id="progressIndicator">0%</div>
+</div>
+<br/>
+
+<div id="volumes"> </div>
+
+Note:
+<textarea name="note" cols="10" rows="5" id="note"></textarea>
+
+<input type="submit" id="submitBurner" value="Burn selected" name="submitBurner" />
- if ($addForm) {
- $retHTML .= "</form>";
+</div>
+<!--
+<div id="debug" style="float: right; width: 10em; border: 1px #ff0000 solid; background-color: #ffe0e0; -moz-opacity: 0.7;">
+no debug output yet
+</div>
+-->
+EOF3
+ $retHTML .= q{
+ <input type="hidden" value="burn" name="action">
+ <input type="hidden" value="results" name="search_results">
+ <table style="fview" border="0" cellspacing="0" cellpadding="2">
+ <tr class="tableheader">
+ <td class="tableheader">
+ <input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');">
+ </td>
+ } .
+ sort_header($param, 'Share', 'share', 'center') .
+ sort_header($param, '#', 'num', 'center') .
+ qq{
+ <td align="center">Type</td>
+ } .
+ sort_header($param, 'Date', 'date', 'center') .
+ sort_header($param, 'Age/days', 'age', 'center') .
+ sort_header($param, 'Size/Mb', 'size', 'center') .
+ sort_header($param, 'gzip size/Kb', 'incsize', 'center') .
+ qq{
+ <td align="center">medias</td></tr>
+ };
+
+ my @color = (' bgcolor="#e0e0e0"', '');
+
+ my $i = 0;
+ my $host = '';
+
+ foreach my $backup ( getBackupsNotBurned($param) ) {
+
+ if ($host ne $backup->{'host'}) {
+ $i++;
+ $host = $backup->{'host'};
+ }
+ my $ftype = "";
+
+ my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
+
+ $retHTML .=
+ '<tr' . $color[$i %2 ] . '>
+ <td class="fview">';
+
+ if (($backup->{'inc_size'} || 0) > 0) {
+ $retHTML .= '
+ <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';
+ }
+
+ my $img_url = $Conf{CgiImageDirURL};
+
+ $retHTML .=
+ '</td>' .
+ '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
+ '<td align="center">' . $backup->{'backupnum'} . '</td>' .
+ '<td align="center">' . $backup->{'type'} . '</td>' .
+ '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
+ '<td align="center">' . $backup->{'age'} . '</td>' .
+ '<td align="right">' . $backup->{'size'} . '</td>' .
+ '<td align="right">' . sprintf("%0.1f", $backup->{'inc_size'} / 1024 ) .
+ '<input type="hidden" id="fss'.$checkbox_key .'" value="'. $backup->{'inc_size_calc'} .'"></td>' .
+ '<input type="hidden" id="prt'.$checkbox_key .'" value="'. $backup->{'volumes'} .'"></td>' .
+ '<td align="left">' . ( qq{<img src="$img_url/icon-cd.gif" alt="media">} x $backup->{volumes} ) . '</td>' .
+
+ "</tr>\n";
}
+
+ $retHTML .= "</table>";
+ $retHTML .= "</form>";
return $retHTML;
}
my $start_t = time();
my ($results, $files);
- if ($param->{'use_hest'}) {
- ($results, $files) = getFilesHyperEstraier($param, $offset);
+ if ($param->{'use_hest'} && length($hilite) > 0) {
+ ($results, $files) = getFilesHyperEstraier($param);
} else {
- ($results, $files) = getFiles($param, $offset);
+ ($results, $files) = getFiles($param);
}
my $dur_t = time() - $start_t;
</div>
<table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0">
<tr class="fviewheader">
- <td align="center">Share</td>
- <td align="center">Type and Name</td>
- <td align="center">#</td>
- <td align="center">Size</td>
- <td align="center">Date</td>
+ <td></td>
+ };
+
+ sub sort_header($$$$) {
+ my ($param, $display, $name, $align) = @_;
+
+ my ($sort_what, $sort_direction) = split(/_/,$param->{'sort'},2);
+
+ my $old_sort = $param->{'sort'};
+
+ my $html = qq{<td align="$align"};
+ my $arrow = '';
+
+ if (lc($sort_what) eq lc($name)) {
+ my $direction = lc($sort_direction);
+
+ # swap direction or fallback to default
+ $direction =~ tr/ad/da/;
+ $direction = 'a' unless ($direction =~ /[ad]/);
+
+ $param->{'sort'} = $name . '_' . $direction;
+ $html .= ' style="border: 1px solid #808080;"';
+
+ # add unicode arrow for direction
+ $arrow .= ' ';
+ $arrow .= $direction eq 'a' ? '▲'
+ : $direction eq 'd' ? '▼'
+ : ''
+ ;
+
+ } else {
+ $param->{'sort'} = $name . '_a';
+ }
+
+ $html .= '><a href="' . page_uri($param) . '">' . $display . '</a>' . $arrow . '</td>';
+ $param->{'sort'} = $old_sort;
+
+ return $html;
+ }
+
+ $retHTML .=
+ sort_header($param, 'Share', 'share', 'center') .
+ sort_header($param, 'Type and Name', 'path', 'center') .
+ sort_header($param, '#', 'num', 'center') .
+ sort_header($param, 'Size', 'size', 'center') .
+ sort_header($param, 'Date', 'date', 'center');
+
+ $retHTML .= qq{
<td align="center">Media</td>
</tr>
};
return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_);
}
+ my $sth_archived;
+ my %archived_cache;
+
+ sub check_archived($$$) {
+ my ($host, $share, $num) = @_;
+
+ if (my $html = $archived_cache{"$host $share $num"}) {
+ return $html;
+ }
+
+ $sth_archived ||= $dbh->prepare(qq{
+ select
+ dvd_nr, note,
+ count(archive_burned.copy) as copies
+ from archive
+ inner join archive_burned on archive_burned.archive_id = archive.id
+ inner join archive_backup on archive.id = archive_backup.archive_id
+ inner join backups on backups.id = archive_backup.backup_id
+ inner join hosts on hosts.id = backups.hostid
+ inner join shares on shares.id = backups.shareid
+ where hosts.name = ? and shares.name = ? and backups.num = ?
+ group by dvd_nr, note
+ });
+
+ my @mediums;
+
+ $sth_archived->execute($host, $share, $num);
+ while (my $row = $sth_archived->fetchrow_hashref()) {
+ push @mediums, '<abbr title="' .
+ $row->{'note'} .
+ ' [' . $row->{'copies'} . ']' .
+ '">' .$row->{'dvd_nr'} .
+ '</abbr>';
+ }
+
+ my $html = join(", ",@mediums);
+ $archived_cache{"$host $share $num"} = $html;
+ return $html;
+ }
+
+ my $i = $offset * $on_page;
+
foreach $file (@{ $files }) {
+ $i++;
+
my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'});
$retHTML .= qq{<tr class="fviewborder">};
+ $retHTML .= qq{<td class="fviewborder">$i</td>};
+
$retHTML .=
qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} .
qq{<td class="fviewborder"><img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" alt="$typeStr" align="middle"> } . hilite_html( $file->{'filepath'}, $hilite ) . qq{</td>} .
qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupnum'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'filepath'} )}, $file->{'backupnum'} ) . qq{</td>} .
qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} .
qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} .
- qq{<td class="fviewborder">} . $file->{'dvd'} . qq{</td>};
+ qq{<td class="fviewborder">} . check_archived( $file->{'hname'}, $file->{'sname'}, $file->{'backupnum'} ) . qq{</td>};
$retHTML .= "</tr>";
}
my $max_page = int( $results / $on_page );
my $page = 0;
- sub page_link($$$) {
- my ($param,$page,$display) = @_;
-
- $param->{'offset'} = $page;
+ sub page_uri($) {
+ my $param = shift || die "no param?";
- my $html = '<a href = "' . $MyURL;
+ my $uri = $MyURL;
my $del = '?';
foreach my $k (keys %{ $param }) {
if ($param->{$k}) {
- $html .= $del . $k . '=' . ${EscURI( $param->{$k} )};
+ $uri .= $del . $k . '=' . ${EscURI( $param->{$k} )};
$del = '&';
}
}
- $html .= '">' . $display . '</a>';
+ return $uri;
+ }
+
+ sub page_link($$$) {
+ my ($param,$page,$display) = @_;
+
+ $param->{'offset'} = $page if (defined($page));
+
+ my $html = '<a href = "' . page_uri($param) . '">' . $display . '</a>';
}
$retHTML .= '<div style="text-align: center;">';