<?php

if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
if (!defined('APP_PATH_ROOT')) define('APP_PATH_ROOT', dirname(__FILE__));
if (!defined('APP_PATH_WWW')) define('APP_PATH_WWW', dirname(__FILE__));
if (!defined('APP_PATH_CONFIG')) define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');

function P_OSIEDLE( $cmd, $value ) {
	global $thiss;

	if ($cmd == 'POST_VERIFY') {
		return;
	}

	require_once APP_PATH_ROOT . DS . 'se-lib' . DS . 'Lib.php';
	Lib::loadClass('V');
	Lib::loadClass('User');
	Lib::loadClass('Config');
	Lib::loadClass('DB');

	/*
		4335 KOMORKA P_OSIEDLE
			4336 DANE Chełm
			4337 DANE Morena
			4338 DANE Osiedle Alfa Park
			4339 DANE Osiedle Casa Patrizia
			4340 DANE Osiedle Cieszynka
			4341 DANE Osiedle 3 Dęby I
			4342 DANE Osiedle 3 Dęby II
			4343 DANE Osiedle Dworak
			4344 DANE Osiedle Jabłoniowa
	*/

	$field_name = 'P_OSIEDLE';
	$select_list = array();

	$db = DB::getDB();
	$sql = "select z.`ID`, z.`DESC`
		from `CRM_LISTA_ZASOBOW` as z
		where
			z.`A_STATUS` in('WAITING', 'NORMAL')
			and `PARENT_ID`=4335
		order by z.`DESC` ASC
	";
	$res = $db->query($sql);
	while ($r = $db->fetch($res)) {
		$select_list [$r->DESC] = "{$r->DESC}";
	}

	echo '<select name="' . $field_name . '">';
		echo ' <option value="">' . " " . '</option>';
		foreach ($select_list as $key => $val) {
			$sel = ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD'][$field_name] == $key)? ' selected="selected"' : '';
			echo '<option value="' . $key . '"' . $sel . '>' . $val . '</option>';
		}
	echo '</select>';

}
