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