apples.* fixes
apples.* fixes


Former-commit-id: b167947a39fb1f09f7573db22f525d6fdb943ec4

--- /dev/null
+++ b/admin/conflicts.php
@@ -1,1 +1,48 @@
+<?php
 
+include_once('../include/common.inc.php');
+include_header();
+                require_once '../lib/php-diff/lib/Diff.php';
+                require_once '../lib/php-diff/lib/Diff/Renderer/Html/SideBySide.php';
+
+$db = $server->get_db('disclosr-agencies');
+
+try {
+    $rows = $db->get_view("app", "getConflicts", null, true)->rows;
+    //print_r($rows);
+    foreach ($rows as $row) {
+echo "<h2>".$row->id."</h2>";
+$request = Requests::get($serverAddr."disclosr-agencies/".$row->id);
+$origSort = object_to_array(json_decode($request->body));
+ksort($origSort);
+    $origDoc = explode(",",json_encode($origSort));
+	foreach($row->value as $conflictRev) {
+$conflictURL = $serverAddr."disclosr-agencies/".$row->id."?rev=".$conflictRev;
+$request = Requests::get($conflictURL);
+$conflictSort = object_to_array(json_decode($request->body));
+ksort($conflictSort);
+    $conflictDoc = explode(",",json_encode($conflictSort));
+echo "curl -X DELETE ".$conflictURL."<br>".PHP_EOL;
+                // Options for generating the diff
+                $options = array(
+                        //'ignoreWhitespace' => true,
+                        //'ignoreCase' => true,
+                );
+
+                // Initialize the diff class
+                $diff = new Diff($conflictDoc, $origDoc, $options);
+
+                // Generate a side by side diff
+                $renderer = new Diff_Renderer_Html_SideBySide;
+                echo $diff->Render($renderer);
+}
+die();
+	
+    }
+} catch (SetteeRestClientException $e) {
+    setteErrorHandler($e);
+}
+
+include_footer();
+?>
+

--- a/bubbletree.php
+++ b/bubbletree.php
@@ -1,23 +1,23 @@
 
 <!DOCTYPE html> 
 <html xmlns="http://www.w3.org/1999/xhtml"> 
-<head> 
-	<meta charset="UTF-8"/> 
-	<title>Minimal BubbleTree Demo</title> 
-	<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script> 
-	<script type="text/javascript" src="javascripts/bubbletree/lib/jquery.history.js"></script> 
-	<script type="text/javascript" src="javascripts/bubbletree/lib/raphael.js"></script> 
-	<script type="text/javascript" src="javascripts/bubbletree/lib/vis4.js"></script> 
-	<script type="text/javascript" src="javascripts/bubbletree/lib/Tween.js"></script> 
-	<script type="text/javascript" src="javascripts/bubbletree/build/bubbletree.js"></script> 
-	<link rel="stylesheet" type="text/css" href="javascripts/bubbletree/build/bubbletree.css" /> 
-	<script type="text/javascript" src="javascripts/bubbletree/styles/cofog.js"></script> 
-	
-	
-	<script type="text/javascript"> 
+    <head> 
+        <meta charset="UTF-8"/> 
+        <title>Minimal BubbleTree Demo</title> 
+        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script> 
+        <script type="text/javascript" src="javascripts/bubbletree/lib/jquery.history.js"></script> 
+        <script type="text/javascript" src="javascripts/bubbletree/lib/raphael.js"></script> 
+        <script type="text/javascript" src="javascripts/bubbletree/lib/vis4.js"></script> 
+        <script type="text/javascript" src="javascripts/bubbletree/lib/Tween.js"></script> 
+        <script type="text/javascript" src="javascripts/bubbletree/build/bubbletree.js"></script> 
+        <link rel="stylesheet" type="text/css" href="javascripts/bubbletree/build/bubbletree.css" /> 
+        <script type="text/javascript" src="javascripts/bubbletree/styles/cofog.js"></script> 
+
+
+        <script type="text/javascript"> 
        
