add network graph
[contractdashboard.git] / lib / common.inc.php
blob:a/lib/common.inc.php -> blob:b/lib/common.inc.php
--- a/lib/common.inc.php
+++ b/lib/common.inc.php
@@ -4,17 +4,13 @@
 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 = "../";
 }
-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();
@@ -61,7 +57,7 @@
     } else {
         login();
     }
-}
+}*/
 
 //   $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 function databaseError($errMsg) {
@@ -96,9 +92,41 @@
 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) {
+  echo "<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
@@ -156,6 +184,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 -->
@@ -273,12 +302,12 @@
         </div><!-- /topbar-wrapper -->
         <script type="text/javascript">
                         	
-/*            var options_xml = {
+            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);*/
+            var as_xml = new bsn.AutoSuggest('searchKeyword', options_xml);
         </script>
         <div class="container-fluid">
             <div class="row-fluid">
@@ -287,7 +316,7 @@
                 	<div class="well sidebar-nav">
                     		<li class="nav-header">Year</li>
 <?php
-foreach (range(2007,2016) as $year) {
+foreach (range(2007,2017) as $year) {
 $get = $_GET;
 $get['year'] = $year;
 $query = http_build_query($get);
@@ -309,7 +338,7 @@
                 global $start;
                 $end = (float) array_sum(explode(' ', microtime()));
 
-                echo '</div>  <footer> <small>        Incorporates AusTender materials under a Creative Commons Attribution 3.0 Australia licence (CC BY 3.0 AU) https://creativecommons.org/licenses/by/3.0/au/ <br/> AusTender materials are released by the Department of Finance. <br/> AusTender materials are subject to change and should be verified on the AusTender website to ensure the information is up to date and correct: www.tenders.gov.au. <br/>' . "Processing time: " . sprintf("%.4f", ($end - $start)) . " seconds" . '</small>  </footer>';
+                echo '</div>  <footer>' . "Processing time: " . sprintf("%.4f", ($end - $start)) . " seconds" . '  <footer>';
 
                     if (strpos($_SERVER['SERVER_NAME'], ".gs")) {
                     ?>