<?php

function UPDATEDB() {
global $thiss,$error,$MENU_INIT,$AUTOBOK_EMAIL;
 $_POST['TAB_UPDATE_STAT']="1" ;
if($_SESSION['CURRENT_MENU']=="A_PROBLEM") {

// echo "CURRENT A_PROBLEM";
if(!($_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID]==$_SESSION[$thiss->DETECT_TABLE_COLUMN]['WIEVID'])) $ERROR=$ERROR . " BRAK_AUTORYZACJI_DLA_ID" ;
if(!(strstr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['FUNCPERMEDIT']['A_PROBLEM'],'W'))) $ERROR=$ERROR . " BRAK_UPRAWNIEN_DO [$thiss->DETECT_TABLE_COLUMN][FUNCPERMEDIT][A_PROBLEM]=W" ;

if((strlen($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM'])>0) && (!($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM']=="UNVERIFIED"))) { 
 ZAP_SQL("select ADM_ACCOUNT from ADMIN_USERS where ADM_ACCOUNT='$_POST[T_WORKPOINTS_USER]' and A_STATUS='NORMAL' and ADM_TECH_WORKER!='NO' and ADM_COMPANY like '$_SESSION[ADM_COMPANY]'");
 if($_SESSION[MYSQL_NUM_ROWS]==1) $T_WORKPOINTS_USER_VAL="1";
//echo "HERE";
if((!(isset($ERROR))) && isset($_POST['A_PROBLEM']) && ($T_WORKPOINTS_USER_VAL==1) && (!($_POST['A_PROBLEM'])) && ($_POST['A_PROBLEM_DESC']) && ($_POST['T_WORKPOINTS_USER']) && ($_POST['T_WORKPOINTS_DATE']) && (isset($_POST['T_WORKPOINTS_VALUE'])) ) { 



	if(!($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM'])) $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM']="0" ; 
	if(!($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['P_ACCOUNT']) || ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['P_ACCOUNT']=="N/S;") ) $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['P_ACCOUNT']="0" ; 
	$T_WORKPOINTS_VALUE = $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['T_WORKPOINTS_VALUE'] + $_POST['T_WORKPOINTS_VALUE'] ;
	$P_ACCOUNT = $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['P_ACCOUNT'] + $_POST['P_ACCOUNT'] ;
	if(!($_POST['P_ACCOUNT'])) $_POST['P_ACCOUNT'] = "N/S;" ;
	if(isset($_POST['DO_APPOITMENT_CLEAR'])) $ZAP_SQL_APPOITMENT = "L_APPOITMENT_DATE='', L_APPOITMENT_USER='', L_APPOITMENT_PERIOD='', L_APPOITMENT_TYPE='', L_APPOITMENT_INFO=''";
	$A_PROBLEM_DATE=date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i) ;

		unset($ZAP_FIELD);
		unset($ZAP_VAL) ; unset($ZAP_UPD) ;
		//zapisanie dodatkowego info do bazy technicznej, ze wystawiono platny problem lub dano upust @2012-09-25
		if((isset($_POST['DO_DISCONNECT_REPORT']))&&(strlen($_POST['DO_DISCONNECT_REPORT_FROM'])>8) && (strlen($_POST['T_WORKPOINTS_DATE'])>8) ) {
			 $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM_DESC'].="(sys : DO_DISCONNECT_REPORT_FROM ".$_POST['DO_DISCONNECT_REPORT_FROM'].")";
			 $_POST['A_PROBLEM_DESC'].="(sys : DO_DISCONNECT_REPORT_FROM ".$_POST['DO_DISCONNECT_REPORT_FROM'].")";
		 	}
	    if((isset($_POST['T_WORKPOINTS_DATE']))&&(strlen($_POST['P_ACCOUNT'])>0)&&($_POST['P_ACCOUNT']<>"N/S;")) { 
	    			$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM_DESC'].="(sys : P_ACCOUNT ".$_POST['P_ACCOUNT'].")"; 
	    			$_POST['A_PROBLEM_DESC'].="(sys : P_ACCOUNT ".$_POST['P_ACCOUNT'].")";
	    	}



		if($_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC_TO_KEY']['P_ACCOUNT']) {
		$ZAP_FIELD.=" , P_ACCOUNT  ";
		$ZAP_VAL.="  , '".$_POST['P_ACCOUNT']."' ";
		$ZAP_UPD.=" , P_ACCOUNT='".$P_ACCOUNT."' " ;
		}
	$ZAP_SQL_HIST = "insert into ".$thiss->DETECT_TABLE_NAME."_HIST (ID, ID_USERS2, A_RECORD_UPDATE_DATE, A_RECORD_UPDATE_AUTHOR , A_PROBLEM, A_PROBLEM_DESC, T_WORKPOINTS_USER, T_WORKPOINTS_VALUE, T_WORKPOINTS_DATE, T_WORKPOINTS_TYPE $ZAP_FIELD ) values ('','" . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'] . "', '".date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i)."', '".$_SESSION['ADM_ACCOUNT']."', '$_POST[A_PROBLEM]', '$_POST[A_PROBLEM_DESC] ($_SESSION[ADM_ACCOUNT])', '$_POST[T_WORKPOINTS_USER]', '$_POST[T_WORKPOINTS_VALUE]', '$_POST[T_WORKPOINTS_DATE]','$_POST[T_WORKPOINTS_TYPE]' $ZAP_VAL )";
	$ZAP_SQL = "update ".$thiss->DETECT_TABLE_NAME." SET $ZAP_SQL_APPOITMENT,  A_RECORD_UPDATE_DATE='".date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i)."', A_RECORD_UPDATE_AUTHOR='".$_SESSION[ADM_ACCOUNT]."' ,  A_PROBLEM='$_POST[A_PROBLEM]', A_PROBLEM_DESC='$_POST[A_PROBLEM_DESC] ($_SESSION[ADM_ACCOUNT])', A_PROBLEM_DATE='$A_PROBLEM_DATE', T_WORKPOINTS_USER='$_POST[T_WORKPOINTS_USER]',T_WORKPOINTS_VALUE='$T_WORKPOINTS_VALUE', T_WORKPOINTS_DATE='$_POST[T_WORKPOINTS_DATE]',T_WORKPOINTS_TYPE='$_POST[T_WORKPOINTS_TYPE]' $ZAP_UPD  where ID='" . $_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID] . "'";

	ZAP_SQL_UPDATE($ZAP_SQL_HIST); $RESULT=$_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;
	ZAP_SQL_UPDATE($ZAP_SQL); $RESULT=$RESULT + $_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;

	//TYP 14 - reklamacja

		//Wykrycie tabeli nazwy tabeli  SES_X_C
	if(substr($thiss->DETECT_TABLE_NAME,0,4)=='SES_' && substr($thiss->DETECT_TABLE_NAME,-2)=='_A') {
	
	//	echo "<h2>Detect table name=:".$thiss->DETECT_TABLE_NAME."</h2>";

     $SES_C_COLUMN=substr($thiss->DETECT_TABLE_NAME,0,(strlen($thiss->DETECT_TABLE_NAME)-1))."C" ;
     
     //$SES_C_COLUMN.="___C";
     //echo "<h2> SES_C_COLUMN_TO:: ".$SES_C_COLUMN." </h2>";

 	if((isset($_POST['DO_DISCONNECT_REPORT']))&&(strlen($_POST['DO_DISCONNECT_REPORT_FROM'])>8) && (strlen($_POST['T_WORKPOINTS_DATE'])>8) ) {
	  ZAP_SQL_UPDATE("insert into ".$SES_C_COLUMN." (ID,ID_SERVICES,ID_BILLING_USERS,TYPE,VALUE1,VALUE2) values
	  ('','".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_SERVICES']."','".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_BILLING_USERS']."','14','".$_POST['DO_DISCONNECT_REPORT_FROM']."','".$_POST['T_WORKPOINTS_DATE']."')") ;$RESULT+=$_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;
	}
	if((isset($_POST['T_WORKPOINTS_DATE']))&&(strlen($_POST['P_ACCOUNT'])>0)&&($_POST['P_ACCOUNT']<>"N/S;")) {
	  ZAP_SQL_UPDATE("insert into ".$SES_C_COLUMN." (ID,ID_SERVICES,ID_BILLING_USERS,TYPE,VALUE1,VALUE2) values
	  ('','".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_SERVICES']."','".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_BILLING_USERS']."','15','".$_POST['T_WORKPOINTS_DATE']."','".$_POST['P_ACCOUNT']."')") ;$RESULT+=$_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;
	}
	}
     echo "PASSED($RESULT)<hr>";

   } else {

	 echo "<h2>Podano zle zmienne lub nie wypelniono wszystkich pol(1)</h2><br>Errory: $ERROR<br>"; 
	print_r($_POST) ;

          }
