<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

class DomainsList
{
	var $caller;
	function DomainsList(&$caller)
	{
		$this->caller = &$caller;
	}
	function make($cond = false, $default = false)
	{
		if($cond && (!is_object($cond) && !method_exists($cond, 'getSQL'))) {
			$this->addError('DomainFactory::getDomainsList: bad arguments');
			return false;	
		}
		$query = 'SELECT id, domain FROM domains';
		if($cond) {
			$query .= ' WHERE ' . $cond->getSQL();
		}
		$query .= ' ORDER BY domain';
		$db = &get_db_connection();
		if($qres = $db->Select($query))
		{
			$domains = array();
			while($darr = $qres->nextrow())	
			{
				$domains[$darr['id']] = $darr['domain'];
			}
			if(!count($domains))
			{
				return false;	
			}
			$this->caller->smarty->assign('DOMAINS', $domains);
			if($default !== false)
			{
				$this->caller->smarty->assign('DOMAINS_DEFAULT', $default);	
			}
			
		}
		else
		{
			$this->caller->smarty->addMessage(ERROR, ltext('err_system'));
			return false;
		}
	}
	
	function checkDomain($domain, $user = false)
	{
		$domain *= 1;
		if ($user === false) {
			$user = $this->caller->user;	
		}
		$db =& get_db_connection();
		$dres = $db->Select('SELECT COUNT(*) AS cnt FROM domains WHERE kunde=\'' . $db->Quote($user) . '\' AND id=' . $domain); 
		if ($dres) {
			$wer = $dres->nextrow();
			if (!$wer['cnt']) {
				$this->caller->smarty->addMessage(ERROR, ltext('err_invaliduser'));
				return false;
			}
		}
		else
		{
			$this->caller->smarty->addMessage(ERROR, ltext('err_system'));
			return false;
		}
		//echo "dfdgf";
		return true;
	}	
		
}


?>
