]> git.sur5r.net Git - contagged/commitdiff
Added Google Maps support
authorAndreas Gohr <gohr@cosmocode.de>
Thu, 21 Jun 2007 12:50:46 +0000 (14:50 +0200)
committerAndreas Gohr <gohr@cosmocode.de>
Thu, 21 Jun 2007 12:50:46 +0000 (14:50 +0200)
darcs-hash:20070621125046-6e07b-29b03beafdebdfc7952e60e31761a6f91b372164.gz

19 files changed:
entry.php
img.php
inc/config.php
inc/functions.php
inc/init.php
inc/lang/en.php
index.php
scripts/gui.js
scripts/maps.js [new file with mode: 0644]
styles/design.css
styles/layout.css
templates/entry_map.tpl [new file with mode: 0644]
templates/entry_show.tpl
templates/export_list_csv.tpl [deleted file]
templates/header.tpl
templates/list_csv.tpl [new file with mode: 0644]
templates/list_map.tpl [new file with mode: 0644]
templates/list_map_entry.tpl [new file with mode: 0644]
templates/toolbar.tpl

index e22452267af40da0d26eaf22ced382c8dec81c77..75c6b87c17ea2026c59c26923a68cf7e7938a6c7 100644 (file)
--- 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 27a49b6c90ea1b0a624c5a304da3b4f79c1bb15c..3cdd23dc7d23ace64fb5adbaaf0f74442c5527d8 100644 (file)
--- 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];
 ?>
index d46910e4a6d9005604c1c0b1b9cd94b9d8b62737..5f8aaf4bf8546594bf7b9cb4549ddc08f9223fb3 100644 (file)
 
   // 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;
index fa341b59d8cb53b1f52194640dab9c6c9d7fc29e..52f101654d98554fbf3c55bc277ffd0f26e67dc8 100644 (file)
@@ -482,5 +482,4 @@ function utf8_encode_array(&$array) {
   }
 }
 
-
 ?>
index ad5c90014d7ecb18f1bd869d478c3a0a1d65b872..72bea22c6a5ccc5a7733c66d90e75abc3c674c91 100644 (file)
@@ -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']];
+
 ?>
index 1f2b97d3fad64660011c7ed7e293ca29c845e105..561c6374b89e0c28dc5f0147fb88960d4b0684e3 100644 (file)
@@ -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';
index 5bd4fca712ba37020553766e7bde7e8841b1b763..58e4a6f3968a2592893fe9bb6b918b4852515cfa 100644 (file)
--- 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';
   }
   $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
index e4a9a2688bbe5e0d895d0824519f50838cadb45b..3148b9e3ef76e463057bb055dedf07c04cd9a463 100644 (file)
@@ -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 (file)
index 0000000..6ff50ee
--- /dev/null
@@ -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; i<gmap_data.length; i++){
+        var t = 1;
+        if(i>10) 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);
+}
+
index 5a4d9f27a9879d000335c92d6d830b4bc2ef7e96..0f810e654c2b1ede3fac4c1a8e3019f184476941 100644 (file)
@@ -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;
index da79d8f4f003506dca2844cb2879cbebd43077d1..d923bee1b4821d9f281ec9605450bae597c91228 100644 (file)
@@ -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 (file)
index 0000000..04e6038
--- /dev/null
@@ -0,0 +1,32 @@
+{include file="header.tpl"}
+
+<script type="text/javascript">
+
+    gmap_data = [
+        {ldelim}
+            adr: '{$entry.street|escape:javascript}, {$entry.zip|escape:javascript} {$entry.location|escape:javascript}',
+            info: '<h4>{$lang.business|escape:javascript}</h4>{$entry.street|escape:javascript}<br />{$entry.zip|escape:javascript} {$entry.location|escape:javascript}'
+        {rdelim},
+        {ldelim}
+            adr: '{$entry.homestreet|replace:"\n":", "|escape:javascript}',
+            info: '<h4>{$lang.private|escape:javascript}</h4>{$entry.homestreet|replace:"\n":"<br />"|escape:javascript}'
+        {rdelim}
+    ];
+</script>
+
+<div id="map">
+
+    <h1>
+    <img src="pix/{$entry.type|h}.png" border="0" width="22" height="22"
+    align="middle" title="{$entry.type|h}" alt="" />
+    {$entry.givenname|h} {$entry.name|h}
+    </h1>
+
+
+    <div id="google_map"></div>
+
+
+
+</div>
+
+{include file="footer.tpl"}
index e94d2dbce197c37ed121c74a727adc617ba8b92d..a626377e66abd020e461544a1ecdf0817d354f80 100644 (file)
@@ -21,6 +21,7 @@
         <table width="100%">
           <tr>
             <td colspan="2">
+
               {$entry.title|h} {$entry.givenname|h} {$entry.name|h}<br />
 {if $entry.organization}
               <a href="index.php?org={$entry.organization|escape:url}">{$entry.organization|h}</a><br />
@@ -32,7 +33,7 @@
               {$entry.street|h}<br />
 {/if}
 {if $entry.location}
