more export fixes
more export fixes


Former-commit-id: 4ca7f1f81d51d7c094d904b6aa1e176cf5958630

file:a/about.php -> file:b/about.php
--- a/about.php
+++ b/about.php
@@ -5,10 +5,6 @@
 <div class="foundation-header">
     <h1><a href="about.php">About/FAQ</a></h1>
 </div>
-<a href="http://thenounproject.com/noun/document-dump/">Document Dump icon designed by  Iconathon,  2013</a>
-Contact us: maxious@lambdacomplex.org
-
-Exports: <a href="admin/exportAll.csv.php">All Agencies</a> <a href="admin/exportEmployees.csv.php">Agency Employee Headcounts</a>
 <h2> Attributions </h2>
 National Archives of Australia, Australian Governments’ Interactive Functions Thesaurus, 2nd edition, September 2005, published at http://www.naa.gov.au/recordkeeping/thesaurus/index.htm <br/>
 data.gov.au http://data.gov.au/dataset/directory-gov-au-full-data-export/ <br/>

--- a/admin/refreshDesignDoc.php
+++ b/admin/refreshDesignDoc.php
@@ -8,7 +8,7 @@
 $obj->_id = "_design/" . urlencode("app");
 $obj->language = "javascript";
 $obj->views->all->map = "function(doc) {   emit(doc._id, doc); };";
-$obj->views->byDate->map = "function(doc) {   emit(doc.date, doc); };";
+$obj->views->byDate->map = "function(doc) {  if (doc.title != "Disclosure Log Updated") { emit(doc.date, doc); } };";
 $obj->views->byDateMonthYear->map = "function(doc) {   emit(doc.date, doc); };";
 $obj->views->byDateMonthYear->reduce = "_count";
 $obj->views->byAgencyID->map = "function(doc) {   emit(doc.agencyID, doc); };";

file:b/charts.php (new)
--- /dev/null
+++ b/charts.php
@@ -1,1 +1,133 @@
+<?php
+include_once('include/common.inc.php');
+include_header('Charts');
+$db = $server->get_db('disclosr-agencies');
+?>
+<div class="foundation-header">
+    <h1><a href="about.php">Charts</a></h1>
+    <h4 class="subheader">Lorem ipsum.</h4>
+</div>
+<div id="scores" style="width:900px;height:500px;"></div>
+<div id="employees" style="width:1000px;height:900px;"></div>
+<script id="source">
+    window.onload = function() {
+        $(document).ready(function() {
+            var d1 = [];
+            var scorelabels = [];
+    <?php
+    try {
+        $rows = $db->get_view("app", "scoreHas?group=true", null, true)->rows;
 
+
+        $dataValues = Array();
+        foreach ($rows as $row) {
+            $dataValues[$row->value] = $row->key;
+        }
+        $i = 0;
+        ksort($dataValues);
+        foreach ($dataValues as $value => $key) {
+
+            echo "       d1.push([$i, $value]);" . PHP_EOL;
+            echo "        scorelabels.push('$key');" . PHP_EOL;
+            $i++;
+        }
+    } catch (SetteeRestClientException $e) {
+        setteErrorHandler($e);
+    }
+    ?>
+                function scoretrackformatter(obj) {
+                    if (scorelabels[Math.floor(obj.x)]) {
+                        return (scorelabels[Math.floor(obj.x)])+"="+obj.y;
+                     
+                    } else {
+                        return "";
+                    }
+                }
+                function scoretickformatter(val, axis) {
+                    if (scorelabels[Math.floor(val)]) {
+                        return '<p style="margin-top:8em;-webkit-transform:rotate(-90deg);">'+(scorelabels[Math.floor(val)])+"</b>";
+                     
+                    } else {
+                        return "";
+                    }
+                }
+                Flotr.draw(document.getElementById("scores"), [ {data: d1}], {
+                    HtmlText: true,
+                    bars : {
+                        show : true
+                    },
+                    mouse : {
+                        track : true,
+                        relative : true,
+                        trackFormatter: scoretrackformatter
+                    },yaxis: {
+                        autoscaling: true
+                    },
+                    xaxis: {
+                    autoscaling: true,
+                        minorTickFreq: 0.6,
+                        noTicks : scorelabels.length,
+                        tickFormatter: scoretickformatter
+                    }
+                });
+                
+                
+                
+                
+                
+                
+                
+                
+var emplabels = [];
+function emptrackformatter(obj) {
+                   
+                        return (obj.series.label)+" = "+obj.y+" in "+emplabels[Math.floor(obj.x)];
+                     
+                }
+                function emptickformatter(val, axis) {
+                    if (emplabels[Math.floor(val)]) {
+                        return '<p style="margin-top:8em;-webkit-transform:rotate(-90deg);">'+(emplabels[Math.floor(val)])+"</b>";
+                     
+                    } else {
+                        return "";
+                    }
+                }
+function onDataReceived(series) {
+    emplabels = series.labels;
+                       Flotr.draw(document.getElementById("employees"), series.data, {
+                    mouse : {
+                        track : true,
+                        relative : true,
+                    trackFormatter: emptrackformatter
+                    },yaxis: {
+                        max: 10000,
+                        scaling: 'logarithmic'
+                    },
+                    xaxis: {
+                    minorTickFreq: 1,
+                    noTicks: emplabels.length,
+                    showMinorLabels: true,
+                        tickFormatter: emptickformatter
+                    },
+                    legend: {
+                        show: false
+                    }
+                });
+                }
+        
+                $.ajax({
+                    url: "admin/exportEmployees.csv.php?format=json",
+                    method: 'GET',
+                    dataType: 'json',
+                    success: onDataReceived
+                });
+
+    
+            });
+        };
+ 
+</script>
+
+<?php
+include_footer();
+?>

