diff options
author | Ivan Kohler <ivan@freeside.biz> | 2012-03-26 19:20:29 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2012-03-26 23:33:19 -0700 |
commit | 9b4209f91ad9e3c4cef7deebfb0180f6faf1d0dc (patch) | |
tree | 669ab13c6febb3b815613cd0d2227446f3c1b46a | |
parent | 5561349c87fdcc646c18010ea57925f90170f321 (diff) |
more contact-aware new customer screen, RT#16819
-rwxr-xr-x | httemplate/edit/cust_main.cgi | 17 | ||||
-rw-r--r-- | httemplate/edit/cust_main/billing.html | 4 | ||||
-rw-r--r-- | httemplate/edit/cust_main/contact.html | 211 | ||||
-rw-r--r-- | httemplate/edit/cust_main/contacts_new.html | 61 | ||||
-rw-r--r-- | httemplate/edit/cust_main/first_pkg.html | 4 | ||||
-rw-r--r-- | httemplate/edit/cust_main/top_misc.html | 64 | ||||
-rw-r--r-- | httemplate/edit/elements/edit.html | 275 | ||||
-rwxr-xr-x | httemplate/edit/process/cust_main.cgi | 13 |
8 files changed, 402 insertions, 247 deletions
diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index d2c0cb785..399431311 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -50,7 +50,7 @@ % } <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, @@ -127,9 +127,9 @@ function samechanged(what) { </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_', @@ -138,17 +138,23 @@ function samechanged(what) { '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" @@ -204,6 +210,7 @@ function samechanged(what) { VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>" onClick = "this.disabled=true; bottomfixup(this.form);" > +<BR><BR> </FORM> <& /elements/footer.html &> diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html index bf6c62339..18c7ae9a6 100644 --- a/httemplate/edit/cust_main/billing.html +++ b/httemplate/edit/cust_main/billing.html @@ -34,7 +34,7 @@ % % 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> @@ -580,7 +580,7 @@ function toggle(obj) { </TABLE> - <% $r %> <% mt('required fields') |h %> + <% $r %><% mt('required fields') |h %> % } <script type="text/javascript"> diff --git a/httemplate/edit/cust_main/contact.html b/httemplate/edit/cust_main/contact.html index 4912327c6..57490b962 100644 --- a/httemplate/edit/cust_main/contact.html +++ b/httemplate/edit/cust_main/contact.html @@ -1,4 +1,4 @@ -<% &ntable("#cccccc") %> +<TABLE CLASS="fsinnerbox"> <TR> <TH ALIGN="right"><%$r%><% mt('Contact name (last, first)') |h %></TH> @@ -14,8 +14,6 @@ <TD><INPUT TYPE="hidden" NAME="ss" VALUE="<% $opt{ss} %>"></TD> % } - - </TR> % if ( $conf->exists('cust-email-high-visibility') && !$pre ) { @@ -30,100 +28,19 @@ </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 &> % } @@ -152,16 +69,88 @@ </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; @@ -189,15 +178,15 @@ if ( $conf->exists('cust_main-require_censustract') ) { $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' @@ -206,8 +195,6 @@ my $stateid_state_label = FS::Msgcat::_gettext('stateid_state') =~ /^(stateid_st ? '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; diff --git a/httemplate/edit/cust_main/contacts_new.html b/httemplate/edit/cust_main/contacts_new.html new file mode 100644 index 000000000..f59126a66 --- /dev/null +++ b/httemplate/edit/cust_main/contacts_new.html @@ -0,0 +1,61 @@ +<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> diff --git a/httemplate/edit/cust_main/first_pkg.html b/httemplate/edit/cust_main/first_pkg.html index 2e9f36f99..ad118b4a9 100644 --- a/httemplate/edit/cust_main/first_pkg.html +++ b/httemplate/edit/cust_main/first_pkg.html @@ -6,8 +6,8 @@ % % 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> diff --git a/httemplate/edit/cust_main/top_misc.html b/httemplate/edit/cust_main/top_misc.html index 2d1d978e3..7ba167b7f 100644 --- a/httemplate/edit/cust_main/top_misc.html +++ b/httemplate/edit/cust_main/top_misc.html @@ -1,4 +1,49 @@ -<% &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)) %> @@ -144,6 +189,23 @@ my( $cust_main, %opt ) = @_; 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; diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 4e896f239..73faad4c0 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -111,6 +111,11 @@ Example: #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 ### @@ -186,41 +191,60 @@ Example: </%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> @@ -723,24 +747,28 @@ Example: : $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) = @_; @@ -756,116 +784,113 @@ my $fields = $opt{'fields'} || [ 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> diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi index 994f9b7ca..44fbb4f10 100755 --- a/httemplate/edit/process/cust_main.cgi +++ b/httemplate/edit/process/cust_main.cgi @@ -302,4 +302,17 @@ if ( $new->custnum eq '' or $duplicate_of ) { } +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> |