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