More MySQL purging
[contractdashboard.git] / lib / common.inc.php
blob:a/lib/common.inc.php -> blob:b/lib/common.inc.php
<?php <?php
date_default_timezone_set("Australia/ACT"); date_default_timezone_set("Australia/ACT");
   
error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL ^ E_NOTICE);
   
   
$conn = new PDO("pgsql:dbname=contractDashboard;user=postgres;password=snmc;host=localhost"); include('db.inc.php');
   
if (!$conn) { define('ROOT', pathinfo(__FILE__, PATHINFO_DIRNAME));
die("A database error occurred.\n"); if (strstr($_SERVER['PHP_SELF'], "labs/") || strstr($_SERVER['PHP_SELF'], "admin/") || strstr($_SERVER['PHP_SELF'], "heuristics/")) {
} $basePath = "../";
  }
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /*require ROOT . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'openid.php';
function databaseError($errMsg) require(ROOT.'/solarium/vendor/autoload.php');
{ require(ROOT.'/solarium/library/Solarium/Autoloader.php');
if ($errMsg[2] != "") { Solarium\Autoloader::register();
die(print_r($errMsg,true)); // check solarium version available
} //echo 'Solarium library version: ' . Solarium\Client::VERSION . ' - ';
} $config = array(
  'endpoint' => array(
function ucsmart($str) { 'localhost' => array(
$shortWords = Array("The","Pty","Ltd","Inc","Red","Oil","A","An","And","At","For","In" 'host' => '127.0.0.1',
,"Of","On","Or","The","To","With"); 'port' => 8983,
$strArray = explode(" ",preg_replace("/(?<=(?<!:|’s)\W) 'path' => '/solr/contracts/',
(A|An|And|At|For|In|Of|On|Or|The|To|With) )
(?=\W)/e", 'strtolower("$1")', ucwords(strtolower($str)))); )
foreach($strArray as &$word) { );
if (strlen($word) <= 4 && !in_array($word,$shortWords)) $word = strtoupper($word); // create a client instance
} $solr_client = new Solarium\Client($config);
return implode(" ",$strArray);  
}  
  $openid = new LightOpenID($_SERVER['HTTP_HOST']);
function percent($num_amount, $num_total) { // you have to open the session to be able to modify or remove it
$count1 = $num_amount / $num_total; session_start();
$count2 = $count1 * 100; function login() {
$count = number_format($count2, 2); global $openid;
return $count; if (!$openid->mode) {
} $openid->required = array('contact/email');
function array_sum_all($a) { $openid->identity = 'https://www.google.com/accounts/o8/id';
if(!is_array($a)) return $a; header('Location: ' . $openid->authUrl());
foreach($a as $key=>$value) }
$totale += array_sum_all($value); }
return $totale;  
} function auth() {
// magic query modifiers global $openid;
$agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING); if ($_SESSION['authed'] == true) {
if ($agency != "") $agencyQ = "agencyName = '" . $agency . "' AND "; return true;
  }
$supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING);  
if ($supplier != "") { if ($openid->mode) {
$supplierParts = explode("-", $supplier); $attr = $openid->getAttributes();
$supplierName = "%".$supplierParts[1]."%"; if ($attr['contact/email'] != 'maxious@gmail.com') {
$supplierABN = $supplierParts[0]; die('Access Denied');
if ($supplierParts[0] > 0) $supplierQ = ' "supplierABN" = :supplierABN AND '; } else {
else $supplierQ = ' "supplierName" LIKE :supplierName AND '; $_SESSION['authed'] = true;
} }
  } else {
$startYear = 2007; login();
$year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT); }
if ($year != "") $yearQ = "YEAR(publishDate) = " . $year . " AND "; }*/
   
$standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010'; // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$start =0.0; function databaseError($errMsg) {
  if ($errMsg[2] != "") {
function include_header($title) { echo '<div class="alert-message error">';
global $start; die(print_r($errMsg, true));
?> echo "</div>";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" }
"http://www.w3.org/TR/html4/strict.dtd"> }
<html>  
<head> function ucsmart($str) {
<title>Contract Dashboard - <?php echo $title; ?></title> $shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In"
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/reset-fonts-grids/reset-fonts-grids.css"> , "Of", "On", "Or", "The", "To", "With");
  $strArray = explode(" ", preg_replace_callback("/(?<=(?<!:|’s)\W)
<script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script> (A|An|And|At|For|In|Of|On|Or|The|To|With)
<link rel="stylesheet" href="autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" /> (?=\W)/",
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> function($matches) { return strtolower($matches[1]); } , ucwords(strtolower($str))));
<script type="text/javascript"> foreach ($strArray as &$word) {
$(document).ready(function() if (strlen($word) <= 4 && !in_array($word, $shortWords))
{ $word = strtoupper($word);
//hide the all of the element with class msg_body }
$(".msg_body").hide(); return implode(" ", $strArray);
//toggle the componenet with class msg_body }
$(".msg_head").click(function()  
{ function percent($num_amount, $num_total) {
$(this).next(".msg_body").slideToggle(600); $count1 = $num_amount / $num_total;
}); $count2 = $count1 * 100;
}); $count = number_format($count2, 2);
</script> return $count;
  }
<style type="text/css" title="currentStyle">  
@import "media/css/demo_table.css"; function array_sum_all($a) {
</style> if (!is_array($a))
<script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script> return $a;
<script type="text/javascript" charset="utf-8"> $totale = 0;
jQuery.fn.dataTableExt.aTypes.unshift( foreach ($a as $key => $value)
function ( sData ) $totale += array_sum_all($value);
{ return $totale;
var sValidChars = "0123456789.-,"; }
var Char;  
  function show_stats($stats) {
/* Check the numeric part */ echo "<br/>";
for ( i=1 ; i<sData.length ; i++ ) if ($stats['consultancy'] > 0) {
{ echo "<b>Consultancies:</b> {$stats['consultancy']} contracts, ".percent($stats['consultancy'],$stats['total']);
Char = sData.charAt(i); echo "%<br/>";
if (sValidChars.indexOf(Char) == -1) }
{ if ($stats['confidentialityContract']+$stats['confidentialityOutputs'] > 0) {
return null; $confidentialities = $stats['confidentialityContract']+$stats['confidentialityOutputs'];
} echo "<b>Confidentialities:</b> $confidentialities contracts, ".percent( $confidentialities,$stats['total'])."%";
} echo "( {$stats['confidentialityContract']} on the contract, {$stats['confidentialityOutputs']} on the outputs)";
  echo "<br/>";
/* Check prefixed by currency */ }
if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) echo "<b>Procurement methods:</b> ";
{ if ($stats['open'] > 0) {
return 'currency'; echo "Open {$stats['open']} contracts, ".percent($stats['open'],$stats['total']);
} echo "%, ";
return null; }
} if ($stats['openSON'] > 0) {
); echo "Open via SON {$stats['openSON']} contracts, ".percent($stats['openSON'],$stats['total']);
jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) { echo "%, ";
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */ }
var x = a == "-" ? 0 : a.replace( /,/g, "" ); if ($stats['prequalified'] > 0) {
var y = b == "-" ? 0 : b.replace( /,/g, "" ); echo "Prequalified {$stats['prequalified']} contracts, ".percent($stats['prequalified'],$stats['total']);
  echo "%, ";
/* Remove the currency sign */ }
x = x.substring( 1 ); if ($stats['limited'] > 0) {
y = y.substring( 1 ); echo "limited {$stats['limited']} contracts, ".percent($stats['limited'],$stats['total']);
  echo "%, ";
/* Parse and return */ }
x = parseFloat( x ); }
y = parseFloat( y );  
return x - y; // magic query modifiers
}; $agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING);
  if ($agency != "")
jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) { $agencyQ = "agencyName = '" . $agency . "' AND ";
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */  
var x = a == "-" ? 0 : a.replace( /,/g, "" ); $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING);
var y = b == "-" ? 0 : b.replace( /,/g, "" ); if ($supplier != "") {
  $supplierParts = explode("-", $supplier);
/* Remove the currency sign */ $supplierName = "%" . $supplierParts[1] . "%";
x = x.substring( 1 ); $supplierABN = $supplierParts[0];
y = y.substring( 1 ); if ($supplierParts[0] > 0)
  $supplierQ = ' "supplierABN" = :supplierABN AND ';
/* Parse and return */ else
x = parseFloat( x ); $supplierQ = ' "supplierName" ILIKE :supplierName AND ';
y = parseFloat( y ); }
return y - x;  
}; $startYear = 2007;
$(document).ready(function() { $year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT);
$('table').dataTable(); if ($year != "") {
} ); $yearQ = 'extract(year from "contractStart") = ' . $year . " AND ";
</script> }
<link type="text/css" rel="stylesheet" href="style.css"> $standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010';
</head> $start = 0.0;
<body><div id="doc3" class="yui-t4">  
<div id="hd"> function local_url() {
<h1> contract dashboard</h1> return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/";
</div> }
<div id="sitenav">  
<a href="displayAgency.php">agencies</a> function include_header($title) {
<a href="displaySupplier.php">suppliers</a> global $start;
<a href="displayCategory.php">product/service categories</a> ?>
<a href="displayCalendar.php">time periods</a> <!DOCTYPE html>
| metrics | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" version="XHTML+RDFa 1.1"
<a href="displayProcurementMethod.php">procurement method</a> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
<a href="displayConfidentialities.php">contractual confidentiality</a> xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
<a href="displayConsultancies.php">consultancies</a> xmlns:gr="http://purl.org/goodrelations/v1#"
<a href="displayAmendments.php">amendments</a> xmlns:dc="http://purl.org/dc/terms/"
<a href="displayMap.php">postcodes</a> xmlns:pc="http://purl.org/procurement#"
<div id="search"><form method="post" action="search.php" class="asholder"> xmlns:unspsc="http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#"
<label for="searchKeyword">search</label> xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
<input type="text" id="searchKeyword" name="searchKeyword" value="" style="width:150px" /> xmlns:pcdt="http://purl.org/procurement/public-contracts-datatypes#"
<input type="hidden" id="searchID" name="searchID" value=""/><input type="submit" value="submit" /> prefix="rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
</form></div> rdfs: http://www.w3.org/2000/01/rdf-schema#
<script type="text/javascript"> gr: http://purl.org/goodrelations/v1#
  dcterms: http://purl.org/dc/terms/
var options_xml = { pc: http://purl.org/procurement/public-contracts#
script: function (input) { return "search_autosuggest.php?input="+input; }, cpv: http://purl.org/weso/pscs/cpv/2008/resource/
varname:"input", unspsc: http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#
callback: function (obj) { document.getElementById('searchID').value = obj.id; } v: http://www.w3.org/2006/vcard/ns#
}; payment: http://reference.data.gov.uk/def/payment#
var as_xml = new bsn.AutoSuggest('searchKeyword', options_xml); br: http://purl.org/business-register#
</script> xsd: http://www.w3.org/2001/XMLSchema#
  pcdt: http://purl.org/procurement/public-contracts-datatypes#">
</div> <head>
<div id="bd" role="main"> <title><?php echo $title; ?> - Contract Dashboard</title>
<div id="yui-main"> <meta name="viewport" content="width=device-width, initial-scale=1">
<div class="yui-b"><div class="yui-g"> <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<?php <link rel="stylesheet" type="text/css" href="bootstrap-responsive.css">
$start = (float) array_sum(explode(' ',microtime())); <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
} <!--[if lt IE 9]>
  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
