Add google webmaster tools and fix site map
[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();
  // check solarium version available
require ROOT . DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'openid.php'; //echo 'Solarium library version: ' . Solarium\Client::VERSION . ' - ';
$openid = new LightOpenID($_SERVER['HTTP_HOST']); $config = array(
  'endpoint' => array(
function login() { 'localhost' => array(
global $openid; 'host' => '127.0.0.1',
if (!$openid->mode) { 'port' => 8983,
$openid->required = array('contact/email'); 'path' => '/solr/contracts/',
$openid->identity = 'https://www.google.com/accounts/o8/id'; )
header('Location: ' . $openid->authUrl()); )
} );
} // create a client instance
  $solr_client = new Solarium\Client($config);
function auth() {  
global $openid;  
if ($_SESSION['authed'] == true) { $openid = new LightOpenID($_SERVER['HTTP_HOST']);
return true; // you have to open the session to be able to modify or remove it
} session_start();
  function login() {
if ($openid->mode) { global $openid;
$attr = $openid->getAttributes(); if (!$openid->mode) {
if ($attr['contact/email'] != 'maxious@gmail.com') { $openid->required = array('contact/email');
die('Access Denied'); $openid->identity = 'https://www.google.com/accounts/o8/id';
} else { header('Location: ' . $openid->authUrl());
$_SESSION['authed'] = true; }
} }
} else {  
login(); function auth() {
} global $openid;
} if ($_SESSION['authed'] == true) {
  return true;
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
function databaseError($errMsg) {  
if ($errMsg[2] != "") { if ($openid->mode) {
echo '<div class="alert-message error">'; $attr = $openid->getAttributes();
die(print_r($errMsg, true)); if ($attr['contact/email'] != 'maxious@gmail.com') {
echo "</div>"; die('Access Denied');
} } else {
} $_SESSION['authed'] = true;
  }
function ucsmart($str) { } else {
$shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In" login();
, "Of", "On", "Or", "The", "To", "With"); }
$strArray = explode(" ", preg_replace("/(?<=(?<!:|’s)\W) }*/
(A|An|And|At|For|In|Of|On|Or|The|To|With)  
(?=\W)/e", 'strtolower("$1")', ucwords(strtolower($str)))); // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
foreach ($strArray as &$word) { function databaseError($errMsg) {
if (strlen($word) <= 4 && !in_array($word, $shortWords)) if ($errMsg[2] != "") {
$word = strtoupper($word); echo '<div class="alert-message error">';
} die(print_r($errMsg, true));
return implode(" ", $strArray); echo "</div>";
} }
  }
function percent($num_amount, $num_total) {  
$count1 = $num_amount / $num_total; function ucsmart($str) {
$count2 = $count1 * 100; $shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In"
$count = number_format($count2, 2); , "Of", "On", "Or", "The", "To", "With");
return $count; $strArray = explode(" ", preg_replace_callback("/(?<=(?<!:|’s)\W)
} (A|An|And|At|For|In|Of|On|Or|The|To|With)
  (?=\W)/",
function array_sum_all($a) { function($matches) { return strtolower($matches[1]); } , ucwords(strtolower($str))));
if (!is_array($a)) foreach ($strArray as &$word) {
return $a; if (strlen($word) <= 4 && !in_array($word, $shortWords))
foreach ($a as $key => $value) $word = strtoupper($word);
$totale += array_sum_all($value); }
return $totale; return implode(" ", $strArray);
} }
   
// magic query modifiers function percent($num_amount, $num_total) {
$agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING); $count1 = $num_amount / $num_total;
if ($agency != "") $count2 = $count1 * 100;
$agencyQ = "agencyName = '" . $agency . "' AND "; $count = number_format($count2, 2);
  return $count;
$supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING); }
if ($supplier != "") {  
$supplierParts = explode("-", $supplier); function array_sum_all($a) {
$supplierName = "%" . $supplierParts[1] . "%"; if (!is_array($a))
$supplierABN = $supplierParts[0]; return $a;
if ($supplierParts[0] > 0) $totale = 0;
$supplierQ = ' "supplierABN" = :supplierABN AND '; foreach ($a as $key => $value)
else $totale += array_sum_all($value);
$supplierQ = ' "supplierName" LIKE :supplierName AND '; return $totale;
} }
   
