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