Record listing and individual viewing
[disclosr.git] / getAgency.php
blob:a/getAgency.php -> blob:b/getAgency.php
--- a/getAgency.php
+++ b/getAgency.php
@@ -3,23 +3,33 @@
 include_once('common.inc.php');
 include_header();
 $db = $server->get_db('disclosr-agencies');
-//get an agency record as json/html, search by name/abn/id
+if (isset($_REQUEST['id'])) {
+    //get an agency record as json/html, search by name/abn/id
 // by name = startkey="Ham"&endkey="Ham\ufff0"
 // edit?
-$rows = $db->get_view("app","byABN")->rows;
-//print_r($rows);
-foreach ($rows as $row) {
-
-    echo "<table>";
-    echo '<tr> <td colspan="2"><h3>' . $row->value->name . "</h3></td></tr>";
+    
+   $row = $db->get($_REQUEST['id']);
+   //print_r($row);
+    echo '<table width="100%">';
+    echo '<tr> <td colspan="2"><h3>' . $row->name . "</h3></td></tr>";
     echo "<tr><th>Field Name</th><th>Field Value</th></tr>";
-foreach ($row->value as $key => $value) {
-            if (is_a($value, 'stdClass')) {
-            		echo "<tr><td>$key</td><td>".var_dump($value,true)."</td></tr>";
-            } else echo "<tr><td>$key</td><td>$value</td></tr>";
-	} // also show documents/URLs available
+    foreach ($row as $key => $value) {
+        if (is_a($value, 'stdClass')) {
+            echo "<tr><td>$key</td><td>" . var_dump($value, true) . "</td></tr>";
+        } else
+            echo "<tr><td>$key</td><td>$value</td></tr>";
+    }
 
     echo "</table>";
+} else {
+
+    $rows = $db->get_view("app", "showNamesABNs")->rows;
+//print_r($rows);
+    foreach ($rows as $row) {
+        //   print_r($row);
+        echo '<li><a href="getAgency.php?id=' . $row->key . '">' .
+                (isset($row->value->name) && $row->value->name != "" ? $row->value->name : "NO NAME " . $row->value->abn) 
+                . '</a></li>';
+    }
 }
-
 include_footer();