2 package BackupPC::SearchLib;
5 use BackupPC::CGI::Lib qw(:all);
6 use BackupPC::Attrib qw(:all);
13 my $dbh = DBI->connect( "dbi:SQLite:dbname=$Conf{SearchDB}",
14 "", "", { RaiseError => 1, AutoCommit => 1 } );
17 " SELECT shares.ID AS ID, shares.share AS name FROM shares;");
19 push (@ret, { 'ID' => '', 'name' => '-'});
20 while ( $tmp = $st->fetchrow_hashref() ) {
21 push( @ret, { 'ID' => $tmp->{'ID'}, 'name' => $tmp->{'name'} } );
36 if ( defined( $param->{'search_backup_day_from'} ) && $param->{'search_backup_day_from'} ne "") {
38 ' strftime("%d", datetime(backups.date, "unixepoch","localtime")) >= "'
39 . $param->{'search_backup_day_from'} ."\"");
41 if ( defined( $param->{'search_backup_day_to'} ) && $param->{'search_backup_day_to'} ne "") {
43 ' strftime("%d", datetime(backups.date, "unixepoch","localtime")) <= "'
44 . $param->{'search_backup_day_from'} ."\"");
46 if ( defined( $param->{'search_backup_month_from'} ) && $param->{'search_backup_month_from'} ne "") {
48 ' strftime("%m", datetime(backups.date, "unixepoch","localtime")) >= "'
49 . $param->{'search_backup_month_from'} ."\"");
51 if ( defined( $param->{'search_backup_month_to'} ) && $param->{'search_backup_month_to'} ne "") {
53 ' strftime("%m", datetime(backups.date, "unixepoch","localtime")) <= "'
54 . $param->{'search_backup_month_to'} ."\"");
56 if ( defined( $param->{'search_backup_year_from'} ) && $param->{'search_backup_year_from'} ne "") {
58 ' strftime("%Y", datetime(backups.date, "unixepoch","localtime")) >= "'
59 . $param->{'search_backup_year_from'} ."\"");
61 if ( defined( $param->{'search_backup_year_to'} ) && $param->{'search_backup_year_to'} ne "") {
63 ' strftime("%Y", datetime(backups.date, "unixepoch","localtime")) <= "'
64 . $param->{'search_backup_year_to'} ."\"");
67 if ( defined( $param->{'search_day_from'} ) && $param->{'search_day_from'} ne "" ) {
69 ' strftime("%d", datetime(files.date, "unixepoch","localtime")) >= "'
70 . $param->{'search_day_from'} ."\"");
72 if ( defined( $param->{'search_month_from'} ) && $param->{'search_month_from'} ne "") {
74 ' strftime("%m", datetime(files.date, "unixepoch","localtime")) >= "'
75 . $param->{'search_month_from'} ."\"");
77 if ( defined( $param->{'search_year_from'} ) && $param->{'search_year_from'} ne "") {
79 ' strftime("%Y", datetime(files.date, "unixepoch","localtime")) >= "'
80 . $param->{'search_year_from'} ."\"");
82 if ( defined( $param->{'search_day_to'} ) && $param->{'search_day_to'} ne "" ) {
84 ' strftime("%d", datetime(files.date, "unixepoch","localtime")) <= "'
85 . $param->{'search_day_to'} ."\"");
87 if ( defined( $param->{'search_month_to'} ) && $param->{'search_month_to'} ne "" ) {
89 ' strftime("%m", datetime(files.date, "unixepoch","localtime")) <= "'
90 . $param->{'search_month_to'} ."\"" );
92 if ( defined( $param->{'search_year_to'} )&& $param->{'search_year_to'} ne "" ) {
94 ' strftime("%Y", datetime(files.date, "unixepoch","localtime")) <= "'
95 . $param->{'search_year_to'} ."\"");
98 if ( defined( $param->{'search_host'} ) && $param->{'search_host'} ne "") {
99 push( @conditions, ' backups.hostID = ' . $param->{'search_host'} );
102 if ( defined ($param->{'search_filename'}) && $param->{'search_filename'} ne "") {
103 push (@conditions, " files.name LIKE '".$param->{'search_filename'}."%'");
107 foreach $cond(@conditions)
124 my $dbh = DBI->connect( "dbi:SQLite:dbname=$Conf{SearchDB}",
125 "", "", { RaiseError => 1, AutoCommit => 1 } );
128 SELECT files.id AS fid,
130 shares.name AS sname,
131 shares.share AS sharename,
132 backups.num AS backupNum,
133 files.name AS filename,
134 files.path AS filepath,
135 shares.share||files.fullpath AS networkPath,
136 date(files.date, 'unixepoch', 'localtime') AS date,
137 files.type AS filetype,
142 INNER JOIN shares ON files.shareID=shares.ID
143 INNER JOIN hosts ON hosts.ID = shares.hostID
144 INNER JOIN backups ON backups.hostID = hosts.ID
145 LEFT JOIN dvds ON dvds.ID = files.dvdid
149 if (defined($where) && $where ne "")
151 $sql .= " WHERE ". $where;
155 my $st = $dbh->prepare(
164 while ($tmp = $st->fetchrow_hashref())
167 'hname' => $tmp->{'hname'},
168 'sname' => $tmp->{'sname'},
169 'sharename' => $tmp->{'sharename'},
170 'backupno' => $tmp->{'backupNum'},
171 'fname' => $tmp->{'filename'},
172 'fpath' => $tmp->{'filepath'},
173 'networkpath' => $tmp->{'networkPath'},
174 'date' => $tmp->{'date'},
175 'type' => $tmp->{'filetype'},
176 'size' => $tmp->{'size'},
177 'id' => $tmp->{'fid'},
178 'dvd' => $tmp->{'dvd'}
189 sub getBackupsNotBurned()
191 my $dbh = DBI->connect( "dbi:SQLite:dbname=$Conf{SearchDB}",
192 "", "", { RaiseError => 1, AutoCommit => 1 } );
197 backups.num AS backupno,
198 backups.type AS type,
200 FROM backups, shares, files, hosts
202 backups.num = files.backupNum AND
203 shares.ID = files.shareID AND
204 backups.hostID = shares.hostID AND
205 hosts.ID = backups.hostID AND
208 backups.hostID, backups.num
210 my $st = $dbh -> prepare( $sql );
214 while ( my $tmp = $st -> fetchrow_hashref() )
217 'host' => $tmp->{'host'},
218 'hostid' => $tmp->{'hostID'},
219 'backupno' => $tmp->{'backupno'},
220 'type' => $tmp->{'type'},
221 'date' => $tmp->{'date'}
229 sub displayBackupsGrid()
238 <script language="javascript" type="text/javascript">
241 function checkAll(location)
243 for (var i=0;i<document.forma.elements.length;i++)
245 var e = document.forma.elements[i];
246 if ((e.checked || !e.checked) && e.name != \'all\') {
247 if (eval("document.forma."+location+".checked")) {
258 $retHTML .= q{<form name="forma" method="POST" action="}."$MyURL"."?action=burn\"";
259 $retHTML.= q{<input type="hidden" value="burn" name="action">};
260 $retHTML .= q{<input type="hidden" value="results" name="search_results">};
262 $retHTML .= "<table style=\"fview\">";
266 $retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>";
268 $retHTML .= "<td class=\"tableheader\">Host</td> <td class=\"tableheader\">Backup no</td> <td class=\"tableheader\">Type</td> <td class=\"tableheader\">date</td></tr>";
269 my @backups = getBackupsNotBurned();
275 $retHTML .= "<td colspan=7 style=\"tableheader\">";
276 $retHTML .= "<input type=\"submit\" value=\"Burn selected backups on medium\" name=\"submitBurner\">";
281 foreach $backup(@backups)
288 $retHTML .= "<td class=\"fview\"> <input type=\"checkbox\" name=\"fcb"
289 .$backup->{'hostid'}."_".$backup->{'backupno'}
290 ."\" value=\"".$backup->{'hostid'}."_".$backup->{'backupno'}."\"> </td>";
293 $retHTML .= "<td class=\"fviewborder\">" . $backup->{'host'} . "</td>";
294 $retHTML .= "<td class=\"fviewborder\">" . $backup->{'backupno'} . "</td>";
295 $retHTML .= "<td class=\"fviewborder\">" . $backup->{'type'} . "</td>";
296 $retHTML .= "<td class=\"fviewborder\">" . $backup->{'date'} . "<td>";
299 $retHTML .= "</table>";
302 $retHTML .= "</form>";
312 my ($where, $addForm) = @_;
318 <script language="javascript" type="text/javascript">
321 function checkAll(location)
323 for (var i=0;i<document.forma.elements.length;i++)
325 var e = document.forma.elements[i];
326 if ((e.checked || !e.checked) && e.name != \'all\') {
327 if (eval("document.forma."+location+".checked")) {
340 $retHTML .= q{<form name="forma" method="POST" action="}."$MyURL"."?action=burn\"";
341 $retHTML.= q{<input type="hidden" value="burn" name="action">};
342 $retHTML .= q{<input type="hidden" value="results" name="search_results">};
344 $retHTML .= "<table style=\"fview\">";
348 $retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>";
350 $retHTML .= "<td class=\"tableheader\">Host</td> <td class=\"tableheader\">Name</td> <td class=\"tableheader\">Type</td> <td class=\"tableheader\">backup no.</td> <td class=\"tableheader\">size</td> <td class=\"tableheader\">date</td> <td class=\"tableheader\">Media</td></tr>";
351 my @files = getFiles($where);
357 $retHTML .= "<td colspan=7 style=\"tableheader\">";
358 $retHTML .= "<input type=\"submit\" value=\"Burn selected files on medium\" name=\"submitBurner\">";
363 foreach $file(@files)
367 if ($file->{'type'} == BPC_FTYPE_DIR)
378 $retHTML .= "<td class=\"fview\"> <input type=\"checkbox\" name=\"fcb"
380 ."\" value=\"".$file->{'id'}."\"> </td>";
383 $retHTML .= "<td class=\"fviewborder\">" . $file->{'hname'} ."</td>";
384 $retHTML .= "<td class=\"fviewborder\">" . $file->{'fname'} . "</td>";
385 $retHTML .= "<td class=\"fviewborder\">" . $ftype . "</td>";
386 $retHTML .= "<td class=\"fviewborder\">" . $file->{'backupno'} . "</td>";
387 $retHTML .= "<td class=\"fviewborder\">" . $file->{'size'} . "</td>";
388 $retHTML .= "<td class=\"fviewborder\">" . $file->{'date'} . "</td>";
389 $retHTML .= "<td class=\"fviewborder\">" . $file->{'dvd'} . "</td>";
392 $retHTML .= "</table>";
395 $retHTML .= "</form>";