<?php

define('SHOWROOM_SEARCH', true);
/*  Az ARCHLine-ból hívódik a link  */
class Showroom2 extends Controller
{
	var $collectionlangs = array('eng','hun','ita','ger');
	var $defaultparam = array('style'=>array('style_new','showroomweb_min'),'tartalom'=>'site');
	
	function Showroom2()
	{
		parent::Controller();
		$this->load->model('mcollection2');
		
		if($this->uri->segment(1)!="collection2")
			setcookie("sr_prversion","2020",time()+10000,"/");
	}
	
	function index($param1=""){
		$data['gyartok'] = $this->mcollection2->get_gyartok();
		
		$data['tartalom']='collection2/index';
		$data['title'] = hun() ? 'ARCHLine.XP Bemutatóterem - ' : 'ARCHLine.XP Showroom - ';
		$data['title'] .= lang('collec_brands');
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style'] = array('collection','style_new');		// programba való
		else{
			$data['style'] = $param1['style'];						// átlag böngészőbe
		}
		
		
		if($this->uri->segment(1)=="collection2"){
			if( is_numeric($this->uri->segment(4))){
				setcookie("sr_prversion",($this->uri->segment(4)+1984),time()+10000,"/");
				// 28 - 2012 -es verzió
				// 29 - 2013 -as verzió
			}elseif( isset($_COOKIE['sr_prversion']) && !$this->uri->segment(4) ){
				
			}else{
				setcookie("sr_prversion","2012",time()+10000,"/");
			}
			
			// ez nem szükséges ..
			$data['javascript'] = array("collection");
		}else{
			setcookie("sr_prversion","2020",time()+10000,"/");
		}
		
		if($this->uri->segment(3)!="" && in_array($this->uri->segment(3),$this->collectionlangs) ){
			$latogato = $this->phpsession->get('user');
			$latogato['lang'] = $this->uri->segment(3);
			$this->phpsession->save('user',$latogato);
			if($this->muser->user['lang']!=$this->uri->segment(3)){
				redirect($this->uri->segment(1)."/".$this->uri->segment(2)."/".$this->uri->segment(3)."/".$this->uri->segment(4));
			}
		}
		
		
		$showroomstat = $this->cache->get('showroom-stat');
		if( !$showroomstat ){
			$showroomstat = $this->mcollection2->get_all_showdown();
			$this->cache->write($showroomstat, 'showroom-stat', 3600);	// óránként frissül majd
		}
		
		$data['stat'] = $showroomstat;
		$data['mobilink'] = "/mobile/shbrands";
		
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
	}
	
	function brandgroup($param1=""){
		
		if( !$this->uri->segment(3) ){
			$this->index();
			return;
		}
		
		$brandgroup      = $this->db->query("SELECT * FROM coll2_mangrp WHERE azon='{$this->uri->segment(3)}'")->row();
		
		if( !$brandgroup->group_id ){
			$this->index();
			return;
		}
		$data['gyartok'] = $this->mcollection2->get_gyartokcsop($brandgroup->group_id);
		
		$data['tartalom']='collection2/index';
		$data['title'] = hun() ? 'ARCHLine.XP Bemutatóterem - ' : 'ARCHLine.XP Showroom - ';
		$data['title'] .= $brandgroup->nev;
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style'] = array('collection','style_new');		// programba való
		else{
			$data['style'] = $param1['style'];						// átlag böngészőbe
		}
		
		$showroomstat = $this->cache->get('showroom-stat-'.$brandgroup->azon);
		if( !$showroomstat ){
			$showroomstat = $this->mcollection2->get_group_showdown($brandgroup->group_id);
			$this->cache->write($showroomstat, 'showroom-stat-'.$brandgroup->azon, 3600);	// óránként frissül majd
		}
		
		$data['stat'] = $showroomstat;
		
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
	}
	
