Depreciate MySQL and GD image graphs
[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"); include('db.inc.php');
   
if (!$conn) { define('ROOT', pathinfo(__FILE__, PATHINFO_DIRNAME));
die("A database error occurred.\n"); if (strstr($_SERVER['PHP_SELF'], "labs/") || strstr($_SERVER['PHP_SELF'], "admin/") || strstr($_SERVER['PHP_SELF'], "heuristics/")) {
} $basePath = "../";
  }
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /*require ROOT . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'openid.php';
function databaseError($errMsg) require(ROOT.'/solarium/vendor/autoload.php');
{ require(ROOT.'/solarium/library/Solarium/Autoloader.php');
die($errMsg); Solarium\Autoloader::register();
} // check solarium version available
  //echo 'Solarium library version: ' . Solarium\Client::VERSION . ' - ';
function ucsmart($str) { $config = array(
$shortWords = Array("The","Pty","Ltd","Inc","Red","Oil","A","An","And","At","For","In" 'endpoint' => array(
,"Of","On","Or","The","To","With"); 'localhost' => array(
$strArray = explode(" ",preg_replace("/(?<=(?<!:|’s)\W) 'host' => '127.0.0.1',
(A|An|And|At|For|In|Of|On|Or|The|To|With) 'port' => 8983,
(?=\W)/e", 'strtolower("$1")', ucwords(strtolower($str)))); 'path' => '/solr/contracts/',
foreach($strArray as &$word) { )
if (strlen($word) <= 4 && !in_array($word,$shortWords)) $word = strtoupper($word); )
} );
return implode(" ",$strArray); // create a client instance
} $solr_client = new Solarium\Client($config);
   
function percent($num_amount, $num_total) {  
$count1 = $num_amount / $num_total; $openid = new LightOpenID($_SERVER['HTTP_HOST']);
$count2 = $count1 * 100; // you have to open the session to be able to modify or remove it
$count = number_format($count2, 2); session_start();
return $count; function login() {
} global $openid;
function array_sum_all($a) { if (!$openid->mode) {
if(!is_array($a)) return $a; $openid->required = array('contact/email');
foreach($a as $key=>$value) $openid->identity = 'https://www.google.com/accounts/o8/id';
$totale += array_sum_all($value); header('Location: ' . $openid->authUrl());
return $totale; }
} }
// magic query modifiers  
$agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING); function auth() {
if ($agency != "") $agencyQ = "agencyName = '" . $agency . "' AND "; global $openid;
  if ($_SESSION['authed'] == true) {
$supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING); return true;
if ($supplier != "") { }
$supplierParts = explode("-", $supplier);  
$supplierName = "%".$supplierParts[1]."%"; if ($openid->mode) {
$supplierABN = $supplierParts[0]; $attr = $openid->getAttributes();
if ($supplierParts[0] > 0) $supplierQ = ' "supplierABN" = :supplierABN AND '; if ($attr['contact/email'] != 'maxious@gmail.com') {
else $supplierQ = ' "supplierName" LIKE :supplierName AND '; die('Access Denied');
} } else {
  $_SESSION['authed'] = true;
$startYear = 2007; }
$year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT); } else {
if ($year != "") $yearQ = "YEAR(publishDate) = " . $year . " AND "; login();
  }
$standardQ = ' "childCN" = 0 '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010'; }*/
$start =0.0;  
  // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
function include_header($title) { function databaseError($errMsg) {
global $start; if ($errMsg[2] != "") {
?> echo '<div class="alert-message error">';
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" die(print_r($errMsg, true));
"http://www.w3.org/TR/html4/strict.dtd"> echo "</div>";
<html> }
<head> }
<title>Contract Dashboard - <?php echo $title; ?></title>  
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/reset-fonts-grids/reset-fonts-grids.css"> function ucsmart($str) {
  $shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In"
<script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script> , "Of", "On", "Or", "The", "To", "With");
<link rel="stylesheet" href="autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" /> $strArray = explode(" ", preg_replace_callback("/(?<=(?<!:|’s)\W)
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> (A|An|And|At|For|In|Of|On|Or|The|To|With)
<script type="text/javascript"> (?=\W)/",
$(document).ready(function() function($matches) { return strtolower($matches[1]); } , ucwords(strtolower($str))));
{ foreach ($strArray as &$word) {
//hide the all of the element with class msg_body if (strlen($word) <= 4 && !in_array($word, $shortWords))
$(".msg_body").hide(); $word = strtoupper($word);
//toggle the componenet with class msg_body }
$(".msg_head").click(function() return implode(" ", $strArray);
{ }
$(this).next(".msg_body").slideToggle(600);  
}); function percent($num_amount, $num_total) {
}); $count1 = $num_amount / $num_total;
</script> $count2 = $count1 * 100;
  $count = number_format($count2, 2);
<style type="text/css" title="currentStyle"> return $count;
@import "media/css/demo_table.css"; }
</style>  
<script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script> function array_sum_all($a) {
<script type="text/javascript" charset="utf-8"> if (!is_array($a))
jQuery.fn.dataTableExt.aTypes.unshift( return $a;
function ( sData ) $totale = 0;
{ foreach ($a as $key => $value)
var sValidChars = "0123456789.-,"; $totale += array_sum_all($value);
var Char; return $totale;
  }
/* Check the numeric part */  
for ( i=1 ; i<sData.length ; i++ ) function show_stats($stats) {
{ setlocale(LC_MONETARY, 'en_US');
Char = sData.charAt(i); $value = number_format(doubleval($stats['total_value']) , 2);
if (sValidChars.indexOf(Char) == -1) echo "<br/> {$stats['total']} contracts, total value $$value <br/>";
{ if ($stats['consultancy'] > 0) {
return null; echo "<b>Consultancies:</b> {$stats['consultancy']} contracts, ".percent($stats['consultancy'],$stats['total']);
} echo "%<br/>";
} }
  if ($stats['confidentialityContract']+$stats['confidentialityOutputs'] > 0) {
/* Check prefixed by currency */ $confidentialities = $stats['confidentialityContract']+$stats['confidentialityOutputs'];
if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) echo "<b>Confidentialities:</b> $confidentialities contracts, ".percent( $confidentialities,$stats['total'])."%";
{ echo "( {$stats['confidentialityContract']} on the contract, {$stats['confidentialityOutputs']} on the outputs)";
return 'currency'; echo "<br/>";
} }
return null; echo "<b>Procurement methods:</b> ";
} if ($stats['open'] > 0) {
); echo "Open {$stats['open']} contracts, ".percent($stats['open'],$stats['total']);
jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) { echo "%, ";
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */ }
var x = a == "-" ? 0 : a.replace( /,/g, "" ); if ($stats['openSON'] > 0) {
var y = b == "-" ? 0 : b.replace( /,/g, "" ); echo "Open via SON {$stats['openSON']} contracts, ".percent($stats['openSON'],$stats['total']);
  echo "%, ";
/* Remove the currency sign */ }
x = x.substring( 1 ); if ($stats['prequalified'] > 0) {
y = y.substring( 1 ); echo "Prequalified {$stats['prequalified']} contracts, ".percent($stats['prequalified'],$stats['total']);
  echo "%, ";
/* Parse and return */ }
x = parseFloat( x ); if ($stats['limited'] > 0) {
y = parseFloat( y ); echo "limited {$stats['limited']} contracts, ".percent($stats['limited'],$stats['total']);
return x - y; echo "%, ";
}; }
  }
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) */ // magic query modifiers
var x = a == "-" ? 0 : a.replace( /,/g, "" ); $agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING);
var y = b == "-" ? 0 : b.replace( /,/g, "" ); if ($agency != "")
  $agencyQ = "agencyName = '" . $agency . "' AND ";
