//Code is under active development.
//Feel free to use at your own risk.
//No copyright asserted.
<?php
if (next($record)==$main_icb) {
$param = explode(".",next($record));
if ($param[0]=="lastReport") {
$sub_param = $param[1]; //echo "sub: ". $sub_param;
$to_word = next($record);
$param_value = next($record); //echo $param_value ." ". $tally['revenue-budget'];
if ($sub_param=="period" AND !$last_report) {
$period = rtrim($param_value,".");
if (!$reporter) {
list($search_q,$reporter) = get_reporter($main_icb,$native_units);
}
if ($reporter) {
$report_url = "http://". $reporter ."/?prowl=get+". $main_icb ."+". $native_units ."+report+for+". $period; //echo "report_url: ". $report_url;
$timeout = stream_context_create(array('http' => array('timeout'=>2)));
$last_report = @file_get_contents($report_url,0,$timeout); //echo "last report: ". $last_report;
if (!$last_report) {
$set_verify = "The reporter did not return any matching reports.";
}
else {
$last_content = explode("Prowl/version ",$last_report); //echo $last_content;
if (count($last_content)==1) {
$set_verify = "The <a href='". $report_url ."'>last report</a> was not formatted as a Prowl record.";
$last_report = "";
}
else {
$last_content = explode("\n",$last_content[1]);
$last_content = array_filter($last_content);
$version_no = current($last_content);
list($model_indicator,$last_model_name) = explode(": ",next($last_content));
list($report_icb,$report_units,$report_word,$for_word,$report_period,$last_status) = explode(" ",next($last_content));
if ($report_icb!=$main_icb OR $report_period!=($period .":") OR $report_units!=$native_units) {
$set_verify = "The <a href='". $report_url ."'>last report</a> did not match the query parameters of: ". $main_icb .", ". $year .", ". $native_units .".";
}
else {
$set_verify = "Verified <a href='". $report_url ."'>last report</a>";
}
}
}
}
else {
$set_verify = "The last report can not be located. Missing or malformed reporter declaration string on ". $main_icb ." home page.";
}
$record_copy = $date ." set ". $main_icb ." ". $param[0] .".". $sub_param ." to ". $param_value;
}
else if ($sub_param=="SHA1") {
$set_sha1 = rtrim($param_value,".");
$report_sha1 = sha1($last_report);
if ($report_sha1==$set_sha1) {
$set_verify = "<a href='". $report_url ."'>Verified</a>";
}
else {
$set_verify = "The set-sha1 did not match the calculated sha1 digest of the <a href='". $report_url ."'>last report</a>. (". $report_sha1 .")";
$create=0; $revert=0; $outflow=0; $inflow=0; $cr_bal=0; $db_bal=0; $headcount=0;
}
$record_copy = $date ." set ". $main_icb ." ". $param[0] .".". $sub_param ." to ". $set_sha1 .".";
}
else if ($sub_param=="filesize") {
$set_filesize = rtrim($param_value,".");
$units = trim(substr(next($record),0,-1));
$report_filesize = strlen($last_report);
if ($report_filesize==$param_value) {
$set_verify = "<a href='". $report_url ."'>Verified</a>";
}
else {
$set_verify = "The set-filesize did not match the calculated filesize of the <a href='". $report_url ."'>last report</a>. (". $report_filesize .")";
}
$record_copy = $date ." set ". $main_icb ." ". $param[0] .".". $sub_param ." to ". $set_filesize ." ". $units .".";
}
}
else if ($param[0]=="unusedBudget") {
$sub_param = $param[1];
$to_word = next($record);
$param_value = next($record); //echo $param_value ." ". $tally['revenue-budget'];
$units = trim(substr(next($record),0,-1)); //echo "<br />units= ". $units ."". $native_units;
if (!valid_amt_units($param_value,$units,$native_units)) {
$set_verify = "Incorrect amount or unit value.";
}
else {
$tally_record = explode("-12-31 tally unusedBudget.". $sub_param ." ",$last_report);
$tally_record = explode(" ",end($tally_record)); //echo "<br />tally_record[0] = ". $tally_record[0];
if ($tally_record[0] == $param_value) {
$set_verify = "<a href='". $report_url ."'>Verified</a>";
}
else {
$set_verify = "The unusedBudget.". $sub_param ." should be set to the last tallied value of <a href='". $report_url ."'>". number_format($tally_record[0],2) ."</a>.";
}
if ($sub_param=="revenueBal") {
$db_bal=$tally_record[0];
$start_db=$tally_record[0];
}
else if ($sub_param=="expenseBal") {
$cr_bal=$tally_record[0];
$start_cr=$tally_record[0];
}
}
}
else if ($param[0]=="headCount") {
$to_word = next($record);
$param_value = next($record);
$units = trim(next($record));
if (!is_numeric($param_value)) {
$set_verify = "The ". $param ." value is not numeric.";
}
else {
$tally_record = explode("-12-31 tally headCount ",$last_report);
$tally_record = explode(" ",trim(end($tally_record)));
if ($param_value==$tally_record[0]) {
$headcount = $param_value;
$set_verify = "<a href='". $report_url ."'>Verified</a>";
}
else {
$set_verify = "The headCount should be set to the last tallied value of <a href='". $report_url ."'>". $tally['headcount'] ."</a>.";
}
}
}
else if ($param[0]=="netBalance") {
$to_word = next($record);
$param_value = next($record);
$units = trim(next($record));
if (!is_numeric($param_value)) {
$set_verify = "The ". $param ." value is not numeric.";
}
else {
$tally_record = explode("-12-31 tally netBalance ",$last_report);
$tally_record = explode(" ",trim(end($tally_record)));
}
if ($tally_record[0] == $param_value) {
$set_verify = "<a href='". $ref_link ."'>Verified</a>";
$net_bal = $param_value;
$start_net_bal=$param_value;
}
else {
$set_verify = "The netBalance should be set to the last tallied value of <a href='". $report_url ."'>". number_format($tally_record[0],2) ."</a>.";
}
}
}
?>
1