<?php

/**
 * Dodawanie/usuwanie problemów.
 * 
 * example:
 *   index.php?MENU_INIT=A_PROBLEM&tbl=SES_USERS2_A&id={ID}
 * 
 */
function A_PROBLEM() {

	$tbl = V::get('tbl', '', $_GET);
	$id  = V::get('id',  '', $_GET, 'int');

	if (!$tbl || $id <= 0) {
		echo '<div class="alert alert-error">' . "Wrong param proces tbl or id!" . '</div>';
		return;
	}

	$allowedTbls = array();
	$allowedTbls[] = 'SES_USERS2_A';
	$allowedTbls[] = 'SES_TV_A';
	$allowedTbls[] = 'SES_VOIP_A';

	$tblOut = htmlspecialchars($tbl);
	if (!in_array($tbl, $allowedTbls)) {
		echo '<div class="alert alert-error">' . "Table {$tblOut} not allowed!" . '</div>';
		return;
	}

	Lib::loadClass('ProcesHelper');
	$zasobID = ProcesHelper::getZasobTableID($tbl);
	if ($zasobID <= 0) {
		echo '<div class="alert alert-error">' . "Can't find table {$tblOut} zasob id!" . '</div>';
		return;
	}

	$zasobObj = ProcesHelper::getZasobTableInfo($zasobID);
	if (!$zasobObj) {
		echo '<div class="alert alert-error">' . "Zasob id = {$zasobID} (tabela {$tlbOut}) nie istnieje" . '</div>';
		return;
	}

	$userAcl = User::getAcl();
	$userAcl->fetchGroups();
	if (!$userAcl->hasTableAcl($zasobObj->ID)) {
		echo '<div class="alert alert-error">' . "Brak uprawnień do tabeli {$tblOut} (id zasobu: {$zasobObj->ID})" . '</div>';
		return;
	}

	$tblAcl = $userAcl->getTableAcl($zasobObj->ID);

	$forceTblAclInit = ('1' == V::get('_force', '', $_GET));
	$tblAcl->init($forceTblAclInit);

	echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$tblAcl (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($tblAcl);echo'</pre>';

	$problemFldsList = array();
	$problemFldsList[] = 'A_PROBLEM';
	$problemFldsList[] = 'A_PROBLEM_DATE';
	$problemFldsList[] = 'A_PROBLEM_DESC';

	$problemFldsList[] = 'T_WORKPOINTS_TYPE';
	$problemFldsList[] = 'T_WORKPOINTS_DATE';
	// P_ACCOUNT	// Obciazenie Abonenta / P_ACCOUNT
	// DO_APPOITMENT_CLEAR	// Skasowanie danych o  spotkaniach APPOITMENTS / APPOITMENTS var CLEAR
	// ID_BILLING_USERS // DO_DISCONNECT_REPORT // DO_DISCONNECT_REPORT_FROM

}


//function A_PROBLEM($ID,$A_PROBLEM) {
if (0) {// TODO: RMME - OLD VERSION

global $thiss,$ARG1,$ARG1_VAL,$result,$error;

if ($_SESSION['CURRENT_MENU'] == $thiss->DETECT_EDIT_FUNCTION || $_SESSION['LAST_MENU'] == $thiss->DETECT_EDIT_FUNCTION) {
if ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['WIEVID'] == $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID']) {
	// show action links
	if (strlen($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM']) > 0) {
		CREATE_MENUFUNC_INIT_2('A_PROBLEM', 'A_PROBLEM', 'REMOVE', 'USUN PROBLEM');
		echo "&nbsp;<a target=blank href=".$_SERVER['PHP_SELF']."?FUNCTION_INIT=ORDERER&ARG1_VAL=ZLECENIE_NAPRAWY&HEADER_NOT_INIT=YES><img src=icon/print.gif border=0 alt=DRUKUJ_ZLECENIE_MONTAZU></a>";
		echo "<font size=-1> | " ;
		if ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM'] == 'UNVERIFIED') {
			CREATE_MENUFUNC_INIT_2('A_PROBLEM', 'A_PROBLEM', 'ADD', 'USTAW_PROBLEM');
		}
		if ($_SESSION['CURRENT_MENU'] == 'A_PROBLEM') CREATE_MENUFUNC_INIT_2('A_PROBLEM', 'ORDERER', 'POST', 'PRZESLIJ_ZLECENIE_MAIL');
		if ($_SESSION['CURRENT_MENU'] == 'A_PROBLEM') echo " | " ;
		if ($_SESSION['CURRENT_MENU'] == 'A_PROBLEM') echo "<a href='".$_SERVER['PHP_SELF']."?FUNCTION_INIT=ORDERER&ARG1_VAL=ZLECENIE_NAPRAWY&HEADER_NOT_INIT=YES' target='blank'>DRUKUJ_ZLECENIE</a>";
		if ($_SESSION['CURRENT_MENU'] == 'A_PROBLEM') echo " | </font>" ;
	} else {
		CREATE_MENUFUNC_INIT_2('A_PROBLEM', 'A_PROBLEM', 'ADD', 'DODAJ PROBLEM');
	}

	// run action
	if (($_SESSION['CURRENT_MENU'] == 'A_PROBLEM') && (!($ARG1=='ORDERER'))) {
		echo "<form action='' method='POST'>
		<input type='hidden' name='FUNCTION_INIT' value='UPDATEDB'><table cellspacing=0 cellpadding=4 border=1>
		<tr><td colspan='2'><b>MENU ZGLASZANIA / USUWANIA PROBLEMOW</b></td></tr>";
		if ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM'] == 'UNVERIFIED') {
			echo "<tr><td>Rodzaj Problemu / Problem Level</td><td>"; 
			GETFORMITEM($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM'], $_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPE']['A_PROBLEM'], 'A_PROBLEM');
			echo "(obecnie " . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM'] . ")</td></tr>";
		}
		else if (strlen($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM']) > 0) {
			echo "<tr><td>Rodzaj Problemu / Problem Level</td><td>";
			echo "<input type='hidden' name='A_PROBLEM' value=''>";
			echo "Problem usuwany (obecnie " . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM'] . ")</td></tr>";
		}
		else {
			echo "<tr><td>Rodzaj Problemu / Problem Level</td><td>";
			GETFORMITEM($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM'], $_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPE']['A_PROBLEM'], 'A_PROBLEM');
			echo "(obecnie " . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM'] . ")</td></tr>";
		}
		echo "<tr><td><br>Opis Problemu/Problem Description:</td><td>" ;
		GETFORMITEM($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM_DESC'], $_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPE']['A_PROBLEM_DESC'], 'A_PROBLEM_DESC');
		echo "</td></tr>";
		if ((strlen($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM']) > 0) && (!($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM'] == 'UNVERIFIED')) ) {
			echo "<tr><td>Typ pracy / T_WORKPOINTS_TYPE</td><td>";
			T_WORKPOINTS_TYPE_TYPES();
if (0) {//function T_WORKPOINTS_TYPE_TYPES() {
	$T_WORKPOINTS_TYPE_TYPES[1]['TYPE']='Technik_w_dyzurze';
	$T_WORKPOINTS_TYPE_TYPES[2]['TYPE']='Administrator_w_godzinach';
	$T_WORKPOINTS_TYPE_TYPES[3]['TYPE']='Technik_w_akordzie';
	$T_WORKPOINTS_TYPE_TYPES[4]['TYPE']='Naprawa_gwarancyjna';
	$T_WORKPOINTS_TYPE_TYPES[1]['VALUE']="TECH_AT_DUTY";
	$T_WORKPOINTS_TYPE_TYPES[2]['VALUE']="ADMIN_AT_WORK";
	$T_WORKPOINTS_TYPE_TYPES[3]['VALUE']="TECH_AT_CONTRACT";
	$T_WORKPOINTS_TYPE_TYPES[4]['VALUE']="GUARANTY_SERVICE";
	echo "<select name=T_WORKPOINTS_TYPE><option value=''> </option>
	 ";

	foreach ($T_WORKPOINTS_TYPE_TYPES as $value) {
		echo "<option value='" . $value['VALUE'] . "'" ;
	if($_SESSION['USERS2_COLUMN']['EDITRECORD']['T_WORKPOINTS_TYPE'] == $value['VALUE']) echo "selected";
		echo ">" . $value['TYPE'] . "</option>" ;
		echo "asd";
		 }
		echo "</select>";
	//	CREATE_MENU_NOTD_INIT_3(TEMPEDIT_EVAL,T_WORKPOINTS_TYPE,$value[VALUE],$value[TYPE]);
	//	echo " | ";
}
			echo "</td></tr>";
			echo "<tr><td>Data pracy / T_WORKPOINTS_DATE (YYYY-MM-DD)</td><td>";
			GETFORMITEM($_SESSION[$thiss->DETECT_TABLE_COLUMN]['TEMPEDITRECORD']['T_WORKPOINTS_DATE'], $_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPE']['T_WORKPOINTS_DATE'], 'T_WORKPOINTS_DATE');
			echo "<font size='-2'>"; T_WORKPOINTS_DATE_SELECT(); echo "</font>";
			echo "</td></tr>";
			echo "<tr><td>Wykonawca pracy / T_WORKPOINTS_USER</td><td>";
			T_WORKPOINTS_USER_SELECT();
			echo "</td></tr>";
			echo "<tr><td>Wartosc pracy / T_WORKPOINTS_VALUE</td><td>";
			GETFORMITEM($_SESSION[$thiss->DETECT_TABLE_COLUMN]['TEMPEDITRECORD']['T_WORKPOINTS_VALUE'], $_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPE']['T_WORKPOINTS_VALUE'], 'T_WORKPOINTS_VALUE');
			echo "<font size='-2'>";
			T_WORKPOINTS_VALUE_TYPES();
if(0) {//function T_WORKPOINTS_VALUE_TYPES() {
	$T_WORKPOINTS_VALUE_TYPES[1]['TYPE']='BEZPLATNIE';
	$T_WORKPOINTS_VALUE_TYPES[2]['TYPE']='USTERKA';
	$T_WORKPOINTS_VALUE_TYPES[3]['TYPE']='USTERKA_PLATNA';
	$T_WORKPOINTS_VALUE_TYPES[4]['TYPE']='PRZELACZENIE';
	$T_WORKPOINTS_VALUE_TYPES[1]['VALUE']="0";
	$T_WORKPOINTS_VALUE_TYPES[2]['VALUE']="16";
	$T_WORKPOINTS_VALUE_TYPES[3]['VALUE']="19";
	$T_WORKPOINTS_VALUE_TYPES[4]['VALUE']="20";
	foreach ($T_WORKPOINTS_VALUE_TYPES as $value) {
		CREATE_MENU_NOTD_INIT_3('TEMPEDIT_EVAL', 'T_WORKPOINTS_VALUE', $value['VALUE'], $value['TYPE']);
		echo " | ";
	}
}
			echo "</font>";
			echo "</td></tr>";

			if(substr($thiss->DETECT_TABLE_NAME,0,4)=='SES_' && substr($thiss->DETECT_TABLE_NAME,-2)=='_A') {
				echo "<tr><td>Obciazenie Abonenta / P_ACCOUNT </td><td>";
				echo "<input type=text name='P_ACCOUNT' value='' />";// $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['P_ACCOUNT']
				echo "<font size='-2'>";
				P_ACCOUNT_TYPES();
if(0) {//function P_ACCOUNT_TYPES() {
	$P_ACCOUNT_TYPES[1]['TYPE']='BEZPLATNIE';
	$P_ACCOUNT_TYPES[2]['TYPE']='USTERKA_PLATNA_do_1g';
	$P_ACCOUNT_TYPES[3]['TYPE']='USTERKA_PLATNA_do_2g';
	$P_ACCOUNT_TYPES[1]['VALUE']="";
	$P_ACCOUNT_TYPES[2]['VALUE']="30";
	$P_ACCOUNT_TYPES[3]['VALUE']="60";
	foreach ($P_ACCOUNT_TYPES as $value) {
		CREATE_MENU_NOTD_INIT_3('TEMPEDIT_EVAL', 'P_ACCOUNT', $value['VALUE'], $value['TYPE']);
		echo " | ";
	}
}
				echo "</font>";
				echo "</td></tr>";
			}

			echo "<tr><td>Skasowanie danych o  spotkaniach APPOITMENTS / APPOITMENTS var CLEAR</td><td>";
			echo "<input type=checkbox name='DO_APPOITMENT_CLEAR' checked>";
			echo "</td></tr>";
		if(substr($thiss->DETECT_TABLE_NAME,0,4)=='SES_' && substr($thiss->DETECT_TABLE_NAME,-2)=='_A') {
	
				//wykrycie ID_BILLING_USERS jeżeli tabela SES_
				 ZAP_SQL("select ID_BILLING_USERS from SERVICES where ID='".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_SERVICES']."'");
				 list($ID_BILLING_USERS)=mysql_fetch_row($result);
			 if(strlen($ID_BILLING_USERS)<1) {
				  $error.=" Nie znaleziono ID_BILLING_USERS!!! ";
				 }
				 echo "<input type=hidden name='ID_BILLING_USERS' value='$ID_BILLING_USERS'>";
				echo "<tr><td>Uznanie dni niedzialania uslugi zgodnie z datą zgłoszenia i usunięcia usterki (YYYY-MM-DD HH-MM) <input type=\"checkbox\" name=\"DO_DISCONNECT_REPORT\"></td><td>";
				echo "OD:<input type=text size=20 name='DO_DISCONNECT_REPORT_FROM' value=\"".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM_DATE']."\">, do dnia wykonania pracy";
				echo "</td></tr>";
			}
		}
		else {
			echo "<tr><td>Data Problemu / A_PROBLEM_DATE</td><td>";
			if( (strlen($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM']) > 1) && (strlen($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM_DATE']) > 1)) {
				$TEMP_A_PROBLEM_DATE = $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM_DATE'];
			} else {
				$TEMP_A_PROBLEM_DATE = date('Y-m-d-H:i');
			}
			GETFORMITEM($TEMP_A_PROBLEM_DATE, $_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPE']['A_PROBLEM_DATE'], 'A_PROBLEM_DATE');
			// 2011-11-23: pole nieuzywane, problem z odpisywaniem maila przez klientow
			// @see superedit-UPDATEDB.php
			//if (strlen($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_PROBLEM']) < 1) {
			//	echo "<tr><td>Przeslanie wiadomosci dla abonenta umozliwiajacej anulowanie problemu</td><td> <input type=checkbox name='A_DB_USER_PROBLEM_REPORT_S_ALIAS_INFO' checked>";
			//}
			echo "</td></tr>";
		}

		echo "<tr><td colspan='2' align='center'><input type='submit' value='      OK      '></td></tr></table></form>";
		CREATE_MENUFUNC_NOTD_INIT($_SESSION['LAST_MENU'], 'POWROT<img src=icon/back.gif border=0 alt=POWROT>');
		echo "<hr>";
	}
}
}

	if(isset($error))  echo "ERROR($RESULT,$ERROR ".$error.")";

}

// @from superedit-UPDATEDB.php
if(0){// 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 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))) && 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" ;
		$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'] ;

			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>"; 
		}
	} 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'] . "'";
			ZAP_SQL_UPDATE($ZAP_SQL_HIST); $RESULT=$_SESSION['MYSQL_UPDATE_NUM_ROWS'];
			ZAP_SQL_UPDATE($ZAP_SQL); $RESULT=$RESULT + $_SESSION['MYSQL_UPDATE_NUM_ROWS'];
		}
	}
}