echo "<br>USUWAM PROBLEM<br>";
 } else if(strlen($_POST['A_PROBLEM'])>1) { //EOF if(strlen($_SESSION[USERS_COLUMN][EDITRECORD][A_PROBLEM])>0)
	if(!($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID']==$_SESSION[$thiss->DETECT_TABLE_COLUMN]['WIEVID'])) $ERROR=$ERROR . " BRAK_AUTORYZACJI_DLA_ID" ;
	if(!(strstr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['FUNCPERMEDIT']['A_PROBLEM'],'W'))) $ERROR=$ERROR . " BRAK_UPRAWNIEN_DO [$thiss->DETECT_TABLE_COLUMN][FUNCPERMEDIT][A_PROBLEM]=W" ;
	// ZAP_SQL("select ADM_ACCOUNT from ADMIN_USERS where ADM_ACCOUNT='$_POST[T_WORKPOINTS_USER]' and ADM_STATUS='NORMAL' and ADM_TECH_WORKER!='NO' and ADM_COMPANY like '$_SESSION[ADM_COMPANY]'");
	//if($_SESSION[MYSQL_NUM_ROWS]==1)
	  $T_WORKPOINTS_USER_VAL="1";

	if((!(isset($ERROR))) && ($T_WORKPOINTS_USER_VAL==1) && ($_POST['A_PROBLEM']) && ($_POST['A_PROBLEM_DESC']) && ($_POST['A_PROBLEM_DATE'])) { 
	$A_PROBLEM_DATE=date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i) ;
	$ZAP_SQL_HIST = "insert into ".$thiss->DETECT_TABLE_NAME."_HIST (ID, ID_USERS2, A_RECORD_UPDATE_DATE, A_RECORD_UPDATE_AUTHOR , A_PROBLEM, A_PROBLEM_DESC ) values ('','" . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'] . "', '".date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i)."', '".$_SESSION['ADM_ACCOUNT']."', '".$_POST['A_PROBLEM']."', '".$_POST['A_PROBLEM_DESC']." (".$_SESSION['ADM_ACCOUNT'].")')";
	$ZAP_SQL = "update ".$thiss->DETECT_TABLE_NAME." SET  A_RECORD_UPDATE_DATE='".date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i)."', A_RECORD_UPDATE_AUTHOR='".$_SESSION['ADM_ACCOUNT']."' ,   A_PROBLEM='".$_POST['A_PROBLEM']."', A_PROBLEM_DESC='".$_POST['A_PROBLEM_DESC']." (".$_SESSION['ADM_ACCOUNT'].")', A_PROBLEM_DATE='".$A_PROBLEM_DATE."'  where ID='" . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'] . "'";
