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