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"); $conn = new PDO("pgsql:dbname=contractDashboard;user=postgres;password=snmc;host=localhost");
   
if (!$conn) { if (!$conn) {
die("A database error occurred.\n"); die("A database error occurred.\n");
} }
   
define('ROOT' , pathinfo(__FILE__, PATHINFO_DIRNAME)); define('ROOT', pathinfo(__FILE__, PATHINFO_DIRNAME));
if (strstr($_SERVER['PHP_SELF'], "labs/")) { if (strstr($_SERVER['PHP_SELF'], "labs/") || strstr($_SERVER['PHP_SELF'], "admin/") || strstr($_SERVER['PHP_SELF'], "heuristics/")) {
$basePath = "../"; $basePath = "../";
} }
  if ($_SERVER['HTTP_HOST'] != "localhost") {
require ROOT . DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'openid.php'; require $basePath."lib/amon-php/amon.php";
$openid = new LightOpenID($_SERVER['HTTP_HOST']); Amon::config(array('address'=> 'http://127.0.0.1:2464',
  'protocol' => 'http',
function login() { 'secret_key' => "JBcSUdFOi5lK0vCjLjbHDpQamcBnRA4iV7QLaTADeDQ"));
global $openid; Amon::setup_exception_handler();
if (!$openid->mode) { }
$openid->required = array('contact/email');  
$openid->identity = 'https://www.google.com/accounts/o8/id'; require ROOT . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'openid.php';
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 login() {
function auth() { global $openid;
global $openid; if (!$openid->mode) {
if ($_SESSION['authed'] == true) { $openid->required = array('contact/email');
return true; $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') { function auth() {
die('Access Denied'); global $openid;
} else { if ($_SESSION['authed'] == true) {
$_SESSION['authed'] = true; return true;
} }
} else {  
login(); if ($openid->mode) {
} $attr = $openid->getAttributes();
} if ($attr['contact/email'] != 'maxious@gmail.com') {
  die('Access Denied');
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } else {
function databaseError($errMsg) { $_SESSION['authed'] = true;
if ($errMsg[2] != "") { }
echo '<div class="alert-message 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) if ($_SERVER['HTTP_HOST'] != "localhost") Amon::log(print_r($errMsg, true).print_r($_REQUEST, true).print_r($_SERVER, true), array('error'));
(A|An|And|At|For|In|Of|On|Or|The|To|With) die(print_r($errMsg, true));
(?=\W)/e", 'strtolower("$1")', ucwords(strtolower($str)))); echo "</div>";
foreach ($strArray as &$word) { }
if (strlen($word) <= 4 && !in_array($word, $shortWords)) }
$word = strtoupper($word);  
} function ucsmart($str) {
return implode(" ", $strArray); $shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In"
} , "Of", "On", "Or", "The", "To", "With");
  $strArray = explode(" ", preg_replace("/(?<=(?<!:|’s)\W)
function percent($num_amount, $num_total) { (A|An|And|At|For|In|Of|On|Or|The|To|With)
$count1 = $num_amount / $num_total; (?=\W)/e", 'strtolower("$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;
  foreach ($a as $key => $value)
$supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING); $totale += array_sum_all($value);
if ($supplier != "") { return $totale;
$supplierParts = explode("-", $supplier); }
$supplierName = "%" . $supplierParts[1] . "%";  
$supplierABN = $supplierParts[0]; // magic query modifiers
if ($supplierParts[0] > 0) $agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING);
$supplierQ = ' "supplierABN" = :supplierABN AND '; if ($agency != "")
else $agencyQ = "agencyName = '" . $agency . "' AND ";
$supplierQ = ' "supplierName" LIKE :supplierName AND ';  
} $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING);
  if ($supplier != "") {
$startYear = 2007; $supplierParts = explode("-", $supplier);
$year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT); $supplierName = "%" . $supplierParts[1] . "%";
if ($year != "") $supplierABN = $supplierParts[0];
$yearQ = "YEAR(publishDate) = " . $year . " AND "; if ($supplierParts[0] > 0)
  $supplierQ = ' "supplierABN" = :supplierABN AND ';
$standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010'; else
$start = 0.0; $supplierQ = ' "supplierName" LIKE :supplierName AND ';
function local_url() { }
return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/";  
} $startYear = 2007;
function include_header($title) { $year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT);
global $start; if ($year != "") {
?> $yearQ = "YEAR(publishDate) = " . $year . " AND ";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" }
"http://www.w3.org/TR/html4/strict.dtd"> $standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010';
<html> $start = 0.0;
<head>  
<title>Contract Dashboard - <?php echo $title; ?></title> function local_url() {
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"> return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/";
<!-- 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_header($title) {
<![endif]--> global $start;
<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" /> <!DOCTYPE html>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" version="XHTML+RDFa 1.1"
<script type="text/javascript"> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
$(document).ready(function() xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
{ xmlns:gr="http://purl.org/goodrelations/v1#"
//hide the all of the element with class msg_body xmlns:dc="http://purl.org/dc/terms/"
$(".msg_body").hide(); xmlns:pc="http://purl.org/procurement#"
//toggle the componenet with class msg_body xmlns:unspsc="http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#"
$(".msg_head").click(function() xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
{ xmlns:pcdt="http://purl.org/procurement/public-contracts-datatypes#"
$(this).next(".msg_body").slideToggle(600); prefix="rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
}); rdfs: http://www.w3.org/2000/01/rdf-schema#
}); gr: http://purl.org/goodrelations/v1#
</script> dcterms: http://purl.org/dc/terms/
  pc: http://purl.org/procurement/public-contracts#
<style type="text/css" title="currentStyle"> cpv: http://purl.org/weso/pscs/cpv/2008/resource/
@import "media/css/demo_table.css"; unspsc: http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#
</style> v: http://www.w3.org/2006/vcard/ns#
<script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script> payment: http://reference.data.gov.uk/def/payment#
<script type="text/javascript" language="javascript" src="lib/bootstrap-dropdown.js"></script> br: http://purl.org/business-register#
<script type="text/javascript" charset="utf-8"> xsd: http://www.w3.org/2001/XMLSchema#
jQuery.fn.dataTableExt.aTypes.unshift( pcdt: http://purl.org/procurement/public-contracts-datatypes#">
function ( sData ) <head>
{ <title><?php echo $title; ?> - Contract Dashboard</title>
var sValidChars = "0123456789.-,"; <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
var Char; <link rel="stylesheet" type="text/css" href="bootstrap-responsive.css">
  <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
/* Check the numeric part */ <!--[if lt IE 9]>
for ( i=1 ; i<sData.length ; i++ ) <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
{ <![endif]-->
Char = sData.charAt(i); <script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script>
if (sValidChars.indexOf(Char) == -1) <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>
return null; <script type="text/javascript">
} $(document).ready(function()
} {
  //hide the all of the element with class msg_body
/* Check prefixed by currency */ $(".msg_body").hide();
if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) //toggle the componenet with class msg_body
{ $(".msg_head").click(function()
return 'currency'; {
} $(this).next(".msg_body").slideToggle(600);
return null; });
} });
); </script>
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) */ <style type="text/css" title="currentStyle">
var x = a == "-" ? 0 : a.replace( /,/g, "" ); @import "media/css/demo_table.css";
var y = b == "-" ? 0 : b.replace( /,/g, "" ); </style>
  <script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script>
/* Remove the currency sign */ <script type="text/javascript" language="javascript" src="lib/bootstrap-dropdown.js"></script>
x = x.substring( 1 ); <script type="text/javascript" charset="utf-8">
y = y.substring( 1 ); jQuery.fn.dataTableExt.aTypes.unshift(
  function ( sData )
/* Parse and return */ {
x = parseFloat( x ); var sValidChars = "0123456789.-,";
y = parseFloat( y ); var Char;
return x - y;  
}; /* Check the numeric part */
  for ( i=1 ; i<sData.length ; i++ )
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) */ Char = sData.charAt(i);
var x = a == "-" ? 0 : a.replace( /,/g, "" ); if (sValidChars.indexOf(Char) == -1)
var y = b == "-" ? 0 : b.replace( /,/g, "" ); {
  return null;
/* Remove the currency sign */ }
x = x.substring( 1 ); }
y = y.substring( 1 );  
  /* Check prefixed by currency */
