<?php
class Testforum extends Controller
{

	var $fuser = false;
	var $elozo;
	var $kepek_utvonal = "public/img/forum/";
	var $kepek_utvonal_eng = "public/img/forum/eng/";
	var $galeria_utvonal = "public/forum-galeria/hun/";
	var $galeria_utvonal_eng = "public/forum-galeria/eng/";


	function __construct()
	{
		parent::Controller();

		$this->userekoldal = 30;

		$user = $this->phpsession->get('fuser');
		if(!$user){

		}else{
			$this->fuser = $user;
		}

		$this->lang->load('site', $this->muser->user['lang']);
		$this->load->model('mforum');

		define( "BENTIIP", "84.3.20.66aaaaaaaaaaaa");
		define( "UBUNTU", "o33333333333");
		define( "MEHET", "igen");

	}

	function index()
	{
		$this->temakorok();
	}

	function temakorok(){
		hun() ? $data['title'] = 'ARCHLine.XP Fórum' : $data['title'] = 'ARCHLine.XP Forum';
		$data['tartalom']='testforum/temakorok';
		$data['csik']=array('home','forum');

		$user = $this->phpsession->get('fuser');
		if( $this->mforum->moderator($user['name']) )
			$data['moderator'] = true;
		$this->phpsession->save('valasz',false);
		$this->phpsession->save('hszid',false);
		$this->phpsession->save('oldal',0);
		$this->phpsession->save('temakor',false);

		if( is_numeric($this->uri->segment(3)) ) $temaoldal = $this->uri->segment(3);
		else $temaoldal = 0;
		$this->phpsession->save('temakoroldal',$temaoldal);

		$temak = $this->mforum->get_alaptemakorok($temaoldal);
		foreach( $temak as $tema ){
			$cim = $tema->cim;
			if(count($cim) > 26)
				$ut26 = array($cim[26]);
			else
				$ut26 = array("a");
			$tomb = preg_grep("/[abcdefghijklmnopqrstxyzA-Z]/",$ut26);
			if( count($tomb) == 0 ){
				if(strlen($tema->cim) > 26){
					$tema->rov_cim = substr($tema->cim,0,20);
					$tema->rov_cim .= "..";
				}
			}else{
				$tema->rov_cim = substr($tema->cim,0,27);
				if(strlen($tema->cim) > 27)
				$tema->rov_cim .= "..";
			}

			$xx = $this->mforum->get_tkuthsz($tema->temakor_id);
			if($xx != ""){
				$tema->datum = $xx->datum;
				if($xx->user != "586"){
					$xxxx = $this->mforum->get_userUid($xx->user);
					if(isset($xxxx->nev))
						$tema->utolsouser = $xxxx->nev;
					else
						$tema->utolsouser = "";
				}
				else
					$tema->utolsouser = "Németh Kálmán";
			}
			else
				$tema->datum = $this->mforum->get_tkdate($tema->temakor_id);

		}

		usort( $temak, "hasonlito" );
		$data['temak'] = $temak;

		if( $this->mforum->vanmegtemakor($this->phpsession->get('temakoroldal')) ){
			$data['kovetkezo'] = true;
			$data['kov'] = ($temaoldal+1);
		}
		if( $temaoldal > 0 ){
			$data['elozo'] = true;
			$data['elobbi'] = ($temaoldal-1);
		}

		$data['oldalak_szama'] = $this->mforum->get_tkoldal();
		$data['akt_oldal'] = $this->phpsession->get('temakoroldal');
		$data['style'] = array('jquery.ui');

		$data['aktmenu'] = "1";
		$this->load->view('site_forum',$data);
	}

	function temak(){
		hun() ? $data['title'] = 'ARCHLine.XP Fórum' : $data['title'] = 'ARCHLine.XP Forum';
		$data['tartalom']='testforum/temak';
		$data['csik']=array('home','forum');

		$user = $this->phpsession->get('fuser');
		if( $this->mforum->moderator($this->fuser['name']) )
			$data['moderator'] = true;
		$this->phpsession->save('valasz',false);
		$this->phpsession->save('hszid',false);
		$this->phpsession->save('oldal',0);

		if( is_numeric($this->uri->segment(3)) ) $temakor = $this->uri->segment(3);
		else if( $this->phpsession->get('temakor') ) $temakor = $this->phpsession->get('temakor');
		else redirect('forum');
		$this->phpsession->save('temakor',$temakor);

		if( is_numeric($this->uri->segment(4)) ) $temaoldal = $this->uri->segment(4);
		else $temaoldal = 0;
		$this->phpsession->save('temaoldal',$temaoldal);

		$temak = $this->mforum->get_alap2($temakor, $temaoldal);
		foreach( $temak as $tema ){
			$cim = $tema->cim;
			$tema->rov_cim = $tema->cim;

			$tema->utolsouser = $this->mforum->get_utolsouserTema($tema->tema_id);
			if( isset($tema->utolsouser->user) && $tema->utolsouser->user == "586" )
				$tema->utolsouser = "Németh Kálmán";
			elseif( isset($tema->utolsouser->nev) )
				$tema->utolsouser = $tema->utolsouser->nev;
			else
				$tema->utolsouser = "";
		}


		if( !$temak ){
			$data['infok'] = array("1");
		}
		else{
			if( $this->mforum->vanmegtema($this->phpsession->get('temaoldal'),$temakor) ){
				$data['kovetkezo'] = true;
				$data['kov'] = ($temaoldal+1);
			}
			if( $temaoldal > 0 ){
				$data['elozo'] = true;
				$data['elobbi'] = ($temaoldal-1);
			}

			$data['oldalak_szama'] = $this->mforum->get_toldal();
			$data['akt_oldal'] = $this->phpsession->get('temaoldal');
		}

		$data['temak'] = $temak;
		$data['temakorcim'] = $this->mforum->get_tkcim($temakor)->cim;


		$data['meta']['keyw'] = $data['temakorcim'].', ';
		$data['title'] .= ' - ' . $data['temakorcim'];

		$data['aktmenu'] = "1";
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$this->load->view('site_forum',$data);
	}

	function ujtema(){
		$tomb = $this->phpsession->get('fuser');
		$user = $tomb['name'];
		$temakor_id = $this->phpsession->get('temakor');
		if( $user ){
			if($this->input->post('nyit')!=false){
				$this->mforum->temabeszur($this->input->post('temacim'));

				redirect('forum');
			}else{
				hun() ? $data['title'] = $data['title'] = 'ARCHLine.XP Fórum téma nyitás' : $data['title'] = 'ARCHLine.XP Forum new topic';
				$data['tartalom']='testforum/ujtema';
				$data['csik']=array('home','forum');

				$this->load->view('site_forum',$data);
			}
		}else{
			$this->index();
		}
	}

	function ujtemakor(){
		$tomb = $this->phpsession->get('fuser');
		$user = $tomb['name'];
		$temakor_id = 0;
		if( $this->mforum->moderator($tomb['name']) ){
			if($this->input->post('nyit')!=false){
				$this->mforum->temakorbeszur($this->input->post('temacim'));

				redirect('forum/temakorok');
			}else{
				hun() ? $data['title'] = 'ARCHLine.XP Fórum témakör nyitás' : $data['title'] = 'ARCHLine.XP Forum new board';
				$data['tartalom']='testforum/ujtemakor';
				$data['csik']=array('home','forum');

				$this->load->view('site_forum',$data);
			}
		}else{
			$this->index();
		}
	}

	 function csere($input){
		$mit[0]="/>/";
		$mit[1]="/</";
		$mit[2]="/\n/";
		$mit[3]="/'/";
		$mit[4]="/=/";
		$mit[5]="/\"/";
		$mit[6]="/;/";
		$mire[0]="&gt;";
		$mire[1]="&lt;";
		$mire[2]="<br />";
		$mire[3]="\'";
		$mire[4]="\=";
		$mire[5]="\\\"";
		$mire[6]="\;";
		return preg_replace($mit,$mire,$input);
    }

    function csere2($input){
		$mit[2]="/\n/";
		$mire[2]="<br />";
		return preg_replace($mit,$mire,$input);
    }

