amon key
[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 = "../";
  }
define('ROOT', pathinfo(__FILE__, PATHINFO_DIRNAME)); /*require ROOT . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'openid.php';
if (strstr($_SERVER['PHP_SELF'], "labs/")) { require(ROOT.'/solarium/vendor/autoload.php');
$basePath = "../"; require(ROOT.'/solarium/library/Solarium/Autoloader.php');
} Solarium\Autoloader::register();
require $basePath."lib/amon-php/amon.php"; // check solarium version available
Amon::config(array('address'=> 'http://127.0.0.1:2464', //echo 'Solarium library version: ' . Solarium\Client::VERSION . ' - ';
'protocol' => 'http', $config = array(
'secret_key' => "JBcSUdFOi5lK0vCjLjbHDpQamcBnRA4iV7QLaTADeDQ")); 'endpoint' => array(
Amon::setup_exception_handler(); 'localhost' => array(
  'host' => '127.0.0.1',
require ROOT . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'openid.php'; 'port' => 8983,
$openid = new LightOpenID($_SERVER['HTTP_HOST']); 'path' => '/solr/contracts/',
  )
function login() { )
global $openid; );
if (!$openid->mode) { // create a client instance
$openid->required = array('contact/email'); $solr_client = new Solarium\Client($config);
$openid->identity = 'https://www.google.com/accounts/o8/id';  
header('Location: ' . $openid->authUrl());  
} $openid = new LightOpenID($_SERVER['HTTP_HOST']);
} // you have to open the session to be able to modify or remove it
  session_start();
function auth() { function login() {
global $openid; global $openid;
if ($_SESSION['authed'] == true) { if (!$openid->mode) {
return true; $openid->required = array('contact/email');
} $openid->identity = 'https://www.google.com/accounts/o8/id';
  header('Location: ' . $openid->authUrl());
if ($openid->mode) { }
$attr = $openid->getAttributes(); }
if ($attr['contact/email'] != 'maxious@gmail.com') {  
die('Access Denied'); function auth() {
} else { global $openid;
$_SESSION['authed'] = true; if ($_SESSION['authed'] == true) {
} return true;
} else { }
login();  
} if ($openid->mode) {
} $attr = $openid->getAttributes();
  if ($attr['contact/email'] != 'maxious@gmail.com') {
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); die('Access Denied');
function databaseError($errMsg) { } else {
if ($errMsg[2] != "") { $_SESSION['authed'] = true;
echo '<div class="alert-message error">'; }
Amon::log(print_r($errMsg, true), array('error')); } else {
die(print_r($errMsg, true)); login();
echo "</div>"; }
} }*/
}  
  // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
