71873: GlobalVision - directions
[freeside.git] / httemplate / elements / coord-links.html
index 02a224a..a755791 100644 (file)
@@ -1,5 +1,7 @@
 <& /elements/init_overlib.html &>
 
+% if ( $apikey ) {
+
 <& /elements/popup_link.html,
      'action'      => $p. 'view/map.html?'. $query,
      'label'       => mt('map'),
   &>
 % }
 
+% } # end if $apikey
+
 <A HREF="<%$p%>view/kml.cgi?<% $query %>"><% mt('earth') |h %></A>
 
 <%init>
 
-my ($latitude, $longitude, $name, $agentnum) = @_;
+my %opt = ();
+my ($latitude, $longitude, $name, $agentnum);
+if ( ref($_[0]) ) {
+  %opt = %{ $_[0] };
+  $latitude  = $opt{latitude};
+  $longitude = $opt{longitude};
+  $name      = $opt{name};
+  $agentnum  = $opt{agentnum};
+} else {
+  ($latitude, $longitude, $name, $agentnum) = @_;
+}
 
 my $query = 'name='. uri_escape_utf8($name).
             ';lat='. $latitude.
             ';lon='. $longitude;
 
 my $js_name = $name;
-$js_name =~ s/[<>"]/ /g;
+$js_name =~ s/[<>"']/ /g;
 $m->interp->apply_escapes($js_name, 'js_string');
 $js_name =~ s/^'//;
 $js_name =~ s/'$//;
 
-my $origin;
+my $conf = new FS::Conf;
+my $apikey = $conf->config('google_maps_api_key');
+
 #for directions link
-if ( $agentnum =~ /^\d+$/ ) {
-  $origin = FS::Conf->new->config('company_address', $agentnum);
-  $origin = uri_escape($origin);
-}
+my @origin = $opt{company_address}
+               ? @{ $opt{company_address} }
+               : $conf->config('company_address', $agentnum);
+my $origin = uri_escape(join(',', @origin));
+
 </%init>