<?php

function HANDL_ANALIZA_HISTORII() {
?>
HANDL_ANALIZA_HISTORII <form action="index.php" method="GET">
<input type="hidden" name="MENU_INIT" value="HANDL_ANALIZA_HISTORII">
<input type="hidden" name="ADD" value="ADD">

<table border=1><tr><td>

<?php
echo "Dodaj Lancuch dla poszukiwan okresu , (zakoncz znakiem %) - 5500 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>";

$res = null;
$db = DB::getDB();
$ZAP_SQL="SELECT t1.S_ADDRESS_STREET as S_ADDRESS_STREET_t1 , t2.* FROM USERS2_MARKETING_HIST as t2 left join USERS2_MARKETING 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 5500 ";
echo "$ZAP_SQL \n <br>";
if ($_GET[A_RECORD_UPDATE_DATE]) {
	$res = $db->query("$ZAP_SQL");
}

echo "<hr>@2013-12-02 bindera: Uwaga jezeli ustalono T_WORKPOINTS_USER, to system dodaje raport do uzytkownika , ktorego wartosc zostala ustawiona w tym polu";
if ($res) while ($DWA = $db->fetch_array($res)) {
		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['T_WORKPOINTS_USER']!='N/S;') {
				   $DWA[A_RECORD_UPDATE_AUTHOR]=$DWA['T_WORKPOINTS_USER'];
				  if($DWA_A=='T_WORKPOINTS_USER') $ARR['STAT'][$DWA['T_WORKPOINTS_USER']]['WORKPOINTS']++;
		}

			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);
	echo "</pre>";
}