//	echo "<hr>$ZAP_SQL_HIST<hr>$ZAP_SQL<hr>";
        ZAP_SQL_UPDATE($ZAP_SQL_HIST); $RESULT=$_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;
	ZAP_SQL_UPDATE($ZAP_SQL); $RESULT=$RESULT + $_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;

//$_SESSION[USERS_COLUMN][EDITRECORD][S_ALIAS]
   if(isset($_POST['A_DB_USER_PROBLEM_REPORT_S_ALIAS_INFO'])) { 
$A_DB_USER_PROBLEM_REPORT_S_ALIAS_INFO="Zostal zgloszony problem dla Twojego adresu, Typ problemu to ".$_POST['A_PROBLEM']." (".$_POST['A_PROBLEM_DESC']."). Jezeli z jakichs przyczyn chcial(a)bys go odwolac - np. usluga zaczela poprawnie funkcjonowac, odpowiedz na tego maila, kasujac cala tresc (mozesz dodatkowo umiescic opis, uzywajac zwrotu ^opis problemu^), pozostawiajac jedynie: 
Odwoluje problem z dnia $A_PROBLEM_DATE .";
mail($_SESSION['USERS_COLUMN']['EDITRECORD']['S_ALIAS'], 'Potwierdzenie zgloszenia problemu, Odwolaj go, jezeli zaczelo wszystko dzialac poprawnie.', $A_DB_USER_PROBLEM_REPORT_S_ALIAS_INFO, "From: $AUTOBOK_EMAIL Automatyczne Biuro Obslugi <$AUTOBOK_EMAIL>
Reply-To: $AUTOBOK_EMAIL") ;
   echo "<br>DODATKOWO WYSLANO WIADOMOSC UMOZLIWIAJACA SKASOWANIE PROBLEMU NA ". $_SESSION['USERS_COLUMN']['EDITRECORD']['S_ALIAS']." <br>";
   }
echo "PASSED(".$RESULT.")<hr>";
 } 
 else { echo "<h2>Podano zle zmienne lub nie wypelniono wszystkich pol</h2><br>Errory: ".$ERROR."<br>"; 
//	print_r($_POST);
          }
