Include textual subcategories in openspending/csv export
Include textual subcategories in openspending/csv export

file:b/.gitignore (new)
  /admin/neo4jimporter/target/
  /admin/neo4jimporter/.settings/
  /nbproject/private/
<?php <?php
error_reporting(E_ALL); error_reporting(E_ALL);
include_once("../lib/common.inc.php"); include_once("../lib/common.inc.php");
$unspscresult = $conn->prepare('select * from "UNSPSCcategories";'); $unspscresult = $conn->prepare('select * from "UNSPSCcategories";');
$unspscresult->execute(); $unspscresult->execute();
foreach ($unspscresult->fetchAll() as $row) { foreach ($unspscresult->fetchAll() as $row) {
$unspsc[$row['Title']] = $row['UNSPSC']; $unspsc[$row['Title']] = $row['UNSPSC'];
// some Australian spellings // some Australian spellings
$isiz = str_replace("iz", "is", $row['Title']); $isiz = str_replace("iz", "is", $row['Title']);
$unspsc[$isiz] = $row['UNSPSC']; $unspsc[$isiz] = $row['UNSPSC'];
$filfill = str_replace("fill", "fil", $row['Title']); $filfill = str_replace("fill", "fil", $row['Title']);
$unspsc[$filfill] = $row['UNSPSC']; $unspsc[$filfill] = $row['UNSPSC'];
$defence = str_replace("efense", "efence", $row['Title']); $defence = str_replace("efense", "efence", $row['Title']);
$unspsc[$defence] = $row['UNSPSC']; $unspsc[$defence] = $row['UNSPSC'];
$armor = str_replace("rmored", "rmoured", $row['Title']); $armor = str_replace("rmored", "rmoured", $row['Title']);
$unspsc[$armor] = $row['UNSPSC']; $unspsc[$armor] = $row['UNSPSC'];
$erre = str_replace("er", "re", $row['Title']); $erre = str_replace("er", "re", $row['Title']);
$unspsc[$erre] = $row['UNSPSC']; $unspsc[$erre] = $row['UNSPSC'];
  $tire = str_replace("ire", "yre", $row['Title']);
  $unspsc[$tire] = $row['UNSPSC'];
  $aeroplane = str_replace("airplane","aeroplane", $row['Title']);
  $unspsc[$aeroplane] = $row['UNSPSC'];
$lyslyz = str_replace("lyz", "lys", $row['Title']); $lyslyz = str_replace("lyz", "lys", $row['Title']);
$unspsc[$lyslyz] = $row['UNSPSC']; $unspsc[$lyslyz] = $row['UNSPSC'];
// some divergence from standard // some divergence from standard
$tobacco = str_replace("Food Beverage and Tobacco Products", "Food and Beverage Products", $row['Title']); $tobacco = str_replace("Food Beverage and Tobacco Products", "Food and Beverage Products", $row['Title']);
$unspsc[$tobacco] = $row['UNSPSC']; $unspsc[$tobacco] = $row['UNSPSC'];
$architect = str_replace("Building and Construction and Maintenance Services", "Architectural services", $row['Title']); $architect = str_replace("Building and Construction and Maintenance Services", "Architectural services", $row['Title']);
  $unspsc[$architect] = $row['UNSPSC'];
  $powercable = str_replace("Power cable", "Power cable installation and supply", $row['Title']);
  $unspsc[$powercable] = $row['UNSPSC'];
  $forensicIT = str_replace("Building and Construction and Maintenance Services", "Architectural services", $row['Title']);
$unspsc[$architect] = $row['UNSPSC']; $unspsc[$architect] = $row['UNSPSC'];
// some just plain wrong // some just plain wrong
$noOilRigs = str_replace("Building and Construction and Maintenance Services", "Management and provision of all facilities engineering modification and maintenance services for a site or platform", $row['Title']); $noOilRigs = str_replace("Building and Construction and Maintenance Services", "Management and provision of all facilities engineering modification and maintenance services for a site or platform", $row['Title']);
$unspsc[$noOilRigs] = $row['UNSPSC']; $unspsc[$noOilRigs] = $row['UNSPSC'];
} }
$query = 'SELECT "CNID","category","value" $query = 'SELECT "CNID","category","value"
FROM contractnotice FROM contractnotice
WHERE "categoryUNSPSC" IS NULL OR "categoryUNSPSC" = 0'; WHERE "categoryUNSPSC" IS NULL OR "categoryUNSPSC" = 0';
$emptycatresult = $conn->prepare($query); $emptycatresult = $conn->prepare($query);
$missing = Array(); $missing = Array();
$emptycatresult->execute(); $emptycatresult->execute();
foreach ($emptycatresult->fetchAll() as $record) { foreach ($emptycatresult->fetchAll() as $record) {
if (!isset($unspsc[$record['category']]) || $unspsc[$record['category']] == "") { if (!isset($unspsc[$record['category']]) || $unspsc[$record['category']] == "") {
$missing[$record['category']] = (isset($missing[$record['category']]) ? $missing[$record['category']] : 0) + $record['value']; $missing[$record['category']] = (isset($missing[$record['category']]) ? $missing[$record['category']] : 0) + $record['value'];
// echo "<br>\n Category not found for: \n"; // echo "<br>\n Category not found for: \n";
// print_r($record); // print_r($record);
} else { } else {
$result = $conn->exec('UPDATE contractnotice SET "categoryUNSPSC" = $result = $conn->exec('UPDATE contractnotice SET "categoryUNSPSC" =
\'' . $unspsc[$record['category']] . '\' where "CNID" = \'' . $record['CNID'] . '\';'); \'' . $unspsc[$record['category']] . '\' where "CNID" = \'' . $record['CNID'] . '\';');
if ($result) { if ($result) {
echo $record['CNID'] . " set to " . ($unspsc[$record['category']]) . " <br>\n"; echo $record['CNID'] . " set to " . ($unspsc[$record['category']]) . " <br>\n";
} else { } else {
echo "error<br>"; echo "error<br>";
print_r($conn->errorInfo()); print_r($conn->errorInfo());
} }
} }
} }
asort($missing, SORT_NUMERIC); asort($missing, SORT_NUMERIC);
print_r($missing); print_r($missing);
?> ?>
   
