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 "; }
  function cleanseName($input) {
$standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010';  
$start = 0.0; return trim(join(" ",array_filter(explode(" ",strtolower($input)), function($v, $k) {
  $cleanseNamesCorp = Array(
function include_header($title) { "ltd",
global $start; "limited",
?> "australia",
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "australian",
"http://www.w3.org/TR/html4/strict.dtd"> "australasia",
<html> "(aus)",
<head> "(aust)",
<title>Contract Dashboard - <?php echo $title; ?></title> "(australia)",
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"> "the",
<!-- Le HTML5 shim, for IE6-8 support of HTML elements --> "pty",
<!--[if lt IE 9]> "contractors",
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> "p/l",
<![endif]--> "inc.",
<script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script> "inc",
<link rel="stylesheet" href="autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" /> "incorporated"
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> );
<script type="text/javascript"> return !in_array($v,$cleanseNamesCorp) ;
$(document).ready(function() }, ARRAY_FILTER_USE_BOTH)));
{ }
//hide the all of the element with class msg_body function ucsmart($str) {
$(".msg_body").hide(); $shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In"
//toggle the componenet with class msg_body , "Of", "On", "Or", "The", "To", "With", "Use", "No", "Yes");
$(".msg_head").click(function() $strArray = explode(" ", preg_replace_callback("/(?<=(?<!:|’s)\W)
{ (A|An|And|At|For|In|Of|On|Or|The|To|With)
$(this).next(".msg_body").slideToggle(600); (?=\W)/",
}); function($matches) { return strtolower($matches[1]); } , ucwords(strtolower($str))));
}); foreach ($strArray as &$word) {
</script> if (strlen($word) <= 4 && !in_array($word, $shortWords))
  $word = strtoupper($word);
<style type="text/css" title="currentStyle"> }
@import "media/css/demo_table.css"; return implode(" ", $strArray);
</style> }
<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> function percent($num_amount, $num_total) {
<script type="text/javascript" charset="utf-8"> $count1 = $num_amount / $num_total;
jQuery.fn.dataTableExt.aTypes.unshift( $count2 = $count1 * 100;
function ( sData ) $count = number_format($count2, 2);
{ return $count;
var sValidChars = "0123456789.-,"; }
var Char;  
  function array_sum_all($a) {
/* Check the numeric part */ if (!is_array($a))
for ( i=1 ; i<sData.length ; i++ ) return $a;
{ $totale = 0;
Char = sData.charAt(i); foreach ($a as $key => $value)
if (sValidChars.indexOf(Char) == -1) $totale += array_sum_all($value);
{ return $totale;
return null; }
}  
} function show_stats($stats) {
  setlocale(LC_MONETARY, 'en_US');
/* Check prefixed by currency */ $value = number_format(doubleval($stats['total_value']) , 2);
if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) echo "<br/> {$stats['total']} contracts, total value $$value <br/>";
{ if ($stats['consultancy'] > 0) {
return 'currency'; echo "<b>Consultancies:</b> {$stats['consultancy']} contracts, ".percent($stats['consultancy'],$stats['total']);
} echo "%<br/>";
return null; }
} if ($stats['confidentialityContract']+$stats['confidentialityOutputs'] > 0) {
); $confidentialities = $stats['confidentialityContract']+$stats['confidentialityOutputs'];
jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) { echo "<b>Confidentialities:</b> $confidentialities contracts, ".percent( $confidentialities,$stats['total'])."%";
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */ echo "( {$stats['confidentialityContract']} on the contract, {$stats['confidentialityOutputs']} on the outputs)";
var x = a == "-" ? 0 : a.replace( /,/g, "" ); echo "<br/>";
var y = b == "-" ? 0 : b.replace( /,/g, "" ); }
  echo "<b>Procurement methods:</b> ";
/* Remove the currency sign */ if ($stats['open'] > 0) {
x = x.substring( 1 ); echo "Open {$stats['open']} contracts, ".percent($stats['open'],$stats['total']);
y = y.substring( 1 ); echo "%, ";
  }
/* Parse and return */ if ($stats['openSON'] > 0) {
x = parseFloat( x ); echo "Open via SON {$stats['openSON']} contracts, ".percent($stats['openSON'],$stats['total']);
y = parseFloat( y ); echo "%, ";
return x - y; }
}; if ($stats['prequalified'] > 0) {
  echo "Prequalified {$stats['prequalified']} contracts, ".percent($stats['prequalified'],$stats['total']);
jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) { echo "%, ";
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */ }
var x = a == "-" ? 0 : a.replace( /,/g, "" ); if ($stats['limited'] > 0) {
var y = b == "-" ? 0 : b.replace( /,/g, "" ); echo "limited {$stats['limited']} contracts, ".percent($stats['limited'],$stats['total']);
  echo "%, ";
/* Remove the currency sign */ }
x = x.substring( 1 ); }
y = y.substring( 1 );  
  // magic query modifiers