	function ujhsz(){
		$tomb = $this->phpsession->get('fuser');
		if( $tomb ){
			if($this->input->post('hozzaad')!=false){
				$tema_id = $this->phpsession->get('temaid');
				$error = "";

				$kep = "NULL";

				if(!$this->input->post('hszuj'))
					$hszszoveg = $this->input->post('hsz');
				else
					$hszszoveg = $this->input->post('hszuj');


				if(!$this->input->post('valasz'))
					$valasz = $this->phpsession->get('valasz');
				else
					$valasz = $this->input->post('valasz');



				if($hszszoveg == "" || $hszszoveg == "<p>&#160;</p>" || trim($hszszoveg) == "<br />")
					$error .= "Üres hozzászólás!<br />";


				if ($_FILES["fkep"]["error"]==0 && ($error == "") ){
					$login = $tomb['name'];
					$user_id = $this->mforum->get_userid($login);
					//ha nincs mappája
					if(hun())
						$hova = $this->kepek_utvonal.$user_id;
					elseif(eng())
						$hova = $this->kepek_utvonal_eng.$user_id;

					if(!is_dir($hova)){
						//akkor hozza létre
						mkdir($hova,0644);
						chmod($hova,0777);
					}
					$feltolt_konyvtar = $hova."/";
					//ha több fájl lenne ugyanazon a néven
					$rand = rand(100,999);
					$feltolt_fajlnev=$feltolt_konyvtar . $rand . "__" . $this->ekezet($_FILES["fkep"]["name"]);

					$error = "";
					$mi = $_FILES['fkep']['name']."$";

					$mire = "\.bmp|\.jpg|\.jpeg|\.png|\.gif|\.tif|\.BMP|\.JPG|\.PNG|\.GIF";
					if( !(ereg( $mire , $mi )) ){
						$error .= "Hibás fájl kiterjesztés, elfogadott kiterjesztések: .bmp, .jpg, .png, .gif<br />";
					}
					if( $_FILES['fkep']['size'] > 1024 * 1024 * 10 ){
						$error .= "A kép mérete nagyobb 10 MB-nál.<br />";
					}
					else if( $hszszoveg != "" && !$error){
						if (copy($_FILES["fkep"]["tmp_name"], $feltolt_fajlnev)){
							$kep = $rand . "__". $this->ekezet($_FILES["fkep"]["name"]);
							$mit = $hova."/".$kep;
							chmod($mit,0777);
						}else{
							$kep = "NULL";
						}
					}
				}

				if(!$error){
					$this->mforum->hszbeszur($hszszoveg,$tema_id,$valasz,$kep);

					$this->load->library('email');
					$this->email->initialize();
					// ertesitesek kikuldese
					$kiknek = $this->mforum->ertesites($tema_id);
					foreach($kiknek as $kinek){
						$alap = $this->mforum->default_mail($kinek->email);
						if(!$alap)
							$alap = $kinek->email;

						$mail_data['tema'] = $this->mforum->get_cim($tema_id)->cim;
						$mail_data['hsz'] = $hszszoveg;

						$this->email->from('info@cadline.hu', 'Cadline Weboldal');
						$this->email->subject('ARCHLine.XP Fórum - Új hozzászólás');
						$this->email->message($this->load->view('mail/forum_ujhsz', $mail_data, true));

						$this->email->send($alap, 'smtp');
						$this->email->clear();
					}
					// end ertesitesek kikuldese


					$temaid = $this->phpsession->get('tema_id');
					header("Location: listaz/$temaid");
				}else{
					hun() ? $data['title'] = 'ARCHLine.XP Fórum új hozzászólás' : $data['title'] = 'ARCHLine.XP Forum new post';
					$data['tartalom']='testforum/ujhsz';
					$data['csik']=array('home','forum');
					$user = $this->phpsession->get('fuser');
					if($this->mforum->moderator($user['name']))
						$data['moderator']=true;
					$data['error']=$error;
					$data['hsz']=$this->input->post('hsz');

					$this->load->view('site_forum',$data);
				}
			}else if( $this->phpsession->get('temaid') ){
				hun() ? $data['title'] = 'ARCHLine.XP Fórum új hozzászólás' : $data['title'] = 'ARCHLine.XP Forum new post';
				$data['tartalom']='testforum/ujhsz';
				$data['csik']=array('home','forum');
				$data['javascript'] = array('../editor/fckeditor');
				$user = $this->phpsession->get('fuser');
				if($this->mforum->moderator($user['name']))
					$data['moderator']=true;

				$this->load->view('site_forum',$data);
			}else{
				$this->index();
			}
		}else{
			$this->index();
		}
	}

	function valasz(){
		$tomb = $this->phpsession->get('fuser');
		if( $this->uri->segment(3) ){
			$this->phpsession->save('valasz',$this->uri->segment(3));
			$id = $this->uri->segment(3);
			$temaid = $this->mforum->get_temaidByHszid($id);
			$this->phpsession->save('temaid',$temaid);
		}
		if( $tomb ){
			if( $this->phpsession->get('temaid') ){
				hun() ? $data['title'] = 'ARCHLine.XP Fórum új hozzászólás' : $data['title'] = 'ARCHLine.XP Forum new post';
				$data['tartalom']='testforum/ujhsz';
				$data['csik']=array('home','forum');
				$data['javascript'] = array('../editor/fckeditor');
				$user = $this->phpsession->get('fuser');
				if($this->mforum->moderator($user['name']))
					$data['moderator']=true;

				$this->load->view('site_forum',$data);
			}else{
				$this->index();
			}
		}else{
			$this->index();
		}
	}

	function listaz(){
		$this->phpsession->save('valasz',false);
		if( !($this->phpsession->get('oldal')) ) $this->phpsession->save('oldal',0);
		if( $this->uri->segment(3) == 'kov' ) $this->kovetkezo();
		if( $this->uri->segment(3) == 'elozo' ) $this->elozo();

		if( is_numeric($this->uri->segment(3)) ){
			$tema_id = $this->uri->segment(3);
			$this->phpsession->save('temaid',$tema_id);
//			redirect('forum/listaz');
		}else if($this->phpsession->get('temaid')){
			$tema_id = $this->phpsession->get('temaid');
		}else{
			$tema_id = 0;
		}

		if(!($tema_id) || !is_numeric($tema_id) || !$this->mforum->is_temaid($tema_id)){
			redirect('forum');
		}else{
			$data['tartalom']='testforum/temamutat';
			$data['csik']=array('home','forum');
			$user = $this->phpsession->get('fuser');
			if($this->mforum->moderator($user['name']))
				$data['moderator']=true;

			if( !is_numeric($this->uri->segment(4)) )
				$oldal = $this->phpsession->get('oldal');
			else{
				$oldal = $this->uri->segment(4);
				$this->phpsession->save('oldal',$oldal);
			}
			$hszek = $this->mforum->get_lista($tema_id,$oldal);
			foreach( $hszek as $hsz){
				if( !($hsz->valasz == "0" || $hsz->valasz == "NULL") ){
					$vszid = $hsz->valasz;
					$elozo = $this->mforum->get_hsz($vszid);
					if( $elozo->user == "" )
						$elozo = $this->mforum->get_hsz2($vszid);
					if( isset($elozo->user) && $elozo->user != "0" && $elozo->user != "" ){
						$hsz->valasz = $elozo->user . ", (" . $elozo->datum . ")";
						if( $elozo->user == 586 )
							$hsz->valasz = "Németh Kálmán, (" . $elozo->datum . ")";
						elseif( $elozo->user == 270 )
							$hsz->valasz = "Tóth M.Levente, Mészáros Marcel, (" . $elozo->datum . ")";
					}
					elseif( $elozo )
						$hsz->valasz = "[Törölt felhasználó], (" . $elozo->datum . ")";
					else
						$hsz->valasz = "-";
				}
				//if(!eng()) $hsz->szoveg = $this->csere2($hsz->szoveg);
				if( strtotime($hsz->datum) < 1282039000) $hsz->szoveg = $this->csere2($hsz->szoveg);

				if( $hsz->user_id == 586 ){
					$hsz->user = "Németh Kálmán";
				}elseif( $hsz->user_id == 270 ){
					$hsz->user = "Tóth M.Levente, Mészáros Marcel";
				}
			}

			if( !$hszek ){
				$data['infok'] = array("2");
			}else{
				if( $this->mforum->vanmegoldal($tema_id,$this->phpsession->get('oldal')))
					$data['kovetkezo'] = true;
				if( $this->phpsession->get('oldal') > 0 )
					$data['elozo'] = true;
			}

			$data['hszek_json'] = json_encode($hszek);

			$user = $this->phpsession->get('fuser');
			if( $this->mforum->moderator($user['name']) )
				$data['szerk']=true;
			$data['temacim'] = $this->mforum->get_cim($tema_id)->cim;
			$temakor_id = $this->mforum->get_tema1($tema_id)->temakor_id;
			$data['temakorcim'] = $this->mforum->get_temakor1($temakor_id)->cim;
			$data['temakorid'] = $temakor_id;
			$data['tema_id'] = $tema_id;
			$data['oldalak_szama'] = (int)$this->mforum->get_temaoldal($tema_id);
			$data['akt_oldal'] = $oldal;

			$data['hozzaszolasok'] = $hszek;

			$data['meta']['keyw'] = $data['temacim'].', ';

			hun() ? $data['title'] = 'ARCHLine.XP Fórum' : $data['title'] = 'ARCHLine.XP Forum';
			$data['title'] .= ' - ' . $data['temacim'];

			$data['aktmenu'] = "1";
			$data['style'] = array('jquery.ui'/*,'fancybox2'*/);
			$data['javascript'] = array('../editor/fckeditor','jquery_ui'/*,'fancybox/jquery-1.3.2.min','fancybox/jquery.easing.1.3','fancybox/jquery.fancybox-1.2.1.pack','fancybox/fancy'*/);
			$this->load->view('site_forum',$data);
		}
	}

	function kovetkezo(){
		$oldalszam = $this->phpsession->get('oldal');
		if( $this->mforum->vanmegoldal($this->phpsession->get('temaid'),$oldalszam)){
			$oldalszam++;
		}
		$this->phpsession->save('oldal',$oldalszam);
	}

	function elozo(){
		$oldalszam = $this->phpsession->get('oldal');
		if( $oldalszam > 0 )
			$oldalszam--;
		$this->phpsession->save('oldal',$oldalszam);
	}

	function ekezet($input){
		$mit = array("/á/", "/Á/", "/é/", "/É/", "/í/", "/Í/", "/ö/", "/Ö/", "/ő/", "/Ő/", "/ó/", "/Ó/", "/ú/", "/Ú/", "/ü/", "/Ü/", "/ű/", "/Ű/", "/ /");
		$mire = array("a", "A", "e", "E", "i", "I", "o", "O", "o", "O", "o", "O", "u", "U", "u", "U", "u", "U", "_");
		$output = preg_replace($mit, $mire, $input);
		return $output;
	}

