Merge branch 'master' of ssh://apples.lambdacomplex.org/git/disclosr
Merge branch 'master' of ssh://apples.lambdacomplex.org/git/disclosr


Former-commit-id: 3df5c7f8ae2e72a7e4ef02c533d19f602f90e201

file:a/about.php -> file:b/about.php
--- a/about.php
+++ b/about.php
@@ -5,6 +5,10 @@
 <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/>

file:a/charts.php (deleted)
--- a/charts.php
+++ /dev/null
@@ -1,133 +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>
-<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">Lorem ipsum.</h4>
+    <h4 class="subheader"></h4>
 </div>
 <div id="bydate" style="width:1000px;height:300px;"></div>
-<div id="byagency" style="width:1200px;height:300px;"></div>
+<div id="byagency" style="width:1200px;height:800px;"></div>
 <script id="source">
     window.onload = function () {
         $(document).ready(function () {
@@ -59,7 +59,7 @@
                     mode: 'x'
                 },
                 HtmlText: false,
-                title: 'Time'
+                title: 'Disclosure Log entries added by Date'
             };
 
             // Draw graph with default options, overwriting with passed options
@@ -98,12 +98,12 @@
     var agencylabels = [];
     function agencytrackformatter(obj) {
 
-        return agencylabels[Math.floor(obj.x)] + " = " + obj.y;
+        return agencylabels[Math.floor(obj.y)] + " = " + obj.x;
 
     }
     function agencytickformatter(val, axis) {
         if (agencylabels[Math.floor(val)]) {
-            return '<p style="margin-top:8em;-webkit-transform:rotate(-90deg);">' + (agencylabels[Math.floor(val)]) + "</b>";
+            return  (agencylabels[Math.floor(val)]) ;
 
         } else {
             return "";
@@ -117,7 +117,7 @@
             $dataValues = Array();
             $i = 0;
             foreach ($rows as $row) {
-                echo "       d2.push([".$i.", $row->value]);" . PHP_EOL;
+                echo "       d2.push([ $row->value,$i]);" . PHP_EOL;
                 echo "       agencylabels.push(['".str_replace("'","",$idtoname[$row->key])."']);" . PHP_EOL;
 
                 $i++;
@@ -131,9 +131,10 @@
         document.getElementById("byagency"),
         [d2],
         {
+            title: "Disclosure Log entries by Agency",
             bars: {
                 show: true,
-                horizontal: false,
+                horizontal: true,
                 shadowSize: 0,
                 barWidth: 0.5
             },
@@ -143,14 +144,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.py
+++ b/documents/datagov-export.py
@@ -13,9 +13,20 @@
     pass
 
 import tempfile
-def add_package_resource_cachedurl(ckan, package_name, url, name, format, size, **kwargs):
+def add_package_resource_cachedurl(ckan, package_name, url, name, format, license_id, size,**kwargs):
+    if "xls" in url:
+	format = "xls"
+    if "pdf" in url:
+	format = "pdf"
+    if "xlsx" in url:
+	format = "xlsx"
     (returned_url, mime_type, content) = scrape.fetchURL(scrape.docsdb,
                                                 url, "dataset_resource", "AGIMO", False)
+    if mime_type in ["application/vnd.ms-excel","application/msexcel","application/x-msexcel","application/x-ms-excel","application/x-excel","application/x-dos_ms_excel","application/xls","application/x-xls"]:
+	format = "xls"
+    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)
 	    tfName = os.path.abspath(tf.name)
@@ -23,12 +34,12 @@
 	    tf.seek(0)
 	    tf.write(content)
 	    tf.flush()
-	    ckan.add_package_resource (package_name, tfName, name=name)
+	    ckan.add_package_resource (package_name, tfName, name=name, format=format, license_id=license_id)
     else:
 	print "fetch error"
-	ckan.add_package_resource(package_name, url, name=name, resource_type='data',
+	return ckan.add_package_resource(package_name, url, name=name, resource_type='data',
                                                       format=format,
-                                                      size=size)
+                                                      size=size, mimetype=mime_type, license_id=license_id)
 
 # Instantiate the CKAN client.
 api_key = 'ff34526e-f794-4068-8235-fcbba38cd8bc'
@@ -147,15 +158,15 @@
     return munge(input_name.replace(' ', '').replace('.', '_').replace('&', 'and'))
 
 
-def get_licence_id(licencename):
+def get_license_id(licencename):
     map = {
         "Creative Commons - Attribution-Share Alike 2.0 Australia (CC-SA)\nThe downloadable version of the database is licensed under CC-BY-SA Creative Commons Attribution Share Alike and contains only the database fields that are released under that license. These fields are object title, object number, object description as well as temporal, spatial and dimension details. It also contains a persistent URL for each record.": 'cc-by-sa',
         "CreativeCommonsAttributionNonCommercial30AustraliaCCBYNC30": 'cc-nc',
         'Otherpleasespecify': 'notspecified',
         '': 'notspecified',
         "Publicly available data": 'notspecified',
-        "CreativeCommonsAttributionNoDerivativeWorks30AustraliaCCBYND30": "other-closed",
-        "CreativeCommonsAttributionNonCommercialNoDerivs30AustraliaCCBYNCND30": "other-closed",
+        "CreativeCommonsAttributionNoDerivativeWorks30AustraliaCCBYND30": "cc-by-nd",
+        "CreativeCommonsAttributionNonCommercialNoDerivs30AustraliaCCBYNCND30": "cc-nc-nd",
         'CreativeCommonsAttribution30AustraliaCCBY30': 'cc-by',
         "Creative Commons - Attribution 2.5 Australia (CC-BY)": 'cc-by',
         'CreativeCommonsAttributionCCBY25': 'cc-by',
@@ -191,6 +202,8 @@
                 agency = doc.value['metadata']["Agency"]
                 if agency == "APS":
                     agency = "Australian Public Service Commission"
+                if agency == "Department of Broadband, Communications and the Digital Ecomomy":
+                    agency = "Department of Broadband, Communications and the Digital Economy"
                 if agency == "Shared Services, Treasury Directorate":
                     agency = "Shared Services Procurement, Treasury Directorate"
                 if agency == "Treasury - Shared Services":
@@ -248,8 +261,8 @@
                         'tags': tags, #tags are mandatory?
                         'author': creator,
                         'maintainer': creator,
-                        'licence_id': get_licence_id(doc.value['metadata']['DCTERMS.License']),
-                        'notes': html2text.html2text(doc.value['metadata']['Description']),
+                        '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 "," "),
                         'owner_org': org_id,
                         'extras': extras,
                         'private': (pkg_name not in goodcsvdata and pkg_name not in goodotherdata)
@@ -292,9 +305,8 @@
                                     name = resource['name']
                                 print resource
                                 add_package_resource_cachedurl(ckan, pkg_name, url_fix(resource['href']), name,
-                                                          format,
-                                                          human2bytes(resource.get('size', '0B')),
-                                                          resource_type='data')
+                                                          format, get_license_id(doc.value['metadata']['DCTERMS.License']),
+                                                          human2bytes(resource.get('size', '0B')))
                         else:
                             print "resources already exist"
                     except CkanApiError, e:

--- a/documents/scrape.py
+++ b/documents/scrape.py
@@ -112,7 +112,7 @@
     else:
         if (('page_scraped' in doc) and ((time.time() - doc['page_scraped']) < 60 * 24 * 14) or (scrape_again == False)):
             print "Uh oh, trying to scrape URL again too soon!" + hash
-	    if "_attachments" in doc.keys():
+	    if (not doc.has_key('file_size') or doc["file_size"] != "0") and "_attachments" in doc.keys():
 	            last_attachment_fname = doc["_attachments"].keys()[-1]
 	            last_attachment = docsdb.get_attachment(doc, last_attachment_fname)
         	    content = last_attachment.read()

--- 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,6 +79,7 @@
                         <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>

--- /dev/null
+++ b/employees-fail.php
@@ -1,1 +1,134 @@
+<?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,11 +2,12 @@
 
 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>";
 
@@ -22,7 +23,8 @@
                 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 " >";
@@ -62,7 +64,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;
@@ -70,7 +72,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 != "") {
@@ -85,7 +87,8 @@
 // 
 }
 
-function addDefaultFields($row) {
+function addDefaultFields($row)
+{
     global $schemas;
     $defaultFields = array_keys($schemas['agency']['properties']);
     foreach ($defaultFields as $defaultField) {
@@ -119,103 +122,103 @@
 // 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 == "") {
+    foreach ($_POST as $postkey => $postvalue) {
+        if ($postvalue == "") {
+            unset($_POST[$postkey]);
+        }
+        if (is_array($postvalue)) {
+            if (count($postvalue) == 1 && $postvalue[0] == "") {
                 unset($_POST[$postkey]);
-            }
-            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]);
-                        }
+            } 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);
-        } 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);
+    }
+    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 {
-        $row = $rowArray;
-    }
-
-    if ($mode == "view") {
-            echo ' <div class="container-fluid">
+        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 {
+    $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>';
-        }
+
+    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">
+    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
+    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 + "'/>")
+                    );
+                }
+            });