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',
32 { 'field' => 'refnum',
33 'type' => 'select-part_referral',
34 'empty_label' => 'Select advertising source',
37 { 'field' => 'residential_commercial',
39 'options' => [ 'Residential', 'Commercial', ],
40 'onchange' => 'rescom_changed',
42 { 'field' => 'disabled',
46 { 'field' => 'company',
51 { 'field' => 'contactnum',
54 'o2m_table' => 'contact',
55 'm2_label' => 'Contact',
56 'm2_error_callback' => $m2_error_callback,
57 'include_opt_callback' => sub { 'for_prospect' => '1' },
60 { 'field' => 'locationnum',
61 'type' => 'select-cust_location',
62 'empty_label' => 'No address',
63 'disable_empty' => $conf->exists('prospect_main-location_required'),
64 'alt_format' => $conf->exists('prospect_main-alt_address_format'),
65 'include_opt_callback' => sub {
66 'prospect_main' => shift
70 'new_callback' => $new_callback,
71 'edit_callback' => $edit_callback,
72 'error_callback' => $error_callback,
74 'html_bottom' => $javascript,
75 'body_etc' => 'onLoad="rescom_changed()"',
80 my $curuser = $FS::CurrentUser::CurrentUser;
81 my $conf = new FS::Conf;
84 if ( $cgi->param('error') ) {
85 $prospectnum = scalar($cgi->param('prospectnum'));
88 unless $curuser->access_right(($prospectnum ? 'Edit' : 'New'). ' prospect');
90 } elsif ( $cgi->keywords ) { #editing
93 unless $curuser->access_right('Edit prospect');
95 } else { #new prospect
98 unless $curuser->access_right('New prospect');
102 my $new_callback = sub {
103 my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
105 if ( $cgi->param('session') =~ /^(\w+)$/ ) {
108 #add a link to the image.cgi for this card
109 $opt_hashref->{'html_bottom'} .=
110 qq(<BR><IMG SRC="${p}view/image.cgi?type=png;prefname=bizcard$session" ).
111 ' WIDTH=604 HEIGHT=328><BR>';
113 #fill in the incoming params: name, address1/address2, city_state_zip
114 foreach my $param ( grep /^sel\d+$/, $cgi->param ) {
115 $param =~ /^sel(\d+)$/ or die 'again, wtf (daily)';
117 my $field = $cgi->param($param);
118 my $value = $cgi->param("val$num");
119 $cgi->param($field => $value);
122 if ( $cgi->param('company') ) {
123 $prospect_main->company( $cgi->param('company') );
126 if ( $cgi->param('name') =~ /^(.*\S+)\s+(\w+)\s*$/ ) {
127 $cgi->param('contactnum0_first' => $1);
128 $cgi->param('contactnum0_last' => $2);
131 if ( grep $cgi->param($_), qw( address1 address2 city_state_zip ) ) {
132 $cgi->param('locationnum', -1);
133 if ( $cgi->param('city_state_zip') =~ /^(\s*)([\w\s]+)[\., ]+(\w{2})[, ]+(\d{5}(-\d{4})?)/ ) {
134 $cgi->param('city' => $2);
135 $cgi->param('state' => $3);
136 $cgi->param('zip' => $4);
142 #config to default to commercial and/or disable residential when someone needs
143 $prospect_main->set('residential_commercial', 'Residential');
147 my $edit_callback = sub {
148 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
149 my( $cgi, $prospect_main ) = @_;
151 qsearch('cust_location', { 'prospectnum' => $prospect_main->prospectnum } );
152 die 'multiple locations for prospect '. $prospect_main->prospectnum
153 if scalar(@cust_location) > 1;
154 $prospect_main->set('locationnum', $cust_location[0]->locationnum)
155 if scalar(@cust_location);
156 #warn 'prospect_main.locationnum '.$prospect_main->get('locationnum');
158 $prospect_main->set('residential_commercial',
159 length($prospect_main->company)
165 my $error_callback = sub {
166 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
167 my( $cgi, $prospect_main ) = @_;
168 $cgi->param('locationnum') =~ /^(\-?\d*)$/
169 or die 'illegal locationnum '. $cgi->param('locationnum');
170 my $locationnum = $1;
171 $prospect_main->set('locationnum', $locationnum);
173 $prospect_main->set('residential_commercial',
174 ($cgi->param('residential_commercial') eq 'Commercial')
181 my $m2_error_callback = sub {
182 my($cgi, $object) = @_;
184 #process_o2m fields in process/prospect_main.html
185 my @fields = qw( first last title comment );
186 my @gfields = ( '', map "_$_", @fields );
189 if ( /^contactnum(\d+)$/ ) {
191 if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
192 my $x = new FS::contact {
193 'contactnum' => scalar($cgi->param("contactnum$num")),
194 map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
207 #my @agentnums = $FS::CurrentUser::CurrentUser->agentnums;
209 my $javascript = <<END;
210 <SCRIPT TYPE="text/javascript">
211 function rescom_changed() {
212 var f = document.edit_topform;
214 if ( f.residential_commercial_Residential.checked ) {
216 c.style.backgroundColor = '#dddddd';
217 } else if ( f.residential_commercial_Commercial.checked ) {
219 c.style.backgroundColor = '#ffffff';