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))  
$word = strtoupper($word); function ucsmart($str) {
} $shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In"
return implode(" ", $strArray); , "Of", "On", "Or", "The", "To", "With");
} $strArray = explode(" ", preg_replace_callback("/(?<=(?<!:|’s)\W)
  (A|An|And|At|For|In|Of|On|Or|The|To|With)
function percent($num_amount, $num_total) { (?=\W)/",
$count1 = $num_amount / $num_total; function($matches) { return strtolower($matches[1]); } , ucwords(strtolower($str))));
$count2 = $count1 * 100; foreach ($strArray as &$word) {
$count = number_format($count2, 2); if (strlen($word) <= 4 && !in_array($word, $shortWords))
return $count; $word = strtoupper($word);
} }
  return implode(" ", $strArray);
function array_sum_all($a) { }
if (!is_array($a))  
return $a; function percent($num_amount, $num_total) {
foreach ($a as $key => $value) $count1 = $num_amount / $num_total;
$totale += array_sum_all($value); $count2 = $count1 * 100;
return $totale; $count = number_format($count2, 2);
} return $count;
  }
// magic query modifiers  
$agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING); function array_sum_all($a) {
if ($agency != "") if (!is_array($a))
$agencyQ = "agencyName = '" . $agency . "' AND "; return $a;
  $totale = 0;
$supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING); foreach ($a as $key => $value)
if ($supplier != "") { $totale += array_sum_all($value);
$supplierParts = explode("-", $supplier); return $totale;
$supplierName = "%" . $supplierParts[1] . "%"; }
$supplierABN = $supplierParts[0];  
if ($supplierParts[0] > 0) function show_stats($stats) {
$supplierQ = ' "supplierABN" = :supplierABN AND '; echo "<br/>";
else if ($stats['consultancy'] > 0) {
$supplierQ = ' "supplierName" LIKE :supplierName AND '; echo "<b>Consultancies:</b> {$stats['consultancy']} contracts, ".percent($stats['consultancy'],$stats['total']);
} echo "%<br/>";
  }
