Beginnings of visual conflict resolution
Beginnings of visual conflict resolution


Former-commit-id: f8dfd63919aab30a6b99f6861e80a36b55f5af04

[submodule "couchdb/couchdb-lucene"] [submodule "couchdb/couchdb-lucene"]
path = couchdb/couchdb-lucene path = couchdb/couchdb-lucene
url = https://github.com/rnewson/couchdb-lucene.git url = https://github.com/rnewson/couchdb-lucene.git
[submodule "couchdb/settee"] [submodule "couchdb/settee"]
path = couchdb/settee path = couchdb/settee
url = https://github.com/inadarei/settee.git url = https://github.com/inadarei/settee.git
[submodule "lib/springy"] [submodule "lib/springy"]
path = lib/springy path = lib/springy
url = https://github.com/dhotson/springy.git url = https://github.com/dhotson/springy.git
  [submodule "lib/php-diff"]
  path = lib/php-diff
  url = https://github.com/chrisboulton/php-diff.git
   
<?php <?php
   
require_once 'include/common.inc.php'; require_once '../include/common.inc.php';
try { try {
$server->create_db('disclosr-agencies'); $server->create_db('disclosr-agencies');
} catch (SetteeRestClientException $e) { } catch (SetteeRestClientException $e) {
setteErrorHandler($e); setteErrorHandler($e);
} }
$db = $server->get_db('disclosr-agencies'); $db = $server->get_db('disclosr-agencies');
createAgencyDesignDoc(); createAgencyDesignDoc();
$conn = new PDO("pgsql:dbname=contractDashboard;user=postgres;password=snmc;host=localhost"); $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(); $abntonames = Array();
foreach ($conn->query($namesQ) as $row) { foreach ($conn->query($namesQ) as $row) {
$abntonames[$row['abn']] = explode("|", $row['names']); $abntonames[$row['abn']] = explode("|", $row['names']);
} }
$result = $conn->query("select * from agency"); $result = $conn->query("select * from agency");
while ($agency = $result->fetch(PDO::FETCH_ASSOC)) { while ($agency = $result->fetch(PDO::FETCH_ASSOC)) {
$agency['_id'] = md5($agency['abn']); $agency['_id'] = md5($agency['abn']);
$agency['otherNames'] = $abntonames[$agency['abn']]; $agency['otherNames'] = $abntonames[$agency['abn']];
if (sizeof($abntonames[$agency['abn']]) == 1) if (sizeof($abntonames[$agency['abn']]) == 1)
$agency['name'] = $abntonames[$agency['abn']][0]; $agency['name'] = $abntonames[$agency['abn']][0];
$agency["lastScraped"] = "1/1/1970"; $agency["lastScraped"] = "1/1/1970";
$agency["scrapeDepth"] = 1; $agency["scrapeDepth"] = 1;
try { try {
$doc = $db->save($agency); $doc = $db->save($agency);
//print_r($doc); //print_r($doc);
echo $agency['abn'] . " imported \n<br>"; echo $agency['abn'] . " imported \n<br>";
} catch (SetteeRestClientException $e) { } catch (SetteeRestClientException $e) {
setteErrorHandler($e); setteErrorHandler($e);
} }
} }
?> ?>
   
  <?php
 
  include_once('../include/common.inc.php');
  include_header();
  // Include the diff class
  echo '<STYLE TYPE="text/css">
  <!--
  @import url(../lib/php-diff/example/styles.css);
  -->
  </STYLE>
  ';
  require_once dirname(__FILE__) . '/../lib/php-diff/lib/Diff.php';
  // Generate a side by side diff
  require_once dirname(__FILE__) . '/../lib/php-diff/lib/Diff/Renderer/Html/SideBySide.php';
  $renderer = new Diff_Renderer_Html_SideBySide;
 
 
 
  $db = $server->get_db('disclosr-agencies');
  $docs = Array();
  try {
  $rows = $db->get_view("app", "getConflicts")->rows;
  //print_r($rows);
  foreach ($rows as $row) {
  echo '<h2>' . $row->id . '</h2>';
  echo "Comparing " . $row->value[0] . " and " . $row->value[1];
  $docA = explode(",", json_encode($db->get($row->id . "?rev=" . $row->value[0])));
  $docB = explode(",", json_encode($db->get($row->id . "?rev=" . $row->value[1])));
  // Options for generating the diff
  $options = array(
  //'ignoreWhitespace' => true,
  //'ignoreCase' => true,
  );
 
  // Initialize the diff class
  $diff = new Diff($docA, $docB, $options);
  echo $diff->Render($renderer);
  }
  } catch (SetteeRestClientException $e) {
  setteErrorHandler($e);
  }
  include_footer();
  ?>
