Fix hard coded ABN bug
[disclosr.git] / getAgency.php
blob:a/getAgency.php -> blob:b/getAgency.php
--- a/getAgency.php
+++ b/getAgency.php
@@ -31,7 +31,7 @@
             if (strpos($key, "_") === 0) {
                 echo"<input type='hidden' id='$key' name='$key' value='$value'/>";
             } if (strpos($key, "has") === 0) {
-                echo "<label for='$key'><input type='checkbox' id='$key' name='$key' value='$value'> $key</label>";
+                echo "<label for='$key'><input type='checkbox' id='$key' name='$key' checked='$value'> $key</label>";
             } 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 != "") {
@@ -47,10 +47,19 @@
 }
 
 function addDefaultFields($row) {
-    $defaultFields = Array("name");
+    global $schemas;
+    $defaultFields = array_keys($schemas['agency']['properties']);
     foreach ($defaultFields as $defaultField) {
-        if (!isset($row[$defaultField]))
+        if (!isset($row[$defaultField])) {
+            if ($schemas['agency']['properties'][$defaultField]['type'] == "string") {
+                
             $row[$defaultField] = "";
+            }
+             if ($schemas['agency']['properties'][$defaultField]['type'] == "array") {
+                
+            $row[$defaultField] = Array("");
+            }
+        }
     }
     return $row;
 }
@@ -119,12 +128,20 @@
     } else {
 
         try {
-            $rows = $db->get_view("app", "showNamesABNs")->rows;
+            /*$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>';
+            }*/
+            $rows = $db->get_view("app", "byName")->rows;
+            //print_r($rows);
+            foreach ($rows as $row) {
+                //   print_r($row);
+                echo '<li><a href="getAgency.php?id=' . $row->value . '">' .
+                $row->key
                 . '</a></li>';
             }
         } catch (SetteeRestClientException $e) {