-		$(function() {
-		<?php
+            $(function() {
+<?php
 include_once('include/common.inc.php');
 
 include("lib/Color.php");
@@ -29,7 +29,7 @@
 try {
     $rows = $db->get_view("app", "byDeptStateName", null, true)->rows;
     foreach ($rows as $row) {
-       	$portfolios[trim(str_replace(Array("Department of","Department","the","'","`"),"",$row->key))] = $row->value;
+        $portfolios[trim(str_replace(Array("Department of", "Department", "the", "'", "`"), "", $row->key))] = $row->value;
     }
 } catch (SetteeRestClientException $e) {
     setteErrorHandler($e);
@@ -40,74 +40,87 @@
     $rows = $db->get_view("app", "byCanonicalName", null, true)->rows;
 //print_r($rows);
     foreach ($rows as $row) {
-	$employees = 0;
-	$portfolioid = 0;
-	if (isset($row->value->employees)) $employees = $row->value->employees;
-	if (isset($row->value->statistics->employees)) {
-$agencyEmployeesArray = object_to_array($row->value->statistics->employees);
-if (isset($agencyEmployeesArray["2010-2011"]["value"])) {
- $employees = $agencyEmployeesArray["2010-2011"]["value"];
-} else {
-    // get last year that is recorded? throw error?
-    continue;
-}
-}
-if (!($employees > 0)) $employees =0;
-	if (isset($row->value->parentOrg)) $portfolioid = $row->value->parentOrg;
-	if (isset($row->value->orgType) && $row->value->orgType == "FMA-DepartmentOfState") $portfolioid = $row->id;
-       	$agencies[$portfolioid][$row->value->name] = $employees;
+        $employees = 0;
+        $portfolioid = 0;
+        if (isset($row->value->employees)) {
+            $employees = $row->value->employees;
+        }
+        if (isset($row->value->statistics->employees)) {
+            $agencyEmployeesArray = object_to_array($row->value->statistics->employees);
+            if (isset($agencyEmployeesArray["2010-2011"]["value"])) {
+                $employees = $agencyEmployeesArray["2010-2011"]["value"];
+            } else {
+                // bailout for agencies that are closed for business
+                continue;
+            }
+        }
+        if (!($employees > 0)) {
+            $employees = 0;
+        }
+        if (isset($row->value->parentOrg)) {
+            $portfolioid = $row->value->parentOrg;
+        }
+        if (isset($row->value->orgType) && $row->value->orgType == "FMA-DepartmentOfState") {
+            $portfolioid = $row->id;
+        }
+        $agencies[$portfolioid][$row->value->name] = $employees;
     }
 } catch (SetteeRestClientException $e) {
     setteErrorHandler($e);
 }
 //print_r($portfolios);
 //print_r($agencies);
-$i = 0;
+
+// http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
+$golden_ratio_conjugate = 0.618033988749895;
+$h = 0.00+rand(0,10)/10; # use random start value
 foreach ($portfolios as $portfolioName => $portfolioID) {
-$i++;
-$portfolioColor = $color->hsv2hex(Array($i/10, .7, abs(($i*(1/10))-.5) + .5));
-	$subnodes = Array();
-	$portfolioEmployees = 0;
-	foreach ($agencies[$portfolioID] as $agencyName => $agencyEmployees) {
-		$agencyColor = $color->hsv2hex(Array($i/10, rand(1,10)/10, abs(($i*(1/10))-.5) + .5));
-		$subnodes[] = Array(
-			"label" => str_replace(Array("'","`"),"",$agencyName),
-			"amount" => $agencyEmployees,
-			"color" => "#".$agencyColor
-		);
-		$portfolioEmployees += $agencyEmployees;
-	}
-	$nodes[] = Array(
-		"label" => $portfolioName,
-		"amount" => $portfolioEmployees,
-		"color" => "#".$portfolioColor,
-		"children" => $subnodes
-	);
-	$total += $portfolioEmployees;
+  $h += $golden_ratio_conjugate;
+  
+  $h =  fmod($h,1);
+    $portfolioColor = $color->hsv2hex(Array($h, .3, .99));
+    $subnodes = Array();
+    $portfolioEmployees = 0;
+    foreach ($agencies[$portfolioID] as $agencyName => $agencyEmployees) {
+        $agencyColor = $color->hsv2hex(Array($h / 10, rand(1, 10) / 10, abs(($h * (1 / 10)) - .5) + .5));
+        $subnodes[] = Array(
+            "label" => str_replace(Array("'", "`"), "", $agencyName),
+            "amount" => $agencyEmployees,
+            //"color" => "#" . $agencyColor
+        );
+        $portfolioEmployees += $agencyEmployees;
+    }
+    $nodes[] = Array(
+        "label" => $portfolioName,
+        "amount" => $portfolioEmployees,
+        //"color" => "#" . $portfolioColor,
+        "children" => $subnodes
+    );
+    $total += $portfolioEmployees;
 }
 $data = Array(
-	"label" => "Australian Federal Government",
-	"amount" => $total,
-	"color" => "#000000",
-	"children" => $nodes
+    "label" => "Australian Federal Government",
+    "amount" => $total,
+    //"color" => "#000000",
+    "children" => $nodes
 );
 echo "var data =eval('('+'" . json_encode($data) . "'+')');";
 ?>
 
-			new BubbleTree({
-				data: data,
-				container: '.bubbletree'
-			});
+        new BubbleTree({
+            data: data,
+            container: '.bubbletree'
+        });
 		
 			
-		});
+    });
      
-	</script> 
-</head> 
-<body> 
-	<div class="bubbletree-wrapper"> 
-		<div class="bubbletree"></div> 
-	</div> 
-</body> 
+        </script> 
+    </head> 
+    <body> 
+        <div class="bubbletree-wrapper"> 
+            <div class="bubbletree"></div> 
+        </div> 
+    </body> 
 </html> 
 

--- a/getAgency.php
+++ b/getAgency.php
@@ -137,7 +137,7 @@
         }
     }
 
-    $mode = "edit";
+    $mode = "view";
     $rowArray = object_to_array($obj);
 ksort($rowArray);
     if ($mode == "edit") {

file:b/index.php (new)
--- /dev/null
+++ b/index.php
@@ -1,1 +1,9 @@
+<?php
+/* Redirect to a different page in the current directory that was requested */
+$host  = $_SERVER['HTTP_HOST'];
+$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
+$extra = 'getAgency.php';
+header("Location: http://$host$uri/$extra");
+exit;
+?>