/* Parse and return */ $agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING);
x = parseFloat( x ); if ($agency != "")
y = parseFloat( y ); $agencyQ = "agencyName = '" . $agency . "' AND ";
return y - x;  
}; $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING);
$(document).ready(function() { if ($supplier != "") {
$('table').dataTable(); if ($supplier[0] !== '-') {
} ); $supplierParts = explode("-", $supplier);
</script>  
<link type="text/css" rel="stylesheet" href="style.css"> $supplierABN = array_shift($supplierParts);
</head> $supplierName = "%" . implode('-',$supplierParts) . "%";
<body>  
<div class="topbar"> $supplierQ = ' "supplierABN" = :supplierABN AND ';
<div class="topbar-inner"> } else {
<div class="container-fluid"> $supplierName = "%" . substr($supplier,1) . "%";
<a class="brand" href="#">contract dashboard</a> $supplierQ = ' "supplierName" ILIKE :supplierName AND ';
<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> $startYear = 2007;
<li><a href="displayCalendar.php">time periods</a></li> $year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT);
<!-- <li class="dropdown"> if ($year != "") {
<a href="#" class="dropdown-toggle">metrics</a> $yearQ = 'extract(year from "contractStart") = ' . $year . " AND ";
<ul class="dropdown-menu">--> }
<li><a href="displayProcurementMethod.php">tenderm</a></li> $standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010';
<li><a href="displayConfidentialities.php">confidentiality</a></li> $start = 0.0;
<li><a href="displayConsultancies.php">consultancies</a></li>  
<li><a href="displayAmendments.php">amendments</a></li> function local_url() {
<li><a href="displayMap.php">geo</a></li> return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/";
<!-- </ul> }
</li>-->  
</ul> function include_header($title) {
  global $start;
  ?>
<form method="post" action="search.php" class="pull-right"> <!DOCTYPE html>
<input type="text" id="searchKeyword" name="searchKeyword" value="" placeholder="Search" /> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" version="XHTML+RDFa 1.1"
<input type="hidden" id="searchID" name="searchID" value=""/> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
</form> xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:gr="http://purl.org/goodrelations/v1#"
</div> xmlns:dc="http://purl.org/dc/terms/"
</div><!-- /topbar-inner --> xmlns:pc="http://purl.org/procurement#"
</div><!-- /topbar --> xmlns:unspsc="http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#"
</div><!-- /topbar-wrapper --> xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
<script type="text/javascript"> xmlns:pcdt="http://purl.org/procurement/public-contracts-datatypes#"
  prefix="rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
var options_xml = { rdfs: http://www.w3.org/2000/01/rdf-schema#
script: function (input) { return "search_autosuggest.php?input="+input; }, gr: http://purl.org/goodrelations/v1#
varname:"input", dcterms: http://purl.org/dc/terms/
callback: function (obj) { document.getElementById('searchID').value = obj.id; } pc: http://purl.org/procurement/public-contracts#
}; cpv: http://purl.org/weso/pscs/cpv/2008/resource/
var as_xml = new bsn.AutoSuggest('searchKeyword', options_xml); unspsc: http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#
</script> v: http://www.w3.org/2006/vcard/ns#
<div class="container-fluid"> payment: http://reference.data.gov.uk/def/payment#
<div class="sidebar"> br: http://purl.org/business-register#
<div class="well"> xsd: http://www.w3.org/2001/XMLSchema#
Filter by:<li> pcdt: http://purl.org/procurement/public-contracts-datatypes#">
<li>year <head>
<li><li>2008</li> <title><?php echo $title; ?> - Contract Dashboard</title>
</li> <meta name="viewport" content="width=device-width, initial-scale=1">
</li> <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
</li> <br> <link rel="stylesheet" type="text/css" href="bootstrap-responsive.css">
</div> </div> <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<div class="content"> <!--[if lt IE 9]>
<?php <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
$start = (float) array_sum(explode(' ', microtime())); <![endif]-->
} <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" />
function include_footer() { <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
global $start; <script type="text/javascript">
$end = (float) array_sum(explode(' ', microtime())); $(document).ready(function()
  {
echo ' <footer>' . "Processing time: " . sprintf("%.4f", ($end - $start)) . " seconds" . ' <footer>'; //hide the all of the element with class msg_body
echo '</div> </div></body> </html>'; $(".msg_body").hide();
} //toggle the componenet with class msg_body
  $(".msg_head").click(function()
include ("graphs.inc.php"); {
?> $(this).next(".msg_body").slideToggle(600);
  });
  });
  </script>
   
  <style type="text/css" title="currentStyle">
  @import "media/css/demo_table.css";
  </style>
  <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>
  <script type="text/javascript" charset="utf-8">
  jQuery.fn.dataTableExt.aTypes.unshift(
  function ( sData )
  {
  var sValidChars = "0123456789.-,";
  var Char;
   
  /* Check the numeric part */
  for ( i=1 ; i<sData.length ; i++ )
  {
  Char = sData.charAt(i);
  if (sValidChars.indexOf(Char) == -1)
  {
  return null;
  }
  }
   
  /* 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 );