<?php
class Mforum extends Model
{
	var $ev;
	var $ho;
	var $nap;
	var $most;
	
	function mforum()
	{
		parent::Model();
		$now = time();
		
		$this->ev = date('Y',$now);
		$this->ho = date('m',$now);
		$this->nap = date('d',$now);
		$this->most = time();
		
		$this->userdb = $this->load->database('hardlock',true);
	}
	
	function get_alap($oldal = 0)
	{
		$lang = $this->muser->user['lang'];
		$honnan = $oldal*10;
		
		$query = " SELECT * FROM ( ( SELECT t.tema_id, t.cim, f.nev megnyito, count(*) szam, max(h.datum) datum FROM `cadline2`.`temak` t, `cadline2`.`hozzaszolasok` h, `hardlock`.`forum_user` f WHERE f.user_id = t.megnyito AND t.tema_id = h.tema_id AND t.nyelv = '$lang' GROUP BY t.tema_id)";
		$query .= " UNION (SELECT t.tema_id, t.cim, f.nev megnyito, 0 szam, t.datum FROM `cadline2`.`temak` t, `hardlock`.`forum_user` f WHERE f.user_id = t.megnyito AND t.tema_id NOT IN (SELECT tema_id FROM hozzaszolasok) AND t.nyelv = '$lang' )";
		$query .= " ) tt ORDER BY tt.datum DESC LIMIT $honnan,10";
		
		$query = $this->db->query($query)->result();
		
		$temak = $query;
		return $temak;
	}
	
	function get_alap2($temakor_id, $oldal = 0)
	{
		$lang = $this->muser->user['lang'];
		$honnan = $oldal*10;
		
		$query = " SELECT * FROM ( ( SELECT t.tema_id, t.cim, f.nev megnyito, count(*) szam, max(h.datum) datum FROM `cadline2`.`temak` t, `cadline2`.`hozzaszolasok` h, `hardlock`.`forum_user` f WHERE f.user_id = t.megnyito AND t.tema_id = h.tema_id AND t.nyelv = '$lang' AND t.temakor_id = '$temakor_id' GROUP BY t.tema_id)";
		$query .= " UNION (SELECT t.tema_id, t.cim, f.nev megnyito, 0 szam, t.datum FROM `cadline2`.`temak` t, `hardlock`.`forum_user` f WHERE f.user_id = t.megnyito AND t.tema_id NOT IN (SELECT tema_id FROM hozzaszolasok) AND t.nyelv = '$lang' AND t.temakor_id = '$temakor_id' )";
		$query .= " ) tt ORDER BY tt.datum DESC LIMIT $honnan,10";
		
		$query = $this->db->query($query)->result();
		
		$temak = $query;
		return $temak;
	}
	
	function get_alaptemakorok($oldal = 0)
	{
		$lang = $this->muser->user['lang'];
		$honnan = $oldal*5;
		
		$query = " SELECT * FROM ( ( SELECT t.temakor_id, t.cim, f.nev megnyito, count(*) szam, '2010-05-25 15:16:32' datum FROM `cadline2`.`temakorok` t, `cadline2`.`temak` tt, `hardlock`.`forum_user` f WHERE f.user_id = t.megnyito AND tt.temakor_id = t.temakor_id AND t.nyelv = '$lang' GROUP BY t.temakor_id)";
		$query .= " UNION (SELECT t.temakor_id, t.cim, f.nev megnyito, 0 szam, t.datum FROM `cadline2`.`temakorok` t, `hardlock`.`forum_user` f WHERE f.user_id = t.megnyito AND t.temakor_id NOT IN (SELECT temakor_id FROM temak) AND t.nyelv = '$lang' )";
		$query .= " ) tt ORDER BY tt.datum DESC LIMIT $honnan,5";
		
		$query = $this->db->query($query)->result();
		
		$temak = $query;
		return $temak;
	}
	
	function get_tkuthsz($tk_id){
		$query = "SELECT h.datum FROM `cadline2`.`temak` tt, `cadline2`.`hozzaszolasok` h  WHERE tt.temakor_id = $tk_id AND h.tema_id = tt.tema_id ORDER BY h.datum DESC LIMIT 0,1";
		
		$query = $this->db->query($query)->result();
		return $query[0]->datum;
	}
	
	function get_tkdate($tk_id){
		$query = "SELECT datum FROM `cadline2`.`temakorok` WHERE temakor_id = $tk_id";
		
		$query = $this->db->query($query)->result();
		return $query[0]->datum;
	}
	
