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