From 6ac45d15e85b10e3d63645c26a0a2acbad103df1 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Sat, 18 Jan 2014 19:13:14 -0800 Subject: [PATCH] FS/FS/pbx_extension.pm --- FS/FS.pm | 2 + FS/FS/Schema.pm | 19 +++++ FS/FS/svc_pbx.pm | 2 +- FS/t/pbx_extension.t | 5 ++ httemplate/edit/process/svc_pbx.html | 13 ++++ httemplate/edit/svc_pbx.html | 52 ++++++++++++++ httemplate/elements/pbx_extension.html | 113 ++++++++++++++++++++++++++++++ httemplate/elements/tr-pbx_extension.html | 24 +++++++ httemplate/view/svc_pbx.cgi | 51 ++++++++++++-- 9 files changed, 276 insertions(+), 5 deletions(-) create mode 100644 FS/t/pbx_extension.t create mode 100644 httemplate/edit/process/svc_pbx.html create mode 100644 httemplate/edit/svc_pbx.html create mode 100644 httemplate/elements/pbx_extension.html create mode 100644 httemplate/elements/tr-pbx_extension.html diff --git a/FS/FS.pm b/FS/FS.pm index afea6f122..11d8b6e0f 100644 --- a/FS/FS.pm +++ b/FS/FS.pm @@ -204,6 +204,8 @@ L - Externally tracked service class. L - PBX service class +L - PBX extension class + L - Certificate service class L - Dish network service class diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 3cb1b773a..2300c07fc 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -5657,6 +5657,25 @@ sub tables_hashref { ], }, + 'pbx_extension' => { + 'columns' => [ + 'extensionnum', 'serial', '', '', '', '', + 'svcnum', 'int', '', '', '', '', + 'extension', 'varchar', '', $char_d, '', '', + 'pin', 'varchar', 'NULL', $char_d, '', '', + 'sip_password', 'varchar', 'NULL', $char_d, '', '', + 'phone_name', 'varchar', 'NULL', $char_d, '', '', + ], + 'primary_key' => 'extensionnum', + 'unique' => [ [ 'svcnum', 'extension' ] ], + 'index' => [ [ 'svcnum' ] ], + 'foreign_keys' => [ + { columns => [ 'svcnum' ], + table => 'svc_pbx', + }, + ], + }, + 'svc_mailinglist' => { #svc_group? 'columns' => [ 'svcnum', 'int', '', '', '', '', diff --git a/FS/FS/svc_pbx.pm b/FS/FS/svc_pbx.pm index 7c228f8b5..7899621b2 100644 --- a/FS/FS/svc_pbx.pm +++ b/FS/FS/svc_pbx.pm @@ -1,5 +1,5 @@ package FS::svc_pbx; -use base qw( FS::svc_External_Common ); +use base qw( FS::o2m_Common FS::svc_External_Common ); use strict; use Tie::IxHash; diff --git a/FS/t/pbx_extension.t b/FS/t/pbx_extension.t new file mode 100644 index 000000000..796c9aa49 --- /dev/null +++ b/FS/t/pbx_extension.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::pbx_extension; +$loaded=1; +print "ok 1\n"; diff --git a/httemplate/edit/process/svc_pbx.html b/httemplate/edit/process/svc_pbx.html new file mode 100644 index 000000000..15023a4b9 --- /dev/null +++ b/httemplate/edit/process/svc_pbx.html @@ -0,0 +1,13 @@ +<& elements/svc_Common.html, + table => 'svc_pbx', + edit_ext => 'html', + process_o2m => { table => 'pbx_extension', + fields => [qw( extension pin sip_password phone_name )], + }, +&> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific? + + diff --git a/httemplate/edit/svc_pbx.html b/httemplate/edit/svc_pbx.html new file mode 100644 index 000000000..d973bf5e9 --- /dev/null +++ b/httemplate/edit/svc_pbx.html @@ -0,0 +1,52 @@ +<& elements/svc_Common.html, + 'table' => 'svc_pbx', + + 'end_callback' => sub { + my( $cgi, $svc_pbx, $fields, $opt ) = @_; + $opt->{labels}{extensionnum} = ' '; + push @$fields, + { type => 'tablebreak-tr-title', + value => 'Extensions', + }, + { + field => 'extensionnum', + type => 'pbx_extension', + o2m_table => 'pbx_extension', + m2_label => ' ', + m2_error_callback => $m2_error_callback, + }, + ; + + }, + +&> +<%init> + +my $m2_error_callback = sub { + my($cgi, $object) = @_; + + #process_o2m fields in process/svc_pbx.html + my @fields = qw( extension pin sip_password phone_name ); + my @gfields = ( '', map "_$_", @fields ); + + map { + if ( /^extensionnum(\d+)$/ ) { + my $num = $1; + if ( grep $cgi->param("extensionnum$num$_"), @gfields ) { + my $x = new FS::pbx_extension { + 'extensionnum' => scalar($cgi->param("extensionnum$num")), + map { $_ => scalar($cgi->param("extensionnum${num}_$_")) } @fields, + }; + $x; + } else { + (); + } + } else { + (); + } + } + $cgi->param; +}; + + + diff --git a/httemplate/elements/pbx_extension.html b/httemplate/elements/pbx_extension.html new file mode 100644 index 000000000..62a1f5172 --- /dev/null +++ b/httemplate/elements/pbx_extension.html @@ -0,0 +1,113 @@ +% unless ( $opt{'js_only'} ) { + + + + + + +% ### +% # extension +% ### + + +% ### +% # pin +% ### + + +% ### +% # sip_password +% ### + + +% ### +% # phone_name +% ### + + + +
+ + > +
+ Extension +
+ + > +
+ PIN +
+ + MAXLENGTH = <% $passwordmax + 2 %> + <% $onchange %> + > +
+ SIP Password +
+ + > +
+ Name +
+ +% } +<%init> + +my( %opt ) = @_; + +my $conf = new FS::Conf; +my $passwordmax = $conf->config('sip_passwordmax') || 80; + +my $name = $opt{'element_name'} || $opt{'field'} || 'extensionnum'; +my $id = $opt{'id'} || 'extensionnum'; + +my $curr_value = $opt{'curr_value'} || $opt{'value'}; + +my $onchange = ''; +if ( $opt{'onchange'} ) { + $onchange = $opt{'onchange'}; + $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/; + $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack. all onchange + #callbacks should act the same + $onchange = 'onChange="'. $onchange. '"'; +} + +my $pbx_extension = $curr_value + ? qsearchs('pbx_extension', { 'extensionnum' => $curr_value } ) + : new FS::pbx_extension {}; + + diff --git a/httemplate/elements/tr-pbx_extension.html b/httemplate/elements/tr-pbx_extension.html new file mode 100644 index 000000000..a9d640d51 --- /dev/null +++ b/httemplate/elements/tr-pbx_extension.html @@ -0,0 +1,24 @@ +% unless ( $opt{'js_only'} ) { + + <% include('tr-td-label.html', %opt) %> + > + +% } +% + <% include( '/elements/pbx_extension.html', %opt ) %> +% +% unless ( $opt{'js_only'} ) { + + + + +% } +<%init> + +my( %opt ) = @_; + +my $cell_style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : ''; + +$opt{'label'} ||= 'Extension'; + + diff --git a/httemplate/view/svc_pbx.cgi b/httemplate/view/svc_pbx.cgi index ff0d28501..9b18dc3bd 100644 --- a/httemplate/view/svc_pbx.cgi +++ b/httemplate/view/svc_pbx.cgi @@ -1,6 +1,6 @@ <% include('elements/svc_Common.html', 'table' => 'svc_pbx', - 'edit_url' => $p."edit/svc_Common.html?svcdb=svc_pbx;svcnum=", + 'edit_url' => $p.'edit/svc_pbx.html?', 'labels' => \%labels, 'html_foot' => $html_foot, ) @@ -19,6 +19,48 @@ my $html_foot = sub { my $svc_pbx = shift; ## + # Extensions + ## + + my @pbx_extension = sort { $a->extension cmp $b->extension } + $svc_pbx->pbx_extension; + + my $extensions = ''; + if ( @pbx_extension ) { + + $extensions .= 'Extensions'. + include('/elements/table-grid.html'); + my $bgcolor1 = '#eeeeee'; + my $bgcolor2 = '#ffffff'; + my $bgcolor = ''; + + #$extensions .= ' + # + # Ext + # Name + # + #'; + + foreach my $pbx_extension ( @pbx_extension ) { + if ( $bgcolor eq $bgcolor1 ) { + $bgcolor = $bgcolor2; + } else { + $bgcolor = $bgcolor1; + } + + $extensions .= qq( + + ). $pbx_extension->extension. qq( + ). $pbx_extension->phone_name. qq( + + ); + + } + + $extensions .= '
'; + } + + ## # CDR links ## @@ -29,7 +71,7 @@ my $html_foot = sub { #matching as per package def cdr_svc_method my $cust_pkg = $svc_pbx->cust_svc->cust_pkg; - return '' unless $cust_pkg; + return $extensions unless $cust_pkg; my @voip_pkgs = grep { $_->plan eq 'voip_cdr' } $cust_pkg->part_pkg->self_and_bill_linked; @@ -43,7 +85,7 @@ my $html_foot = sub { my $cdr_svc_method = ( $voip_pkg && $voip_pkg->option('cdr_svc_method') ) || 'svc_phone.phonenum'; - return '' unless $cdr_svc_method =~ /^svc_pbx\.(.*)$/; + return $extensions unless $cdr_svc_method =~ /^svc_pbx\.(.*)$/; my $field = $1; my $search; @@ -55,7 +97,7 @@ my $html_foot = sub { $search = 'svcnum='. $svc_pbx->svcnum; } else { warn "unknown cdr_svc_method svc_pbx.$field"; - return ''; + return $extensions } my @links = map { @@ -67,6 +109,7 @@ my $html_foot = sub { # concatenate & return ### + $extensions. join(' | ', @links ). '
'; }; -- 2.11.0