Edit and view modes for agency records
[disclosr.git] / getAgency.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
 
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);
 
    $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) {
        echo displayValue($key, $value, $mode);
    }
    if ($mode == "view") {
        echo "</table>";
    }
    if ($mode == "edit") {
        echo '</form>';
    }
} 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();