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