//The complete free software package may be dowloaded from http://tyaga.org/kit/.
<?php

include_once("parser.php");

$start=microtime(true); 
$create=0;
$revert=0;
$inflow=0;
$outflow=0;
$cr_bal=0;
$db_bal=0;
$net_bal=0;
$start_db=0;
$start_cr=0;
$record_array=array(); //an array of arrays
$audit_results=array(); //an array of arrays

if (!$url) {
  
$url "reports/tyagaorg_2008_hour.txt";
}

if (isset(
$_POST['content'])) {
  
$src_content $_POST['content'];
}
else if (
$url) {
  
$src_content=file_get_contents($url);
}

list(
$message,$version_no,$model_name,$main_icb,$year,$native_units,$status,$content) = prowl_content($src_content,$query_icb,$query_units,$query_year); //echo "status, model_name: ". $status .", ". $model_name ."<br />";

if ($message) {
  echo 
$message;
}
else {
  
$record_array content_parse($content,$main_icb,$native_units,$year,4); //$record_array is array of arrays //reset($record_array);  

  
while (current($record_array) AND $i<2000) {    
    
$record current($record_array); //$record is an array
    
    
if (!$record['message']) {   
      
$keyword $record['keyword'];
      
$amount $record['sign']*$record['amount'];
          
      if (
$keyword=="from") {      
        if (
$record['from_icb']==$main_icb AND $record['to_icb']!=$main_icb) { //txn was an outflow            
          
$cr_bal=$cr_bal-$amount;
          
$outflow $outflow+$amount;
          
$net_bal=$net_bal-$amount;            
        }
        else if (
$record['from_icb']!=$main_icb AND $record['to_icb']==$main_icb) {
          
$db_bal=$db_bal-$amount;  
          
$inflow $inflow+$amount;
          
$net_bal=$net_bal+$amount;
        }        
        else {
          
$from_icb "<font color='red'>"$record['from_icb'] ."</font>";
          
$to_icb "<font color='red'>"$record['to_icb'] ."</font>";
        }                              
      }      
      else if (
$keyword=="add") {         
        
$cr_bal=$cr_bal+$amount;
        
$db_bal=$db_bal+$amount;   
        
$create $create+$amount;           
      } 
      else if (
$keyword=="cut") {
        
$cr_bal=$cr_bal-$amount;
        
$db_bal=$db_bal-$amount
        
$revert $revert $amount;             
      }    
      else if (
$keyword=="set") { 
        include(
"audit_tally.php");          
      }           
      else if (
$keyword=="tally") {
        if (
$record['param']=="unusedBudget") {        
          switch (
$record['sub_param']) {
            case 
".adds"$tally_amt valid_tally($record['amount'],$create); break;            
            case 
".cuts"$tally_amt valid_tally($record['amount'],$revert); break;                
            case 
".revenueBal"$tally_amt valid_tally($record['amount'],$db_bal); break;              
            case 
".expenseBal"$tally_amt valid_tally($record['amount'],$cr_bal); break;          
          }
        }       
        else {         
          switch (
$record['param']) {
            case 
"inflow"$tally_amt valid_tally($record['amount'],$inflow); break;                
            case 
"outflow"$tally_amt valid_tally($record['amount'],$outflow); break;                
            case 
"netBalance"$tally_amt valid_tally($record['amount'],$net_bal); break;
          }
        }
      }
              
      if (
$record['notary']) {
        
$notary explode(",",$record['notary']);
        
$http_context stream_context_create(array('http' => array('timeout'=>1,'method'=>'POST','content'=>"prowl=get+~"urlencode(substr($record['copy'],11)) ."~")));
                                        
        while (
current($notary)) {
          
$get_url "http://"current($notary) ."/";          
          
$link_contents = @file_get_contents($get_url,0,$http_context);          
                
          if (!
$link_contents) {
            
$link_note $link_note ."<a href=\""$get_url ."\">link not found</a> |";
          }
          else if (
strpos($link_contents,$record['copy'])===false) {
            
$link_note $link_note ."<a href=\""$get_url ."\">record not found</a> |";
          }
          else {
            
$link_note $link_note ."<a href=\""$get_url ."\">notarized</a> |";
          }
                      
          
next($notary);
        }
      }
      else {
        
$link_note "no links";
      }          
    } 
    
    if (
$record['message']) {
      
$audit_array[] = array($record['copy'],$record['message']); 
    }            
    else if (
$keyword=="tally") { 
      
$audit_array[] = array($record['copy'],$tally_amt $addl_mssg); 
    }
    else if (
$keyword=="set") { 
      
$audit_array[] = array($record['copy'],$set_verify $addl_mssg); 
    }      
    else {
      
$audit_array[] = array($record['copy'],$link_note $addl_mssg); 
    }
    
    
next($record_array);    
    
$i++;
    
$keyword"";
    
$amount "";
    
$link_note="";
    
$addl_mssg "";
  }


//The rest of the code are for presenting the results in the audit_array 
?>
  
<h4><a href="" onclick="toggle_disp('src_content'); return false;">Click here to View and Modify Source Data</a></h4>
<table align="center">
<tr align="center">
<td>
<form method="POST" action="" align="center" id="src_content" style="display: none;" >
<p>See what happens when period and amounts are changed, "ocaup" is changed to "cc", etc.</p>
<textarea name="content" rows="20" cols="100">
<?php echo $src_content?>
</textarea><br />
<input type="submit" name="submit" value="Submit">
</form>
</td>
</tr>
</table>
  
      
<table border="1" cellpadding="10" align="center">   
  <?php         
  
  
foreach($audit_array as $result) {
    
?>
    <tr>
      <td width="500"><?php echo current($result?></td>
      <td width="300"><?php echo next($result?></td>
    </tr>
    <?php
  
}

if (
trim($status)=="Pending") { 
  if (
$model_name=="ocaup") {
    
?>
    <tr align="center">
      <td colspan="2">
        <?php
        
echo "
        <b>unusedBudget.revenueBal</b> = {set} + {adds} - {cuts} - {inflow}<br /><b>"
.         
        
number_format($db_bal,2) ."</b> "$native_units ." = {".  number_format($start_db,2) ."} + {"number_format($create,2) ."} - {"number_format($revert,2) ."} - {"number_format($inflow,2) ."}<br /><br />
        <b>unusedBudget.expenseBal</b> = {set} + {adds} - {cuts} - {outflow}<br /><b>"
.         
        
number_format($cr_bal,2) ."</b> "$native_units ." = {".  number_format($start_cr,2) ."} + {"number_format($create,2) ."} - {"number_format($revert,2) ."} - {"number_format($outflow,2) ."}<br />";        
                
        
?>      
      </td>
    </tr>
    <?php
  
}
  else if (
$model_name=="cc") { //echo " line207 ";
    
?>
    <tr align="center">
      <td colspan="2">
        <?php
        
echo "<b>netBalance</b> = {set} + {inflow} - {outflow} <br /><b>".         
        
number_format($net_bal,2) ."</b> "$native_units ." = {".  number_format($start_net_bal,2) ."} + {"number_format($inflow,2) ."} - {"number_format($outflow,2) ."}<br /><br />";        
        
?>      
      </td>
    </tr>
    
    
    <?php
  
}
}

?>

</table>

<?php 

echo "<br />total time: ". (microtime(true)-$start) ."s";
?>
1