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,
59 { 'field' => 'locationnum',
60 'type' => 'select-cust_location',
61 'empty_label' => 'No address',
62 'disable_empty' => $conf->exists('prospect_main-location_required'),
63 'alt_format' => $conf->exists('prospect_main-alt_address_format'),
64 'include_opt_callback' => sub {
65 'prospect_main' => shift
69 'new_callback' => $new_callback,
70 'edit_callback' => $edit_callback,
71 'error_callback' => $error_callback,
73 'html_bottom' => $javascript,
74 'body_etc' => 'onLoad="rescom_changed()"',
79 my $curuser = $FS::CurrentUser::CurrentUser;
80 my $conf = new FS::Conf;
83 if ( $cgi->param('error') ) {
84 $prospectnum = scalar($cgi->param('prospectnum'));
87 unless $curuser->access_right(($prospectnum ? 'Edit' : 'New'). ' prospect');
89 } elsif ( $cgi->keywords ) { #editing
92 unless $curuser->access_right('Edit prospect');
94 } else { #new prospect
97 unless $curuser->access_right('New prospect');
101 my $new_callback = sub {
102 my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
104 if ( $cgi->param('session') =~ /^(\w+)$/ ) {
107 #add a link to the image.cgi for this card
108 $opt_hashref->{'html_bottom'} .=
109 qq(<BR><IMG SRC="${p}view/image.cgi?type=png;prefname=bizcard$session" ).
110 ' WIDTH=604 HEIGHT=328><BR>';
112 #fill in the incoming params: name, address1/address2, city_state_zip
113 foreach my $param ( grep /^sel\d+$/, $cgi->param ) {
114 $param =~ /^sel(\d+)$/ or die 'again, wtf (daily)';
116 my $field = $cgi->param($param);
117 my $value = $cgi->param("val$num");
118 $cgi->param($field => $value);
121 if ( $cgi->param('company') ) {
122 $prospect_main->company( $cgi->param('company') );
125 if ( $cgi->param('name') =~ /^(.*\S+)\s+(\w+)\s*$/ ) {
126 $cgi->param('contactnum0_first' => $1);
127 $cgi->param('contactnum0_last' => $2);
130 if ( grep $cgi->param($_), qw( address1 address2 city_state_zip ) ) {
131 $cgi->param('locationnum', -1);
132 if ( $cgi->param('city_state_zip') =~ /^(\s*)([\w\s]+)[\., ]+(\w{2})[, ]+(\d{5}(-\d{4})?)/ ) {
133 $cgi->param('city' => $2);
134 $cgi->param('state' => $3);
135 $cgi->param('zip' => $4);
141 #config to default to commercial and/or disable residential when someone needs
142 $prospect_main->set('residential_commercial', 'Residential');
146 my $edit_callback = sub {
147 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
148 my( $cgi, $prospect_main ) = @_;
150 qsearch('cust_location', { 'prospectnum' => $prospect_main->prospectnum } );
151 die 'multiple locations for prospect '. $prospect_main->prospectnum
152 if scalar(@cust_location) > 1;
153 $prospect_main->set('locationnum', $cust_location[0]->locationnum)
154 if scalar(@cust_location);
155 #warn 'prospect_main.locationnum '.$prospect_main->get('locationnum');
157 $prospect_main->set('residential_commercial',
158 length($prospect_main->company)
164 my $error_callback = sub {
165 #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
166 my( $cgi, $prospect_main ) = @_;
167 $cgi->param('locationnum') =~ /^(\-?\d*)$/
168 or die 'illegal locationnum '. $cgi->param('locationnum');
169 my $locationnum = $1;
170 $prospect_main->set('locationnum', $locationnum);
172 $prospect_main->set('residential_commercial',
173 ($cgi->param('residential_commercial') eq 'Commercial')
180 my $m2_error_callback = sub {
181 my($cgi, $object) = @_;
183 #process_o2m fields in process/prospect_main.html
184 my @fields = qw( first last title comment );
185 my @gfields = ( '', map "_$_", @fields );
188 if ( /^contactnum(\d+)$/ ) {
190 if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
191 my $x = new FS::contact {
192 'contactnum' => scalar($cgi->param("contactnum$num")),
193 map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
206 #my @agentnums = $FS::CurrentUser::CurrentUser->agentnums;
208 my $javascript = <<END;
209 <SCRIPT TYPE="text/javascript">
210 function rescom_changed() {
211 var f = document.edit_topform;
213 if ( f.residential_commercial_Residential.checked ) {
215 c.style.backgroundColor = '#dddddd';
216 } else if ( f.residential_commercial_Commercial.checked ) {
218 c.style.backgroundColor = '#ffffff';