<?php
class Collection extends Controller
{
	var $pw = "dfDF34mkZ6";
	var $ervenydesseg = 172800; //3600;
	var $ervenydessegemail = 999999;

	var $archline_default_kat = 4;

	var $viewerfilelimit = 3145728;

	var $limitalt = array('valerio'=>'ita', 'itc'=>'ger');

	function __construct()
	{
		parent::Controller();
		$this->lang->load('site', $this->muser->user['lang']);
		$this->load->model('mcollection');
		$this->cookieupdate();
	}

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

	function upload(){
		$this->load->model('mcollection2');

		// volt-e belepesi hiba
		$hibavoltekorabban = $this->phpsession->get('feltoltesbelepesihiba');
		$hibavoltekorabbanemail = $this->phpsession->get('feltoltesbelepesihibaemail');
		if( $hibavoltekorabban == "hfvj" ){
			$error = "Hibás név vagy jelszó";
			$data["error"] = $error;
			$data["email"] = $hibavoltekorabbanemail;
			unset($_SESSION['default']['feltoltesbelepesihiba']);
			unset($_SESSION['default']['feltoltesbelepesihibaemail']);
		}


		if(hun()){
			$data['title'] = 'ARCHLine.XP Feltöltés';
			$data['feltetel'] = $this->mpages->get_row(572);
		}
		else{
			$data['title'] = 'ARCHLine.XP Upload';
			$data['feltetel'] = $this->mpages->get_row(571);
		}


		// nyelv megadása: url 5. paraméter
		$lang = $this->uri->segment(5);
		// ha volt, elmenteni
		if( $lang )
			$_SESSION['showroom']['lang'] = $lang;

		// ha nem volt nyelv es elmentve sincs, legyen angol
		/*if( !$lang ){
			$lang = ( isset($_SESSION['showroom']['lang']) && $_SESSION['showroom']['lang'] != "" ) ? $_SESSION['showroom']['lang'] : "eng";
		}*/

		if ( $this->cookieupdate() ){
			$data['email'] = $_COOKIE['azonosito'];
			$data['belepve'] = true;
			$belepve = $_COOKIE['azonosito'];

			if( isset($this->limitalt[$belepve]) && $this->limitalt[$belepve] != $lang && $lang ){
				//$data["error"] .= "Denied: ".$lang;
				print "Denied: ".$lang;
				return;
			}
		}

		if($this->uri->segment(3)!=""){
			$tipus = $this->uri->segment(4);
			if( !$tipus )
				$tipus = "temp";

			$data["fajl"] = $this->uri->segment(3);

			/* szövegfájl átadással */
			$fajlnev = '/home/vendeg/'.$this->uri->segment(3);
			$fa = fopen( $fajlnev, "r" ) or die("Upload error, nem sikerult megnyitni: ".$fajlnev);
			$ol = fgets( $fa, 1024);
			$adatok = explode("#",$ol);
	//		$lang = $this->muser->user['lang'];
			$honnan = "/home/vendeg/".$adatok[2];
			$kepnev = time()."_".$adatok[3];
			$ide= "public/img/collection/".$tipus."/".$kepnev;
			if( /*$belepve  &&  */copy($honnan,$ide) ){
				$adatok[3] = $ide;
			}else{
				$adatok[3] = "";
			}


			$data["fajl"]    = $adatok[0];
			$data["eredeti"] = $adatok[1];
			$data["vendegkep"] = $adatok[2];
			$data["kepalap"] = $adatok[3];
			$data["cim"]     = $adatok[4];
			$data["cimhun"]  = $adatok[5] ? $adatok[5] : $adatok[4];
			$data["prver"]   = ($adatok[6]=="-1") ? "2012" : $adatok[6];
			$data["tipus"]   = $tipus;
			$data["archline_nyelv"] = $lang;
			$data["limituser"] = $this->limitalt;

			fclose($fa);

		}else{
			redirect('objects/upload');
		}

	//	$kategoriak = $this->muser->get_kategoriak($tipus);
	//	$kategoriak = $this->mcollection->get_darab($kategoriak);
		if($lang=="ita")
			$kategoriak = $this->db->query("SELECT * FROM coll2_cat WHERE m_id=6 AND deleted=0")->result();
		if($tipus=="project")
			$kategoriak = $this->db->query("SELECT CONCAT(nev_hun,' - ',nev_eng) as nev FROM dl_kategoriak WHERE tipus='project' AND deleted=0")->result();

		$tipusok = $this->db->query("SELECT type, CONCAT(type_download,': ',name_eng,' - ',name_hun) typename FROM coll2_types ORDER BY typename")->result();

		$data['gyartok'] = $this->mcollection2->get_gyartok();

		$data['tartalom']   = 'collection/upload';
		$data['style']      = array('temp/style_interior');
		$data['javascript'] = array('objfeltoltes_2');
		$data['kategoriak'] = $kategoriak;
		$data['tipusok']    = $tipusok;

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

	}

