<?php | <?php |
include_once("./lib/common.inc.php"); | include_once("./lib/common.inc.php"); |
if ($_REQUEST['month']) { | if ($_REQUEST['month']) { |
$monthParts = explode("-", $_REQUEST['month']); | $monthParts = explode("-", str_replace(Array("'","/","\\",'-'), "",$_REQUEST['month'])); |
$year = $monthParts[1]; | $year = $monthParts[1]; |
$month = $monthParts[0]; | $month = $monthParts[0]; |
$monthName = date("F Y", mktime(0,0,0,$month,1,$year)); | $monthName = date("F Y", mktime(0,0,0,$month,1,$year)); |
include_header($monthName); | include_header($monthName); |
echo "<center><h1>" . $monthName . "</h1></center>"; | echo "<center><h1>" . $monthName . "</h1></center>"; |
$query = 'SELECT "CNID", "description", "value", "agencyName", "category", "contractStart", "supplierName" | $query = 'SELECT "CNID", "description", "value", "agencyName", "category", "contractStart", "supplierName" |
FROM contractnotice | FROM contractnotice |
WHERE "childCN" is null | WHERE "childCN" is null |
AND extract(year from "contractStart") = :year | AND extract(year from "contractStart") = :year |
AND extract(month from "contractStart") = :month | AND extract(month from "contractStart") = :month |
ORDER BY value DESC'; | ORDER BY value DESC'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":month", $monthParts[0]); | $query->bindParam(":month", $monthParts[0]); |
$query->bindParam(":year", $monthParts[1]); | $query->bindParam(":year", $monthParts[1]); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
//MethodCountGraph($supplier); | //MethodCountGraph($supplier); |
//CnCGraph($supplier); | //CnCGraph($supplier); |
echo "<table> <thead> | echo "<table> <thead> |
<tr> | <tr> |
<th>Contract Notice Number</th> | <th>Contract Notice Number</th> |
<th>Contract Description</th> | <th>Contract Description</th> |
<th>Total Contract Value</th> | <th>Total Contract Value</th> |
<th>Agency</th> | <th>Agency</th> |
<th>Contract Start Date</th> | <th>Contract Start Date</th> |
<th>Supplier</th> | <th>Supplier</th> |
</tr> | </tr> |
</thead>"; | </thead>"; |
foreach ($query->fetchAll() as $row) { | foreach ($query->fetchAll() as $row) { |
setlocale(LC_MONETARY, 'en_US'); | setlocale(LC_MONETARY, 'en_US'); |
$value = number_format(doubleval($row['value']), 2); | $value = number_format(doubleval($row['value']), 2); |
echo ("<tr> | echo ("<tr> |
<td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td> | <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td> |
<td><b>{$row['description']}</b></a></td> | <td><b>{$row['description']}</b></a></td> |
<td>\$$value</td><td>{$row['agencyName']}</td> | <td>\$$value</td><td>{$row['agencyName']}</td> |
<td>{$row['contractStart']}</td> | <td>{$row['contractStart']}</td> |
<td>{$row['supplierName']}</td> | <td>{$row['supplierName']}</td> |
</tr>"); | </tr>"); |
} | } |
echo "</table>"; | echo "</table>"; |
} else { | } else { |
/* | /* |
split by year | split by year |
todo: | todo: |
Year/Month drilldown - largest contracts, agencies, suppliers | Year/Month drilldown - largest contracts, agencies, suppliers |
count per month | count per month |
big picture graphs? */ | big picture graphs? */ |
include_header("Months and Years"); | include_header("Months and Years"); |
ContractStartingGraph(); | ContractStartingGraph(); |
ContractPublishedGraph(); | ContractPublishedGraph(); |
$query = 'SELECT extract(year from "contractStart"), extract(month from "contractStart"), | $query = 'SELECT extract(year from "contractStart"), extract(month from "contractStart"), |
SUM(value) as val, count(1) as count FROM contractnotice WHERE "childCN" is null GROUP BY extract(year from "contractStart"), extract(month from "contractStart") ORDER BY extract(year from "contractStart"), extract(month from "contractStart") '; | SUM(value) as val, count(1) as count FROM contractnotice WHERE "childCN" is null GROUP BY extract(year from "contractStart"), extract(month from "contractStart") ORDER BY extract(year from "contractStart"), extract(month from "contractStart") '; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
echo "<table> <thead> | echo "<table> <thead> |
<tr> | <tr> |
<th>Month/Year</th> | <th>Month/Year</th> |
<th>Total Contracts Value</th> | <th>Total Contracts Value</th> |
<th>Number of Contracts</th> | <th>Number of Contracts</th> |
</tr> | </tr> |
</thead>"; | </thead>"; |
foreach ($query->fetchAll() as $row) { | foreach ($query->fetchAll() as $row) { |
setlocale(LC_MONETARY, 'en_US'); | setlocale(LC_MONETARY, 'en_US'); |
$value = number_format(doubleval($row["val"]), 2); | $value = number_format(doubleval($row["val"]), 2); |
$month_name = date('F', mktime(0, 0, 0, $row[1])); | $month_name = date('F', mktime(0, 0, 0, $row[1])); |
echo ("<tr><td><b><a href=\"?month=$row[1]-$row[0]\">$month_name {$row[0]}</a></b></td><td>\$$value</td><td>({$row['count']} contracts)</td></tr>"); | echo ('<tr><td><b><a href="?month=$row[1]-$row[0]">'.$month_name.' '.$row[0].'</a></b></td><td>$'.$value.'</td><td>(' .$row['count'].' contracts)</td></tr>'); |
} | } |
echo "</table>"; | echo "</table>"; |
} | } |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
include_once ("../lib/common.inc.php"); | include_once ("../lib/common.inc.php"); |
$heuristics = Array(); | $heuristics = Array(); |
//each heuristic adds self to description array | //each heuristic adds self to description array |
include ("dateHeuristics.php"); | include ("dateHeuristics.php"); |
include ("historyHeuristics.php"); | include ("historyHeuristics.php"); |
//include ("metadataHeuristics.php"); | //include ("metadataHeuristics.php"); |
//include ("valueHeuristics.php"); | //include ("valueHeuristics.php"); |
function runHeuristic($heuristicName, $cn) | function runHeuristic($heuristicName, $cn) { |
{ | |
global $conn; | global $conn; |
// check if already ran | // check if already ran |
$query = "select count(*) from heuristic_results where heuristic_name = '$heuristicName' and \"CNID\" = '{$cn['CNID']}'"; | $query = "select count(*) from heuristic_results where heuristic_name = '$heuristicName' and \"CNID\" = '{$cn['CNID']}'"; |
$result = $conn->query($query); | $result = $conn->query($query); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
$r = $result->fetch(PDO::FETCH_BOTH); | $r = $result->fetch(PDO::FETCH_BOTH); |
if ($r[0] == 0) { | if ($r[0] == 0) { |
// if not, run now | // if not, run now |
$hresults = call_user_func($heuristicName, $cn); | $hresults = call_user_func($heuristicName, $cn); |
if (!isset($hresults["heuristic_value"]) || !isset($hresults["raw_value"]) || !isset($hresults["mean"]) || !isset($hresults["stddev"])) { | if (!isset($hresults["heuristic_value"]) || !isset($hresults["raw_value"]) || !isset($hresults["mean"]) || !isset($hresults["stddev"])) { |
print_r($hresults); | print_r($hresults); |
die("Missing field in heurtistic $heuristicName result"); | die("Missing field in heurtistic $heuristicName result"); |
} | } |
$query = "insert into heuristic_results values('$heuristicName', | $query = "insert into heuristic_results values('$heuristicName', |
'{$hresults["heuristic_value"]}', | '{$hresults["heuristic_value"]}', |
'{$hresults["raw_value"]}', | '{$hresults["raw_value"]}', |
'{$hresults["mean"]}', | '{$hresults["mean"]}', |
'{$hresults["stddev"]}', | '{$hresults["stddev"]}', |
'{$cn["CNID"]}', | '{$cn["CNID"]}', |
NOW(), | NOW(), |
'{$cn["publishDate"]}', | '{$cn["publishDate"]}'," |
'{$cn["agencyABN"]}', | //."'{$cn["agencyABN"]}', |
'{$cn["supplierID"]}' | ."0,'{$cn["supplierID"]}' |
)"; | )"; |
// save value and cn data via sql | // save value and cn data via sql |
$result = $conn->query($query); | $result = $conn->query($query); |
$errors = $conn->errorInfo(); | $errors = $conn->errorInfo(); |
if ($errors[2] == "") echo "Saved $heuristicName for {$cn["CNID"]} <br>\n"; | if ($errors[2] == "") |
elseif (strpos($errors[2] , "Duplicate entry") === false) echo $hresults . " failed insert.<br>" . print_r($errors,true) . " <br> $query <br><br>\n"; | echo "Saved $heuristicName for {$cn["CNID"]} <br>\n"; |
} | elseif (strpos($errors[2], "Duplicate entry") === false) |
echo $hresults . " failed insert.<br>" . print_r($errors, true) . " <br> $query <br><br>\n"; | |
} | |
} | } |
?> | ?> |
<?php | <?php |
$heuristics["HISTORY_LOW_TRANSACTIONS_AGENCY"] = Array( | $heuristics["HISTORY_LOW_TRANSACTIONS_AGENCY"] = Array( |
"description" => "unusual for agency due to previous low number of transactions " | "description" => "unusual for agency due to previous low number of transactions " |
); | ); |
function HISTORY_LOW_TRANSACTIONS_AGENCY($cn) | function HISTORY_LOW_TRANSACTIONS_AGENCY($cn) |
{ | { |
$thisAgencyTransactions = getAgencyTransactions($cn['agencyName']); | $thisAgencyTransactions = getAgencyTransactions($cn['agencyName']); |
$averageAgencyTransactions = getAverageAgencyTransactions(); | $averageAgencyTransactions = getAverageAgencyTransactions(); |
$stddevAgencyTransactions = getstddevAgencyTransactions(); | $stddevAgencyTransactions = getstddevAgencyTransactions(); |
$diff = strtotime($cn['contractEnd']) - strtotime($cn['contractStart']); | $diff = strtotime($cn['contractEnd']) - strtotime($cn['contractStart']); |
$days = intval($diff / (60 * 60 * 24)); | $days = intval($diff / (60 * 60 * 24)); |
$value = abs($days - $averageAgencyTransactions) / $stddevAgencyTransactions; | $value = abs($days - $averageAgencyTransactions) / $stddevAgencyTransactions; |
return Array( | return Array( |
"heuristic_value" => $value, | "heuristic_value" => $value, |
"raw_value" => $days, | "raw_value" => $days, |
"mean" => $averageAgencyTransactions, | "mean" => $averageAgencyTransactions, |
"stddev" => $stddevAgencyTransactions | "stddev" => $stddevAgencyTransactions |
); | ); |
} | } |
$agencyTransactions = Array(); | $agencyTransactions = Array(); |
function getAgencyTransactions($agencyName) | function getAgencyTransactions($agencyName) |
{ | { |
global $agencyTransactions; | global $agencyTransactions,$conn; |
if (!$agencyTransactions[$agencyName]) { | if (!$agencyTransactions[$agencyName]) { |
$query = 'select count(*) from contractnotice where agencyName = "' . $agencyName . '"'; | $query = 'select count(*) from contractnotice where "agencyName" = \'' . $agencyName . '"\''; |
$result = $conn->query($query); | $result = $conn->query($query); |
$r = $result->fetch(PDO::FETCH_BOTH); | $r = $result->fetch(PDO::FETCH_BOTH); |
$agencyTransactions[$agencyName] = $r[0]; | $agencyTransactions[$agencyName] = $r[0]; |
} | } |
return $agencyTransactions[$agencyName]; | return $agencyTransactions[$agencyName]; |
} | } |
$averageAgencyTransactions; | $averageAgencyTransactions; |
function getAverageAgencyTransactions() | function getAverageAgencyTransactions() |
{ | { |
global $averageAgencyTransactions; | global $averageAgencyTransactions; |
if (!$averageAgencyTransactions) { | if (!$averageAgencyTransactions) { |
getStatsAgencyTransactions(); | getStatsAgencyTransactions(); |
} | } |
return $averageAgencyTransactions; | return $averageAgencyTransactions; |
} | } |
$stddevAgencyTransactions; | $stddevAgencyTransactions; |
function getstddevAgencyTransactions() | function getstddevAgencyTransactions() |
{ | { |
global $stddevAgencyTransactions; | global $stddevAgencyTransactions; |
if (!$stddevAgencyTransactions) { | if (!$stddevAgencyTransactions) { |
getStatsAgencyTransactions(); | getStatsAgencyTransactions(); |
} | } |
return $stddevAgencyTransactions; | return $stddevAgencyTransactions; |
} | } |
function getStatsAgencyTransactions() | function getStatsAgencyTransactions() |
{ | { |
global $averageAgencyTransactions, $stddevAgencyTransactions; | global $averageAgencyTransactions, $stddevAgencyTransactions,$conn; |
$query = "select avg(count), STDDEV(count) from (select count(*) as count | $query = 'select avg(count), STDDEV(count) from (select count(*) as count |
from contractnotice group by agencyName) as a;"; | from contractnotice group by "agencyName") as a;'; |
$result = $conn->query($query); | $result = $conn->query($query); |
$r = $result->fetch(PDO::FETCH_BOTH); | $r = $result->fetch(PDO::FETCH_BOTH); |
$averageAgencyTransactions = $r[0]; | $averageAgencyTransactions = $r[0]; |
$stddevAgencyTransactions = $r[1]; | $stddevAgencyTransactions = $r[1]; |
} | } |
$heuristics["HISTORY_LOW_TRANSACTIONS_SUPPLIER"] = Array( | $heuristics["HISTORY_LOW_TRANSACTIONS_SUPPLIER"] = Array( |
"description" => "unusual for supplier due to previous low number of transactions " | "description" => "unusual for supplier due to previous low number of transactions " |
); | ); |
function HISTORY_LOW_TRANSACTIONS_SUPPLIER($cn) | function HISTORY_LOW_TRANSACTIONS_SUPPLIER($cn) |
{ | { |
$thisSupplierTransactions = getSupplierTransactions($cn['supplierName'], $cn['supplierABN']); | $thisSupplierTransactions = getSupplierTransactions($cn['supplierName'], $cn['supplierABN']); |
$averageSupplierTransactions = getAverageSupplierTransactions(); | $averageSupplierTransactions = getAverageSupplierTransactions(); |
$stddevSupplierTransactions = getstddevSupplierTransactions(); | $stddevSupplierTransactions = getstddevSupplierTransactions(); |
$diff = strtotime($cn['contractEnd']) - strtotime($cn['contractStart']); | $diff = strtotime($cn['contractEnd']) - strtotime($cn['contractStart']); |
$days = intval($diff / (60 * 60 * 24)); | $days = intval($diff / (60 * 60 * 24)); |
$value = abs($days - $averageSupplierTransactions) / $stddevSupplierTransactions; | $value = abs($days - $averageSupplierTransactions) / $stddevSupplierTransactions; |
return Array( | return Array( |
"heuristic_value" => $value, | "heuristic_value" => $value, |
"raw_value" => $days, | "raw_value" => $days, |
"mean" => $averageSupplierTransactions, | "mean" => $averageSupplierTransactions, |
"stddev" => $stddevSupplierTransactions | "stddev" => $stddevSupplierTransactions |
); | ); |
} | } |
$supplierTransactions = Array(); | $supplierTransactions = Array(); |
function getSupplierTransactions($supplierName, $supplierABN) | function getSupplierTransactions($supplierName, $supplierABN) |
{ | { |
global $supplierTransactions; | global $supplierTransactions,$conn; |
if ($supplierABN != 0 && $supplierABN != "") { | if ($supplierABN != 0 && $supplierABN != "") { |
if (!$supplierTransactions[$supplierABN]) { | if (!$supplierTransactions[$supplierABN]) { |
$query = 'select count(*) from contractnotice where supplierABN = "' . $supplierABN . '"'; | $query = "select count(*) from contractnotice where \"supplierABN\" = '" . $supplierABN . "'"; |
$result = $conn->query($query); | $result = $conn->query($query); |
$r = $result->fetch(PDO::FETCH_BOTH); | $r = $result->fetch(PDO::FETCH_BOTH); |
$supplierTransactions[$supplierABN] = $r[0]; | $supplierTransactions[$supplierABN] = $r[0]; |
} | } |
return $supplierTransactions[$supplierABN]; | return $supplierTransactions[$supplierABN]; |
} | } |
if (!$supplierTransactions[$supplierName]) { | if (!$supplierTransactions[$supplierName]) { |
$query = 'select count(*) from contractnotice where supplierName = "' . $supplierName . '"'; | $query = "select count(*) from contractnotice where \"supplierName\" = '" . $supplierName . "'"; |
$result = $conn->query($query); | $result = $conn->query($query); |
$r = $result->fetch(PDO::FETCH_BOTH); | $r = $result->fetch(PDO::FETCH_BOTH); |
$supplierTransactions[$supplierName] = $r[0]; | $supplierTransactions[$supplierName] = $r[0]; |
} | } |
return $supplierTransactions[$supplierName]; | return $supplierTransactions[$supplierName]; |
} | } |
$averageSupplierTransactions; | $averageSupplierTransactions; |
function getAverageSupplierTransactions() | function getAverageSupplierTransactions() |
{ | { |
global $averageSupplierTransactions; | global $averageSupplierTransactions; |
if (!$averageSupplierTransactions) { | if (!$averageSupplierTransactions) { |
getStatsSupplierTransactions(); | getStatsSupplierTransactions(); |
} | } |
return $averageSupplierTransactions; | return $averageSupplierTransactions; |
} | } |
$stddevSupplierTransactions; | $stddevSupplierTransactions; |
function getstddevSupplierTransactions() | function getstddevSupplierTransactions() |
{ | { |
global $stddevSupplierTransactions; | global $stddevSupplierTransactions; |
if (!$stddevSupplierTransactions) { | if (!$stddevSupplierTransactions) { |
getStatsSupplierTransactions(); | getStatsSupplierTransactions(); |
} | } |
return $stddevSupplierTransactions; | return $stddevSupplierTransactions; |
} | } |
function getStatsSupplierTransactions() | function getStatsSupplierTransactions() |
{ | { |
global $averageSupplierTransactions, $stddevSupplierTransactions; | global $averageSupplierTransactions, $stddevSupplierTransactions,$conn; |
$query = 'select avg(count), stddev(count) from (select IF(supplierABN != "",supplierABN,supplierName) as supplierID, count(*) as count from contractnotice group by supplierID) as a;'; | $query = 'select avg(count), stddev(count) from ( |
select (case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as "supplierID", | |
count(*) as count from contractnotice group by "supplierID") as a;'; | |
$result = $conn->query($query); | $result = $conn->query($query); |
$r = $result->fetch(PDO::FETCH_BOTH); | $r = $result->fetch(PDO::FETCH_BOTH); |
$averageSupplierTransactions = $r[0]; | $averageSupplierTransactions = $r[0]; |
$stddevSupplierTransactions = $r[1]; | $stddevSupplierTransactions = $r[1]; |
} | } |
<?php | <?php |
if (php_sapi_name() != "cli") { | if (php_sapi_name() != "cli") { |
include_once ("../lib/common.inc.php"); | include_once ("../lib/common.inc.php"); |
auth(); | auth(); |
include_once("heuristics.inc.php"); | include_once("heuristics.inc.php"); |
$query = 'SELECT *, agency.abn as "agencyABN", case when "supplierABN" != 0 then "supplierABN"::text else "supplierName" end as "supplierID" | // agency table missing JOIN agency ON contractnotice."agencyName" |
FROM contractnotice JOIN agency ON contractnotice."agencyName"=agency."agencyName" | $query = 'SELECT *, case when "supplierABN" != 0 then "supplierABN"::text else "supplierName" end as "supplierID" |
FROM contractnotice | |
WHERE DATE("importDate") = (select * from (SELECT DATE("importDate") | WHERE DATE("importDate") = (select * from (SELECT DATE("importDate") |
FROM contractnotice ORDER BY "importDate" DESC limit 1) alias) limit 10'; | FROM contractnotice ORDER BY "importDate" DESC limit 1) alias) limit 100'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
foreach ($query->fetchAll() as $cn) { | foreach ($query->fetchAll() as $cn) { |
//get each new CN from latest update | //get each new CN from latest update |
foreach ($heuristics as $heuristic => $description) { | foreach ($heuristics as $heuristic => $description) { |
// run all heuristics | // run all heuristics |
runHeuristic($heuristic, $cn); | runHeuristic($heuristic, $cn); |
} | } |
flush(); | flush(); |
} | } |
/*foreach agency | /*foreach agency |
aggregate agency metrics | aggregate agency metrics |
foreach supplier | foreach supplier |
aggreate supplier metrics | aggreate supplier metrics |
foreach CN | foreach CN |
aggregate CN metrics */ | aggregate CN metrics */ |
} | } |
?> | ?> |
<?php | <?php |
/* - large contract value | |
- standard dev from mean/median | /* - large contract value |
- percent of total contracts for supplier/agency*/ | - standard dev from mean/median |
$heuristics["VALUE_LARGE_CONTRACT_OVERALL"] = Array( | - percent of total contracts for supplier/agency */ |
"description" => "unusual value for time of year"); | $heuristics["VALUE_LARGE_CONTRACT_OVERALL"] = Array( |
function METADATA_DUPLICATED_DESCRIPTION($cn) | "description" => "unusual value for time of year"); |
{ | |
$averageContractPeriod = getAverageContractPeriod(); | function VALUE_LARGE_CONTRACT_OVERALL($cn) { |
$diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); | $averageContractPeriod = getAverageContractPeriod(); |
$days = intval($diff / 24); | $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); |
return ($days > 45 ? 1 : 0); | $days = intval($diff / 24); |
return ($days > 45 ? 1 : 0); | |
} | } |
/* - peculiar value | /* - peculiar value |
- Just under 80k, amplified if other contracts with same supplier are just under | - Just under 80k, amplified if other contracts with same supplier are just under |
*/ | */ |
$heuristics["VALUE_NEAR_THRESHOLD"] = Array( | $heuristics["VALUE_NEAR_THRESHOLD"] = Array( |
"description" => "unusual value for time of year"); | "description" => "unusual value for time of year"); |
/* | /* |
- unusual variation amount - absolute value; large reductions as well as large increases | - unusual variation amount - absolute value; large reductions as well as large increases |
*/ | */ |
$heuristics["VALUE_LARGE_VARIATION"] = Array( | $heuristics["VALUE_LARGE_VARIATION"] = Array( |
"description" => "unusual value for time of year"); | "description" => "unusual value for time of year"); |
function METADATA_DUPLICATED_DESCRIPTION($cn) | |
{ | function VALUE_LARGE_VARIATION($cn) { |
$averageContractPeriod = getAverageContractPeriod(); | $averageContractPeriod = getAverageContractPeriod(); |
$diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); | $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); |
$days = intval($diff / 24); | $days = intval($diff / 24); |
return ($days > 45 ? 1 : 0); | return ($days > 45 ? 1 : 0); |
} | } |
/* - unusual value for time of year | /* - unusual value for time of year |
- compare to all other records in last 2 weeks | - compare to all other records in last 2 weeks |
- ie. many large contracts in june so takes more to standout*/ | - ie. many large contracts in june so takes more to standout */ |
$heuristics["VALUE_HIGH_FOR_MONTH"] = Array( | $heuristics["VALUE_HIGH_FOR_MONTH"] = Array( |
"description" => "unusual value for time of year" | "description" => "unusual value for time of year" |
); | ); |
function VALUE_HIGH_FOR_MONTH($cn, $monthAsInt) | |
{ | function VALUE_HIGH_FOR_MONTH($cn, $monthAsInt) { |
$averageContractPeriod = getAverageContractPeriod(); | $averageContractPeriod = getAverageContractPeriod(); |
$diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); | $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); |
$days = intval($diff / 24); | $days = intval($diff / 24); |
return ($days > 45 ? 1 : 0); | return ($days > 45 ? 1 : 0); |
} | } |
$monthlyValueAverage = Array(); | $monthlyValueAverage = Array(); |
function getAgencyTransactions($agencyName) | |
{ | function getAgencyTransactions($agencyName) { |
global $agencyTransactions; | global $agencyTransactions; |
if (!$agencyTransactions[$agencyName]) { | if (!$agencyTransactions[$agencyName]) { |
$query = 'select count(*) from contractnotice where agencyName = "' . $agencyName . '"'; | $query = 'select count(*) from contractnotice where agencyName = "' . $agencyName . '"'; |
$result = $conn->query($query); | $result = $conn->query($query); |
$r = $result->fetch(PDO::FETCH_BOTH); | $r = $result->fetch(PDO::FETCH_BOTH); |
$agencyTransactions[$agencyName] = $r[0]; | $agencyTransactions[$agencyName] = $r[0]; |
} | } |
return $agencyTransactions[$agencyName]; | return $agencyTransactions[$agencyName]; |
} | } |
?> | ?> |
<?php | <?php |
/*// most interesting | /*// most interesting |
SELECT sum(heuristic_value) as sum, CNID | SELECT sum(heuristic_value) as sum, CNID |
FROM heuristic_results group by CNID order by sum DESC limit 30 | FROM heuristic_results group by CNID order by sum DESC limit 30 |
// spread of values | // spread of values |
select floor(sum) as val,count(*) from (SELECT sum(heuristic_value) | select floor(sum) as val,count(*) from (SELECT sum(heuristic_value) |
as sum FROM heuristic_results group by CNID) as a group by val*/ | as sum FROM heuristic_results group by "CNID") as a group by val*/ |
$series = Array(); | $series = Array(); |
include_once("../lib/common.inc.php"); | include_once("../lib/common.inc.php"); |
$query = "select heuristic_name, floor(heuristic_value) as val,count(*) from heuristic_results group by heuristic_name, val"; | $query = "select heuristic_name, floor(heuristic_value) as val,count(*) from heuristic_results group by heuristic_name, val"; |
$result = $conn->query($query); | $result = $conn->query($query); |
foreach ($result->fetchAll() as $r) { | foreach ($result->fetchAll() as $r) { |
$series[$r["heuristic_name"]][$r["val"]] = $r[2]; | $series[$r["heuristic_name"]][$r["val"]] = $r[2]; |
} | } |
$labels = Array(); | |
foreach ($series as $value) { | |
$labels = $labels+array_keys($value); | |
} | |
$labels = Array(0,1,2,3,4,5); | |
foreach ($series as $seriesName => $seriesEntry) { | |
$data; | |
foreach ($labels as $label) { | |
$data[$label] = ($seriesEntry[$label] ? $seriesEntry[$label] : 0); | |
} | |
} | |
print_r($labels); | |
print_r($data); | |
?> | ?> |
<?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"); |
} | } |
define('ROOT', pathinfo(__FILE__, PATHINFO_DIRNAME)); | define('ROOT', pathinfo(__FILE__, PATHINFO_DIRNAME)); |
if (strstr($_SERVER['PHP_SELF'], "labs/") || strstr($_SERVER['PHP_SELF'], "admin/")) { | if (strstr($_SERVER['PHP_SELF'], "labs/") || strstr($_SERVER['PHP_SELF'], "admin/") || strstr($_SERVER['PHP_SELF'], "heuristics/")) { |
$basePath = "../"; | $basePath = "../"; |
} | } |
require $basePath."lib/amon-php/amon.php"; | require $basePath."lib/amon-php/amon.php"; |
Amon::config(array('address'=> 'http://127.0.0.1:2464', | Amon::config(array('address'=> 'http://127.0.0.1:2464', |
'protocol' => 'http', | 'protocol' => 'http', |
'secret_key' => "JBcSUdFOi5lK0vCjLjbHDpQamcBnRA4iV7QLaTADeDQ")); | 'secret_key' => "JBcSUdFOi5lK0vCjLjbHDpQamcBnRA4iV7QLaTADeDQ")); |
Amon::setup_exception_handler(); | 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'; |
$openid = new LightOpenID($_SERVER['HTTP_HOST']); | $openid = new LightOpenID($_SERVER['HTTP_HOST']); |
// you have to open the session to be able to modify or remove it | // you have to open the session to be able to modify or remove it |
session_start(); | session_start(); |
function login() { | function login() { |
global $openid; | global $openid; |
if (!$openid->mode) { | if (!$openid->mode) { |
$openid->required = array('contact/email'); | $openid->required = array('contact/email'); |
$openid->identity = 'https://www.google.com/accounts/o8/id'; | $openid->identity = 'https://www.google.com/accounts/o8/id'; |
header('Location: ' . $openid->authUrl()); | header('Location: ' . $openid->authUrl()); |
} | } |
} | } |
function auth() { | function auth() { |
global $openid; | global $openid; |
if ($_SESSION['authed'] == true) { | if ($_SESSION['authed'] == true) { |
return true; | return true; |
} | } |
if ($openid->mode) { | if ($openid->mode) { |
$attr = $openid->getAttributes(); | $attr = $openid->getAttributes(); |
if ($attr['contact/email'] != 'maxious@gmail.com') { | if ($attr['contact/email'] != 'maxious@gmail.com') { |
die('Access Denied'); | die('Access Denied'); |
} else { | } else { |
$_SESSION['authed'] = true; | $_SESSION['authed'] = true; |
} | } |
} else { | } else { |
login(); | login(); |
} | } |
} | } |
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
function databaseError($errMsg) { | function databaseError($errMsg) { |
if ($errMsg[2] != "") { | if ($errMsg[2] != "") { |
echo '<div class="alert-message error">'; | echo '<div class="alert-message error">'; |
Amon::log(print_r($errMsg, true).print_r($_REQUEST, true).print_r($_SERVER, true), array('error')); | Amon::log(print_r($errMsg, true).print_r($_REQUEST, true).print_r($_SERVER, true), array('error')); |
die(print_r($errMsg, true)); | die(print_r($errMsg, true)); |
echo "</div>"; | echo "</div>"; |
} | } |
} | } |
function ucsmart($str) { | function ucsmart($str) { |
$shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In" | $shortWords = Array("The", "Pty", "Ltd", "Inc", "Red", "Oil", "A", "An", "And", "At", "For", "In" |
, "Of", "On", "Or", "The", "To", "With"); | , "Of", "On", "Or", "The", "To", "With"); |
$strArray = explode(" ", preg_replace("/(?<=(?<!:|’s)\W) | $strArray = explode(" ", preg_replace("/(?<=(?<!:|’s)\W) |
(A|An|And|At|For|In|Of|On|Or|The|To|With) | (A|An|And|At|For|In|Of|On|Or|The|To|With) |
(?=\W)/e", 'strtolower("$1")', ucwords(strtolower($str)))); | (?=\W)/e", 'strtolower("$1")', ucwords(strtolower($str)))); |
foreach ($strArray as &$word) { | foreach ($strArray as &$word) { |
if (strlen($word) <= 4 && !in_array($word, $shortWords)) | if (strlen($word) <= 4 && !in_array($word, $shortWords)) |
$word = strtoupper($word); | $word = strtoupper($word); |
} | } |
return implode(" ", $strArray); | return implode(" ", $strArray); |
} | } |
function percent($num_amount, $num_total) { | function percent($num_amount, $num_total) { |
$count1 = $num_amount / $num_total; | $count1 = $num_amount / $num_total; |
$count2 = $count1 * 100; | $count2 = $count1 * 100; |
$count = number_format($count2, 2); | $count = number_format($count2, 2); |
return $count; | return $count; |
} | } |
function array_sum_all($a) { | function array_sum_all($a) { |
if (!is_array($a)) | if (!is_array($a)) |
return $a; | return $a; |
foreach ($a as $key => $value) | foreach ($a as $key => $value) |
$totale += array_sum_all($value); | $totale += array_sum_all($value); |
return $totale; | return $totale; |
} | } |
// magic query modifiers | // magic query modifiers |
$agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING); | $agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING); |
if ($agency != "") | if ($agency != "") |
$agencyQ = "agencyName = '" . $agency . "' AND "; | $agencyQ = "agencyName = '" . $agency . "' AND "; |
$supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING); | $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING); |
if ($supplier != "") { | if ($supplier != "") { |
$supplierParts = explode("-", $supplier); | $supplierParts = explode("-", $supplier); |
$supplierName = "%" . $supplierParts[1] . "%"; | $supplierName = "%" . $supplierParts[1] . "%"; |
$supplierABN = $supplierParts[0]; | $supplierABN = $supplierParts[0]; |
if ($supplierParts[0] > 0) | if ($supplierParts[0] > 0) |
$supplierQ = ' "supplierABN" = :supplierABN AND '; | $supplierQ = ' "supplierABN" = :supplierABN AND '; |
else | else |
$supplierQ = ' "supplierName" LIKE :supplierName AND '; | $supplierQ = ' "supplierName" LIKE :supplierName AND '; |
} | } |
$startYear = 2007; | $startYear = 2007; |
$year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT); | $year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT); |
if ($year != "") { | if ($year != "") { |
$yearQ = "YEAR(publishDate) = " . $year . " AND "; | $yearQ = "YEAR(publishDate) = " . $year . " AND "; |
} | } |
$standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010'; | $standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010'; |
$start = 0.0; | $start = 0.0; |
function local_url() { | function local_url() { |
return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/"; | return "http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/"; |
} | } |
function include_header($title) { | function include_header($title) { |
global $start; | global $start; |
?> | ?> |
<!DOCTYPE html> | <!DOCTYPE html> |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" version="XHTML+RDFa 1.1" | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" version="XHTML+RDFa 1.1" |
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" | xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" |
xmlns:gr="http://purl.org/goodrelations/v1#" | xmlns:gr="http://purl.org/goodrelations/v1#" |
xmlns:dc="http://purl.org/dc/terms/" | xmlns:dc="http://purl.org/dc/terms/" |
xmlns:pc="http://purl.org/procurement#" | xmlns:pc="http://purl.org/procurement#" |
xmlns:unspsc="http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#" | xmlns:unspsc="http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml#" |
xmlns:xsd="http://www.w3.org/2001/XMLSchema#" | xmlns:xsd="http://www.w3.org/2001/XMLSchema#" |
xmlns:pcdt="http://purl.org/procurement/public-contracts-datatypes#" | xmlns:pcdt="http://purl.org/procurement/public-contracts-datatypes#" |
prefix="rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# | prefix="rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# |
rdfs: http://www.w3.org/2000/01/rdf-schema# | rdfs: http://www.w3.org/2000/01/rdf-schema# |
gr: http://purl.org/goodrelations/v1# | gr: http://purl.org/goodrelations/v1# |
dcterms: http://purl.org/dc/terms/ | dcterms: http://purl.org/dc/terms/ |
pc: http://purl.org/procurement/public-contracts# | pc: http://purl.org/procurement/public-contracts# |
cpv: http://purl.org/weso/pscs/cpv/2008/resource/ | cpv: http://purl.org/weso/pscs/cpv/2008/resource/ |
unspsc: http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml# | unspsc: http://www.ksl.stanford.edu/projects/DAML/UNSPSC.daml# |
v: http://www.w3.org/2006/vcard/ns# | v: http://www.w3.org/2006/vcard/ns# |
payment: http://reference.data.gov.uk/def/payment# | payment: http://reference.data.gov.uk/def/payment# |
br: http://purl.org/business-register# | br: http://purl.org/business-register# |
xsd: http://www.w3.org/2001/XMLSchema# | xsd: http://www.w3.org/2001/XMLSchema# |
pcdt: http://purl.org/procurement/public-contracts-datatypes#"> | pcdt: http://purl.org/procurement/public-contracts-datatypes#"> |
<head> | <head> |
<title><?php echo $title; ?> - Contract Dashboard</title> | <title><?php echo $title; ?> - Contract Dashboard</title> |
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"> | <link rel="stylesheet" type="text/css" href="bootstrap.min.css"> |
<link rel="stylesheet" type="text/css" href="bootstrap-responsive.css"> | <link rel="stylesheet" type="text/css" href="bootstrap-responsive.css"> |
<!-- Le HTML5 shim, for IE6-8 support of HTML elements --> | <!-- Le HTML5 shim, for IE6-8 support of HTML elements --> |
<!--[if lt IE 9]> | <!--[if lt IE 9]> |
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> | <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> |
<![endif]--> | <![endif]--> |
<script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script> | <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" /> | <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> | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> |
<script type="text/javascript"> | <script type="text/javascript"> |
$(document).ready(function() | $(document).ready(function() |
{ | { |
//hide the all of the element with class msg_body | //hide the all of the element with class msg_body |
$(".msg_body").hide(); | $(".msg_body").hide(); |
//toggle the componenet with class msg_body | //toggle the componenet with class msg_body |
$(".msg_head").click(function() | $(".msg_head").click(function() |
{ | { |
$(this).next(".msg_body").slideToggle(600); | $(this).next(".msg_body").slideToggle(600); |
}); | }); |
}); | }); |
</script> | </script> |
<style type="text/css" title="currentStyle"> | <style type="text/css" title="currentStyle"> |
@import "media/css/demo_table.css"; | @import "media/css/demo_table.css"; |
</style> | </style> |
<script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script> | <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" language="javascript" src="lib/bootstrap-dropdown.js"></script> |
<script type="text/javascript" charset="utf-8"> | <script type="text/javascript" charset="utf-8"> |
jQuery.fn.dataTableExt.aTypes.unshift( | jQuery.fn.dataTableExt.aTypes.unshift( |
function ( sData ) | function ( sData ) |
{ | { |
var sValidChars = "0123456789.-,"; | var sValidChars = "0123456789.-,"; |
var Char; | var Char; |
/* Check the numeric part */ | /* Check the numeric part */ |
for ( i=1 ; i<sData.length ; i++ ) | for ( i=1 ; i<sData.length ; i++ ) |
{ | { |
Char = sData.charAt(i); | Char = sData.charAt(i); |
if (sValidChars.indexOf(Char) == -1) | if (sValidChars.indexOf(Char) == -1) |
{ | { |
return null; | return null; |
} | } |
} | } |
/* Check prefixed by currency */ | /* Check prefixed by currency */ |
if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) | if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) |
{ | { |
return 'currency'; | return 'currency'; |
} | } |
return null; | return null; |
} | } |
); | ); |
jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) { | 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) */ | /* 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 x = a == "-" ? 0 : a.replace( /,/g, "" ); |
var y = b == "-" ? 0 : b.replace( /,/g, "" ); | var y = b == "-" ? 0 : b.replace( /,/g, "" ); |
/* Remove the currency sign */ | /* Remove the currency sign */ |
x = x.substring( 1 ); | x = x.substring( 1 ); |
y = y.substring( 1 ); | y = y.substring( 1 ); |
/* Parse and return */ | /* Parse and return */ |
x = parseFloat( x ); | x = parseFloat( x ); |
y = parseFloat( y ); | y = parseFloat( y ); |
return x - y; | return x - y; |
}; | }; |
jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) { | 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) */ | /* 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 x = a == "-" ? 0 : a.replace( /,/g, "" ); |
var y = b == "-" ? 0 : b.replace( /,/g, "" ); | var y = b == "-" ? 0 : b.replace( /,/g, "" ); |
/* Remove the currency sign */ | /* Remove the currency sign */ |
x = x.substring( 1 ); | x = x.substring( 1 ); |
y = y.substring( 1 ); | y = y.substring( 1 ); |
/* Parse and return */ | /* Parse and return */ |
x = parseFloat( x ); | x = parseFloat( x ); |
y = parseFloat( y ); | y = parseFloat( y ); |
return y - x; | return y - x; |
}; | }; |
$(document).ready(function() { | $(document).ready(function() { |
$('table').dataTable(); | $('table').dataTable(); |
} ); | } ); |
</script> | </script> |
<link type="text/css" rel="stylesheet" href="style.css"> | <link type="text/css" rel="stylesheet" href="style.css"> |
</head> | </head> |
<body> | <body> |
<div class="navbar"> | <div class="navbar"> |
<div class="navbar-inner"> | <div class="navbar-inner"> |
<div class="container-fluid"> | <div class="container-fluid"> |
<a class="brand" href="#">contract dashboard</a> | <a class="brand" href="#">contract dashboard</a> |
<ul class="nav"> | <ul class="nav"> |
<li><a href="displayAgency.php">agencies</a></li> | <li><a href="displayAgency.php">agencies</a></li> |
<li><a href="displaySupplier.php">suppliers</a></li> | <li><a href="displaySupplier.php">suppliers</a></li> |
<li><a href="displayCategory.php">categories</a></li> | <li><a href="displayCategory.php">categories</a></li> |
<li><a href="displayCalendar.php">time periods</a></li> | <li><a href="displayCalendar.php">time periods</a></li> |
<!-- <li class="dropdown"> | <!-- <li class="dropdown"> |
<a href="#" class="dropdown-toggle">metrics</a> | <a href="#" class="dropdown-toggle">metrics</a> |
<ul class="dropdown-menu">--> | <ul class="dropdown-menu">--> |
<li><a href="displayProcurementMethod.php">tenderm</a></li> | <li><a href="displayProcurementMethod.php">tenderm</a></li> |
<li><a href="displayConfidentialities.php">confidentiality</a></li> | <li><a href="displayConfidentialities.php">confidentiality</a></li> |
<li><a href="displayConsultancies.php">consultancies</a></li> | <li><a href="displayConsultancies.php">consultancies</a></li> |
<li><a href="displayAmendments.php">amendments</a></li> | <li><a href="displayAmendments.php">amendments</a></li> |
<li><a href="displayMap.php">geo</a></li> | <li><a href="displayMap.php">geo</a></li> |
</ul> | </ul> |
<form method="post" action="search.php" class="pull-right"> | <form method="post" action="search.php" class="pull-right"> |
<input type="text" id="searchKeyword" name="searchKeyword" value="" placeholder="Search" /> | <input type="text" id="searchKeyword" name="searchKeyword" value="" placeholder="Search" /> |
<input type="hidden" id="searchID" name="searchID" value=""/> | <input type="hidden" id="searchID" name="searchID" value=""/> |
</form> | </form> |
</div> | </div> |
</div><!-- /topbar-inner --> | </div><!-- /topbar-inner --> |
</div><!-- /topbar --> | </div><!-- /topbar --> |
</div><!-- /topbar-wrapper --> | </div><!-- /topbar-wrapper --> |
<script type="text/javascript"> | <script type="text/javascript"> |
var options_xml = { | var options_xml = { |
script: function (input) { return "search_autosuggest.php?input="+input; }, | script: function (input) { return "search_autosuggest.php?input="+input; }, |
varname:"input", | varname:"input", |
callback: function (obj) { document.getElementById('searchID').value = obj.id; } | 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> | </script> |
<div class="container-fluid"> | <div class="container-fluid"> |
<div class="row-fluid"> | <div class="row-fluid"> |
<div class="span3"> | <div class="span3"> |
<div class="well sidebar-nav"> | <div class="well sidebar-nav"> |
<li class="nav-header">Filter by:</li> | <li class="nav-header">Filter by:</li> |
<li>2008</li> | <li>2008</li> |
</div> | </div> |
</div> | </div> |
<div class="span9"> | <div class="span9"> |
<?php | <?php |
$start = (float) array_sum(explode(' ', microtime())); | $start = (float) array_sum(explode(' ', microtime())); |
} | } |
function include_footer() { | function include_footer() { |
global $start; | global $start; |
$end = (float) array_sum(explode(' ', microtime())); | $end = (float) array_sum(explode(' ', microtime())); |
echo '</div> <footer>' . "Processing time: " . sprintf("%.4f", ($end - $start)) . " seconds" . ' <footer>'; | echo '</div> <footer>' . "Processing time: " . sprintf("%.4f", ($end - $start)) . " seconds" . ' <footer>'; |
if (strpos($_SERVER['SERVER_NAME'], ".gs")) { | if (strpos($_SERVER['SERVER_NAME'], ".gs")) { |
?> | ?> |
<script type="text/javascript"> | <script type="text/javascript"> |
var _gaq = _gaq || []; | var _gaq = _gaq || []; |
_gaq.push(['_setAccount', 'UA-12341040-3']); | _gaq.push(['_setAccount', 'UA-12341040-3']); |
_gaq.push(['_trackPageview']); | _gaq.push(['_trackPageview']); |
(function() { | (function() { |
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
})(); | })(); |
</script> | </script> |
<?php | <?php |
} | } |
echo '</div> </div></body> </html>'; | echo '</div> </div></body> </html>'; |
} | } |
include ("graphs.inc.php"); | include ("graphs.inc.php"); |
<?php | <?php |
include ('lib/common.inc.php'); | include ('lib/common.inc.php'); |
$last_updated = date('Y-m-d',@filemtime('cbrfeed.zip')); | $last_updated['page'] = date('Y-m-d',@filemtime('index.php')); |
$sections = Array( | |
"agency", | |
"category", | |
"supplier", | |
"page" | |
); | |
header("Content-Type: text/xml"); | header("Content-Type: text/xml"); |
echo "<?xml version='1.0' encoding='UTF-8'?>"; | echo "<?xml version='1.0' encoding='UTF-8'?>"; |
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; | $result = $conn->query('SELECT title, to_char("lastUpdated",\'YYYY-MM-DD\') as "lastUpdated" from datasets'); |
foreach ($result->fetchAll() as $row) { | |
if ($row['title'] == "Contract Notices") { | |
$last_updated['agency'] = $row['lastUpdated']; | |
$last_updated['supplier'] = $row['lastUpdated']; | |
$last_updated['category'] = $row['lastUpdated']; | |
} | |
} | |
if (isset($_REQUEST['section']) == false) { | |
echo '<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" | |
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | |
foreach ($sections as $section) { | |
echo "<sitemap> | |
<loc>" . local_url() . "sitemap.xml.php?section=$section</loc> | |
<lastmod>" . $last_updated[$section] . '</lastmod></sitemap>'; | |
} | |
echo '</sitemapindex>'; | |
} else { | |
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; | |
if ($_REQUEST['section'] == "page") { | |
echo " <url><loc>".local_url()."index.php</loc><priority>1.0</priority></url>\n"; | echo " <url><loc>".local_url()."index.php</loc><priority>1.0</priority></url>\n"; |
foreach (scandir("./") as $file) { | foreach (scandir("./") as $file) { |
if (strpos($file,".php") !== false && $file != "index.php" && $file != "sitemap.xml.php") echo " <url><loc>".local_url()."$file</loc><priority>0.3</priority></url>\n"; | if (strpos($file,".php") !== false && $file != "index.php" && $file != "sitemap.xml.php") echo " <url><loc>".local_url()."$file</loc><priority>0.3</priority></url>\n"; |
} | } |
} | |
if ($_REQUEST['section'] == "agency") { | |
$result = $conn->query('SELECT DISTINCT "agencyName" from contractnotice'); | |
foreach ($result->fetchAll() as $row) { | |
echo " <url><loc>" . local_url() . "displayAgency.php?agency=" . urlencode($row['agencyName']) . "</loc> | |
<lastmod>" . $last_updated['agency'] . "</lastmod></url>\n"; | |
} | |
} | |
if ($_REQUEST['section'] == "supplier") { | |
$result = $conn->query('SELECT DISTINCT on ("supplierID") ( | |
case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as "supplierID", "supplierABN", "supplierName" from contractnotice'); | |
foreach ($result->fetchAll() as $row) { | |
$supplier = urlencode(stripslashes($row['supplierABN'] . '-' . $row['supplierName'])); | |
echo " <url><loc>" . local_url() . "displaySupplier.php?supplier=$supplier</loc> | |
<lastmod>" . $last_updated['supplier'] . "</lastmod></url>\n"; | |
} | |
} | |
if ($_REQUEST['section'] == "category") { | |
$result = $conn->query('SELECT distinct category FROM contractnotice;'); | |
foreach ($result->fetchAll() as $row) { | |
echo " <url><loc>" . local_url() . "displayCategory.php?category=".urlencode($row['category'])."</loc> | |
<lastmod>" . $last_updated['category'] . "</lastmod></url>\n"; | |
} | |
} | |
echo '</urlset>'; | echo '</urlset>'; |
} | |
?> | ?> |