//echo "DODAJE PROBLEM";
 } else if((strlen($_POST['A_PROBLEM'])==0) && ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM']=="UNVERIFIED")) {
 echo "KASOWANIE PROBLEMU UNVERIFIED"; 
	if((!(isset($ERROR))) && (isset($_POST['A_PROBLEM'])) && ($_POST['A_PROBLEM_DESC']) && ($_POST['A_PROBLEM_DATE'])) { 
	$ZAP_SQL_HIST = "insert into ".$thiss->DETECT_TABLE_NAME."_HIST (ID, ID_USERS2, A_RECORD_UPDATE_DATE, A_RECORD_UPDATE_AUTHOR , A_PROBLEM, A_PROBLEM_DESC ) values ('','" . $_SESSION['USERS_COLUMN']['EDITRECORD']['ID'] . "', '".date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i)."', '".$_SESSION['ADM_ACCOUNT']."', '".$_POST['A_PROBLEM']."', '".$_POST['A_PROBLEM_DESC']."')";
	$ZAP_SQL = "update ".$thiss->DETECT_TABLE_NAME." SET  A_PROBLEM='".$_POST['A_PROBLEM']."', A_PROBLEM_DESC='".$_POST['A_PROBLEM_DESC']." (".$_SESSION['ADM_ACCOUNT'].")', A_PROBLEM_DATE='" . date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i)."'  where ID='" . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'] . "'";
//	echo "<hr>$ZAP_SQL_HIST<hr>$ZAP_SQL<hr>";
        ZAP_SQL_UPDATE($ZAP_SQL_HIST); $RESULT=$_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;
	ZAP_SQL_UPDATE($ZAP_SQL); $RESULT=$RESULT + $_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;
        }
 } //EOF else if(strlen($_SESSION[USERS_COLUMN][EDITRECORD][A_PROBLEM])>0)


 } 
 