	function uploadhozzaad(){
		$lang = $_SESSION['showroom']['lang'];

		if ( $this->cookieupdate() ){
			$data['email'] = $_COOKIE['azonosito'];
			$data['belepve'] = true;
			$belepve = $_COOKIE['azonosito'];

			if( isset($this->limitalt[$belepve]) && $this->limitalt[$belepve] != $lang && $lang ){
				//$data["error"] .= "Denied: ".$lang;
				print "Denied: ".$lang;
				return;
			}
		}else{
			print "<a href='/collection/upload/".$this->uri->segment(3)."'>login in</a>";
			return;
		}

		if(!$this->uri->segment(3)!=""){
			print "leiro fajl hianyzik";
			return;
		}

		$fajlnev = '/home/vendeg/'.$this->uri->segment(3);
		$fa = fopen( $fajlnev, "r" ) or die("Upload error, nem sikerult megnyitni: ".$fajlnev);
		$ol = fgets( $fa, 1024);
		$adatok = explode("#",$ol);
		fclose($fa);

		$data["fajl"]    = $adatok[0];
		$data["eredeti"] = $adatok[1];
		$data["prver"]   = ($adatok[6]=="-1") ? "2012" : $adatok[6];
		$data["archline_nyelv"] = $lang;
		$data["limituser"] = $this->limitalt;






		$this->load->model('mcollection2');
		$guid = '/[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}/';
		$elemnev   = !(preg_match($guid, $adatok[4])) ? $adatok[4] : $adatok[5];
		$azonoscim = array();


		$sql = "SELECT o_id, m_id, c_id FROM collection2 WHERE title_eng='{$elemnev}' AND deleted=0";
		$nevobjektumok = $this->db->query($sql)->result();
		foreach($nevobjektumok as $obj){
			$gyarto = $this->mcollection2->get_manById($obj->m_id);
			$kateg  = $this->mcollection2->get_kategoria($obj->c_id);
			$elemujnev = $this->db->query("SELECT title FROM coll2_desc WHERE o_id={$obj->o_id}")->row();

			$tmpelem = array(
					"objid" => $obj->o_id,
					"gyarto" => $gyarto->name,
					"dir"   => $gyarto->dir,
					"nev"   => $elemujnev->title
				);
			$tmpelem["kategoria"] = hun() ? $kateg->nev_hun : $kateg->nev_eng;
			$azonoscim[] = $tmpelem;
		}
		$data["azonoscimuek"] = $azonoscim;

		$gyartolimit = array( "ita" => "2", "ger" => "itc" );

		if( array_key_exists($lang, $gyartolimit) ){
			if(ita())
				$gyartok = $this->db->query("SELECT * FROM coll2_man WHERE deleted=0 AND group_id LIKE ';{$gyartolimit[$lang]};'")->result();
			else
				$gyartok[0] = $this->mcollection2->get_manBydir($gyartolimit[$lang]);
		}else{
			$gyartok = $this->mcollection2->get_gyartok();
		}

		$ordernev = hun() ? 'title_hun' : 'title_eng';

		foreach($gyartok as $gyarto){
			$gyarto->kategoria = $this->mcollection2->get_kategoriak($gyarto->dir);
			$gyarto->darab = 0;
			foreach($gyarto->kategoria as $kategoria){
				$kategoria->fajl  = $this->mcollection2->get_objektumok($kategoria->c_id,$ordernev.' ASC');
				if( !$kategoria->fajl )
					$kategoria->fajl = array();
				$kategoria->darab = count($kategoria->fajl);
				$gyarto->darab   += $kategoria->darab;
			}
		}


		$brandgroup = false;
		if(ita())
			$brandgroup = $this->db->query("SELECT * FROM coll2_mangrp WHERE group_id=2")->row();
		elseif(hun()||eng())
			$brandgroup = $this->db->query("SELECT * FROM coll2_mangrp WHERE deleted=0")->result();

		$data['tipusok']   = $gyartok;






		$data['tartalom']='collection/uploadhozzaad';
		$data['style'] = array('temp/style_interior');

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

	}

