--- a/lib/common.inc.php +++ b/lib/common.inc.php @@ -4,25 +4,31 @@ error_reporting(E_ALL ^ E_NOTICE); -$conn = new PDO("pgsql:dbname=contractDashboard;user=postgres;password=snmc;host=localhost"); - -if (!$conn) { - die("A database error occurred.\n"); -} +include('db.inc.php'); define('ROOT', pathinfo(__FILE__, PATHINFO_DIRNAME)); if (strstr($_SERVER['PHP_SELF'], "labs/") || strstr($_SERVER['PHP_SELF'], "admin/") || strstr($_SERVER['PHP_SELF'], "heuristics/")) { $basePath = "../"; } -if ($_SERVER['HTTP_HOST'] != "localhost") { -require $basePath."lib/amon-php/amon.php"; -Amon::config(array('address'=> 'http://127.0.0.1:2464', - 'protocol' => 'http', - 'secret_key' => "JBcSUdFOi5lK0vCjLjbHDpQamcBnRA4iV7QLaTADeDQ")); -Amon::setup_exception_handler(); -} - -require ROOT . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'openid.php'; +/*require ROOT . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'openid.php'; +require(ROOT.'/solarium/vendor/autoload.php'); +require(ROOT.'/solarium/library/Solarium/Autoloader.php'); +Solarium\Autoloader::register(); +// check solarium version available +//echo 'Solarium library version: ' . Solarium\Client::VERSION . ' - '; +$config = array( + 'endpoint' => array( + 'localhost' => array( + 'host' => '127.0.0.1', + 'port' => 8983, + 'path' => '/solr/contracts/', + ) + ) +); +// create a client instance +$solr_client = new Solarium\Client($config); + + $openid = new LightOpenID($_SERVER['HTTP_HOST']); // you have to open the session to be able to modify or remove it session_start(); @@ -51,13 +57,12 @@ } else { login(); } -} +}*/ // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); function databaseError($errMsg) { if ($errMsg[2] != "") { echo '<div class="alert-message error">'; - if ($_SERVER['HTTP_HOST'] != "localhost") Amon::log(print_r($errMsg, true).print_r($_REQUEST, true).print_r($_SERVER, true), array('error')); die(print_r($errMsg, true)); echo "</div>"; } @@ -66,9 +71,10 @@ function ucsmart($str) { $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) + $strArray = explode(" ", preg_replace_callback("/(?<=(?<!:|’s)\W) (A|An|And|At|For|In|Of|On|Or|The|To|With) - (?=\W)/e", 'strtolower("$1")', ucwords(strtolower($str)))); + (?=\W)/", +function($matches) { return strtolower($matches[1]); } , ucwords(strtolower($str)))); foreach ($strArray as &$word) { if (strlen($word) <= 4 && !in_array($word, $shortWords)) $word = strtoupper($word); @@ -86,9 +92,43 @@ function array_sum_all($a) { if (!is_array($a)) return $a; + $totale = 0; foreach ($a as $key => $value) $totale += array_sum_all($value); return $totale; +} + +function show_stats($stats) { + setlocale(LC_MONETARY, 'en_US'); + $value = number_format(doubleval($stats['total_value']) , 2); + echo "<br/> {$stats['total']} contracts, total value $$value <br/>"; + if ($stats['consultancy'] > 0) { + echo "<b>Consultancies:</b> {$stats['consultancy']} contracts, ".percent($stats['consultancy'],$stats['total']); + echo "%<br/>"; + } + if ($stats['confidentialityContract']+$stats['confidentialityOutputs'] > 0) { + $confidentialities = $stats['confidentialityContract']+$stats['confidentialityOutputs']; + echo "<b>Confidentialities:</b> $confidentialities contracts, ".percent( $confidentialities,$stats['total'])."%"; + echo "( {$stats['confidentialityContract']} on the contract, {$stats['confidentialityOutputs']} on the outputs)"; + echo "<br/>"; + } + echo "<b>Procurement methods:</b> "; + if ($stats['open'] > 0) { + echo "Open {$stats['open']} contracts, ".percent($stats['open'],$stats['total']); + echo "%, "; + } + if ($stats['openSON'] > 0) { + echo "Open via SON {$stats['openSON']} contracts, ".percent($stats['openSON'],$stats['total']); + echo "%, "; + } + if ($stats['prequalified'] > 0) { + echo "Prequalified {$stats['prequalified']} contracts, ".percent($stats['prequalified'],$stats['total']); + echo "%, "; + } + if ($stats['limited'] > 0) { + echo "limited {$stats['limited']} contracts, ".percent($stats['limited'],$stats['total']); + echo "%, "; + } } // magic query modifiers @@ -98,19 +138,23 @@ $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING); if ($supplier != "") { + if ($supplier[0] !== '-') { $supplierParts = explode("-", $supplier); - $supplierName = "%" . $supplierParts[1] . "%"; - $supplierABN = $supplierParts[0]; - if ($supplierParts[0] > 0) - $supplierQ = ' "supplierABN" = :supplierABN AND '; - else - $supplierQ = ' "supplierName" LIKE :supplierName AND '; + + $supplierABN = array_shift($supplierParts); + $supplierName = "%" . implode('-',$supplierParts) . "%"; + + $supplierQ = ' "supplierABN" = :supplierABN AND '; + } else { + $supplierName = "%" . substr($supplier,1) . "%"; + $supplierQ = ' "supplierName" ILIKE :supplierName AND '; + } } $startYear = 2007; $year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT); if ($year != "") { - $yearQ = "YEAR(publishDate) = " . $year . " AND "; + $yearQ = 'extract(year from "contractStart") = ' . $year . " AND "; } $standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010'; $start = 0.0; @@ -146,6 +190,7 @@ pcdt: http://purl.org/procurement/public-contracts-datatypes#"> <head> <title><?php echo $title; ?> - Contract Dashboard</title> + <meta name="viewport" content="width=device-width, initial-scale=1"> <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 --> @@ -241,11 +286,9 @@ <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">time periods</a></li> - <!-- <li class="dropdown"> - <a href="#" class="dropdown-toggle">metrics</a> - <ul class="dropdown-menu">--> + <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> @@ -254,7 +297,7 @@ </ul> - <form method="post" action="search.php" class="pull-right"> + <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> @@ -275,9 +318,21 @@ <div class="container-fluid"> <div class="row-fluid"> <div class="span3"> +<h3> Filter by: </h3> <div class="well sidebar-nav"> - <li class="nav-header">Filter by:</li> - <li>2008</li> + <li class="nav-header">Year</li> +<?php +foreach (range(2007,2017) as $year) { +$get = $_GET; +$get['year'] = $year; +$query = http_build_query($get); +echo "<li><A href='?$query'>"; +if ($_GET['year'] == $year) echo "<b>"; +echo "$year"; +if ($_GET['year'] == $year) echo "</b>"; +echo "</a></li>"; +} +?> </div> </div> <div class="span9"> @@ -313,7 +368,3 @@ include ("graphs.inc.php"); - - - -