summaryrefslogtreecommitdiff
path: root/httemplate/edit/process
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/edit/process')
-rwxr-xr-xhttemplate/edit/process/addr_block/add.cgi20
-rwxr-xr-xhttemplate/edit/process/addr_block/allocate.cgi25
-rwxr-xr-xhttemplate/edit/process/addr_block/deallocate.cgi24
-rwxr-xr-xhttemplate/edit/process/addr_block/split.cgi19
-rw-r--r--httemplate/edit/process/generic.cgi69
-rw-r--r--httemplate/edit/process/router.cgi100
-rw-r--r--httemplate/edit/process/svc_broadband.cgi54
7 files changed, 301 insertions, 10 deletions
diff --git a/httemplate/edit/process/addr_block/add.cgi b/httemplate/edit/process/addr_block/add.cgi
new file mode 100755
index 000000000..34d799ccd
--- /dev/null
+++ b/httemplate/edit/process/addr_block/add.cgi
@@ -0,0 +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");
+}
+%>
diff --git a/httemplate/edit/process/addr_block/allocate.cgi b/httemplate/edit/process/addr_block/allocate.cgi
new file mode 100755
index 000000000..85b0d7a7a
--- /dev/null
+++ b/httemplate/edit/process/addr_block/allocate.cgi
@@ -0,0 +1,25 @@
+<%
+my $error = '';
+my $blocknum = $cgi->param('blocknum');
+my $routernum = $cgi->param('routernum');
+
+my $addr_block = qsearchs('addr_block', { blocknum => $blocknum });
+my $router = qsearchs('router', { routernum => $routernum });
+
+if($addr_block) {
+ if ($router) {
+ $error = $addr_block->allocate($router);
+ } else {
+ $error = "Cannot find router with routernum $routernum";
+ }
+} 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");
+}
+%>
diff --git a/httemplate/edit/process/addr_block/deallocate.cgi b/httemplate/edit/process/addr_block/deallocate.cgi
new file mode 100755
index 000000000..cfb7ed04d
--- /dev/null
+++ b/httemplate/edit/process/addr_block/deallocate.cgi
@@ -0,0 +1,24 @@
+<%
+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");
+}
+%>
diff --git a/httemplate/edit/process/addr_block/split.cgi b/httemplate/edit/process/addr_block/split.cgi
new file mode 100755
index 000000000..bb6d4ba3e
--- /dev/null
+++ b/httemplate/edit/process/addr_block/split.cgi
@@ -0,0 +1,19 @@
+<%
+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");
+}
+%>
diff --git a/httemplate/edit/process/generic.cgi b/httemplate/edit/process/generic.cgi
new file mode 100644
index 000000000..751987f7a
--- /dev/null
+++ b/httemplate/edit/process/generic.cgi
@@ -0,0 +1,69 @@
+<%
+
+# Welcome to generic.cgi.
+#
+# This script provides a generic edit/process/ backend for simple table
+# editing. All it knows how to do is take the values entered into
+# the script and insert them into the table specified by $cgi->param('table').
+# If there's an existing record with the same primary key, it will be
+# replaced. (Deletion will be added in the future.)
+#
+# Special cgi params for this script:
+# table: the name of the table to be edited. The script will die horribly
+# if it can't find the table.
+# redirect_ok: URL to be displayed after a successful edit. The value of
+# the record's primary key will be passed as a keyword.
+# Defaults to (freeside root)/view/$table.cgi.
+# redirect_error: URL to be displayed if there's an error. The original
+# query string, plus the error message, will be passed.
+# Defaults to $cgi->referer() (i.e. go back where you
+# came from).
+
+
+use FS::Record qw(qsearchs dbdef);
+use DBIx::DBSchema;
+use DBIx::DBSchema::Table;
+
+
+my $error;
+my $p2 = popurl(2);
+my $table = $cgi->param('table');
+my $dbdef = dbdef or die "Cannot fetch dbdef!";
+
+my $dbdef_table = $dbdef->table($table) or die "Cannot fetch schema for $table";
+
+my $pkey = $dbdef_table->primary_key or die "Cannot fetch pkey for $table";
+my $pkey_val = $cgi->param($pkey);
+
+
+#warn "new FS::Record ( $table, (hashref) )";
+my $new = FS::Record::new ( "FS::$table", {
+ map { $_, scalar($cgi->param($_)) } fields($table)
+} );
+
+#warn 'created $new of class '.ref($new);
+
+if($pkey_val and (my $old = qsearchs($table, { $pkey, $pkey_val} ))) {
+ # edit
+ $error = $new->replace($old);
+} else {
+ #add
+ $error = $new->insert;
+ $pkey_val = $new->getfield($pkey);
+ # New records usually don't have their primary keys set until after
+ # they've been checked/inserted, so grab the new $pkey_val so we can
+ # redirect to it.
+}
+
+my $redirect_ok = (($cgi->param('redirect_ok')) ?
+ $cgi->param('redirect_ok') : $p2."view/$table.cgi");
+my $redirect_error = (($cgi->param('redirect_error')) ?
+ $cgi->param('redirect_error') : $cgi->referer());
+
+if($error) {
+ $cgi->param('error', $error);
+ print $cgi->redirect($redirect_error . '?' . $cgi->query_string);
+} else {
+ print $cgi->redirect($redirect_ok . '?' .$pkey_val);
+}
+%>
diff --git a/httemplate/edit/process/router.cgi b/httemplate/edit/process/router.cgi
new file mode 100644
index 000000000..c0cb884f0
--- /dev/null
+++ b/httemplate/edit/process/router.cgi
@@ -0,0 +1,100 @@
+<%
+
+use FS::UID qw(dbh);
+
+my $dbh = dbh;
+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_rf;
+my @old_psr;
+
+my $new = new FS::router {
+ routernum => $routernum,
+ routername => $routername,
+ svcnum => 0
+ };
+
+if($old) {
+ if($old->routername ne $new->routername) {
+ $error = $new->replace($old);
+ } #else do nothing
+} else {
+ $error = $new->insert;
+}
+
+check($error);
+
+if ($old) {
+ @old_psr = $old->part_svc_router;
+ foreach $psr (@old_psr) {
+ if($cgi->param('svcpart_'.$psr->svcpart) eq 'ON') {
+ # do nothing
+ } else {
+ $error = $psr->delete;
+ }
+ }
+ check($error);
+ @old_rf = $old->router_field;
+ foreach $rf (@old_rf) {
+ if(my $new_val = $cgi->param('rf_'.$rf->routerfieldpart)) {
+ if($new_val ne $rf->value) {
+ my $new_rf = new FS::router_field
+ { routernum => $routernum,
+ value => $new_val,
+ routerfieldpart => $rf->routerfieldpart };
+ $error = $new_rf->replace($rf);
+ } #else do nothing
+ } else {
+ $error = $rf->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);
+ } elsif($cgi->param($_) ne '' and /^rf_(\d+)$/) {
+ my $part = $1;
+ if(my @x = grep {$_->routerfieldpart == $part} @old_rf) {
+ # already handled all of these
+ } else {
+ my $new_rf = new FS::router_field
+ { routernum => $routernum,
+ value => $cgi->param('rf_'.$part),
+ routerfieldpart => $part };
+ $error = $new_rf->insert;
+ check($error);
+ }
+ }
+}
+
+
+
+# Yay, everything worked!
+$dbh->commit or die $dbh->errstr;
+print $cgi->redirect(popurl(3). "edit/router.cgi?$routernum");
+
+%>
diff --git a/httemplate/edit/process/svc_broadband.cgi b/httemplate/edit/process/svc_broadband.cgi
index fd7ba20d5..ab8b9f9d8 100644
--- a/httemplate/edit/process/svc_broadband.cgi
+++ b/httemplate/edit/process/svc_broadband.cgi
@@ -1,12 +1,19 @@
<%
+# If it's stupid but it works, it's not stupid.
+# -- U.S. Army
+
+local $FS::UID::AutoCommit = 0;
+my $dbh = FS::UID::dbh;
+
$cgi->param('svcnum') =~ /^(\d*)$/ or die "Illegal svcnum!";
my $svcnum = $1;
-my $old;
+my $old; my @old_sbf;
if ( $svcnum ) {
$old = qsearchs('svc_broadband', { 'svcnum' => $svcnum } )
or die "fatal: can't find broadband service (svcnum $svcnum)!";
+ @old_sbf = $old->sb_field;
} else {
$old = '';
}
@@ -17,14 +24,6 @@ my $new = new FS::svc_broadband ( {
} ( fields('svc_broadband'), qw( pkgnum svcpart ) )
} );
-unless ( $new->ip_addr ) {
- $new->ip_addr(join('.', (map $cgi->param('ip_addr_'.$_), (a..d))));
-}
-
-unless ( $new->mac_addr) {
- $new->mac_addr(join(':', (map $cgi->param('mac_addr_'.$_), (a..f))));
-}
-
my $error;
if ( $svcnum ) {
$error = $new->replace($old);
@@ -33,12 +32,47 @@ if ( $svcnum ) {
$svcnum = $new->svcnum;
}
+unless ($error) {
+ my $sb_field;
+
+ foreach ($cgi->param) {
+ #warn "\$cgi->param $_: " . $cgi->param($_);
+ if(/^sbf_(\d+)/) {
+ my $part = $1;
+ #warn "\$part $part";
+ $sb_field = new FS::sb_field
+ { svcnum => $svcnum,
+ value => $cgi->param($_),
+ sbfieldpart => $part };
+ if (my @x = grep { $_->sbfieldpart eq $part } @old_sbf) {
+ #if (my $old_sb_field = (grep { $_->sbfieldpart eq $part} @old_Sbf)[0]) {
+ #warn "array: " . scalar(@x);
+ if (length($sb_field->value) && ($sb_field->value ne $x[0]->value)) {
+ #warn "replacing " . $x[0]->value . " with " . $sb_field->value;
+ $error = $sb_field->replace($x[0]);
+ #$error = $sb_field->replace($old_sb_field);
+ } elsif (length($sb_field->value) == 0) {
+ #warn "delete";
+ $error = $x[0]->delete;
+ }
+ } else {
+ if (length($sb_field->value) > 0) {
+ #warn "insert";
+ $error = $sb_field->insert;
+ }
+ # else do nothing
+ }
+ }
+ }
+}
+
if ( $error ) {
$cgi->param('error', $error);
$cgi->param('ip_addr', $new->ip_addr);
- $cgi->param('mac_addr', $new->mac_addr);
+ $dbh->rollback;
print $cgi->redirect(popurl(2). "svc_broadband.cgi?". $cgi->query_string );
} else {
+ $dbh->commit or die $dbh->errstr;
print $cgi->redirect(popurl(3). "view/svc_broadband.cgi?" . $svcnum );
}