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