% }
<BR>
-<FONT SIZE="+1"><B><% mt('Billing address') |h %></B></FONT>
+<FONT CLASS="fsinnerbox-title"><% mt('Billing address') |h %></FONT>
<& cust_main/contact.html,
'cust_main' => $cust_main,
</SCRIPT>
<BR>
-<FONT SIZE="+1"><B><% mt('Service address') |h %></B></FONT>
+<FONT CLASS="fsinnerbox-title"><% mt('Service address') |h %></FONT>
-(<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>><% mt('same as billing address') |h %>)
+<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>><% mt('same as billing address') |h %>
<& cust_main/contact.html,
'cust_main' => $cust_main,
'pre' => 'ship_',
'style' => \@ship_style
&>
+<& cust_main/contacts_new.html,
+ 'cust_main' => $cust_main,
+&>
+
%# billing info
<& cust_main/billing.html, $cust_main,
'payinfo' => $payinfo,
'invoicing_list' => \@invoicing_list,
&>
+<BR>
% my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
% if (!$ro_comments || $cust_main->comments) {
- <BR><% mt('Comments') |h %>
- <% &ntable("#cccccc") %>
+ <BR>
+ <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
+ <TABLE CLASS="fsinnerbox">
<TR>
<TD>
<TEXTAREA NAME = "comments"
VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
onClick = "this.disabled=true; bottomfixup(this.form);"
>
+<BR><BR>
</FORM>
<& /elements/footer.html &>
%
% my $r = qq!<font color="#ff0000">*</font> !;
- <BR><FONT SIZE="+1"><B><% mt('Billing information') |h %></B></FONT>
+ <BR><FONT CLASS="fsinnerbox-title"><% mt('Billing information') |h %></FONT>
<% &ntable("#cccccc") %>
<TR>
</TABLE>
- <% $r %> <% mt('required fields') |h %>
+ <% $r %><% mt('required fields') |h %>
% }
<script type="text/javascript">
-<% &ntable("#cccccc") %>
+<TABLE CLASS="fsinnerbox">
<TR>
<TH ALIGN="right"><%$r%><% mt('Contact name (last, first)') |h %></TH>
<TD><INPUT TYPE="hidden" NAME="ss" VALUE="<% $opt{ss} %>"></TD>
% }
-
-
</TR>
% if ( $conf->exists('cust-email-high-visibility') && !$pre ) {
</TR>
% }
-% unless ( $conf->exists('cust-edit-alt-field-order') ) {
-<TR>
- <TD ALIGN="right"><% mt('Company') |h %></TD>
- <TD COLSPAN=7>
- <INPUT TYPE="text" NAME="<%$pre%>company" VALUE="<% $cust_main->get($pre.'company') |h %>" SIZE=70 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
- </TD>
-</TR>
-
-<& /elements/location.html,
- 'prefix' => $pre,
- 'object' => $cust_main,
- 'onchange' => $onchange,
- 'disabled' => $disabled,
- 'style' => \@style,
- 'same_checked' => $opt{'same_checked'},
- 'geocode' => $opt{'geocode'},
- 'censustract' => $opt{'censustract'},
-&>
-
-<TR>
- <TD ALIGN="right"><% $daytime_label %></TD>
- <TD COLSPAN=5>
- <INPUT TYPE="text" NAME="<%$pre%>daytime" VALUE="<% $cust_main->get($pre.'daytime') %>" SIZE=18 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
- </TD>
-</TR>
-
-<TR>
- <TD ALIGN="right"><% $night_label %></TD>
- <TD COLSPAN=5>
- <INPUT TYPE="text" NAME="<%$pre%>night" VALUE="<% $cust_main->get($pre.'night') %>" SIZE=18 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
- </TD>
-</TR>
-
-<TR>
- <TD ALIGN="right"><% $mobile_label %></TD>
- <TD COLSPAN=5>
- <INPUT TYPE="text" NAME="<%$pre%>mobile" VALUE="<% $cust_main->get($pre.'mobile') %>" SIZE=18 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
- </TD>
-</TR>
-
-<TR>
- <TD ALIGN="right"><% mt('Fax') |h %></TD>
- <TD COLSPAN=5>
- <INPUT TYPE="text" NAME="<%$pre%>fax" VALUE="<% $cust_main->get($pre.'fax') %>" SIZE=12 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
- </TD>
-</TR>
-
-% } else {
-
-<TR>
- <TD ALIGN="right"><% $daytime_label %></TD>
- <TD COLSPAN=5>
- <INPUT TYPE="text" NAME="<%$pre%>daytime" VALUE="<% $cust_main->get($pre.'daytime') %>" SIZE=18 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
- </TD>
-</TR>
+% unless ( $conf->exists('cust-edit-alt-field-order') ) { #standard order
-<TR>
- <TD ALIGN="right"><% $night_label %></TD>
- <TD COLSPAN=5>
- <INPUT TYPE="text" NAME="<%$pre%>night" VALUE="<% $cust_main->get($pre.'night') %>" SIZE=18 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
- </TD>
-</TR>
+ <& company &>
+ <& location &>
+ <& phones &>
+ <& fax &>
-<TR>
- <TD ALIGN="right"><% $mobile_label %></TD>
- <TD COLSPAN=5>
- <INPUT TYPE="text" NAME="<%$pre%>mobile" VALUE="<% $cust_main->get($pre.'mobile') %>" SIZE=18 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
- </TD>
-</TR>
-
-<& /elements/location.html,
- 'prefix' => $pre,
- 'object' => $cust_main,
- 'onchange' => $onchange,
- 'disabled' => $disabled,
- 'style' => \@style,
- 'same_checked' => $opt{'same_checked'},
- 'geocode' => $opt{'geocode'},
- 'censustract' => $opt{'censustract'},
-&>
+% } else { #alternate field order
-<TR>
- <TD ALIGN="right"><% mt('Fax') |h %></TD>
- <TD COLSPAN=5>
- <INPUT TYPE="text" NAME="<%$pre%>fax" VALUE="<% $cust_main->get($pre.'fax') %>" SIZE=12 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
- </TD>
-</TR>
-
-<TR>
- <TD ALIGN="right"><% mt('Company') |h %></TD>
- <TD COLSPAN=7>
- <INPUT TYPE="text" NAME="<%$pre%>company" VALUE="<% $cust_main->get($pre.'company') |h %>" SIZE=70 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
- </TD>
-</TR>
+ <& phones &>
+ <& location &>
+ <& fax &>
+ <& company &>
% }
</TABLE>
<%$r%><% mt('required fields') |h %><BR>
+<%def company>
+% my $display = ($cust_main->residential_commercial eq 'Commercial')
+% ? '' : 'none';
+ <TR ID="<%$pre%>company_row" STYLE="display:<%$display%>">
+ <TD ALIGN="right"><% mt('Company') |h %></TD>
+ <TD COLSPAN=7>
+ <INPUT TYPE="text" NAME="<%$pre%>company" ID="<%$pre%>company" VALUE="<% $cust_main->get($pre.'company') |h %>" SIZE=60 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
+ </TD>
+ </TR>
+</%def>
+
+<%def location>
+ <& /elements/location.html,
+ 'prefix' => $pre,
+ 'object' => $cust_main,
+ 'onchange' => $onchange,
+ 'disabled' => $disabled,
+ 'style' => \@style,
+ 'same_checked' => $opt{'same_checked'},
+ 'geocode' => $opt{'geocode'},
+ 'censustract' => $opt{'censustract'},
+ &>
+</%def>
+
+<%def phones>
+ <TR>
+ <TD ALIGN="right" VALIGN="top"><% mt('Phones') %></TD>
+ <TD COLSPAN=6>
+
+ <TABLE CELLSPACING=0 CELLPADDING=0>
+ <TR>
+ <TD>
+ <INPUT TYPE="text" NAME="<%$pre%>daytime" VALUE="<% $cust_main->get($pre.'daytime') %>" SIZE=18 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
+ <BR><FONT SIZE=-1><% $daytime_label %></FONT>
+ </TD>
+ <TD> </TD>
+ <TD>
+ <INPUT TYPE="text" NAME="<%$pre%>night" VALUE="<% $cust_main->get($pre.'night') %>" SIZE=18 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
+ <BR><FONT SIZE=-1><% $night_label %></FONT>
+ </TD>
+ <TD> </TD>
+ <TD>
+ <INPUT TYPE="text" NAME="<%$pre%>mobile" VALUE="<% $cust_main->get($pre.'mobile') %>" SIZE=18 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
+ <BR><FONT SIZE=-1><% $mobile_label %></FONT>
+ </TD>
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+</%def>
+
+<%def fax>
+ <TR>
+ <TD ALIGN="right"><% mt('Fax') |h %></TD>
+ <TD COLSPAN=5>
+ <INPUT TYPE="text" NAME="<%$pre%>fax" VALUE="<% $cust_main->get($pre.'fax') %>" SIZE=12 onChange="<% $onchange %>" <%$disabled%> <%$style%>>
+ </TD>
+ </TR>
+</%def>
+
+<%once>
+
+my $r = qq!<font color="#ff0000">*</font> !;
+
+</%once>
+<%shared>
+
+my( %opt, $cust_main, $pre, $onchange, $disabled, @style, $style,
+ $daytime_label, $night_label, $mobile_label,
+ );
+
+</%shared>
<%init>
-my %opt = @_;
-my $cust_main = $opt{'cust_main'};
-my $pre = $opt{'pre'};
-my $onchange = $opt{'onchange'};
-my $disabled = $opt{'disabled'};
-my @style = ( $opt{'style'} ? @{ $opt{'style'} } : () );
+%opt = @_;
+$cust_main = $opt{'cust_main'};
+$pre = $opt{'pre'};
+$onchange = $opt{'onchange'};
+$disabled = $opt{'disabled'};
+@style = ( $opt{'style'} ? @{ $opt{'style'} } : () );
-my $style = scalar(@style) ? 'STYLE="'. join(';', @style). '"' : '';
+$style = scalar(@style) ? 'STYLE="'. join(';', @style). '"' : '';
my $conf = new FS::Conf;
$opt{censustract} ||= $cust_main->censustract;
}
-my $daytime_label = FS::Msgcat::_gettext('daytime') =~ /^(daytime)?$/
- ? 'Day Phone'
- : FS::Msgcat::_gettext('daytime');
-my $night_label = FS::Msgcat::_gettext('night') =~/^(night)?$/
- ? 'Night Phone'
- : FS::Msgcat::_gettext('night') || 'Night Phone';
-my $mobile_label = FS::Msgcat::_gettext('mobile') =~/^(mobile)?$/
- ? 'Mobile Phone'
- : FS::Msgcat::_gettext('mobile') || 'Mobile Phone';
+$daytime_label = FS::Msgcat::_gettext('daytime') =~ /^(daytime)?$/
+ ? 'Day'
+ : FS::Msgcat::_gettext('daytime');
+$night_label = FS::Msgcat::_gettext('night') =~/^(night)?$/
+ ? 'Night'
+ : FS::Msgcat::_gettext('night') || 'Night';
+$mobile_label = FS::Msgcat::_gettext('mobile') =~/^(mobile)?$/
+ ? 'Mobile'
+ : FS::Msgcat::_gettext('mobile') || 'Mobile';
my $stateid_label = FS::Msgcat::_gettext('stateid') =~ /^(stateid)?$/
? 'Driver’s License'
? 'Driver’s License State'
: FS::Msgcat::_gettext('stateid_state') || 'Driver’s License State';
-my $r = qq!<font color="#ff0000">*</font> !;
-
my @invoicing_list = $cust_main->invoicing_list;
my $agentnum = $cust_main->agentnum if $cust_main->custnum;
--- /dev/null
+<DIV ID="contacts_div" STYLE="display:<% $display %>">
+<BR>
+<FONT CLASS="fsinnerbox-title">Contacts</FONT>
+<% include('/edit/elements/edit.html',
+ 'embed' => $opt{cust_main},
+ 'table' => 'cust_main',
+ 'labels' => { 'contactnum' => 'Contact',
+ #'locationnum' => ' ',
+ },
+ 'fields' => [
+ { 'field' => 'contactnum',
+ 'type' => 'contact',
+ 'colspan' => 6,
+ 'm2m_method' => 'cust_contact',
+ 'm2m_dstcol' => 'contactnum',
+ 'm2_label' => 'Contact',
+ 'm2_error_callback' => $m2_error_callback,
+ },
+ ],
+ 'agent_virt' => 1,
+ )
+%>
+</DIV>
+<%init>
+
+my %opt = @_;
+
+my $display = ($opt{'cust_main'}->residential_commercial eq 'Commercial')
+ ? ''
+ : 'none';
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+my $conf = new FS::Conf;
+
+my $m2_error_callback = sub {
+ my($cgi, $object) = @_;
+
+ #process_o2m fields in process/cust_main-contacts.html
+ my @fields = qw( first last title comment );
+ my @gfields = ( '', map "_$_", @fields );
+
+ map {
+ if ( /^contactnum(\d+)$/ ) {
+ my $num = $1;
+ if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
+ my $x = new FS::contact {
+ 'contactnum' => scalar($cgi->param("contactnum$num")),
+ map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
+ };
+ $x;
+ } else {
+ ();
+ }
+ } else {
+ ();
+ }
+ }
+ $cgi->param;
+};
+
+</%init>
%
% if ( @part_pkg ) {
- <BR><BR>
- <FONT SIZE="+1"><B><% mt('First package') |h %></B></FONT>
+ <BR>
+ <FONT CLASS="fsinnerbox-title"><% mt('First package') |h %></FONT>
<% ntable("#cccccc") %>
<TR>
-<% &ntable("#cccccc") %>
+<TABLE CLASS="fsinnerbox">
+
+<TR>
+ <TD ALIGN="right">Residential</TD>
+ <TD><INPUT TYPE = "radio"
+ NAME = "residential_commercial"
+ ID = "residential_commercial_Residential"
+ VALUE = "Residential"
+ onChange = "rescom_changed(this)"
+ <% $cust_main->residential_commercial eq 'Commercial' ? '' : 'CHECKED' %>
+ ></TD>
+</TR>
+<TR>
+ <TD ALIGN="right">Commercial</TD>
+ <TD><INPUT TYPE = "radio"
+ NAME = "residential_commercial"
+ ID = "residential_commercial_Commercial"
+ VALUE = "Commercial"
+ onChange = "rescom_changed(this)"
+ <% $cust_main->residential_commercial eq 'Commercial' ? 'CHECKED' : '' %>
+ ></TD>
+</TR>
+
+<SCRIPT TYPE="text/javascript">
+ function rescom_changed() {
+ var f = document.CustomerForm;
+
+ if ( f.residential_commercial_Residential.checked ) {
+ document.getElementById('contacts_div').style.display = 'none';
+ } else { // if ( f.residential_commercial_Commercial.checked ) {
+ document.getElementById('contacts_div').style.display = '';
+ }
+
+ if ( f.residential_commercial_Residential.checked && ! f.company.value.length ) {
+ document.getElementById('company_row').style.display = 'none'
+ } else { // if ( f.residential_commercial_Commercial.checked ) {
+ document.getElementById('company_row').style.display = '';
+ }
+
+ if ( f.residential_commercial_Residential.checked && ! f.ship_company.value.length ) {
+ document.getElementById('ship_company_row').style.display = 'none'
+ } else { // if ( f.residential_commercial_Commercial.checked ) {
+ document.getElementById('ship_company_row').style.display = '';
+ }
+ }
+</SCRIPT>
% foreach my $field ($cust_main->virtual_fields) {
<% $cust_main->pvf($field)->widget('HTML', 'edit',$cust_main->getfield($field)) %>
my $custnum = $opt{'custnum'};
+if ( $cgi->param('error') ) {
+ $cust_main->set('residential_commercial',
+ ($cgi->param('residential_commercial') eq 'Commercial')
+ ? 'Commercial'
+ : 'Residential'
+ );
+} elsif ( $custnum ) { #editing
+ $cust_main->set('residential_commercial',
+ length($cust_main->company)
+ ? 'Commercial'
+ : 'Residential'
+ );
+} else { #new customer
+ #config to default to commercial and/or disable residential when someone needs
+ $cust_main->set('residential_commercial', 'Residential');
+}
+
my $conf = new FS::Conf;
my $curuser = $FS::CurrentUser::CurrentUser;
#we're in a popup (no title/menu/searchboxes)
'popup' => 1,
+ #we're embedded (rows only: no header at all, no html_init, no error
+ # display, no <FORM>, no hidden fields for table name or primary key, no
+ # display of primary key, no submit button, no html_foot, no footer)
+ 'embed' => $object, #need to pass the object
+
###
# HTML callbacks
###
</%doc>
-<% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html',
- $title,
- include( '/elements/menubar.html', @menubar ),
- $opt{'body_etc'},
- )
-%>
+% unless ( $opt{embed} ) {
+%
+% my $title = $opt{action}. ' '. ( $opt{name} || $opt{'name_singular'} );
+%
+% my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html";
+% $viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'};
+%
+% my @menubar;
+% if ( $opt{'menubar'} ) {
+% @menubar = @{ $opt{'menubar'} };
+% } else {
+% my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'});
+% @menubar = (
+% "View all $items" => $viewall_url,
+% );
+% }
-<% defined($opt{'html_init'})
- ? ( ref($opt{'html_init'})
- ? &{$opt{'html_init'}}()
- : $opt{'html_init'}
- )
- : ''
-%>
+ <% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html',
+ $title,
+ include( '/elements/menubar.html', @menubar ),
+ $opt{'body_etc'},
+ )
+ %>
+
+ <% defined($opt{'html_init'})
+ ? ( ref($opt{'html_init'})
+ ? &{$opt{'html_init'}}()
+ : $opt{'html_init'}
+ )
+ : ''
+ %>
-<% include('/elements/error.html') %>
+ <% include('/elements/error.html') %>
% my $url = $opt{'post_url'} || popurl(1)."process/$table.html";
-<FORM NAME = "edit_topform"
- METHOD = POST
- ACTION = "<% $url %>"
- <% $opt{onsubmit} ? 'onSubmit="return '.$opt{onsubmit}.'(this)"' : '' %>
->
+ <FORM NAME = "edit_topform"
+ METHOD = POST
+ ACTION = "<% $url %>"
+ <% $opt{onsubmit} ? 'onSubmit="return '.$opt{onsubmit}.'(this)"' : '' %>
+ >
-<INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
-<INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
+ <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
+ <INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
-<FONT SIZE="+1"><B>
-<% ( $opt{labels} && exists $opt{labels}->{$pkey} )
- ? $opt{labels}->{$pkey}
- : $pkey
-%>
-</B></FONT>
-#<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
+ <FONT SIZE="+1"><B>
+ <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
+ ? $opt{labels}->{$pkey}
+ : $pkey
+ %>
+ </B></FONT>
+ #<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
+
+% }
% my $tablenum = 0;
<TABLE ID="TableNumber<% $tablenum++ %>" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
: $opt{'html_bottom'}
%>
-<BR>
+% unless ($opt{'embed'}) {
-<INPUT TYPE = "submit"
- ID = "submit"
- VALUE = "<% ( !$clone && $object->$pkey() )
- ? "Apply changes"
- : "Add ". ( $opt{'name'} || $opt{'name_singular'} )
- %>"
->
+ <BR>
-</FORM>
+ <INPUT TYPE = "submit"
+ ID = "submit"
+ VALUE = "<% ( !$clone && $object->$pkey() )
+ ? "Apply changes"
+ : "Add ". ( $opt{'name'} || $opt{'name_singular'} )
+ %>"
+ >
-<% ref( $opt{'html_foot'} )
- ? &{ $opt{'html_foot'} }( $object )
- : $opt{'html_foot'}
-%>
+ </FORM>
+
+ <% ref( $opt{'html_foot'} )
+ ? &{ $opt{'html_foot'} }( $object )
+ : $opt{'html_foot'}
+ %>
+
+ <% include("/elements/footer.html") %>
-<% include("/elements/footer.html") %>
+% }
<%init>
my(%opt) = @_;
|| [ grep { $_ ne $pkey } fields($table) ];
#my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
-#$m->comp('/elements/handle_uri_query');
-if ( $cgi->param('redirect') ) {
- my $session = $cgi->param('redirect');
- my $pref = $curuser->option("redirect$session");
- die "unknown redirect session $session\n" unless length($pref);
- $cgi = new CGI($pref);
-}
-
-&{$opt{'begin_callback'}}( $cgi, $fields, \%opt )
- if $opt{'begin_callback'};
-
-my %qsearch = (
- 'table' => $table,
- 'extra_sql' => ( $opt{'agent_virt'}
- ? ' AND '. $curuser->agentnums_sql(
- 'null_right' => $opt{'agent_null_right'}
- )
- : ''
- ),
-);
-
-my $mode;
-my $object;
+my( $mode, $object);
my $clone = '';
-if ( $cgi->param('error') ) {
+if ( $opt{'embed'} ) {
- $mode = 'error';
+ $object = $opt{'embed'};
+ $mode = $cgi->param('error')
+ ? 'error'
+ : $object->$pkey()
+ ? 'edit'
+ : 'new';
- $object = $class->new( {
- map { $_ => scalar($cgi->param($_)) } fields($table)
- });
+} else {
- &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt )
- if $opt{'error_callback'};
+ #$m->comp('/elements/handle_uri_query');
+ if ( $cgi->param('redirect') ) {
+ my $session = $cgi->param('redirect');
+ my $pref = $curuser->option("redirect$session");
+ die "unknown redirect session $session\n" unless length($pref);
+ $cgi = new CGI($pref);
+ }
-} elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) {
+ &{$opt{'begin_callback'}}( $cgi, $fields, \%opt )
+ if $opt{'begin_callback'};
+
+ my %qsearch = (
+ 'table' => $table,
+ 'extra_sql' => ( $opt{'agent_virt'}
+ ? ' AND '. $curuser->agentnums_sql(
+ 'null_right' => $opt{'agent_null_right'}
+ )
+ : ''
+ ),
+ );
- $mode = 'clone';
+ if ( $cgi->param('error') ) {
- $clone = $1;
+ $mode = 'error';
- $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'}
- if $opt{'agent_clone_extra_sql'};
+ $object = $class->new( {
+ map { $_ => scalar($cgi->param($_)) } fields($table)
+ });
- $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } })
- or die "$pkey $clone not found in $table";
+ &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt )
+ if $opt{'error_callback'};
- &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt )
- if $opt{'clone_callback'};
+ } elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) {
- #$object->$pkey('');
+ $mode = 'clone';
- $opt{action} ||= 'Add';
+ $clone = $1;
-} elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
+ $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'}
+ if $opt{'agent_clone_extra_sql'};
- $mode = 'edit';
+ $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } })
+ or die "$pkey $clone not found in $table";
- my $value;
- if ( $cgi->param($pkey) ) {
- $value = $cgi->param($pkey)
- } else {
- my( $query ) = $cgi->keywords;
- $value = $query;
- }
- $value =~ /^(\d+)$/ or die "unparsable $pkey";
- $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } })
- or die "$pkey $1 not found in $table";
-
- warn "$table $pkey => $1"
- if $opt{'debug'};
+ &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt )
+ if $opt{'clone_callback'};
- &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt )
- if $opt{'edit_callback'};
+ #$object->$pkey('');
-} else { #adding
+ $opt{action} ||= 'Add';
- $mode = 'new';
+ } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
- my $hashref = $opt{'new_hashref_callback'}
- ? &{$opt{'new_hashref_callback'}}
- : {};
+ $mode = 'edit';
- $object = $opt{'new_object_callback'}
- ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt )
- : $class->new( $hashref );
+ my $value;
+ if ( $cgi->param($pkey) ) {
+ $value = $cgi->param($pkey)
+ } else {
+ my( $query ) = $cgi->keywords;
+ $value = $query;
+ }
+ $value =~ /^(\d+)$/ or die "unparsable $pkey";
+ $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } })
+ or die "$pkey $1 not found in $table";
- &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt )
- if $opt{'new_callback'};
+ warn "$table $pkey => $1"
+ if $opt{'debug'};
-}
+ &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt )
+ if $opt{'edit_callback'};
-&{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt )
- if $opt{'end_callback'};
+ } else { #adding
-$opt{action} ||= $object->$pkey() ? 'Edit' : 'Add';
+ $mode = 'new';
-my $title = $opt{action}. ' '. ( $opt{name} || $opt{'name_singular'} );
+ my $hashref = $opt{'new_hashref_callback'}
+ ? &{$opt{'new_hashref_callback'}}
+ : {};
-my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html";
-$viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'};
+ $object = $opt{'new_object_callback'}
+ ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt )
+ : $class->new( $hashref );
+
+ &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt )
+ if $opt{'new_callback'};
+
+ }
+
+ &{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt )
+ if $opt{'end_callback'};
+
+ $opt{action} ||= $object->$pkey() ? 'Edit' : 'Add';
-my @menubar = ();
-if ( $opt{'menubar'} ) {
- @menubar = @{ $opt{'menubar'} };
-} else {
- my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'});
- @menubar = (
- "View all $items" => $viewall_url,
- );
}
</%init>
}
+unless ( $error ) { #XXX i guess i should be transactional... all in the insert
+ # or replace call
+ my @contact_fields = qw( classnum first last title comment emailaddress );
+ foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
+ push @contact_fields, 'phonetypenum'.$phone_type->phonetypenum;
+ }
+
+ $error = $new->process_o2m( 'table' => 'contact',
+ 'fields' => \@contact_fields,
+ 'params' => scalar($cgi->Vars),
+ );
+}
+
</%init>