	// felhasználó akar feltölteni a viewerbe
	function uploaduser(){

		if( $_SERVER['HTTP_HOST'] == 'old.archlinexp.com' && hun())
		{
			$this->muser->user['lang']='eng';
			unset($this->muser->user['admin']);
			unset($this->muser->user['admin_lang']);
			$this->phpsession->save('user',$this->muser->user);
			redirect('collection/uploaduser/'.$this->uri->segment(3));
		}

		// feltoltési információk
		if($this->uri->segment(3)==""){
			print "Hiba: hiányzó adatok!";
			exit();
		}

		// volt-e belepesi hiba
		$hibavoltekorabban = $this->phpsession->get('feltoltesbelepesihiba');
		$hibavoltekorabbanemail = $this->phpsession->get('feltoltesbelepesihibaemail');
		if( $hibavoltekorabban == "hfvj" ){
			$error = "Hibás név vagy jelszó";
			$data["error"] = $error;
			$data["email"] = $hibavoltekorabbanemail;
			unset($_SESSION['default']['feltoltesbelepesihiba']);
			unset($_SESSION['default']['feltoltesbelepesihibaemail']);
		}

		if( $this->cookieupdate() ){
			$this->load->model('mforum');
			$data['email'] = $_COOKIE['azonosito'];
			$data['belepve'] = true;
			$belepve = $_COOKIE['azonosito'];
		}
		$data['email'] = $_COOKIE['azonosito'];

		$fajlnev =  $this->uri->segment(3);
		$data["fajl"] = $fajlnev;

		/* szövegfájl átadással */
		$leirofajl = '/home/vendeg/'.$fajlnev;
		$fa = fopen( $leirofajl, "r" ) or die("Upload error, nem sikerult megnyitni: ".$leirofajl);
		$ol = fgets( $fa, 1024);
		$adatok   = explode("#",$ol);
		$projekt  = $adatok[0];
		$uplfajl  = "/home/vendeg/".$adatok[1];		// kép, pdf, stb.
		$elonezet = "/home/vendeg/".$adatok[2];		// előnézeti kép
		$nagykep  = "/home/vendeg/".$adatok[3];		// nagy kép
		$elonezettemp = "public/img/collection/temp/".time()."_".$adatok[2];
		$fajlmeret = filesize($uplfajl);

		// fájl méret korlát
		if($fajlmeret >= $this->viewerfilelimit){
			$record->osztaly = "collection";
			$record->fv = "upload";
			$record->hiba = "Túl nagy fájl: ".$adatok[1]." ({$fajlmeret})\n".$_COOKIE['azonosito'];
			$record->datum = date('Y-m-d H:i:s',time());
			$this->db->insert('a_hibak',$record);

			$data['tartalom'] = 'forum/kiir';
			$data['style'] = array('temp/style_interior');
			$data['email'] = $_COOKIE['azonosito'];

			$data['info'] = "<div style='text-align: center; color: #fff; font-size: 1.3em;'>File size is too large</div>";

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

		if( $belepve ){
			copy($elonezet,$elonezettemp);
		}

		// új projekt vagy meglevő bővítése
		$projektdir = strtolower($this->ekezet($projekt));
		$nyelv  = hun() ? "hun" : "eng";
		$login  = $_COOKIE['azonosito'];
		if( $login!="guest" ){
			$query  = $this->db->query("SELECT user_id FROM `cadline2`.`forum_user` WHERE login = '".$login."' AND nyelv='{$nyelv}'")->row();
			$userid = $query->user_id;
		}
		else{
			$userid = "guest";
		}

		//vendege-e
		if( $userid == "guest" && isset($_COOKIE['uploaduserPrevUsername']) ){
			$subject = str_replace(' ','-',strtolower($_COOKIE['uploaduserPrevUsername']));
			$pattern = '/[-_a-z0-9]*/';
			preg_match_all($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
			$username = "";
			foreach($matches[0] as $m) if($m[0]) $username .= $m[0];

			$ujprojekt = false;
			$tmpprtitl = $this->db->query("SELECT nev FROM collection_projects WHERE userid='guest' AND mappa='{$username}/{$projektdir}' AND deleted=0 ")->row();
			$projekttitle = $tmpprtitl->nev;


			if($tmpprtitl->nev){
				$ujprojekt = false;
				$projekttitle = $tmpprtitl->nev;
			}else{
				$projektdir2 = strtolower($this->ekezet($_COOKIE['uploaduserPrevProjname']));
				$tmpprtitl2 = $this->db->query("SELECT nev FROM collection_projects WHERE userid='guest' AND mappa='{$username}/{$projektdir2}' AND deleted=0 ")->row();


				if($tmpprtitl2->nev){
					$ujprojekt = false;
					$projekttitle = $tmpprtitl2->nev;
				}else{
					$ujprojekt = true;
					$projekttitle = isset($_COOKIE['uploaduserPrevProjname']) ? $_COOKIE['uploaduserPrevProjname'] : $projekt;
				}
			}

		}
		elseif( !is_dir("public/img/collection/users/".$userid."/".$projektdir."/") ){
			$ujprojekt = true;
			$projekttitle = $projekt;
		}else{
			$ujprojekt = false;
			$tmpprtitl = $this->db->query("SELECT nev FROM collection_projects WHERE userid='{$userid}' AND mappa='{$projektdir}' AND deleted=0 ")->row();
			$projekttitle = $tmpprtitl->nev;

			if($tmpprtitl->nev){
				$ujprojekt = false;
				$projekttitle = $tmpprtitl->nev;
			}else{
				$ujprojekt = true;
				$projekttitle = $projekt;
			}
		}

		if(hun())
			$data['feltetel'] = $this->mpages->get_row(728);
		else
			$data['feltetel'] = $this->mpages->get_row(727);

		$data["projekt"]   = $projekt;
		$data["ujprojekt"] = $ujprojekt;
		$data["projekttitle"] = $projekttitle;
		$data["nagyfajl"]  = $uplfajl;
		$data["elonezet"]  = $elonezet;
		$data["nagykep"]   = $nagykep;
		$data["elonezettemp"] = $elonezettemp;

		fclose($fa);


		$data['tartalom']   = 'collection/uploaduser';
		$data['style']      = array('temp/style_interior');
		$data['javascript'] = array('objfeltoltes_2');

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

	function kategoria(){

		if( !$this->uri->segment(3) )
			$kat = 26;
		else
			$kat = $this->uri->segment(3);

		$data['objects']=$this->mcollection->get_bykategoria($kat);

		$tipus = $this->mcollection->get_tipus($kat);
		$kategoriak = $this->mcollection->get_kategoriak($tipus);
		$kategoriak = $this->mcollection->get_darab($kategoriak);

		$darab = $this->mcollection->get_darabegykategoria($kat);

		$data['kategoriak'] = $kategoriak;

		$data['aktiv']=$kat;

		$data['tartalom']='collection/kat';
		$data['csik']=array('home',$tipus.'s');
		$data['javascript']=array('dl_select','objfeltoltes_2','fancybox/jquery-1.3.2.min','fancybox/jquery.easing.1.3','fancybox/jquery.fancybox-1.2.1.pack','fancybox/fancy');

		$data['onload']="leirasmeretezes(".$darab.")";

		$data['title'] = 'ARCHLine.XP Collection';
		$data['title'] .= " - " . $this->muser->get_katName($kat);

		if( true ||  ( strstr($_SERVER['HTTP_USER_AGENT'],'Ubuntu/8.04') )  ){
			$data['style'] = array('temp/style_interior','fancybox2');
			$this->load->view('site_upload',$data);
		}
		else{
			$data['style'] = array('fancybox2');
			$this->load->view('site',$data);
		}
	}

	function category_archlinexp(){

		// nyelv megadása: url 3. paraméter
		$lang = $this->uri->segment(3);
		// ha volt, elmenteni
		if( $lang )
			$_SESSION['projects']['lang'] = $lang;

		// ha nem volt nyelv es elmentve sincs, legyen angol
		if( !$lang ){
			if( isset($_SESSION['projects']['lang']) && $_SESSION['projects']['lang'] != "" )
				$lang = $_SESSION['projects']['lang'];
			else
				$lang = "Eng";
		}

		$CI = &get_instance();
		if( $lang == "Hun" ){
			$CI->muser->user['lang']="hun";
		}else{
			$CI->muser->user['lang']="eng";
		}


		// gyári vagy felhasználói projektek   - minimum bizalom szint
		if( $_POST["trust"] )
			$bizalom = $_POST["trust"];
		else
			$bizalom = 10;


		// kategória
		if( !$_POST["category"] )
			$kat = $this->archline_default_kat;
		else
			$kat = $_POST["category"];


		// saját nyelvre szűrés
		if( $_POST["mycountry"] == "on" )
			$mycountry = true;
		else
			$mycountry = false;


		$data['projects'] = $this->mcollection->getInArchline($kat,$bizalom,$lang,$mycountry);

		$lang_file = "public/collection/start_dialog_".$lang.".xml";
		if( !file_exists($lang_file) )
			$lang_file = "public/collection/start_dialog_Eng.xml";;
		$data['lang'] = simplexml_load_file($lang_file);


		$kategoriak = $this->mcollection->get_kategoriak("project");
		$kategoriak = $this->mcollection->get_darab($kategoriak);

	//	$darab = count($data['projects']);

		$data['urllang'] = $lang;
		$data['kategoriak'] = $kategoriak;

		$data['aktiv']=$kat;

	//	$data['style'] = array('temp/style_interior','fancybox2');
		$this->load->view('collection/category_archlinexp',$data);

		/*
		const CALLanguage::LanguageParameters CALLanguage::Languages[] = {
									 "Eng",    "eng",             // english      0
									 "Ita",    "ita",             // Italian      1
									 "Esp",    "spanish",         // Esp          2
									 "Hun",    "hun",             // Hun         3
									 "Ger",    "german",          // Ger         4
									 "Gre",    "greek",           // Gre         5
									 "Cz",     "czech",   		  // Cz         6
									 "Pol",    "polish",          // Pol         7
									 "Cr",     "eng",     		  // Cr         8
									 "Nl",     "dutch",       	  // Nl         9
									 "Kor",    "korean",          // Kor         10
									 "JP",     "japan",      	  // JP         11
									};
		*/
	}

	function submit(){
		$this->load->model('mforum');
		$email = $_POST["email"];
		$jelszo = $_POST["jelszo"];
		$fajltipus = $_POST["tipus"];
		$error = "";
		$kep = "";
		$stop = "";


		$ell = md5($_COOKIE['azonosito'].$this->pw.$_COOKIE['sessid']);

		$belepve = $this->phpsession->get('feltolo');
		if( !empty($_COOKIE['hash']) && $_COOKIE['hash']== $ell ){

			$user_id = $this->mforum->get_userid($_COOKIE['azonosito']);

		}elseif( !$this->mforum->belep($email,$jelszo) ){
			$error = "hibás felhasználó név vagy jelszó";
			$stop = $error;

			$data["error"] = $error;

			if(hun()){
				$data['title'] = 'ARCHLine.XP Feltöltés';
				$data['feltetel'] = $this->mpages->get_row(572);
			}
			else{
				$data['title'] = 'ARCHLine.XP Upload';
				$data['feltetel'] = $this->mpages->get_row(571);
			}

			$data["fajl"] = $_POST["originalFilenameField"];
			$data["eredeti"] = $_POST["eredetinev"];
			$data["kepalap"] = $_POST["kepalap"];
			$data["cim"] = $_POST["projhectNameField"];
			$data["tipus"] = $_POST["tipus"];
			$data["szerzo"] = $_POST["SzerzoField"];
			$data["leiras"] = $_POST["projectDescriptionField"];
			$data["archline_nyelv"] = $_POST["archline_nyelv"];

			$data['tartalom']='collection/upload';
			$data['style'] = array('temp/style_interior');
			$data['javascript'] = array('objfeltoltes_2');
			$data['kategoriak'] = $this->muser->get_kategoriak($_POST["tipus"]);


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

		}else{
			$user_id = $this->mforum->get_userid($email);
			$tomb = array();
			$tomb['feltolto_id'] = $user_id;
			$tomb['email'] = $email;
			$this->phpsession->save('feltolo',$tomb);
		}


		$lang = $this->muser->user['lang'];

		$fajlnev = $_POST["originalFilenameField"];  // ez van a vendegnel
		$fajlnev2 = $this->ekezet($_POST["eredetinev"]);   // ez legyen a publicban

		$tempFolder = "/home/vendeg/"; //ide másolja az FTP applet a fájlt
		$storeFolder = "public/collection/".$fajltipus."s/"; //mi itt szeretnénk tárolni

		$fajl = $tempFolder.$fajlnev;

		$ido = time();
		$storeFilename= $storeFolder.$ido."_".$fajlnev2;

		if(!$error){
			if (copy($fajl,$storeFilename)){
				$prFile = $storeFilename;
				$prSize = filesize($storeFilename);
			}else{
				$prFile = "NULL";
				$error .= "Nem másoltam át a fájlt<br /> vendegben: ".$fajl." publicba: ".$storeFilename;
			}
		}

		$link = "public/collection/".$fajltipus."s/".$ido."_".$fajlnev2;

		$kep = $_POST["kepalap"];
		$this->kep($kep,$fajltipus);


		// új kategória felvétele, ha megadták
		if( $_POST["ujkat"] != "" && !$stop ){
			if(hun()){
				$nevhun = $_POST["ujkat"];
				$neveng = "";
			}else{
				$nevhun = "";
				$neveng = $_POST["ujkat"];
			}

			$kat_id = $this->muser->new_kategoria($fajltipus,$nevhun,$neveng);
		}else{
			$kat_id = $_POST["kategoria"];
		}


		// Felvétel az adatbázisba
		if(!$error){
			$ujpr->user_id = $user_id;
			$ujpr->object = $link;
			$ujpr->title = $_POST["projhectNameField"];
			$ujpr->meret = $prSize;
			$ujpr->datum = date('Y-m-d H:i:s',time());
			$ujpr->nyelv = $lang;
			$ujpr->kep = $kep;
			$ujpr->text = $_POST["projectDescriptionField"];
			$ujpr->szerzo = $_POST["SzerzoField"];
			$ujpr->kat_id = $kat_id;
			$ujpr->tipus = $fajltipus;
			$ujpr->eredeti = $_POST["eredetinev"];
			$ujpr->bizalom = 5;
			$ujpr->sorszam = 50;
			$ujpr->archline_nyelv = $_POST["archline_nyelv"];

			$this->mcollection->newobject($ujpr);


			// felhasználóhoz beírni a feltöltést
			$emailcim = $_COOKIE['azonosito'];

			// ha nem email cim, lekerdezzuk az emailt
			if(!preg_match('/^([a-zA-Z0-9_\.])+([\-]?[a-zA-Z0-9]+)*@([a-zA-Z0-9_\-\.])+(\.[a-zA-Z]{2,4})$/i', $emailcim)){
				$qaf = $this->mforum->get_user_szem($emailcim);
				$emailcim = $qaf[0]->email;

				if(!$emailcim){
					$qaf = $this->mforum->get_user_alap($_COOKIE['azonosito']);
					$emailcim = $qaf[0]->email;
				}
			}

			$nUserID = $this->mforum->get_nUserID30($emailcim);
			if( is_numeric($nUserID) ){
				$this->load->model('mclusers');
				$this->mclusers->addEvent($nUserID, 114, "Feltöltés: ".$fajltipus.", név:  ".$_POST["projhectNameField"].", ".$link);
			}


			// Felvétel a régi helyére
			switch($fajltipus){
				case 'project':
					$this->load->model('mprojects');
					$this->mprojects->newproject($ujpr);
					break;
				case 'object':
					$this->load->model('mobjects');
					$this->mobjects->newobject($ujpr);
					break;
				case 'group':
					$this->load->model('mgroups');
					$ujpr->group = $ujpr->object;
					$ujpr->kategoria = 900;
					$ujpr->email = $user_id;
					$this->mgroups->newgroup($ujpr);
					break;
			}


			//print "<br /> <b>Új ".$fajltipuftp://eszter%40cadline.hu@cadline.hu:21/www.cadline.hu/application/controllers/collection.phps." felvéve</b>";
		}else{
			//print "<br /> <b>Nem került adat az adatbázisba</b>";
			//print $error;
		}

		//ha nem volt print:
		if( !$stop )
			redirect('collection/kategoria/'.$kat_id);
	}

	// 2012. 04. ??-tól, cégekhez rendelt objektumok
	function ujsubmit(){
		$this->load->model('mcollection2');
		include('application/helpers/sajatfeltolto.php');
		include('application/helpers/myimg_helper.php');

		$gyarto   = $_POST['gyarto'];						// mappa
		$gyartominden = $this->mcollection2->get_manBydir($gyarto);

		// új kategória felvétele, ha megadták
		if( $_POST["ujkat_hun"] != "" || $_POST["ujkat_eng"] != ""  ){
			$nevhun = (isset($_POST["ujkat_hun"]) && strlen($_POST["ujkat_hun"])>0 ) ? $_POST["ujkat_hun"] : $_POST["ujkat_eng"];
			$neveng = $_POST["ujkat_eng"];

			$kat_id = $this->mcollection2->new_kategoria($gyarto,$nevhun,$neveng);

			if( $_FILES["ujkatkep"]["error"]==0 ){

				$hova  = "public/img/collection/category/";
				// korábbi kép törlése
				exec("rm public/img/collection/category/".$kat_id.".jpg");
				feltolt("ujkatkep",$hova,$kat_id.".jpg",true);
				$ujkatkep = $hova.$kat_id.".jpg";

				// átméretezés
				kemeretezesvagassh($ujkatkep,$hova.$kat_id."_182x152.jpg",182,152);
				kemeretezesvagassh($ujkatkep,$ujkatkep,182,131);
				chmod($ujkatkep,0777);
			}

		}else{
			$kat_id = $_POST["kategoria"];
		}


		// adatbázisba mentés
		$ujid = false;
		if(!$error){
			$uj->m_id      = $gyartominden->id;
			$uj->desc_hun  = trim($_POST['projectDescriptionFieldhun']);
			$uj->desc_eng  = trim($_POST['projectDescriptionField']);
			$uj->c_id      = $kat_id;
			$uj->datum     = date('Y-m-d H:i:s',time());
			if($_POST["projhectNameFieldhun"])
				$uj->title_hun = trim($_POST["projhectNameFieldhun"]);
			$uj->title_eng = trim($_POST["projhectNameField"]);
			$uj->tipus     = $_POST["tipus"];

			$this->db->insert('cadline2.collection2',$uj);
			$ujid = $this->db->insert_id();


			$leiras->o_id  = $ujid;
			$leiras->lang  = 'eng';
			$leiras->title = trim($_POST["projhectNameField"]);
			$leiras->desc  = trim($_POST['projectDescriptionField']);
			$this->db->insert('cadline2.coll2_desc',$leiras);

			if( $_POST['archline_nyelv'] != "" && $_POST['archline_nyelv'] != "eng" ){
				$leiras->o_id  = $ujid;
				$leiras->lang  = $_POST['archline_nyelv'];
				$leiras->title = trim($_POST["projhectNameField".$_POST['archline_nyelv']]);
				$leiras->desc  = trim($_POST['projectDescriptionField'.$_POST['archline_nyelv']]);
				$this->db->insert('cadline2.coll2_desc',$leiras);
			}

			if( $_POST['prver'] != "" && is_numeric($_POST['prver']) ){
				$verzio->o_id    = $ujid;
				$verzio->version = $_POST['prver'];
				$verzio->fajl    = $this->ekezet($_POST["eredetinev"]);
				$this->db->insert('cadline2.coll2_ver',$verzio);
			}

		}

		if(!$ujid){
			print "sql error";
			return;
		}


		// fájlt a helyére
		$tempFolder  = "/home/vendeg/";								//ide másolja az FTP applet a fájlt
		$storeFolder = "public/collection/".$gyarto."/".$ujid."/";	//mi itt szeretnénk tárolni
		mkdir($storeFolder,0777);
		chmod($storeFolder,0777);
		$fajlnev  = $_POST["originalFilenameField"];		// ez van a vendegnel
		$fajlnev2 = $this->ekezet($_POST["eredetinev"]);	// ez legyen a publicban
		$fajl     = $tempFolder.$fajlnev;
		$storeFilename= $storeFolder.$fajlnev2;

		if (copy($fajl,$storeFilename)){
			chmod($storeFilename,0777);
		}else{
			$error .= "Nem másoltam át a fájlt<br /> vendegben: ".$fajl." public helye: ".$storeFilename;
		}


		// képes dolgok
		$hova   = "public/img/collection/".$gyarto."/".$ujid."/";
		$kiskep = "";
		mkdir($hova,0777);
		chmod($hova,0777);
		mkdir($hova."big/",0777);
		mkdir($hova."thumb/",0777);
		mkdir($hova."orig/",0777);


		// ha új kis képet kapott
		if( $_FILES["kep"]["error"]==0 && isset($_FILES["kep"]["name"]) ){
			$kiskep = $hova.$_FILES["kep"]["name"];
		//	feltolt("kep",$hova,$_FILES["kep"]["name"],true);
			chmod($kiskep,0777);
		}else{
			$tmp = $_POST['kepalap'];
			$tmp = explode("/",$tmp);
			$tmp = end($tmp);
			$honnan = "/home/vendeg/".substr($tmp,11);
			$kiskep =  $hova.$this->ekezet(substr($tmp,11));

		//	athelyez($honnan,$kiskep,true);
			chmod($kiskep,0777);
		}

		// eredetileg feltoltott kep lementese
		copy($honnan,$hova.'orig/'.$this->ekezet(substr($tmp,11)));
		copy($honnan,$kiskep);

		// materialnal az elonezeti kep legyen a nagy kep ha nem toltottek fel masikat
		$nagykeparany = (488/396);
		$nagykeparany2 = (480/400);
		if( $_POST["tipus"]=="material" && $_FILES["nagykep22"]["error"]!=0 ){
			$nagykep = $hova."big/".end(explode("/",$kiskep));
			$nagykep = str_replace(' ','\ ',$nagykep);
			$nagykep = str_replace("'","\'",$nagykep);
			$elonezeti = $hova."thumb/".end(explode("/",$kiskep));
			$ujkiskep = $hova.end(explode("/",$kiskep));
			copy($kiskep,$nagykep);
			kemeretezesvagassh($nagykep,$elonezeti,182,131);
			kemeretezesvagassh($nagykep,$hova."zz_thumb.jpg",182,152);		// uj kozepes kep
			chmod($nagykep,0777);
			// kis kep a nagy kepbol
			kemeretezesvagassh($nagykep,$ujkiskep,70,68);
			kemeretezesvagassh($nagykep,$hova."zz_small.jpg",79,66);		// uj kis kep

			// nagy kep atmeretezes
			list($ow,$oh) = getimagesize($nagykep);
			$orignagykeparany = ($ow/$oh);

			$diff2 = abs($nagykeparany2-$orignagykeparany);
			// ha nagyon eltérő az arány, akkor meghagyja az eredetit, és fehérrel tölti ki a maradék helyet
			if( $diff2 < 0.3 )
				kemeretezesvagassh($nagykep,$hova."zz_big.jpg",480,400);		// uj nagy kep
			else
				kemeretezesvagasshbg($nagykep,$hova."zz_big.jpg",480,400);

			$diff = abs($nagykeparany-$orignagykeparany);
			// ha nagyon eltérő az arány, akkor meghagyja az eredetit, és fehérrel tölti ki a maradék helyet
			if( $diff < 0.3 )
				kemeretezesvagassh($nagykep,$nagykep,488,396);
			else
				kemeretezesvagasshbg($nagykep,$nagykep,488,396);


			chmod($ujkiskep,0777);

		}
		else{
			$ujnagykep = $hova."big/".$this->ekezet($_FILES["nagykep22"]["name"]);
			$elonezeti = $hova."thumb/".$this->ekezet($_FILES["nagykep22"]["name"]);
			feltolt("nagykep22",$hova."big/",$_FILES["nagykep22"]["name"],true);

			chmod($ujnagykep,0777);
			kemeretezesvagassh($ujnagykep,$elonezeti,182,131);			// előnézeti kép a nagy képből
			kemeretezesvagassh($ujnagykep,$hova."zz_thumb.jpg",182,152);	// uj kozepes kep
			$ujkiskep = $hova.end(explode("/",$kiskep));


			kemeretezesvagassh($ujnagykep,$ujkiskep,70,68);				// kis kép a nagy képből
			kemeretezesvagassh($ujnagykep,$hova."zz_small.jpg",79,66);	// uj kis kep

			// nagy kep atmeretezes
			list($ow,$oh) = getimagesize($ujnagykep);

			$diff2 = abs($nagykeparany2-$orignagykeparany);
			if( $diff2 < 0.3 ){
				kemeretezesvagassh($ujnagykep,$hova."zz_big.jpg",480,400);
			}else{
				kemeretezesvagasshbg($ujnagykep,$hova."zz_big.jpg",480,400);
			}

			/*$diff = abs($nagykeparany-$orignagykeparany);
			if( $diff < 0.3 ){
				kemeretezesvagassh($ujnagykep,$ujnagykep,488,396);
			}else{
				kemeretezesvagasshbg($ujnagykep,$ujnagykep,488,396);
			}*/

		}


		chmod($hova."big",0777);
		chmod($hova."thumb",0777);
	}

	function uploadhozzaadsubmit(){
		$objidesgyarto  = explode("#",$this->input->post('objidesgyarto'));
		$obj_id  = $objidesgyarto[0];
		$gyardir = $objidesgyarto[1];
		$pverzio = $this->input->post('prverzio');
		$eredeti = $this->input->post('eredeti');	// ez van a vendegnel
		$ujfajl  = $this->input->post('fajl');		// ez legyen a publicban


		// fájl elhelyezése
		$tempFolder  = "/home/vendeg/";									// ide másolja az FTP applet a fájlt
		$storeFolder = "public/collection/".$gyardir."/".$obj_id."/";	// mi itt szeretnénk tárolni
		$tempFajl  = $tempFolder.$eredeti;
		$storeFajl = $storeFolder.$ujfajl;

		if(is_numeric($obj_id) && is_dir($storeFolder) && copy($tempFajl,$storeFajl)){
			chmod($storeFajl,0777);

			$verzio->o_id    = $obj_id;
			$verzio->version = $pverzio;
			$verzio->fajl    = $ujfajl;
			$this->db->insert('cadline2.coll2_ver',$verzio);

			//print "új elem feltöltve: ".$storeFajl;

		}else{
			$record->osztaly = "collection";
			$record->fv = "uploadhozzaadsubmit";
			$record->hiba = "Hibás hozzáadott feltöltés: ".$obj_id."\ntemp fajl: ".$tempFajl;
			$record->datum = date('Y-m-d H:i:s',time());
			$this->db->insert('a_hibak',$record);

			//print "Hiba a feltöltéskor";
		}

	}


	// felhasználó viewerbe
	function usersubmit(){
		if( !$this->cookieupdate() )
			header("Location: ".$_SERVER["HTTP_REFERER"]);
		include('application/helpers/sajatfeltolto.php');
		include('application/helpers/myimg_helper.php');

		$nyelv = hun() ? "hun" : "eng";

		setcookie("uploaduserPrevUsername",$this->input->post('username'),time()+$this->ervenydesseg,"/");
		setcookie("uploaduserPrevProjname",$this->input->post('projecttitle'),time()+$this->ervenydesseg,"/");

		$error  = "";
		$login  = $_COOKIE['azonosito'];
		if($login != "guest"){
			$query  = $this->db->query("SELECT user_id FROM `cadline2`.`forum_user` WHERE login = '".$login."' AND nyelv='{$nyelv}'")->row();
			$userid = $query->user_id;
		}else{
			//$subject = str_replace(' ','-',strtolower($this->input->post('username')));
			$username = $this->input->post('username');
			if(!$username)
				$username = "a";
			$subject = str_replace(' ','-',strtolower($username));
			$pattern = '/[-_a-z0-9]*/';
			preg_match_all($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
			$username = "";
			foreach($matches[0] as $m) if($m[0]) $username .= $m[0];

			$userid = "guest";
		}
		$shared = ($this->input->post('shared')=="on") ? 1 : 0;

		$projecttitle = $this->input->post('projecttitle');
		$projekt      = $this->input->post('projekt');			// projekt neve
		$projektdir   = strtolower($this->ekezet($projekt));	// mappa neve
		$projekt      = strtolower($this->ekezet($projekt));
		preg_match_all('/[-_a-z0-9]*/', $projektdir, $prdirarray, PREG_OFFSET_CAPTURE);
		$projektdir   = ($username!="") ? $username."/" : "";
		foreach($prdirarray[0] as $m) if($m[0]) $projektdir .= $m[0];
		$nagyfajl     = $this->input->post('nagyfajl');

		$cp_id = $this->db->query("SELECT cp_id FROM collection_projects WHERE userid='{$userid}' AND mappa='{$projektdir}'")->result();
		$cp_id = $cp_id[0]->cp_id;
		if(!$cp_id){
			$ujprojekt = new stdClass();
			$ujprojekt->nev    = $projecttitle;
			$ujprojekt->mappa  = $projektdir;
			$ujprojekt->userid = $userid;
			if( $this->input->post('username') )
				$ujprojekt->guestname = $this->input->post('username');
			$this->db->insert('cadline2.collection_projects',$ujprojekt);
			$cp_id = $this->db->insert_id();
		}

		$uj->userid  = $userid;
		$uj->cp_id   = $cp_id;
		$uj->project = $projektdir;
		$uj->file    = basename($nagyfajl);
		$uj->title   = $this->input->post('cim');
		$uj->desc    = $this->input->post('leiras');
		$uj->shared  = $shared;

		$this->db->insert('cadline2.collection_user',$uj);
		$ujid = $this->db->insert_id();


			// fajl feltoltese
		$helye = "public/img/collection/users/".$userid."/".$projektdir."/".$ujid."/";
		$nagyfajlhelye = $helye.basename($nagyfajl);
		// user első feltöltése
		if(!is_dir("public/img/collection/users/".$userid."/")){
			mkdir("public/img/collection/users/".$userid."/",0777);
			chmod("public/img/collection/users/".$userid."/",0777);
		}
		// guest, első username
		if( $userid == "guest" && !is_dir("public/img/collection/users/".$userid."/".$username."/") ){
			mkdir("public/img/collection/users/".$userid."/".$username."/",0777);
			chmod("public/img/collection/users/".$userid."/".$username."/",0777);
		}
		// új projekt
		if(!is_dir("public/img/collection/users/".$userid."/".$projektdir."/")){
			mkdir("public/img/collection/users/".$userid."/".$projektdir."/",0777);
			chmod("public/img/collection/users/".$userid."/".$projektdir."/",0777);
		}

		mkdir($helye,0777);
		chmod($helye,0777);

		if (copy($nagyfajl,$nagyfajlhelye)){
			$prSize = filesize($nagyfajlhelye);
			chmod($nagyfajlhelye,0777);
		}else{
			$prSize = 0;
			$error .= "Nem másoltam át a fájlt<br /> vendegben: ".$nagyfajl." publicba: ".$nagyfajlhelye;
		}


			// 1024-es elonezeti kep mentese
		copy($this->input->post('elonezetorig'),$helye."1__1024.jpg");

			// nagy kep feltoltese
		if( isset($_FILES['nagykep']) && $_FILES['nagykep']['error'] == 0 ){
			// új nagy kép
			$hova = $helye;
			$ujnagykep = $hova."1__big.jpg";
			feltolt("nagykep",$hova,"1__big.jpg",true);
		}else{
			// programból küldött nagy kép
			$orignagykep = $this->input->post('elonezetorig');
			$hova = $helye;
			$ujnagykep = $hova."1__big.jpg";
			copy($orignagykep,$ujnagykep);
		}
		// nagy kep atmeretezes
		$nagykeparany = (488/396);
		list($ow,$oh) = getimagesize($ujnagykep);
		$orignagykeparany = ($ow/$oh);
	//	print "nagy kep sima arany: {$nagykeparany} , eredeti arany: {$orignagykeparany}";
		$diff = abs($nagykeparany-$orignagykeparany);
		if( $diff < 0.3 ){
			kemeretezesvagassh($ujnagykep,$ujnagykep,488,396);
		}else{
			kemeretezesvagasshbg($ujnagykep,$ujnagykep,488,396);
		}
		chmod($ujnagykep,0777);


			// kis kep feltoltese
		if( isset($_FILES['kiskep']) && $_FILES['kiskep']['error'] == 0 ){
			// új kis kép
			$hova = $helye;
			$ujkiskep = $hova."1__small.jpg";
			feltolt("kiskep",$hova,"1_small.jpg",true);
		}else{
			// programból küldött kis kép
			$elonezetorig = $this->input->post('elonezetorig');
			$hova = $helye;
			$ujkiskep = $hova."1__small.jpg";
			copy($elonezetorig,$ujkiskep);
		}
		// kis kep atmeretezes
		kemeretezesvagassh($ujkiskep,$ujkiskep,68,68);
		chmod($ujkiskep,0777);

		// 300 szeles elonezeti kep letrehozasa
		$kozepkep = $helye.'1__300.jpg';
		/*exec('convert -resize 300 '.$this->input->post('elonezetorig').' '.$kozepkep);*/
		kemeretezesvagasshbg($this->input->post('elonezetorig'),$kozepkep,300,225);
		chmod($ujnagykep,0777);

	}

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

		$data['tartalom']='collection/ujjelszo';
		$data['style'] = array('temp/style_new');
		$data['javascript'] = array('objfeltoltes_2');

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

	function szabalyzat(){
		if(hun()){
			$data['title'] = 'ARCHLine.XP Feltöltés';
			$data['page'] = $this->mpages->get_row(572);
		}
		else{
			$data['title'] = 'ARCHLine.XP Upload';
			$data['page'] = $this->mpages->get_row(571);
		}

		$data['tartalom']='page/show';
		$data['style'] = array('style_new');

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

	function login(){
		$this->load->model('mforum');

		$email = $_POST["email"];
		$jelszo = $_POST["jelszo"];
		$link = $_SERVER["HTTP_REFERER"];
		$error = "";


		// ha vendégként lépnek be
		if( $this->uri->segment(3) == "guest" ){

			$user_id = "guest";
			$email = "guest";

			$sessid=md5($email.time());
			$hash=md5($email . $this->pw . $sessid);
			setcookie("sessid",$sessid,time()+$this->ervenydesseg,"/");
			setcookie("azonosito", $email, time()+$this->ervenydesseg,"/");
			setcookie("hash",$hash,time()+$this->ervenydesseg,"/");

			$tomb = array();
			$tomb['feltolto_id'] = $user_id;
			$tomb['email'] = $email;
			$this->phpsession->save('feltolo',$tomb);

			header("Location: ".$link);

		}
		// ha hibásak a bejelentkezési adatok
		elseif( !$this->mforum->belep($email,$jelszo) ){

			$this->phpsession->save('feltoltesbelepesihiba',"hfvj");
			$this->phpsession->save('feltoltesbelepesihibaemail',$email);
			header("Location: ".$link);

		}else{
			$user_id = $this->mforum->get_userid($email);
			$tomb = array();
			$tomb['feltolto_id'] = $user_id;
			$tomb['email'] = $email;
			//$this->phpsession->save('feltolo',$tomb);

			//header("Location: ".$link);



			$sessid=md5($email.time());
			$hash=md5($email . $this->pw . $sessid);
			setcookie("sessid",$sessid,time()+$this->ervenydesseg,"/");
			setcookie("azonosito", $email, time()+$this->ervenydesseg,"/");
			setcookie("hash",$hash,time()+$this->ervenydesseg,"/");

			$user_id = $this->mforum->get_userid($email);
			$tomb = array();
			$tomb['feltolto_id'] = $user_id;
			$tomb['email'] = $email;
			$this->phpsession->save('feltolo',$tomb);

			header("Location: ".$link);
		}

	}

	function logout(){
		$link = $_SERVER["HTTP_REFERER"];
		unset($_SESSION['default']['feltolo']);

		setcookie("sessid","",0,"/");
		setcookie("azonosito","",0,"/");
		setcookie("hash","",0,"/");

		header("Location: ".$link);
	}

	function desc(){
		if( $this->uri->segment(3) )
			$c_id = $this->uri->segment(3);
		else
			redirect('collection/kategoria');

		$adatok = $this->mcollection->get_row($c_id);

		$data['adatok'] = $adatok;

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

		$data['title'] = 'ARCHLine.XP Collection';
		$data['title'] .= " - " . $adatok->title;

		$data['tartalom'] = 'collection/desc';

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

	function mycollection(){

		$this->load->model('mforum');

		$ell = md5($_COOKIE['azonosito'].$this->pw.$_COOKIE['sessid']);

		if( !empty($_COOKIE['hash']) && $_COOKIE['hash']== $ell ){

			$user_id = $this->mforum->get_userid($_COOKIE['azonosito']);
			$adatok = $this->mcollection->get_allUserId($user_id);

			$data['objects'] = $adatok;
			$data['szerk'] = true;

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

			$data['tartalom'] = 'collection/kat';

		}else{
			$data['tartalom'] = 'collection/login';
			$data['javascript'] = array('objfeltoltes_2');

			if(hun())
				$data['feltetel'] = $this->mpages->get_row(572);
			else
				$data['feltetel'] = $this->mpages->get_row(571);
		}

		$data['style'] = array('temp/style_interior','fancybox2');
		$data['title'] = 'ARCHLine.XP Collection';
		$this->load->view('site_upload',$data);
	}

	function edit(){
		$this->load->model('mforum');

		$c_id = $this->uri->segment(3);
		$user_id = $this->mforum->get_userid($_COOKIE['azonosito']);
		$adatok = $this->mcollection->get_row($c_id);


		if( is_numeric($c_id) && $this->cookieupdate() && $adatok->u_id == $user_id ){

			if( !$this->input->post('do') ){
				$data['object'] = $adatok;

				$kategoriak = $this->muser->get_kategoriak($adatok->tipus);
				$kategoriak = $this->mcollection->get_darab($kategoriak);

				$data['kategoriak'] = $kategoriak;
				$data['szerk'] = true;

				$data['tartalom'] = 'collection/edit';
				print "rendben";

				$data['style'] = array('temp/style_interior');
				$data['javascript'] = array('objfeltoltes_2');
				$data['title'] = 'ARCHLine.XP Collection';
				$this->load->view('site_upload',$data);

			}else{

				$lang = $this->muser->user['lang'];

				$error = "";
				$kep = $adatok->kep;
				$kat_id = 0;

				$tipusa = $adatok->tipus;
				$this->kep($kep,$tipusa);


				// új kategória felvétele, ha megadták
				if( $_POST["ujkat"] != "" ){
					if(hun()){
						$nevhun = $_POST["ujkat"];
						$neveng = "";
					}else{
						$nevhun = "";
						$neveng = $_POST["ujkat"];
					}

					$kat_id = $this->muser->new_kategoria($tipusa,$nevhun,$neveng);
				}else{
					$kat_id = $_POST["kategoria"];
				}


				if(!$error){
					$ujpr->title = $_POST["projhectNameField"];
					$ujpr->meret = $adatok->size;
					$ujpr->datum = $adatok->datum;
					$ujpr->nyelv = $adatok->nyelv;
					$ujpr->kep = $kep;
					$ujpr->text = $_POST["projectDescriptionField"];
					$ujpr->fajl = $adatok->fajl;
					$ujpr->szerzo = $_POST["SzerzoField"];
					$ujpr->kat_id = $kat_id;

					$this->mcollection->editobject($ujpr,$c_id);
				}

				redirect('collection/mycollection');

			}

		}else{

			//print "hiba";
			redirect('collection/mycollection');
		}
	}

	function del(){
		$this->load->model('mforum');

		$c_id = $this->uri->segment(3);
		$user_id = $this->mforum->get_userid($_COOKIE['azonosito']);
		$adatok = $this->mcollection->get_row($c_id);

		if( is_numeric($c_id) && $this->cookieupdate() && $adatok->u_id == $user_id ){
			$this->mcollection->del($c_id);
		}

		redirect('collection/mycollection');
	}

	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 cookieupdate(){
		if( isset($_COOKIE['azonosito'],$_COOKIE['sessid']) )
			$ell = md5($_COOKIE['azonosito'].$this->pw.$_COOKIE['sessid']);
		else
			return false;

		if ( !empty($_COOKIE['hash']) && $_COOKIE['hash']== $ell ){
			setcookie("sessid",$_COOKIE['sessid'],time()+$this->ervenydesseg,"/");
			setcookie("azonosito", $_COOKIE['azonosito'] , time()+$this->ervenydessegemail,"/");
			setcookie("hash",$_COOKIE['hash'] ,time()+$this->ervenydesseg,"/");

			return true;

		}else{
			return false;
		}
	}

	function kep(&$kep,$tipus){
		if ($_FILES["kep"]["error"]==0){
			$kepnev = time()."_". $_FILES["kep"]["name"];
			$ide= "public/img/collection/".$tipus."/".$kepnev;
			if (copy($_FILES["kep"]["tmp_name"],$ide)){
				$kep = $ide;
				//print " Sikerült a képmásolás! ";
			}else{
				//print " Nem sikerült a képet felmásolni! ";
			}
		}
	}


}

?>
