4 my $curuser = $FS::CurrentUser::CurrentUser;
5 my $acl_edit = $curuser->access_right('Edit FCC report configuration');
6 my $acl_edit_global = $curuser->access_right('Edit FCC report configuration for all agents');
8 unless $acl_edit or $acl_edit_global;
10 my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc;
13 Shapetype => Geo::Shapelib::POLYGON,
14 FieldNames => [ 'Tech', 'Down', 'Up' ],
15 FieldTypes => [ 'String:32', 'Double', 'Double' ],
18 my( $name, $shapefile );
20 my($query) = $cgi->keywords;
21 if ( $query =~ /^(\d+)$/ || $cgi->param('zonenum') =~ /^(\d+$)/ ) {
24 my $deploy_zone = qsearchs('deploy_zone', { 'zonenum' => $zonenum })
25 or die 'unknown zonenum';
27 $shapefile = new Geo::Shapelib {
28 Name => "$dir/$zonenum-$$",
32 $deploy_zone->shapefile_add($shapefile);
34 } elsif ( $cgi->param('zonetype') =~ /^(\w)$/ ) {
37 my @deploy_zone = qsearch('deploy_zone', { 'zonetype' => $zonetype,
40 $shapefile = new Geo::Shapelib {
41 Name => "$dir/$zonetype-$$",
45 $_->shapefile_add($shapefile) foreach @deploy_zone;
48 die "no zonenum or zonetype\n";
51 $shapefile->set_bounds;
55 #slurp up .shp .shx and .dbf files and put them in a zip.. return that
59 open(my $fh, '>', \$content);
61 my $zip = new Archive::Zip;
62 $zip->addFile("$dir/$name-$$.$_", "$name.$_") foreach qw( shp shx dbf );
63 unless ( $zip->writeToFileHandle($fh) == Archive::Zip::AZ_OK() ) {
64 die "failed to create .shz file\n";
68 unlink("$dir/$name-$$.$_") foreach qw( shp shx dbf );
70 #http_header('Content-Type' => 'x-gis/x-shapefile' );
71 http_header('Content-Type' => 'archive/zip' );
72 http_header('Content-Disposition' => "filename=$name.shz" );
73 http_header('Content-Length' => length($content) );
74 http_header('Cache-control' => 'max-age=60' );