	function login(){
		$name = $this->input->post('name');
		$passwd = $this->input->post('passwd');

		$name = $this->csere($name);

		if(!$passwd || !$name)
		{
			$this->belephiba(9);
		}
		else
		{
			$name2 = $this->ekezet($name);
			$vanaktiv = $this->mforum->vanaktivprog($name);

			if( ($this->mforum->belep($name,$passwd) || $this->mforum->belep($name2,$passwd))
				&& $vanaktiv )
			{
				$uid = $this->mforum->get_userid($name);
				if( !$uid || !is_numeric($uid) ){
					$this->belephiba(6);
				}else{
					$fuser['lang']=$this->muser->user['lang'];
					$fuser['name']=$name;
					$fuser['t_nev'] = $this->mforum->get_nev($name);
					$fuser['rang'] = $this->mforum->get_rang($uid);
					$rang = $fuser['rang'];
				}




				// ha csak feltolto
				if( $rang != "user" && $rang != "moderator" ){
					$fuser['user_id'] = $uid;
					$this->phpsession->save('feltolto',$fuser);
					$this->belephiba(8);
				}
				//ha még nem fogadta el a szabályzatot:
				elseif( !($this->mforum->szabalyzat($uid) ) ){
					if(hun())
						$lap = $this->mpages->get_row(454);
					else
						$lap = $this->mpages->get_row(559);

					hun() ? $data['title'] = 'ARCHLine.XP Fórum szabályzat' : $data['title'] = 'ARCHLine.XP Forum Rules';
					$data['tartalom'] = '/forum/szabalyzat';
					$data['lap'] = $lap;
					//$user = $this->phpsession->get('fuser');
					if($this->mforum->moderator($name))
						$data['moderator']=true;

					//ha még nem fogadta el a szabályzatot:
					if( !($this->mforum->szabalyzat($uid) ) ){
						$data['uid'] = $uid;
						$data['login'] = $name2;
						$data['pw'] = md5($passwd);
						$data['nemelfogad'] = true;
						$data['infok'] = array("0");
					}

					$this->load->view('site_forum',$data);
				}
				else{
					$fuser['user_id'] = $uid;
					$this->phpsession->save('fuser',$fuser);
					redirect('forum');
				}
			}else{
				if( $name == "moderator" ){
					$szam = date(W);
					$this->mforum->jelszovaltmod($szam);
					if( $this->mforum->belep($name,$passwd) ){
						$fuser['lang']=$this->muser->user['lang'];
						$fuser['name']=$name;
						$fuser['t_nev'] = $this->mforum->get_nev($name);
						$uid = $this->mforum->get_userid($name);
						$fuser['user_id'] = $uid;
						$this->phpsession->save('fuser',$fuser);
						redirect('forum');
					}
				}

				if( !$vanaktiv )
					$this->belephiba(7);
				else{
					$this->belephiba(6);
				}
			}
		}
	}

	function belephiba($szoveg){
		$data['tartalom']='testforum/temakorok';
		hun() ? $data['title'] = 'ARCHLine.XP Fórum' : $data['title'] = 'ARCHLine.XP Forum';
		$data['csik']=array('home','forum');

		if( !is_numeric($szoveg) ){
			$data['error'] = $szoveg;
		}
		else{
			$data['error'] = array($szoveg);
		}

		$this->phpsession->save('valasz',false);
		$this->phpsession->save('hszid',false);
		$this->phpsession->save('oldal',0);
		$this->phpsession->save('temakor',false);

		if( is_numeric($this->uri->segment(3)) ) $temaoldal = $this->uri->segment(3);
		else $temaoldal = 0;
		$this->phpsession->save('temakoroldal',$temaoldal);

		$temak = $this->mforum->get_alaptemakorok($temaoldal);
		foreach( $temak as $tema ){
			$cim = $tema->cim;
			$tema->rov_cim = $tema->cim;

			/*if(strlen($tema->cim) > 26){
				$ut26 = array($cim[26]);
				$tomb = preg_grep("/[abcdefghijklmnopqrstxyzA-Z]/",$ut26);
			}
			if( count($tomb) == 0 ){
				if(strlen($tema->cim) > 26){
					$tema->rov_cim = substr($tema->cim,0,20);
					$tema->rov_cim .= "..";
				}
			}else{
				$tema->rov_cim = substr($tema->cim,0,27);
				if(strlen($tema->cim) > 27)
				$tema->rov_cim .= "..";
			}*/

			$xx = $this->mforum->get_tkuthsz($tema->temakor_id);
			if($xx != ""){
				$tema->datum = $xx->datum;
				if($xx->user != "586")
					$tema->utolsouser = $this->mforum->get_userUid($xx->user)->nev;
				else
					$tema->utolsouser = "Németh Kálmán";
			}
			else
				$tema->datum = $this->mforum->get_tkdate($tema->temakor_id);
		}

		usort( $temak, "hasonlito" );
		$data['temak'] = $temak;

		if( $this->mforum->vanmegtemakor($this->phpsession->get('temakoroldal')) ){
			$data['kovetkezo'] = true;
			$data['kov'] = ($temaoldal+1);
		}
		if( $temaoldal > 0 ){
			$data['elozo'] = true;
			$data['elobbi'] = ($temaoldal-1);
		}

		$data['oldalak_szama'] = $this->mforum->get_tkoldal();
		$data['akt_oldal'] = 1;

		$this->load->view('site_forum',$data);
	}

	function logout(){
		unset($_SESSION['default']['fuser']);
		unset($_SESSION['default']['feltolto']);
		redirect('forum');
	}

	function szerkeszt(){
		$tomb = $this->phpsession->get('fuser');
		if( $this->uri->segment(3) != "")
			$hszid = $this->uri->segment(3);
		else
			//$hszid = $this->phpsession->get('hszid');
			$hszid = $this->input->post('hszid');

		if( $this->mforum->moderator($tomb['name']) || $this->mforum->get_sajathsz($tomb['user_id'], $hszid) ){
			if($this->input->post('szerk')!=false){
				//$hszid = $this->phpsession->get('hszid');
				$hszid = $this->input->post('hszid');
				$this->mforum->hszszerk($this->input->post('hsz'),$hszid);
				$user_id = $this->mforum->get_hsz($hszid)->user_id;

				if( $this->input->post('kepki')=='on' ){
					if(hun())
						$kep =  $this->kepek_utvonal . $user_id ."/". $this->mforum->get_Kep($hszid)->kep;
					elseif(eng())
						$kep =  $this->kepek_utvonal_eng . $user_id ."/". $this->mforum->get_Kep($hszid)->kep;

					chmod($kep, 777);
					unlink($kep);
					$this->mforum->kepki($hszid);
				}

				$temaid = $this->phpsession->get('tema_id');
				header("Location: listaz/$temaid");
			}else if( $this->uri->segment(3) != "" ){
				$this->phpsession->save('hszid',$this->uri->segment(3));

				$data['szoveg']=$this->mforum->get_Text($this->phpsession->get('hszid'))->szoveg;
				$kep = $this->mforum->get_Kep($this->phpsession->get('hszid'))->kep;
				if( $kep != "" && $kep != "NULL" ){
					$user_id = $this->mforum->get_hsz($this->phpsession->get('hszid'))->user_id;
					if(hun())
						$data['kep'] = "/".$this->kepek_utvonal. $user_id . "/".$kep;
					elseif(eng())
						$data['kep'] = "/".$this->kepek_utvonal_eng. $user_id . "/".$kep;
				}

				hun() ? $data['title'] = 'ARCHLine.XP Fórum' : $data['title'] = 'ARCHLine.XP Forum';
				$data['javascript'] = array('../editor/fckeditor');
				$data['tartalom']='testforum/szerkeszt';
				$data['csik']=array('home','forum');

				$this->load->view('site_forum',$data);
			}else{
				$this->index();
			}
		}else{
			redirect('forum');
		}
	}

	function torles(){
		$tomb = $this->phpsession->get('fuser');
		$hszid = $this->uri->segment(3);
		if( $this->mforum->moderator($tomb['name']) || $this->mforum->get_sajathsz($tomb['user_id'], $hszid) ){
			if( $this->uri->segment(3) != "" ){
				$hszid = $this->uri->segment(3);
				$uid = $this->mforum->torol($hszid);

				//ha nincs kep a mappajaban:
				if(hun())
					$mappa = $this->kepek_utvonal . $uid;
				elseif(eng())
					$mappa = $this->kepek_utvonal_eng . $uid;

				$handle = opendir($mappa);
				//ha nincs fajl a konyvtarban, akkor toroljuk a mappat
				chmod($mappa,0777);
				$fajl = readdir($handle);
				$fajl = readdir($handle);
				$fajl = readdir($handle);
				if(!($fajl)){
					//closedir($mappa);
					rmdir($mappa);
				}

				$tema_id = $this->phpsession->get('temaid');
				if( is_int($this->mforum->get_temaoldal($tema_id)) && ($this->phpsession->get('oldal') == $this->mforum->get_temaoldal($tema_id)) ){
					$this->elozo();
				}
				redirect('forum/listaz');
			}else{
				$this->index();
			}
		}else{
			redirect('forum');
		}
	}

	function tatnevez(){
		$tomb = $this->phpsession->get('fuser');
		if( $this->mforum->moderator($tomb['name']) ){
			if( $this->uri->segment(3) != "" && ($this->input->post('atnevez')==false) ){
				$tid = $this->uri->segment(3);

				hun() ? $data['title'] = 'ARCHLine.XP Fórum' : $data['title'] = 'ARCHLine.XP Forum';
				$data['tartalom']='testforum/temaatnevez';
				$data['csik']=array('home','forum');
				$data['tema_id'] = $tid;
				$data['temacim'] = $this->mforum->get_cim($tid)->cim;
				$data['moderator'] = true;

				$this->load->view('site_forum',$data);
			}else if($this->input->post('atnevez')!=false){
				$this->mforum->tatnevez($this->input->post('tid'),$this->input->post('ujnev'));

				header("Location: index");
			}else{
				$this->index();
			}
		}else{
			redirect('forum');
		}
	}

	function tkatnevez(){
		$tomb = $this->phpsession->get('fuser');
		if( $this->mforum->moderator($tomb['name']) ){
			if( $this->uri->segment(3) != "" && ($this->input->post('atnevez')==false) ){
				$tid = $this->uri->segment(3);

				hun() ? $data['title'] = 'ARCHLine.XP Fórum' : $data['title'] = 'ARCHLine.XP Forum';
				$data['tartalom']='testforum/tkatnevez';
				$data['csik']=array('home','forum');
				$data['tema_id'] = $tid;
				$data['temacim'] = $this->mforum->get_tkcim($tid)->cim;
				$data['moderator'] = true;

				$this->load->view('site_forum',$data);
			}else if($this->input->post('atnevez')!=false){
				$this->mforum->tkatnevez($this->input->post('tid'),$this->input->post('ujnev'));

				header("Location: index");
			}else{
				$this->index();
			}
		}else{
			redirect('forum');
		}
	}

	function tematorol(){
		$tomb = $this->phpsession->get('fuser');
		if( $tomb && $this->mforum->moderator($tomb['name']) ){
			if( $this->uri->segment(3) != "" ){
				$tid = $this->uri->segment(3);
				$this->mforum->tematorol($tid);

				redirect('forum');
			}else{
				redirect('forum');
			}
		}else{
			redirect('forum');
		}
	}