$startYear = 2007; if ($stats['confidentialityContract']+$stats['confidentialityOutputs'] > 0) {
$year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT); $confidentialities = $stats['confidentialityContract']+$stats['confidentialityOutputs'];
if ($year != "") { echo "<b>Confidentialities:</b> $confidentialities contracts, ".percent( $confidentialities,$stats['total'])."%";
$yearQ = "YEAR(publishDate) = " . $year . " AND "; echo "( {$stats['confidentialityContract']} on the contract, {$stats['confidentialityOutputs']} on the outputs)";
} echo "<br/>";
$standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010'; }
$start = 0.0; echo "<b>Procurement methods:</b> ";
  if ($stats['open'] > 0) {
function local_url() { echo "Open {$stats['open']} contracts, ".percent($stats['open'],$stats['total']);
return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/"; echo "%, ";
} }
  if ($stats['openSON'] > 0) {
function include_header($title) { echo "Open via SON {$stats['openSON']} contracts, ".percent($stats['openSON'],$stats['total']);
global $start; echo "%, ";
?> }
<!DOCTYPE html> if ($stats['prequalified'] > 0) {
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" version="XHTML+RDFa 1.1" echo "Prequalified {$stats['prequalified']} contracts, ".percent($stats['prequalified'],$stats['total']);
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" echo "%, ";
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" }
xmlns:gr="http://purl.org/goodrelations/v1#" if ($stats['limited'] > 0) {
xmlns:dc="http://purl.org/dc/terms/" echo "limited {$stats['limited']} contracts, ".percent($stats['limited'],$stats['total']);
xmlns:pc="http://purl.org/procurement#" echo "%, ";
xmlns:unspsc="http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#" }
xmlns:xsd="http://www.w3.org/2001/XMLSchema#" }
xmlns:pcdt="http://purl.org/procurement/public-contracts-datatypes#"  
prefix="rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# // magic query modifiers
rdfs: http://www.w3.org/2000/01/rdf-schema# $agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING);
gr: http://purl.org/goodrelations/v1# if ($agency != "")
dcterms: http://purl.org/dc/terms/ $agencyQ = "agencyName = '" . $agency . "' AND ";
pc: http://purl.org/procurement/public-contracts#  
cpv: http://purl.org/weso/pscs/cpv/2008/resource/ $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING);
unspsc: http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml# if ($supplier != "") {
v: http://www.w3.org/2006/vcard/ns# $supplierParts = explode("-", $supplier);
payment: http://reference.data.gov.uk/def/payment# $supplierName = "%" . $supplierParts[1] . "%";
br: http://purl.org/business-register# $supplierABN = $supplierParts[0];
xsd: http://www.w3.org/2001/XMLSchema# if ($supplierParts[0] > 0)
pcdt: http://purl.org/procurement/public-contracts-datatypes#"> $supplierQ = ' "supplierABN" = :supplierABN AND ';
<head> else
<title><?php echo $title; ?> - Contract Dashboard</title> $supplierQ = ' "supplierName" ILIKE :supplierName AND ';
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"> }
<link rel="stylesheet" type="text/css" href="bootstrap-responsive.css">  
<!-- Le HTML5 shim, for IE6-8 support of HTML elements --> $startYear = 2007;
<!--[if lt IE 9]> $year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT);
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> if ($year != "") {
<![endif]--> $yearQ = 'extract(year from "contractStart") = ' . $year . " AND ";
<script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script> }
<link rel="stylesheet" href="autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" /> $standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010';
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> $start = 0.0;
<script type="text/javascript">  
$(document).ready(function() function local_url() {
{ return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/";
//hide the all of the element with class msg_body }
$(".msg_body").hide();  
//toggle the componenet with class msg_body function include_header($title) {
$(".msg_head").click(function() global $start;
{ ?>
$(this).next(".msg_body").slideToggle(600); <!DOCTYPE html>
}); <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" version="XHTML+RDFa 1.1"
}); xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
</script> xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:gr="http://purl.org/goodrelations/v1#"
<style type="text/css" title="currentStyle"> xmlns:dc="http://purl.org/dc/terms/"
@import "media/css/demo_table.css"; xmlns:pc="http://purl.org/procurement#"
</style> xmlns:unspsc="http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#"
<script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script> xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
<script type="text/javascript" language="javascript" src="lib/bootstrap-dropdown.js"></script> xmlns:pcdt="http://purl.org/procurement/public-contracts-datatypes#"
<script type="text/javascript" charset="utf-8"> prefix="rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
jQuery.fn.dataTableExt.aTypes.unshift( rdfs: http://www.w3.org/2000/01/rdf-schema#
function ( sData ) gr: http://purl.org/goodrelations/v1#
{ dcterms: http://purl.org/dc/terms/
var sValidChars = "0123456789.-,"; pc: http://purl.org/procurement/public-contracts#
var Char; cpv: http://purl.org/weso/pscs/cpv/2008/resource/
  unspsc: http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#
/* Check the numeric part */ v: http://www.w3.org/2006/vcard/ns#
for ( i=1 ; i<sData.length ; i++ ) payment: http://reference.data.gov.uk/def/payment#
{ br: http://purl.org/business-register#
Char = sData.charAt(i); xsd: http://www.w3.org/2001/XMLSchema#
if (sValidChars.indexOf(Char) == -1) pcdt: http://purl.org/procurement/public-contracts-datatypes#">
{ <head>
return null; <title><?php echo $title; ?> - Contract Dashboard</title>
} <meta name="viewport" content="width=device-width, initial-scale=1">
} <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="bootstrap-responsive.css">
/* Check prefixed by currency */ <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) <!--[if lt IE 9]>
{ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
return 'currency'; <![endif]-->
} <script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script>
return null; <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">
jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) { $(document).ready(function()
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */ {
var x = a == "-" ? 0 : a.replace( /,/g, "" ); //hide the all of the element with class msg_body
var y = b == "-" ? 0 : b.replace( /,/g, "" ); $(".msg_body").hide();
  //toggle the componenet with class msg_body
/* Remove the currency sign */ $(".msg_head").click(function()
x = x.substring( 1 ); {
y = y.substring( 1 ); $(this).next(".msg_body").slideToggle(600);
  });
/* Parse and return */ });
x = parseFloat( x ); </script>
y = parseFloat( y );  
return x - y; <style type="text/css" title="currentStyle">
}; @import "media/css/demo_table.css";
  </style>
jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) { <script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script>
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */ <script type="text/javascript" language="javascript" src="lib/bootstrap-dropdown.js"></script>
var x = a == "-" ? 0 : a.replace( /,/g, "" ); <script type="text/javascript" charset="utf-8">
var y = b == "-" ? 0 : b.replace( /,/g, "" ); jQuery.fn.dataTableExt.aTypes.unshift(
  function ( sData )
/* Remove the currency sign */ {
x = x.substring( 1 ); var sValidChars = "0123456789.-,";
y = y.substring( 1 ); var Char;
   
/* Parse and return */ /* Check the numeric part */
x = parseFloat( x ); for ( i=1 ; i<sData.length ; i++ )
y = parseFloat( y ); {
return y - x; Char = sData.charAt(i);
}; if (sValidChars.indexOf(Char) == -1)
$(document).ready(function() { {
$('table').dataTable(); return null;
} ); }
</script> }
<link type="text/css" rel="stylesheet" href="style.css">  
</head> /* Check prefixed by currency */
<body> if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' )
<div class="navbar"> {
<div class="navbar-inner"> return 'currency';
<div class="container-fluid"> }
<a class="brand" href="#">contract dashboard</a> return null;
<ul class="nav"> }
<li><a href="displayAgency.php">agencies</a></li> );
<li><a href="displaySupplier.php">suppliers</a></li> jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) {
<li><a href="displayCategory.php">categories</a></li> /* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
<li><a href="displayCalendar.php">time periods</a></li> var x = a == "-" ? 0 : a.replace( /,/g, "" );
<!-- <li class="dropdown"> var y = b == "-" ? 0 : b.replace( /,/g, "" );
<a href="#" class="dropdown-toggle">metrics</a>  
<ul class="dropdown-menu">--> /* Remove the currency sign */
<li><a href="displayProcurementMethod.php">tenderm</a></li> x = x.substring( 1 );
<li><a href="displayConfidentialities.php">confidentiality</a></li> y = y.substring( 1 );
<li><a href="displayConsultancies.php">consultancies</a></li>  
<li><a href="displayAmendments.php">amendments</a></li> /* Parse and return */
<li><a href="displayMap.php">geo</a></li> x = parseFloat( x );
</ul> y = parseFloat( y );
  return x - y;
  };