/* Remove the currency sign */  
x = x.substring( 1 ); $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING);
y = y.substring( 1 ); if ($supplier != "") {
  if ($supplier[0] !== '-') {
/* Parse and return */ $supplierParts = explode("-", $supplier);
x = parseFloat( x );  
y = parseFloat( y ); $supplierABN = array_shift($supplierParts);
return y - x; $supplierName = "%" . implode('-',$supplierParts) . "%";
};  
$(document).ready(function() { $supplierQ = ' "supplierABN" = :supplierABN AND ';
$('table').dataTable(); } else {
} ); $supplierName = "%" . substr($supplier,1) . "%";
</script> $supplierQ = ' "supplierName" ILIKE :supplierName AND ';
<link type="text/css" rel="stylesheet" href="style.css"> }
</head> }
<body><div id="doc3" class="yui-t4">  
<div id="hd"> $startYear = 2007;
<h1> contract dashboard</h1> $year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT);
</div> if ($year != "") {
<div id="sitenav"> $yearQ = 'extract(year from "contractStart") = ' . $year . " AND ";
<a href="displayAgency.php">agencies</a> }
<a href="displaySupplier.php">suppliers</a> $standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010';
<a href="displayCategory.php">product/service categories</a> $start = 0.0;
<a href="displayCalendar.php">time periods</a>  
| metrics | function local_url() {
<a href="displayProcurementMethod.php">procurement method</a> return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/";
<a href="displayConfidentialities.php">contractual confidentiality</a> }
<a href="displayConsultancies.php">consultancies</a>  
<a href="displayAmendments.php">amendments</a> function include_header($title) {
<a href="displayMap.php">postcodes</a> global $start;
<div id="search"><form method="post" action="search.php" class="asholder"> ?>
<label for="searchKeyword">search</label> <!DOCTYPE html>
<input type="text" id="searchKeyword" name="searchKeyword" value="" style="width:150px" /> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" version="XHTML+RDFa 1.1"
<input type="hidden" id="searchID" name="searchID" value=""/><input type="submit" value="submit" /> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
</form></div> xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
<script type="text/javascript"> xmlns:gr="http://purl.org/goodrelations/v1#"
  xmlns:dc="http://purl.org/dc/terms/"
var options_xml = { xmlns:pc="http://purl.org/procurement#"
script: function (input) { return "search_autosuggest.php?input="+input; }, xmlns:unspsc="http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#"
varname:"input", xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
callback: function (obj) { document.getElementById('searchID').value = obj.id; } xmlns:pcdt="http://purl.org/procurement/public-contracts-datatypes#"
}; prefix="rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
var as_xml = new bsn.AutoSuggest('searchKeyword', options_xml); rdfs: http://www.w3.org/2000/01/rdf-schema#
</script> gr: http://purl.org/goodrelations/v1#
  dcterms: http://purl.org/dc/terms/
</div> pc: http://purl.org/procurement/public-contracts#
<div id="bd" role="main"> cpv: http://purl.org/weso/pscs/cpv/2008/resource/
<div id="yui-main"> unspsc: http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#
<div class="yui-b"><div class="yui-g"> v: http://www.w3.org/2006/vcard/ns#
<?php payment: http://reference.data.gov.uk/def/payment#
$start = (float) array_sum(explode(' ',microtime())); br: http://purl.org/business-register#
} xsd: http://www.w3.org/2001/XMLSchema#
  pcdt: http://purl.org/procurement/public-contracts-datatypes#">