file:b/bootstrap.min.css (new)
  html,body{margin:0;padding:0;}
  h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,cite,code,del,dfn,em,img,q,s,samp,small,strike,strong,sub,sup,tt,var,dd,dl,dt,li,ol,ul,fieldset,form,label,legend,button,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;font-weight:normal;font-style:normal;font-size:100%;line-height:1;font-family:inherit;}
  table{border-collapse:collapse;border-spacing:0;}
  ol,ul{list-style:none;}
  q:before,q:after,blockquote:before,blockquote:after{content:"";}
  html{overflow-y:scroll;font-size:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;}
  a:focus{outline:thin dotted;}
  a:hover,a:active{outline:0;}
  article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block;}
  audio,canvas,video{display:inline-block;*display:inline;*zoom:1;}
  audio:not([controls]){display:none;}
  sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}
  sup{top:-0.5em;}
  sub{bottom:-0.25em;}
  img{border:0;-ms-interpolation-mode:bicubic;}
  button,input,select,textarea{font-size:100%;margin:0;vertical-align:baseline;*vertical-align:middle;}
  button,input{line-height:normal;*overflow:visible;}
  button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}
  button,input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;-webkit-appearance:button;}
  input[type="search"]{-webkit-appearance:textfield;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;}
  input[type="search"]::-webkit-search-decoration{-webkit-appearance:none;}
  textarea{overflow:auto;vertical-align:top;}
  body{background-color:#ffffff;margin:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;font-weight:normal;line-height:18px;color:#404040;}
  .container{width:940px;margin-left:auto;margin-right:auto;zoom:1;}.container:before,.container:after{display:table;content:"";zoom:1;}
  .container:after{clear:both;}
  .container-fluid{position:relative;min-width:940px;padding-left:20px;padding-right:20px;zoom:1;}.container-fluid:before,.container-fluid:after{display:table;content:"";zoom:1;}
  .container-fluid:after{clear:both;}
  .container-fluid>.sidebar{position:absolute;top:0;left:20px;width:220px;}
  .container-fluid>.content{margin-left:240px;}
  a{color:#0069d6;text-decoration:none;line-height:inherit;font-weight:inherit;}a:hover{color:#00438a;text-decoration:underline;}
  .pull-right{float:right;}
  .pull-left{float:left;}
  .hide{display:none;}
  .show{display:block;}
  .row{zoom:1;margin-left:-20px;}.row:before,.row:after{display:table;content:"";zoom:1;}
  .row:after{clear:both;}
  .row>[class*="span"]{display:inline;float:left;margin-left:20px;}
  .span1{width:40px;}
  .span2{width:100px;}
  .span3{width:160px;}
  .span4{width:220px;}
  .span5{width:280px;}
  .span6{width:340px;}
  .span7{width:400px;}
  .span8{width:460px;}
  .span9{width:520px;}
  .span10{width:580px;}
  .span11{width:640px;}
  .span12{width:700px;}
  .span13{width:760px;}
  .span14{width:820px;}
  .span15{width:880px;}
  .span16{width:940px;}
  .span17{width:1000px;}
  .span18{width:1060px;}
  .span19{width:1120px;}
  .span20{width:1180px;}
  .span21{width:1240px;}
  .span22{width:1300px;}
  .span23{width:1360px;}
  .span24{width:1420px;}
  .row>.offset1{margin-left:80px;}
  .row>.offset2{margin-left:140px;}
  .row>.offset3{margin-left:200px;}
  .row>.offset4{margin-left:260px;}
  .row>.offset5{margin-left:320px;}
  .row>.offset6{margin-left:380px;}
  .row>.offset7{margin-left:440px;}
  .row>.offset8{margin-left:500px;}
  .row>.offset9{margin-left:560px;}
  .row>.offset10{margin-left:620px;}
  .row>.offset11{margin-left:680px;}
  .row>.offset12{margin-left:740px;}
  .span-one-third{width:300px;}
  .span-two-thirds{width:620px;}
  .row>.offset-one-third{margin-left:340px;}
  .row>.offset-two-thirds{margin-left:660px;}
  p{font-size:13px;font-weight:normal;line-height:18px;margin-bottom:9px;}p small{font-size:11px;color:#bfbfbf;}
  h1,h2,h3,h4,h5,h6{font-weight:bold;color:#404040;}h1 small,h2 small,h3 small,h4 small,h5 small,h6 small{color:#bfbfbf;}
  h1{margin-bottom:18px;font-size:30px;line-height:36px;}h1 small{font-size:18px;}
  h2{font-size:24px;line-height:36px;}h2 small{font-size:14px;}
  h3,h4,h5,h6{line-height:36px;}
  h3{font-size:18px;}h3 small{font-size:14px;}
  h4{font-size:16px;}h4 small{font-size:12px;}
  h5{font-size:14px;}
  h6{font-size:13px;color:#bfbfbf;text-transform:uppercase;}
  ul,ol{margin:0 0 18px 25px;}
  ul ul,ul ol,ol ol,ol ul{margin-bottom:0;}
  ul{list-style:disc;}
  ol{list-style:decimal;}
  li{line-height:18px;color:#808080;}
  ul.unstyled{list-style:none;margin-left:0;}
  dl{margin-bottom:18px;}dl dt,dl dd{line-height:18px;}
  dl dt{font-weight:bold;}
  dl dd{margin-left:9px;}
  hr{margin:20px 0 19px;border:0;border-bottom:1px solid #eee;}
  strong{font-style:inherit;font-weight:bold;}
  em{font-style:italic;font-weight:inherit;line-height:inherit;}
  .muted{color:#bfbfbf;}