<form method="post" action="search.php" class="pull-right">  
<input type="text" id="searchKeyword" name="searchKeyword" value="" placeholder="Search" /> jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) {
<input type="hidden" id="searchID" name="searchID" value=""/> /* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
</form> var x = a == "-" ? 0 : a.replace( /,/g, "" );
  var y = b == "-" ? 0 : b.replace( /,/g, "" );
</div>  
</div><!-- /topbar-inner --> /* Remove the currency sign */
</div><!-- /topbar --> x = x.substring( 1 );
</div><!-- /topbar-wrapper --> y = y.substring( 1 );
<script type="text/javascript">  
  /* Parse and return */
var options_xml = { x = parseFloat( x );
script: function (input) { return "search_autosuggest.php?input="+input; }, y = parseFloat( y );
varname:"input", return y - x;
callback: function (obj) { document.getElementById('searchID').value = obj.id; } };
}; $(document).ready(function() {
var as_xml = new bsn.AutoSuggest('searchKeyword', options_xml); $('table').dataTable();
</script> } );
<div class="container-fluid"> </script>
<div class="row-fluid"> <link type="text/css" rel="stylesheet" href="style.css">
<div class="span3"> </head>
<div class="well sidebar-nav"> <body>
<li class="nav-header">Filter by:</li> <div class="navbar">
<li>2008</li> <div class="navbar-inner">