	function get_lista($temaid,$oldal){
		$oszam = $oldal*10;
		
		$query = "SELECT * FROM( (SELECT hsz_id, belso.user user_id, user.nev user, belso.szoveg, valasz, kep, belso.datum FROM `hardlock`.`forum_user` user, (SELECT hsz_id, user,szoveg, valasz, kep, h.datum FROM hozzaszolasok h WHERE h.tema_id = $temaid) belso WHERE user.user_id = belso.user) UNION ( SELECT hsz_id, user user_id, 'torolt felhasznalo' user, szoveg, valasz, kep, h.datum FROM `hardlock`.`forum_user` f, hozzaszolasok h WHERE tema_id = $temaid AND h.user NOT IN ( SELECT user_id FROM `hardlock`.`forum_user` ) ) ) cucc ORDER BY datum DESC LIMIT $oszam,10";
		
		$query = $this->db->query($query)->result();
		
		return $query;
	}
	
	function get_cim($temaid){
		$query = $this->db->query("SELECT cim FROM temak WHERE tema_id = $temaid")->row();
		return $query;
	}
	
	function get_tkcim($temakorid){
		$query = $this->db->query("SELECT cim FROM temakorok WHERE temakor_id = $temakorid")->row();
		return $query;
	}
	
	function get_temaoldal($tema_id){
		$query = $this->db->query("SELECT count(*) szam FROM hozzaszolasok WHERE tema_id = $tema_id")->row();
		$oldalak = $query->szam;
		return ($oldalak/10);
	}
	
	function get_toldal(){
		$lang = $this->muser->user['lang'];
		$query = $this->db->query("SELECT count(*) szam FROM temak WHERE nyelv = '$lang'")->row();
		$oldalak = $query->szam;
		return ($oldalak/10);
	}
	
	function get_tkoldal(){
		$lang = $this->muser->user['lang'];
		$query = $this->db->query("SELECT count(*) szam FROM temakorok WHERE nyelv = '$lang'")->row();
		$oldalak = $query->szam;
		return ($oldalak/5);
	}
	
	function get_nev($login){
		$query = $this->db->query(" SELECT nev FROM `hardlock`.`forum_user` WHERE login = '$name' ")->row();
		return $query->nev;
	}
	
	function get_userid($login){
		$query = $this->db->query(" SELECT user_id FROM `hardlock`.`forum_user` WHERE login = '$login' ")->row();
		return $query->user_id;
	}
	
	function szabalyzat($uid){
		$query = $this->db->query(" SELECT szabaly FROM `hardlock`.`forum_user` WHERE user_id = '$uid' ")->row();
		if( $query->szabaly == 0)
			return false;
		else
			return true;
	}
	
	function elfogad($uid){
		$Date = date('Y-m-d H:i:s',time());
		$query = $this->db->query(" UPDATE `hardlock`.`forum_user` SET `szabaly`=1, `datum` = '$Date' WHERE user_id = '$uid' ");
	}
	
	function temabeszur($temacim){
		if($temacim != ""){
			
			$tomb = $this->phpsession->get('fuser');
			$user = $tomb['name'];
			$lang = $tomb['lang'];
			$user_id = $this->get_userid($user);
			
			$record = $this->mdb->set_post_object('temak');
			$record->tema_id = 'NULL';
			$record->cim = $temacim;
			$record->megnyito = $tomb['name'];
			$record->nyelv = $this->muser->user['lang'];
			$record->datum = date('Y-m-d H:i:s',$this->most);
			
			$temakor_id = 0;
			$temakor_id = $this->phpsession->get('temakor');
			
			$this->load->model('mdb');
			$query = "INSERT INTO `cadline2`.`temak` VALUES (NULL,'" . $temacim ."','" . $user_id ."','" . $lang. "','".$record->datum."', ".$temakor_id.")";
			
			$this->db->query($query);
		}
	}
	
	function temakorbeszur($temacim){
		if($temacim != ""){
			
			$tomb = $this->phpsession->get('fuser');
			$user = $tomb['name'];
			$lang = $tomb['lang'];
			$user_id = $this->get_userid($user);
			
			$record = $this->mdb->set_post_object('temak');
			$record->tema_id = 'NULL';
			$record->cim = $temacim;
			$record->megnyito = $tomb['name'];
			$record->nyelv = $this->muser->user['lang'];
			$record->datum = date('Y-m-d H:i:s',$this->most);
			
			$temakor_id = 0;
			
			$this->load->model('mdb');
			$query = "INSERT INTO `cadline2`.`temakorok` VALUES (NULL,'" . $temacim ."','" . $user_id ."','" . $lang. "','".$record->datum."')";
			
			$this->db->query($query);
		}
	}
	