function include_footer() { <head>
global $start; <title><?php echo $title; ?> - Contract Dashboard</title>
$end = (float) array_sum(explode(' ',microtime())); <meta name="viewport" content="width=device-width, initial-scale=1">
?> <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
</div> <link rel="stylesheet" type="text/css" href="bootstrap-responsive.css">
</div> <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
</div> <!--[if lt IE 9]>
<div class="yui-b"> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
Filter by:<ul> <![endif]-->
<li>year <script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script>
<ul><li>2008</li> <link rel="stylesheet" href="autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" />
</ul> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</li> <script type="text/javascript">
</ul> <br> </div> </div> $(document).ready(function()
  {
<?php //hide the all of the element with class msg_body
echo '<div id="ft"><p>'."Processing time: ". sprintf("%.4f", ($end-$start))." seconds".'</p></div>'; $(".msg_body").hide();
echo '</div> </body> </html>'; //toggle the componenet with class msg_body
} $(".msg_head").click(function()
?> {
  $(this).next(".msg_body").slideToggle(600);
  });
  });
  </script>
   
  <style type="text/css" title="currentStyle">
  @import "media/css/demo_table.css";
  </style>
  <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>
  <script type="text/javascript" charset="utf-8">
  jQuery.fn.dataTableExt.aTypes.unshift(
  function ( sData )
  {
  var sValidChars = "0123456789.-,";
  var Char;
   
  /* Check the numeric part */
  for ( i=1 ; i<sData.length ; i++ )
  {
  Char = sData.charAt(i);
  if (sValidChars.indexOf(Char) == -1)
  {
  return null;
  }
  }
   
  /* Check prefixed by currency */
  if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' )
  {
  return 'currency';
  }
  return null;
  }
  );
  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, "" );
  var y = b == "-" ? 0 : b.replace( /,/g, "" );
   
  /* Remove the currency sign */
  x = x.substring( 1 );
  y = y.substring( 1 );
   
  /* Parse and return */
  x = parseFloat( x );
  y = parseFloat( y );
  return x - y;
  };
   
  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) */
  var x = a == "-" ? 0 : a.replace( /,/g, "" );
  var y = b == "-" ? 0 : b.replace( /,/g, "" );
   
  /* Remove the currency sign */
  x = x.substring( 1 );
  y = y.substring( 1 );
   
  /* Parse and return */
  x = parseFloat( x );
  y = parseFloat( y );
  return y - x;
  };
  $(document).ready(function() {
  $('table').dataTable();
  } );
  </script>
  <link type="text/css" rel="stylesheet" href="style.css">
  </head>
  <body>
  <div class="navbar">
  <div class="navbar-inner">
  <div class="container-fluid">
  <a class="brand" href="#">contract dashboard</a>
  <ul class="nav">
  <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>
  <li><a href="displayCategory.php">categories</a></li>
  <li><a href="displayCalendar.php">dates</a></li>
  <li><a href="displayProcurementMethod.php">tenderm</a></li>
  <li><a href="displayConfidentialities.php">confidentiality</a></li>
  <li><a href="displayConsultancies.php">consultancies</a></li>
  <li><a href="displayAmendments.php">amendments</a></li>
  <li><a href="displayMap.php">geo</a></li>
  </ul>
   
   
  <form method="get" action="search.php" class="pull-right"