<?php <?php
   
include_once('include/common.inc.php'); include_once('../include/common.inc.php');
include_header(); include_header();
   
$db = $server->get_db('disclosr-agencies'); $db = $server->get_db('disclosr-agencies');
$docs = Array(); $docs = Array();
try { try {
$rows = $db->get_view("app", "byABN")->rows; $rows = $db->get_view("app", "byABN")->rows;
//print_r($rows); //print_r($rows);
foreach ($rows as $row) { foreach ($rows as $row) {
$docs["a" . $row->key] = $row->value; $docs["a" . $row->key] = $row->value;
} }
} catch (SetteeRestClientException $e) { } catch (SetteeRestClientException $e) {
setteErrorHandler($e); setteErrorHandler($e);
} }
//print_r($docs); //print_r($docs);
$row = 1; $row = 1;
if (($handle = fopen("cacfma.csv", "r")) !== FALSE) { if (($handle = fopen("cacfma.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$row++; $row++;
echo $data[0] . " " . str_replace("?", "", $data[1]) . "<br />\n"; echo $data[0] . " " . str_replace("?", "", $data[1]) . "<br />\n";
$name = $data[0]; $name = $data[0];
$abn = trim(str_replace("?", "", $data[1])); $abn = trim(str_replace("?", "", $data[1]));
$aabn = "a".$abn; $aabn = "a".$abn;
if (isset($docs[$aabn])) { if (isset($docs[$aabn])) {
echo "Existing agency ABN detected<br>"; echo "Existing agency ABN detected<br>";
if (!in_array($name, object_to_array($docs[$aabn]->otherNames)) && $name != $docs[$aabn]->name) { if (!in_array($name, object_to_array($docs[$aabn]->otherNames)) && $name != $docs[$aabn]->name) {
$docs[$aabn]->otherNames[] = $name; $docs[$aabn]->otherNames[] = $name;
try { try {
$docs[$aabn] = $db->save($docs[$aabn]); $docs[$aabn] = $db->save($docs[$aabn]);
//print_r($doc); //print_r($doc);
echo $abn . " additional names imported \n<br>"; echo $abn . " additional names imported \n<br>";
} catch (SetteeRestClientException $e) { } catch (SetteeRestClientException $e) {
setteErrorHandler($e); setteErrorHandler($e);
} }
} }
} else { } else {
echo "New agency ABN detected<br>"; echo "New agency ABN detected<br>";
$agency['_id'] = md5($aabn); $agency['_id'] = md5($aabn);
$agency['name'] = $name; $agency['name'] = $name;
$agency["abn"] = $abn; $agency["abn"] = $abn;
try { try {
$doc = $db->save($agency); $doc = $db->save($agency);
print_r($doc); print_r($doc);
echo $abn . " imported \n<br>"; echo $abn . " imported \n<br>";
} catch (SetteeRestClientException $e) { } catch (SetteeRestClientException $e) {
setteErrorHandler($e); setteErrorHandler($e);
} }
} }
echo "<hr>"; echo "<hr>";
} }
fclose($handle); fclose($handle);
} }
include_footer(); include_footer();
?> ?>
<?php <?php
   
date_default_timezone_set("Australia/Sydney"); date_default_timezone_set("Australia/Sydney");
   
$basePath = ""; $basePath = "";
if (strstr($_SERVER['PHP_SELF'], "alaveteli/") if (strstr($_SERVER['PHP_SELF'], "alaveteli/")
|| strstr($_SERVER['PHP_SELF'], "myway/") || strstr($_SERVER['PHP_SELF'], "admin/")
|| strstr($_SERVER['PHP_SELF'], "lib/") || strstr($_SERVER['PHP_SELF'], "lib/")
|| strstr($_SERVER['PHP_SELF'], "geo/") || strstr($_SERVER['PHP_SELF'], "include/"))
|| strstr($_SERVER['PHP_SELF'], "include/")  
|| strstr($_SERVER['PHP_SELF'], "servicealerts/"))  
$basePath = "../"; $basePath = "../";
   
include_once ('couchdb.inc.php'); include_once ('couchdb.inc.php');
include_once ('template.inc.php'); include_once ('template.inc.php');
   
# Convert a stdClass to an Array. http://www.php.net/manual/en/language.types.object.php#102735 # Convert a stdClass to an Array. http://www.php.net/manual/en/language.types.object.php#102735
   
