//Code is under active development.
//Feel free to use at your own risk.
//No copyright asserted.
<?php
$start=microtime();
include_once("observer_functions_5.php");
if ($_GET['prowl']) {
if (!$db5) {include("../../db5_connect.php");}
$message = check_journal($_GET['prowl']);
if (!$message) { //echo "message11: ". $message ."<";
$icb_list=array();
$record=explode(" ",$_GET['prowl']);
$date = current($record);//echo "date=". $date ."<br />";
if ($keyword=="reverse") {
$rev_phrase = $date ." reverse ";
$date = next($record);
$keyword = next($record);
} else {
$sign = 1;
}
$keyword = next($record);
if ($keyword=="from") {
$from_icb=next($record);
$to_word= next($record);
if ($to_word=="to") {
$to_icb=next($record);
$amount=next($record);
if ($from_icb==$to_icb) {
$message = "The same entity is indicated in the from-to record fields.";
}
else if (!is_numeric($amount)) {
$message = "The submitted amount is not numeric.";
}
else {
$units = next($record); //echo "<br />units, amount=". $units .", ". $amount ."<br />";
if (substr($units,-1)!=".") {
$id=next($record);
}
list($message1,$from_tally_date) = check_brand($from_icb,$units);
list($message2,$to_tally_date) = check_brand($to_icb,$units);
if (!$from_tally_date AND !$to_tally_date) {
$message = $message1 ." ". $message2;
}
else {
if ($message1==$from_icb OR $message1=="external") {
$ledger_from = $message1;
}
else {$message = $message1;}
if ($message2==$to_icb OR $message2=="external") {
$ledger_to = $message2;
}
else {$message = $message1 ." ". $message2;}
}
}
}
}
else if ($keyword=="add" OR $keyword=="cut") { //this might have reporter also
$amount=next($record);
if (!is_numeric($amount)) {
$message = "The submitted amount is not numeric.";
}
else {
$units = next($record);
$other_keyword = next($record);
$main_icb = next($record);
$parameter = next($record);
$from_icb=$main_icb;
$to_icb=$main_icb;
if (substr($units,-1)!=".") {
$id=next($record);
}
list($message1,$from_tally_date) = check_brand($from_icb,$units);
if ($message1==$from_icb OR $message1=="external") {
$ledger_from = $message1;
}
else {
$message = $message1;
}
$ledger_to=""; //only one ledger would be updated
}
}
else if ($keyword=="set") {
$main_icb = next($record);
$param = next($record);
$to_word = next($record);
$param_value = next($record);
$units = trim(next($record));
$units = rtrim($units,".");
$from_icb=$main_icb;
$to_icb=$main_icb;
if ($param!="lastReportSHA1") {
$param_value = number_format($param_value,2,".","");
}
list($message1,$from_tally_date) = check_brand($from_icb,$units);
if ($message1==$from_icb OR $message1=="external") {
$ledger_from = $message1;
}
else {$message = $message1;}
$ledger_to=""; //only one ledger would be updated
}
else {
$message = "Record keyword was not recognized.";
}
if (!$message) {
$record = trim(implode(" ",$record));
if (substr($record,-1)!=".") {$record = $record .".";} //echo "rcd: ". $record ." ";
if ($main_icb) {
list($from_publ,$icb_list) = verify_record($main_icb,$units,$record,$icb_list);
}
else { //echo "here"; print_r($_GET);
list($from_publ,$icb_list) = verify_record($from_icb,$units,$record,$icb_list);
list($to_publ,$icb_list) = verify_record($to_icb,$units,$record,$icb_list);
}
if ($from_publ==0 AND $to_publ===0) {
$message = "Both ". $from_icb ." and ". $to_icb ." have not published the record yet.";
}
else if ($from_publ===1 AND $to_publ===0) {
$message = $to_icb ." has not published the record yet.";
if ($icb_list[$to_icb]) {
//notify reporter
}
}
else if ($from_publ===0 AND $to_publ===1) {
$message = $from_icb ." has not published the record yet.";
if ($icb_list[$from_icb]) {
//notify reporter
}
}
else if ($from_publ===0 AND !$to_publ) {
$message = $from_icb ." has not published the record yet.";
}
}
if (!$message) { //print_r($icb_list);
list($from_search_q,$from_reporter) = explode(",",$icb_list[$from_icb]);
list($to_search_q,$to_reporter) = explode(",",$icb_list[$to_icb]);
$from_reporter = addslashes($from_reporter);
$to_reporter = addslashes($to_reporter);
$reporter = isset($reporter)?addslashes($reporter):0;
list($message,$ref_log) = journal_entry($from_reporter,$to_reporter,$record,$reporter,0);
//a notary check is performed as a courtesy to non-registered brands
if ($ledger_from=="external" AND $ledger_to=="external") {
if (!$message) {
$message = "The record was entered in the journal. Please register ". $from_icb ." and/or ". $to_icb ." for the units of ". $units ." in order to post the record into an itemized report.";
}
}
else {
if (!$message) {
if ($from_reporter == $to_reporter) {
if ($from_reporter!="") {$notary = " [". $from_reporter ."]";}
}
else if ($from_reporter AND $to_reporter) {
$notary = " [". $from_reporter .",". $to_reporter ."]";
}
else if ($from_reporter) {
$notary = " [". $from_reporter ."]";
}
else if ($to_reporter) {
$notary = " [". $to_reporter ."]";
}
if ($ledger_from) {
$message3 = update_ledger($ledger_from,$units,$from_tally_date,":". time() ."\n". $record . $notary);
}
if ($ledger_to) {
$message4 = update_ledger($ledger_to,$units,$to_tally_date,":". time() ."\n". $record . $notary);
}
$message5 = update_journal($record);
if ($message3 OR $message4 OR $message5) {
$message = $message3 . $message4 . $message5;
}
else {
$message = "The record was successfully posted.";
}
}
}
}
}
}
else {
$_GET['prowl'] = "2008-10-22 from localhost/wordpress to localhost/currency 200.00 dollar #123abc";
}
?>
1