<?php

class Test extends Controller {

	function Test()
	{
		parent::Controller();
		$this->load->helper('url');
		$this->config->load('katalog_config');
		$this->data = $this->config->item('data');
		$this->load->model('Emaily');
		$this->load->model('Dbmysql');
		$this->load->model('Kategorie');
	}
	
	function index()
	{
		//print_r($this);
		//$x = create_captcha();
		//print_r($x);
	}
	
	function reg()
	{
		require_once("HTML/QuickForm.php");
		$form = new HTML_QuickForm('registrace', 'post', '');
		$form->setRequiredNote('<font color="#ff000">*</font>&nbsp;'.$this->data['words'][51]);
		$form->setJsWarnings($this->data['words'][137].':', '');
		$elem = &$form->addElement('text', 'ico', $this->data['words'][137].':', array('size' => 20));
		$form->addRule('ico', $this->data['words'][124], 'required', '', 'client');
		$form->addRule('ico', $this->data['words'][137].' '.$this->data['words'][138], 'numeric', '', 'client');
		if (!empty($data['iduser']))
		{
			$elem->SetValue($data['iduser']);
			$elem->freeze();
		}
$elem = &$form->addElement('text', 'wlogin', 'Login:', array('size' => 20));
$form->addRule('wlogin', 'chybí login', 'required', '', 'client');
if (!empty($data['wlogin']))
$elem->SetValue($data['wlogin']);
$elem = &$form->addElement('text', 'wpass', 'Heslo:', array('size' => 20));
$form->addRule('wpass', 'chybí heslo', 'required', '', 'client');
if (!empty($data['wpass']))
$elem->SetValue($data['wpass']);
$elem = &$form->addElement('text', 'credit', 'Kredit:', array('size' =>
20));
$form->addRule('credit', 'chybí kredit', 'required', '', 'client');
$form->addRule('credit', 'kredit musí být číselný', 'numeric', '',
'client');
if (!empty($data['credit']))
$elem->SetValue($data['credit']);
else
$elem->SetValue('0.00');
$elem = &$form->addElement('text', 'discount', '\'discount\':',
array('size' => 20));
if (!empty($data['discount']))
$elem->SetValue($data['discount']);

$prepaidArr = array(
0 => 'Ne',
1 => 'Ano'
);
$elem = &$form->addElement('select', 'prepaid', 'Prepaid:', $prepaidArr);
if (!empty($data['prepaid']))
$elem->SetValue($data['prepaid']);

$form->addElement('submit', '__submit', 'Uložit');
$form->display();
	}//koniec
	
	function captcha()
	{
		session_start();
		$this->load->plugin('captcha');

		$vals = array(
					'word'		 => '',
					'img_path'	 => './captcha/',
					'img_url'	 => '/captcha/',
					//'font_path'	 => './system/texb.ttf',
					'img_width'	 => '130',
					'img_height' => '50',
					'strlen'		 => 6,
					'font-size'	 => 55,
					'expiration' => 7200
				);
	
		if(!empty($_POST))
		{
			if($_SESSION['word'] == $_POST['word'])echo 'Y';
			else echo 'N';
		}
	
		$_SESSION = create_captcha($vals);
		echo $_SESSION['image'];
		echo '<form method="post">
		<input type="text" name="word">
		<input type="submit">
		</form>';
	}
	
	function emaily()
	{
		$id = 2; $key = 'fewqgtewjjytr';$mail = 'test@test.loc';
		$this->Emaily->email_test($id, $key, $mail);
	}
	
	function modalwin()
	{
		echo '
		<form id="fNovyZapis" name="fNovyZapis">
		<input type="hidden" name="kategorie1key" value="">
		<input size=30 type="text" name="kategorie1val" value="" readonly><input name="button" onclick="OpenModalWin(\'/test/addmodalkat/\',\'kat\',500,600)" type="button" value="vybrat kategorii"><br>
		</form>
		';
	}
	
	function addmodalkat()
	{
		echo '<p><a href="#" onclick="window.close()">Resetovat kategorii</a></p>';
		echo $this->Kategorie->katTree(0);
	}
	
	function sms()
	{
		if ($stream = fopen('http://www.relaxservis.com', 'r'))
		{
			echo stream_get_contents($stream, -1, 10);
			fclose($stream);
		}
	}
	
	function menu()
	{
		$this->load->view('test', $this->data);
	}
}
?>