<?php

function K_OD_KOGO($COMMAND,$K_OD_KOGO) {
global $ARG1,$ARG1_VAL,$result,$thiss,$error,$conn;
 if($COMMAND==POST_VERIFY) { 
	
  } else {
  if($_SESSION[CURRENT_MENU]==$thiss->DETECT_EDIT_FUNCTIONNN_TODO) {

//      if(strstr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['PERMEDIT']['K_OD_KOGO'],"RW")) {
//        GETFORMITEM($_SESSION[$thiss->DETECT_TABLE_COLUMN][EDIT_TEMPLATE]['K_OD_KOGO'],$_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPE']['K_OD_KOGO'],'K_OD_KOGO');
//	 echo " ( $K_OD_KOGO $thiss->DETECT_TABLE_COLUMN )" . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC']['K_OD_KOGO'] ;
//       }


  
  } else if(($_SESSION[CURRENT_MENU]=="NEW_RECORD")||($_SESSION[CURRENT_MENU]==$thiss->DETECT_EDIT_FUNCTION)) {
//	echo "DUPA".$_SESSION[CURRENT_MENU]."/".$thiss->DETECT_EDIT_FUNCTION;


  	if(strstr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['PERMEDIT']['K_OD_KOGO'],"RW")) {
		ZAP_SQL("select 1+1;");
		$SQL="select  concat(ID,'.') as ID , 'L.Dz.' as SRC, K_OD_KOGO, OD_KOGO_ADRES as OD_KOGO_ADRES  from ".$thiss->DETECT_TABLE_NAME." where A_STATUS!='DELETED' group by K_OD_KOGO ";
		if ($_SESSION['SES_USERS2_A_COLUMN']) {
			$SQL.="\n union select concat(ID_SERVICES,'.',ID) as ID ,'Czlonkowie' as SRC , P_NAME as K_OD_KOGO , concat(P_ADDRESS_CITY, ' ', P_ADDRESS_STREET, ' ', P_ADDRESS_HOUSE ) as OD_KOGO_ADRES  from USERS2 where A_STATUS!='DELTED' and A_STATUS!='WARNING'  group by K_OD_KOGO ";
		}

		$SQL.="\n order by K_OD_KOGO";

//		$SQL="select ID , 'L.Dz.' as SRC, K_OD_KOGO   from ".$thiss->DETECT_TABLE_NAME." where A_STATUS!='DELETED' group by K_OD_KOGO
//		      union select ID,'Czlonkowie' as SRC , P_NAME as K_OD_KOGO from USERS2 where A_STATUS!='DELTED' and A_STATUS!='WARNING'
//
//		group by K_OD_KOGO 		order by K_OD_KOGO";
//		echo $SQL;
		$res2=mysql_query($SQL);
	 	echo "<select name=K_OD_KOGO_FUNC id=\"K_OD_KOGO_FUNC\" onchange=\"showSelected();\"><option value=''> </option>";


		$SELECTED="0";
	  	while ($h=mysql_fetch_array($res2)) {
			echo "\n<option value='".$h[OD_KOGO_ADRES]."'" ;
			if($_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][K_OD_KOGO]==$h[K_OD_KOGO]) {
				$SELECTED=1;
				echo " selected='true' ";
			}
	        	echo ">" . $h[K_OD_KOGO]."(".$h['SRC'].":".$h[0].")</option>" ;
          	}
		if(!$SELECTED) echo "\n<option value='".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][OD_KOGO_ADRES]."' selected='true'>.".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][K_OD_KOGO]."</option>";
		
        echo "</select>";
		echo "<p>";
		GETFORMITEM($_SESSION[$thiss->DETECT_TABLE_COLUMN][EDIT_TEMPLATE]['K_OD_KOGO'],$_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPE']['K_OD_KOGO'],'K_OD_KOGO');	

	//test JAVA



	//eof TEST JAVA
	}
	//        GETFORMITEM($_SESSION[$thiss->DETECT_TABLE_COLUMN][EDIT_TEMPLATE]['K_OD_KOGO'],$_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPE']['K_OD_KOGO'],'K_OD_KOGO');
	//	 echo " ( $K_OD_KOGO $thiss->DETECT_TABLE_COLUMN )" . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC']['K_OD_KOGO'] ;
	//       }

  
  } else     echo $K_OD_KOGO."";
 }



}