	function letezik($tema_id){
		return true;
	}
	
	function hszbeszur($szoveg,$tema_id,$vsz,$kep = "NULL"){
		if($szoveg != ""){ //&& letezik($tema_id)){
			if($vsz){
				$query = " SELECT tema_id FROM hozzaszolasok WHERE hsz_id = '$vsz'";
				$query = $this->db->query($query)->row();
				$hsz_temaja = $query->tema_id;
				if( $hsz_temaja != $tema_id ) $vsz = 'NULL';
			}
			
			$tomb = $this->phpsession->get('fuser');
			$user = $tomb['name'];
			$user_id = $this->get_userid($user);
			$lang = $this->muser->user['lang'];
			$datum = date('Y-m-d H:i:s',$this->most);
			
			$query = "INSERT INTO `cadline2`.`hozzaszolasok` VALUES (NULL,'$tema_id','$szoveg',$user_id,'$vsz','$kep','$datum','$lang')";
			$this->db->query($query);
		}
	}
	
	function moderator($fuser){
		$query = $this->userdb->from('forum_user')->where("login",$fuser);
		$query = $query->select('rang')->get()->row();
		
		$rang = $query->rang;
		
		if( $rang == "moderator" )
			return true;
		else
			return false;
	}
	
	function hszszerk($ujszoveg,$hszid){
		$query = " UPDATE `cadline2`.`hozzaszolasok` SET `szoveg` = '$ujszoveg' WHERE `hsz_id` = $hszid";
		$query = $this->db->query($query);
	}
	
	function tatnevez($tema_id,$ujcim){
		$query = " UPDATE `cadline2`.`temak` SET `cim` = '$ujcim' WHERE `tema_id` = $tema_id";
		$query = $this->db->query($query);
	}
	
	function tkatnevez($tema_id,$ujcim){
		$query = " UPDATE `cadline2`.`temakorok` SET `cim` = '$ujcim' WHERE `temakor_id` = $tema_id";
		$query = $this->db->query($query);
	}
	
	function get_Text($hszid){
		$query = $this->db->query("SELECT szoveg FROM `cadline2`.`hozzaszolasok` WHERE hsz_id = $hszid")->row();
		return $query;
	}
	
	function get_sajathsz($uid, $hszid){
		$query = $this->db->query(" SELECT user FROM `cadline2`.`hozzaszolasok` WHERE hsz_id = $hszid")->row();
		
		if( $query->user == $uid )
			return true;
		else
			return false;
	}
	
	function get_Kep($hszid){
		$query = $this->db->query("SELECT kep FROM hozzaszolasok WHERE hsz_id = $hszid")->row();
		return $query;
	}
	
	function get_hsz($hszid){
		$query = $this->db->query(" SELECT f.nev user, h.datum, h.user user_id FROM `hardlock`.`forum_user` f, `cadline2`.`hozzaszolasok` h WHERE hsz_id=$hszid AND f.user_id = h.user")->row();
		return $query;
	}
	
	function get_hsz2($hszid){
		$query = $this->db->query(" SELECT user, datum FROM hozzaszolasok WHERE hsz_id=$hszid")->row();
		return $query;
	}
	
	function get_user_szem($login){
		$query = " SELECT ff.hlNum aktiv_kod FROM `hardlock`.`forum_user` f, `hardlock`.`cl_users` u, `hardlock`.`cl_fo_hardlock` ff WHERE ff.hlUser=u.nUserID AND f.nUserID = u.nUserID AND f.login = '$login'";
		$kulcsok = $this->db->query($query)->result();
		
		//$query = " SELECT f.login, f.nev, u.strEmail email, p.prHlNum aktiv_kod, tip.typeName pr_tip, ver.verName FROM `hardlock`.`forum_user` f, `hardlock`.`cl_users` u, `hardlock`.`cl_fo_hardlock` ff, `hardlock`.`cl_fo_programs` p, `hardlock`.`cl_fo_types` tip, `hardlock`.`cl_fo_versions` ver WHERE ver.verID=p.prVerID AND tip.typeCode=p.prTypeID AND p.prHlNum = ff.hlNum AND ff.hlUser=u.nUserID AND f.nUserID = u.nUserID AND f.login = '$login'";
		$query = " SELECT f.user_id, f.login, f.nev, f.rang, u.strEmail email, ff.hlNum aktiv_kod FROM `hardlock`.`forum_user` f, `hardlock`.`cl_users` u, `hardlock`.`cl_fo_hardlock` ff WHERE ff.hlUser=u.nUserID AND f.nUserID = u.nUserID AND f.login = '$login'";
		$query = $this->db->query($query)->result();
		return $query;
	}
	
