From 55e57dc0b0041d58c671cfdcb9fb183f0b868969 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 21 Jun 2007 14:50:46 +0200 Subject: [PATCH] Added Google Maps support darcs-hash:20070621125046-6e07b-29b03beafdebdfc7952e60e31761a6f91b372164.gz --- entry.php | 2 + img.php | 4 +- inc/config.php | 12 ++++- inc/functions.php | 1 - inc/init.php | 4 ++ inc/lang/en.php | 1 + index.php | 20 ++++++--- scripts/gui.js | 13 +++--- scripts/maps.js | 44 +++++++++++++++++++ styles/design.css | 5 +++ styles/layout.css | 8 ++++ templates/entry_map.tpl | 32 ++++++++++++++ templates/entry_show.tpl | 5 ++- templates/header.tpl | 5 +++ .../{export_list_csv.tpl => list_csv.tpl} | 0 templates/list_map.tpl | 15 +++++++ templates/list_map_entry.tpl | 7 +++ templates/toolbar.tpl | 17 +++++++ 18 files changed, 176 insertions(+), 19 deletions(-) create mode 100644 scripts/maps.js create mode 100644 templates/entry_map.tpl rename templates/{export_list_csv.tpl => list_csv.tpl} (100%) create mode 100644 templates/list_map.tpl create mode 100644 templates/list_map_entry.tpl diff --git a/entry.php b/entry.php index e224522..75c6b87 100644 --- a/entry.php +++ b/entry.php @@ -11,6 +11,8 @@ if( $_SESSION['ldapab']['username'] && $template='entry_edit.tpl'; }elseif($_REQUEST['mode']=='vcf'){ $template='entry_vcf.tpl'; +}elseif($_REQUEST['mode']=='map'){ + $template='entry_map.tpl'; }else{ $template='entry_show.tpl'; } diff --git a/img.php b/img.php index 27a49b6..3cdd23d 100644 --- a/img.php +++ b/img.php @@ -4,7 +4,7 @@ ldap_login(); $dn = $_REQUEST['dn']; -$sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)',array('jpegPhoto')); +$sr = ldap_search($LDAP_CON,$dn,'(objectClass=inetOrgPerson)',array($FIELDS['photo'])); if(!ldap_count_entries($LDAP_CON,$sr)){ exit; } @@ -12,5 +12,5 @@ $result = ldap_get_binentries($LDAP_CON, $sr); $entry = $result[0]; header("Content-type: image/jpeg"); -print $entry['jpegPhoto'][0]; +print $entry[$FIELDS['photo']][0]; ?> diff --git a/inc/config.php b/inc/config.php index d46910e..5f8aaf4 100644 --- a/inc/config.php +++ b/inc/config.php @@ -50,8 +50,16 @@ // Dateformat for birthdays when using extended schema // see http://www.php.net/manual/en/function.strftime.php - #$conf['dateformat'] = '%Y/%m/%d'; - $conf['dateformat'] = '%d.%m.%Y'; + $conf['dateformat'] = '%Y/%m/%d'; + #$conf['dateformat'] = '%d.%m.%Y'; + + // Google maps key, you can specify multiple when running the app through different vhosts + $conf['gmaps'] = array( + 'localhost' => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSoniRWQPYZHIWuWPbij8hFqvrEuw', + 'intranet.cosmo' => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RTxyuybgLnXtMVD7dljhze3zUboVhTqk9yc-rQVvv2YwFFJN20RCNbIVA', + 'intranet' => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RTjlGRJ-JcA4ENdYSxSTUELqnaldxSOyZdbUNylw_BZHH1bBLrQNGtjZg', + 'fileserver.cosmo' => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RQ2oMD1p7-NjsUZiDyjvzpK3IuhixTXdHGQRp8jtjwAl-P4oPPEB_hGgw', + ); // Force recompilation of smarty templates? $conf['smartycompile'] = 1; diff --git a/inc/functions.php b/inc/functions.php index fa341b5..52f1016 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -482,5 +482,4 @@ function utf8_encode_array(&$array) { } } - ?> diff --git a/inc/init.php b/inc/init.php index ad5c900..72bea22 100644 --- a/inc/init.php +++ b/inc/init.php @@ -39,4 +39,8 @@ $smarty->use_sub_dirs = 0; $smarty->template_dir = dirname(__FILE__).'/../templates'; $smarty->force_compile = $conf['smartycompile']; + + // select the correct google api key + $conf['gmapkey'] = $conf['gmaps'][$_SERVER['HTTP_HOST']]; + ?> diff --git a/inc/lang/en.php b/inc/lang/en.php index 1f2b97d..561c637 100644 --- a/inc/lang/en.php +++ b/inc/lang/en.php @@ -49,6 +49,7 @@ $lang['show'] = 'Show'; $lang['new'] = 'New'; $lang['delete'] = 'Delete'; $lang['copy'] = 'Copy'; +$lang['map'] = 'Map'; $lang['csvexport'] = 'CSV'; $lang['vcfexport'] = 'VCard'; $lang['vcfimport'] = 'Import'; diff --git a/index.php b/index.php index 5bd4fca..58e4a6f 100644 --- a/index.php +++ b/index.php @@ -23,7 +23,9 @@ // select entry template if(!empty($_REQUEST['export']) && $_REQUEST['export'] == 'csv'){ - $entrytpl = 'export_list_csv_entry.tpl'; + $entrytpl = 'list_csv_entry.tpl'; + }elseif(!empty($_REQUEST['export']) && $_REQUEST['export'] == 'map'){ + $entrytpl = 'list_map_entry.tpl'; }else{ $entrytpl = 'list_entry.tpl'; } @@ -52,15 +54,21 @@ $smarty->assign('marker',$_REQUEST['marker']); $smarty->assign('search',$_REQUEST['search']); //display templates - if(!empty($_REQUEST['export']) && $_REQUEST['export'] == 'csv'){ - if ($conf['userlogreq'] == 1 && $user == '') - { + if(!empty($_REQUEST['export'])){ + if ($conf['userlogreq'] == 1 && $user == ''){ header("HTTP/1.1 401 ACCESS DENIED"); exit(); - } else { + } + + if($_REQUEST['export'] == 'csv'){ header("Content-Type: text/csv"); header('Content-Disposition: Attachement; filename="contagged_export.csv"'); - $smarty->display('export_list_csv.tpl'); + $smarty->display('list_csv.tpl'); + exit; + }elseif($_REQUEST['export'] == 'map'){ + header('Content-Type: text/html; charset=utf-8'); + $smarty->display('list_map.tpl'); + exit; } }else{ //save location in session diff --git a/scripts/gui.js b/scripts/gui.js index e4a9a26..3148b9e 100644 --- a/scripts/gui.js +++ b/scripts/gui.js @@ -101,8 +101,6 @@ function noteedit(type){ $('#noteedit_editor').focus(); } - - /** * Initialize everything when DOM is ready */ @@ -146,7 +144,7 @@ $(document).ready(function() { }); // tag editing - if($('#tagedit')){ + if($('#tagedit').length){ var img = new Image(); img.src = 'pix/tag_blue_edit.png'; img.className = 'click'; @@ -156,7 +154,7 @@ $(document).ready(function() { } // note editing - if($('#noteedit')){ + if($('#noteedit').length){ var img; img = new Image(); @@ -186,7 +184,10 @@ $(document).ready(function() { // set focus - if($('#searchfield')) $('#searchfield').focus(); - if($('#firstfield')) $('#firstfield').focus(); + if($('#searchfield').length) $('#searchfield').focus(); + if($('#firstfield').length) $('#firstfield').focus(); + + // run google maps loader + if($('#google_map').length) gmap_loader(); }); diff --git a/scripts/maps.js b/scripts/maps.js new file mode 100644 index 0000000..6ff50ee --- /dev/null +++ b/scripts/maps.js @@ -0,0 +1,44 @@ + +var gmap_data = Array(); +var gmap_centered = false; + +function gmap_loader(){ + if (!GBrowserIsCompatible()) return; + + var map = new GMap2(document.getElementById("google_map")); + var geocoder = new GClientGeocoder(); + map.addControl(new GLargeMapControl()); + map.addControl(new GMapTypeControl()); + map.setCenter(new GLatLng(52.514863,13.381863),10); + + for (var i=0; i10) t = 1000; + if(i>20) t = 2000; + gmap_add(map,geocoder,gmap_data[i].adr,gmap_data[i].info,t) + } +} + +function gmap_add(map,gc,adr,info,t){ + setTimeout(function(){ + gc.getLatLng( + adr, + function(point) { + if (!point) { + //alert(address + " not found"); + } else { + if(!gmap_centered){ + map.setCenter(point, 5); + gmap_centered = true; + } + var marker = new GMarker(point); + map.addOverlay(marker); + GEvent.addListener(marker, "click", function(){ + this.openInfoWindowHtml( info ); + }); + } + } + ); + },t); +} + diff --git a/styles/design.css b/styles/design.css index 5a4d9f2..0f810e6 100644 --- a/styles/design.css +++ b/styles/design.css @@ -110,6 +110,11 @@ a.ed_vcfimport { padding: 1px 0px 1px 16px; } +a.ed_map { + background: transparent url(../pix/map.png) 0px 1px no-repeat; + padding: 1px 0px 1px 18px; +} + a.ed_login { background: transparent url(../pix/key.png) 0px 1px no-repeat; padding: 1px 0px 1px 18px; diff --git a/styles/layout.css b/styles/layout.css index da79d8f..d923bee 100644 --- a/styles/layout.css +++ b/styles/layout.css @@ -169,6 +169,14 @@ div#edit span.hint { font-size: 75%; } +/* mapping */ +div#map div#google_map { + width: 95%; + margin: 2em auto; + height: 40em; +} + + /* tagcloud */ div#tagcloud { margin: 2em; diff --git a/templates/entry_map.tpl b/templates/entry_map.tpl new file mode 100644 index 0000000..04e6038 --- /dev/null +++ b/templates/entry_map.tpl @@ -0,0 +1,32 @@ +{include file="header.tpl"} + + + +
+ +

