2 function checkPasswordValidation(fieldid) {
3 var validationResult = document.getElementById(fieldid+'_result').innerHTML;
4 if (validationResult.match(/Password valid!/)) {
13 <& '/elements/validate_password_js.html', &>
15 <% include('elements/edit.html',
16 'name_singular' => 'prospect',
17 'table' => 'prospect_main',
18 'labels' => { 'prospectnum' => 'Prospect',
19 'disabled' => 'Disabled',
20 'agentnum' => 'Agent',
21 'refnum' => 'Advertising source',
22 'company' => 'Company',
23 'contactnum' => 'Contact',
24 'locationnum' => ' ',
27 { 'field' => 'agentnum',
28 'type' => 'select-agent',
29 'empty_label' => 'Select agent',
33 { 'field' => 'refnum',
34 'type' => 'select-part_referral',
35 'empty_label' => 'Select advertising source',
39 { 'field' => 'residential_commercial',
41 'options' => [ 'Residential', 'Commercial', ],
42 'onchange' => 'rescom_changed',
44 { 'field' => 'disabled',
48 { 'field' => 'contactnum',
51 'o2m_table' => 'contact',
52 'm2_label' => 'Contact',
53 'm2_error_callback' => $m2_error_callback,
54 'include_opt_callback' => sub { 'for_prospect' => '1' },
57 { 'field' => 'company',
62 { 'field' => 'locationnum',
63 'type' => 'select-cust_location',
64 'empty_label' => 'No address',
65 'disable_empty' => $conf->exists('prospect_main-location_required'),
66 'alt_format' => $conf->exists('prospect_main-alt_address_format'),
67 'include_opt_callback' => sub {
68 'prospect_main' => shift
72 'new_callback' => $new_callback,
73 'edit_callback' => $edit_callback,
74 'error_callback' => $error_callback,
76 'html_bottom' => $javascript,
77 'body_etc' => 'onLoad="rescom_changed()"',
82 my $curuser = $FS::CurrentUser::CurrentUser;
83 my $conf = new FS::Conf;
84 my @agentnums = $curuser->agentnums;
87 if ( $cgi->param('error') ) {
88 $prospectnum = scalar($cgi->param('prospectnum'));
91 unless $curuser->access_right(($prospectnum ? 'Edit' : 'New'). ' prospect');
93 } elsif ( $cgi->keywords ) { #editing
96 unless $curuser->access_right('Edit prospect');
98 } else { #new prospect
101 unless $curuser->access_right('New prospect');
105 my $new_callback = sub {
106 my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
108 if ( $cgi->param('session') =~ /^(\w+)$/ ) {
111 #add a link to the image.cgi for this card
112 $opt_hashref->{'html_bottom'} .=
113 qq(<BR><IMG SRC="${p}view/image.cgi?type=png;prefname=bizcard$session" ).
114 ' WIDTH=604 HEIGHT=328><BR>';
116 #fill in the incoming params: name, address1/address2, city_state_zip
117 foreach my $param ( grep /^sel\d+$/, $cgi->param ) {
118 $param =~ /^sel(\d+)$/ or die 'again, wtf (daily)';
120 my $field = $cgi->param($param);
121 my $value = $cgi->param("val$num");
122 $cgi->param($field => $value);
125 if ( $cgi->param('company') ) {
126 $prospect_main->company( $cgi->param('company') );
129 if ( $cgi->param('name') =~ /^(.*\S+)\s+(\w+)\s*$/ ) {
130 $cgi->param('contactnum0_first' => $1);
131 $cgi->param('contactnum0_last' => $2);
134 if ( grep $cgi->param($_), qw( address1 address2 city_state_zip ) ) {
135 $cgi->param('locationnum', -1);
136 if ( $cgi->param('city_state_zip') =~ /^(\s*)([\w\s]+)[\., ]+(\w{2})[, ]+(\d{5}(-\d{4})?)/ ) {
137 $cgi->param('city' => $2);
138 $cgi->param('state' => $3);
139 $cgi->param('zip' => $4);
145 #config to default to commercial and/or disable residential when someone needs
146 $prospect_main->set('residential_commercial', 'Residential');
148 # config to set default agent
149 $prospect_main->agentnum( $agentnums[0] )
150 if scalar(@agentnums) == 1;
151 $prospect_main->agentnum( $conf->config('default_agentnum') )
152 if $conf->exists('default_agentnum');
154 # config to set default refnum
155 $prospect_main->refnum( $conf->config('referraldefault') )
156 if $conf->exists('referraldefault');
159 my $edit_callback = sub {
160 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
161 my( $cgi, $prospect_main ) = @_;
163 qsearch('cust_location', { 'prospectnum' => $prospect_main->prospectnum } );
164 die 'multiple locations for prospect '. $prospect_main->prospectnum
165 if scalar(@cust_location) > 1;
166 $prospect_main->set('locationnum', $cust_location[0]->locationnum)
167 if scalar(@cust_location);
168 #warn 'prospect_main.locationnum '.$prospect_main->get('locationnum');
170 $prospect_main->set('residential_commercial',
171 length($prospect_main->company)
177 my $error_callback = sub {
178 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
179 my( $cgi, $prospect_main ) = @_;
180 $cgi->param('locationnum') =~ /^(\-?\d*)$/
181 or die 'illegal locationnum '. $cgi->param('locationnum');
182 my $locationnum = $1;
183 $prospect_main->set('locationnum', $locationnum);
185 $prospect_main->set('residential_commercial',
186 ($cgi->param('residential_commercial') eq 'Commercial')
193 my $m2_error_callback = sub {
194 my($cgi, $object) = @_;
196 #process_o2m fields in process/prospect_main.html
197 my @fields = qw( first last title comment );
198 my @gfields = ( '', map "_$_", @fields );
201 if ( /^contactnum(\d+)$/ ) {
203 if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
204 my $x = new FS::contact {
205 'contactnum' => scalar($cgi->param("contactnum$num")),
206 map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
219 my $javascript = <<END;
220 <SCRIPT TYPE="text/javascript">
221 function rescom_changed() {
222 var f = document.edit_topform;
224 if ( f.residential_commercial_Residential.checked ) {
226 c.style.backgroundColor = '#dddddd';
227 } else if ( f.residential_commercial_Commercial.checked ) {
229 c.style.backgroundColor = '#ffffff';