/* Parse and return */ if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' )
x = parseFloat( x ); {
y = parseFloat( y ); return 'currency';
return y - x; }
}; return null;
$(document).ready(function() { }
$('table').dataTable(); );
} ); jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) {
</script> /* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
<link type="text/css" rel="stylesheet" href="style.css"> var x = a == "-" ? 0 : a.replace( /,/g, "" );
</head> var y = b == "-" ? 0 : b.replace( /,/g, "" );
<body>  
<div class="topbar"> /* Remove the currency sign */
<div class="topbar-inner"> x = x.substring( 1 );
<div class="container-fluid"> y = y.substring( 1 );
<a class="brand" href="#">contract dashboard</a>  
<ul class="nav"> /* Parse and return */
<li><a href="displayAgency.php">agencies</a></li> x = parseFloat( x );
<li><a href="displaySupplier.php">suppliers</a></li> y = parseFloat( y );
<li><a href="displayCategory.php">categories</a></li> return x - y;
<li><a href="displayCalendar.php">time periods</a></li> };
<!-- <li class="dropdown">  
<a href="#" class="dropdown-toggle">metrics</a> jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) {
<ul class="dropdown-menu">--> /* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
<li><a href="displayProcurementMethod.php">tenderm</a></li> var x = a == "-" ? 0 : a.replace( /,/g, "" );
<li><a href="displayConfidentialities.php">confidentiality</a></li> var y = b == "-" ? 0 : b.replace( /,/g, "" );
<li><a href="displayConsultancies.php">consultancies</a></li>  
<li><a href="displayAmendments.php">amendments</a></li> /* Remove the currency sign */
<li><a href="displayMap.php">geo</a></li> x = x.substring( 1 );
<!-- </ul> y = y.substring( 1 );
</li>-->  
</ul> /* Parse and return */
  x = parseFloat( x );
  y = parseFloat( y );
<form method="post" action="search.php" class="pull-right"> return y - x;
<input type="text" id="searchKeyword" name="searchKeyword" value="" placeholder="Search" /> };
<input type="hidden" id="searchID" name="searchID" value=""/> $(document).ready(function() {
</form> $('table').dataTable();
  } );
