Storing xml now
Signed-off-by: Chris Cormack <crc@liblime.com> Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
parent
6ac79ef1e0
commit
0f315a2cd5
|
|
@ -23,6 +23,7 @@ require Exporter;
|
|||
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
|
||||
use C4::Context;
|
||||
use C4::Output;
|
||||
use XML::Simple;
|
||||
# use Smart::Comments;
|
||||
# use Data::Dumper;
|
||||
|
||||
|
|
@ -325,22 +326,28 @@ sub get_criteria {
|
|||
}
|
||||
|
||||
sub execute_query {
|
||||
my ( $sql, $type, $format ) = @_;
|
||||
my ( $sql, $type, $format, $id ) = @_;
|
||||
my $dbh = C4::Context->dbh();
|
||||
|
||||
# take this line out when in production
|
||||
$sql .= " LIMIT 10";
|
||||
if ($format eq 'url'){
|
||||
}
|
||||
else {
|
||||
$sql .= " LIMIT 10";
|
||||
}
|
||||
my $sth = $dbh->prepare($sql);
|
||||
$sth->execute();
|
||||
my $colnames=$sth->{'NAME'};
|
||||
my @results;
|
||||
my $row = join ('</th><th>',@$colnames);
|
||||
$row = "<tr><th>$row</th></tr>";
|
||||
my $row;
|
||||
my %temphash;
|
||||
$row = join ('</th><th>',@$colnames);
|
||||
$row = "<tr><th>$row</th></tr>";
|
||||
$temphash{'row'} = $row;
|
||||
push @results, \%temphash;
|
||||
|
||||
my $string;
|
||||
my %xmlhash;
|
||||
my $i=1;
|
||||
while ( my @data = $sth->fetchrow_array() ) {
|
||||
|
||||
# tabular
|
||||
|
|
@ -359,14 +366,25 @@ sub execute_query {
|
|||
$row = join(",",@data);
|
||||
$string .="\n" . $row;
|
||||
}
|
||||
|
||||
if ($format eq 'url'){
|
||||
my $temphash;
|
||||
@$temphash{@$colnames}=@data;
|
||||
$xmlhash{$i}=$temphash;
|
||||
$i++;
|
||||
}
|
||||
push @results, \%temphash;
|
||||
# }
|
||||
}
|
||||
$sth->finish();
|
||||
if ( $format eq 'text' || $format eq 'tab' || $format eq 'csv') {
|
||||
if ( $format eq 'text' || $format eq 'tab' || $format eq 'csv' ) {
|
||||
return $string;
|
||||
}
|
||||
elsif ($format eq 'url') {
|
||||
my $url;
|
||||
my $xml = XMLout(\%xmlhash);
|
||||
store_results($id,$xml);
|
||||
return $url;
|
||||
}
|
||||
else {
|
||||
return ( \@results );
|
||||
}
|
||||
|
|
@ -389,6 +407,15 @@ sub save_report {
|
|||
|
||||
}
|
||||
|
||||
sub store_results {
|
||||
my ($id,$xml)=@_;
|
||||
my $dbh = C4::Context->dbh();
|
||||
my $query = "INSERT INTO saved_reports (report_id,report,date_run) VALUES (?,?,now())";
|
||||
my $sth = $dbh->prepare($query);
|
||||
$sth->execute($id,$xml);
|
||||
$sth->finish();
|
||||
}
|
||||
|
||||
sub delete_report {
|
||||
my ( $id ) = @_;
|
||||
my $dbh = C4::Context->dbh();
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@
|
|||
<tr><td class="cell">Output Format</td>
|
||||
<td><select name="format">
|
||||
<option value="text">Text</option>
|
||||
<option value="url">URL</option>
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr><td class="cell">Email</td>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ my $message;
|
|||
if ($format eq 'text'){
|
||||
$message="<table>$results</table>";
|
||||
}
|
||||
if ($format eq 'url'){
|
||||
$message="something";
|
||||
}
|
||||
|
||||
if ($email){
|
||||
my $to = $email;
|
||||
|
|
|
|||
Loading…
Reference in New Issue