	function get_nUserID($kulcs){
		$query = " SELECT h.hlUser FROM `hardlock`.`cl_fo_hardlock` h WHERE h.hlNum = '$kulcs' ";
		$query = $this->db->query($query)->row();
		return $query->hlUser;
	}
	
	function get_nUserID2($uid){
		$query = " SELECT f.nUserID FROM `hardlock`.`forum_user` f WHERE f.user_id = '$uid' ";
		$query = $this->db->query($query)->row();
		return $query->nUserID;
	}
	
	function get_user_kulcsok($login){
		$query = " SELECT ff.hlNum kulcs_kod FROM `hardlock`.`forum_user` f, `hardlock`.`cl_users` u, `hardlock`.`cl_fo_hardlock` ff WHERE ff.hlUser=u.nUserID AND f.nUserID = u.nUserID AND f.login = '$login' AND ff.hlCtrID='36' AND ff.hlStat != 2";
		$query = $this->db->query($query)->result();
		return $query;
	}
	
	function get_user_progs($key_id){
		/*$max_prID = " SELECT max(prID) max FROM `hardlock`.`cl_fo_programs` p WHERE p.prHlNum = '$key_id'";
		$max_prID = $this->db->query($max_prID)->result();
		$max_prID = $max_prID[0]->max;*/
		
		$query = " SELECT prID, p.prPass sorozat_sz, tip.typeName pr_tip, ver.verName pr_ver, p.prActCode aktiv_kod FROM `hardlock`.`cl_fo_programs` p, `hardlock`.`cl_fo_types` tip, `hardlock`.`cl_fo_versions` ver WHERE ver.verID=p.prVerID AND tip.typeCode=p.prTypeID AND p.prHlNum = '$key_id' ORDER BY prSellDate";
		$query = $this->db->query($query)->result();
		return $query;
	}
	
