summaryrefslogtreecommitdiff
path: root/httemplate/edit/process/svc_acct.cgi
blob: 0a89e253c652e6bf86276c3eecde044dd3bb6496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
%if ( $error ) {
%  $cgi->param('error', $error);
<% $cgi->redirect(popurl(2). "svc_acct.cgi?". $cgi->query_string ) %>
%} else {
<% $cgi->redirect(popurl(3). "view/svc_acct.cgi?" . $svcnum ) %>
%}
<%init>

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_acct', { 'svcnum' => $svcnum } )
    or die "fatal: can't find account (svcnum $svcnum)!";
} else {
  $old = '';
}

#unmunge popnum
$cgi->param('popnum', (split(/:/, $cgi->param('popnum') ))[0] );

#unmunge passwd
if ( $cgi->param('_password') eq '*HIDDEN*' ) {
  die "fatal: no previous account to recall hidden password from!" unless $old;
  $cgi->param('_password',$old->getfield('_password'));
}

#unmunge usergroup
$cgi->param('usergroup', [ $cgi->param('radius_usergroup') ] );

#unmunge bytecounts
foreach (map { $_,$_."_threshold" } qw( upbytes downbytes totalbytes )) {
  $cgi->param($_, FS::UI::bytecount::parse_bytecount($cgi->param($_)) );
}

my %hash = $svcnum ? $old->hash : ();
map {
    $hash{$_} = scalar($cgi->param($_));
  #} qw(svcnum pkgnum svcpart username _password popnum uid gid finger dir
  #  shell quota slipip)
  } (fields('svc_acct'), qw ( pkgnum svcpart usergroup ));
my $new = new FS::svc_acct ( \%hash );

my $error;
if ( $svcnum ) {
  foreach (grep { $old->$_ != $new->$_ } qw( seconds upbytes downbytes totalbytes )) {
    my %hash = map { $_ => $new->$_ } 
               grep { $new->$_ }
               qw( seconds upbytes downbytes totalbytes );

    $error = $new->set_usage(\%hash);  #unoverlimit and trigger radius changes
    last;                              #once is enough
  }
  $error ||= $new->replace($old);
} else {
  $error = $new->insert;
  $svcnum = $new->svcnum;
}

</%init>