From: maxious Date: Tue, 03 Jan 2012 13:42:56 +0000 Subject: includes/nav cleanup X-Git-Url: https://maxious.lambdacomplex.org/git/?p=disclosr.git&a=commitdiff&h=57d9a0f93d6c9e6f91f471996f1b530175ba7709 --- includes/nav cleanup Former-commit-id: 814e610d82c2640010ae9ead51310519574f6adb --- --- a/about.php +++ b/about.php @@ -1,3 +1,4 @@ + Organisational Data Sources http://www.comlaw.gov.au/Browse/Results/ByTitle/AdministrativeArrangementsOrders/Current/Ad/0 defines departments --- a/common.inc.php +++ /dev/null @@ -1,101 +1,1 @@ -_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); };"; -$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); -} - -require (realpath(dirname(__FILE__) . '/couchdb/settee/src/settee.php')); - -$server = new SetteeServer('http://127.0.0.1:5984'); - -function setteErrorHandler($e) { - echo $e->getMessage() . "
" . PHP_EOL; -} - -function include_header() { - ?> - - - - - - - - - - - - - - Disclosr - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - - - - - - - - - - - --- a/getAgency.php +++ b/getAgency.php @@ -1,6 +1,6 @@ $key
    "; + echo '
    +
    +
    +
    ' . $key . '
    '; foreach ($value as $subkey => $subvalue) { - echo "
  1. $subvalue
  2. "; + echo ""; } - echo "
"; + echo " + + "; } else { - if (strpos($key,"_") === 0) { + if (strpos($key, "_") === 0) { echo""; + } if (strpos($key, "has") === 0) { + echo ""; } else { - echo ""; - + echo ""; } } } + // +} + +function addDefaultFields($row) { + $defaultFields = Array("name"); + foreach ($defaultFields as $defaultField) { + if (!isset($row[$defaultField])) + $row[$defaultField] = ""; + } + return $row; } $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" @@ -41,35 +58,70 @@ $row = $db->get($_REQUEST['id']); //print_r($row); + if (sizeof($_POST) > 0) { + //print_r($_POST); + if (isset($_POST['_id']) && $db->get_rev($_POST['_id']) == $_POST['_rev']) { + echo "Edited version was latest version, continue saving"; + $row = $db->save($_POST); + } else { + echo "ALERT doc revised by someone else while editing."; + } + } $mode = "edit"; - + $row = addDefaultFields(object_to_array($row)); if ($mode == "view") { echo ''; - echo '"; + echo '"; echo ""; } if ($mode == "edit") { - echo ''; + ?> + + + + $value) { + echo displayValue($key, $value, $mode); + } + if ($mode == "view") { + echo "

' . $row->name . "

' . $row['name'] . "

Field NameField Value
"; + } + if ($mode == "edit") { + echo ''; + } + } else { + + try { + $rows = $db->get_view("app", "showNamesABNs")->rows; + //print_r($rows); + foreach ($rows as $row) { + // print_r($row); + echo '
  • ' . + (isset($row->value->name) && $row->value->name != "" ? $row->value->name : "NO NAME " . $row->value->abn) + . '
  • '; + } + } catch (SetteeRestClientException $e) { + setteErrorHandler($e); + } } - foreach ($row as $key => $value) { - echo displayValue($key, $value, $mode); - } - if ($mode == "view") { - echo ""; - } - if ($mode == "edit") { - echo ''; - } -} else { - - $rows = $db->get_view("app", "showNamesABNs")->rows; -//print_r($rows); - foreach ($rows as $row) { - // print_r($row); - echo '
  • ' . - (isset($row->value->name) && $row->value->name != "" ? $row->value->name : "NO NAME " . $row->value->abn) - . '
  • '; - } -} -include_footer(); + include_footer(); + ?> --- a/import.php +++ b/import.php @@ -1,6 +1,6 @@ create_db('disclosr-agencies'); } catch (SetteeRestClientException $e) { @@ -9,10 +9,10 @@ $db = $server->get_db('disclosr-agencies'); createAgencyDesignDoc(); $conn = new PDO("pgsql:dbname=contractDashboard;user=postgres;password=snmc;host=localhost"); -$namesQ = 'select agency.abn, string_agg("agencyName",\',\') as names from agency inner join agency_nametoabn on agency.abn::text = agency_nametoabn.abn group by agency.abn;'; +$namesQ = 'select agency.abn, string_agg("agencyName",\'|\') as names from agency inner join agency_nametoabn on agency.abn::text = agency_nametoabn.abn group by agency.abn;'; $abntonames = Array(); foreach ($conn->query($namesQ) as $row) { - $abntonames[$row['abn']] = explode(",", $row['names']); + $abntonames[$row['abn']] = explode("|", $row['names']); } $result = $conn->query("select * from agency"); while ($agency = $result->fetch(PDO::FETCH_ASSOC)) { --- /dev/null +++ b/include/common.inc.php @@ -1,1 +1,39 @@ + array. + $Class = (array) $Class; + + # Iterate through the former properties looking for any stdClass properties. + # Recursively apply (array). + foreach ($Class as $key => $value) { + if (is_object($value) && get_class($value) === 'stdClass') { + $Class[$key] = object_to_array($value); + } + } + return $Class; +} + +# Convert an Array to stdClass. http://www.php.net/manual/en/language.types.object.php#102735 + +function array_to_object(array $array) { + # Iterate through our array looking for array values. + # If found recurvisely call itself. + foreach ($array as $key => $value) { + if (is_array($value)) { + $array[$key] = array_to_object($value); + } + } + + # Typecast to (object) will automatically convert array -> stdClass + return (object) $array; +} +?> + + + --- /dev/null +++ b/include/couchdb.inc.php @@ -1,1 +1,27 @@ +_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); };"; + $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); +} +require ('couchdb/settee/src/settee.php'); + +$server = new SetteeServer('http://127.0.0.1:5984'); + +function setteErrorHandler($e) { + echo $e->getMessage() . "
    " . PHP_EOL; +} + +?> + --- /dev/null +++ b/include/template.inc.php @@ -1,1 +1,75 @@ + + + + + + + + + + + + + + + Disclosr + + + + + + + + + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + + + --- /dev/null +++ b/schemas/agency.json.php @@ -1,1 +1,19 @@ + "Representation of government agency and online transparency measures", + "type" => "object", + "properties" => Array( + "name" => Array("type" => "string", "required" => true, "description" => "Agency Name, most recent and broadest"), + "othernames" => Array("type" => "array", "required" => true, "description" => "Agency Names", + "items" => Array("type" => "string")), + ), + /*"org":{"type":"object", + "properties":{ + "organizationName":{"type":"string"}, + "organizationUnit":{"type":"string"}}, + } + }*/ +); +?> + --- /dev/null +++ b/schemas/schemas.inc.php @@ -1,1 +1,5 @@ +