	function get_user_moduls($prID){
		$query = " SELECT m.mdCode modul_kod, n.mdtName modul FROM  (
			SELECT * FROM `hardlock`.`cl_fo_modules` WHERE `mdDate` NOT LIKE '0000-00-00' OR mdDate IS NULL) m, 
			`hardlock`.`cl_modultypes` n WHERE m.mdPrID='$prID' AND mdID=n.ID";
		$query = $this->db->query($query)->result();
		return $query;
	}
	
	function get_user_alap($login){
		$query = " SELECT f.rang, f.user_id, f.login, f.nev, f.email FROM `hardlock`.`forum_user` f WHERE f.login = '$login'";
		$query = $this->db->query($query)->result();
		return $query;
	}
	
	function get_user($login){
		//$result_limit = $this->keydb->from('cl_fo_hardlock')->join('cl_users','cl_fo_hardlock.hlUser=cl_users.nUserID','left')->orderby('hlNum','desc')->where("hlNum >= '".$from."' AND hlNum <= '".$to."'")->get();
		
		//$programs = $this->keydb->where('prHlNum',$key_id)->join('cl_fo_types','cl_fo_programs.prTypeID=cl_fo_types.typeCode')->join('cl_fo_versions','cl_fo_programs.prVerID=cl_fo_versions.verID','left')->get('cl_fo_programs');
		
		$query = " SELECT ff.hlNum aktiv_kod FROM `hardlock`.`forum_user` f, `hardlock`.`cl_users` u, `hardlock`.`cl_fo_hardlock` ff WHERE ff.hlUser=u.nUserID AND f.nUserID = u.nUserID AND f.login = '$login'";
		$kulcsok = $this->db->query($query)->result();
		
		$query = " SELECT f.login, f.nev, u.strEmail email, p.prHlNum aktiv_kod, tip.typeName pr_tip, ver.verName FROM `hardlock`.`forum_user` f, `hardlock`.`cl_users` u, `hardlock`.`cl_fo_hardlock` ff, `hardlock`.`cl_fo_programs` p, `hardlock`.`cl_fo_types` tip, `hardlock`.`cl_fo_versions` ver WHERE ver.verID=p.prVerID AND tip.typeCode=p.prTypeID AND p.prHlNum = ff.hlNum AND ff.hlUser=u.nUserID AND f.nUserID = u.nUserID AND f.login = '$login'";
		$query = $this->db->query($query)->result();
		return $query;
	}
	
	function get_login($uid){
		$query = $this->db->query(" SELECT login FROM `hardlock`.`forum_user` WHERE user_id = $uid")->row();
		return $query->login;
	}
	
	function get_login2($email){
		$query = $this->db->query(" SELECT login FROM `hardlock`.`forum_user` WHERE email = '$email'")->row();
		return $query->login;
	}
	
	function set_user($uid,$nev,$email,$jelszo,$login,$rang){
		if($jelszo==""){
			$query = " UPDATE `hardlock`.`forum_user` SET `nev` = '$nev', `login` = '$login', `rang` = '$rang' WHERE `user_id` = $uid";
			
		}
		else{
			$query = " UPDATE `hardlock`.`forum_user` SET `nev` = '$nev', `jelszo` = MD5('$jelszo'), `login` = '$login', `rang` = '$rang' WHERE `user_id` = $uid";
		}
		$query = $this->db->query($query);
	}
	
	function set_prog($pid,$tipus,$sor,$akt){
		$query2 = " UPDATE `cadline2`.`f_progs` SET `pr_tip` = '$tipus', `aktiv_kod` = '$akt', `sorozat_sz` = '$sor' WHERE `f_progs`.`prog_id` = $pid";
		$query = $this->db->query($query2);
	}
	
	function get_users($oldal,$ord,$vissza){
		$db = 30;
		$oszam = ($db*$oldal);
		$query = " SELECT * FROM `hardlock`.`forum_user` f ORDER BY $ord";
		
		if($vissza)
			$query .= " DESC";
		$query .= " LIMIT $oszam,$db";
		
		$query = $this->db->query($query)->result();
		
		return $query;
	}
	
	function get_kusers($oldal,$log,$nev,$mail,$belep,$kulcs,$ord,$vissza){
		$db = 30;
		$oszam = ($db*$oldal);
		
		/*$eredm = $this->db->from('hardlock.forum_user');
		
		if(trim($kulcs) != ""){
			$eredm = $eredm->join('hardlock.cl_fo_hardlock','cl_fo_hardlock.hlUser=forum_user.nUserID','left');
			$eredm = $eredm->where('hlNum LIKE','%'.$kulcs.'%');
			$eredm = $eredm->where('cl_fo_hardlock.hlCtrId','36');
		}
		if(trim($log) != "")
			$eredm = $eredm->where('cl_fo_hardlock.hlNum LIKE','%'.$kulcs.'%');
		if(trim($nev) != "")
			$eredm = $eredm->where('forum_user.nev LIKE','%'.$nev.'%');
		if(trim($mail) != "")
			$eredm = $eredm->where('forum_user.email LIKE', '%'.$mail.'%');
		if(trim($belep) != "" && $belep != -1)
			$eredm = $eredm->where('forum_user.szabaly', $belep);
			
		$eredm = $eredm->groupby('forum_user.login');
		if($vissza)
			$eredm = $eredm->orderby($ord, 'DESC');
		else
			$eredm = $eredm->orderby($ord);
		
		$eredm = $eredm->limit($oszam,$db)->get()->result();*/
		
		//return $eredm;
		
		//->where("login LIKE '%".$log."%' AND nev LIKE '%".$nev."%' AND email LIKE '%".$mail."%' AND hlNum LIKE '%".$kulcs."%' ")->limit($oszam,$db)->get();
		
		
		
		
		if($belep != -1 && $belep != "" ){
			$query = " SELECT * FROM `hardlock`.`forum_user` f, `hardlock`.`cl_fo_hardlock` h WHERE h.hlUser=f.nUserID AND f.login LIKE '%$log%' AND f.nev LIKE '%$nev%' AND f.email LIKE '%$mail%' AND h.hlNum LIKE '%$kulcs%' AND h.hlCtrId = 36 AND f.szabaly = '$belep' GROUP BY f.login ORDER BY $ord";
		}
		else{
			$query = " SELECT * FROM `hardlock`.`forum_user` f, `hardlock`.`cl_fo_hardlock` h WHERE h.hlUser=f.nUserID AND f.login LIKE '%$log%' AND f.nev LIKE '%$nev%' AND f.email LIKE '%$mail%' AND h.hlNum LIKE '%$kulcs%' AND h.hlCtrId = 36 GROUP BY f.login ORDER BY $ord";
		}
		if($vissza)
			$query .= " DESC";
		$query .= "  LIMIT $oszam,$db";
		
		$query = $this->db->query($query)->result();
		
		return $query;
	}
	
	function get_usersdb(){
		$query = " SELECT count(*) szam FROM `hardlock`.`forum_user`";
		$query = $this->db->query($query)->row();
		$db = $query->szam - 1;
		return ($db/30);
	}
	
	function get_kusersdb($klog,$knev,$kmail,$belep,$kulcs){
		if($kulcs)
			return 0;
		if($belep != -1 && $belep != "")
			$query = " SELECT count(*) szam FROM `hardlock`.`forum_user` f, `hardlock`.`cl_fo_hardlock` h WHERE h.hlUser=f.nUserID AND login LIKE '%$klog%' AND nev LIKE '%$knev%' AND email LIKE '%$kmail%' AND szabaly = '$belep' AND h.hlNum LIKE '%$kulcs%' AND h.hlCtrId = 36";
		else
			$query = " SELECT count(*) szam FROM `hardlock`.`forum_user` f, `hardlock`.`cl_fo_hardlock` h WHERE h.hlUser=f.nUserID AND login LIKE '%$klog%' AND nev LIKE '%$knev%' AND email LIKE '%$kmail%' AND h.hlNum LIKE '%$kulcs%' AND h.hlCtrId = 36";
		
		$query = $this->db->query($query)->row();
		$db = $query->szam - 1;
		return ($db/30);
	}
	
	function is_email($email){
		$query = " SELECT login FROM `hardlock`.`forum_user` WHERE email = '$email'";
		$query = $this->db->query($query)->row();
		if( $query->login )
			return true;
		else
			return false;
	}
	
	function is_temaid($tema_id){
		$query = " SELECT megnyito FROM `cadline2`.`temak` WHERE tema_id = $tema_id";
		$query = $this->db->query($query)->row();
		if( $query->megnyito )
			return true;
		else
			return false;
	}
	
	function ujuser($login,$nev,$jsz1,$email,$nUserID,$rang){
		//$this->db->query("SET NAMES latin2");
		$query = " INSERT INTO `hardlock`.`forum_user` ( `nUserID`, `nev`, `jelszo`, `email`, `login` , `rang`) VALUES ( $nUserID, '$nev' , MD5('$jsz1'), '$email', '$login', '$rang')";
		$this->db->query($query);
		//$this->db->query("SET NAMES utf8");
	}
	
	function del_user($id){
		$this->db->query(" DELETE FROM `hardlock`.`forum_user` WHERE user_id = $id;");
	}
	
	function vanmegoldal($tema_id,$szam){
		$query = " SELECT count(*) szam FROM hozzaszolasok h WHERE tema_id = '$tema_id'";
		$query = $this->db->query($query)->row();
		$hszek = $query->szam;
		if( $hszek > ($szam*10+10))
			return true;
		else
			return false;
	}
	
	function vanmeguser($oszam){
		$query = " SELECT count(*) szam FROM `hardlock`.`forum_user`";
		$query = $this->db->query($query)->row();
		$hszek = $query->szam;
		if( $hszek > ($oszam*30+30))
			return true;
		else
			return false;
	}
	
	function vanmegkuser($oszam,$klog,$knev,$kmail,$belep,$kulcs){
		if($kulcs)
			return false;
		if($belep != -1 && $belep != "")
			$query = " SELECT count(*) szam FROM `hardlock`.`forum_user` f WHERE login LIKE '%$klog%' AND nev LIKE '%$knev%' AND email LIKE '%$kmail%' AND szabaly = $belep";// AND sorozat_sz LIKE '%$kssz%'";
		else
			$query = " SELECT count(*) szam FROM `hardlock`.`forum_user` f WHERE login LIKE '%$klog%' AND nev LIKE '%$knev%' AND email LIKE '%$kmail%'";
		$query = $this->db->query($query)->row();
		$hszek = $query->szam;
		if( $hszek > ($oszam*30+30))
			return true;
		else
			return false;
	}
	
	function vanmegtema( $oldalszam ){
		$lang = $this->muser->user['lang'];
		$query = " SELECT count(*) szam FROM temak t WHERE nyelv = '$lang'";
		$query = $this->db->query($query)->row();
		$temak = $query->szam;
		if( $temak > ($oldalszam*10+10))
			return true;
		else
			return false;
	}
	
	function vanmegtemakor( $oldalszam ){
		$lang = $this->muser->user['lang'];
		$query = " SELECT count(*) szam FROM temakorok WHERE nyelv = '$lang'";
		$query = $this->db->query($query)->row();
		$temak = $query->szam;
		if( $temak > ($oldalszam*5+5))
			return true;
		else
			return false;
	}
	
	function torol($hszid){
		$query = $this->db->query(" SELECT kep,user FROM `hozzaszolasok` WHERE hsz_id = '$hszid'")->row();
		$kep = $query->kep;
		$uid = $query->user;
		if( $kep ){
			$user_id = $query->user;
			$mit = "public/img/forum/".$user_id."/".$kep;
			chmod($mit, 777);
			unlink($mit);
		}
		$query = " DELETE FROM `hozzaszolasok` where hsz_id = '$hszid'";
		$this->db->query($query);
		
		return $uid;
	}
	
	function kepki($hszid){
		$query = " UPDATE `cadline2`.`hozzaszolasok` SET `kep` = 'NULL' WHERE `hsz_id` = '$hszid'";
		$this->db->query($query);
	}
	
	function tematorol($temaid){
		$query = " DELETE FROM `temak` WHERE tema_id = $temaid";
		$this->db->query($query);
		$kepek = array();
		$kepek = $this->db->query(" SELECT kep, user FROM hozzaszolasok WHERE tema_id = $temaid")->result();
		foreach( $kepek as $kep ){
			$kep2 =  "public/img/forum/".$kep->user."/". $kep->kep;
			chmod($kep2, 777);
			unlink($kep2);
		}
		$query = " DELETE FROM `hozzaszolasok` WHERE tema_id = $temaid";
		$this->db->query($query);
	}
	
	function temakortorol($tid){
		$query = " DELETE FROM `temakorok` WHERE temakor_id = $tid";
		$this->db->query($query);
		
		$query = " SELECT tema_id FROM `temak` WHERE temakor_id = $tid";
		
		$temak = $this->db->query($query)->result();
		foreach($temak as $tema){
			$this->tematorol($tema->tema_id);
		}
	}
	
	function belep($name,$passwd){
		$pw = md5($passwd);
		$query = $this->userdb->from('forum_user')->where("login",$name)->where('jelszo',$pw);
		$query = $query->select('count(*) db')->get()->row();
		
		$db = $query->db;
		
		return $db;
	}
	
	function szabadlogin($login,$myid){
		$query = $this->userdb->from('forum_user')->where('login',$login);
		$query = $query->select('user_id')->get()->row();
		
		if(!$query)
			return true;
		else if($query->user_id == $myid)
			return true;
		else
			return false;
	}
	
	function myedit($login, $nev, $jelszo, $uid){
		if($jelszo!=""){
			$query = " UPDATE `hardlock`.`forum_user` SET `nev` = '$nev', `jelszo` = MD5('$jelszo'), `login` = '$login' WHERE `user_id` = $uid";
		}
		else{
			$query = " UPDATE `hardlock`.`forum_user` SET `nev` = '$nev', `login` = '$login' WHERE `user_id` = $uid";
		}
		$query = $this->db->query($query);
	}
	
	function vegrehajt($parancs){
		$this->db->query($parancs);
	}
	
	function ujjelszo($email){
		$rand = rand(100000,999999);
		$hm = $rand;
		
		$this->userdb = $this->load->database('hardlock',true);
		$query = $this->userdb->from('forum_user')->where('email',$email);
		$bennevan = $query->select('user_id uid')->get()->row();
		
		if($bennevan){
			$query = " UPDATE `hardlock`.`forum_user` SET `jelszo` = MD5('$hm') WHERE `email` = '$email'";
			$this->db->query($query);
			return $hm;
		}
		else{
			return false;
		}
	}
	
	function jelszovaltmod($s){
		$query = " UPDATE `hardlock`.`forum_user` SET `jelszo` = MD5('archxp2010$s') WHERE login = 'moderator' ";
		$this->db->query($query);
	}
	
	
	function orszagjav(){
		$parancs = " SELECT * FROM `cadline2`.`userstats` WHERE usCtrName LIKE '%EUROPEAN UNION (EU)%' ANd usID > 410088";
		$ered = $this->db->query($parancs)->result();
		/*print "<pre>";
		print_r($ered);
		print "</pre>";*/
		$i = 0;
		
		foreach($ered as $key => $value){
			$user_IP = $value->usIP;
			//print "IP: " . $user_IP;
			
			$orszagok = array(
				"XX" => "(Unknown Country?) (XX)",
				"AF" => "AFGHANISTAN  (AF)",
				"AL" => "ALBANIA (AL)",
				"DZ" => "ALGERIA (DZ)",
				"AD" => "ANDORRA (AD)",
				"AU" => "AUSTRALIA (AU)",
				"AT" => "AUSTRIA (AT)",
				"BE" => "BELGIUM (BE)",
				"BA" => "BOSNIA AND HERZEGOVINA (BA)",
				"BR" => "BRAZIL (BR)",
				"CA" => "CANADA (CA)",
				"CL" => "CHILE (CL)",
				"CN" => "CHINA (CN)",
				"CR" => "COSTARICA (CR)",
				"HR" => "CROATIA (HR)",
				"CY" => "CYPRUS (CY)",
				"CZ" => "CZECH REPUBLIC (CZ)",
				"DK" => "DENMARK (DK)",
				"DO" => "DOMINICAN REPUBLIC (DO)",
				"ET" => "ETHIOPIA (ET)",
				"EU" => "EUROPEAN UNION (EU)",
				"FI" => "FINLAND (FI)",
				"FR" => "FRANCE (FR)",
				"DE" => "GERMANY (DE)",
				"GR" => "GREECE (GR)",
				"VA" => "HOLY SEE (VATICAN CITY STATE) (VA)",
				"HU" => "HUNGARY (HU)",
				"IS" => "ICELAND (IS)",
				"IN" => "INDIA (IN)",
				"IR" => "IRAN, ISLAMIC REPUBLIC OF (IR)",
				"IE" => "IRELAND (IE)",
				"IL" => "ISRAEL (IL)",
				"IT" => "ITALY (IT)",
				"JO" => "JORDAN (JO)",
				"KR" => "KOREA, REPUBLIC OF (KR)",
				"LB" => "LEBANON (LB)",
				"LU" => "LUXEMBOURG (LU)",
				"MK" => "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF (MK)",
				"MT" => "MALTA (MT)",
				"MX" => "MEXICO (MX)",
				"MA" => "MOROCCO (MA)",
				"NL" => "NETHERLANDS (NL)",
				"NO" => "NORWAY (NO)",
				"PK" => "PAKISTAN (PK)",
				"PL" => "POLAND (PL)",
				"PT" => "PORTUGAL (PT)",
				"RO" => "ROMANIA (RO)",
				"RU" => "RUSSIAN FEDERATION (RU)",
				"SA" => "SAUDI ARABIA (SA)",
				"CS" => "SERBIA AND MONTENEGRO (CS)",
				"SK" => "SLOVAKIA (SK)",
				"ZA" => "SOUTH AFRICA (ZA)",
				"ES" => "SPAIN (ES)",
				"SE" => "SWEDEN (SE)",
				"CH" => "SWITZERLAND (CH)",
				"TW" => "TAIWAN (TW)",
				"TN" => "TUNISIA (TN)",
				"TR" => "TURKEY (TR)",
				"UA" => "UKRAINE (UA)",
				"GB" => "UNITED KINGDOM (GB)",
				"UK" => "UNITED KINGDOM (UK)",
				"US" => "UNITED STATES (US)",
				"UY" => "URUGUAY (UY)"
			);
			
			//getcountrynamefromip
		/*	$locale=file("http://xml.utrace.de/?query=".$user_IP);
			$ctrname2=rtrim(substr($locale[8],13,2));
			print "ctr: " . $ctrname2;
			print "<pre>";
			print_r($locale);
			print "</pre>";
			
			if( $ctrname2 != "" && isset($orszagok["$ctrname2"]) )
				$ctrname = $orszagok["$ctrname2"];
			
			print $ctrname . ", ";
			*/
			
			
			$host=gethostbyaddr($user_IP);
			//print "host: " . $host;
			$temp=explode(".", $host);
			$orszag=$temp[count($temp)-1];
			$ISP=$temp[count($temp)-2];
			//$orszagok=array( "hu" =>"Magyarország", "de" =>"Németország", "uk" =>"Anglia", "it" =>"Olaszorszag");
			$orszag = strtoupper($orszag);
			if ($orszagok["$orszag"]=="")
				{$orszag="n/a";}
			else
				$orszag=$orszagok[$orszag];
			//echo "<br>Internetszolgaltatod: ".$host." - ".$orszag;//, ip: ".$row["usIP"]; 
			
			//print "<br /><br />";
			
			
			
			
			
			
			if($orszag != 'n/a'){
				//print "ctr: " . $ctrname;
				$p = " UPDATE `cadline2`.`userstats` SET usCtrName = '".$orszag."' WHERE usID = '".$value->usID."'";
				$p2 = " UPDATE `cadline2`.`userstats` SET usCtrName = '".$orszag."', usLang = '".$value->usLang."' WHERE usID = '".$value->usID."'";
				print $p2.";<br />";
				$this->db->query($p);
				$i++;
			}
			
		}
		print "lecserelve ".$i." darab";
	}
	
	function feltolt($uid,$fajl,$szamla,$info){
		$query = " INSERT INTO `cadline2`.`forum_fajlok` (`fajl_id`, `user_id`, `fajl`, `szamla`, `info`) VALUES( NULL , '".$uid."', '".$fajl."', '".$szamla."' , '".$info."' )";
		
		$this->db->query($query);
	}
}
?>