<?php


if(!$_GET['DODAJ_WYNIK_ANKIETY']) {
	return;
}


echo "DODAWANIE WYNIKOW ANKIETY / BADANIA nazwa PAWLAK200603 <form action=$PHP_SELF method=\"GET\">";
$_SESSION['USERS2_MARKETING_COLUMN']['EDITRECORD']['T_WORKPOINTS_USER'] = $_GET['T_WORKPOINTS_USER'];
$_SESSION['USERS2_MARKETING_COLUMN']['EDITRECORD']['T_WORKPOINTS_DATE'] = $_GET['T_WORKPOINTS_DATE'];
$_SESSION['USERS2_MARKETING_COLUMN']['EDITRECORD']['T_WORKPOINTS_TYPE'] = $_GET['T_WORKPOINTS_TYPE'];

echo "Autor Badan: (Inicjaly Handlowca) <input type=text name=T_WORKPOINTS_USER value=".$_SESSION['USERS2_MARKETING_COLUMN']['EDITRECORD']['T_WORKPOINTS_USER'].">";

echo "<input type=hidden name=ADD value=ADD>";
echo "<input type=hidden name=DODAJ_WYNIK_ANKIETY value=1>";
echo "<table border=1><tr><td>";
echo "SKROT ULICY z Nr Budynku (np CI50/24 dla CIESZYNSKIEGO 50/24 ) :</td><td>  <input type=text name=S_ADDRESS_STREET size=20 value=$_GET[S_ADDRESS_STREET]></td></tr>";
echo "<tr><td colspan=2><input type=submit name=ADD value=SZUKAJ></td></tr>";
echo '</table>';
echo '<br />';
echo '<table border=1>';
if ($_GET['S_ADDRESS_STREET']) ZAP_SQL("SELECT * FROM USERS2_MARKETING where S_ADDRESS_STREET='".$_GET['S_ADDRESS_STREET']."' limit 1 ");

while ($DWA = mysql_fetch_array($result)) {

//echo "I_OPER to $DWA[I_OPER] ";
//print_r($_GET);

$NAME="I_BAD_DATE";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="I_OPER";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="I_OPER_ZAD";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="I_OPER_FIN";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="I_OPER_ZAINT";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="S_OTHER_INFO";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="T_BAD_DATE";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="T_OPER";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="T_OPER_ZAD";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="T_OPER_FIN";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="T_OPER_ZAINT";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";

$NAME="TV_BAD_DATE";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="TV_OPER";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="TV_OPER_ZAD";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="TV_OPER_FIN";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="TV_OPER_ZAINT";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";







$NAME="P_NAME";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";
$NAME="P_PHONE";$VALUE=$DWA[$NAME];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "</td></tr>";

$NAME="T_WORKPOINTS_USER";$VALUE=$_SESSION['USERS2_MARKETING_COLUMN']['EDITRECORD']['T_WORKPOINTS_USER'];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
//$_SESSION[USERS2_MARKETING_COLUMN][EDITRECORD][T_WORKPOINTS_USER]=$DWA[$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";T_WORKPOINTS_USER_SELECT();;echo "(DANE SUGEROWANE!)</td></tr>";

$NAME="T_WORKPOINTS_TYPE";$VALUE=$_SESSION['USERS2_MARKETING_COLUMN']['EDITRECORD']['T_WORKPOINTS_TYPE'];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "(DANE SUGEROWANE!)</td></tr>";
$NAME="T_WORKPOINTS_DATE";$VALUE=$_SESSION['USERS2_MARKETING_COLUMN']['EDITRECORD']['T_WORKPOINTS_DATE'];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
echo "<tr><td>$DESC_TO_LANG</td><td>";GETFORMITEM($VALUE,$TYPE,$NAME);echo "(DANE SUGEROWANE!)</td></tr>";
{// kolor dywanu
	$NAME="P_FLOOR_CONTROL";$VALUE=$_SESSION['USERS2_MARKETING_COLUMN']['EDITRECORD']['T_WORKPOINTS_TYPE'];$TYPE=$_SESSION['USERS2_MARKETING_COLUMN']['TYPE'][$NAME];$DESC_TO_LANG=$_SESSION['USERS2_MARKETING_COLUMN']['DESC_TO_LANG'][$NAME];
	if (empty($DESC_TO_LANG)) $DESC_TO_LANG = "Kolor dywanu";
	echo '<tr><td>' . $DESC_TO_LANG . '</td><td>';
		GETFORMITEM($VALUE, $TYPE, $NAME);
	echo '</td></tr>';
}
echo "<tr><td colspan=2><input type=submit name=ADD_VERIFIED value=ADD_VERIFIED></td></tr>";


if ($_GET['ADD_VERIFIED']) {
	$ZAP_UPD_VAL="update USERS2_MARKETING set ID=ID , A_RECORD_UPDATE_AUTHOR='".$_SESSION['AUTHORIZE_USER']."', A_RECORD_UPDATE_DATE=now()  ";
	$ZAP_UPD_HIST_FIELD="A_RECORD_UPDATE_DATE ,  A_RECORD_UPDATE_AUTHOR , ID_USERS2  ";
	$ZAP_UPD_HIST_VAL=" now() , '".$_SESSION['AUTHORIZE_USER']."' , ID  ";
	foreach ($_GET as $GET_KEY => $GET_VAL) {
		//     echo "  KEY: $GET_KEY VAL: $GET_VAL <br>\n";
		if (!in_array($GET_KEY, $_SESSION['USERS2_MARKETING_COLUMN']['DESC'])) {
			continue;
		}
		$ZAP_UPD_VAL.=" , $GET_KEY='$GET_VAL' ";
		if ((!strstr($DWA[$GET_KEY],"$GET_VAL")) || ($GET_KEY == "T_WORKPOINTS_USER") || ($GET_KEY == "T_WORKPOINTS_TYPE") ) {
			//        echo "!strstr($DWA[$GET_KEY],$GET_VAL)";
			$ZAP_UPD_HIST_FIELD.=", $GET_KEY ";
			$ZAP_UPD_HIST_VAL.=", '$GET_VAL' ";
		}
	}
	$ZAP_UPD_VAL.=" where S_ADDRESS_STREET='".$_GET['S_ADDRESS_STREET']."' limit 1 ; "  ;
	$ZAP_UPD_HIST="insert into USERS2_MARKETING_HIST  ( $ZAP_UPD_HIST_FIELD ) select $ZAP_UPD_HIST_VAL from USERS2_MARKETING where S_ADDRESS_STREET='".$_GET['S_ADDRESS_STREET']."' limit 1 ; "  ;

	//ZAP_SQL(" $ZAP_UPD_VAL ");
	ZAP_SQL(" $ZAP_UPD_VAL ");

	//echo "<br>UPDATE: $ZAP_UPD_VAL \n";
	//echo "<br>HISTORY: $ZAP_UPD_HIST \n";
	ZAP_SQL(" $ZAP_UPD_HIST ");

	if (mysql_affected_rows($result)) {
		echo "<br>AKTUALIZOWANO <b> ". mysql_affected_rows($result) ." </b> REKORDOW EOL <br>";
	}
	else {
		echo "<br><font color=red> ZAKTUALIZOWANO lub NIE REKORD, dla $_GET[S_ADDRESS_STREET] ???  </font><br>";
	}
}


}
echo "</table>";