function include_footer() { <![endif]-->
global $start; <script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script>
$end = (float) array_sum(explode(' ',microtime())); <link rel="stylesheet" href="autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" />
?> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</div> <script type="text/javascript">
</div> $(document).ready(function()
</div> {
<div class="yui-b"> //hide the all of the element with class msg_body
Filter by:<ul> $(".msg_body").hide();
<li>year //toggle the componenet with class msg_body
<ul><li>2008</li> $(".msg_head").click(function()
</ul> {
</li> $(this).next(".msg_body").slideToggle(600);
</ul> <br> </div> </div> });
  });
<?php </script>
echo '<div id="ft"><p>'."Processing time: ". sprintf("%.4f", ($end-$start))." seconds".'</p></div>';  
echo '</div> </body> </html>'; <style type="text/css" title="currentStyle">
} @import "media/css/demo_table.css";
include ("graphs.inc.php"); </style>
?> <script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script>
  <script type="text/javascript" language="javascript" src="lib/bootstrap-dropdown.js"></script>
  <script type="text/javascript" charset="utf-8">
  jQuery.fn.dataTableExt.aTypes.unshift(
  function ( sData )
  {
  var sValidChars = "0123456789.-,";
  var Char;
   
  /* Check the numeric part */
  for ( i=1 ; i<sData.length ; i++ )
  {
  Char = sData.charAt(i);
  if (sValidChars.indexOf(Char) == -1)
  {
  return null;
  }
  }
   
  /* Check prefixed by currency */
  if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' )
  {
  return 'currency';
  }
  return null;
  }
  );
  jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) {
  /* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
  var x = a == "-" ? 0 : a.replace( /,/g, "" );
  var y = b == "-" ? 0 : b.replace( /,/g, "" );
   
  /* Remove the currency sign */
  x = x.substring( 1 );
  y = y.substring( 1 );
   
  /* Parse and return */
  x = parseFloat( x );
  y = parseFloat( y );
  return x - y;
  };
   
  jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) {
  /* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
  var x = a == "-" ? 0 : a.replace( /,/g, "" );
  var y = b == "-" ? 0 : b.replace( /,/g, "" );
   
  /* Remove the currency sign */
  x = x.substring( 1 );
  y = y.substring( 1 );
   
  /* Parse and return */
  x = parseFloat( x );
  y = parseFloat( y );
  return y - x;
  };
  $(document).ready(function() {
  $('table').dataTable();
  } );
  </script>
  <link type="text/css" rel="stylesheet" href="style.css">
  </head>
  <body>
  <div class="navbar">
  <div class="navbar-inner">
  <div class="container-fluid">
  <a class="brand" href="#">contract dashboard</a>
  <ul class="nav">
  <li><a href="displayAgency.php">agencies</a></li>
  <li><a href="displaySupplier.php">suppliers</a></li>
  <li><a href="displaySON.php">standing offers</a></li>
  <li><a href="displayCategory.php">categories</a></li>
  <li><a href="displayCalendar.php">dates</a></li>
  <li><a href="displayProcurementMethod.php">tenderm</a></li>
  <li><a href="displayConfidentialities.php">confidentiality</a></li>
  <li><a href="displayConsultancies.php">consultancies</a></li>
  <li><a href="displayAmendments.php">amendments</a></li>
  <li><a href="displayMap.php">geo</a></li>
  </ul>
   
   
  <form method="get" action="search.php" class="pull-right">
  <input type="text" id="searchKeyword" name="searchKeyword" value="" placeholder="Search" />
  <input type="hidden" id="searchID" name="searchID" value=""/>
  </form>
   
  </div>