248105f18aa56e8101e294e95b09265c5ef1a145
[freeside.git] / FS / FS / part_export / acct_sql_status.pm
1 package FS::part_export::acct_sql_status;
2 use base qw( FS::part_export::sql_Common );
3
4 use strict;
5 use warnings;
6 use vars qw( %info );
7 use Tie::IxHash;
8
9 tie my %options, 'Tie::IxHash', %{__PACKAGE__->sql_options};
10 delete $options{$_} for qw( table schema static primary_key );
11
12 %info = (
13   'svc'      => 'svc_acct',
14   'desc'     => 'Mailbox status information from SQL',
15   'options'  => \%options,
16   'nodomain' => '',
17   'no_machine' => 1,
18   'notes'    => <<END
19 Read mailbox status information (vacation and spam settings) from an SQL
20 database, tables "vacation" and "users" respectively.
21 END
22 );
23
24 sub rebless { shift; }
25
26 #don't want to inherit these from sql_Common
27 sub _export_insert    {}
28 sub _export_replace   {}
29 sub _export_delete    {}
30 sub _export_suspend   {}
31 sub _export_unsuspend {}
32
33 sub export_getstatus {
34   my($self, $svc_acct, $htmlref, $hashref) = @_;
35
36   my $dbh = DBI->connect( map $self->option($_), qw(datasrc username password) )
37     or return "can't connect: ".  $DBI::errstr;
38
39   ###
40   #vacation settings
41   ###
42
43   my $vsth = $dbh->prepare('SELECT * FROM vacation WHERE email = ?')
44     or return "can't prepare: ". $dbh->errstr;
45   $vsth->execute( $svc_acct->email )
46     or return "can't execute: ". $vsth->errstr;
47
48   my $vrow = $vsth->fetchrow_hashref;
49   if ( $vrow ) {
50     $hashref->{'vacation_active'}  = $vrow->{'active'};
51     $hashref->{'vacation_subject'} = $vrow->{'subject'};
52     $hashref->{'vacation_body'}    = $vrow->{'body'};
53 #what about these?
54 #| cache   | text         | NO   |     | NULL                |       |
55 #| domain  | varchar(255) | NO   |     | NULL                |       |
56 #and disabling "Sender e-mail address for auto-reply message:", no place for it
57   }
58
59   ###
60   #spam settings
61   ###
62
63   my $ssth = $dbh->prepare('SELECT * FROM users WHERE address = ?')
64     or return "can't prepare: ". $dbh->errstr;
65   $ssth->execute( $svc_acct->email )
66     or return "can't execute: ". $ssth->errstr;
67
68   my $srow = $ssth->fetchrow_hashref;
69   if ( $srow ) {
70     $hashref->{'spam_tag_level'}     = $srow->{'spam_tag_level'};
71     $hashref->{'spam_tag2_level'}    = $srow->{'spam_tag2_level'};
72     $hashref->{'spam_kill_level'}    = $srow->{'spam_kill_level'};
73     $hashref->{'bypass_spam_checks'} = $srow->{'bypass_spam_checks'};
74     $hashref->{'spam_tag2_level'}    = $srow->{'spam_tag2_level'};
75   }
76
77   ###
78   # spam allow/deny list
79   ###
80
81   #my $lsth = $dbh->prepare('SELECT * FROM 
82
83   #htmlref not implemented/used for this status export
84
85
86   ''; #no errors
87
88 }
89
90 1;