	function manufacturer($param1=""){
		
		if( !$this->uri->segment(3) ){
			$this->index();
			return;
		}
		
		$dir        = $this->uri->segment(3);
		$gyarto     = $this->mcollection2->get_manBydir($dir);
		
		if(!$gyarto){
			header("HTTP/1.1 404 Not Found");
			//show_404('Hibas marka: '.$dir);
		}
		
		$kategoriak = $this->mcollection2->get_kategoriak($dir);
		
		$data['kategoriak'] = $kategoriak;
		$data['gyarto']     = $gyarto;
		$data['gyartok']    = $this->mcollection2->get_gyartok();
		
		
		$kategorianevek = "";
		$i=0;
		
		foreach($kategoriak as $kat){
			if($i==6)
				break;
			hun() ? $kategorianevek .= $kat->nev_hun.", " : $kategorianevek .= $kat->nev_eng.", ";
			$i++;
		}
		
		if(hun()){
			$data['meta']['desc'] = 'ARCHLine.XP Bemutatóterem - '.$gyarto->name.' kategóriák: '.substr($kategorianevek,0,-2);
		}else{
			$data['meta']['desc'] = 'ARCHLine.XP Showroom - categories of '.$gyarto->name.': '.substr($kategorianevek,0,-2);
		}
		
		
		$data['mobilink'] = "/mobile/shcategories/".$dir;
		$data['tartalom'] ='collection2/manufacturer';
		$data['title']    = hun() ? 'ARCHLine.XP Bemutatóterem' : 'ARCHLine.XP Showroom';
		$data['title']   .= " - " . $gyarto->name;
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style'] = array('collection','style_new');		// programba való
		else{
			$data['style'] = $param1['style'];						// átlag böngészőbe
		}
		
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
	}
	
	function category($param1=""){
		if( !$this->uri->segment(3) || !is_numeric($this->uri->segment(3)) ){
			redirect($this->uri->segment(1));
			$this->index();
			return;
		}
		
		$ordernev = hun() ? 'title_hun' : 'title_eng';
		
		$cid         = $this->uri->segment(3);
		$kategoria   = $this->mcollection2->get_kategoria($cid);
		if(!$kategoria){
			header("HTTP/1.1 404 Not Found");
			//show_404('Nem letezo kategoria: '.$kategoria);
		}
		$objkektumok = $this->mcollection2->get_objektumok($cid,$ordernev.' ASC');
		$gyarto      = $this->mcollection2->get_manById($kategoria->m_id);
		$kategoriak  = $this->mcollection2->get_kategoriak($gyarto->dir);
		
		$data['kategoriak'] = $kategoriak;
		
		$data['objektumok'] = $objkektumok;
		$data['kategoria']  = $kategoria;
		$data['gyarto']     = $gyarto;
		
		
		$elemekstr = "";
		$i=0;
		$nyelv = $this->muser->user['lang'];
		
		foreach($objkektumok as $obj){
			if($i<6)
				hun() ? $elemekstr .= $obj->title_hun.", " : $elemekstr .= $obj->title_eng.", ";
			
			$leiras = $this->db->query("SELECT title FROM coll2_desc WHERE lang='{$nyelv}' AND o_id=".$obj->o_id)->row();
			if( !$leiras )
				$leiras = $this->db->query("SELECT title FROM coll2_desc WHERE lang='eng' AND o_id=".$obj->o_id)->row();
			$obj->title = $leiras->title;
			
			$i++;
		}
		
		if(hun()){
			$data['meta']['desc'] = 'ARCHLine.XP Bemutatóterem - '.$kategoria->nev_hun.' kategória elemei: '.substr($elemekstr,0,-2);
			$data['title']  = 'ARCHLine.XP Bemutatóterem';
			$katnev = $kategoria->nev_hun;
		}else{
			$data['meta']['desc'] = 'ARCHLine.XP Showroom - '.$kategoria->nev_eng." items: ".substr($elemekstr,0,-2);
			$data['title']  = 'ARCHLine.XP Showroom';
			$katnev = $kategoria->nev_eng;
		}
		
		$data['title'] .= " - " . $gyarto->name." - ".$katnev;
		$data['mobilink'] = "/mobile/shobjects/".$cid;
		$data['tartalom']='collection2/category';
		
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style'] = array('collection','style_new');		// programba való
		else{
			$data['style'] = $param1['style'];						// átlag böngészőbe
		}
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
	}
	
