summaryrefslogtreecommitdiff
path: root/httemplate/edit/process
diff options
context:
space:
mode:
authorivan <ivan>2007-08-01 22:26:52 +0000
committerivan <ivan>2007-08-01 22:26:52 +0000
commiteb4ff7f73c5d4bdf74a3472448b5a195598ff4cd (patch)
treebb38241e8c865c3bca861da7749071feeadd2b5b /httemplate/edit/process
parent32b5d3a31f112a381f0a15ac5e3a2204242f3405 (diff)
event refactor, landing on HEAD!
Diffstat (limited to 'httemplate/edit/process')
-rw-r--r--httemplate/edit/process/access_group.html1
-rw-r--r--httemplate/edit/process/elements/process.html312
-rw-r--r--httemplate/edit/process/invoice_logo.html26
-rw-r--r--httemplate/edit/process/invoice_template.html15
-rw-r--r--httemplate/edit/process/part_event.html86
-rw-r--r--httemplate/edit/process/quick-cust_pkg.cgi26
6 files changed, 343 insertions, 123 deletions
diff --git a/httemplate/edit/process/access_group.html b/httemplate/edit/process/access_group.html
index c80311586..581b50f9e 100644
--- a/httemplate/edit/process/access_group.html
+++ b/httemplate/edit/process/access_group.html
@@ -10,6 +10,7 @@
'num_col' => 'rightobjnum',
'name_col' => 'rightname',
'names_list' => [ FS::AccessRight->rights() ],
+ 'param_style' => 'link_table.value checkboxes',
},
)
%>
diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html
index e388c678b..19d3fbef1 100644
--- a/httemplate/edit/process/elements/process.html
+++ b/httemplate/edit/process/elements/process.html
@@ -1,111 +1,203 @@
-%
-%
-% # options example...
-% #
-% ###
-% ##req
-% ##
-% #
-% # 'table' =>
-% #
-% # #? 'primary_key' => #required when the dbdef doesn't know...???
-% # #? 'fields' => []
-% #
-% ###
-% ##opt
-% ###
-% #
-% # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
-% # OR
-% # 'redirect' => 'view/table.cgi?', # value of primary key is appended
-% #
-% # 'error_redirect' => popurl(2).'edit/table.cgi?', #query string appended
-% #
-% # 'edit_ext' => 'html', #defaults to 'html', you might want 'cgi' while the
-% # #naming is still inconsistent
-% #
-% # 'copy_on_empty' => [ 'old_field_name', 'another_old_field', ... ],
-% #
-% # 'clear_on_error' => [ 'form_field1', 'form_field2', ... ],
-% #
-% # 'process_m2m' => { 'link_table' => 'link_table_name',
-% # 'target_table' => 'target_table_name',
-% # },
-% # 'process_m2name' => { 'link_table' => 'link_table_name',
-% # 'link_static' => { 'column' => 'value' },
-% # 'num_col' => 'column', #if column name is different in
-% # #link_table than source_table
-% # 'name_col' => 'name_column',
-% # 'names_list' => [ 'list', 'names' ],
-% # },
-%
-% my(%opt) = @_;
-%
-% #false laziness w/edit.html
-% my $table = $opt{'table'};
-% my $class = "FS::$table";
-% my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
-% my $fields = $opt{'fields'}
-% #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
-% || [ fields($table) ];
-%
-% my $pkeyvalue = $cgi->param($pkey);
-%
-% my $old = qsearchs( $table, { $pkey => $pkeyvalue } ) if $pkeyvalue;
-%
-% my $new = $class->new( {
-% map {
-% $_, scalar($cgi->param($_));
-% } @$fields
-% } );
-%
-% 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));
-% }
-% }
-%
-% my $error;
-% if ( $pkeyvalue ) {
-% $error = $new->replace($old);
-% } else {
-% $error = $new->insert;
-% $pkeyvalue = $new->getfield($pkey);
-% }
-%
-% if ( !$error && $opt{'process_m2m'} ) {
-% $error = $new->process_m2m( %{ $opt{'process_m2m'} },
-% 'params' => scalar($cgi->Vars),
-% );
-% }
-%
-% if ( !$error && $opt{'process_m2name'} ) {
-% $error = $new->process_m2name( %{ $opt{'process_m2name'} },
-% 'params' => scalar($cgi->Vars),
-% );
-% }
-%
-% # XXX print?!?!
-%
-% if ( $error ) {
-% $cgi->param('error', $error);
-% if (scalar(@{$opt{'clear_on_error'}})) {
-% foreach my $field (@{$opt{'clear_on_error'}}) {
-% $cgi->param($field, '')
-% }
-% }
-% my $edit_ext = $opt{'edit_ext'} || 'html';
-% my $url = $opt{'error_redirect'} || popurl(2)."$table.$edit_ext?";
-% print $cgi->redirect($url. $cgi->query_string );
-% } elsif ( $opt{'redirect'} ) {
-% print $cgi->redirect( $opt{'redirect'}. $pkeyvalue );
-% } else {
-% print $cgi->redirect( popurl(3).
-% ( $opt{'viewall_dir'} || 'search' ).
-% "/$table.html"
-% );
-% }
-%
-%
+<%doc>
+Example:
+
+ include( 'elements/process.html',
+
+ ###
+ # required
+ ###
+
+ 'table' => 'tablename',
+
+ #? 'primary_key' => #required when the dbdef doesn't know...???
+ #? 'fields' => [] #""
+
+ ###
+ # optional
+ ###
+
+ 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
+ OR
+ 'redirect' => 'view/table.cgi?', # value of primary key is appended
+
+ 'error_redirect' => popurl(2).'edit/table.cgi?', #query string appended
+
+ 'edit_ext' => 'html', #defaults to 'html', you might want 'cgi' while the
+ #naming is still inconsistent
+
+ 'copy_on_empty' => [ 'old_field_name', 'another_old_field', ... ],
+
+ 'clear_on_error' => [ 'form_field1', 'form_field2', ... ],
+
+ 'process_m2m' => { 'link_table' => 'link_table_name',
+ 'target_table' => 'target_table_name',
+ },
+ 'process_m2name' => { 'link_table' => 'link_table_name',
+ 'link_static' => { 'column' => 'value' },
+ 'num_col' => 'column', #if column name is different in
+ #link_table than source_table
+ 'name_col' => 'name_column',
+ 'names_list' => [ 'list', 'names' ],
+
+ 'param_style' => 'link_table.value checkboxes',
+ #or#
+ 'param_style' => 'name_colN values',
+
+
+ },
+
+ #supplies arguments to insert() and replace()
+ # for use with tables that are FS::option_Common
+ 'args_callback' => sub { my( $cgi, $object ) = @_; },
+
+ 'debug' => 1, #turns on debugging output
+
+ #agent virtualization
+ 'agent_virt' => 1,
+ 'agent_null_right' => 'Access Right Name',
+
+ )
+
+</%doc>
+<%once>
+
+ my $me = 'process.html:';
+
+</%once>
+<%init>
+
+my(%opt) = @_;
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+#false laziness w/edit.html
+my $table = $opt{'table'};
+my $class = "FS::$table";
+my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
+my $fields = $opt{'fields'}
+ #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
+ || [ fields($table) ];
+
+my $pkeyvalue = $cgi->param($pkey);
+
+my $old = '';
+if ( $pkeyvalue ) {
+ $old = qsearchs({
+ 'table' => $table,
+ 'hashref' => { $pkey => $pkeyvalue },
+ 'extra_sql' => ( $opt{'agent_virt'}
+ ? ' AND '. $curuser->agentnums_sql(
+ 'null_right' => $opt{'agent_null_right'}
+ )
+ : ''
+ ),
+ });
+}
+
+my %hash = map { $_ => scalar($cgi->param($_)) } @$fields;
+
+my $new = $class->new( \%hash );
+
+if ( $opt{'agent_virt'} ) {
+ die "illegal agentnum"
+ unless $curuser->agentnums_href->{$new->agentnum}
+ or $opt{'agent_null_right'}
+ && ! $new->agentnum
+ && $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));
+ }
+}
+
+my $error = $new->check;
+
+my @args = ();
+if ( !$error && $opt{'args_callback'} ) {
+ @args = &{ $opt{'args_callback'} }( $cgi, $new );
+}
+
+if ( !$error && $opt{'debug'} ) {
+ warn "$me updating record in $table table using $class class\n";
+ warn Dumper(\%hash);
+ warn "with args: \n". Dumper(\@args) if @args;
+}
+
+if ( !$error ) {
+ if ( $pkeyvalue ) {
+ $error = $new->replace($old, @args);
+ } else {
+ $error = $new->insert(@args);
+ $pkeyvalue = $new->getfield($pkey);
+ }
+}
+
+if ( !$error && $opt{'process_m2m'} ) {
+
+ if ( $opt{'debug'} ) {
+ warn "$me processing m2m:\n". Dumper( %{ $opt{'process_m2m'} },
+ 'params' => scalar($cgi->Vars),
+ );
+ }
+
+ $error = $new->process_m2m( %{ $opt{'process_m2m'} },
+ 'params' => scalar($cgi->Vars),
+ );
+}
+
+if ( !$error && $opt{'process_m2name'} ) {
+
+ if ( $opt{'debug'} ) {
+ warn "$me processing m2name:\n". Dumper( %{ $opt{'process_m2name'} },
+ 'params' => scalar($cgi->Vars),
+ );
+ }
+
+ $error = $new->process_m2name( %{ $opt{'process_m2name'} },
+ 'params' => scalar($cgi->Vars),
+ );
+}
+
+# XXX print?!?!
+
+if ( $error ) {
+ $cgi->param('error', $error);
+ if ( $opt{'clear_on_error'} && scalar(@{$opt{'clear_on_error'}}) ) {
+ foreach my $field (@{$opt{'clear_on_error'}}) {
+ $cgi->param($field, '')
+ }
+ }
+ my $edit_ext = $opt{'edit_ext'} || 'html';
+ my $url = $opt{'error_redirect'} || popurl(2)."$table.$edit_ext";
+ if ( length($cgi->query_string) > 1920 ) { #stupid IE 2083 URL limit
+
+ 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";
+ }
+ print $cgi->redirect("$url?redirect=$session");
+ } else {
+ print $cgi->redirect("$url?". $cgi->query_string );
+ }
+} elsif ( $opt{'redirect'} ) {
+ print $cgi->redirect( $opt{'redirect'}. $pkeyvalue );
+} else {
+ print $cgi->redirect( popurl(3).
+ ( $opt{'viewall_dir'} || 'search' ).
+ "/$table.html"
+ );
+}
+
+</%init>
diff --git a/httemplate/edit/process/invoice_logo.html b/httemplate/edit/process/invoice_logo.html
new file mode 100644
index 000000000..d641a9959
--- /dev/null
+++ b/httemplate/edit/process/invoice_logo.html
@@ -0,0 +1,26 @@
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+ unless $curuser->access_right('Configuration');
+
+my $conf = new FS::Conf;
+
+$cgi->param('type') =~ /^(png|eps)$/ or die "illegal type";
+my $type = $1;
+
+$cgi->param('name') =~ /^([^\.\/]*)$/ or die "illegal name";
+my $tname = my $name = $1;
+$tname = "_$tname" if length($tname);
+
+$cgi->param('preview_session') =~ /^(\w*)$/ or die "illegal preview_session";
+my $session = $1;
+my $data = decode_base64( $curuser->option("logo_preview$session") );
+
+$conf->set("logo$name.$type", $data);
+
+$cgi->redirect(popurl(3). "edit/invoice_logo.html?type=$type;name=$name;msg=Logo%20changed");
+
+</%init>
+
diff --git a/httemplate/edit/process/invoice_template.html b/httemplate/edit/process/invoice_template.html
new file mode 100644
index 000000000..6c9371ad1
--- /dev/null
+++ b/httemplate/edit/process/invoice_template.html
@@ -0,0 +1,15 @@
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $conf = new FS::Conf;
+
+my $confname = $cgi->param('confname');
+my $value = $cgi->param('value');
+
+$conf->set($confname, $value);
+
+$cgi->redirect(popurl(3). 'browse/invoice_template.html');
+
+</%init>
diff --git a/httemplate/edit/process/part_event.html b/httemplate/edit/process/part_event.html
new file mode 100644
index 000000000..428025fd1
--- /dev/null
+++ b/httemplate/edit/process/part_event.html
@@ -0,0 +1,86 @@
+<% include( 'elements/process.html',
+ #'debug' => 1,
+ 'table' => 'part_event',
+ 'viewall_dir' => 'browse',
+ 'process_m2name' =>
+ {
+ 'link_table' => 'part_event_condition',
+ 'num_col' => 'eventpart',
+ 'name_col' => 'conditionname',
+ 'names_list' => [ FS::part_event_condition->all_conditionnames() ],
+ 'param_style' => 'name_colN values',
+ 'args_callback' => sub { # FS/FS/m2name_Common.pm
+ my( $object, $prefix, $params, $listref ) = @_;
+ #warn "$object $prefix $params $listref\n";
+
+ my $cond = $object->conditionname;
+
+ my %option_fields = $object->option_fields;
+
+ push @$listref, map {
+ my $field = $_;
+
+ my $cgi_field = "$prefix$cond.$field";
+
+ my $value = $params->{$cgi_field};
+
+ my $info = $option_fields{$_};
+ $info = { label=>$info, type=>'text' }
+ unless ref($info);
+
+ if ( $info->{'type'} =~
+ /^(select|checkbox)-?multiple$/
+ or $info->{'type'} =~ /^select/
+ && $info->{'multiple'}
+ )
+ {
+ #special processing for compound fields
+ $value = { map { $_ => 1 }
+ split(/\0/, $value)
+ };
+ } elsif ( $info->{'type'} eq 'freq' ) {
+ $value .= $params->{$cgi_field.'_units'};
+ }
+
+ #warn "value of $cgi_field is $value\n";
+
+ ( $field => $value );
+ }
+ keys %option_fields;
+ },
+ },
+
+ 'args_callback' => sub {
+
+ my( $cgi, $object ) = @_;
+
+ my $prefix = $object->action.'.';
+
+ map { my $option = $_;
+ #my $value = scalar( $cgi->param( "$prefix$option" ) );
+ my $value = join(',', $cgi->param( "$prefix$option" ) );
+
+ if ( $option eq 'reasonnum' && $value == -1 ) {
+ $value = {
+ 'typenum' => scalar( $cgi->param( "new$prefix${option}T" ) ),
+ 'reason' => scalar( $cgi->param( "new$prefix${option}" ) ),
+ };
+ }
+
+ ( $option => $value );
+ }
+ @{ $object->option_fields_listref };
+
+ },
+
+ 'agent_virt' => 1,
+ 'agent_null_right' => 'Edit global billing events',
+)
+%>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Edit billing events')
+ || $FS::CurrentUser::CurrentUser->access_right('Edit global billing events');
+
+</%init>
diff --git a/httemplate/edit/process/quick-cust_pkg.cgi b/httemplate/edit/process/quick-cust_pkg.cgi
index 7afc9f2bb..66d02e307 100644
--- a/httemplate/edit/process/quick-cust_pkg.cgi
+++ b/httemplate/edit/process/quick-cust_pkg.cgi
@@ -1,5 +1,3 @@
-%
-%
%#untaint custnum
%$cgi->param('custnum') =~ /^(\d+)$/
% or die 'illegal custnum '. $cgi->param('custnum');
@@ -9,19 +7,21 @@
%my $pkgpart = $1;
%
%my @cust_pkg = ();
-%my $error = FS::cust_pkg::order($custnum, [ $pkgpart ], [], \@cust_pkg, );
+%my $error = FS::cust_pkg::order($custnum, [ $pkgpart ], [], \@cust_pkg, [ $cgi->param('refnum') ] );
%
%if ($error) {
-%
-
-<!-- mason kludge -->
-%
-% eidiot($error);
+% $cgi->param('error', $error);
+% print $cgi->redirect(popurl(2). 'misc/order_pkg.html?'. $cgi->query_string );
%} else {
-% print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum".
-% "#cust_pkg". $cust_pkg[0]->pkgnum );
-%}
-%
-%
+% my $frag = "cust_pkg". $cust_pkg[0]->pkgnum;
+<% header('Package ordered') %>
+ <SCRIPT TYPE="text/javascript">
+ // XXX fancy ajax rebuild table at some point, but a page reload will do for now
+ // XXX chop off trailing #target and replace... ?
+ window.top.location = '<% popurl(3). "view/cust_main.cgi?keywords=$custnum;fragment=$frag#$frag" %>';
+ </SCRIPT>
+
+ </BODY></HTML>
+%}