diff options
Diffstat (limited to 'httemplate/edit')
-rw-r--r-- | httemplate/edit/allocate.html | 9 | ||||
-rw-r--r-- | httemplate/edit/elements/edit.html | 16 | ||||
-rw-r--r-- | httemplate/edit/elements/svc_Common.html | 21 | ||||
-rwxr-xr-x | httemplate/edit/process/addr_block/add.cgi | 36 | ||||
-rwxr-xr-x | httemplate/edit/process/addr_block/allocate.cgi | 4 | ||||
-rwxr-xr-x | httemplate/edit/process/addr_block/deallocate.cgi | 40 | ||||
-rwxr-xr-x | httemplate/edit/process/addr_block/split.cgi | 44 | ||||
-rw-r--r-- | httemplate/edit/process/elements/process.html | 17 | ||||
-rw-r--r-- | httemplate/edit/process/router.cgi | 80 | ||||
-rwxr-xr-x | httemplate/edit/process/svc_acct_pop.cgi | 5 | ||||
-rw-r--r-- | httemplate/edit/process/svc_broadband.cgi | 36 | ||||
-rwxr-xr-x | httemplate/edit/router.cgi | 110 | ||||
-rwxr-xr-x | httemplate/edit/svc_acct_pop.cgi | 5 | ||||
-rw-r--r-- | httemplate/edit/svc_broadband.cgi | 310 |
14 files changed, 236 insertions, 497 deletions
diff --git a/httemplate/edit/allocate.html b/httemplate/edit/allocate.html index 29c16ae6a..0f05fcc7d 100644 --- a/httemplate/edit/allocate.html +++ b/httemplate/edit/allocate.html @@ -12,15 +12,22 @@ 'table' => 'router', 'name_col' => 'routername', 'disable_empty' => 1, + 'agent_virt' => 1, + 'agent_null_right' => + 'Engineering global configuration', }, ], 'post_url' => "process/addr_block/allocate.cgi", 'popup' => 1, + 'agent_virt' => 1, + 'agent_null_right' => 'Engineering global configuration', ) %> <%init> +my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + unless $curuser->access_right('Engineering configuration') + || $curuser->access_right('Engineering global configuration'); </%init> diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 86eb2b3c7..47b246477 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -108,8 +108,8 @@ Example: #run before display to return a different value 'value_callback' => sub { my( $columname, $value ) = @_; }, - #XXX describe - 'field_callback' => sub { }, + #run before display to manipulate element of the 'fields' arrayref + 'field_callback' => sub { my( $cgi, $object, $field_hashref ) = @_; }, 'viewall_dir' => '', #'search' or 'browse', defaults to 'search' @@ -179,7 +179,7 @@ Example: % @$fields % ) { % -% &{ $opt{'field_callback'} }( $f ) +% my $trash = &{ $opt{'field_callback'} }( $cgi, $object, $f ) % if $opt{'field_callback'}; % % my $field = $f->{'field'}; @@ -227,10 +227,18 @@ Example: % 'disabled' => $f->{'disabled'}, % ); % -% #select-table +% #select-table, checkboxes-table % $include_common{$_} = $f->{$_} % foreach grep exists($f->{$_}), qw( table name_col ); % +% #checkboxes-table +% $include_common{$_} = $f->{$_} +% foreach grep exists($f->{$_}), qw( target_table link_table ); +% +% #*-table +% $include_common{$_} = $f->{$_} +% foreach grep exists($f->{$_}), qw( hashref agent_virt agent_null_right ); +% % if ( $type eq 'tablebreak-tr-title' ) { % $include_common{'table_id'} = 'TableNumber'. $tablenum++ % } diff --git a/httemplate/edit/elements/svc_Common.html b/httemplate/edit/elements/svc_Common.html index 72abcba1f..b6737c14a 100644 --- a/httemplate/edit/elements/svc_Common.html +++ b/httemplate/edit/elements/svc_Common.html @@ -13,7 +13,7 @@ % $pkgnum = $1; % $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart'; % $svcpart = $1; -% $cgi->delete_all(); #so edit.html treats this correctly as new?? +% #$cgi->delete_all(); #so edit.html treats this correctly as new?? % } % <% include( 'edit.html', @@ -63,7 +63,7 @@ }, 'field_callback' => sub { - my $f = shift; + my ($cgi, $object, $f) = @_; my $columndef = $part_svc->part_svc_column($f->{'field'}); my $flag = $columndef->columnflag; if ( $flag eq 'F' ) { @@ -72,6 +72,23 @@ } }, + 'html_init' => sub { + my $cust_main; + if ( $pkgnum ) { + my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum}); + $cust_main = $cust_pkg->cust_main if $cust_pkg; + } + $cust_main + ? include( '/elements/small_custview.html', + $cust_main, + '', + 1, + popurl(2). "view/cust_main.cgi" + ). '<BR>' + : ''; + + }, + 'html_table_bottom' => sub { my $svc_x = shift; my $html = ''; diff --git a/httemplate/edit/process/addr_block/add.cgi b/httemplate/edit/process/addr_block/add.cgi index e9f9b9736..4321f946a 100755 --- a/httemplate/edit/process/addr_block/add.cgi +++ b/httemplate/edit/process/addr_block/add.cgi @@ -1,28 +1,20 @@ -% -% -%my $error = ''; -%my $ip_gateway = $cgi->param('ip_gateway'); -%my $ip_netmask = $cgi->param('ip_netmask'); -% -%my $new = new FS::addr_block { -% ip_gateway => $ip_gateway, -% ip_netmask => $ip_netmask, -% routernum => 0 }; -% -%$error = $new->insert; -% -%if ( $error ) { -% $cgi->param('error', $error); -% print $cgi->redirect(popurl(4). "browse/addr_block.cgi?". $cgi->query_string ); -%} else { -% print $cgi->redirect(popurl(4). "browse/addr_block.cgi"); -%} -% +<% include( '../elements/process.html', + 'table' => 'addr_block', + 'redirect' => popurl(4). 'browse/addr_block.cgi?dummy=', + 'error_redirect' => popurl(4). 'browse/addr_block.cgi?', + 'agent_virt' => 1, + 'agent_null_right' => 'Engineering global configuration', + ) +%> <%init> -my $conf = new FS::Conf; +my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + unless $curuser->access_right('Engineering configuration') + || $curuser->access_right('Engineering global configuration'); + +$cgi->param('routernum', 0) # in FS::addr_block::check instead? + unless $cgi->param('routernum'); </%init> diff --git a/httemplate/edit/process/addr_block/allocate.cgi b/httemplate/edit/process/addr_block/allocate.cgi index d1bd73f1f..f377d8155 100755 --- a/httemplate/edit/process/addr_block/allocate.cgi +++ b/httemplate/edit/process/addr_block/allocate.cgi @@ -8,7 +8,9 @@ <%init> my $conf = new FS::Conf; +my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + unless $curuser->access_right('Engineering configuration') + || $curuser->access_right('Engineering global configuration'); </%init> diff --git a/httemplate/edit/process/addr_block/deallocate.cgi b/httemplate/edit/process/addr_block/deallocate.cgi index 95e1b7e4d..91184b33e 100755 --- a/httemplate/edit/process/addr_block/deallocate.cgi +++ b/httemplate/edit/process/addr_block/deallocate.cgi @@ -1,32 +1,20 @@ -% -%my $error = ''; -%my $blocknum = $cgi->param('blocknum'); -% -%my $addr_block = qsearchs('addr_block', { blocknum => $blocknum }); -% -%if($addr_block) { -% my $router = $addr_block->router; -% if ($router) { -% $error = $addr_block->deallocate($router); -% } else { -% $error = "Block is not allocated to a router"; -% } -%} else { -% $error = "Cannot find block with blocknum $blocknum"; -%} -% -%if ( $error ) { -% $cgi->param('error', $error); -% print $cgi->redirect(popurl(4). "browse/addr_block.cgi?" . $cgi->query_string); -%} else { -% print $cgi->redirect(popurl(4). "browse/addr_block.cgi"); -%} -% - +<% include( '../elements/process.html', + 'table' => 'addr_block', + 'copy_on_empty' => [ grep { $_ ne 'routernum' } + fields 'addr_block' ], + 'redirect' => popurl(4). 'browse/addr_block.cgi?', + 'error_redirect' => popurl(4). 'browse/addr_block.cgi?', + 'agent_virt' => 1, + 'agent_null_right' => 'Engineering global configuration', + ) +%> <%init> my $conf = new FS::Conf; +my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + unless $curuser->access_right('Engineering configuration') + || $curuser->access_right('Engineering global configuration'); +$cgi->param('routernum', 0); # just to be explicit about what we are doing </%init> diff --git a/httemplate/edit/process/addr_block/split.cgi b/httemplate/edit/process/addr_block/split.cgi index b3a33b18a..eb55d008e 100755 --- a/httemplate/edit/process/addr_block/split.cgi +++ b/httemplate/edit/process/addr_block/split.cgi @@ -1,27 +1,27 @@ -% -%my $error = ''; -%my $blocknum = $cgi->param('blocknum'); -%my $addr_block = qsearchs('addr_block', { blocknum => $blocknum }); -% -%if ( $addr_block) { -% $error = $addr_block->split_block; -%} else { -% $error = "Unknown blocknum: $blocknum"; -%} -% -% -%if ( $error ) { -% $cgi->param('error', $error); -% print $cgi->redirect(popurl(4). "browse/addr_block.cgi?". $cgi->query_string ); -%} else { -% print $cgi->redirect(popurl(4). "browse/addr_block.cgi"); -%} -% - +<% $cgi->redirect(popurl(4). "browse/addr_block.cgi?". $cgi->query_string ) %> <%init> -my $conf = new FS::Conf; +my $curuser = $FS::CurrentUser::CurrentUser; + die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + unless $curuser->access_right('Engineering configuration') + || $curuser->access_right('Engineering global configuration'); + +my $error = ''; +$cgi->param('blocknum') =~ /^(\d+)$/ or die "invalid blocknum"; +my $blocknum = $1; + +my $addr_block = qsearchs({ 'table' => 'addr_block', + 'hashref' => { blocknum => $blocknum }, + 'extra_sql' => ' AND '. $curuser->agentnums_sql( + 'null_right' => 'Engineering global configuration' + ), + }) + or $error = "Unknown blocknum: $blocknum"; + +$error ||= $addr_block->split_block; + +$cgi->param('error', $error) + if $error; </%init> diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html index 6f271ee29..de0304a94 100644 --- a/httemplate/edit/process/elements/process.html +++ b/httemplate/edit/process/elements/process.html @@ -33,7 +33,8 @@ Example: 'clear_on_error' => [ 'form_field1', 'form_field2', ... ], - #pass an arrayref of hashrefs for multiple m2ms or m2names + #pass an arrayref of hashrefs for multiple m2ms or m2names + #be certain you incorporate m2m_Common if you see error: param 'process_m2m' => { 'link_table' => 'link_table_name', 'target_table' => 'target_table_name', @@ -176,6 +177,13 @@ my %hash = my $new = $class->new( \%hash ); +if ($old && exists($opt{'copy_on_empty'})) { + foreach my $field (@{$opt{'copy_on_empty'}}) { + $new->set($field, $old->get($field)) + unless scalar($cgi->param($field)); + } +} + if ( $opt{'agent_virt'} ) { die "illegal agentnum" unless $curuser->agentnums_href->{$new->agentnum} @@ -184,13 +192,6 @@ if ( $opt{'agent_virt'} ) { && $curuser->access_right($opt{'agent_null_right'}); } -if ($old && exists($opt{'copy_on_empty'})) { - foreach my $field (@{$opt{'copy_on_empty'}}) { - $new->set($field, $old->get($field)) - unless scalar($cgi->param($field)); - } -} - $error ||= $new->check; my @args = (); diff --git a/httemplate/edit/process/router.cgi b/httemplate/edit/process/router.cgi index 7e0baf782..6e717d19c 100644 --- a/httemplate/edit/process/router.cgi +++ b/httemplate/edit/process/router.cgi @@ -1,70 +1,20 @@ -%local $FS::UID::AutoCommit=0; -% -%sub check { -% my $error = shift; -% if($error) { -% $cgi->param('error', $error); -% print $cgi->redirect(popurl(3) . "edit/router.cgi?". $cgi->query_string); -% dbh->rollback; -% exit; -% } -%} -% -%my $error = ''; -%my $routernum = $cgi->param('routernum'); -%my $routername = $cgi->param('routername'); -%my $old = qsearchs('router', { routernum => $routernum }); -%my @old_psr; -% -%my $new = new FS::router { -% map { -% ($_, scalar($cgi->param($_))); -% } fields('router') -%}; -% -%if($old) { -% $error = $new->replace($old); -%} else { -% $error = $new->insert; -% $routernum = $new->routernum; -%} -% -%check($error); -% -%if ($old) { -% @old_psr = $old->part_svc_router; -% foreach my $psr (@old_psr) { -% if($cgi->param('svcpart_'.$psr->svcpart) eq 'ON') { -% # do nothing -% } else { -% $error = $psr->delete; -% } -% } -% check($error); -%} -% -%foreach($cgi->param) { -% if($cgi->param($_) eq 'ON' and /^svcpart_(\d+)$/) { -% my $svcpart = $1; -% if(grep {$_->svcpart == $svcpart} @old_psr) { -% # do nothing -% } else { -% my $new_psr = new FS::part_svc_router { svcpart => $svcpart, -% routernum => $routernum }; -% $error = $new_psr->insert; -% } -% check($error); -% } -%} -% -% -%# Yay, everything worked! -%dbh->commit or die dbh->errstr; -%print $cgi->redirect(popurl(3). "browse/router.cgi"); -% +<% include('elements/process.html', + 'table' => 'router', + 'viewall_dir' => 'browse', + 'viewall_ext' => 'cgi', + 'edit_ext' => 'cgi', + 'process_m2m' => { 'link_table' => 'part_svc_router', + 'target_table' => 'part_svc', + }, + 'agent_virt' => 1, + 'agent_null_right' => 'Engineering global configuration', + ) +%> <%init> +my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + unless $curuser->access_right('Engineering configuration') + || $curuser->access_right('Engineering global configuration'); </%init> diff --git a/httemplate/edit/process/svc_acct_pop.cgi b/httemplate/edit/process/svc_acct_pop.cgi index 75b89c88f..522e94948 100755 --- a/httemplate/edit/process/svc_acct_pop.cgi +++ b/httemplate/edit/process/svc_acct_pop.cgi @@ -6,8 +6,11 @@ %} <%init> +my $curuser = $FS::CurrentUser::CurrentUser; + die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + unless $curuser->access_right('Engineering configuration') + || $curuser->access_right('Engineering global configuration'); my $popnum = $cgi->param('popnum'); diff --git a/httemplate/edit/process/svc_broadband.cgi b/httemplate/edit/process/svc_broadband.cgi index 8600da349..d5c9820bb 100644 --- a/httemplate/edit/process/svc_broadband.cgi +++ b/httemplate/edit/process/svc_broadband.cgi @@ -1,38 +1,8 @@ -%if ( $error ) { -% $cgi->param('error', $error); -% $cgi->param('ip_addr', $new->ip_addr); -<% $cgi->redirect(popurl(2). "svc_broadband.cgi?". $cgi->query_string ) %> -%} else { -<% $cgi->redirect(popurl(3). "view/svc_broadband.cgi?" . $svcnum ) %> -%} +<% include('elements/svc_Common.html', 'table' => 'svc_broadband') %> <%init> +my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific? - -$cgi->param('svcnum') =~ /^(\d*)$/ or die "Illegal svcnum!"; -my $svcnum = $1; - -my $old; -if ( $svcnum ) { - $old = qsearchs('svc_broadband', { 'svcnum' => $svcnum } ) - or die "fatal: can't find broadband service (svcnum $svcnum)!"; -} else { - $old = ''; -} - -my $new = new FS::svc_broadband ( { - map { - ($_, scalar($cgi->param($_))); - } ( fields('svc_broadband'), qw( pkgnum svcpart ) ) -} ); - -my $error; -if ( $svcnum ) { - $error = $new->replace($old); -} else { - $error = $new->insert; - $svcnum = $new->svcnum; -} + unless $curuser->access_right('Provision customer service'); #something else more specific? </%init> diff --git a/httemplate/edit/router.cgi b/httemplate/edit/router.cgi index c08e54449..180dcb7a7 100755 --- a/httemplate/edit/router.cgi +++ b/httemplate/edit/router.cgi @@ -1,78 +1,44 @@ -<% include('/elements/header.html', "$action Router", menubar( - 'View all routers' => "${p}browse/router.cgi", - )) +<% include('elements/edit.html', + 'post_url' => popurl(1).'process/router.cgi', + 'name' => 'router', + 'table' => 'router', + 'viewall_url' => "${p}browse/router.cgi", + 'labels' => { 'routernum' => 'Router', + 'routername' => 'Name', + 'svc_part' => 'Service', + }, + 'fields' => [ + { 'field'=>'routername', 'type'=>'text', 'size'=>32 }, + { 'field'=>'agentnum', 'type'=>'select-agent' }, + ], + 'error_callback' => $callback, + 'edit_callback' => $callback, + 'new_callback' => $callback, + ) %> - -<% include('/elements/error.html') %> - -<FORM ACTION="<%popurl(1)%>process/router.cgi" METHOD=POST> - <INPUT TYPE="hidden" NAME="table" VALUE="router"> - <INPUT TYPE="hidden" NAME="redirect_ok" VALUE="<%$p3%>/browse/router.cgi"> - <INPUT TYPE="hidden" NAME="redirect_error" VALUE="<%$p3%>/edit/router.cgi"> - <INPUT TYPE="hidden" NAME="routernum" VALUE="<%$routernum%>"> - <INPUT TYPE="hidden" NAME="svcnum" VALUE="<%$router->svcnum%>"> - Router #<%$routernum or "(NEW)"%> - -<BR><BR>Name <INPUT TYPE="text" NAME="routername" SIZE=32 VALUE="<%$router->routername%>"> - -<BR><BR> -Custom fields: -<BR> -<%table() %> -% -%foreach my $field ($router->virtual_fields) { -% print $router->pvf($field)->widget('HTML', 'edit', -% $router->getfield($field)); -%} -% - -</TABLE> -% -%unless ($router->svcnum) { -% - -<BR><BR>Select the service types available on this router<BR> -% -% -% foreach my $part_svc ( qsearch('part_svc', { svcdb => 'svc_broadband', -% disabled => '' }) ) { -% - - <BR> - <INPUT TYPE="checkbox" NAME="svcpart_<%$part_svc->svcpart%>"<% - qsearchs('part_svc_router', { svcpart => $part_svc->svcpart, - routernum => $routernum } ) ? ' CHECKED' : ''%> VALUE="ON"> - <A HREF="<%${p}%>edit/part_svc.cgi?<%$part_svc->svcpart%>"> - <%$part_svc->svcpart%>: <%$part_svc->svc%></A> -% } -% } - - - <BR><BR><INPUT TYPE="submit" VALUE="Apply changes"> - </FORM> - -<% include('/elements/footer.html') %> - <%init> -die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); +my $curuser = $FS::CurrentUser::CurrentUser; -my $router; -if ( $cgi->keywords ) { - my($query) = $cgi->keywords; - $query =~ /^(\d+)$/; - $router = qsearchs('router', { routernum => $1 }) - or print $cgi->redirect(popurl(2)."browse/router.cgi") ; -} else { - $router = new FS::router ( { - map { $_, scalar($cgi->param($_)) } fields('router') - } ); -} - -my $routernum = $router->routernum; -my $action = $routernum ? 'Edit' : 'Add'; - -my $p3 = popurl(3); +die "access denied" + unless $curuser->access_right('Engineering configuration') + || $curuser->access_right('Engineering global configuration'); + +my $callback = sub { + my ($cgi, $object, $fields) = (shift, shift, shift); + unless ($object->svcnum) { + push @{$fields}, + { 'type' => 'tablebreak-tr-title', + 'value' => 'Select the service types available on this router', + }, + { 'field' => 'svc_part', + 'type' => 'checkboxes-table', + 'target_table' => 'part_svc', + 'link_table' => 'part_svc_router', + 'name_col' => 'svc', + 'hashref' => { 'svcdb' => 'svc_broadband', 'disabled' => '' }, + }; + } +}; </%init> diff --git a/httemplate/edit/svc_acct_pop.cgi b/httemplate/edit/svc_acct_pop.cgi index 3c16a1f95..b0ae1c381 100755 --- a/httemplate/edit/svc_acct_pop.cgi +++ b/httemplate/edit/svc_acct_pop.cgi @@ -27,8 +27,11 @@ Local <INPUT TYPE="text" NAME="loc" SIZE=5 MAXLENGTH=4 VALUE="<% $hashref->{ <%init> +my $curuser = $FS::CurrentUser::CurrentUser; + die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + unless $curuser->access_right('Engineering configuration') + || $curuser->access_right('Engineering global configuration'); my $svc_acct_pop; if ( $cgi->param('error') ) { diff --git a/httemplate/edit/svc_broadband.cgi b/httemplate/edit/svc_broadband.cgi index c2fb58dda..25fb009ac 100644 --- a/httemplate/edit/svc_broadband.cgi +++ b/httemplate/edit/svc_broadband.cgi @@ -1,167 +1,26 @@ -<% include('/elements/header.html', "Broadband Service $action") %> - -<% include('/elements/error.html') %> - -Service #<B><%$svcnum ? $svcnum : "(NEW)"%></B><BR><BR> - -<FORM ACTION="<%${p1}%>process/svc_broadband.cgi" METHOD=POST> - <INPUT TYPE="hidden" NAME="svcnum" VALUE="<%$svcnum%>"> - <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<%$pkgnum%>"> - <INPUT TYPE="hidden" NAME="svcpart" VALUE="<%$svcpart%>"> - - <%&ntable("#cccccc",2)%> - <TR> - <TD ALIGN="right">Description</TD> - <TD BGCOLOR="#ffffff"> -% if ( $part_svc->part_svc_column('description')->columnflag eq 'F' ) { - - <INPUT TYPE="hidden" NAME="description" VALUE="<%$description%>"><%$description%> -% } else { - - <INPUT TYPE="text" NAME="description" VALUE="<%$description%>"> -% } - - </TD> - </TR> - <TR> - <TD ALIGN="right">IP Address</TD> - <TD BGCOLOR="#ffffff"> -% if ( $part_svc->part_svc_column('ip_addr')->columnflag eq 'F' ) { - - <INPUT TYPE="hidden" NAME="ip_addr" VALUE="<%$ip_addr%>"><%$ip_addr%> -% } else { - - <INPUT TYPE="text" NAME="ip_addr" VALUE="<%$ip_addr%>"> -% } - - </TD> - </TR> - <TR> - <TD ALIGN="right">Download speed</TD> - <TD BGCOLOR="#ffffff"> -% if ( $part_svc->part_svc_column('speed_down')->columnflag eq 'F' ) { - - <INPUT TYPE="hidden" NAME="speed_down" VALUE="<%$speed_down%>"><%$speed_down%>Kbps -% } else { - - <INPUT TYPE="text" NAME="speed_down" SIZE=5 VALUE="<%$speed_down%>">Kbps -% } - - </TD> - </TR> - <TR> - <TD ALIGN="right">Upload speed</TD> - <TD BGCOLOR="#ffffff"> -% if ( $part_svc->part_svc_column('speed_up')->columnflag eq 'F' ) { - - <INPUT TYPE="hidden" NAME="speed_up" VALUE="<%$speed_up%>"><%$speed_up%>Kbps -% } else { - - <INPUT TYPE="text" NAME="speed_up" SIZE=5 VALUE="<%$speed_up%>">Kbps -% } - - </TD> - </TR> -% if ($action eq 'Add') { - - <TR> - <TD ALIGN="right">Router/Block</TD> - <TD BGCOLOR="#ffffff"> - <SELECT NAME="blocknum"> -% -% warn $svc_broadband->svcpart; -% foreach my $router ($svc_broadband->allowed_routers) { -% warn $router->routername; -% foreach my $addr_block ($router->addr_block) { -% - - <OPTION VALUE="<%$addr_block->blocknum%>"<%($addr_block->blocknum eq $blocknum) ? ' SELECTED' : ''%>> - <%$router->routername%>:<%$addr_block->ip_gateway%>/<%$addr_block->ip_netmask%></OPTION> -% -% } -% } -% - - </SELECT> - </TD> - </TR> -% } else { - - - <TR> - <TD ALIGN="right">Router/Block</TD> - <TD BGCOLOR="#ffffff"> - <%$svc_broadband->addr_block->router->routername%>:<%$svc_broadband->addr_block->NetAddr%> - <INPUT TYPE="hidden" NAME="blocknum" VALUE="<%$svc_broadband->blocknum%>"> - </TD> - </TR> -% } - <TR> - <TD ALIGN="right">MAC Address</TD> - <TD BGCOLOR="#ffffff"> - <INPUT TYPE="text" NAME="mac_addr" VALUE="<%$mac_addr%>"> - </TD> - </TR> - <TR> - <TD ALIGN="right">Latitude</TD> - <TD BGCOLOR="#ffffff"> - <INPUT TYPE="text" NAME="latitude" VALUE="<%$latitude%>"> - </TD> - </TR> - <TR> - <TD ALIGN="right">Longitude</TD> - <TD BGCOLOR="#ffffff"> - <INPUT TYPE="text" NAME="longitude" VALUE="<%$longitude%>"> - </TD> - </TR> - <TR> - <TD ALIGN="right">Altitude</TD> - <TD BGCOLOR="#ffffff"> - <INPUT TYPE="text" NAME="altitude" VALUE="<%$altitude%>"> - </TD> - </TR> - <TR> - <TD ALIGN="right">VLAN Profile</TD> - <TD BGCOLOR="#ffffff"> -% if ( $part_svc->part_svc_column('vlan_profile')->columnflag eq 'F' ) { - - <INPUT TYPE="hidden" NAME="vlan_profile" VALUE="<%$vlan_profile%>"><%$vlan_profile%> -% } else { - - <INPUT TYPE="text" NAME="vlan_profile" VALUE="<%$vlan_profile%>"> -% } - - </TD> - </TR> - <TR> - <TD ALIGN="right">Authentication Key</TD> - <TD BGCOLOR="#ffffff"> -% if ( $part_svc->part_svc_column('auth_key')->columnflag eq 'F' ) { - - <INPUT TYPE="hidden" NAME="auth_key" VALUE="<%$auth_key%>"><%$auth_key%> -% } else { - - <INPUT TYPE="text" NAME="auth_key" VALUE="<%$auth_key%>"> -% } - - </TD> - </TR> -% -%foreach my $field ($svc_broadband->virtual_fields) { -% if ( $part_svc->part_svc_column($field)->columnflag ne 'F' && -% $part_svc->part_svc_column($field)->columnflag ne 'X') { -% print $svc_broadband->pvf($field)->widget('HTML', 'edit', -% $svc_broadband->getfield($field)); -% } -%} - - </TABLE> - <BR> - <INPUT TYPE="submit" NAME="submit" VALUE="Submit"> -</FORM> - -<% include('/elements/footer.html') %> - +<% include('elements/svc_Common.html', + 'post_url' => popurl(1). 'process/svc_broadband.cgi', + 'name' => 'broadband service', + 'table' => 'svc_broadband', + 'labels' => { 'svcnum' => 'Service #', + 'description' => 'Description', + 'ip_addr' => 'IP address', + 'speed_down' => 'Download speed', + 'speed_up' => 'Upload speed', + 'blocknum' => 'Router/Block', + 'block_disp' => 'Router/Block', + 'mac_addr' => 'MAC address', + 'latitude' => 'Latitude', + 'longitude' => 'Longitude', + 'altitude' => 'Altitude', + 'vlan_profile' => 'VLAN profile', + 'authkey' => 'Authentication key', + }, + 'fields' => \@fields, + 'field_callback' => $callback, + 'dummy' => $cgi->query_string, + ) +%> <%init> die "access denied" @@ -170,85 +29,58 @@ die "access denied" # If it's stupid but it works, it's still stupid. # -Kristian -use HTML::Widgets::SelectLayers; -use Tie::IxHash; - -my( $svcnum, $pkgnum, $svcpart, $part_svc, $svc_broadband ); -if ( $cgi->param('error') ) { - - $svc_broadband = new FS::svc_broadband ( { - map { $_, scalar($cgi->param($_)) } fields('svc_broadband'), qw(svcpart) - } ); - $svcnum = $svc_broadband->svcnum; - $pkgnum = $cgi->param('pkgnum'); - $svcpart = $svc_broadband->svcpart; - $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart}); - die "No part_svc entry!" unless $part_svc; - -} elsif ( $cgi->param('pkgnum') && $cgi->param('svcpart') ) { #adding - - $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum'; - $pkgnum = $1; - $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart'; - $svcpart = $1; - - $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart}); - die "No part_svc entry!" unless $part_svc; - - $svc_broadband = new FS::svc_broadband({ svcpart => $svcpart }); - - $svcnum=''; +my @fields = ( + qw( description ip_addr speed_down speed_up blocknum ), + { field=>'block_label', type=>'fixed' }, + qw( mac_addr latitude longitude altitude vlan_profile authkey ) +); - $svc_broadband->set_default_and_fixed; +my $callback = sub { + my ($cgi, $object, $fieldref) = @_; -} else { #editing + my $svcpart = $object->svcnum ? $object->cust_svc->svcpart + : $cgi->param('svcpart'); - my($query) = $cgi->keywords; - $query =~ /^(\d+)$/ or die "unparsable svcnum"; - $svcnum=$1; - $svc_broadband=qsearchs('svc_broadband',{'svcnum'=>$svcnum}) - or die "Unknown (svc_broadband) svcnum!"; - - my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum}) - or die "Unknown (cust_svc) svcnum!"; - - $pkgnum=$cust_svc->pkgnum; - $svcpart=$cust_svc->svcpart; - - $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart}); + my $part_svc = qsearchs( 'part_svc', { svcpart => $svcpart } ); die "No part_svc entry!" unless $part_svc; -} -my $action = $svc_broadband->svcnum ? 'Edit' : 'Add'; - -if ($pkgnum) { - - #Nothing? - -} elsif ( $action eq 'Edit' ) { - - #Nothing? - -} else { - die "\$action eq Add, but \$pkgnum is null!\n"; -} - -my $p1 = popurl(1); - -my ($ip_addr, $speed_up, $speed_down, $blocknum, $mac_addr, - $latitude, $longitude, $altitude, $vlan_profile, $auth_key, - $description) = - ($svc_broadband->ip_addr, - $svc_broadband->speed_up, - $svc_broadband->speed_down, - $svc_broadband->blocknum, - $svc_broadband->mac_addr, - $svc_broadband->latitude, - $svc_broadband->longitude, - $svc_broadband->altitude, - $svc_broadband->vlan_profile, - $svc_broadband->auth_key, - $svc_broadband->description, - ); + my $columndef = $part_svc->part_svc_column($fieldref->{'field'}); + if ($columndef->columnflag eq 'F') { + $fieldref->{'type'} = 'fixed'; + $fieldref->{'value'} = $columndef->columnvalue; + } + + if ($object->svcnum) { + + $fieldref->{type} = 'hidden' + if $fieldref->{field} eq 'blocknum'; + + $fieldref->{value} = $object->addr_block->label + if $fieldref->{field} eq 'block_label'; + + } else { + + $fieldref->{type} = 'hidden' if $fieldref->{field} eq 'block_label'; + + if ($fieldref->{field} eq 'blocknum') { + my $cust_pkg = qsearchs( 'cust_pkg', {pkgnum => $cgi->param('pkgnum')} ); + die "No cust_pkg entry!" unless $cust_pkg; + + $object->svcpart($part_svc->svcpart); + my @addr_block = + grep { ! $_->agentnum + || $cust_pkg->cust_main->agentnum == $_->agentnum + && $FS::CurrentUser::CurrentUser->agentnum($_->agentnum) + } + map { $_->addr_block } $object->allowed_routers; + my @options = map { $_->blocknum } @addr_block; + my %option_labels = map { ( $_->blocknum => $_->label ) } @addr_block; + $fieldref->{type} = 'select'; + $fieldref->{options} = \@options; + $fieldref->{labels} = \%option_labels; + } + + } +}; </%init> |