<?php

function NADANIE_PROBLEMOW_FUNC() {
if (!$_GET['DODAJ_REKORDY_MIESZKAN']) {
//	die('404');
}
MENU();


echo "<br><hr>NADANIE_PROBLEMOW <form action='".$PHP_SELF."' method='GET'>";
echo "<input type=hidden name=ADD value=ADD>";
echo "<input type=hidden name=NADANIE_PROBLEMOW value=1>";
echo "100 rekordow (pokazane przykladowe dane optymalne dla biezacej daty 2007-09-01 oraz prowadzonej akcji \"przedluzenie umow dla istniejacego operatora\")<br>";
echo "  <input type=text name=M_REWIR size=30 value=$_GET[M_REWIR]> Okresl M_REWIR (np: GD.CH.F%)<br>";
echo " <input type=text name=A_PROBLEM_DESC size=50 value=\"$_GET[A_PROBLEM_DESC]\"> Wpisz opis problemu (np: \"TODO20070809HANDL: PRZEDLUZYC UMOWE\")<br>";
echo " <input type=text name=I_OPER_FIN size=50 value=\"$_GET[I_OPER_FIN]\"> Wpisz gorny termin zakonczenia umowy na internet (np: 2007-10-00 )<br>";
echo " <input type=text name=I_BAD_DATE size=50 value=\"$_GET[I_BAD_DATE]\"> Wpisz gorny termin daty waznosci badania danego rekordu (np: 2007-01-01 )<br>";
echo " <input type=text name=I_BAD_DATE_MIN size=50 value=\"$_GET[I_BAD_DATE_MIN]\"> Wpisz dolny termin daty waznosci badania danego rekordu (np: 0000-00-00 )<br>";
echo " <input type=text name=I_OPER size=50 value=\"$_GET[I_OPER]\"> Wpisz operatora biezacego internet dla ktorego chcesz przeprowadzic akcje (np: BN )<br>";
echo "<input type=submit name=ADD value=SZUKAJ><br>";

//if($_GET[I_BAD_DATE_MIN]=="0000-00-00")

$ZAP_SQL="create temporary table TEMP_MARKETING
select  t1.ID , t1.S_ADDRESS_STREET , t1.I_OPER, t1.I_OPER_FIN from USERS2_MARKETING as t1 
right join USERS2 as t2 on t2.S_ADDRESS_STREET=t1.S_ADDRESS_STREET
where
t2.A_STATUS='NORMAL' and
 t1.I_OPER='$_GET[I_OPER]' and
  ( t1.I_OPER_FIN='0000-00-00' or t1.I_OPER_FIN<'$_GET[I_OPER_FIN]' ) and
  ( t1.I_BAD_DATE<='$_GET[I_BAD_DATE]' )  and  ( t1.I_BAD_DATE>='$_GET[I_BAD_DATE_MIN]' )  and 
  t1.M_REWIR like '$_GET[M_REWIR]' and t1.A_PROBLEM=''	
group by t1.ID  
order by t1.I_OPER_FIN
  
  limit 100 ;";
if($_GET[M_REWIR]) {
 echo "<br> ZAP_SQL <br> $ZAP_SQL ";
 $conn=mysql_pconnect($INTERFACE_ADDR,$SQL_USER,$SQL_USER_PASS);
 if (!$conn) die("ERROR podczas tworzenia polaczenia do bazy $SQL_DATABASE !\n");
 mysql_select_db($SQL_DATABASE) or die("ERROR podczas wyboru bazy R50!");
 $result = mysql_query($ZAP_SQL,$conn) or die("Blad zapytania ZAP_SQL. * $ZAP_SQL *!");
 $result2 = mysql_query("select * from TEMP_MARKETING",$conn) or die("Blad zapytania ZAP_SQL. **!");
// ZAP_SQL("$ZAP_SQL");
 }
//$ZAP_SQL("select * from TEMP_MARKETING");

//print_r($result2);
echo "<table><tr><td>";
while($DWA=mysql_fetch_array($result2)) {



echo "<tr><td>".$DWA[0]."</td><td>".$DWA[1]."</td><td>".$DWA[2]."/".$DWA[3]."</td><td>".$DWA[4]."</td></tr>\n";

 }

echo "</td></tr>\n";


echo "</table>";
echo "<input type=submit name=ADD value=NADAJ_PROBLEMY><br>";
if($_GET[ADD]=="NADAJ_PROBLEMY") {
 echo "<br> NADAJE lub NADALEM PROBLEMY $ADM_RECORD_USER";
 $ZAP_SQL1="update USERS2_MARKETING as t1, TEMP_MARKETING as t2 set 
 t1.A_RECORD_UPDATE_AUTHOR='".$_SESSION['ADM_ACCOUNT']."' , t1.A_RECORD_UPDATE_DATE=now() , t1.A_PROBLEM_DATE=now() ,
 t1.A_PROBLEM='UNVERIFIED', t1.A_PROBLEM_DESC='$_GET[A_PROBLEM_DESC]'
 where t1.ID=t2.ID ;";

 $ZAP_SQL2="insert into USERS2_MARKETING_HIST (ID_USERS2,A_RECORD_UPDATE_DATE,A_RECORD_UPDATE_AUTHOR,A_PROBLEM,A_PROBLEM_DATE,A_PROBLEM_DESC)
 select ID,now(),'$ADM_ACCOUNT','UNVERIFIED',now(),'$_GET[A_PROBLEM_DESC]' from TEMP_MARKETING ;";
echo "ZAP_SQL $ZAP_SQL1 <br> $ZAP_SQL2";
if($_SESSION['ADM_ADMIN_LEVEL']>"1") echo "<font color=red><b>".$_SESSION['ADM_ADMIN_LEVEL']." ERROR BRAK UPRAWNIEN <BR></font>"; else$result3 = mysql_query($ZAP_SQL1,$conn) or die("Blad zapytania ZAP_SQL. *$ZAP_SQL*!");
if($_SESSION['ADM_ADMIN_LEVEL']>"1") echo "<font color=red><b>".$_SESSION['ADM_ADMIN_LEVEL']." ERROR BRAK UPRAWNIEN <BR></font>"; else$result4 = mysql_query($ZAP_SQL2,$conn) or die("Blad zapytania ZAP_SQL. *$ZAP_SQL*!");

 }


echo " </form>";


}