	function temakortorol(){
		$tomb = $this->phpsession->get('fuser');
		if( $tomb && $this->mforum->moderator($tomb['name']) ){
			if( $this->uri->segment(3) != "" ){
				$tid = $this->uri->segment(3);
				$this->mforum->temakortorol($tid);

				redirect('forum');
			}else{
				redirect('forum');
			}
		}else{
			redirect('forum');
		}
	}

	function mypost(){
		$this->phpsession->save('valasz',false);

		$data['tartalom']='testforum/mypost';
		$data['csik']=array('home','forum');
		$data['javascript'] = array('forum');
		$user = $this->phpsession->get('fuser');

		if(!$user)
			redirect('forum');

		$hszek = $this->mforum->get_mypost($user['user_id']);
		foreach( $hszek as $hsz){
			$elo = $hsz->valasz;
			$hsz->valasz = $this->mforum->get_valaszok($hsz->hsz_id);
			$hsz->valaszdb = count($hsz->valasz);
			$hsz->elozo = $this->mforum->get_hsz($elo);
			$tema = $this->mforum->get_tema1($hsz->tema_id);
			$hsz->tema =  $this->mforum->get_tema1($hsz->tema_id);
			$temakor = $this->mforum->get_temakor1($tema->temakor_id);
			$hsz->temakor = $temakor->cim;

			//print_r($hsz->elozo);
		}

		$data['hozzaszolasok'] = $hszek;
		$data['hszdb'] = count($hszek);

		hun() ? $data['title'] = 'ARCHLine.XP Fórum' : $data['title'] = 'ARCHLine.XP Forum';

		$this->load->view('site_forum',$data);
	}


	function myuser(){
		$user = $this->phpsession->get('fuser');
		if($user){
			$tomb = $this->phpsession->get('fuser');
			$login = $tomb['name'];
			$this->user($login);
		}else
			redirect('forum');
	}

	function user($login){
		if(!$login)
			redirect('forum');

		hun() ? $data['title'] = 'ARCHLine.XP Fórum' : $data['title'] = 'ARCHLine.XP Forum';
		$data['tartalom']='testforum/user';
		$data['csik']=array('home','forum');
		$user = $this->phpsession->get('fuser');
		if($this->mforum->moderator($user['name']))
			$data['moderator']=true;

		$data['user']=$login;
		$data['adatok'] = $this->mforum->get_user($login);
		$szemadatok = $this->mforum->get_user_szem($login);
		$emailek = $szemadatok[0]->email;
		$emailek = explode(";",$emailek);
		$szemadatok[0]->email = "";
		foreach( $emailek as $email ){
			$szemadatok[0]->email .= $email . "<br />";
		}
		$van = $szemadatok[0]->nev;
		if($van)
			$data['szemadatok'] = $szemadatok;
		else
			$data['szemadatok'] = $this->mforum->get_user_alap($login);

		$kulcsok = $this->mforum->get_user_kulcsok($login);

		foreach($kulcsok as $key_kulcs => $kulcs){
			$programs = $this->mforum->getProgramsByHlNum($kulcs->kulcs_kod);

            foreach($programs as $key_program => $program){
                $modulok = $this->mforum->getModulesByPrID($program->prID);
                $programs[$key_program]->modulok = $modulok;
            }

            $kulcsok[$key_kulcs]->programok = $programs;
		}

        $data['kulcsok'] = $kulcsok;

		$data['aktmenu'] = "3";
		$this->load->view('site_forum',$data);
	}

	function users(){
		$user = $this->phpsession->get('fuser');
		if( $user && $this->mforum->moderator($user['name'])){
			hun() ? $data['title'] = 'ARCHLine.XP Fórum Felhasználók' : $data['title'] = 'ARCHLine.XP Forum Users';
			$data['tartalom']='testforum/users';
			$data['csik']=array('home','forum');

			$this->phpsession->save('ukoldal',0);
			$this->phpsession->save('klogin',"");
			$this->phpsession->save('knev',"");
			$this->phpsession->save('kemail',"");
			$this->phpsession->save('ksorozat',"");
			$this->phpsession->save('belep',"");

			if( !($this->phpsession->get('uoldal')) ){
				$this->phpsession->save('uoldal',0);
				$oldal = 0;
			}else{
				$oldal = $this->phpsession->get('uoldal');
			}

			if( $this->uri->segment(3) == kov ){
				$oldal++;
				$this->phpsession->save('uoldal',$oldal);
			}else if( $this->uri->segment(3) == elozo && $oldal > 0 ){
				$oldal--;
				$this->phpsession->save('uoldal',$oldal);
			}
			else if( is_numeric($this->uri->segment(3))){
				$oldal = $this->uri->segment(3);
				$this->phpsession->save('uoldal',$oldal);
			}

			if( $this->uri->segment(3) == "rendez" ){
				$ord = $this->uri->segment(4);


				$vissza = $this->phpsession->get('rendezvissza');
				if($this->phpsession->get('rendez') == $ord){
					$vissza = !$vissza;
				}
				$this->phpsession->save('rendezvissza',$vissza);


				$this->phpsession->save('rendez',$ord);
				$oldal = 0;
				$this->phpsession->save('uoldal',$oldal);
			}else if( $this->phpsession->get('rendez') ){
				$ord = $this->phpsession->get('rendez');
				$vissza = $this->phpsession->get('rendezvissza');
			}else{
				$ord = "nev";
				$vissza = false;
			}

			$data['users']=$this->mforum->get_users($oldal,$ord,$vissza);

			if( $this->mforum->vanmeguser($this->phpsession->get('uoldal')) )
				$data['kovetkezo'] = true;
			if( $this->phpsession->get('uoldal') > 0 )
				$data['elozo'] = true;

			$data['oldalak_szama'] = (int)$this->mforum->get_usersdb();
			$data['akt_oldal'] = $oldal;
			$data['moderator']=true;

			$data['aktmenu'] = "4";
			$this->load->view('site_forum',$data);
		}else{
			redirect('forum');
		}
	}

	function ukeres(){
		$user = $this->phpsession->get('fuser');
		if($this->mforum->moderator($user['name'])){
			hun() ? $data['title'] = 'ARCHLine.XP Fórum Felhasználók' : $data['title'] = 'ARCHLine.XP Forum Users';
			$data['tartalom']='testforum/users';
			$data['csik']=array('home','forum');
			$data['moderator'] = true;

			if( !($this->phpsession->get('ukoldal')) ){
				$this->phpsession->save('ukoldal',0);
				$oldal = 0;
			}else{
				$oldal = $this->phpsession->get('ukoldal');
			}

			if( is_numeric($this->uri->segment(3))){
				$oldal = $this->uri->segment(3);
				$this->phpsession->save('ukoldal',$oldal);
			}

			if( $this->uri->segment(3) == "rendez" ){
				$ord = $this->uri->segment(4);

				$vissza = $this->phpsession->get('rendezvissza');
				if($this->phpsession->get('rendez') == $ord){
					$vissza = !$vissza;
				}
				$this->phpsession->save('rendezvissza',$vissza);

				$this->phpsession->save('rendez',$ord);
				$oldal = 0;
				$this->phpsession->save('ukoldal',0);
			}else if( $this->phpsession->get('rendez') ){
				$ord = $this->phpsession->get('rendez');
				$vissza = $this->phpsession->get('rendezvissza');
			}else{
				$ord = "nev";
				$vissza = false;
			}

			if( $this->input->post('klogin') || $this->input->post('knev') || $this->input->post('kemail') || $this->input->post('kulcssz') || ($this->input->post('belep') != -1 && $this->input->post('belep') != "" ) ){
				$oldal = 0;
				$this->phpsession->save('ukoldal',$oldal);
				$klog = $this->input->post('klogin');
				$this->phpsession->save('klogin',$this->input->post('klogin'));
				$knev = $this->input->post('knev');
				$this->phpsession->save('knev',$knev);
				$kmail = $this->input->post('kemail');
				$this->phpsession->save('kemail',$this->input->post('kemail'));
				$kulcs = $this->input->post('kulcssz');
				$this->phpsession->save('kulcssz',$this->input->post('kulcssz'));
				$belep = $this->input->post('belep');
				$this->phpsession->save('belep',$this->input->post('belep'));
			}else{
				$klog = $this->phpsession->get('klogin');
				$knev = $this->phpsession->get('knev');
				$kmail = $this->phpsession->get('kemail');
				$kulcs = $this->phpsession->get('kulcssz');
				$belep = $this->phpsession->get('belep');
			}
			$users = $this->mforum->get_kusers($oldal,$klog,$knev,$kmail,$belep,$kulcs,$ord,$vissza);
			$data['users'] = $users;

			if( $this->mforum->vanmegkuser($this->phpsession->get('ukoldal'),$klog,$knev,$kmail,$belep,$kulcs) )
				$data['kovetkezo'] = true;
			if( $this->phpsession->get('ukoldal') > 0 )
				$data['elozo'] = true;



			$data['oldalak_szama'] = (int)$this->mforum->get_kusersdb($klog,$knev,$kmail,$belep,$kulcs);
			$data['akt_oldal'] = $oldal;

			$data['aktmenu'] = "4";
			$this->load->view('site_forum',$data);

		}else{
			redirect('forum');
		}
	}

