6 'name_singular' => #singular name for the record
7 # (preferred, will be pluralized automatically)
8 'name' => #name for the record
9 # (deprecated, will be pluralized simplistically)
12 #? 'primary_key' => #required when the dbdef doesn't know...???
17 #listref - each item is a literal column name (or method) or hashref
19 #if not specified all columns (except for the primary key) will be editable
22 { 'field' => 'another_columname',
23 'type' => 'text', #text
29 #selectlayers (can now use after a tablebreak-tr-title... but not inside columnstart/columnnext/columnend)
35 #hidden - hidden value from object
36 #fixed - display fixed value from object or here
39 'value' => 'Y', #for checkbox, title, fixed, hidden
41 'onchange' => 'javascript_function',
43 'include_opt_callback' => sub { my $object = @_;
44 ( 'option' => 'value', );
47 'm2name_table' => 'table_name',
48 'm2name_namecol' => 'name_column',
51 #'m2m_srccol' => #opt, if not the same as this table
52 'm2m_dstcol' => #required for now, eventuaully opt, if not the same as target table
56 'm2_label' => 'Label', #
57 'm2_new_default' => \@table_name_objects, #default
60 'm2_error_callback' => sub { my($cgi, $object) = @_; },
61 'm2_remove_warnings' => \%warnings, #hashref of warning
64 'm2_new_js' => 'function_name', #javascript function called
65 #on spawned rows (one arg:
67 'm2_remove_js' => 'function_name', #js function called when
68 #a row is deleted (three
71 #layer_fields & layer_values_callback only for selectlayer
73 'fieldname' => 'Label',
76 type =>'text', #text, money
79 'layer_values_callback' =>
81 my( $cgi, $object ) = @_;
82 { 'layer' => { 'fieldname' => 'current_value',
83 'fieldname2' => 'field2value',
86 'layer2' => { 'l2fieldname' => 'l2value',
95 'menubar' => '', #menubar arrayref
99 'agent_null' => 1, #if true, always allow no-agentnum globals
100 'agent_null_right' => 'Access Right Name',
101 'agent_clone_extra_sql' => '', #if provided, this overrides the extra_sql
102 #implementing agent virt, for clone
103 #operations. i.e. pass "1=1" to allow
106 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
108 # overrides default popurl(1)."process/$table.html"
109 'post_url' => popurl(1).'process/something',
111 #we're in a popup (no title/menu/searchboxes)
114 #we're embedded (rows only: no header at all, no html_init, no error
115 # display, no <FORM>, no hidden fields for table name or primary key, no
116 # display of primary key, no submit button, no html_foot, no footer)
117 'embed' => $object, #need to pass the object
119 #don't show the primary key label and value
120 'no_pkey_display' => 1,
126 'body_etc' => '', # Additional BODY attributes, i.e. onLoad=""
128 'html_init' => '', #after the header/menubar
130 #string or coderef of additional HTML to add before </TABLE>
131 'html_table_bottom' => '',
133 #after </TABLE> but before the submit
134 'html_bottom' => '', #string
135 'html_bottom' => sub {
141 #javascript function name, will be called with form name as arg
142 'onsubmit' => 'check_form_data',
144 #at the very bottom (well, as low as you can go from here)
148 # initialization callbacks
151 ###global callbacks, always run if provided
153 #after decoding long CGI "redirect=" responses but
154 # before object creation/search
155 # (useful if you have a long form that might trigger redirect= and you need
156 # to do things with $cgi params - they're not decoded in the calling
158 'begin_callback' = sub { my( $cgi, $fields_listref, $opt_hashref ) = @_; },
160 #after the mode-specific object creation/search
161 'end_callback' = sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
163 ###mode-specific callbacks. one (and only one) of these four is called
166 'new_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
169 'edit_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
171 #run when re-displaying with an error
172 'error_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
175 'clone_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
177 ###callbacks called in new mode only
179 # returns a hashref for the new object
180 'new_hashref_callback'
182 # returns the new object iself (otherwise, ->new is called)
183 'new_object_callback'
187 #run before display to return a different value
188 'value_callback' => sub { my( $columname, $value ) = @_; },
190 #run before display to manipulate element of the 'fields' arrayref
191 'field_callback' => sub { my( $cgi, $object, $field_hashref ) = @_; },
197 % unless ( $opt{embed} ) {
199 % my $title = $opt{action}. ' '. ( $opt{name} || $opt{'name_singular'} );
201 % my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html";
202 % $viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'};
205 % if ( $opt{'menubar'} ) {
206 % @menubar = @{ $opt{'menubar'} };
208 % my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'});
210 % "View all $items" => $viewall_url,
214 <% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html',
216 include( '/elements/menubar.html', @menubar ),
221 <% defined($opt{'html_init'})
222 ? ( ref($opt{'html_init'})
223 ? &{$opt{'html_init'}}()
229 <% include('/elements/error.html') %>
231 % my $url = $opt{'post_url'} || popurl(1)."process/$table.html";
233 <FORM NAME = "edit_topform"
235 ACTION = "<% $url %>"
236 <% $opt{onsubmit} ? 'onSubmit="return '.$opt{onsubmit}.'(this)"' : '' %>
239 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
240 <INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
242 % unless ( $opt{'no_pkey_display'} ) {
245 <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
246 ? $opt{labels}->{$pkey}
250 #<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
257 <TABLE ID="TableNumber<% $tablenum++ %>" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
260 % my @g_row_stack = ();
261 % foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} }
265 % my $trash = &{ $opt{'field_callback'} }( $cgi, $object, $f )
266 % if $opt{'field_callback'};
268 % my $field = $f->{'field'};
269 % my $type = $f->{'type'} ||= 'text';
271 % my $label = ( $opt{labels} && exists $opt{labels}->{$field} )
272 % ? $opt{labels}->{$field}
275 % my $onchange = $f->{'onchange'};
277 % my $layer_values = {};
278 % $layer_values = &{ $f->{'layer_values_callback'} }( $cgi, $object )
279 % if $f->{'layer_values_callback'}
280 % && ! $f->{'m2name_table'}
281 % && ! $f->{'o2m_table'}
282 % && ! $f->{'m2m_method'};
284 % warn "layer values: ". Dumper($layer_values)
287 % my %include_common = (
289 % #text and derivitives
290 % 'size' => $f->{'size'},
291 % 'maxlength' => $f->{'maxlength'},
292 % 'prefix' => $f->{'prefix'},
293 % 'postfix' => $f->{'postfix'},
296 % 'rows' => $f->{'rows'},
297 % 'cols' => $f->{'cols'},
299 % #checkbox, title, fixed, hidden
300 % #& deprecated weird value hashref used only by reason.html
301 % 'value' => $f->{'value'},
304 % 'noescape' => $f->{'noescape'},
307 % 'options' => $f->{'options'},
308 % 'labels' => $f->{'labels'},
309 % 'multiple' => $f->{'multiple'},
310 % 'label_showkey' => $f->{'label_showkey'},
311 % 'disable_empty' => $f->{'disable_empty'},
313 % 'reason_class' => $f->{'reason_class'},
316 % 'layer_fields' => $f->{'layer_fields'},
317 % 'layer_values' => $layer_values,
318 % 'html_between' => $f->{'html_between'},
320 % #umm. for select-agent_types at least
321 % 'disabled' => $f->{'disabled'},
322 % 'fixed' => $f->{'fixed'},
325 % 'colspan' => $f->{'colspan'},
326 % 'required' => $f->{'required'},
329 % $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}),
330 % qw( js_only html_only select_only layers_only cell_style ),#selectlayers,?
331 % qw( empty_label ), # select-*
332 % qw( value_col compare_sub order_by ), # select-table
333 % qw( table name_col ), #(select,checkboxes)-table
334 % qw( target_table link_table ), #checkboxes-table
335 % qw( hashref agent_virt agent_null agent_null_right ),#*-table
336 % qw( formatted_value ), #fixed
337 % qw( country ), #select-country
338 % qw( width height config ), #htmlarea
339 % qw( alt_format ), #select-cust_location
340 % qw( classnum ), # select-inventory_item
344 % $include_common{$_} = ref( $f->{$_} ) eq 'CODE'
345 % ? &{ $f->{$_} }( $cgi, $object ) #, $f )
347 % foreach grep exists($f->{$_}), qw( extra_sql );
349 % if ( $type eq 'tablebreak-tr-title' ) {
350 % $include_common{'table_id'} = 'TableNumber'. $tablenum++;
352 % if ( $type eq 'tablebreak-tr-title' || $type eq 'title' ) {
353 % $include_common{'colspan'} = $f->{colspan} if $f->{colspan};
356 % if ( $f->{include_opt_callback} ) {
357 % %include_common = ( %include_common,
358 % &{ $f->{include_opt_callback} }( $object )
362 % my $layer_prefix_on = '';
364 % my $include_sub = sub {
367 % my $fieldnum = delete $opt{'fieldnum'};
369 % my $include = $type;
370 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
371 % $include = "tr-$include" unless $include =~ /^(hidden|tablebreak|column)/;
373 % $include_common{'layer_prefix'} = "$field$fieldnum."
374 % if $layer_prefix_on;
377 % ( "/elements/$include.html",
378 % 'field' => "$field$fieldnum",
379 % 'id' => "$field$fieldnum", #separate?
380 % 'label_id' => $field."_label$fieldnum", #don't want field0_label0...
385 % if ( $include eq 'tr-input-date-field' ) {
386 % # it's either hacking it here, or changing a lot more stuff
388 % "/elements/$include.html", {
390 % 'value' => $opt{curr_value},
392 % 'noinit' => $f->{noinit},
400 % my $column_sub = sub {
403 % my $column = delete($opt{field});
404 % my $fieldnum = delete($opt{fieldnum});
405 % my $include = delete($opt{type}) || 'text';
406 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
408 % ( "/elements/$include.html",
409 % 'field' => $field.'__'.$column.$fieldnum,
410 % 'id' => $field.'__'.$column.$fieldnum,
411 % 'layer_prefix' => $field.'__'.$column.$fieldnum.".",
413 % ? ('cell_style' => 'border-top:1px solid black')
421 % unless ( $type =~ /^column/ ) {
422 % $g_row = 1 if $type eq 'tablebreak-tr-title';
424 % $g_row++ if $type eq 'title';
425 % $g_row += scalar( @{ $f->{options} } )-1 if $type eq 'radio';
427 % if ( $type eq 'columnstart' ) {
428 % push @g_row_stack, $g_row;
430 % #} elsif ( $type eq 'columnnext' ) {
431 % } elsif ( $type eq 'columnend' ) {
432 % $g_row = pop @g_row_stack;
438 % my $curr_value = '';
439 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
442 % if ( $f->{'m2name_table'} ) {
443 % $table = $f->{'m2name_table'};
444 % $col = $f->{'m2name_namecol'};
445 % } elsif ( $f->{'o2m_table'} ) {
446 % $table = $f->{'o2m_table'};
447 % $col = dbdef->table($f->{'o2m_table'})->primary_key;
448 % } elsif ( $f->{'m2m_method'} ) {
449 % $table = $f->{'m2m_method'};
450 % $col = $f->{'m2m_dstcol'};
453 % $layer_prefix_on = 1;
454 % #print out the fields for the existing m2s
456 % if ( $mode eq 'error' ) {
457 % @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object );
458 % } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone'
459 % @existing = $object->$table();
460 % warn scalar(@existing). " from $object->$table: ". join('/', @existing)
462 % } elsif ( $f->{'m2_new_default'} ) { # && $mode eq 'new'
463 % @existing = @{ $f->{'m2_new_default'} };
465 % foreach my $name_obj ( @existing ) {
467 % my $ex_label = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this '.
468 % lc($f->{'m2_label'}).
469 % qq(" onClick="remove_$field($fieldnum);").
470 % ' STYLE="color:#ff0000;font-weight:bold;'.
471 % 'padding-left:2px;padding-right:2px"'.
472 % '> '. ($f->{'m2_label'} || $field ). ' ';
474 % if ( $f->{'layer_values_callback'} ) {
475 % my %switches = ( 'mode' => $mode );
477 % &{ $f->{'layer_values_callback'} }( $cgi, $name_obj, \%switches );
479 % warn "layer values: ". Dumper($layer_values)
482 % my @existing = &{ $include_sub }(
483 % 'label' => $ex_label,
484 % 'fieldnum' => $fieldnum,
485 % 'curr_value' => $name_obj->$col(),
486 % 'onchange' => $onchange,
487 % 'layer_values' => $layer_values,
488 % 'cell_style' => ( $fieldnum ? 'border-top:1px solid black' : '' ),
490 % $existing[0] =~ s(^/elements/tr-)(/elements/);
491 % my @label = @existing;
492 % $label[0] = '/elements/tr-td-label.html';
494 <% include( @label ) %>
495 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
496 <% include( @existing ) %>
499 % if ( $f->{'m2_fields'} ) {
500 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
501 % my $column = $c->{field};
502 % my @column = &{ $column_sub }( %$c,
503 % 'fieldnum' => $fieldnum,
504 % 'curr_value' => $name_obj->$column()
507 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
508 style='text-align:right;vertical-align:top;
509 border-top:1px solid black;padding-top:5px;'>
510 <% $c->{'label'} || '' %>
512 <TD style='border-top:1px solid black;padding-top:3px;'>
513 <% include( @column ) %>
523 % #$field .= $fieldnum;
524 % $onchange .= "\nspawn_$field(what);";
526 % if ( $f->{curr_value_callback} ) {
527 % $curr_value = &{ $f->{curr_value_callback} }( $cgi, $object, $field ),
529 % $curr_value = $object->$field();
531 % $curr_value = &{ $opt{'value_callback'} }( $f->{'field'}, $curr_value )
532 % if $opt{'value_callback'} && $mode ne 'error';
535 % my @include = &{ $include_sub }(
537 % 'fieldnum' => $fieldnum,
538 % 'curr_value' => $curr_value,
539 % 'object' => $object,
541 % 'onchange' => $onchange,
542 % ( $fieldnum ? ('cell_style' => 'border-top:1px solid black') : () ),
545 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
546 % $include[0] =~ s(^/elements/tr-)(/elements/);
547 % my @label = @include;
548 % $label[0] = '/elements/tr-td-label.html';
550 <% include( @label ) %>
551 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
552 <% include( @include ) %>
555 % if ( $f->{'m2_fields'} ) {
556 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
557 % my $column = $c->{field};
558 % my @column = &{ $column_sub }( %$c, 'fieldnum' => $fieldnum );
560 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
561 style='text-align:right;vertical-align:top;
562 border-top:1px solid black;padding-top:5px;'>
563 <% $c->{'label'} || '' %>
565 <TD style='border-top:1px solid black;padding-top:3px;'>
566 <% include( @column ) %>
575 <% include( @include ) %>
578 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
580 <SCRIPT TYPE="text/javascript">
582 var <%$field%>_rownum = <% $g_row %>;
583 var <%$field%>_fieldnum = <% $fieldnum %>;
585 function spawn_<%$field%>(what) {
587 // only spawn if we're the last element... return if not
589 var field_regex = /(\d+)(_[a-z_]+)?$/;
590 var match = field_regex.exec(what.name);
592 alert(what.name + " didn't match for " + what);
595 if ( match[1] != <%$field%>_fieldnum ) {
599 // change the label on the last entry & add a remove button
600 var prev_label = document.getElementById('<% $field %>_label' + <%$field%>_fieldnum );
601 prev_label.innerHTML = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this <% lc($f->{'m2_label'}) %>" onClick="remove_<% $field %>(' + <%$field%>_fieldnum + ');" STYLE="color:#ff0000;font-weight:bold;padding-left:2px;padding-right:2px" > <% $f->{'m2_label'} || $field %>';
603 <%$field%>_fieldnum++;
607 % $include[0] =~ s(^/elements/tr-)(/elements/);
608 % my @layer_opt = ( @include,
609 % 'field' => $field."MAGIC_NUMBER",
610 % 'id' => $field."MAGIC_NUMBER",
611 % 'layer_prefix' => $field."MAGIC_NUMBER.",
613 % warn @layer_opt if $opt{'debug'};
615 var newrow = <% include(@layer_opt, html_only=>1) |js_string %>;
617 % #until the rest have html/js_only
618 % if ( $type eq 'selectlayers' || $type =~ /^select-cgp_rule_/ ) {
619 var newfunc = <% include(@layer_opt, js_only=>1) |js_string %>;
624 // substitute in the new field name
625 var magic_regex = /MAGIC_NUMBER/g;
626 newrow = newrow.replace( magic_regex, <%$field%>_fieldnum );
627 newfunc = newfunc.replace( magic_regex, <%$field%>_fieldnum );
630 if (window.ActiveXObject) {
631 window.execScript(newfunc);
632 } else { /* (window.XMLHttpRequest) */
633 //window.eval(newfunc);
634 setTimeout(newfunc, 0);
639 //hmm, can't use selectlayers after a tablebreak-title for now
640 var table = document.getElementById('TableNumber<% $tablenum-1 %>');
642 var row = table.insertRow(<%$field%>_rownum++);
644 var label_cell = document.createElement('TD');
646 label_cell.id = '<% $field %>_label' + <%$field%>_fieldnum;
648 label_cell.style.textAlign = "right";
649 label_cell.style.verticalAlign = "top";
650 label_cell.style.borderTop = "1px solid black";
651 label_cell.style.paddingTop = "5px";
653 label_cell.innerHTML = '<% $label %>';
655 row.appendChild(label_cell);
657 var widget_cell = document.createElement('TD');
659 widget_cell.style.borderTop = "1px solid black";
660 widget_cell.style.paddingTop = "3px";
661 widget_cell.colSpan = "<% $f->{'colspan'} || 1 %>"
663 widget_cell.innerHTML = newrow;
665 row.appendChild(widget_cell);
667 % if ( $f->{'m2_fields'} ) {
668 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
669 % my $column = $c->{field};
670 % my @column = &{ $column_sub }(%$c, 'fieldnum' => 'MAGIC_NUMBER');
672 var column = <% include(@column, html_only=>1) |js_string %>;
673 column = column.replace( magic_regex, <%$field%>_fieldnum );
675 var column_label = document.createElement('TD');
677 '<% $field %>__<% $column %>_label' + <%$field%>_fieldnum;
679 column_label.style.textAlign = "right";
680 column_label.style.verticalAlign = "top";
681 column_label.style.borderTop = "1px solid black";
682 column_label.style.paddingTop = "5px";
684 column_label.innerHTML = '<% $c->{'label'} || '' %>';
686 row.appendChild(column_label);
688 var column_widget = document.createElement('TD');
690 column_widget.style.borderTop = "1px solid black";
691 column_widget.style.paddingTop = "3px";
693 column_widget.innerHTML = column;
695 row.appendChild(column_widget);
700 % if ( $f->{'m2_new_js'} ) {
701 // take out items selected in previous dropdowns
702 var new_element = document.getElementById("<%$field%>" + <%$field%>_fieldnum );
703 <% $f->{'m2_new_js'} %>(new_element);
705 if ( new_element.length < 2 ) {
706 //just the ** Select new **, so don't display the row
707 row.style.display = 'none';
713 function remove_<%$field%>(remove_fieldnum) {
714 //alert("remove <%$field%> " + remove_fieldnum);
715 var select = document.getElementById('<%$field%>' + remove_fieldnum);
718 alert("can't find element <%$field%>" + remove_fieldnum);
722 % my $warnings = $f->{'m2_remove_warnings'};
724 var sel_value = select.options[select.selectedIndex].value;
725 % foreach my $value ( keys %$warnings ) {
726 if ( sel_value == '<% $value %>' ) {
727 if ( ! confirm( <% $warnings->{$value} |js_string %> ) ) {
734 select.disabled = 'disabled'; // this seems to prevent it from being submitted on tested browsers so far (IE, moz, konq at least)
735 var label_td = document.getElementById('<%$field%>_label' + remove_fieldnum );
736 label_td.parentNode.style.display = 'none';
738 % if ( $f->{m2_remove_js} ) {
739 var opt = select.options[select.selectedIndex];
740 <% $f->{m2_remove_js} %>( opt.value, opt.text, 'no_match');
751 <% ref( $opt{'html_table_bottom'} )
752 ? &{ $opt{'html_table_bottom'} }( $object )
753 : $opt{'html_table_bottom'}
758 <% ref( $opt{'html_bottom'} )
759 ? &{ $opt{'html_bottom'} }( $object )
760 : $opt{'html_bottom'}
763 % unless ($opt{'embed'}) {
767 % unless ($opt{'no_submit'}) {
768 <INPUT TYPE = "submit"
770 VALUE = "<% ( !$clone && $object->$pkey() )
772 : "Add ". ($opt{'name'} || $opt{'name_singular'})
779 <% ref( $opt{'html_foot'} )
780 ? &{ $opt{'html_foot'} }( $object )
784 <% include("/elements/footer.html") %>
791 my $curuser = $FS::CurrentUser::CurrentUser;
793 #false laziness w/process.html
794 my $table = $opt{'table'};
795 my $class = "FS::$table";
796 my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
797 my $fields = $opt{'fields'}
798 #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
799 || [ grep { $_ ne $pkey } fields($table) ];
800 #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
804 if ( $opt{'embed'} ) {
806 $object = $opt{'embed'};
807 $mode = $cgi->param('error')
815 #$m->comp('/elements/handle_uri_query');
816 if ( $cgi->param('redirect') ) {
817 my $session = $cgi->param('redirect');
818 my $pref = $curuser->option("redirect$session");
819 die "unknown redirect session $session\n" unless length($pref);
820 $cgi = new CGI($pref);
823 &{$opt{'begin_callback'}}( $cgi, $fields, \%opt )
824 if $opt{'begin_callback'};
828 'extra_sql' => ( $opt{'agent_virt'}
829 ? ' AND '. $curuser->agentnums_sql(
830 'null_right' => $opt{'agent_null_right'}
836 if ( $cgi->param('error') ) {
840 $object = $class->new( {
841 map { $_ => scalar($cgi->param($_)) } fields($table)
844 &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt )
845 if $opt{'error_callback'};
847 } elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) {
853 $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'}
854 if $opt{'agent_clone_extra_sql'};
856 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } })
857 or die "$pkey $clone not found in $table";
859 &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt )
860 if $opt{'clone_callback'};
864 $opt{action} ||= 'Add';
866 } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
871 if ( $cgi->param($pkey) ) {
872 $value = $cgi->param($pkey)
874 my( $query ) = $cgi->keywords;
877 $value =~ /^(\d+)$/ or die "unparsable $pkey";
878 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } })
879 or die "$pkey $1 not found in $table";
881 warn "$table $pkey => $1"
884 &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt )
885 if $opt{'edit_callback'};
891 my $hashref = $opt{'new_hashref_callback'}
892 ? &{$opt{'new_hashref_callback'}}
895 $object = $opt{'new_object_callback'}
896 ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt )
897 : $class->new( $hashref );
899 &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt )
900 if $opt{'new_callback'};
904 &{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt )
905 if $opt{'end_callback'};
907 $opt{action} ||= $object->$pkey() ? 'Edit' : 'Add';