477 report: improve browse-edit UI
[freeside.git] / httemplate / edit / process / bulk-part_pkg-fcc.html
diff --git a/httemplate/edit/process/bulk-part_pkg-fcc.html b/httemplate/edit/process/bulk-part_pkg-fcc.html
new file mode 100644 (file)
index 0000000..17579aa
--- /dev/null
@@ -0,0 +1,42 @@
+% if ( keys %error ) {
+%   foreach my $pkgpart (keys %error) {
+%     # stuff all the errors back into $cgi
+%     $cgi->param("error$pkgpart", $error{$pkgpart});
+%   }
+%   my $session = int(rand(4294967296)); #XXX
+%   my $pref = new FS::access_user_pref({
+%     'usernum'    => $FS::CurrentUser::CurrentUser->usernum,
+%     'prefname'   => "redirect$session",
+%     'prefvalue'  => $cgi->query_string,
+%     'expiration' => time + 3600, #1h?  1m?
+%   });
+%   my $pref_error = $pref->insert;
+%   if ( $pref_error ) {
+%     die "FATAL: couldn't even set redirect cookie: $pref_error".
+%         " attempting to set redirect$session to ". $cgi->query_string."\n";
+%   }
+<% $cgi->redirect($fsurl.'browse/part_pkg-fcc.html?redirect='.$session) %>
+% } else {
+<% $cgi->redirect($fsurl.'browse/part_pkg-fcc.html?classnum='.$classnum) %>
+% }
+<%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
+die "access denied"
+  unless $curuser->access_right('Bulk edit package definitions');
+
+# non-atomic; report errors but allow successful changes to go through
+# not that I even know how you'd get an error doing this
+
+my %error;
+foreach my $param ($cgi->param) {
+  $param =~ /^pkgpart(\d+)$/ or next;
+  my $pkgpart = $1;
+  my $part_pkg = FS::part_pkg->by_key($pkgpart);
+  my $hashref = decode_json( $cgi->param($param) );
+  my $error = $part_pkg->set_fcc_options($hashref);
+  $error{$pkgpart} = $error if $error;
+}
+
+my $classnum = $cgi->param('classnum');
+
+</%init>