	function edit_user(){
		$user = $this->phpsession->get('fuser');
		if($user && $this->mforum->moderator($user['name'])){
			if( $this->uri->segment(3) != "" && ($this->input->post('edituser')==false) ){
				$uid = $this->uri->segment(3);

				hun() ? $data['title'] = 'ARCHLine.XP Fórum Felhasználó szerkesztése' : $data['title'] = 'ARCHLine.XP Forum Edit User';
				$data['tartalom']='testforum/edit_user';
				$data['csik']=array('home','forum');
				$data['moderator'] = true;

				$login = $this->mforum->get_login($uid);
				$data['adatok'] = $this->mforum->get_user($login);

				$szemadatok = $this->mforum->get_user_szem($login);

				if($szemadatok[0])
					$data['szemadat'] = $szemadatok[0];
				else{
					$cucc = $this->mforum->get_user_alap($login);
					$data['szemadat'] = $cucc[0];
				}

				//$data['kulcsok'] = $this->mforum->get_user_kulcsok($login);

				$kulcsok = $this->mforum->get_user_kulcsok($login);


				$i=0;
				foreach($kulcsok as $key_kulcs => $kulcs){
					$i++;

					$programs = $this->mforum->getProgramsByHlNum($kulcs->kulcs_kod);

					foreach($programs as $key_program => $program){
						$modulok = $this->mforum->getModulesByPrID($program->prID);
						$programs[$key_program]->modulok = $modulok;
					}

					$kulcsok[$key_kulcs]->programok = $programs;


				}

				$data['kulcsok'] = $kulcsok;


				$data['aktmenu'] = "4";
				$this->load->view('site_forum',$data);
			}else if($this->input->post('edituser')!=false){

				$error = "";
				$langerror = array();
				if( ($this->input->post('jelszo1') != "" ||  $this->input->post('jelszo2') != "") && $this->input->post('jelszo1') != $this->input->post('jelszo2') ){
					$error .= "A megadott két jelszó nem egyezik.<br />";
					array_push($langerror,0);
				}else if( ($this->input->post('jelszo1') != "" ||  $this->input->post('jelszo2') != "") && $this->input->post('jelszo1') == $this->input->post('jelszo2') && strlen($this->input->post('jelszo1') ) < 5 ){
					$error .= "A megadott jelszó 5 karakternél rövidebb.<br />";
					array_push($langerror,1);
				}

				$user = $tomb['name'];
				//$myid = $this->mforum->get_userid($user);

				if( $this->input->post('login') == "" ){
					$error .= "A login mező értéke nem lehet üres.<br />";
					array_push($langerror,4);
				}

				if( $this->input->post('login') != "" && !$this->mforum->szabadlogin($this->input->post('login'),$this->input->post('uid')) ){
					$error .= "A megadott login már foglalt, kérem válasszon másikat.<br />";
					array_push($langerror,2);
				}
				elseif( strlen($this->input->post('login') ) < 5 ){
					$error .= "A megadott login 5 karakternél rövidebb.<br />";
					array_push($langerror,3);
				}

				if( $this->input->post('login') != $this->ekezet($this->input->post('login')) ){
					$error .= "A felhasználó névben nem szerepelhet ékezet vagy szóköz!<br />";
					array_push($langerror,5);
				}


				$uid = $this->input->post('uid');

				if( !$error ){

					$this->mforum->set_user($this->input->post('uid'),$this->input->post('nev'),$this->input->post('email'),$this->input->post('jelszo1'),$this->input->post('login'),$this->input->post('rang'));

					redirect("forum/users");
				}else{



					hun() ? $data['title'] = 'ARCHLine.XP Fórum Felhasználó szerkesztése' : $data['title'] = 'ARCHLine.XP Forum Edit User';
					$data['tartalom']='testforum/edit_user';
					$data['csik']=array('home','forum');
					$data['moderator'] = true;


					$login = $this->mforum->get_login($uid);
					$data['adatok'] = $this->mforum->get_user($login);

					$szemadatok = $this->mforum->get_user_szem($login);

					if($szemadatok[0])
						$data['szemadat'] = $szemadatok[0];
					else{
						$cucc = $this->mforum->get_user_alap($login);
						$data['szemadat'] = $cucc[0];
					}

					$kulcsok = $this->mforum->get_user_kulcsok($login);


					$i=0;
					foreach($kulcsok as $key_kulcs => $kulcs){
						$i++;
						$programs = $this->mforum->getProgramsByHlNum($kulcs->kulcs_kod);
						foreach($programs as $key_program => $program){
							$modulok = $this->mforum->getModulesByPrID($program->prID);
							$programs[$key_program]->modulok = $modulok;
						}
						$kulcsok[$key_kulcs]->programok = $programs;
					}

					$data['kulcsok'] = $kulcsok;

					$data['error'] = $error;
					$data['hibak2'] = $langerror;

					$data['aktmenu'] = "4";
					$this->load->view('site_forum',$data);

					print " ";
				}

				$ezt = "edit_user/".$uid;
				header("Location: ".$ezt);
			}else{
				$this->index();
			}
		}else{
			redirect('forum');
		}
	}

	function ujuser(){
		$user = $this->phpsession->get('fuser');
		if($user && $this->mforum->moderator($user['name'])){
			if($this->input->post('do')!=false){
				$login = $this->input->post('login');
				$nev = $this->input->post('nev');
				$jsz1 = $this->input->post('jelszo1');
				$jsz2 = $this->input->post('jelszo2');
				$email = $this->input->post('email');
				$kulcs = $this->input->post('kulcs');
				$rang = $this->input->post('rang');

				if($kulcs)
					$nUserID = $this->mforum->get_nUserID($kulcs);
				else
					$nUserID = "NULL";

				$error = "";
				$langerror = array();

				if( $login == "" )
					$error .= "Nincs login megadva.<br />";

				if( $login != $this->ekezet($login) )
					$error .= "A felhasználó névben nem lehet ékezet vagy szóköz.<br />";
				elseif( !$this->mforum->szabadlogin($login,10000) )
					$error .= "A megadott login már foglalt, kérem válasszon másikat.<br />";

				if( $jsz1 == "" || $jsz2 == "" || $jsz1 != $jsz2 )
					$error .= "A két jelszó nem egyezik vagy nincsenek megadva.<br />";

				if( $this->mforum->is_email($email) )
					$error .= "A megadott e-mail-cím már szerepel az adatbázisban.<br />";

				if(!$error){
					$this->mforum->ujuser($login,$nev,$jsz1,$email,$nUserID,$rang);

					redirect('forum/users');
				}else{
					hun() ? $data['title'] = 'ARCHLine.XP Fórum új felhasználó' : $data['title'] = 'ARCHLine.XP Forum new user';
					$data['tartalom']='testforum/ujuser';
					$data['csik']=array('home','forum');
					$data['error2'] = $error;
					$data['moderator']=true;
					$data['javascript']=array('forum');

					$data['aktmenu'] = "4";
					$this->load->view('site_forum',$data);
				}

			}else{
				$data['title'] = 'ARCHLine.XP Fórum új felhasználó';
				hun() ? $data['title'] = 'ARCHLine.XP Fórum Új Felhasználó' : $data['title'] = 'ARCHLine.XP Forum New User';
				$data['tartalom']='testforum/ujuser';
				$data['csik']=array('home','forum');
				$data['javascript']=array('forum');
				$data['moderator']=true;

				$data['aktmenu'] = "4";
				$this->load->view('site_forum',$data);
			}
		}else{
			redirect('forum');
		}
	}

	function del_user(){
		$user = $this->phpsession->get('fuser');
		if($this->mforum->moderator($user['name'])){
			$id = $this->uri->segment(3);
			$this->mforum->del_user($this->uri->segment(3));
			redirect("forum/users");
		}else{
			redirect('forum');
		}
	}

	function ujuserdb(){
		$user = $this->phpsession->get('fuser');
		if($this->mforum->moderator($user['name'])){
			hun() ? $data['title'] = 'ARCHLine.XP Fórum Felhasználók' : $data['title'] = 'ARCHLine.XP Forum Users';
			$data['tartalom']='testforum/users';
			$data['csik']=array('home','forum');




			$this->access_id = 36;

			$this->load->model('mpartners');
			$this->keydb = $this->load->database('clusers',true);
			$search = false;//$this->input->post('search');

			$from = 0;
			$to = 999999;
			$limit = 2000;

			$this->keydb->query("SET NAMES utf8");
			$result = $this->keydb->from('cl_fo_hardlock')->join('cl_users','cl_fo_hardlock.hlUser=cl_users.nUserID','left')->orderby('hlNum','desc')->where("hlCtrID ='".$this->access_id."'")->where('hlStat',1)->where("hlNum >= '".$from."' AND hlNum <= '".$to."'")->limit(99999)->get();

			//$sorok = $result->result();





			$query = $this->keydb->from('cl_fo_hardlock')->join('cl_users','cl_fo_hardlock.hlUser=cl_users.nUserID','left')->join('cl_users_emails','cl_users.nUserID=cl_users_emails.nUserID','left')->orderby('hlNum','desc')->where("hlCtrID ='".$this->access_id."'")->where('hlStat',1)->where('default',1)->where("hlNum >= '".$from."' AND hlNum <= '".$to."'")->limit(99999)->get();
			$sorok = $query->result();


			//$this->keydb->query("SET NAMES latin2");




			if($result->num_rows()==0)
			{
				$data['sorok'] = false;
			}
			else
			{
				$data['sorok'] = $sorok;
				$data['found'] = $result->num_rows();
			}

			$sorok2 = $sorok;
			$i = 0;
			$j = 0;
			$db = 0;
			foreach($sorok2 as $sor){
				$mailek = $sor->email;
				$mailek = explode(";",$mailek);

				foreach( $mailek as $mail ){
					$mail = trim($mail);

					//megnezzuk hogy benne van-e az adatbázisban és aktív-e
					if( $mail != "" && $sor->hlStat == 1  && !$this->mforum->is_email(strtolower($mail)) ){
						$mailresz = explode('@',$mail);
						$login = $mail;
						$nev = $sor->strName;
						$nev = trim($nev);
						$jsz1 = $mailresz[0];
						$nUserID = $sor->nUserID;
						$rang = "user";

						// eladási dátum 0000-00-00 -e
						$datum = $this->keydb->from('cl_fo_programs')->where("prHlNum",$sor->hlNum)->select('prSellDate')->get()->row();
						if($datum->prSellDate != '0000-00-00'){
							$this->mforum->ujuser($login,$nev,$jsz1,strtolower($mail),$nUserID,$rang);
							$db++;
							$kik[$j]->Nev = $nev;
							$kik[$j]->Login = $login;
							$kik[$j]->Email = $mail;
							$kik[$j]->Datum = $datum->prSellDate;
						}
						$j++;
					}
				}
				$i++;
			}
			$data['darab'] = $db;
			$data['kik'] = $kik;



			$data['sorok2'] = $sorok2;




			$oldal = 0;
			$this->phpsession->save('uoldal',$oldal);
			if( $this->phpsession->get('rendez') )
				$ord = $this->phpsession->get('rendez');
			else
				$ord = "nev";

			$data['users']=$this->mforum->get_users($oldal,$ord);

			if( $this->mforum->vanmeguser($this->phpsession->get('uoldal')) )
				$data['kovetkezo'] = true;
			if( $this->phpsession->get('uoldal') > 0 )
				$data['elozo'] = true;

			$data['oldalak_szama'] = (int)$this->mforum->get_usersdb();
			$data['akt_oldal'] = $oldal;
			$data['moderator']=true;

			$this->phpsession->save('ukoldal',0);
			$this->phpsession->save('klogin',"");
			$this->phpsession->save('knev',"");
			$this->phpsession->save('kemail',"");
			$this->phpsession->save('ksorozat',"");

			$this->load->view('site_forum',$data);
		}else
			redirect('forum');
	}

