X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTicketSystem%2FRT_External.pm;h=63eee867b347220f3cdeac59753bed548875b809;hb=e6af2112aae23d3d15a24e70978c3c277a93f2f9;hp=7a39c915333ee4ca75396b22c32eef97ef8000da;hpb=8d4abaa99403699aa5b5f02e899d2ea33980f913;p=freeside.git diff --git a/FS/FS/TicketSystem/RT_External.pm b/FS/FS/TicketSystem/RT_External.pm index 7a39c9153..63eee867b 100644 --- a/FS/FS/TicketSystem/RT_External.pm +++ b/FS/FS/TicketSystem/RT_External.pm @@ -1,11 +1,15 @@ package FS::TicketSystem::RT_External; use strict; -use vars qw( $conf $priority_field $priority_field_queue $field ); +use vars qw( $conf $default_queueid + $priority_field $priority_field_queue $field + $external_dbh $external_url ); +use URI::Escape; use FS::UID; install_callback FS::UID sub { my $conf = new FS::Conf; + $default_queueid = $conf->config('ticket_system-default_queueid'); $priority_field = $conf->config('ticket_system-custom_priority_field'); if ( $priority_field ) { @@ -18,12 +22,22 @@ install_callback FS::UID sub { $priority_field_queue = ''; $field = ''; } + + $external_url = ''; + if ($conf->config('ticket_system') eq 'RT_External') { + my ($datasrc, $user, $pass) = $conf->config('ticket_system-rt_external_datasrc'); + $external_dbh = DBI->connect($datasrc, $user, $pass, { 'ChopBlanks' => 1 }) + or die "RT_External DBI->connect error: $DBI::errstr\n"; + + $external_url = $conf->config('ticket_system-rt_external_url'); + } + }; sub num_customer_tickets { my( $self, $custnum, $priority, $dbh ) = @_; - #$dbh ||= create one from some config options + $dbh ||= $external_dbh; my( $from_sql, @param) = $self->_from_customer( $custnum, $priority ); @@ -39,10 +53,12 @@ sub customer_tickets { my( $self, $custnum, $limit, $priority, $dbh ) = @_; $limit ||= 0; - #$dbh ||= create one from some config options + $dbh ||= $external_dbh; my( $from_sql, @param) = $self->_from_customer( $custnum, $priority ); - my $sql = "select * $from_sql order by priority desc limit $limit"; + my $sql = "select tickets.*, queues.name". + ( length($priority) ? ", ticketcustomfieldvalues.content" : '' ). + " $from_sql order by priority desc limit $limit"; my $sth = $dbh->prepare($sql) or die $dbh->errstr. "preparing $sql"; $sth->execute(@param) or die $sth->errstr. "executing $sql"; @@ -115,51 +131,88 @@ sub _from_customer { } -sub href_customer_tickets { +sub _href_customer_tickets { my( $self, $custnum, $priority ) = @_; + #i snarfed this from an RT bookmarked search, it could be unescaped in the + #source for readability and run through uri_escape my $href = 'Search/Results.html?Order=ASC&Query=%20MemberOf%20%3D%20%27freeside%3A%2F%2Ffreeside%2Fcust_main%2F'. $custnum. '%27%20%20AND%20%28%20Status%20%3D%20%27open%27%20%20OR%20Status%20%3D%20%27new%27%20%20OR%20Status%20%3D%20%27stalled%27%20%29%20' ; - if ( $priority && $field && $priority_field_queue ) { + if ( defined($priority) && $field && $priority_field_queue ) { $href .= 'AND%20Queue%20%3D%20%27'. $priority_field_queue. '%27%20'; } - if ( $priority && $field ) { - $href .= '%20AND%20%27CF.'. $field. '%27%20%3D%20%27'. $priority. '%27%20'; + if ( defined($priority) && $field ) { + $href .= '%20AND%20%27CF.'. $field. '%27%20'; + if ( $priority ) { + $href .= '%3D%20%27'. $priority. '%27%20'; + } else { + $href .= 'IS%20%27NULL%27%20'; + } } $href .= '&Rows=100'. '&OrderBy=id&Page=1'. - '&Format=%27%20%20%20%3Cb%3E%3Ca%20href%3D%22%2Ffreeside%2Frt%2FTicket%2FDisplay.html%3Fid%3D__id__%22%3E__id__%3C%2Fa%3E%3C%2Fb%3E%2FTITLE%3A%23%27%2C%20%0A%27%3Cb%3E%3Ca%20href%3D%22%2Ffreeside%2Frt%2FTicket%2FDisplay.html%3Fid%3D__id__%22%3E__Subject__%3C%2Fa%3E%3C%2Fb%3E%2FTITLE%3ASubject%27%2C%20%0A%27__Status__%27%2C%20'; + '&Format=%27%20%20%20%3Cb%3E%3Ca%20href%3D%22'. + $self->baseurl. + 'Ticket%2FDisplay.html%3Fid%3D__id__%22%3E__id__%3C%2Fa%3E%3C%2Fb%3E%2FTITLE%3A%23%27%2C%20%0A%27%3Cb%3E%3Ca%20href%3D%22'. + $self->baseurl. + 'Ticket%2FDisplay.html%3Fid%3D__id__%22%3E__Subject__%3C%2Fa%3E%3C%2Fb%3E%2FTITLE%3ASubject%27%2C%20%0A%27__Status__%27%2C%20'; - if ( $priority && $field ) { + if ( defined($priority) && $field ) { $href .= '%0A%27__CustomField.'. $field. '__%2FTITLE%3ASeverity%27%2C%20'; } $href .= '%0A%27__QueueName__%27%2C%20%0A%27__OwnerName__%27%2C%20%0A%27__Priority__%27%2C%20%0A%27__NEWLINE__%27%2C%20%0A%27%27%2C%20%0A%27%3Csmall%3E__Requestors__%3C%2Fsmall%3E%27%2C%20%0A%27%3Csmall%3E__CreatedRelative__%3C%2Fsmall%3E%27%2C'; - if ( $priority && $field ) { + if ( defined($priority) && $field ) { $href .= '%20%0A%27__-__%27%2C'; } $href .= '%20%0A%27%3Csmall%3E__ToldRelative__%3C%2Fsmall%3E%27%2C%20%0A%27%3Csmall%3E__LastUpdatedRelative__%3C%2Fsmall%3E%27%2C%20%0A%27%3Csmall%3E__TimeLeft__%3C%2Fsmall%3E%27'; $href; + +} + +sub href_customer_tickets { + my $self = shift; + $self->baseurl. $self->_href_customer_tickets(@_); } +sub _href_new_ticket { + my( $self, $custnum, $requestors ) = @_; + + 'Ticket/Create.html?'. + "Queue=$default_queueid". + "&new-MemberOf=freeside://freeside/cust_main/$custnum". + ( $requestors ? '&Requestors='. uri_escape($requestors) : '' ) + ; +} + sub href_new_ticket { - my( $self, $custnum ) = @_; - 'Ticket/Create.html?Queue=1&new-MemberOf=freeside://freeside/cust_main/'.$custnum; + my $self = shift; + $self->baseurl. $self->_href_new_ticket(@_); } -sub href_ticket { +sub _href_ticket { my($self, $ticketnum) = @_; 'Ticket/Display.html?id='.$ticketnum; } +sub href_ticket { + my $self = shift; + $self->baseurl. $self->_href_ticket(@_); +} + +sub baseurl { + #my $self = shift; + $external_url; +} + 1;