	function details($param1=""){
		if( !$this->uri->segment(3) || !is_numeric($this->uri->segment(3)) ){
			$this->index();
			return;
		}else{
			$this->shownovel($this->uri->segment(3));
		}
		
		$oid    = $this->uri->segment(3);
		$adatok = $this->mcollection2->get_elem($oid);
		if($adatok === false){
			header("HTTP/1.1 404 Not Found");
			$adatok->title_hun = "A keresett elem nem található";
			$adatok->title_eng = "Not found";
			$data['adatok'] = $adatok;
			$data['style']  = array('collection','style_new');
			$data['title'] = 'ARCHLine.XP Collection';
			$data['tartalom'] = 'collection2/details';
			if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
				$this->load->view($param1['tartalom'],$data);
			else
				$this->load->view('site_upload',$data);
			
			return;
		}
		
		$ordernev = hun() ? 'title_hun' : 'title_eng';
		
		$gyarto = $this->mcollection2->get_manById($adatok->m_id);
		$fajlok = scandir('public/collection/'.$gyarto->dir.'/'.$adatok->o_id);
		$kategoriaelemek = $this->mcollection2->get_objektumok($adatok->c_id,$ordernev.' ASC');
		$nagykepek = scandir('public/img/collection/'.$gyarto->dir.'/'.$adatok->o_id."/big");
		$kategoria = $this->mcollection2->get_kategoria($adatok->c_id);
		$verziok   = $this->db->query("SELECT fajl, version FROM coll2_ver WHERE o_id={$adatok->o_id} AND deleted=0")->result_array();
		
		$object = $this->mcollection2->get_elem2($oid);
		$kovi  = $this->mcollection2->get_elem_next2($object);
		$elozo = $this->mcollection2->get_elem_prev2($object);
		$sorszam = $this->mcollection2->get_sorszam2($object);
		
		function fajl_ev($array){
			$vals = array();
			foreach ($array as $value) {
				$vals[$value['fajl']] = $value['version'];
			}
			return $vals;
		}
		
		if( count($verziok)>0 ){
			$verziok2 = fajl_ev($verziok);
		}
		
		
		foreach($kategoriaelemek as $elem){
			$kepek = scandir('public/img/collection/'.$gyarto->dir.'/'.$elem->o_id);
			foreach($kepek as $kep){
				if( $kep != "." && $kep != ".." && !is_dir("public/img/collection/".$gyarto->dir."/".$elem->o_id."/".$kep) ){
					$elem->kep = "public/img/collection/".$gyarto->dir."/".$elem->o_id."/".$kep;
					break;
				}
			}
			$elem->kep2 = "public/img/collection/".$gyarto->dir."/".$elem->o_id."/zz_small.jpg";
		}
		
		$mit = array("\r\n", "\n", "\r");
		
		$nyelv = $this->muser->user['lang'];
		$leiras = $this->db->query("SELECT title, `desc` FROM coll2_desc WHERE lang='{$nyelv}' AND o_id=".$oid)->row();
		if( !$leiras )
			$leiras = $this->db->query("SELECT title, `desc` FROM coll2_desc WHERE lang='eng' AND o_id=".$oid)->row();
		
		$adatok->leiras = $leiras->desc;
		$adatok->leiras = str_replace($mit,'<br />',$adatok->leiras);
		$adatok->title  = $leiras->title;
		
		$data['adatok']  = $adatok;
		$data['gyarto']  = $gyarto;
		$data['kat']     = $kategoria;
		$data['fajlok']  = $fajlok;
		$data['verziok'] = $verziok2;
		$data['kepek']   = $kategoriaelemek;
		$data['sorszam']   = $sorszam;
		$data['nagykepek'] = $nagykepek;
		$data['kovetkezo'] = $kovi->o_id;
		$data['elozo']   = $elozo->o_id;
		
		if( isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'],'search') && isset($_SESSION['shsearch']) && $_SESSION['shsearch'] ){
			$data['search'] = true;
		}
		
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style']  = array(
									'../js/jsor-jcarousel/skins/tango/skincollection',
									'collection',
									'style_new'
								);	// archline-ba való
		else{
			$data['style'] = $param1['style'];						// átlag böngészőbe
		}
		
		$data['style'][]    = "../js/Smooth-Div-Scroll/css/smoothDivScroll";
		
		$data['title'] = hun() ? 'ARCHLine.XP Bemutatóterem - ' : 'ARCHLine.XP Showroom - ';
		$data['title'] .= hun() ? $adatok->title_hun : $adatok->title_eng;
		$data['title'] .= " (by ".$gyarto->name.")";
		$data['meta']['desc'] = $data['title'].": ";
		$data['meta']['desc'] .= trim(str_replace("\n"," ",substr(($str=wordwrap(strip_tags($adatok->leiras),80,'$$')),0,strpos($str,'$$'))." ..."));
		