--- a/documents/charts.php
+++ b/documents/charts.php
@@ -13,10 +13,10 @@
 ?>
 <div class="foundation-header">
     <h1><a href="about.php">Charts</a></h1>
-    <h4 class="subheader"></h4>
+    <h4 class="subheader">Lorem ipsum.</h4>
 </div>
 <div id="bydate" style="width:1000px;height:300px;"></div>
-<div id="byagency" style="width:1200px;height:800px;"></div>
+<div id="byagency" style="width:1200px;height:300px;"></div>
 <script id="source">
     window.onload = function () {
         $(document).ready(function () {
@@ -59,7 +59,7 @@
                     mode: 'x'
                 },
                 HtmlText: false,
-                title: 'Disclosure Log entries added by Date'
+                title: 'Time'
             };
 
             // Draw graph with default options, overwriting with passed options
@@ -98,12 +98,12 @@
     var agencylabels = [];
     function agencytrackformatter(obj) {
 
-        return agencylabels[Math.floor(obj.y)] + " = " + obj.x;
+        return agencylabels[Math.floor(obj.x)] + " = " + obj.y;
 
     }
     function agencytickformatter(val, axis) {
         if (agencylabels[Math.floor(val)]) {
-            return  (agencylabels[Math.floor(val)]) ;
+            return '<p style="margin-top:8em;-webkit-transform:rotate(-90deg);">' + (agencylabels[Math.floor(val)]) + "</b>";
 
         } else {
             return "";
@@ -117,7 +117,7 @@
             $dataValues = Array();
             $i = 0;
             foreach ($rows as $row) {
-                echo "       d2.push([ $row->value,$i]);" . PHP_EOL;
+                echo "       d2.push([".$i.", $row->value]);" . PHP_EOL;
                 echo "       agencylabels.push(['".str_replace("'","",$idtoname[$row->key])."']);" . PHP_EOL;
 
                 $i++;
@@ -131,10 +131,9 @@
         document.getElementById("byagency"),
         [d2],
         {
-            title: "Disclosure Log entries by Agency",
             bars: {
                 show: true,
-                horizontal: true,
+                horizontal: false,
                 shadowSize: 0,
                 barWidth: 0.5
             },
@@ -144,14 +143,14 @@
                 trackFormatter: agencytrackformatter
             },
             yaxis: {
+                min: 0,
+                autoscaleMargin: 1
+            },
+            xaxis: {
                 minorTickFreq: 1,
                 noTicks: agencylabels.length,
                 showMinorLabels: true,
                 tickFormatter: agencytickformatter
-            },
-            xaxis: {
-                min: 0,
-                autoscaleMargin: 1
             },
             legend: {
                 show: false

--- a/documents/datagov-export-groups.py
+++ b/documents/datagov-export-groups.py
@@ -10,7 +10,11 @@
 # Instantiate the CKAN client.
 #ckan = ckanclient.CkanClient(base_location='http://localhost:5000/api',    api_key='b47b24cd-591d-40c1-8677-d73101d56d1b')
 api_key = 'ff34526e-f794-4068-8235-fcbba38cd8bc'
-ckan = ckanclient.CkanClient(base_location='http://data.disclosurelo.gs/api',
+server = 'data.disclosurelo.gs'
+api_key = 'c30eb6f5-0f90-47e0-bf05-9b1b4e3a461a'
+server = 'ckan.data.gov.au'
+
+ckan = ckanclient.CkanClient(base_location='http://' + server + '/api',
                              api_key=api_key)
 couch = couchdb.Server('http://127.0.0.1:5984/')
 #couch = couchdb.Server('http://192.168.1.113:5984/')

--- a/documents/datagov-export.py
+++ b/documents/datagov-export.py
@@ -14,6 +14,7 @@
 
 import tempfile
 def add_package_resource_cachedurl(ckan, package_name, url, name, format, license_id, size,**kwargs):
+    excluded_apis = "recent-earthquakes,sentinel-hotspots,abc-local-stations,action-bus-service-gtfs-feed-act,current-and-future-road-reports-traffic-restrictions-in-south-australia,current-and-future-road-reports-traffic-restrictions-in-south-australia,current-and-future-road-reports-traffic-restrictions-in-south-australia,current-and-future-road-reports-traffic-restrictions-in-south-australia,current-and-future-road-reports-traffic-restrictions-in-south-australia,current-and-future-road-reports-traffic-restrictions-in-south-australia,journey-planner-data-act,live-traffic-cameras-nsw,precis-forecast-national,precis-forecast-national,precis-forecast-new-south-wales,precis-forecast-new-south-wales,precis-forecast-northern-territory,precis-forecast-northern-territory,precis-forecast-queensland,precis-forecast-queensland,precis-forecast-south-australia,precis-forecast-south-australia,precis-forecast-tasmania,precis-forecast-tasmania,precis-forecast-victoria,precis-forecast-victoria,precis-forecast-western-australia,precis-forecast-western-australia,register-of-penalty-notices-nsw,sentinel-hotspots,trove-people-and-organisations-data,weather-data-services-radar,abc-local-stations,act-emergency-services-agency-esa-28093-current-incidents,act-emergency-services-agency-esa-news-alerts,act-government-news-and-events,act-government-summaries-of-cabinet-outcomes,act-magistrates-court-judgements,act-supreme-court-judgements,act-supreme-court-sentences,actpla-latest-news,all-vacant-act-government-jobs,community-engagement-current-engagements,community-engagement-news,edd-media-releases,edd-news-and-events,freedom-of-information-foi-summaries,libraries-act-announcements,nsw-rural-fire-service-current-incidents,nsw-rural-fire-service-major-updates,precis-forecast-new-south-wales,precis-forecast-south-australia,precis-forecast-tasmania,precis-forecast-victoria,sentinel-hotspots,south-australian-road-crash-statistics,trove-people-and-organisations-data,weather-warnings-for-new-south-wales-australian-capital-territory,weather-warnings-for-northern-territory,weather-warnings-for-queensland,weather-warnings-for-south-australia,weather-warnings-for-tasmania,weather-warnings-for-victoria,weather-warnings-for-western-australia".split(",")
     if "xls" in url:
 	format = "xls"
     if "pdf" in url:
@@ -27,8 +28,12 @@
     if mime_type in ["application/xlsx","application/x-xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]:
 	format = "xlsx"
 
-    if content != None:
-	    tf = tempfile.NamedTemporaryFile(delete=False)
+    #put file extensions on for windows users downloading files
+    suffix = name.encode("ascii","ignore").replace("/","")
+    if len(suffix) < 5 or (suffix[-4] != "." and suffix[-5] != "."):
+	suffix = suffix + "." + format
+    if content != None and package_name not in excluded_apis:
+	    tf = tempfile.NamedTemporaryFile(suffix=suffix)
 	    tfName = os.path.abspath(tf.name)
 	    print tfName
 	    tf.seek(0)
@@ -196,7 +201,7 @@
             pkg_name = filter(lambda x: x in '0123456789abcdefghijklmnopqrstuvwxyz-_',
                               doc.value['url'].replace("http://data.gov.au/dataset/", '').replace('/', '')[:100]);
             print pkg_name
-            if pkg_name != "":
+            if pkg_name != "" :
 
                 #add to or create organization using direct API
                 agency = doc.value['metadata']["Agency"]
@@ -262,7 +267,7 @@
                         'author': creator,
                         'maintainer': creator,
                         'license_id': get_license_id(doc.value['metadata']['DCTERMS.License']),
-                        'notes': html2text.html2text(doc.value['metadata']['Description']).replace('AC/a!a','-').replace('AC/a!aC/',"'").replace("AC/a!E",":")replace("A "," "),
+                        'notes': html2text.html2text(doc.value['metadata']['Description']).replace('AC/a!a','-').replace('AC/a!aC/',"'").replace("AC/a!E",":").replace("A "," "),
                         'owner_org': org_id,
                         'extras': extras,
                         'private': (pkg_name not in goodcsvdata and pkg_name not in goodotherdata)

--- a/documents/genericScrapers.py
+++ b/documents/genericScrapers.py
@@ -202,7 +202,7 @@
     def getDate(self, content, entry, doc):
         strdate = ''.join(content.stripped_strings).strip()
         (a, b, c) = strdate.partition("(")
-        strdate = self.remove_control_chars(a.replace("Octber", "October").replace("1012","2012")replace("Janrurary", "January").replace("1012","2012"))
+        strdate = self.remove_control_chars(a.replace("Octber", "October").replace("1012","2012").replace("Janrurary", "January").replace("1012","2012"))
         print strdate
         try:
 		edate = parse(strdate, dayfirst=True, fuzzy=True).strftime("%Y-%m-%d")

--- a/documents/runScrapers.sh
+++ b/documents/runScrapers.sh
@@ -1,7 +1,8 @@
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+echo $DIR
 cd $DIR
 echo "" > /tmp/disclosr-error
-for f in scrapers/*.py; do
+for f in $DIR/scrapers/*.py; do
 	echo "Processing $f file..";
 	md5=`md5sum /tmp/disclosr-error`
 	python $f 3>&1 1>&2 2>&3 | tee --append /tmp/disclosr-error;

--- a/documents/template.inc.php
+++ b/documents/template.inc.php
@@ -58,11 +58,11 @@
     <div class="navbar navbar-inverse navbar-fixed-top">
         <div class="navbar-inner">
             <div class="container-fluid">
-                <!--<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
+                <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                     <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
-                </a>    -->
+                </a>
                 <a class="brand" href="#">Australian Disclosure Logs</a>
 
                 <div class="nav-collapse collapse">
@@ -79,7 +79,6 @@
                         <li><a href="agency.php">By Agency</a></li>
                         <li><a href="date.php">By Date</a></li>
                         <li><a href="disclogsList.php">List of Disclosure Logs</a></li>
-                        <li><a href="charts.php">Charts</a></li>
                         <li><a href="about.php">About</a></li>
 
                     </ul>

file:a/employees-fail.php (deleted)
--- a/employees-fail.php
+++ /dev/null
@@ -1,134 +1,1 @@
-<?php
-include_once('include/common.inc.php');
-include_header('Charts');
-$db = $server->get_db('disclosr-agencies');
-?>
-<div class="foundation-header">
-    <h1><a href="about.php">Charts</a></h1>
-    <h4 class="subheader">Lorem ipsum.</h4>
-</div>
-<div id="scores" style="width:900px;height:500px;"></div>
-<script id="source">
-    window.onload = function() {
-        $(document).ready(function() {
-            var d1 = [];
-            var scorelabels = [];
-    <?php
-    try {
-        $rows = $db->get_view("app", "scoreHas?group=true", null, true)->rows;
 
-
-        $dataValues = Array();
-        foreach ($rows as $row) {
-            $dataValues[$row->value] = $row->key;
-        }
-        $i = 0;
-        ksort($dataValues);
-        foreach ($dataValues as $value => $key) {
-
-            echo "       d1.push([$i, $value]);" . PHP_EOL;
-            echo "        scorelabels.push('$key');" . PHP_EOL;
-            $i++;
-        }
-    } catch (SetteeRestClientException $e) {
-        setteErrorHandler($e);
-    }
-    ?>
-                function scoretrackformatter(obj) {
-                    if (scorelabels[Math.floor(obj.x)]) {
-                        return (scorelabels[Math.floor(obj.x)])+"="+obj.y;
-                     
-                    } else {
-                        return "";
-                    }
-                }
-                function scoretickformatter(val, axis) {
-                    if (scorelabels[Math.floor(val)]) {
-                        return '<p style="margin-top:8em;-webkit-transform:rotate(-90deg);">'+(scorelabels[Math.floor(val)])+"</b>";
-                     
-                    } else {
-                        return "";
-                    }
-                }
-                Flotr.draw(document.getElementById("scores"), [ {data: d1}], {
-                    HtmlText: true,
-                    bars : {
-                        show : true
-                    },
-                    mouse : {
-                        track : true,
-                        relative : true,
-                        trackFormatter: scoretrackformatter
-                    },yaxis: {
-                        autoscaling: true
-                    },
-                    xaxis: {
-                    autoscaling: true,
-                        minorTickFreq: 0.6,
-                        noTicks : scorelabels.length,
-                        tickFormatter: scoretickformatter
-                    }
-                });
-                
-                
-                
-                
-                
-                
-                
-                
-<div id="employees" style="width:1000px;height:900px;"></div>
-var emplabels = [];
-function emptrackformatter(obj) {
-                   
-                        return (obj.series.label)+" = "+obj.y+" in "+emplabels[Math.floor(obj.x)];
-                     
-                }
-                function emptickformatter(val, axis) {
-                    if (emplabels[Math.floor(val)]) {
-                        return '<p style="margin-top:8em;-webkit-transform:rotate(-90deg);">'+(emplabels[Math.floor(val)])+"</b>";
-                     
-                    } else {
-                        return "";
-                    }
-                }
-function onDataReceived(series) {
-    emplabels = series.labels;
-                       Flotr.draw(document.getElementById("employees"), series.data, {
-                    mouse : {
-                        track : true,
-                        relative : true,
-                    trackFormatter: emptrackformatter
-                    },yaxis: {
-                        max: 10000,
-                        scaling: 'logarithmic'
-                    },
-                    xaxis: {
-                    minorTickFreq: 1,
-                    noTicks: emplabels.length,
-                    showMinorLabels: true,
-                        tickFormatter: emptickformatter
-                    },
-                    legend: {
-                        show: false
-                    }
-                });
-                }
-        
-                $.ajax({
-                    url: "admin/exportEmployees.csv.php?format=json",
-                    method: 'GET',
-                    dataType: 'json',
-                    success: onDataReceived
-                });
-
-    
-            });
-        };
- 
-</script>
-
-<?php
-include_footer();
-?>
-

--- a/getAgency.php
+++ b/getAgency.php
@@ -2,12 +2,11 @@
 
 include_once('include/common.inc.php');
 
-function displayValue($key, $value, $mode)
-{
+function displayValue($key, $value, $mode) {
     global $db, $schemas;
-    $ignoreKeys = Array("metadata", "metaTags", "statistics", "rtkURLs", "rtkDescriptions");
+    $ignoreKeys = Array("metadata" ,"metaTags", "statistics","rtkURLs","rtkDescriptions");
     if ($mode == "view") {
-        if (strpos($key, "_") === 0 || in_array($key, $ignoreKeys))
+        if (strpos($key, "_") === 0 || in_array($key,$ignoreKeys))
             return;
         echo "<tr>";
 
@@ -23,8 +22,7 @@
                 echo "<li ";
                 if (isset($schemas['agency']["properties"][$key]['x-property'])) {
                     echo ' property="' . $schemas['agency']["properties"][$key]['x-property'] . '" ';
-                }
-                if (isset($schemas['agency']["properties"][$key]['x-itemprop'])) {
+                } if (isset($schemas['agency']["properties"][$key]['x-itemprop'])) {
                     echo ' itemprop="' . $schemas['agency']["properties"][$key]['x-itemprop'] . '" ';
                 }
                 echo " >";
@@ -64,7 +62,7 @@
 					</div>";
         } else {
             if (strpos($key, "_") === 0) {
-                echo "<input type='hidden' id='$key' name='$key' value='$value'/>";
+                echo"<input type='hidden' id='$key' name='$key' value='$value'/>";
             } else if ($key == "parentOrg") {
                 echo "<label for='$key'>$key</label><select  id='$key' name='$key'><option value=''> Select... </option>";
                 $rows = $db->get_view("app", "byDeptStateName")->rows;
@@ -72,7 +70,7 @@
                 foreach ($rows as $row) {
                     echo "<option value='{$row->value}'" . (($row->value == $value) ? "SELECTED" : "") . " >" . str_replace("Department of ", "", $row->key) . "</option>";
                 }
-                echo " </select>";
+                echo" </select>";
             } else {
                 echo "<label>$key</label><input  class='input-text' type='text' id='$key' name='$key' value='$value'/>";
                 if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") {
@@ -87,8 +85,7 @@
 // 
 }
 
-function addDefaultFields($row)
-{
+function addDefaultFields($row) {
     global $schemas;
     $defaultFields = array_keys($schemas['agency']['properties']);
     foreach ($defaultFields as $defaultField) {
@@ -122,128 +119,128 @@
 // by name = startkey="Ham"&endkey="Ham\ufff0"
 // edit?
 
-$obj = $db->get($_REQUEST['id']);
-include_header(isset($obj->name) ? $obj->name : "");
+    $obj = $db->get($_REQUEST['id']);
+    include_header(isset($obj->name) ? $obj->name : "");
 //print_r($row);
-if (sizeof($_POST) > 0) {
+    if (sizeof($_POST) > 0) {
 //print_r($_POST);
-    foreach ($_POST as $postkey => $postvalue) {
-        if ($postvalue == "") {
-            unset($_POST[$postkey]);
-        }
-        if (is_array($postvalue)) {
-            if (count($postvalue) == 1 && $postvalue[0] == "") {
+        foreach ($_POST as $postkey => $postvalue) {
+            if ($postvalue == "") {
                 unset($_POST[$postkey]);
-            } else {
-                foreach ($_POST[$postkey] as $key => &$value) {
-                    if ($value == "") {
-                        unset($_POST[$postkey][$key]);
+            }
+            if (is_array($postvalue)) {
+                if (count($postvalue) == 1 && $postvalue[0] == "") {
+                    unset($_POST[$postkey]);
+                } else {
+                    foreach ($_POST[$postkey] as $key => &$value) {
+                        if ($value == "") {
+                            unset($_POST[$postkey][$key]);
+                        }
                     }
                 }
             }
         }
-    }
-    if (isset($_POST['_id']) && $db->get_rev($_POST['_id']) == $_POST['_rev']) {
-        echo "Edited version was latest version, continue saving";
-        $newdoc = $_POST;
-        $newdoc['metadata']['lastModified'] = time();
-        $obj = $db->save($newdoc);
+        if (isset($_POST['_id']) && $db->get_rev($_POST['_id']) == $_POST['_rev']) {
+            echo "Edited version was latest version, continue saving";
+            $newdoc = $_POST;
+            $newdoc['metadata']['lastModified'] = time();
+            $obj = $db->save($newdoc);
+        } else {
+            echo "ALERT doc revised by someone else while editing. Document not saved.";
+        }
+    }
+
+    $mode = "view";
+    $rowArray = object_to_array($obj);
+    ksort($rowArray);
+    if ($mode == "edit") {
+        $row = addDefaultFields($rowArray);
     } else {
-        echo "ALERT doc revised by someone else while editing. Document not saved.";
-    }
-}
-
-$mode = "view";
-$rowArray = object_to_array($obj);
-ksort($rowArray);
-if ($mode == "edit") {
-    $row = addDefaultFields($rowArray);
+        $row = $rowArray;
+    }
+
+    if ($mode == "view") {
+            echo ' <div class="container-fluid">
+      <div class="row-fluid">
+        <div class="span3">
+          <div class="well sidebar-nav">
+            <ul class="nav nav-list">
+              <li class="nav-header">Statistics</li>';
+            
+             if (isset($row['statistics']['employees'])) {
+                echo '<div><i class="icon-user" style="float:left"></i><p style="margin-left:16px;">';
+                $keys = array_keys($row['statistics']['employees']);
+                $lastkey = $keys[count($keys)-1];
+                echo $row['statistics']['employees'][$lastkey]['value'].' employees <small>('.$lastkey.')</small>';
+                echo '</div>';
+            }
+        if (isset($row['statistics']['budget'])) {
+            echo '<div><i class="icon-shopping-cart" style="float:left"></i><p style="margin-left:16px;">';
+            $keys = array_keys($row['statistics']['budget']);
+            $lastkey = $keys[count($keys)-1];
+            echo "$".number_format(floatval($row['statistics']['budget'][$lastkey]['value'])).' <small>('.$lastkey.' budget)</small>';
+            echo '</div>';
+        }
+    echo '  </ul>
+          </div><!--/.well -->
+        </div><!--/span-->
+        <div class="span9">';
+        echo '<div itemscope itemtype="http://schema.org/GovernmentOrganization" typeof="schema:GovernmentOrganization" about="#' . $row['_id'] . '">';
+        echo '<div class="hero-unit">
+            <h1 itemprop="name">' . $row['name'] . '</h1>';
+            if (isset($row['description'])) {
+                echo '<p>'.$row['description'].'</p>';
+            }
+        echo '</div><table width="100%">';
+        echo "<tr><th>Field Name</th><th>Field Value</th></tr>";
+    }
+    if ($mode == "edit") {
+        ?>
+        <input  id="addfield" type="button" value="Add Field"/>
+        <script>
+            window.onload = function() {
+                $(document).ready(function() {
+                    // put all your jQuery goodness in here.
+                    // http://charlie.griefer.com/blog/2009/09/17/jquery-dynamically-adding-form-elements/
+                    $('#addfield').click(function() {
+                        var field_name=window.prompt("fieldname?","");
+                        if (field_name !="") {
+                            $('#submitbutton').before($('<span></span>')
+                            .append("<label>"+field_name+"</label>")
+                            .append("<input  class='input-text' type='text' id='"+field_name+"' name='"+field_name+"'/>")
+                        );
+                        }
+                    });
+                });
+            };
+        </script>
+        <form id="editform" class="nice" method="post">
+        <?php
+
+    }
+    foreach ($row as $key => $value) {
+        echo displayValue($key, $value, $mode);
+    }
+    if ($mode == "view") {
+        echo "</table></div>";
+              echo '         </div><!--/span-->
+          </div><!--/row-->
+        </div><!--/span-->
+      </div><!--/row-->';
+    }
+    if ($mode == "edit") {
+        echo '<input id="submitbutton" type="submit"/></form>';
+    }
 } else {
-    $row = $rowArray;
-}
-
-if ($mode == "view") {
+// show all list
+    include_header('Agencies');
     echo ' <div class="container-fluid">
       <div class="row-fluid">
         <div class="span3">
           <div class="well sidebar-nav">
             <ul class="nav nav-list">
-