<?php


function TABLE_UPDATEDB() {
global $error,$thiss;

$REQUIRED_RESULT=2;

if($_SESSION['CURRENT_MENU']==$thiss->DETECT_EDIT_FUNCTION) {
	echo "<hr>f. TABLE_UPDATEDB - <hr>";
      if($_POST) {
       $ZAP_SQL_UPDATE = "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']."'";
       $ZAP_SQL_HISTORY_F = "insert into ".$thiss->DETECT_TABLE_NAME."_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[$thiss->DETECT_TABLE_COLUMN]['WIEVID']."'";



	



		//przywrocenie wartosci do edycji
       foreach ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC'] as $value) {
//     echo "*" . $_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD]["$value"] . "===" . $_POST["$value"] . ")***<br>" ;
			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(strstr($_SESSION[$thiss->DETECT_TABLE_COLUMN][PERMEDIT]["$value"],'W'))  $_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][$value]=$_POST[$value];
			if(($_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPESPECIAL'][$value])) { 
				SEF($_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPESPECIAL'][$value]);
			  $_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPESPECIAL'][$value]('POST_VERIFY') ;
			  }
			 }
		}

       foreach ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC'] as $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"]) && (strstr($_SESSION[$thiss->DETECT_TABLE_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[$thiss->DETECT_TABLE_COLUMN][FIND]["$value"] = $_POST[$value]  ;
//	 $_SESSION[$thiss->DETECT_TABLE_COLUMN][FINDSQL] = $_SESSION[$thiss->DETECT_TABLE_COLUMN][FINDSQL] . " and $value like '$_POST[$value]' ";
	 }
       } //EOF foreach1
      } //EOF post
   if(!($error)) {
      $ZAP_SQL_HISTORY = $ZAP_SQL_HISTORY_F . $ZAP_SQL_HISTORY_V . ");" ;
      $ZAP_SQL_UPDATE = $ZAP_SQL_UPDATE . " where ID='" . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['WIEVID'] . "' " ;
//      echo "<hr>$ZAP_SQL_UPDATE<hr>$ZAP_SQL_HISTORY<hr>";
      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>";
      
        //dopisanie do daty podlaczenia @2012-09-25 sqix jezeli byl result, ma uprawnienia, jest zmienna i jest to tym SES_X_A, to 
        if(($RESULT==2)&&(strstr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['PERMEDIT']['T_WHEN_CONNECTED'],"W"))&&($_REQUEST['T_WHEN_CONNECTED'])&&(substr($thiss->DETECT_TABLE_NAME,0,4)=='SES_' && substr($thiss->DETECT_TABLE_NAME,-2)=='_A')) {
                $SES_B_COLUMN=substr($thiss->DETECT_TABLE_NAME,0,(strlen($thiss->DETECT_TABLE_NAME)-1))."B" ;
                $REQUIRED_RESULT++;
				$ZAP_SQL_SES_B=" insert into ".$SES_B_COLUMN." (ID, ID_SERVICES, ID_BILLING_USERS, TIMESTAMP , TYPE , VALUE1 )";
				$ZAP_SQL_SES_B.=" select '',U.ID_SERVICES, SV.ID_BILLING_USERS, now(),'4','".$_REQUEST['T_WHEN_CONNECTED']."'";
				$ZAP_SQL_SES_B.=" from ".$thiss->DETECT_TABLE_NAME." as U ";
				$ZAP_SQL_SES_B.=" left join SERVICES as SV on SV.ID=U.ID_SERVICES";
				$ZAP_SQL_SES_B.=" where U.ID='".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID']."'";
				
				echo "<h2>Test zaktualizacji daty podlaczenia do L2 ZAP_SQL_SES_B to : ".$ZAP_SQL_SES_B."</h2>";
				ZAP_SQL_UPDATE($ZAP_SQL_SES_B); $RESULT=$RESULT+$_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;
				
			 	$REQUIRED_RESULT++; //dodaje dodatkowy wymog wykonania tego zapytania, dotyczacego aktualizacji statusow
				$ZAP_SQL_STATUS_SERVICES=" update SERVICES as SV , ".$thiss->DETECT_TABLE_NAME." as U  ";
				$ZAP_SQL_STATUS_SERVICES.="	set SV.A_STATUS='NORMAL', U.A_STATUS='NORMAL' ";
				$ZAP_SQL_STATUS_SERVICES.=" where U.ID_SERVICES=SV.ID and SV.A_STATUS='WAITING' and U.ID='".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID']."' ";
        		echo "<h2>Test zaktualizacji statusow do L2 ZAP_SQL_SES_B to : ".$ZAP_SQL_STATUS_SERVICES."</h2>";
        		ZAP_SQL_UPDATE($ZAP_SQL_STATUS_SERVICES); $RESULT=$RESULT+$_SESSION['MYSQL_UPDATE_NUM_ROWS'] ;


        
        
        }
      
   }
 } 

echo "<h2>AKTUALIZACJA DANYCH: ";
if($RESULT==$REQUIRED_RESULT) echo "OK($RESULT)"; else { echo "ERROR($RESULT,$error)";
// print_r($_POST);
 }
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']);
echo "<hr>";

	$_REQUEST['MENU_INIT'] = 'MENU';

}
