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