		if($gyarto->dir=="cadline")
			$data['noindex']=true;
		
		$data['tartalom'] = 'collection2/details';
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
	}
	
	function detailssimple(){
		if( !$this->uri->segment(3) || !is_numeric($this->uri->segment(3)) ){
			print "Parameter error";
			return;
		}else{
			$this->shownovel($this->uri->segment(3));
		}
		
		
		$oid    = $this->uri->segment(3);
		$adatok = $this->mcollection2->get_elem($oid);
		$gyarto = $this->mcollection2->get_manById($adatok->m_id);
		$fajlok = scandir('public/collection/'.$gyarto->dir.'/'.$adatok->o_id);
		$kategoriaelemek = $this->mcollection2->get_objektumok($adatok->c_id);
		$nagykepek = scandir('public/img/collection/'.$gyarto->dir.'/'.$adatok->o_id."/big");
		$kategoria = $this->mcollection2->get_kategoria($adatok->c_id);
		$verziok   = $this->db->query("SELECT fajl, version FROM coll2_ver WHERE o_id={$adatok->o_id} AND deleted=0")->result_array();
		
		$object = $this->mcollection2->get_elem2($oid);
		if($this->uri->segment(4)=="type"){
			$kovi  = $this->mcollection2->get_elem_next3($object);
			$elozo = $this->mcollection2->get_elem_prev3($object);
		}else{
			$kovi  = $this->mcollection2->get_elem_next2($object);
			$elozo = $this->mcollection2->get_elem_prev2($object);
		}
		$sorszam = $this->mcollection2->get_sorszam2($object);
		
		function fajl_ev($array){
			$vals = array();
			foreach ($array as $value) {
				$vals[$value['fajl']] = $value['version'];
			}
			return $vals;
		}
		
		if( count($verziok)>0 ){
			$verziok2 = fajl_ev($verziok);
		}
		
		$mit = array("\r\n", "\n", "\r");
		
		$nyelv = $this->muser->user['lang'];
		$leiras = $this->db->query("SELECT title, `desc` FROM coll2_desc WHERE lang='{$nyelv}' AND o_id=".$oid)->row();
		if( !$leiras )
			$leiras = $this->db->query("SELECT title, `desc` FROM coll2_desc WHERE lang='eng' AND o_id=".$oid)->row();
		
		$adatok->leiras = $leiras->desc;
		$adatok->leiras = str_replace($mit,'<br />',$adatok->leiras);
		$adatok->title  = $leiras->title;
		
		$data['adatok'] = $adatok;
		$data['gyarto'] = $gyarto;
		$data['kat']    = $kategoria;
		$data['fajlok'] = $fajlok;
		$data['verziok'] = $verziok2;
		$data['kepek']  = $kategoriaelemek;
		$data['sorszam']   = $sorszam;
		$data['nagykepek'] = $nagykepek;
		$data['kovetkezo'] = $kovi->o_id;
		$data['elozo']  = $elozo->o_id;
		
		$this->load->view('collection2/detailssimple',$data);
	}
	
	function downloadcategory(){
		$cat_id = $this->uri->segment(3);
		
		if(!$cat_id){
			print "0";
			return;
		}
		
		function fajl_ev($array){
			$vals = array();
			foreach ($array as $value) {
				$vals[$value['fajl']] = $value['version'];
			}
			return $vals;
		}
		
		$valasz = array();
		$kategoria = $this->mcollection2->get_kategoria($cat_id);
		$gyarto    = $this->mcollection2->get_manById($kategoria->m_id);
		
		$objkektumok = $this->mcollection2->get_objektumok($cat_id);
		foreach($objkektumok as $obj){
			$fajlok = scandir('public/collection/'.$gyarto->dir.'/'.$obj->o_id);
			
			$verziok = $this->db->query("SELECT fajl, version FROM coll2_ver WHERE o_id={$obj->o_id} AND deleted=0")->result_array();
			if( count($verziok)>0 ){
				$verziok = fajl_ev($verziok);
			}
			
			$letoltlink = "http://www.archlinexp.com";
			$fajl = "";
			// megfelelő programverzióhoz tartozó fájl
			if(count($fajlok)>3){
				$prverzio = 2013;
				$fajl = array_search($prverzio, $verziok);
				if(in_array($fajl,$fajlok)){
					$letoltlink .= "/public/collection/{$gyarto->dir}/{$obj->o_id}/{$fajl}?download=1&type=";
					if( $verziok[$fajl] == "2013" && $obj->tipus=="object" ){
						$letoltlink .= "accessory";
					}elseif($obj->tipus=="lamp"){
						$letoltlink .= "lamps";
					}else{
						$letoltlink .= $obj->tipus;
					}
					$letoltlink .= "&brandcategory=".base64_encode($gyarto->name.'\\'.$kategoria->nev_eng);
				}else{
					$letoltlink = "hibas fajl!";
				}
			}elseif(!isset($fajlok[2])){
				$letoltlink = "nincs fajl!";
			}else{
				$fajl=$fajlok[2];
				$letoltlink .= "/public/collection/{$gyarto->dir}/{$obj->o_id}/{$fajl}?download=1&type=";
				if( $verziok[$fajl] == "2013" && $obj->tipus=="object" ){
					$letoltlink .= "accessory";
				}elseif($obj->tipus=="lamp"){
					$letoltlink .= "lamps";
				}else{
					$letoltlink .= $obj->tipus;
				}
				$letoltlink .= "&brandcategory=".base64_encode($gyarto->name.'\\'.$kategoria->nev_eng);
			}
			
			$valasz[] = array($letoltlink, $obj->o_id, $verziok[$fajl]);
			
		}
		
		
		// statisztika + válasz az archline-nak
	//	print count($valasz);
		foreach($valasz as $v){
			print $v[0].";";
			
			// statisztika
			//$this->downloadplus($v[1]);
			fopen("http://www.archlinexp.com/collection2/downloadplus/".$v[1]."/".$v[2], "r");
		}
		
	}
	
	
	function ajaxkategoriak(){
		$dir = $this->uri->segment(3);
		$kategoriak = $this->mcollection2->get_kategoriak($dir);
		
		
		print "<select name=\"kategoria\" id=\"kategoria\" onchange=\"katvaltas2(this.value)\" style=\"width: 255px;\">";
		print	"<option value=\"999\">-- ".lang('collec_valasszon')." --</option>";
				foreach($kategoriak as $kategoria){
					print "<option value=\"".$kategoria->c_id."\">";
					print 	$kategoria->nev_hun." | ".$kategoria->nev_eng;
					print "</option>";
				}
		print	"<option value=\"999999\">-- ".lang('collec_ujkategoria')." --</option>";
		print "</select>";
	}
	
	function downloadplus(){
		if( !$this->uri->segment(3) || !is_numeric($this->uri->segment(3)) )
			return;
		
		$oid = $this->uri->segment(3);
		
		$this->load->library('user_agent');
		// robotokat ne számítsa a statisztikába
		if($this->agent->is_robot())
			return;
		
		
		if(isset($_SESSION['coll2elemletoltve']))
			$letoltve = $_SESSION['coll2elemletoltve'];
		else
			$letoltve = array();
		if( !in_array($oid, $letoltve) ){
	//		$this->db->query("UPDATE collection2 SET `down` = `down`+1 WHERE o_id={$oid}");
			$_SESSION['coll2elemletoltve'][] = $oid;
			
			$prverzio = $this->uri->segment(4);
			if( is_numeric($prverzio) ){
	//			$this->db->query("UPDATE coll2_ver SET `down` = `down`+1 WHERE o_id={$oid} AND version='{$prverzio}'");
			}
		}
	}
	
	function shownovel($oid){
		if(isset($_SESSION['coll2elemmegtekintve']))
			$megtekintve = $_SESSION['coll2elemmegtekintve'];
		else
			$megtekintve = array();
		if( !in_array($oid, $megtekintve) ){
	//		$this->db->query("UPDATE collection2 SET `show` = `show`+1 WHERE o_id={$oid}");
			$_SESSION['coll2elemmegtekintve'][] = $oid;
		}
	}
	
	
	function search($param1=""){
		$search = urldecode($this->uri->segment(3));
		if( !$search && isset($_SESSION['shsearch']) )
			$search = $_SESSION['shsearch'];
		else
			$_SESSION['shsearch'] = str_replace('_', ' ', $search);
		
		$search = str_replace('_', ' ', $search);
		
		$result = $this->mcollection2->search($search);
		$gyartoktmp = array();
		
		if(!$result){
			header("HTTP/1.1 404 Not Found");
		}else{
			foreach($result as $obj){
				if( !in_array( $obj->gyartodir, $gyartoktmp ) ){
					$gyartoktmp[] = $obj->gyartodir;
					if( count($gyartoktmp) > 1 )
						break;
				}
			}
		}
		
		if( count($gyartoktmp) == 1 ){
			$gyarto = new stdClass();
			$gyarto->dir = $gyartoktmp[0];
		}
		else
			$gyarto = false;
		
		$data['kategoria']  = $search;
		$data['objektumok'] = $result;
		$data['gyarto']     = $gyarto;
		$data['noindex']    = true;
		$data['search']     = true;
		$data['title']      = hun() ? "Bemutatóterem keresés: ".$search : "Showroom search: ".$search;
		
		$data['tartalom'] = 'collection2/category';
		
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style'] = array('collection','style_new');		// programba való
		else{
			$data['style'] = $param1['style'];						// átlag böngészőbe
		}
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
	}
	
	
	
	function types($param1=array('style'=>array('style_new','showroomweb_min'),'tartalom'=>'site')){
		if($this->uri->segment(1)!="collection2")
			$param1 = $this->defaultparam;
		
		if( $this->uri->segment(3)!="" ){
			//print "type: ".$this->uri->segment(3).", param: "; print_r($param1);
			$this->typebrands($this->uri->segment(3),$param1);
			return;
		}
		
		$mezo  = hun() ? "name_hun" : "name_eng";
		$sql   = "SELECT type, {$mezo} as name FROM coll2_types WHERE type IN (SELECT tipus FROM collection2 WHERE deleted=0 AND m_id IN (SELECT id FROM coll2_man WHERE deleted=0) GROUP BY tipus)";
		$types = $this->db->query($sql)->result();
		
		
		$data['types'] = $types;
		
		$data['tartalom'] = 'collection2/types';
		$data['title']    = hun() ? 'ARCHLine.XP Bemutatóterem - típusok' : 'ARCHLine.XP Showroom - types';
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style'] = array('collection','style_new');		// programba való
		else{
			$data['style'] = $param1['style'];						// átlag böngészőbe
		}
		
		$showroomstat = $this->cache->get('showroom-stat');
		if( !$showroomstat ){
			$showroomstat = $this->mcollection2->get_all_showdown();
			$this->cache->write($showroomstat, 'showroom-stat', 3600);	// óránként frissül majd
		}
		$data['stat'] = $showroomstat;
		
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
	}
	
	// típusból márkák
	function typebrands($type,$param1=""){
		if( $this->uri->segment(4)!="" ){
			$this->typebrandscategory($type,$this->uri->segment(4),$param1);
			return;
		}
		
		//print_r($param1);
		$sql = "SELECT name, dir FROM coll2_man m WHERE m.deleted=0 AND id IN (SELECT m_id FROM collection2 WHERE tipus='{$type}' AND deleted=0 GROUP BY m_id)";
		$brands = $this->db->query($sql)->result();
		
		$leiras = $this->db->query("SELECT * FROM coll2_types WHERE type='{$type}'")->row();
		$leiras = hun() ? $leiras->desc_hun : $leiras->desc_eng;
		$leiras = str_replace(array("\r\n", "\n", "\r"),'<br />',$leiras);
		
		$showroomstat = $this->cache->get('showroom-stat-'.$type);
		if( !$showroomstat ){
			$sql = "SELECT sum(`show`) as views, sum(`down`) as downloads FROM `collection2` o INNER JOIN `coll2_cat` c ON c.c_id=o.c_id  WHERE o.deleted=0 AND c.deleted=0 AND o.tipus='{$type}'";
			$showroomstat = $this->db->query($sql)->row();
			$this->cache->write($showroomstat, 'showroom-stat-'.$type, 3600);	// óránként frissül majd
		}
		$data['stat'] = $showroomstat;
		
		
		$data['gyartok'] = $brands;
		$data['ballink'] = "types/{$type}";
		$data['leiras']  = $leiras;
		
		$data['canonical'] = "showroom";
		$data['tartalom']  = 'collection2/index';
		$data['title']     = hun() ? 'ARCHLine.XP Bemutatóterem - ' : 'ARCHLine.XP Showroom - ';
		$data['title']    .= lang('collec_brands');
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style'] = array('collection','style_new');		// programba való
		else{
			$data['style'] = $param1['style'];						// átlag böngészőbe
		}
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
		
	}
	
	// típusból márkákból kategóriák
	function typebrandscategory($type,$brand,$param1=""){
		$sql = "SELECT o.c_id, c.nev_hun, c.nev_eng FROM collection2 o LEFT JOIN coll2_cat c ON c.c_id=o.c_id WHERE tipus='{$type}' AND o.m_id=(SELECT id FROM coll2_man WHERE dir='{$brand}') AND o.deleted=0 AND c.deleted=0 GROUP BY c_id";
		$kategoriak = $this->db->query($sql)->result();
		
		if( $this->uri->segment(5)!="" ){
			$this->typebrandscategoryitems($type,$brand,$this->uri->segment(5),$kategoriak,$param1);
			return;
		}
		
		$data['kategoriak']  = $kategoriak;
		$data['gyarto']->dir = $brand;
		$data['ballink']     = "types/{$type}/{$brand}";
		
		$data['canonical'] = "showroom/manufacturer/{$brand}";
		$data['tartalom']  = 'collection2/manufacturer';
		$data['title']     = hun() ? 'ARCHLine.XP Bemutatóterem' : 'ARCHLine.XP Showroom';
		$data['title']    .= " - " . $gyarto->name;
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style'] = array('collection','style_new');		// programba való
		else{
			$data['style'] = $param1['style'];						// átlag böngészőbe
		}
		
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
		
	}
	
	// típusból márkákból kategóriákból elemek
	function typebrandscategoryitems($type,$brand,$cid,$kategoriak,$param1=""){
		if( $this->uri->segment(6)!="" ){
			$this->typebrandscategoryitemdetails($type,$brand,$cid,$this->uri->segment(6),$param1);
			return;
		}
		// utvonal stimmel-e
		$marka = $this->db->query("SELECT dir FROM coll2_cat c LEFT JOIN coll2_man m ON c.m_id=m.id WHERE c_id={$cid}")->row();
		if($marka->dir!=$brand){
			redirect($this->uri->segment(1)."/types/{$type}/{$marka->dir}/{$cid}");
		}
		
		$ordernev = hun() ? 'title_hun' : 'title_eng';
		$sql = "SELECT * FROM collection2 WHERE tipus='{$type}' AND c_id={$cid} AND deleted=0 ORDER BY {$ordernev} ASC ";
		$objkektumok = $this->db->query($sql)->result();
		
		$data['objektumok']  = $objkektumok;
		$data['kategoriak']  = $kategoriak;
		$data['gyarto']->dir = $brand;
		$data['canonical']   = "showroom/category/{$cid}";
		$data['ballink']     = "types/{$type}/{$brand}";
		$data['jobblink']    = "types/{$type}/{$brand}/{$cid}";
		$data['tartalom']    = 'collection2/category';
		
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style'] = array('collection','style_new');		// programba való
		else
			$data['style'] = $param1['style'];						// átlag böngészőbe
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
		
	}
	
	function typebrandscategoryitemdetails($type,$brand,$cid,$oid,$param1=""){
		//$oid    = $this->uri->segment(6);
		$adatok = $this->mcollection2->get_elem($oid);
		if($adatok === false){
			header("HTTP/1.1 404 Not Found");
			$adatok->title_hun = "A keresett elem nem található";
			$adatok->title_eng = "Not found";
			$data['adatok'] = $adatok;
			$data['style']  = array('collection','style_new');
			$data['title'] = 'ARCHLine.XP Collection';
			$data['tartalom'] = 'collection2/details';
			if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
				$this->load->view($param1['tartalom'],$data);
			else
				$this->load->view('site_upload',$data);
			
			return;
		}
		
		// utvonal stimmel-e
		$marka = $this->db->query("SELECT dir FROM coll2_man WHERE id={$adatok->m_id}")->row();
		if($adatok->c_id!=$cid || $marka->dir!=$brand){
			redirect($this->uri->segment(1)."/types/{$type}/{$marka->dir}/{$adatok->c_id}/{$oid}");
		}
		
		$ordernev = hun() ? 'title_hun' : 'title_eng';
		$sqlobjs  = "SELECT * FROM collection2 WHERE tipus='{$type}' AND c_id={$cid} AND deleted=0 ORDER BY {$ordernev} ASC ";
		$gyarto   = $this->mcollection2->get_manById($adatok->m_id);
		$fajlok   = scandir('public/collection/'.$gyarto->dir.'/'.$adatok->o_id);
		$kategoriaelemek = $this->db->query($sqlobjs)->result();
		$nagykepek = scandir('public/img/collection/'.$gyarto->dir.'/'.$adatok->o_id."/big");
		$kategoria = $this->mcollection2->get_kategoria($adatok->c_id);
		$verziok   = $this->db->query("SELECT fajl, version FROM coll2_ver WHERE o_id={$adatok->o_id} AND deleted=0")->result_array();
		
		$object = $this->mcollection2->get_elem2($oid);
		$kovi  = $this->mcollection2->get_elem_next3($object);
		$elozo = $this->mcollection2->get_elem_prev3($object);
		$sorszam = $this->mcollection2->get_sorszam2($object);
		
		foreach($kategoriaelemek as $elem){
			$kepek = scandir('public/img/collection/'.$gyarto->dir.'/'.$elem->o_id);
			foreach($kepek as $kep){
				if( $kep != "." && $kep != ".." && !is_dir("public/img/collection/".$gyarto->dir."/".$elem->o_id."/".$kep) ){
					$elem->kep = "public/img/collection/".$gyarto->dir."/".$elem->o_id."/".$kep;
					break;
				}
			}
			$elem->kep2 = "public/img/collection/".$gyarto->dir."/".$elem->o_id."/zz_small.jpg";
		}
		
		
		$mit = array("\r\n", "\n", "\r");
		$nyelv  = $this->muser->user['lang'];
		$leiras = $this->db->query("SELECT title, `desc` FROM coll2_desc WHERE lang='{$nyelv}' AND o_id=".$oid)->row();
		if( !$leiras )
			$leiras = $this->db->query("SELECT title, `desc` FROM coll2_desc WHERE lang='eng' AND o_id=".$oid)->row();
		
		$adatok->leiras = $leiras->desc;
		$adatok->leiras = str_replace($mit,'<br />',$adatok->leiras);
		$adatok->title  = $leiras->title;
		
		function fajl_ev($array){
			$vals = array();
			foreach ($array as $value) {
				$vals[$value['fajl']] = $value['version'];
			}
			return $vals;
		}
		
		if( count($verziok)>0 ){
			$verziok2 = fajl_ev($verziok);
		}
		
		$data['adatok']  = $adatok;
		$data['gyarto']  = $gyarto;
		$data['kat']     = $kategoria;
		$data['fajlok']  = $fajlok;
		$data['verziok'] = $verziok2;
		$data['kepek']   = $kategoriaelemek;
		$data['sorszam']   = $sorszam;
		$data['nagykepek'] = $nagykepek;
		$data['kovetkezo'] = $kovi->o_id;
		$data['elozo']   = $elozo->o_id;
		$data['urlend']  = '/type';
		$data['vurl']    = '/showroom2/detailssimple/';
		$data['canonical'] = "showroom/details/{$oid}";
		
		$this->shownovel($oid);
		
		if( !is_array($param1) || count($param1['style']) == 0 )
			$data['style']  = array(
									'../js/jsor-jcarousel/skins/tango/skincollection',
									'collection',
									'style_new'
								);	// archline-ba való
		else
			$data['style'] = $param1['style'];						// átlag böngészőbe
		
		
		$data['style'][]    = "../js/Smooth-Div-Scroll/css/smoothDivScroll";
		
		$data['title'] = hun() ? 'ARCHLine.XP Bemutatóterem - ' : 'ARCHLine.XP Showroom - ';
		$data['title'] .= hun() ? $adatok->title_hun : $adatok->title_eng;
		$data['title'] .= " (by ".$gyarto->name.")";
		
		if($gyarto->dir=="cadline")
			$data['noindex']=true;
		
		$data['tartalom'] = 'collection2/details';
		
		if( isset($param1['tartalom']) && strlen($param1['tartalom']) > 1 )
			$this->load->view($param1['tartalom'],$data);
		else
			$this->load->view('site_upload',$data);
	}
	
}

?>