/* else if($_SESSION['CURRENT_MENU']=="USERS_EDIT") {  //EOF if($_SESSION[CURRENT_MENU]==A_PROBLEM)

      if($_POST) {
       $ZAP_SQL_UPDATE = "update USERS2 set A_RECORD_UPDATE_DATE='".date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i)."',A_RECORD_UPDATE_AUTHOR='".$_SESSION[ADM_ACCOUNT]."'";
       $ZAP_SQL_HISTORY_F = "insert into USERS2_HIST (ID,A_RECORD_UPDATE_DATE,A_RECORD_UPDATE_AUTHOR,ID_USERS2";
       $ZAP_SQL_HISTORY_V = ") values ('','".date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i)."','".$_SESSION['ADM_ACCOUNT']."','".$_SESSION[USERS_COLUMN][WIEVID]."'";

       foreach ($_SESSION[$thiss->DETECT_TABLE_COLUMN][DESC] as $value) {
        if(strstr($_SESSION[$thiss->DETECT_TABLE_COLUMN][PERMEDIT]["$value"],W)) $_SESSION[$thiss->DETECT_TABLE_COLUMN][EDIT_TEMPLATE][$value]=$_POST[$value]; 
	 if(($_SESSION[$thiss->DETECT_TABLE_COLUMN][WIEVID]==$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID]) && (isset($_POST["$value"])) &&  (!($_POST["$value"]==$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][$value]))) {
  	  if(($_SESSION[$thiss->DETECT_TABLE_COLUMN][TYPESPECIAL][$value])) { 
 	    $_SESSION[$thiss->DETECT_TABLE_COLUMN][TYPESPECIAL][$value](POST_VERIFY) ;
	  }
	 }
	}

       foreach ($_SESSION[USERS_COLUMN]['DESC'] as $value) {
	if(($_SESSION[USERS_COLUMN][WIEVID]==$_SESSION[USERS_COLUMN][EDITRECORD][ID]) &&(isset($_POST["$value"])) && ($_POST["$value"]!=$_SESSION[USERS_COLUMN][EDITRECORD]["$value"]) && (strstr($_SESSION[USERS_COLUMN][PERMEDIT]["$value"],'W'))) { 
	 $ZAP_SQL_UPDATE = $ZAP_SQL_UPDATE . ",$value='".$_POST["$value"]."' ";
 	 $ZAP_SQL_HISTORY_F = $ZAP_SQL_HISTORY_F . ",$value";
 	 $ZAP_SQL_HISTORY_V = $ZAP_SQL_HISTORY_V . ",'". $_POST["$value"]. "'";
//  	 $_SESSION[USERS_COLUMN][FIND]["$value"] = $_POST[$value]  ;
//	 $_SESSION[USERS_COLUMN][FINDSQL] = $_SESSION[USERS_COLUMN][FINDSQL] . " and $value like '$_POST[$value]' ";
	 }
       } //EOF foreach1
      } //EOF post
      $ZAP_SQL_HISTORY = $ZAP_SQL_HISTORY_F . $ZAP_SQL_HISTORY_V . ");" ;
      $ZAP_SQL_UPDATE = $ZAP_SQL_UPDATE . " where ID='" . $_SESSION['USERS_COLUMN']['WIEVID'] . "' " ;
      //echo "<hr>$ZAP_SQL_UPDATE<hr>$ZAP_SQL_HISTORY<hr>";
       if(!($error)) {
      ZAP_SQL_UPDATE($ZAP_SQL_HISTORY); $RESULT=$_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;
      ZAP_SQL_UPDATE($ZAP_SQL_UPDATE); $RESULT=$RESULT + $_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;
      echo "PASSED($RESULT)<hr>";
       }
 } 
 */
 
 else if(($_SESSION['CURRENT_MENU']=="NEW_EXTRA_SERVICES")) {  //EOF if($_SESSION[CURRENT_MENU]==USERS_EDIT)


  echo "AKTUALIZACJA DLA [CURRENT_MENU]==NEW_EXTRA_SERVICES";
       $ZAP_SQL_INSERT_F = "insert into $thiss->DETECT_TABLE_NAME (ID,A_RECORD_UPDATE_DATE,A_RECORD_UPDATE_AUTHOR,A_RECORD_CREATE_DATE,A_RECORD_CREATE_AUTHOR";
       $ZAP_SQL_INSERT_V = ") values ('','".date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i)."','".$_SESSION[ADM_ACCOUNT]."','".date(Y)."-".date(m)."-".date(d)."-".date(H).":".date(i)."','".$_SESSION[ADM_ACCOUNT]."'";

  foreach ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC'] as $value) {
  // echo "";
     if(isset($_POST[$value])) { 
      $_SESSION[$thiss->DETECT_TABLE_COLUMN]['NEWDEAL'][$value]=$_POST[$value];
      $ZAP_SQL_INSERT_F = $ZAP_SQL_INSERT_F . ",$value";
      $ZAP_SQL_INSERT_V = $ZAP_SQL_INSERT_V . ",'". $_POST["$value"]. "'";      
     }
  }
  $ZAP_SQL_INSERT = $ZAP_SQL_INSERT_F . $ZAP_SQL_INSERT_V . ");" ;
echo "**** $ZAP_SQL_INSERT *** TODO ***";
//  ZAP_SQL_UPDATE($ZAP_SQL_INSERT); $RESULT=$_SESSION[MYSQL_UPDATE_NUM_ROWS] ;
 }