</div> </script>
</div><!-- /topbar-inner --> <link type="text/css" rel="stylesheet" href="style.css">
</div><!-- /topbar --> </head>
</div><!-- /topbar-wrapper --> <body>
<script type="text/javascript"> <div class="navbar">
  <div class="navbar-inner">
var options_xml = { <div class="container-fluid">
script: function (input) { return "search_autosuggest.php?input="+input; }, <a class="brand" href="#">contract dashboard</a>
varname:"input", <ul class="nav">
callback: function (obj) { document.getElementById('searchID').value = obj.id; } <li><a href="displayAgency.php">agencies</a></li>
}; <li><a href="displaySupplier.php">suppliers</a></li>
var as_xml = new bsn.AutoSuggest('searchKeyword', options_xml); <li><a href="displayCategory.php">categories</a></li>
</script> <li><a href="displayCalendar.php">time periods</a></li>
<div class="container-fluid"> <!-- <li class="dropdown">
<div class="sidebar"> <a href="#" class="dropdown-toggle">metrics</a>
<div class="well"> <ul class="dropdown-menu">-->
Filter by:<li> <li><a href="displayProcurementMethod.php">tenderm</a></li>
<li>year <li><a href="displayConfidentialities.php">confidentiality</a></li>
<li><li>2008</li> <li><a href="displayConsultancies.php">consultancies</a></li>
</li> <li><a href="displayAmendments.php">amendments</a></li>
</li> <li><a href="displayMap.php">geo</a></li>
</li> <br> </ul>
</div> </div>  
<div class="content">  
<?php <form method="post" action="search.php" class="pull-right">
$start = (float) array_sum(explode(' ', microtime())); <input type="text" id="searchKeyword" name="searchKeyword" value="" placeholder="Search" />
} <input type="hidden" id="searchID" name="searchID" value=""/>
  </form>
function include_footer() {  
global $start; </div>
$end = (float) array_sum(explode(' ', microtime())); </div><!-- /topbar-inner -->
  </div><!-- /topbar -->
echo ' <footer>' . "Processing time: " . sprintf("%.4f", ($end - $start)) . " seconds" . ' <footer>'; </div><!-- /topbar-wrapper -->
echo '</div> </div></body> </html>'; <script type="text/javascript">
}  
  var options_xml = {
include ("graphs.inc.php"); script: function (input) { return "search_autosuggest.php?input="+input; },
?> varname:"input",
  callback: function (obj) { document.getElementById('searchID').value = obj.id; }
  };
  var as_xml = new bsn.AutoSuggest('searchKeyword', options_xml);
  </script>
  <div class="container-fluid">
  <div class="row-fluid">
  <div class="span3">