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