diff options
| author | ivan <ivan> | 2004-12-06 14:00:43 +0000 | 
|---|---|---|
| committer | ivan <ivan> | 2004-12-06 14:00:43 +0000 | 
| commit | dda497584a2e12907bba7cf07051fe34ede63b32 (patch) | |
| tree | 55dc30fe82643f7d638da30e0bb23d7e94d2223a | |
| parent | b5ca5dd85a6b1eacdc0888aedecadb716e625ec3 (diff) | |
1st try at adding custom field handling
| -rw-r--r-- | FS/FS/Conf.pm | 14 | ||||
| -rw-r--r-- | FS/FS/TicketSystem.pm | 4 | ||||
| -rw-r--r-- | FS/FS/TicketSystem/RT_External.pm | 95 | ||||
| -rw-r--r-- | FS/FS/TicketSystem/RT_Internal.pm | 14 | ||||
| -rw-r--r-- | FS/FS/TicketSystem/RT_Libs.pm | 3 | ||||
| -rwxr-xr-x | httemplate/search/cust_main.cgi | 36 | 
6 files changed, 157 insertions, 9 deletions
| diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 1346796af..b43fa1ab6 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1336,6 +1336,20 @@ httemplate/docs/config.html    },    { +    'key'         => 'ticket_system-custom_priority_field-values', +    'section'     => '', +    'description' => 'Values for the custom field from the ticketing system tobreak down and sort customer ticket lists.', +    'type'        => 'textarea', +  }, + +  { +    'key'         => 'ticket_system-custom_priority_field_queue', +    'section'     => '', +    'description' => 'Ticketing system queue in which the custom field specified in ticket_system-custom_priority_field is located.', +    'type'        => 'text', +  }, + +  {      'key'         => 'company_name',      'section'     => 'required',      'description' => 'Your company name', diff --git a/FS/FS/TicketSystem.pm b/FS/FS/TicketSystem.pm index 2a5c68f7d..9d961fc47 100644 --- a/FS/FS/TicketSystem.pm +++ b/FS/FS/TicketSystem.pm @@ -1,12 +1,12 @@  package FS::TicketSystem;  use strict; -use vars qw( $system $AUTOLOAD ); +use vars qw( $conf $system $AUTOLOAD );  use FS::Conf;  use FS::UID;  install_callback FS::UID sub {  -  my $conf = new FS::Conf; +  $conf = new FS::Conf;    $system = $conf->config('ticket_system');  }; diff --git a/FS/FS/TicketSystem/RT_External.pm b/FS/FS/TicketSystem/RT_External.pm index b74740ca7..a105c2752 100644 --- a/FS/FS/TicketSystem/RT_External.pm +++ b/FS/FS/TicketSystem/RT_External.pm @@ -1,6 +1,101 @@  package FS::TicketSystem::RT_External;  use strict; +use vars qw( $conf $priority_field $priority_field_queue $field ); +use FS::UID; + +install_callback FS::UID sub {  +  my $conf = new FS::Conf; +  $priority_field = +    $conf->config('ticket_system-custom_priority_field'); +  if ( $priority_field ) { +    $priority_field_queue = +      $conf->config('ticket_system-custom_priority_field_queue'); +    $field = $priority_field_queue +                  ? $priority_field_queue. '.%7B'. $priority_field. '%7D' +                  : $priority_field; +  } else { +    $priority_field_queue = ''; +    $field = ''; +  } +}; + +sub num_customer_tickets { +  my( $self, $custnum, $priority, $dbh ) = @_; + +  #$dbh ||= create one from some config options + +  my @param = (); +  my $priority_sql = ''; +  if ( defined($priority) ) { +    if ( length($priority) ) { +      my $queue_sql = " queue = ( select id from queues where queues.name = ? ) +                        or ( ? = '' and queue = 0 )"; +      $priority_sql = " +        and ? = ( select content from TicketCustomFieldValues +                   where ticket = tickets.id +                     and customfield = ( select id from customfields +                                          where name = ? +                                            and ( $queue_sql ) +                                       ) +                ) +      "; +      push @param, $priority, +                   $priority_field, +                   $priority_field_queue, +                   $priority_field_queue; +    } else { +      return '0nothandledyet0'; +    } +  } + +  my $sql = " +    select count(*) from tickets  +       where ( status = 'new' or status = 'open' or status = 'stalled' ) +         and target = 'freeside://freeside/cust_main/$custnum' +  "; + +  my $sth = $dbh->prepare($sql) or die $dbh->errstr; +  $sth->execute(@param)         or die $sth->errstr; + +  $sth->fetchrow_arrayref->[0]; + +} + +sub href_customer_tickets { +  my( $self, $custnum, $priority ) = @_; + +  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 ) { +    $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'; +  } + +  $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'; + +  if ( $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 ) { +    $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; +}  1; diff --git a/FS/FS/TicketSystem/RT_Internal.pm b/FS/FS/TicketSystem/RT_Internal.pm index ec0c3f7be..74006f577 100644 --- a/FS/FS/TicketSystem/RT_Internal.pm +++ b/FS/FS/TicketSystem/RT_Internal.pm @@ -2,6 +2,9 @@ package FS::TicketSystem::RT_Internal;  use strict;  use vars qw( @ISA ); +use FS::UID qw(dbh); +use FS::CGI qw(popurl); +use FS::TicketSystem::RT_Libs;  @ISA = qw( FS::TicketSystem::RT_Libs ); @@ -13,5 +16,16 @@ sub sql_customer_tickets {     )";  } +sub num_customer_tickets { +  my( $self, $custnum, $priority ) = ( shift, shift, shift ); +  $self->SUPER::new_customer_tickets( $custnum, $priority, dbh ); +} + +sub href_customer_tickets { +  my $self = shift; +  # well, 2 is wrong here but will have to do for now +  popurl(2).'rt/'. $self->SUPER::href_customer_tickets(@_); +} +  1; diff --git a/FS/FS/TicketSystem/RT_Libs.pm b/FS/FS/TicketSystem/RT_Libs.pm index aba783fdc..aebe8c562 100644 --- a/FS/FS/TicketSystem/RT_Libs.pm +++ b/FS/FS/TicketSystem/RT_Libs.pm @@ -1,7 +1,8 @@ -package FS::TicketSystem::RT_Libs.pm +package FS::TicketSystem::RT_Libs;  use strict;  use vars qw( @ISA ); +use FS::TicketSystem::RT_External;  @ISA = qw( FS::TicketSystem::RT_External ); diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index 48fbf41bb..7d15d1cfc 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -279,6 +279,7 @@ if ( scalar(@cust_main) == 1 && ! $cgi->param('referral_custnum') ) {      }      print ' cancelled customers</a> )';    } +    if ( $cgi->param('referral_custnum') ) {      $cgi->param('referral_custnum') =~ /^(\d+)$/        or eidiot "Illegal referral_custnum\n"; @@ -314,6 +315,13 @@ END            '</FORM>';    } +  my @custom_priorities = (); +  if ( $conf->config('ticket_system-custom_priority_field') +       && @{ $conf->config('ticket_system-custom_priority_field-values') } ) { +    @custom_priorities = +      $conf->config('ticket_system-custom_priority_field-values'); +  } +    print "<BR><BR>". $pager. &table(). <<END;        <TR>          <TH></TH> @@ -390,12 +398,28 @@ END      }      foreach my $addl_col ( @addl_cols ) { -      print "<TD ROWSPAN=$rowspan>".  -            qq!<A HREF="${p}rt/Search/Results.html?Order=ASC&Query=%20MemberOf%20%3D%20%27freeside%3A%2F%2Ffreeside%2Fcust_main%2F!. -            $cust_main->custnum.  -            qq!%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&Rows=50&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%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%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">!. -              $cust_main->get($addl_col). -            "</A></TD>"; +      print "<TD ROWSPAN=$rowspan ALIGN=right>"; +      if ( $addl_col eq 'tickets' ) { +        if ( @custom_priorities ) { +          foreach my $priority ( @custom_priorities ) { +            print '<A HREF="'. +                    FS::TicketSystem->href_customer_tickets($custnum,$priority). +                  '">'. +                  FS::TicketSystem->num_customer_tickets($custnum,$priority). +                  " $priority</A><BR>"; +          } +        } +        print '<A HREF="'. +              FS::TicketSystem->href_customer_tickets($cust_main->custnum, $p). +              '">'. +              $cust_main->get($addl_col); +        print ' total' +          if @custom_priorities; +        print "</A>"; +      } else { +        print $cust_main->get($addl_col); +      } +      print "</TD>";      }      my($n1)=''; | 
