2 % $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(3). 'misc/qual.html?'. $cgi->query_string ) %>
5 <% header('Qualification entered') %>
6 <SCRIPT TYPE="text/javascript">
7 window.top.location = '<% popurl(3).'view/qual.cgi?qualnum='. $qual->qualnum %>';
13 my $curuser = $FS::CurrentUser::CurrentUser;
16 unless $curuser->access_right('Qualify service');
18 # copied from misc/qual.html :(
19 $cgi->param('custnum') =~ /^(\d+)$/;
21 $cgi->param('prospectnum') =~ /^(\d+)$/;
23 my $cust_or_prospect = $custnum ? "cust" : "prospect";
24 my $table = $cust_or_prospect . "_main";
25 my $custnum_or_prospectnum = $custnum ? $custnum : $prospectnum;
26 my $cust_main_or_prospect_main = qsearchs({
28 'hashref' => { $cust_or_prospect."num" => $custnum_or_prospectnum },
29 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
31 die "neither prospect nor customer specified or found"
32 unless $cust_main_or_prospect_main;
34 $cgi->param('exportnum') =~ /^(\d+)$/ or die 'illegal exportnum';
37 my $phonenum = $cgi->param('phonenum');
39 $phonenum =~ /^(\d*)$/ or die 'illegal phonenum';
42 $cgi->param('locationnum') =~ /^(\-?\d*)$/
43 or die 'illegal locationnum '. $cgi->param('locationnum');
47 my $cust_location = '';
49 map { $_ => scalar($cgi->param($_)) }
50 qw( address1 address2 city county state zip country geocode ),
51 grep scalar($cgi->param($_)),
52 qw( location_type location_number location_kind )
55 if ( $locationnum == -1 || $locationnum == -3 ) { # adding a new one
57 $cust_location = new FS::cust_location {
58 $cust_or_prospect."num" => $custnum_or_prospectnum,
62 #locationnum '': default service location
63 } elsif ( $locationnum eq '' && $cust_or_prospect eq 'prospect' ) {
64 die "a location must be specified explicitly for prospects";
66 #locationnum -2: address not required for qual
67 } elsif ( $locationnum == -2 && $phonenum eq '' ) {
68 $error = "Nothing to qualify - neither phone number nor address specified";
70 } else { #existing location, possibly with an edit
71 $cust_location = qsearchs('cust_location', { 'locationnum'=>$locationnum })
72 or die "Unknown locationnum $locationnum";
73 $cust_location->$_($location_hash{$_}) foreach keys %location_hash;
76 my $qual = new FS::qual {
79 $qual->phonenum($phonenum) if $phonenum ne '';
80 #$qual->locationnum($locationnum) if $locationnum > 0;
81 $qual->exportnum($exportnum) if $exportnum > 0;
82 $qual->set( $cust_or_prospect."num" => $custnum_or_prospectnum )
83 unless $locationnum == -1 || $locationnum == -3 || $locationnum > 0;
85 $error ||= $qual->insert( 'cust_location' => $cust_location );