/[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 146 - (show annotations)
Fri Oct 7 12:03:05 2005 UTC (18 years, 7 months ago) by iklaric
File size: 2264 byte(s)
 r159@klaxLaptop:  klax | 2005-10-07 13:14:47 +0200
 - switched from hardcoded sql's to $dbh->prepare() & execute()
 - various bugfixes

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 {
44 if ($key =~ m/fcb([0-9]+)_([0-9]+)/gi)
45 {
46 my $hostID = $1;
47 my $backupnum = $2;
48 push(@selectedBackups, ($hostID, $backupnum));
49 $total_size += BackupPC::SearchLib::getGzipSize($hostID, $backupnum);
50 }
51 }
52
53 # create new archive
54 my $sth = $dbh->prepare(q{
55 INSERT INTO archive (
56 id,
57 dvd_nr,
58 note,
59 username,
60 date
61 ) VALUES (
62 nextVal('archive_id_seq'),
63 nextVal('dvd_nr'),
64 ?,
65 ?,
66 NOW()
67 )
68 });
69
70 # FIXME insert user here
71 $sth->execute($In{'note'}, 'dummy_user');
72
73 if ($total_size > $Conf{MaxArchiveSize}) {
74 $cont .= eval( q{ ${h2(Error)}});
75 $cont .= "Selected backups exceed max archive size.";
76 } else {
77
78
79 foreach my $backup_id (@selected_backup_ids) {
80
81 # link backups with archive
82 my $sth = $dbh->prepare(q{
83 INSERT INTO archive_backup (
84 archive_id, backup_id, status
85 ) VALUES (
86 (SELECT last_value FROM archive_id_seq), ?, ?
87 )
88 });
89
90 $sth->execute($backup_id, 'ok');
91
92 $dbh->commit();
93
94 $cont .= qq{
95 Archived following backups:
96 } . join(",", @selected_backup_ids) . qq{
97 <br/>with following message:
98 <div style="border: 1px solid #e0e0e0">
99 } . $In{'note'} . qq{
100 </div>
101 };
102 }
103 $dbh->commit();
104 }
105 }
106
107 Header($Lang->{Burn_media}, "", 1, "", $cont);
108
109 Trailer();
110 $dbh->disconnect();
111 }
112
113 1;

  ViewVC Help
Powered by ViewVC 1.1.26