diff options
author | mark <mark> | 2009-08-09 09:05:38 +0000 |
---|---|---|
committer | mark <mark> | 2009-08-09 09:05:38 +0000 |
commit | 283ea2b5137ae3ec36882b492e6de024b0ce6027 (patch) | |
tree | 25edd2e6f0ba3446c13a5b3e4417cfba0447d62f /FS | |
parent | c183de0b7e942672cafdc1c14a203e389ffd2c43 (diff) |
Add cust_attachment stuff
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/AccessRight.pm | 3 | ||||
-rw-r--r-- | FS/FS/Conf.pm | 14 | ||||
-rw-r--r-- | FS/FS/Mason.pm | 1 | ||||
-rw-r--r-- | FS/FS/Record.pm | 8 | ||||
-rw-r--r-- | FS/FS/Schema.pm | 16 | ||||
-rw-r--r-- | FS/FS/cust_attachment.pm | 170 |
6 files changed, 209 insertions, 3 deletions
diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index 29cecd5..d192125 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -100,6 +100,9 @@ tie my %rights, 'Tie::IxHash', { rightname=>'Delete customer', desc=>"Enable customer deletions. Be very careful! Deleting a customer will remove all traces that this customer ever existed! It should probably only be used when auditing a legacy database. Normally, you cancel all of a customer's packages if they cancel service." }, #aka. deletecustomers 'Add customer note', #NEW 'Edit customer note', #NEW + 'Download attachment', #NEW + 'Add attachment', #NEW + 'Edit attachment', #NEW 'Bill customer now', #NEW 'Bulk send customer notices', #NEW ], diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 66f7457..1da5583 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -736,6 +736,20 @@ worry that config_items is freeside-specific and icky. }, { + 'key' => 'disable_cust_attachment', + 'section' => '', + 'description' => 'Disable customer file attachments', + 'type' => 'checkbox', + }, + + { + 'key' => 'max_attachment_size', + 'section' => '', + 'description' => 'Maximum size for customer file attachments (leave blank for unlimited)', + 'type' => 'text', + }, + + { 'key' => 'disable_customer_referrals', 'section' => 'UI', 'description' => 'Disable new customer-to-customer referrals in the web interface', diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index ed99bf6..d73d381 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -186,6 +186,7 @@ Initializes the Mason environment, loads all Freeside and RT libraries, etc. use FS::part_pkg_taxrate; use FS::tax_rate; use FS::part_pkg_report_option; + use FS::cust_attachment; use FS::h_cust_pkg; use FS::h_svc_acct; use FS::h_svc_broadband; diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 9e1c0e8..11afd9f 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -55,14 +55,13 @@ FS::UID->install_callback( sub { $conf_encryption = $conf->exists('encryption'); $File::CounterFile::DEFAULT_DIR = $conf->base_dir . "/counters.". datasrc; if ( driver_name eq 'Pg' ) { - eval "use DBD::Pg qw(:pg_types);"; + eval "use DBD::Pg ':pg_types'"; die $@ if $@; } else { eval "sub PG_BYTEA { die 'guru meditation #9: calling PG_BYTEA when not running Pg?'; }"; } } ); - =head1 NAME FS::Record - Database record objects @@ -2718,7 +2717,10 @@ sub _quote { ) { no strict 'subs'; - dbh->quote($value, PG_BYTEA); +# dbh->quote($value, { pg_type => PG_BYTEA() }); # doesn't work right + # Pg binary string quoting: convert each character to 3-digit octal prefixed with \\, + # single-quote the whole mess, and put an "E" in front. + return ("E'" . join('', map { sprintf('\\\\%03o', ord($_)) } split(//, $value) ) . "'"); } else { dbh->quote($value); } diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 80aed82..0ede000 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -372,6 +372,22 @@ sub tables_hashref { 'index' => [ ['typenum'] ], }, + 'cust_attachment' => { + 'columns' => [ + 'attachnum', 'serial', '', '', '', '', + 'custnum', 'int', '', '', '', '', + '_date', @date_type, '', '', + 'otaker', 'varchar', '', 32, '', '', + 'filename', 'varchar', '', 32, '', '', + 'mime_type', 'varchar', '', 32, '', '', + 'body', 'blob', 'NULL', '', '', '', + 'disabled', @date_type, '', '', + ], + 'primary_key' => 'attachnum', + 'unique' => [], + 'index' => [ ['custnum'] ], + }, + 'cust_bill' => { 'columns' => [ 'invnum', 'serial', '', '', '', '', diff --git a/FS/FS/cust_attachment.pm b/FS/FS/cust_attachment.pm new file mode 100644 index 0000000..9527381 --- /dev/null +++ b/FS/FS/cust_attachment.pm @@ -0,0 +1,170 @@ +package FS::cust_attachment; + +use strict; +use base qw( FS::Record ); +use FS::Record qw( qsearch qsearchs ); +use FS::Conf; + +=head1 NAME + +FS::cust_attachment - Object methods for cust_attachment records + +=head1 SYNOPSIS + + use FS::cust_attachment; + + $record = new FS::cust_attachment \%hash; + $record = new FS::cust_attachment { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::cust_attachment object represents a file attached to a L<FS::cust_main> +object. FS::cust_attachment inherits from FS::Record. The following fields +are currently supported: + +=over 4 + +=item attachnum + +Primary key (assigned automatically). + +=item custnum + +Customer number (see L<FS::cust_main>). + +=item _date + +The date the record was last updated. + +=item otaker + +Order taker (assigned automatically; see L<FS::UID>). + +=item filename + +The file's name. + +=item mime_type + +The Content-Type of the file. + +=item body + +The contents of the file. + +=item disabled + +If the attachment was disabled, this contains the date it was disabled. + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new attachment object. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'cust_attachment'; } + +sub nohistory_fields { 'body'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +=item delete + +Delete this record from the database. + +=cut + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +# the replace method can be inherited from FS::Record + +=item check + +Checks all fields to make sure this is a valid example. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + my $conf = new FS::Conf; + my $error; + if($conf->config('disable_cust_attachment') ) { + $error = 'Attachments disabled (see configuration)'; + } + + $error = + $self->ut_numbern('attachnum') + || $self->ut_number('custnum') + || $self->ut_numbern('_date') + || $self->ut_text('otaker') + || $self->ut_text('filename') + || $self->ut_text('mime_type') + || $self->ut_numbern('disabled') + || $self->ut_anything('body') + ; + if($conf->config('max_attachment_size') + and $self->size > $conf->config('max_attachment_size') ) { + $error = 'Attachment too large' + } + return $error if $error; + + $self->SUPER::check; +} + +=item size + +Returns the size of the attachment in bytes. + +=cut + +sub size { + my $self = shift; + return length($self->body); +} + +=back + +=head1 BUGS + +Doesn't work on non-Postgres systems. + +=head1 SEE ALSO + +L<FS::Record>, schema.html from the base documentation. + +=cut + +1; + |