	function myedit(){
		$tomb = $this->phpsession->get('fuser');
		if( $tomb ){
			if($this->input->post('mysave')!=false){

				$error = "";
				$langerror = array();
				if( ($this->input->post('jelszo1') != "" ||  $this->input->post('jelszo2') != "") && $this->input->post('jelszo1') != $this->input->post('jelszo2') ){
					$error .= "A megadott két jelszó nem egyezik.<br />";
					array_push($langerror,0);
				}else if( ($this->input->post('jelszo1') != "" ||  $this->input->post('jelszo2') != "") && $this->input->post('jelszo1') == $this->input->post('jelszo2') && strlen($this->input->post('jelszo1') ) < 5 ){
					$error .= "A megadott jelszó 5 karakternél rövidebb.<br />";
					array_push($langerror,1);
				}

				$user = $tomb['name'];
				$myid = $this->mforum->get_userid($user);

				if( $this->input->post('login') == "" ){
					$error .= "A login mező értéke nem lehet üres.<br />";
					array_push($langerror,4);
				}

				if( $this->input->post('login') != "" && !$this->mforum->szabadlogin($this->input->post('login'),$myid) ){
					$error .= "A megadott login már foglalt, kérem válasszon másikat.<br />";
					array_push($langerror,2);
				}
				elseif( strlen($this->input->post('login') ) < 5 ){
					$error .= "A megadott login 5 karakternél rövidebb.<br />";
					array_push($langerror,3);
				}

				if( $this->input->post('login') != $this->ekezet($this->input->post('login')) ){
					$error .= "A felhasználó névben nem szerepelhet ékezet vagy szóköz!<br />";
					array_push($langerror,5);
				}


				$ertesitesek = $this->input->post('temak');
				if(count($ertesitesek) == 0 || (count($ertesitesek) == 1 && $ertesitesek[0] == "") )
					$ertesit = NULL;
				elseif( count($ertesitesek) == count($this->mforum->get_temak()) )
					$ertesit = "mind";
				else
					$ertesit = ";".implode(";", $ertesitesek).";";


				if($error){
					hun() ? $data['title'] = 'ARCHLine.XP Adatok változtatása' : $data['title'] = 'ARCHLine.XP Edit Data';
					$data['tartalom']='testforum/myedit';
					$data['csik']=array('home','forum');
					$user = $this->phpsession->get('fuser');
					if($this->mforum->moderator($user['name']))
						$data['moderator']=true;
					$data['error2'] = $error;
					$data['hibak2'] = $langerror;

					$user = $tomb['name'];
					$user_id = $this->mforum->get_userid($user);
					$data['user_id'] = $user_id;
					$data['cucc'] = $this->mforum->get_user_alap($user);

					$data['aktmenu'] = "3";
					$this->load->view('site_forum',$data);
				}else{
					$plogin = $this->input->post('login');
					$pnev = $this->input->post('nev');
					$pjelszo = $this->input->post('jelszo1');

					$this->mforum->myedit($plogin, $pnev, $pjelszo, $myid, $ertesit);
					$fuser['lang']=$this->muser->user['lang'];
					$fuser['t_nev'] = $this->mforum->get_nev($plogin);
					$fuser['name'] = $this->input->post('login');
					$this->phpsession->save('fuser',$fuser);
					$this->myuser();
				}
			}else{
				hun() ? $data['title'] = 'ARCHLine.XP Adatok változtatása' : $data['title'] = 'ARCHLine.XP Edit Data';
				$data['tartalom']='testforum/myedit';
				$data['csik']=array('home','forum');
				$user = $this->phpsession->get('fuser');
				if($this->mforum->moderator($user['name']))
					$data['moderator']=true;

				if(hun())
					$nyelv = "hun";
				else
					$nyelv = "eng";

				$user = $tomb['name'];
				$user_id = $this->mforum->get_userid($user);
				$data['user_id'] = $user_id;
				$data['temak'] = $this->mforum->get_temak($nyelv);
				$data['cucc'] = $this->mforum->get_user_alap($user);

				$data['aktmenu'] = "3";
				$this->load->view('site_forum',$data);
			}
		}else{
			redirect('forum');
		}
	}

	function ujjelszo(){
		if($this->input->post('kuld')!=false){
			$email = $this->input->post('email');
			$uzenet = "A megadott e-mail-cím: " . $email;
			//$uzenet = $email;

			$ujjelszo = $this->mforum->ujjelszo($email);

			if($ujjelszo){

				$this->load->library('email');
				$this->load->helper('email');
				$this->email->initialize();
				$this->email->addOfficialImages();

				$mailnek->ujjsz = $ujjelszo;
				$mailnek->login = $this->mforum->get_login2($email);


				/* Akarmilyem mailcimet is adott meg, a default emailre kuldjuk a levelet */
				$email2 = $this->mforum->default_mail($email);
				if($email2 != "")
					$email = $email2;


				$this->email->from('info@cadline.hu', 'Cadline Weboldal');
				if(hun())
					$this->email->subject('Uj jelszo');
				else
					$this->email->subject('New Password');
				$this->email->message($this->load->view('mail_ujjelszo',$mailnek,true));
				$this->email->send($email,'smtp');

				$uzenet = $email." -re kiküldtük az Ön új jelszavát.<br />";

			}else{
				$uzenet .= " nincs a felhasználók között.<br />";
			}

			hun() ? $data['title'] = 'ARCHLine.XP Fórum új jelszó' : $data['title'] = 'ARCHLine.XP Forum new password';

			$data['uzenet']=$uzenet;
			$this->phpsession->save('fuzenet',$uzenet);

			if( isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'],'/collection/') ){
				$data['tartalom']='collection/ujjelszo_valasz';
				$data['style'] = array('temp/style_new');
				$this->load->view('site_upload',$data);
			}
			else{
				$data['tartalom']='testforum/temakorok';
				$data['csik']=array('home','forum');
				$this->load->view('site_forum',$data);
			}

		}else{
			hun() ? $data['title'] = 'ARCHLine.XP Fórum új jelszó' : $data['title'] = 'ARCHLine.XP Forum new password';

			$data['tartalom']='testforum/ujjelszo';
			$data['csik']=array('home','forum');

			if( strstr($_SERVER['HTTP_REFERER'],'collection/upload') || strstr($_SERVER['HTTP_REFERER'],'collection/submit') ){
				$data['style'] = array('temp/style_new');
				$this->load->view('site_upload',$data);
			}
			else{
				$this->load->view('site_new',$data);
			}
		}
	}

	function szabalyzat(){
		if(hun())
			$lap = $this->mpages->get_row(454);
		else
			$lap = $this->mpages->get_row(559);

		hun() ? $data['title'] = 'ARCHLine.XP Fórum szabályzat' : $data['title'] = 'ARCHLine.XP Forum Rules';
        $data['tartalom'] = '/forum/szabalyzat';
        $data['lap'] = $lap;
        $user = $this->phpsession->get('fuser');
		if($this->mforum->moderator($user['name']))
			$data['moderator']=true;

		$uid = $this->mforum->get_userid($user['name']);
		//ha még nem fogadta el a szabályzatot:
		if( !($this->mforum->szabalyzat($uid) ) ){
			$data['uid'] = $uid;
			$data['nemelfogad'] = true;
		}

		$data['aktmenu'] = "2";
		$this->load->view('site_forum',$data);
	}

	function elfogad(){
		if($this->input->post('el')=="igen"){

			$uid = $this->input->post('uid');
			$name = $this->input->post('fnev');
			$passwd = $this->input->post('jelszo');
			if( $this->mforum->belep($name,$passwd,false) ){
				$this->mforum->elfogad($uid);

				$fuser['lang']=$this->muser->user['lang'];
				$fuser['name']=$this->mforum->get_login($uid);
				$fuser['t_nev'] = $this->mforum->get_nev($name);

				$fuser['user_id'] = $uid;


				$this->phpsession->save('fuser',$fuser);
				$Date = date('Y-m-d',time());

				$nUserID = $this->mforum->get_nUserID2($uid);
			}

			redirect('forum');

		}else{
			$this->logout();
		}
	}

	function ido(){
	   die(date('Y-m-d H:i:s', time()));
	}

	function emailjavitas(){
		$tomb = $this->phpsession->get('fuser');
		if(!$tomb)
			redirect('forum');

		hun() ? $data['title'] = 'ARCHLine.XP Fórum Felhasználók' : $data['title'] = 'ARCHLine.XP Forum Users';
		$data['tartalom']='testforum/users';
		$data['csik']=array('home','forum');

		$cl_users = $this->mforum->get_cl_users();

		$db = 0;
		$cserek = "";
		foreach($cl_users as $user){
			$nUserID = $user->nUserID;
			//print $user->strName;
			$x = $this->mforum->cseremail($nUserID);
			if( $x ){
				$cserek .= $x;
				$db++;
			}
		}

		$data['email']=$db;
		$data['cserek']=$cserek;



		$oldal = 0;
		$this->phpsession->save('uoldal',$oldal);
		if( $this->phpsession->get('rendez') )
			$ord = $this->phpsession->get('rendez');
		else
			$ord = "nev";

		$data['users']=$this->mforum->get_users($oldal,$ord);

		if( $this->mforum->vanmeguser($this->phpsession->get('uoldal')) )
			$data['kovetkezo'] = true;
		if( $this->phpsession->get('uoldal') > 0 )
			$data['elozo'] = true;

		$data['oldalak_szama'] = (int)$this->mforum->get_usersdb();
		$data['akt_oldal'] = $oldal;
		$data['moderator']=true;

		$this->phpsession->save('ukoldal',0);
		$this->phpsession->save('klogin',"");
		$this->phpsession->save('knev',"");
		$this->phpsession->save('kemail',"");
		$this->phpsession->save('ksorozat',"");

		$this->load->view('site_forum',$data);
	}