-              {$entry.zip} {$entry.location|h}<br />
+              {$entry.zip|h} {$entry.location|h}<br />
 {/if}
 {if $entry.state}
               {$entry.state|h}
@@ -40,7 +41,7 @@
 {if $entry.country}
               {$entry.country|h}
 {/if}
-              <br /><br />
+              </br /><br />
             </td>
           </tr>
 {if $entry.phone}
diff --git a/templates/export_list_csv.tpl b/templates/export_list_csv.tpl
deleted file mode 100644 (file)
index 34835a2..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-{$lang.name|csv};{$lang.givenname|csv};{$lang.title|csv};{$lang.organization|csv};{$lang.office|csv};{$lang.street|csv};{$lang.zip|csv};{$lang.location|csv};{$lang.phone|csv};{$lang.fax|csv};{$lang.pager|csv};{$lang.homestreet|csv};{$lang.homephone|csv};{$lang.mobile|csv};{$lang.url|csv};{$lang.note|csv};{$lang.mail|csv};{$lang.mail|csv};{$lang.mail|csv};{$lang.marker|csv}
-{$list}
index 0fc34924a8d9e4fed4c8922e375b4d1f9c4494ea..4939c97ba313b34770fdec30ffd59557ffdf8819 100644 (file)
     <script src="scripts/interface/imagebox.js" type="text/javascript"></script>
     <script src="scripts/formatDate.js" type="text/javascript"></script>
 
+    {if $conf.gmapkey}
+    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key={$conf.gmapkey}" type="text/javascript"></script>
+    <script src="scripts/maps.js" type="text/javascript"></script>
+    {/if}
+
     <script src="scripts/gui.js" type="text/javascript"></script>
 
     <script type="text/javascript">
diff --git a/templates/list_csv.tpl b/templates/list_csv.tpl
new file mode 100644 (file)
index 0000000..34835a2
--- /dev/null
@@ -0,0 +1,2 @@
+{$lang.name|csv};{$lang.givenname|csv};{$lang.title|csv};{$lang.organization|csv};{$lang.office|csv};{$lang.street|csv};{$lang.zip|csv};{$lang.location|csv};{$lang.phone|csv};{$lang.fax|csv};{$lang.pager|csv};{$lang.homestreet|csv};{$lang.homephone|csv};{$lang.mobile|csv};{$lang.url|csv};{$lang.note|csv};{$lang.mail|csv};{$lang.mail|csv};{$lang.mail|csv};{$lang.marker|csv}
+{$list}
diff --git a/templates/list_map.tpl b/templates/list_map.tpl
new file mode 100644 (file)
index 0000000..a710ce7
--- /dev/null
@@ -0,0 +1,15 @@
+{include file="header.tpl"}
+
+<script type="text/javascript">
+
+    gmap_data = [
+        {$list}
+    ];
+</script>
+
+<div id="map">
+
+<div id="google_map"></div>
+</div>
+
+{include file="footer.tpl"}
diff --git a/templates/list_map_entry.tpl b/templates/list_map_entry.tpl
new file mode 100644 (file)
index 0000000..5557416
--- /dev/null
@@ -0,0 +1,7 @@
+
+{ldelim}
+    adr: '{$entry.street|escape:javascript}, {$entry.zip|escape:javascript} {$entry.location|escape:javascript}',
+    info: '<h4>{$entry.organization|escape:javascript}</h4>{$entry.street|escape:javascript}<br />{$entry.zip|escape:javascript} {$entry.location|escape:javascript}'
+{rdelim},
+
+
index a5683c3d483d0a9813b0e2dac92293dc53a76c22..cd1df671e868bb7e664346d9b65302cd1fe073a5 100644 (file)
@@ -16,6 +16,7 @@
   <li class="sep">&nbsp;</li>
 
   {if $dn} <!-- begin contact page functions -->
+
     {if $user} <!-- begin editing functions -->
 
       <!-- edit/show, copy, delete -->
       <a href="entry.php?dn={$dn|escape:url}&amp;mode=vcf" class="ed_vcfexport">{$lang.vcfexport}</a>
     </li>
 
+    <!-- show on map -->
+    {if $smarty.request.mode == 'map' && $conf.gmapkey}
+        <li>
+          <a href="entry.php?dn={$dn|escape:url}" class="ed_show">{$lang.show}</a>
+        </li>
+    {elseif $conf.gmapkey}
+        <li>
+          <a href="entry.php?dn={$dn|escape:url}&amp;mode=map" class="ed_map">{$lang.map}</a>
+        </li>
+    {/if}
+
     <li class="sep">&nbsp;</li>
   {/if} <!-- end contact page functions -->
 
 
   {if $list} <!-- export -->
+    {if $smarty.request.export != 'map' && $conf.gmapkey}
+        <li>
+          <a href="index.php?filter={$filter|escape:url}&amp;marker={$marker|escape:url}&amp;search={$search|escape:url}&amp;export=map" class="ed_map">{$lang.map}</a>
+        </li>
+    {/if}
     <li>
       <a href="index.php?filter={$filter|escape:url}&amp;marker={$marker|escape:url}&amp;search={$search|escape:url}&amp;export=csv"
          class="ed_csvexport">{$lang.csvexport}</a>