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