Edit and view modes for agency records
Former-commit-id: e975475a91653ade66930f0630d673ec384a64e7
--- a/common.inc.php
+++ b/common.inc.php
@@ -4,12 +4,13 @@
global $db;
$obj = new stdClass();
$obj->_id = "_design/" . urlencode("app");
+ $obj->language = "javascript";
$obj->views->byABN->map = "function(doc) { emit(doc.abn, doc); };";
$obj->views->byName->map = "function(doc) { emit(doc.name, doc); };";
$obj->views->getActive->map = 'function(doc) { if (doc.status == "active") { emit(doc._id, doc); } };';
$obj->views->getSuspended->map = 'function(doc) { if (doc.status == "suspended") { emit(doc._id, doc); } };';
$obj->views->getScrapeRequired->map = "function(doc) { emit(doc.abn, doc); };";
-$obv->views->showNamesABNs->map = "function(doc) { emit(doc._id, {name: doc.name, abn: doc.abn}); };";
+$obj->views->showNamesABNs->map = "function(doc) { emit(doc._id, {name: doc.name, abn: doc.abn}); };";
// allow safe updates (even if slightly slower due to extra: rev-detection check).
return $db->save($obj, true);
}
@@ -37,7 +38,7 @@
<!-- Set the viewport width to device width for mobile -->
<meta name="viewport" content="width=device-width" />
- <title>Welcome to Foundation</title>
+ <title>Disclosr</title>
<!-- Included CSS Files -->
<link rel="stylesheet" href="stylesheets/foundation.css">
--- a/getAgency.php
+++ b/getAgency.php
@@ -2,25 +2,65 @@
include_once('common.inc.php');
include_header();
+
+function displayValue($key, $value, $mode) {
+ if ($mode == "view") {
+ if (is_array($value)) {
+ echo "<tr><td>$key</td><td><ol>";
+ foreach ($value as $subkey => $subvalue) {
+ echo "<li>$subvalue</li>";
+ }
+ echo "</ol></td></tr>";
+ } else {
+ echo "<tr><td>$key</td><td>$value</td></tr>";
+ }
+ }
+ if ($mode == "edit") {
+ if (is_array($value)) {
+ echo "<label>$key</label><ol>";
+ foreach ($value as $subkey => $subvalue) {
+ echo "<li>$subvalue</li>";
+ }
+ echo "</ol>";
+ } else {
+ if (strpos($key,"_") === 0) {
+ echo"<input type='hidden' id='$key' name='$key' value='$value'/>";
+ } else {
+ echo "<label>$key</label><input class='input-text' type='text' id='$key' name='$key' value='$value'/></tr>";
+
+ }
+ }
+ }
+}
+
$db = $server->get_db('disclosr-agencies');
if (isset($_REQUEST['id'])) {
//get an agency record as json/html, search by name/abn/id
// by name = startkey="Ham"&endkey="Ham\ufff0"
// edit?
-
- $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>";
+
+ $row = $db->get($_REQUEST['id']);
+ //print_r($row);
+
+ $mode = "edit";
+
+ if ($mode == "view") {
+ 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>";
+ }
+ if ($mode == "edit") {
+ echo '<form class="nice">';
+ }
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 displayValue($key, $value, $mode);
}
-
- echo "</table>";
+ if ($mode == "view") {
+ echo "</table>";
+ }
+ if ($mode == "edit") {
+ echo '</form>';
+ }
} else {
$rows = $db->get_view("app", "showNamesABNs")->rows;
@@ -28,8 +68,8 @@
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>';
+ (isset($row->value->name) && $row->value->name != "" ? $row->value->name : "NO NAME " . $row->value->abn)
+ . '</a></li>';
}
}
include_footer();