else if ($_SESSION['CURRENT_MENU'] == 'M_DIST_DESC_HTML') {
	//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">edit - thiss: ';print_r($thiss);echo'</pre>';
	if ($thiss->DETECT_TABLE_NAME == 'IN7_MK_BAZA_DYSTRYBUCJI'  // aktualna tabela to IN7_MK_BAZA_DYSTRYBUCJI
			&& array_key_exists('M_DIST_DESC_HTML', $_REQUEST)  // sa dane w requescie
			&& $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'] > 0  // jest ID edytowanego rekordu
	) {
		global $thiss, $conn;
		$obj = new stdClass();
		$obj->ID = $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'];
		$obj->A_RECORD_CREATE_DATE = date('Y')."-".date('m')."-".date('d')."-".date('H').":".date('i');
		$obj->A_RECORD_CREATE_AUTHOR = $_SESSION['ADM_ACCOUNT'];
		$obj->A_RECORD_UPDATE_DATE = date('Y')."-".date('m')."-".date('d')."-".date('H').":".date('i');
		$obj->A_RECORD_UPDATE_AUTHOR = $_SESSION['ADM_ACCOUNT'];
		$field = 'M_DIST_DESC_HTML';
		$obj->M_DIST_DESC_HTML = $_REQUEST[$field];
		$obj->M_DIST_DESC_HTML = addslashes($_REQUEST[$field]);
		//$obj->M_DIST_DESC_HTML = mysql_real_escape_string($_REQUEST[$field], $conn);
		if ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPESPECIAL'][$field]) {
			$_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPESPECIAL'][$field]('POST_VERIFY', $obj->M_DIST_DESC_HTML);
		}

		$sql_set = array();// update
		$sql_set []= "`M_DIST_DESC_HTML`='" . $obj->M_DIST_DESC_HTML . "'";
		$sql_set []= "`A_RECORD_UPDATE_DATE`='" . $obj->A_RECORD_UPDATE_DATE . "'";
		$sql_set []= "`A_RECORD_UPDATE_AUTHOR`='" . $obj->A_RECORD_UPDATE_AUTHOR . "'";

		$sql_arr_hist = array();// insert into HIST table
		$sql_arr_hist['ID'] = "''";
		$sql_arr_hist['ID_USERS2'] = "'" . $obj->ID . "'";
		$sql_arr_hist['A_RECORD_CREATE_DATE'] = "'" . $obj->A_RECORD_CREATE_DATE . "'";
		$sql_arr_hist['A_RECORD_CREATE_AUTHOR'] = "'" . $obj->A_RECORD_CREATE_AUTHOR . "'";
		$sql_arr_hist['A_RECORD_UPDATE_DATE'] = "'" . $obj->A_RECORD_UPDATE_DATE . "'";
		$sql_arr_hist['A_RECORD_UPDATE_AUTHOR'] = "'" . $obj->A_RECORD_UPDATE_AUTHOR . "'";
		$sql_arr_hist['M_DIST_DESC_HTML'] = "'" . $obj->M_DIST_DESC_HTML . "'";

		if (!$error) {
			$ZAP_SQL_INSERT = "insert into `" . $thiss->DETECT_TABLE_NAME . "_HIST` (".implode(",", array_keys($sql_arr_hist)).") values(".implode(",", array_values($sql_arr_hist))."); ";
			$ZAP_SQL = "update `" . $thiss->DETECT_TABLE_NAME . "` set ".implode(",", $sql_set)." where `ID`='" . $obj->ID . "' limit 1; ";
//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">ZAP_SQL_INSERT: ';print_r($ZAP_SQL_INSERT);echo'</pre>';
//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">ZAP_SQL: ';print_r($ZAP_SQL);echo'</pre>';
			ZAP_SQL_UPDATE($ZAP_SQL); $RESULT = $_SESSION['MYSQL_UPDATE_NUM_ROWS'];
			ZAP_SQL_UPDATE($ZAP_SQL_INSERT); $RESULT = $RESULT + $_SESSION['MYSQL_UPDATE_NUM_ROWS'];
			if ($RESULT > 0) {// data saved
				$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['M_DIST_DESC_HTML'] = $obj->M_DIST_DESC_HTML;
			}
		}
	} else {
		// TODO: error
	}
}

//echo " Fnction UPDATEDB ";
//print_r($_POST);
//CREATE_MENU_INIT(USERS_FILTER_PROBLEM,PROBLEM,PROBLEMY);
echo "<h2>AKTUALIZACJA DANYCH: ";
$WYMAGANY_RESULT=2 ; if(isset($_POST['DO_DISCONNECT_REPORT'])) $WYMAGANY_RESULT++ ;
if((isset($_POST['T_WORKPOINTS_DATE']))&&(strlen($_POST['P_ACCOUNT'])>0)&&($_POST['P_ACCOUNT']<>"N/S;")) $WYMAGANY_RESULT++ ;
if($RESULT==$WYMAGANY_RESULT) echo "OK($RESULT)"; else { echo "ERROR($RESULT,$ERROR ".$error.")";
// print_r($_POST);
// print_r($_SESSION);
 }
echo "</h2>";
CREATE_MENUFUNC_NOTD_INIT($_SESSION['LAST_MENU'],'POWROT DO ' . $_SESSION['LAST_MENU']);
echo " | ";
CREATE_MENUFUNC_NOTD_INIT($_SESSION['CURRENT_MENU'],'POWROT DO ' . $_SESSION['CURRENT_MENU']);
if(!($RESULT==2)) {
 echo " | ";
 CREATE_MENUFUNC_INIT_2($_SESSION['CURRENT_MENU'],'','RESTORE','POWROT_I_POPRAWA_DANYCH') ;
 }
echo "<hr>";
 $MENU_INIT='MENU';

}