	function ujuserdb_eng(){
		$user = $this->phpsession->get('fuser');
		if($this->mforum->moderator($user['name'])){
			hun() ? $data['title'] = 'ARCHLine.XP Fórum Felhasználók' : $data['title'] = 'ARCHLine.XP Forum Users';
			$data['tartalom']='testforum/users';
			$data['csik']=array('home','forum');
			$oldal = 0;
			$this->phpsession->save('uoldal',$oldal);
			if( $this->phpsession->get('rendez') )
				$ord = $this->phpsession->get('rendez');
			else
				$ord = "nev";

			$data['users']=$this->mforum->get_users($oldal,$ord);

			if( $this->mforum->vanmeguser($this->phpsession->get('uoldal')) )
				$data['kovetkezo'] = true;
			if( $this->phpsession->get('uoldal') > 0 )
				$data['elozo'] = true;

			$data['oldalak_szama'] = (int)$this->mforum->get_usersdb();
			$data['akt_oldal'] = $oldal;
			$data['moderator']=true;

			$this->phpsession->save('ukoldal',0);
			$this->phpsession->save('klogin',"");
			$this->phpsession->save('knev',"");
			$this->phpsession->save('kemail',"");
			$this->phpsession->save('ksorozat',"");

			$sorok = $this->mforum->get_cl_users_eng();

			$i = 0;
			$j = 0;
			$db = 0;
			foreach($sorok as $sor){
				$mailek = $sor->strEMail;
				$mailek = explode(";",$mailek);

				foreach( $mailek as $mail ){
					/*  csak az elso email cimet veszi fel  */
					$mail = trim($mailek[0]);


					//megnezzuk hogy benne van-e az adatbázisban és aktív-e
					if( $mail != "" && $sor->hlStat == 1  && !$this->mforum->is_email(strtolower($mail)) ){
						$mailresz = explode('@',$mail);
						$login = $mail;
						$nev = $sor->strName;
						$nev = trim($nev);
						$jsz1 = $mailresz[0];
						$nUserID = $sor->nUserID;
						$rang = "user";


						// eladási dátum 0000-00-00 -e
						$datum = $this->db->from('`clusers_eng`.`cl_fo_programs`')->where("prHlNum",$sor->hlNum)->select('prSellDate')->get()->row();

						$prog = $this->db->query(" SELECT * FROM `clusers_eng`.`cl_fo_programs` WHERE prHlNum = '".$sor->hlNum."'")->result();

						if($datum->prSellDate != '0000-00-00' && $this->mforum->szabadlogin($login) ){
							$this->mforum->ujuser_eng($login,$nev,$jsz1,strtolower($mail),$nUserID,$rang);

					//		print "<br />Felvenném: ".$login.$nev.$jsz1.strtolower($mail).$nUserID.$rang;

							$db++;
							$kik[$j]->Nev = $nev;
							$kik[$j]->Login = $login;
							$kik[$j]->Email = $mail;
							$kik[$j]->Datum = $datum->prSellDate;
						}
						$j++;
					}
				}
				$i++;
			}
			$data['darab'] = $db;
			$data['kik'] = $kik;

			$data['sorok2'] = $sorok;

			$this->load->view('site_forum',$data);
		}else{
			redirect('forum');
		}
	}

	function info($info){
		$data['title'] = 'ARCHLine.XP';
        $data['tartalom'] = '/forum/kiir';
        $data['info'] = $info;

		$this->load->view('site_forum',$data);
	}

	function galeria(){
		$user = $this->phpsession->get('fuser');

		if( is_numeric($this->uri->segment(3)) ){
			$this->galeriamutat();
		}elseif($user){
			$this->sajatgaleria();
		}else{
			redirect("forum");
		}
	}

	function galeriamutat(){
		$user_id = $this->uri->segment(3);
		$lang = $this->muser->user['lang'];

		$fajlok = $this->mforum->get_galeria($user_id,$lang);

		$data["fajlok"] = $fajlok;
		if(hun())
			$data['utvonal'] = $this->galeria_utvonal.$user_id;
		else
			$data['utvonal'] = $this->galeria_utvonal_eng.$user_id;

		$data['tartalom'] = '/forum/galeria';
		$data['javascript'] = array(
			'interior_menu',
	    	'fancybox/jquery-1.3.2.min',
			'fancybox/jquery.easing.1.3',
			'fancybox/jquery.fancybox-1.2.1.pack',
			'fancybox/fancy'
		);

		$data['style'] = array('fancybox');

		$this->load->view('site_forum',$data);

	}

	function sajatgaleria(){
		$this->load->model('mrender');
		$user = $this->phpsession->get('fuser');

		if($user){
			hun() ? $data['title'] = 'ARCHLine.XP Saját Galéria' : $data['title'] = 'ARCHLine.XP My Gallery';
			$data['tartalom'] = '/forum/sajatgaleria';

			$uid = $user['user_id'];
			$data['uid'] = $uid;

			$data['fajlok'] = $this->mforum->fajlok($uid);
			$data['szabad_hely'] = (200 * 1024 * 1024) - $this->foglalt_hely($uid);

	//		$data['renderek'] = $this->mrender->get_byuserid($uid);

			$data['javascript'] = array('fancybox/jquery-1.3.2.min','fancybox/jquery.easing.1.3','fancybox/jquery.fancybox-1.2.1.pack','fancybox/fancy','jquery','jquery_ui');
			$data['style'] = array('fancybox2','jquery.ui');

			if($this->mforum->moderator($user['name']))
				$data['moderator']=true;

			$data['aktmenu'] = "5";
			$this->load->view('site_forum',$data);
		}else
			redirect("forum");
	}

	function foglalt_hely($user_id){
		if(hun())
			$fajlok = $this->galeria_utvonal.$user_id."/";
		else
			$fajlok = $this->galeria_utvonal_eng.$user_id."/";

		$total = 0;

		$handle = opendir($fajlok);
		while($file = readdir($handle)){
			$total += filesize ($fajlok.$file);
			if((is_dir($fajlok.$file.'/')) &&($file != '..')&&($file != '.'))
			{
				$total = $total + $this->foglalt_hely($fajlok.$file.'/');
			}
		}

		return $total;
	}

	function feltolt(){
		$user = $this->phpsession->get('fuser');
        $uid = $user['user_id'];

        if($uid && $_FILES["fajl"]["error"]==0){

			$fajl = "";
			$meret = 0;

			if(hun())
				$hova = $this->galeria_utvonal.$uid;
			elseif(eng())
				$hova = $this->galeria_utvonal_eng.$uid;

			if(!is_dir($hova)){
				mkdir($hova,0644);
				chmod($hova,0777);
			}


			$feltolt_konyvtar = $hova."/";
			//ha több fájl lenne ugyanazon a néven
			$elotag = substr(time(),-6);
			$fajlnev = $this->ekezet($_FILES["fajl"]["name"]);
			$feltolt_fajlnev=$feltolt_konyvtar . $elotag . "__" . $fajlnev;

			$error = "";
			$mi = $_FILES['fajl']['name']."$";

			$mire = "\.exe|\.EXE|\.php|\.PHP|\.sh|\.SH";
			if( (ereg( $mire , $mi )) ){
				$error .= "Hibás fájl kiterjesztés<br />";
			}
			if( $_FILES['fajl']['size'] > 1024 * 1024 * 10 ){
				$error .= "A fájl mérete nagyobb 10 MB-nál.<br />";
			}
			else if( !$error){
				if (copy($_FILES["fajl"]["tmp_name"], $feltolt_fajlnev)){
					$fajl = $elotag . "__". $fajlnev;
					$meret = $_FILES["fajl"]["size"];
					$mit = $hova."/".$fajl;
					chmod($mit,0777);


					// elonezeti kep elkeszitese 150x113-ban
					include('application/helpers/myimg_helper.php');
					kepmeretezesvagas($feltolt_fajlnev,$hova,"elo_".$fajl,"150","113");

				}else{
					$fajl = "NULL";
					$error = "Fájl másolás hiba.<br />";
				}
			}

			if( !$error ){
				$szamla = $this->input->post('szamla');
				$info = $this->input->post('leiras');
				$megoszt = 1;

				if( $this->input->post('megosztas') != "on" ){
					$megoszt = 0;
				}

				$this->mforum->feltolt($uid,$fajl,$meret,$szamla,$megoszt,$info);

				redirect("forum/galeria/".$uid);
			}else{
				$this->info($error);
			}


		}else{
			if( $_FILES['fajl']['error'] != 0 )
				$this->info("Hiba a fájl feltöltésekor!");
			else
				redirect("forum");
		}

	}

	function delfajl(){
		$fajl_id = $this->uri->segment(3);
		$user = $this->phpsession->get('fuser');
		$user_id = $user['user_id'];

		if(!$user)
			redirect('forum');

		if( is_numeric($fajl_id) && $this->mforum->sajatfajl($fajl_id, $user_id) ){
			$this->load->model('mrender');

			$fajl = $this->mforum->delfajl($fajl_id);

			if(hun())
				$mit = "public/forum-galeria/hun/".$user_id."/elo_".$fajl;
			else
				$mit = "public/forum-galeria/eng/".$user_id."/elo_".$fajl;

			// elonezeti kep torlese ha van
			if( file_exists( $mit ) ){
				chmod($mit, 777);
				unlink($mit);
			}

			//	A fájlhoz tartozó rendereknél törölni a galériás fájl id-t.
			$renderek = $this->mrender->get_rowBygforumgalid($fajl_id);
			if( $renderek ){
				foreach($renderek as $render){
					$ertek = NULL;
					$this->db->update('render_img',array('forumgal_id'=>$ertek),"render_id='".$render->render_id."'");
				}
			}
		}
		redirect("forum/galeria");
	}