$startYear = 2007; function show_stats($stats) {
$year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT); echo "<br/>";
if ($year != "") if ($stats['consultancy'] > 0) {
$yearQ = "YEAR(publishDate) = " . $year . " AND "; echo "<b>Consultancies:</b> {$stats['consultancy']} contracts, ".percent($stats['consultancy'],$stats['total']);
  echo "%<br/>";
$standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010'; }
$start = 0.0; if ($stats['confidentialityContract']+$stats['confidentialityOutputs'] > 0) {
function local_url() { $confidentialities = $stats['confidentialityContract']+$stats['confidentialityOutputs'];
return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/"; echo "<b>Confidentialities:</b> $confidentialities contracts, ".percent( $confidentialities,$stats['total'])."%";
} echo "( {$stats['confidentialityContract']} on the contract, {$stats['confidentialityOutputs']} on the outputs)";
function include_header($title) { echo "<br/>";
global $start; }
?> echo "<b>Procurement methods:</b> ";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" if ($stats['open'] > 0) {
"http://www.w3.org/TR/html4/strict.dtd"> echo "Open {$stats['open']} contracts, ".percent($stats['open'],$stats['total']);
<html> echo "%, ";
<head> }
<title>Contract Dashboard - <?php echo $title; ?></title> if ($stats['openSON'] > 0) {
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"> echo "Open via SON {$stats['openSON']} contracts, ".percent($stats['openSON'],$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['prequalified'] > 0) {
<![endif]--> echo "Prequalified {$stats['prequalified']} contracts, ".percent($stats['prequalified'],$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> if ($stats['limited'] > 0) {
<script type="text/javascript"> echo "limited {$stats['limited']} contracts, ".percent($stats['limited'],$stats['total']);
$(document).ready(function() echo "%, ";
{ }
//hide the all of the element with class msg_body }
$(".msg_body").hide();  
//toggle the componenet with class msg_body // magic query modifiers
$(".msg_head").click(function() $agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING);
{ if ($agency != "")
$(this).next(".msg_body").slideToggle(600); $agencyQ = "agencyName = '" . $agency . "' AND ";
});  
}); $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING);
</script> if ($supplier != "") {
  $supplierParts = explode("-", $supplier);
<style type="text/css" title="currentStyle"> $supplierName = "%" . $supplierParts[1] . "%";
@import "media/css/demo_table.css"; $supplierABN = $supplierParts[0];
</style> if ($supplierParts[0] > 0)
<script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script> $supplierQ = ' "supplierABN" = :supplierABN AND ';
<script type="text/javascript" language="javascript" src="lib/bootstrap-dropdown.js"></script> else
<script type="text/javascript" charset="utf-8"> $supplierQ = ' "supplierName" ILIKE :supplierName AND ';
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="topbar"> });
<div class="topbar-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++ )
</li>--> {
</ul> Char = sData.charAt(i);
  if (sValidChars.indexOf(Char) == -1)
  {
<form method="post" action="search.php" class="pull-right"> return null;
<input type="text" id="searchKeyword" name="searchKeyword" value="" placeholder="Search" /> }
<input type="hidden" id="searchID" name="searchID" value=""/> }
</form>  
  /* Check prefixed by currency */
</div> if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' )
</div><!-- /topbar-inner --> {
</div><!-- /topbar --> return 'currency';
</div><!-- /topbar-wrapper --> }
<script type="text/javascript"> return null;
  }
var options_xml = { );
script: function (input) { return "search_autosuggest.php?input="+input; }, jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) {
varname:"input", /* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
callback: function (obj) { document.getElementById('searchID').value = obj.id; } var x = a == "-" ? 0 : a.replace( /,/g, "" );
}; var y = b == "-" ? 0 : b.replace( /,/g, "" );
var as_xml = new bsn.AutoSuggest('searchKeyword', options_xml);  
</script> /* Remove the currency sign */
<div class="container-fluid"> x = x.substring( 1 );
<div class="sidebar"> y = y.substring( 1 );
<div class="well">  
Filter by:<li> /* Parse and return */
<li>year x = parseFloat( x );
<li><li>2008</li> y = parseFloat( y );
</li> return x - y;
</li> };
</li> <br>  
</div> </div> jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) {
<div class="content"> /* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
<?php var x = a == "-" ? 0 : a.replace( /,/g, "" );
$start = (float) array_sum(explode(' ', microtime())); var y = b == "-" ? 0 : b.replace( /,/g, "" );
}  
  /* Remove the currency sign */
function include_footer() { x = x.substring( 1 );
global $start; y = y.substring( 1 );
$end = (float) array_sum(explode(' ', microtime()));  
  /* Parse and return */
echo ' <footer>' . "Processing time: " . sprintf("%.4f", ($end - $start)) . " seconds" . ' <footer>'; x = parseFloat( x );
echo '</div> </div></body> </html>'; y = parseFloat( y );
} return y - x;
  };
include ("graphs.inc.php"); $(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 hr