/[BackupPC]/trunk/lib/BackupPC/CGI/BurnMedia.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/BackupPC/CGI/BurnMedia.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 165 - (show annotations)
Mon Oct 10 13:57:29 2005 UTC (18 years, 6 months ago) by dpavlin
File size: 2623 byte(s)
 r8442@llin:  dpavlin | 2005-10-10 15:57:24 +0200
 insert real user in archives

1 package BackupPC::CGI::BurnMedia;
2
3 use strict;
4 use BackupPC::CGI::Lib qw(:all);
5 use BackupPC::SearchLib;
6 use Data::Dumper;
7 use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc);
8
9 my $dsn = $Conf{SearchDSN};
10 my $db_user = $Conf{SearchUser} || '';
11
12 sub action() {
13 my $cont = "";
14 my $title;
15 my $subtitle;
16 my @files;
17
18 my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 0 } );
19
20 BackupPC::CGI::Lib::NewRequest();
21 # $cont = Dumper(%In);
22 if (!defined($In{submitBurner})) {
23 $title = eval(q{ ${h1($Lang->{Burn_media})}});
24 $cont = Dumper(%In);
25 $subtitle = eval(q{ ${h2($Lang->{Burn_media_select})}});
26 $cont = <<EOF;
27
28 $title
29 $subtitle
30
31 EOF
32
33 $cont .= "Backups that have not been archived:<br>";
34 $cont .= BackupPC::SearchLib::displayBackupsGrid();
35
36 } else {
37
38 my @selected_backup_ids;
39
40 my $total_size = 0;
41
42 foreach my $key(keys(%In)) {
43 if ($key =~ m/^fcb([0-9]+)_([0-9]+)_([0-9]+)$/gi) {
44 my ($host_id, $backup_num, $backup_id) = ($1,$2,$3);
45 push @selected_backup_ids, $backup_id;
46 $total_size += BackupPC::SearchLib::getGzipSize($host_id, $backup_num);
47 }
48 }
49
50 if (($total_size / 1024) > $Conf{MaxArchiveSize}) {
51 $cont .= eval( q{ ${h2(Error)}});
52 $cont .= "Selected backups size $total_size exceed max archive size $Conf{MaxArchiveSize}.";
53 } else {
54
55 # create new archive
56 my $sth = $dbh->prepare(q{
57 INSERT INTO archive (
58 id,
59 dvd_nr,
60 note,
61 username,
62 date,
63 total_size
64 ) VALUES (
65 nextVal('archive_id_seq'),
66 nextVal('dvd_nr'),
67 ?,
68 ?,
69 NOW(),
70 ?
71 )
72 });
73
74 $sth->execute($In{'note'}, $User, $total_size);
75
76 foreach my $backup_id (@selected_backup_ids) {
77
78 # link backups with archive
79 my $sth = $dbh->prepare(q{
80 INSERT INTO archive_backup (
81 archive_id, backup_id
82 ) VALUES (
83 (SELECT last_value FROM archive_id_seq), ?
84 )
85 });
86
87 $sth->execute($backup_id);
88
89 $dbh->commit();
90
91 }
92
93 my ($dvd_nr) = $dbh->selectrow_array(qq{
94 select last_value from dvd_nr
95 });
96
97 $dvd_nr ||= 'error';
98
99 $dbh->commit();
100
101 $cont .= q{
102 Archived following backups:
103 } . join(", ", @selected_backup_ids) . q{
104 <br/>with total size of
105 <b>} . sprintf("%1.2f Mb", $total_size / 1024 / 1024) . q{</b>
106 to media <b>} . $dvd_nr . q{</b>
107 with following message:
108 <div style="background-color: #e0e0e0; display: inline; padding: 2px;">
109 } . $In{'note'} . q{
110 </div>
111 };
112 }
113 }
114
115 Header($Lang->{Burn_media}, "", 1, "", $cont);
116
117 Trailer();
118 $dbh->disconnect();
119 }
120
121 1;

  ViewVC Help
Powered by ViewVC 1.1.26