+ + {$entry.givenname|h} {$entry.name|h} +

+ + +
+ + + +
+ +{include file="footer.tpl"} diff --git a/templates/entry_show.tpl b/templates/entry_show.tpl index e94d2db..a626377 100644 --- a/templates/entry_show.tpl +++ b/templates/entry_show.tpl @@ -21,6 +21,7 @@ {if $entry.phone} diff --git a/templates/header.tpl b/templates/header.tpl index 0fc3492..4939c97 100644 --- a/templates/header.tpl +++ b/templates/header.tpl @@ -20,6 +20,11 @@ + {if $conf.gmapkey} + + + {/if} + + +
+ +
+
+ +{include file="footer.tpl"} diff --git a/templates/list_map_entry.tpl b/templates/list_map_entry.tpl new file mode 100644 index 0000000..5557416 --- /dev/null +++ b/templates/list_map_entry.tpl @@ -0,0 +1,7 @@ + +{ldelim} + adr: '{$entry.street|escape:javascript}, {$entry.zip|escape:javascript} {$entry.location|escape:javascript}', + info: '

{$entry.organization|escape:javascript}

{$entry.street|escape:javascript}
{$entry.zip|escape:javascript} {$entry.location|escape:javascript}' +{rdelim}, + + diff --git a/templates/toolbar.tpl b/templates/toolbar.tpl index a5683c3..cd1df67 100644 --- a/templates/toolbar.tpl +++ b/templates/toolbar.tpl @@ -16,6 +16,7 @@
  •  
  • {if $dn} + {if $user} @@ -43,11 +44,27 @@ {$lang.vcfexport} + + {if $smarty.request.mode == 'map' && $conf.gmapkey} +
  • + {$lang.show} +
  • + {elseif $conf.gmapkey} +
  • + {$lang.map} +
  • + {/if} +
  •  
  • {/if} {if $list} + {if $smarty.request.export != 'map' && $conf.gmapkey} +
  • + {$lang.map} +
  • + {/if}
  • {$lang.csvexport} -- 2.39.5
  • + {$entry.title|h} {$entry.givenname|h} {$entry.name|h}
    {if $entry.organization} {$entry.organization|h}
    @@ -32,7 +33,7 @@ {$entry.street|h}
    {/if} {if $entry.location} - {$entry.zip} {$entry.location|h}
    + {$entry.zip|h} {$entry.location|h}
    {/if} {if $entry.state} {$entry.state|h} @@ -40,7 +41,7 @@ {if $entry.country} {$entry.country|h} {/if} -

    +