#XXX better description
'Events are billing, collection or other actions triggered when certain '.
'customer, invoice, package or other conditions are met.<BR><BR>'.
- qq!<A HREF="${p}edit/part_event.html"><I>Add a new event</I></A><BR><BR>!;
+ qq!<FORM METHOD="POST" ACTION="${p}edit/part_event.html">!.
+ qq!<A HREF="${p}edit/part_event.html"><I>Add a new event</I></A>!.
+ ' or <SELECT NAME="clone"><OPTION></OPTION>';
+
+foreach my $part_event ( qsearch('part_event', {'diabled'=>''}) ) {
+ $html_init .= '<OPTION VALUE="'. $part_event->eventpart. '">'.
+ $part_event->event. '</OPTION>';
+}
+
+$html_init .= '</SELECT><INPUT TYPE="submit" VALUE="Clone existing event">'.
+ '</FORM><BR>';
my $count_query = 'SELECT COUNT(*) FROM part_event WHERE '.
$FS::CurrentUser::CurrentUser->agentnums_sql(
<FORM ACTION="<% $url %>" METHOD=POST NAME="edit_topform">
<INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
-<INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $object->$pkey() %>">
+<INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
<FONT SIZE="+1"><B>
<% ( $opt{labels} && exists $opt{labels}->{$pkey} )
: $pkey
%>
</B></FONT>
-#<% $object->$pkey() || "(NEW)" %>
+#<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
% my $tablenum = 0;
<TABLE ID="TableNumber<% $tablenum++ %>" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
% my @existing = ();
% if ( $mode eq 'error' ) {
% @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object );
-% } elsif ( $object->$pkey() ) { # $mode eq 'edit'
+% } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone'
% @existing = $object->$table();
% warn scalar(@existing). " from $object->$table: ". join('/', @existing)
% if $opt{'debug'};
<BR>
-<INPUT TYPE="submit" ID="submit" VALUE="<% $object->$pkey() ? "Apply changes" : "Add $opt{'name'}" %>">
+<INPUT TYPE="submit" ID="submit" VALUE="<% ( !$clone && $object->$pkey() ) ? "Apply changes" : "Add $opt{'name'}" %>">
</FORM>
$cgi = new CGI($pref);
}
-my $object;
+my %qsearch = (
+ 'table' => $table,
+ 'extra_sql' => ( $opt{'agent_virt'}
+ ? ' AND '. $curuser->agentnums_sql(
+ 'null_right' => $opt{'agent_null_right'}
+ )
+ : ''
+ ),
+);
+
my $mode;
+my $object;
+my $clone = '';
if ( $cgi->param('error') ) {
$mode = 'error';
&{$opt{'error_callback'}}($cgi, $object, $fields, \%opt )
if $opt{'error_callback'};
+} elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) {
+
+ $mode = 'clone';
+
+ $clone = $1;
+
+ $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } });
+
+ #XXX document me
+ &{$opt{'clone_callback'}}($cgi, $object, $fields)
+ if $opt{'clone_callback'};
+
+ #$object->$pkey('');
+
+ $opt{action} ||= 'Add';
+
} elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
$mode = 'edit';
$value = $query;
}
$value =~ /^(\d+)$/ or die "unparsable $pkey";
- $object = qsearchs({
- 'table' => $table,
- 'hashref' => { $pkey => $1 },
- 'extra_sql' => ( $opt{'agent_virt'}
- ? ' AND '. $curuser->agentnums_sql(
- 'null_right' => $opt{'agent_null_right'}
- )
- : ''
- ),
- });
+ $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } });
+
warn "$table $pkey => $1"
if $opt{'debug'};