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