<?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_OFFER_TARGET($ARG1, $ARG1_VAL = '', $params = array()) {

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

	$targets = array();
	$colors = array();
	$colors['OFERTA_PODSTAWOWA'] = '#1EFFFB';
	$colors['OFERTA_ANEKS'] = '#22FF1E';
	$colors['OFERTA_ANTYREZYGNACJA'] = '#FFA500';
	$colors['OFERTA_SPECJALNA_JEDNORAZOWA'] = '#FF6CE9';
	$colors['OFERTA_SPECJALNA_ANTYREZYGNACJA'] = '#FF5D65';

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

	$db = DB::getDB();
	$res = $db->query("select `DESC`, `OPIS` from `CRM_LISTA_ZASOBOW` where `PARENT_ID`='4037' order by SORT_PRIO ");// 4037 KOMORKA P_OFFER_TARGET
	while ($r = $db->fetch($res)) {
		$targets[$r->DESC] = $r->OPIS;
	}

	if ('get_all_params' == V::get('task', '', $params)) {
		return array('targets'=>$targets, 'colors'=>$colors);
	}

	echo '<select name="P_OFFER_TARGET" style="width:400px;">';
		if (!empty($ARG1_VAL)) echo '<option value="' . $ARG1_VAL . '">' . $ARG1_VAL . '</option>';
		echo '<option value=""> </option>';
		foreach ($targets as $k_value => $v_label) {
			$st = '';
			if (isset($colors[$k_value])) {
				$st = ' style="background-color:'.$colors[$k_value].';"';
			}
			echo '<option value="' . $k_value . '"'.$st.'>' . $k_value . ': ' . $v_label . '</option>';
		}
	echo '</select>';
}