	function editgaleria(){
		$fajl_id = $this->input->post('fajl_id');
	//	$fajl_id = $this->uri->segment(3);
		$user = $this->phpsession->get('fuser');
		$user_id = $user['user_id'];

		if(!$user)
			redirect('forum');


		if( is_numeric($fajl_id) && $this->mforum->sajatfajl($fajl_id, $user_id) ){
			if( $this->input->post('do') ){
				$leiras = $this->input->post('leiras');
				$megoszt = 1;

				if( $this->input->post('megosztas') != "on" ){
					$megoszt = 0;
				}

				$this->mforum->editgaleria($fajl_id,$leiras,$megoszt);

				redirect("forum/galeria");

			}else{
				hun() ? $data['title'] = 'ARCHLine.XP Saját Galéria' : $data['title'] = 'ARCHLine.XP My Gallery';
				$data['tartalom'] = '/forum/editgaleria';

				$data['uid'] = $user_id;
				$data['fajlinfo'] = $this->mforum->fajlinfo($fajl_id);
				if(hun())
					$data['utvonal'] = $this->galeria_utvonal;
				else
					$data['utvonal'] = $this->galeria_utvonal_eng;

				$data['utvonal'] .= "/".$user_id;

				if($this->mforum->moderator($user['name']))
					$data['moderator']=true;

				$data['aktmenu'] = "5";
				$this->load->view('site_forum',$data);
			}
		}else{
			redirect("forum");
		}
	}

	function regisztracio(){
		if($this->input->post('do') != ""){
			$nev = $this->input->post('regnev');
			$login = $this->input->post('email');
			$email = $login;
			$jelszo = $this->input->post('jelszo1');

			$szabad = $this->mforum->szabadlogin($login,999999);
			if( $szabad ){
				//$this->mforum->ujuser($login,$nev,$jelszo,$email,"","feltolto");


				$kod = md5($jelszo.time().$nev);

				$record['login'] = $email;
				$record['jelszo'] = md5($jelszo);
				$record['nev'] = $nev;
				$record['email'] = $email;
				$record['rang'] = "guest";
				$record['kod'] = $kod;
				$record['datum'] = date("Y-m-d H:i:s",time());
				$record['nyelv'] = $this->muser->user['lang'];

				$this->db->insert('forum_user_temp',$record);


				$this->load->helper('email');

				//sending the e-mail
				$mail_vars['kod'] = $kod;
				$mail_vars['email'] = $email;
				$mail_vars['first'] = $nev;

				//set the authenticating link
				$mail_vars['link'] = hun() ? 'http://archline.hu/forum/confirm/' . $kod : 'http://www.archlinexp.com/forum/confirm/' . $kod;

				//setting and sending the email
				$this->load->library('email');
				$this->email->initialize();
				$this->email->addOfficialImages();

				$this->email->setFrom('info@cadline.hu', 'CadLine');

				if(hun())
				{
					$mail_vars['mailcontent'] = 'mail/confirm_forum_hun';
					$this->email->subject('ARCHLine.XP regisztráció');
				}
				else
				{
					$mail_vars['mailcontent'] = 'mail/confirm_forum_eng';
					$this->email->subject('ARCHLine.XP registration');
				}

				$this->email->message($this->load->view('mail',$mail_vars,true));
				$this->email->send($mail_vars['email'],'smtp');

				redirect('forum/sentconf');
			}
			else{
				$data['title'] = 'ARCHLine.XP';
				$data['tartalom'] = '/forum/regisztracio';
				$data['javascript'] = array('forum');
				$data['style'] = array('temp/style_interior');
				$data['foglalt'] = "igen";

				$this->load->view('site_upload',$data);
			}
		}else{
			$data['title'] = 'ARCHLine.XP';
			$data['tartalom'] = '/forum/regisztracio';
			$data['javascript'] = array('forum');
			$data['style'] = array('temp/style_interior');

			$this->load->view('site_upload',$data);
		}
	}

	function sentconf(){
		$data['tartalom']='testforum/sentconf';
		$data['lang']=$this->muser->user['lang'];
		$data['style'] = array('temp/style_new');

		$this->load->view('site_upload',$data);
	}

	function confirm(){
		$kod = $this->uri->segment(3);

		$data['style'] = array('temp/style_new');

		if( $this->mforum->confirm($kod) ){

			/*  a felhasználóhoz új eseményt felvenni, ha szerepel az adatbázisban  */
			$adatok = $this->mforum->get_userByKod($kod);
			$nUserID = $this->mforum->get_nUserID30($adatok->email);
			if( $nUserID ){
				$this->load->model('mclusers');
				$this->mclusers->addEvent($nUserID, 114, "Regisztráció");
			}

			$data['tartalom']='testforum/confirm_ok';
			$data['lang']=$this->muser->user['lang'];
		}else{
			$data['tartalom']='testforum/confirm_hiba';
			$data['lang']=$this->muser->user['lang'];
		}

		$this->load->view('site_upload',$data);
	}

	function belepfeltolto(){
		if( $this->input->post("do") != "" ){
			$login = $this->input->post("email");
			$jelszo = $this->input->post("jelszo");

			if( $this->mforum->belep($login,$jelszo) ){
				print "ok";
			}else
				print "nem ok";

		}else{
			$data['title'] = 'ARCHLine.XP';
			$data['tartalom'] = '/forum/belepfeltolto';
			$data['javascript'] = array('forum');

			$this->load->view('site',$data);
		}
	}

	function renderek(){
		$this->load->model('mrender');
		$user = $this->phpsession->get('fuser');
		$feltolto = $this->phpsession->get('feltolto');

		if($user){
			$uid = $user['user_id'];

			if($this->mforum->moderator($user['name']))
				$data['moderator']=true;

		}elseif($feltolto){
			$uid = $feltolto['user_id'];
		}
		else
			redirect("forum");

		hun() ? $data['title'] = 'ARCHLine.XP Renderek' : $data['title'] = 'ARCHLine.XP Renders';
		$data['tartalom'] = '/forum/renderek';

		$data['uid'] = $uid;

		$renderek = $this->mrender->get_byuserid($uid);

		foreach($renderek as $render){
			if($render->allapot=='1' && file_exists($render->keszkep)){
				list($width, $height) = getimagesize($render->keszkep);
				$render->kepmeret = $width . " x ". $height;
			}
			else{
				$render->kepmeret = '-';
			}

		}

		$data['renderek'] = $renderek;

		$data['onload'] = "betolt()";

		$data['javascript'] = array('fancybox/jquery-1.3.2.min','fancybox/jquery.easing.1.3','fancybox/jquery.fancybox-1.2.1.pack','fancybox/fancy','jquery_ui');
		$data['style'] = array('fancybox2','jquery.ui');
		$data['aktmenu'] = "6";
		$this->load->view('site_forum',$data);
	}

	function delrender(){
		$this->load->model('mrender');

		$render_id = $this->uri->segment(3);
		$user = $this->phpsession->get('fuser');
		if(!$user)
			$user = $this->phpsession->get('feltolto');

		if(!$user)
			redirect('forum');

		$render = $this->mrender->get_row($render_id);

		if( is_numeric($this->uri->segment(3)) && $render->user_id == $user['user_id'] ){
			$this->mrender->del($render_id);
		}

		header("Location: ".$_SERVER["HTTP_REFERER"]);
	}

	function rendercopy(){
		$this->load->model('mrender');

		$guid = $this->uri->segment(3);
		$render = $this->mrender->get_rowByguid($guid);

		if( is_numeric($render->render_id) ){
			if( $this->muser->user['lang'] == "hun" )
				$almappa = "hun";
			else
				$almappa = "eng";

			$uid = $render->user_id;

			$helye = "public/forum-galeria/".$almappa."/".$uid;

			if(!is_dir($helye)){
				mkdir($helye,0644);
				chmod($helye,0777);
			}

			$fajluj = basename($render->keszkep);

			$honnan = $render->keszkep;
			$hova = $helye."/".$fajluj;

			if( copy($honnan,$hova) ){
				$meret = filesize($hova);
				$this->mforum->feltolt($render->user_id,$fajluj,$meret,"","1",$render->render_name,$render->nyelv);
				$fajl_id = $this->db->insert_id();
				$this->db->update('render_img',array('forumgal_id'=>$fajl_id),"render_id='".$render->render_id."'");

				$uzenet = array(4);
				$this->phpsession->save('fuzenet',$uzenet);

				// elonezeti kep masolasa is ha van
				$fajlnev = basename($render->keszkep);
				$mappak = substr( $render->keszkep,0,(-1*(strlen($fajlnev))) );
				$elokep = $mappak."elo_".$fajlnev;
				if(file_exists($elokep)){
					$ujelokep = $helye."/elo_".$fajlnev;
					copy($elokep,$ujelokep);
				}
			}else{
				$uzenet = array(14);
				$this->phpsession->save('fhiba',$uzenet);
			}

			redirect('forum/renderek');
		}else{
			$uzenet = array(14);
			$this->phpsession->save('fhiba',$uzenet);
			redirect('forum/renderek');
		}
	}

	function renderletolt(){
		$this->load->model('mrender');
		$render_id = $this->uri->segment(3);
		$render = $this->mrender->get_row($render_id);
		if( isset($render->keszkep) && $render->keszkep != "" && file_exists($render->keszkep) ){
			$path_parts = pathinfo($render->keszkep);
			$ext = strtolower($path_parts["extension"]);

			if($render->render_name == "")
				$render->render_name = "Image";

			header("Content-type: application-download");
			header('Content-Disposition: attachment; filename="'.$render->render_name.'.'.$ext.'"');
			readfile($render->keszkep);
		}else{
			print "hiba a letoltes kozben";
		}
	}

	function szerver(){
		print "<pre>";
		print_r($_SERVER);
		print "</pre>";
	}
}

function hasonlito( $a, $b ){
	if ( $a->datum == $b->datum )
		return 0;
	if ( $a->datum > $b->datum )
		return -1;
	return 1;
}

?>
