<?php

if($_GET['ANALIZA_HISTORII_DEALS']) {
echo "ANALIZA_HISTORII_ALL <form action=$PHP_SELF method=\"GET\">";
echo "<input type=hidden name=ADD value=ADD>";
echo "<input type=hidden name=ANALIZA_HISTORII_ALL value=1>";


echo "<table border=1><tr><td>";

echo "Dodaj Lancuch dla poszukiwan okresu , (zakoncz znakiem %) - 500 rekordow</td><td>  <input type=text name=A_RECORD_UPDATE_DATE size=10 value=$_GET[A_RECORD_UPDATE_DATE]></td>
<td>  <input type=text name=A_RECORD_UPDATE_AUTHOR  size=10 value=\"$_GET[A_RECORD_UPDATE_AUTHOR]\"></td>
</tr>";
echo "<tr><td colspan=1><input type=submit name=ADD value=SZUKAJ></td><td>DATA (np. 2007-%)</td><td>Autor (np. %sqix%)</td><td>OPER</td><td>OPER_FIN</td><td>OPER_ZAD</td></tr>";

$ZAP_SQL="SELECT t1.S_ADDRESS_STREET as S_ADDRESS_STREET_t1 ,
		   t2.* FROM USERS2_DEALS_HIST as t2 left join USERS2_DEALS as t1 on t1.ID=t2.ID_USERS2 where
		   
		    ( t2.A_RECORD_UPDATE_DATE like '".$_GET[A_RECORD_UPDATE_DATE]."' and t2.A_RECORD_UPDATE_AUTHOR like '".$_GET[A_RECORD_UPDATE_AUTHOR]."' )
		 		     
		     limit 5000
		     
		     ";
		     
		    
echo "$ZAP_SQL \n <br>";
if($_GET[A_RECORD_UPDATE_DATE]) ZAP_SQL("$ZAP_SQL");

 while($DWA=mysql_fetch_array($result)) {
 echo "<tr>\n";
    $AR=0;
//   print_r($DWA);
       if($DWA[A_PROBLEM]=='') $ARR[PROBLEM_CLEAR][$DWA[A_RECORD_UPDATE_AUTHOR]]++;
       else if($DWA[A_PROBLEM]!='N/S;') $ARR[PROBLEM_SET][$DWA[A_RECORD_UPDATE_AUTHOR]]++;
    foreach ($DWA as $DWA_A=>$DWA_V ) {
  		 if(($DWA_V!='N/S;')&&($DWA_A!=$AR)||($DWA_V=='S_ADDRESS_STREET_t1')) {
        	echo "<td> ".str_replace('_',' ',$DWA_A)." = $DWA_V </td>";   
	    	$ARR[STAT][$DWA[A_RECORD_UPDATE_AUTHOR]][$DWA_A]++;
            if($DWA_A=='A_RECORD_UPDATE_AUTHOR') $ARR[AUTH][$DWA_V]++;
     	 }
     if($DWA_A==$AR)$AR++;
	//echo "<tr><td>".$DWA[S_ADDRESS_STREET]." $DWA[P_NAME] $DWA[P_PHONE]  $DWA[S_ALIAS] ( $DWA[S_OTHER_INFO] ) </td><td>".$DWA[I_OPER_ZAINT]."</td><td>".$DWA[I_BAD_DATE]." ";
	//echo "</td><td>$DWA[I_OPER]</td><td>$DWA[I_OPER_FIN]</td><td>$DWA[I_OPER_ZAD] asdf</td></tr>";
    }
	echo "</tr>\n";
 }

echo "</table><pre>
Statystyka:
";

print_r($ARR);
unset($ARR);


    
$ZAP_SQL="SELECT  t2.* FROM USERS2_DEALS as t2 where
		 ( t2.A_RECORD_CREATE_DATE like '".$_GET['A_RECORD_UPDATE_DATE']."' and t2.A_RECORD_CREATE_AUTHOR like '".$_GET['A_RECORD_UPDATE_AUTHOR']."' )";
		if($_GET[A_RECORD_UPDATE_DATE]) ZAP_SQL($ZAP_SQL);
 while($DWA=mysql_fetch_object($result)) {
      foreach ($DWA as $DWA_A=>$DWA_V ) {
  		 if((($DWA_V!='')&&($DWA_V!='0'))&&($DWA_A!=$AR)||($DWA_V=='S_ADDRESS_STREET_t1')) {
        	//echo "<td> ".str_replace('_',' ',$DWA_A)." = $DWA_V </td>";   
	    	$ARR[STAT][$DWA->A_RECORD_CREATE_AUTHOR][$DWA_A]++;
            if($DWA_A=='A_RECORD_CREATE_AUTHOR') $ARR[AUTH][$DWA_V]++;
     	 }
     if($DWA_A==$AR)$AR++;
     }
    }

print_r($ARR);

echo "</pre>";

} //EOF IF

