--- a/getAgency.php +++ b/getAgency.php @@ -4,6 +4,7 @@ include_header(); function displayValue($key, $value, $mode) { + global $db; if ($mode == "view") { if (is_array($value)) { echo "$key
    "; @@ -30,8 +31,17 @@ } else { if (strpos($key, "_") === 0) { echo""; - } if (strpos($key, "has") === 0) { - echo ""; + + } else if ($key == "parentOrg") { + echo ""; + } else if (strpos($key, "has") === 0) { + echo ""; } else { echo ""; if ((strpos($key,"URL") > 0 || $key == 'website')&& $value != "") { @@ -52,8 +62,13 @@ foreach ($defaultFields as $defaultField) { if (!isset($row[$defaultField])) { if ($schemas['agency']['properties'][$defaultField]['type'] == "string") { + if (strpos($defaultField, "has") === 0) { + $row[$defaultField] = "false"; + } else { $row[$defaultField] = ""; + } + } if ($schemas['agency']['properties'][$defaultField]['type'] == "array") { @@ -75,13 +90,21 @@ //print_r($row); if (sizeof($_POST) > 0) { //print_r($_POST); + foreach ($_POST as $postkey => $postvalue) { + if ($postvalue == "") { + unset($_POST[$postkey]); + } + if (is_array($postvalue) && count($postvalue) == 1 && $postvalue[0] == "") { + unset($_POST[$postkey]); + } + } if (isset($_POST['_id']) && $db->get_rev($_POST['_id']) == $_POST['_rev']) { echo "Edited version was latest version, continue saving"; $newdoc = $_POST; $newdoc['metadata']['lastModified'] = time(); $row = $db->save($newdoc); } else { - echo "ALERT doc revised by someone else while editing."; + echo "ALERT doc revised by someone else while editing. Document not saved."; } }