X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Felements%2Fprocess.html;h=0439d4e9c195eccc2ffc6522ec83d98b0df8fe8e;hp=e24f3f6813a05e0ae0f9c73dda6d82afe2c4c24c;hb=63973c641c4be00765fa27e55c57cc5b9aa4da19;hpb=03ceab71dad1e5eb366865d304e5e459cc905ce4 diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html index e24f3f681..0439d4e9c 100644 --- a/httemplate/edit/process/elements/process.html +++ b/httemplate/edit/process/elements/process.html @@ -2,7 +2,7 @@ Example: - include( 'elements/process.html', + <& elements/process.html, ### # required @@ -59,12 +59,23 @@ Example: 'process_o2m' => { 'table' => table_name', 'num_col' => 'column', #if column name is different in #link_table than source_table + 'fields' => [qw( fieldname fieldname2 )], }, + 'skip_process' => 0, #boolean, if set true, will skip the main table + #add/edit processing and only run any linked table + #process_ items + #checks CGI params and whatever else before much else runs #return an error string or empty for no error 'precheck_callback' => sub { my( $cgi ) = @_; }, + #after the new object is created + 'post_new_object_callback' => sub { my( $cgi, $object ) = @_; }, + + #after everything's inserted + 'noerror_callback' => sub { my( $cgi, $object ) = @_; }, + #supplies arguments to insert() and replace() # for use with tables that are FS::option_Common (among other things) 'args_callback' => sub { my( $cgi, $object ) = @_; }, @@ -75,13 +86,19 @@ Example: 'agent_virt' => 1, 'agent_null_right' => 'Access Right Name', - ) + #special bulk insert mode + 'bulk' => 'field', + + &> %if ( $error ) { % % my $edit_ext = $opt{'edit_ext'} || 'html'; % my $url = $opt{'error_redirect'} || popurl(2)."$table.$edit_ext"; + +% #my $query = $m->scomp('/elements/create_uri_query'); +% #$cgi->redirect("$url?$query"); % if ( length($cgi->query_string) > 1920 ) { #stupid IE 2083 URL limit % % my $session = int(rand(4294967296)); #XXX @@ -125,14 +142,16 @@ Example: % % if ( $opt{'redirect'} ) { % -<% $cgi->redirect( $opt{'redirect'}. $pkeyvalue ) %> +<% $cgi->redirect( $opt{'redirect'}. $new_pkey) %> % % } else { % % my $ext = $opt{'viewall_ext'} || 'html'; +% my $viewall_dir = $opt{'viewall_dir'} || 'search'; +% my $viewall_url = $opt{'viewall_url'} || ($viewall_dir . "/$table.$ext"); % -<% $cgi->redirect( popurl(3). ($opt{viewall_dir}||'search'). "/$table.$ext" ) %> -% +%#<% $cgi->redirect( popurl(3). ($opt{viewall_dir}||'search'). "/$table.$ext" ) %> +<% $cgi->redirect( popurl(3) . $viewall_url ) %> % } % %} @@ -158,13 +177,13 @@ my $fields = $opt{'fields'} #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ]; || [ fields($table) ]; -my $pkeyvalue = $cgi->param($pkey); +my $old_pkey = $cgi->param($pkey); my $old = ''; -if ( $pkeyvalue ) { +if ( $old_pkey ) { $old = qsearchs({ 'table' => $table, - 'hashref' => { $pkey => $pkeyvalue }, + 'hashref' => { $pkey => $old_pkey }, 'extra_sql' => ( $opt{'agent_virt'} ? ' AND '. $curuser->agentnums_sql( 'null_right' => $opt{'agent_null_right'} @@ -174,121 +193,176 @@ if ( $pkeyvalue ) { }); } +my $bfield = $opt{'bulk'}; + my %hash = map { my @entry = ( $_ => scalar($cgi->param($_)) ); $opt{'value_callback'} ? ( $_ => &{ $opt{'value_callback'} }( @entry )) : ( @entry ) - } @$fields; + } grep { $_ ne $bfield } @$fields; -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} - or $opt{'agent_null_right'} - && ! $new->agentnum - && $curuser->access_right($opt{'agent_null_right'}); +my @values = ( 1 ); +if ( $bfield ) { + @values = $cgi->param($bfield); + #warn join(',', @values); } -$error ||= $new->check; +my $new; +my $new_pkey = ''; +foreach my $value ( @values ) { -my @args = (); -if ( !$error && $opt{'args_callback'} ) { - @args = &{ $opt{'args_callback'} }( $cgi, $new ); -} + if ($opt{'skip_process'}) { -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; -} + $new = $old; + $new_pkey = $old_pkey; -if ( !$error ) { - if ( $pkeyvalue ) { - $error = $new->replace($old, @args); } else { - $error = $new->insert(@args); - $pkeyvalue = $new->getfield($pkey); - } -} -if ( !$error && $opt{'process_m2m'} ) { + $new = $class->new( \%hash ); + + $new->$bfield($value) if $bfield; + + 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{'post_new_object_callback'} ) { + &{ $opt{'post_new_object_callback'} }( $cgi, $new ); + } - my @process_m2m = ref($opt{'process_m2m'}) eq 'ARRAY' - ? @{ $opt{'process_m2m'} } - : ( $opt{'process_m2m'} ); + if ( $opt{'agent_virt'} ) { - foreach my $process_m2m (@process_m2m) { + if ( ! $new->agentnum + && ( ! $opt{'agent_null_right'} + || ! $curuser->access_right($opt{'agent_null_right'}) + ) + ) + { - $process_m2m->{'params'} ||= scalar($cgi->Vars); + $error ||= 'Select an agent'; - warn "$me processing m2m:\n". Dumper( %$process_m2m ) - if $opt{'debug'}; + } else { + + die "illegal agentnum" + unless $curuser->agentnums_href->{$new->agentnum} + or $curuser->access_right('View customers of all agents') + or $opt{'agent_null_right'} + && ! $new->agentnum + && $curuser->access_right($opt{'agent_null_right'}); + + } + + } + + 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 ( $old_pkey ) { + + &{ $opt{'edit_callback'} }( $new, $old ) if $opt{'edit_callback'}; + + $error = $new->replace($old, @args); + } else { + $error = $new->insert(@args); + } + $new_pkey = $new->getfield($pkey); + } + + } #unless $opt{'skip_process'} + + if ( !$error && $opt{'process_m2m'} ) { + + my @process_m2m = ref($opt{'process_m2m'}) eq 'ARRAY' + ? @{ $opt{'process_m2m'} } + : ( $opt{'process_m2m'} ); + + foreach my $process_m2m (@process_m2m) { + + $process_m2m->{'params'} ||= scalar($cgi->Vars); + + warn "$me processing m2m:\n". Dumper( %$process_m2m ) + if $opt{'debug'}; + + $error = $new->process_m2m( %$process_m2m ); + } - $error = $new->process_m2m( %$process_m2m ); } -} + if ( !$error && $opt{'process_m2name'} ) { -if ( !$error && $opt{'process_m2name'} ) { + my @process_m2name = ref($opt{'process_m2name'}) eq 'ARRAY' + ? @{ $opt{'process_m2name'} } + : ( $opt{'process_m2name'} ); - my @process_m2name = ref($opt{'process_m2name'}) eq 'ARRAY' - ? @{ $opt{'process_m2name'} } - : ( $opt{'process_m2name'} ); + foreach my $process_m2name (@process_m2name) { - foreach my $process_m2name (@process_m2name) { + if ( $opt{'debug'} ) { + warn "$me processing m2name:\n". Dumper( %{ $process_m2name }, + 'params' => scalar($cgi->Vars), + ); + } - if ( $opt{'debug'} ) { - warn "$me processing m2name:\n". Dumper( %{ $process_m2name }, - 'params' => scalar($cgi->Vars), - ); + $error = $new->process_m2name( %{ $process_m2name }, + 'params' => scalar($cgi->Vars), + ); } - $error = $new->process_m2name( %{ $process_m2name }, - 'params' => scalar($cgi->Vars), - ); } -} + if ( !$error && $opt{'process_o2m'} ) { -if ( !$error && $opt{'process_o2m'} ) { + my @process_o2m = ref($opt{'process_o2m'}) eq 'ARRAY' + ? @{ $opt{'process_o2m'} } + : ( $opt{'process_o2m'} ); - my @process_o2m = ref($opt{'process_o2m'}) eq 'ARRAY' - ? @{ $opt{'process_o2m'} } - : ( $opt{'process_o2m'} ); + foreach my $process_o2m (@process_o2m) { - foreach my $process_o2m (@process_o2m) { + if ( $opt{'debug'} ) { + warn "$me processing o2m:\n". Dumper( %{ $process_o2m }, + 'params' => scalar($cgi->Vars), + ); + } - if ( $opt{'debug'} ) { - warn "$me processing o2m:\n". Dumper( %{ $process_o2m }, - 'params' => scalar($cgi->Vars), - ); + $error = $new->process_o2m( %{ $process_o2m }, + 'params' => scalar($cgi->Vars), + ); } - $error = $new->process_o2m( %{ $process_o2m }, - 'params' => scalar($cgi->Vars), - ); } -} + 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, '') + } + } + + } else { -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, '') + if ( $opt{'noerror_callback'} ) { + &{ $opt{'noerror_callback'} }( $cgi, $new ); } + } -} + last if $error; + +}