function ucsmart($str) { function databaseError($errMsg) {
$shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In" if ($errMsg[2] != "") {
, "Of", "On", "Or", "The", "To", "With"); echo '<div class="alert-message error">';
$strArray = explode(" ", preg_replace("/(?<=(?<!:|’s)\W) die(print_r($errMsg, true));
(A|An|And|At|For|In|Of|On|Or|The|To|With) echo "</div>";
(?=\W)/e", 'strtolower("$1")', ucwords(strtolower($str)))); }
foreach ($strArray as &$word) { }
if (strlen($word) <= 4 && !in_array($word, $shortWords)) function cleanseName($input) {
$word = strtoupper($word);  
} return trim(join(" ",array_filter(explode(" ",strtolower($input)), function($v, $k) {
return implode(" ", $strArray); $cleanseNamesCorp = Array(
} "ltd",
  "limited",
function percent($num_amount, $num_total) { "australia",
$count1 = $num_amount / $num_total; "australian",
$count2 = $count1 * 100; "australasia",
$count = number_format($count2, 2); "(aus)",
return $count; "(aust)",
} "(australia)",
  "the",
function array_sum_all($a) { "pty",
if (!is_array($a)) "contractors",
return $a; "p/l",
foreach ($a as $key => $value) "inc.",
$totale += array_sum_all($value); "inc",
return $totale; "incorporated"
} );
  return !in_array($v,$cleanseNamesCorp) ;
// magic query modifiers }, ARRAY_FILTER_USE_BOTH)));
$agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING); }
if ($agency != "") function ucsmart($str) {
$agencyQ = "agencyName = '" . $agency . "' AND "; $shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In"
  , "Of", "On", "Or", "The", "To", "With", "Use", "No", "Yes");
$supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING); $strArray = explode(" ", preg_replace_callback("/(?<=(?<!:|’s)\W)
if ($supplier != "") { (A|An|And|At|For|In|Of|On|Or|The|To|With)
$supplierParts = explode("-", $supplier); (?=\W)/",
$supplierName = "%" . $supplierParts[1] . "%"; function($matches) { return strtolower($matches[1]); } , ucwords(strtolower($str))));
$supplierABN = $supplierParts[0]; foreach ($strArray as &$word) {
if ($supplierParts[0] > 0) if (strlen($word) <= 4 && !in_array($word, $shortWords))
$supplierQ = ' "supplierABN" = :supplierABN AND '; $word = strtoupper($word);
else }
$supplierQ = ' "supplierName" LIKE :supplierName AND '; return implode(" ", $strArray);
} }
   
$startYear = 2007; function percent($num_amount, $num_total) {
$year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT); $count1 = $num_amount / $num_total;
if ($year != "") { $count2 = $count1 * 100;
$yearQ = "YEAR(publishDate) = " . $year . " AND "; $count = number_format($count2, 2);
} return $count;
$standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010'; }
$start = 0.0;  
  function array_sum_all($a) {
function local_url() { if (!is_array($a))
return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/"; return $a;
} $totale = 0;
  foreach ($a as $key => $value)
function include_header($title) { $totale += array_sum_all($value);
global $start; return $totale;
?> }
<!DOCTYPE html>  
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" version="XHTML+RDFa 1.1" function show_stats($stats) {
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" setlocale(LC_MONETARY, 'en_US');
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" $value = number_format(doubleval($stats['total_value']) , 2);
xmlns:gr="http://purl.org/goodrelations/v1#" echo "<br/> {$stats['total']} contracts, total value $$value <br/>";
xmlns:dc="http://purl.org/dc/terms/" if ($stats['consultancy'] > 0) {
xmlns:pc="http://purl.org/procurement#" echo "<b>Consultancies:</b> {$stats['consultancy']} contracts, ".percent($stats['consultancy'],$stats['total']);
xmlns:unspsc="http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#" echo "%<br/>";
xmlns:xsd="http://www.w3.org/2001/XMLSchema#" }
xmlns:pcdt="http://purl.org/procurement/public-contracts-datatypes#" if ($stats['confidentialityContract']+$stats['confidentialityOutputs'] > 0) {
prefix="rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# $confidentialities = $stats['confidentialityContract']+$stats['confidentialityOutputs'];
rdfs: http://www.w3.org/2000/01/rdf-schema# echo "<b>Confidentialities:</b> $confidentialities contracts, ".percent( $confidentialities,$stats['total'])."%";
gr: http://purl.org/goodrelations/v1# echo "( {$stats['confidentialityContract']} on the contract, {$stats['confidentialityOutputs']} on the outputs)";
dcterms: http://purl.org/dc/terms/ echo "<br/>";
pc: http://purl.org/procurement/public-contracts# }
cpv: http://purl.org/weso/pscs/cpv/2008/resource/ echo "<b>Procurement methods:</b> ";
unspsc: http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml# if ($stats['open'] > 0) {
v: http://www.w3.org/2006/vcard/ns# echo "Open {$stats['open']} contracts, ".percent($stats['open'],$stats['total']);
payment: http://reference.data.gov.uk/def/payment# echo "%, ";
br: http://purl.org/business-register# }
xsd: http://www.w3.org/2001/XMLSchema# if ($stats['openSON'] > 0) {
pcdt: http://purl.org/procurement/public-contracts-datatypes#"> echo "Open via SON {$stats['openSON']} contracts, ".percent($stats['openSON'],$stats['total']);
<head> echo "%, ";
<title><?php echo $title; ?> - Contract Dashboard</title> }
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"> if ($stats['prequalified'] > 0) {
<link rel="stylesheet" type="text/css" href="bootstrap-responsive.css"> echo "Prequalified {$stats['prequalified']} contracts, ".percent($stats['prequalified'],$stats['total']);
<!-- Le HTML5 shim, for IE6-8 support of HTML elements --> echo "%, ";
<!--[if lt IE 9]> }
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> if ($stats['limited'] > 0) {
<![endif]--> echo "limited {$stats['limited']} contracts, ".percent($stats['limited'],$stats['total']);
<script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script> echo "%, ";
<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> }
<script type="text/javascript">  
$(document).ready(function() // magic query modifiers
{ $agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING);
//hide the all of the element with class msg_body if ($agency != "")
$(".msg_body").hide(); $agencyQ = "agencyName = '" . $agency . "' AND ";
//toggle the componenet with class msg_body  
$(".msg_head").click(function() $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING);
{ if ($supplier != "") {
$(this).next(".msg_body").slideToggle(600); if ($supplier[0] !== '-') {
}); $supplierParts = explode("-", $supplier);
});  
</script> $supplierABN = array_shift($supplierParts);
  $supplierName = "%" . implode('-',$supplierParts) . "%";
<style type="text/css" title="currentStyle">  
@import "media/css/demo_table.css"; $supplierQ = ' "supplierABN" = :supplierABN AND ';
</style> } else {
<script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script> $supplierName = "%" . substr($supplier,1) . "%";
<script type="text/javascript" language="javascript" src="lib/bootstrap-dropdown.js"></script> $supplierQ = ' "supplierName" ILIKE :supplierName AND ';
<script type="text/javascript" charset="utf-8"> }
jQuery.fn.dataTableExt.aTypes.unshift( }
function ( sData )  
{ $startYear = 2007;
var sValidChars = "0123456789.-,"; $year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT);
var Char; if ($year != "") {
  $yearQ = 'extract(year from "contractStart") = ' . $year . " AND ";
/* Check the numeric part */ }
for ( i=1 ; i<sData.length ; i++ ) $standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010';
{ $start = 0.0;
Char = sData.charAt(i);  
if (sValidChars.indexOf(Char) == -1) function local_url() {
{ return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/";
return null; }
}  
} function include_header($title) {
  global $start;
/* Check prefixed by currency */ ?>
if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) <!DOCTYPE html>
{ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" version="XHTML+RDFa 1.1"
return 'currency'; xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
} xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
return null; xmlns:gr="http://purl.org/goodrelations/v1#"
} xmlns:dc="http://purl.org/dc/terms/"
); xmlns:pc="http://purl.org/procurement#"
jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) { xmlns:unspsc="http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#"
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */ xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
var x = a == "-" ? 0 : a.replace( /,/g, "" ); xmlns:pcdt="http://purl.org/procurement/public-contracts-datatypes#"
var y = b == "-" ? 0 : b.replace( /,/g, "" ); prefix="rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
  rdfs: http://www.w3.org/2000/01/rdf-schema#
/* Remove the currency sign */ gr: http://purl.org/goodrelations/v1#
x = x.substring( 1 ); dcterms: http://purl.org/dc/terms/
y = y.substring( 1 ); pc: http://purl.org/procurement/public-contracts#
  cpv: http://purl.org/weso/pscs/cpv/2008/resource/
/* Parse and return */ unspsc: http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#
x = parseFloat( x ); v: http://www.w3.org/2006/vcard/ns#
y = parseFloat( y ); payment: http://reference.data.gov.uk/def/payment#
return x - y; br: http://purl.org/business-register#
}; xsd: http://www.w3.org/2001/XMLSchema#
  pcdt: http://purl.org/procurement/public-contracts-datatypes#">
jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) { <head>
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */ <title><?php echo $title; ?> - Contract Dashboard</title>
var x = a == "-" ? 0 : a.replace( /,/g, "" ); <meta name="viewport" content="width=device-width, initial-scale=1">
var y = b == "-" ? 0 : b.replace( /,/g, "" ); <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="bootstrap-responsive.css">
/* Remove the currency sign */ <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
x = x.substring( 1 ); <!--[if lt IE 9]>
y = y.substring( 1 ); <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  <![endif]-->
/* Parse and return */ <script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script>
x = parseFloat( x ); <link rel="stylesheet" href="autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" />
y = parseFloat( y ); <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
return y - x; <script type="text/javascript">
}; $(document).ready(function()
$(document).ready(function() { {
$('table').dataTable(); //hide the all of the element with class msg_body
} ); $(".msg_body").hide();
</script> //toggle the componenet with class msg_body
<link type="text/css" rel="stylesheet" href="style.css"> $(".msg_head").click(function()
</head> {
<body> $(this).next(".msg_body").slideToggle(600);
<div class="navbar"> });
<div class="navbar-inner"> });
<div class="container-fluid"> </script>
<a class="brand" href="#">contract dashboard</a>  
<ul class="nav"> <style type="text/css" title="currentStyle">
<li><a href="displayAgency.php">agencies</a></li> @import "media/css/demo_table.css";
<li><a href="displaySupplier.php">suppliers</a></li> </style>
<li><a href="displayCategory.php">categories</a></li> <script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script>
<li><a href="displayCalendar.php">time periods</a></li> <script type="text/javascript" language="javascript" src="lib/bootstrap-dropdown.js"></script>
<!-- <li class="dropdown"> <script type="text/javascript" charset="utf-8">
<a href="#" class="dropdown-toggle">metrics</a> jQuery.fn.dataTableExt.aTypes.unshift(
<ul class="dropdown-menu">--> function ( sData )
<li><a href="displayProcurementMethod.php">tenderm</a></li> {
<li><a href="displayConfidentialities.php">confidentiality</a></li> var sValidChars = "0123456789.-,";
<li><a href="displayConsultancies.php">consultancies</a></li> var Char;
<li><a href="displayAmendments.php">amendments</a></li>  
<li><a href="displayMap.php">geo</a></li> /* Check the numeric part */
</ul> for ( i=1 ; i<sData.length ; i++ )
  {
  Char = sData.charAt(i);
<form method="post" action="search.php" class="pull-right"> if (sValidChars.indexOf(Char) == -1)
<input type="text" id="searchKeyword" name="searchKeyword" value="" placeholder="Search" /> {
<input type="hidden" id="searchID" name="searchID" value=""/> return null;
</form> }
  }
</div>  
</div><!-- /topbar-inner --> /* Check prefixed by currency */
</div><!-- /topbar --> if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' )
</div><!-- /topbar-wrapper --> {
<script type="text/javascript"> return 'currency';
  }
var options_xml = { return null;
script: function (input) { return "search_autosuggest.php?input="+input; }, }
varname:"input", );
callback: function (obj) { document.getElementById('searchID').value = obj.id; } 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 as_xml = new bsn.AutoSuggest('searchKeyword', options_xml); var x = a == "-" ? 0 : a.replace( /,/g, "" );
</script> var y = b == "-" ? 0 : b.replace( /,/g, "" );
<div class="container-fluid">  
<div class="row-fluid"> /* Remove the currency sign */
<div class="span3"> x = x.substring( 1 );
<div class="well sidebar-nav"> y = y.substring( 1 );
<li class="nav-header">Filter by:</li>  
<li>2008</li> /* Parse and return */
</div> x = parseFloat( x );