function object_to_array(stdClass $Class) { function object_to_array(stdClass $Class) {
# Typecast to (array) automatically converts stdClass -> array. # Typecast to (array) automatically converts stdClass -> array.
$Class = (array) $Class; $Class = (array) $Class;
   
# Iterate through the former properties looking for any stdClass properties. # Iterate through the former properties looking for any stdClass properties.
# Recursively apply (array). # Recursively apply (array).
foreach ($Class as $key => $value) { foreach ($Class as $key => $value) {
if (is_object($value) && get_class($value) === 'stdClass') { if (is_object($value) && get_class($value) === 'stdClass') {
$Class[$key] = object_to_array($value); $Class[$key] = object_to_array($value);
} }
} }
return $Class; return $Class;
} }
   
# Convert an Array to stdClass. http://www.php.net/manual/en/language.types.object.php#102735 # Convert an Array to stdClass. http://www.php.net/manual/en/language.types.object.php#102735
   
function array_to_object(array $array) { function array_to_object(array $array) {
# Iterate through our array looking for array values. # Iterate through our array looking for array values.
# If found recurvisely call itself. # If found recurvisely call itself.
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
if (is_array($value)) { if (is_array($value)) {
$array[$key] = array_to_object($value); $array[$key] = array_to_object($value);
} }
} }
   
# Typecast to (object) will automatically convert array -> stdClass # Typecast to (object) will automatically convert array -> stdClass
return (object) $array; return (object) $array;
} }
   
function dept_to_portfolio($deptName) { function dept_to_portfolio($deptName) {
return trim(str_replace("Department of", "", str_replace("Department of the", "Department of", $deptName))); return trim(str_replace("Department of", "", str_replace("Department of the", "Department of", $deptName)));
} }
function phrase_to_tag ($phrase) { function phrase_to_tag ($phrase) {
return str_replace(" ","_",str_replace(",","",strtolower($phrase))); return str_replace(" ","_",str_replace(",","",strtolower($phrase)));
} }
function GetDomain($url) function GetDomain($url)
{ {
$nowww = ereg_replace('www\.','',$url); $nowww = ereg_replace('www\.','',$url);
$domain = parse_url($nowww); $domain = parse_url($nowww);
if(!empty($domain["host"])) if(!empty($domain["host"]))
{ {
return $domain["host"]; return $domain["host"];
} else } else
{ {
return $domain["path"]; return $domain["path"];
} }
} }
   
?> ?>
   
   
   
<?php <?php
   
function include_header() { function include_header() {
  global $basePath;
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
   
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ --> <!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]--> <!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
   
<!-- Set the viewport width to device width for mobile --> <!-- Set the viewport width to device width for mobile -->
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
   
<title>Disclosr</title> <title>Disclosr</title>
   
<!-- Included CSS Files --> <!-- Included CSS Files -->
<link rel="stylesheet" href="stylesheets/foundation.css"> <link rel="stylesheet" href="<?php echo $basePath?>stylesheets/foundation.css">
<link rel="stylesheet" href="stylesheets/app.css"> <link rel="stylesheet" href="<?php echo $basePath?>stylesheets/app.css">
   
<!--[if lt IE 9]> <!--[if lt IE 9]>
<link rel="stylesheet" href="stylesheets/ie.css"> <link rel="stylesheet" href="<?php echo $basePath?>stylesheets/ie.css">
<![endif]--> <![endif]-->
   
   
<!-- IE Fix for HTML5 Tags --> <!-- IE Fix for HTML5 Tags -->
<!--[if lt IE 9]> <!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]--> <![endif]-->
   
</head> </head>
<body> <body>
   
<!-- navBar --> <!-- navBar -->
<div id="navbar" class="container"> <div id="navbar" class="container">
<div class="row"> <div class="row">
<div class="four columns"> <div class="four columns">
<h1><a href="/">Disclosr</a></h1> <h1><a href="/">Disclosr</a></h1>
</div> </div>
<div class="eight columns hide-on-phones"> <div class="eight columns hide-on-phones">
<strong class="right"> <strong class="right">
<a href="getAgency.php">Agencies</a> <a href="getAgency.php">Agencies</a>
<a href="about.php">About/FAQ</a> <a href="about.php">About/FAQ</a>
</strong> </strong>
</div> </div>
</div> </div>
</div> </div>
<!-- /navBar --> <!-- /navBar -->
   
<!-- container --> <!-- container -->
<div class="container"> <div class="container">
<?php } <?php }
   
function include_footer() { ?> function include_footer() { ?>
</div> </div>
<!-- container --> <!-- container -->
   
   
   
   
<!-- Included JS Files --> <!-- Included JS Files -->
<script src="javascripts/foundation.js"></script> <script src="<?php echo $basePath?>javascripts/foundation.js"></script>
<script src="javascripts/app.js"></script> <script src="<?php echo $basePath?>javascripts/app.js"></script>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
   
</body> </body>
</html> </html>
   
<?php } <?php }
   
?> ?>
   
directory:b/lib/php-diff (new)