<?php
class Other extends Controller
{
	var $kulcsprverzio;
	function Other()
	{
		parent::Controller();
		// array( serial, prtype, prcontact );
		$this->kulcsprverzio = array(
			// 2013 interior prof - előfizetés
		//	'950054' => array('9500549300568130',9,1),	// már eladva
			'950055' => array('9500559300623371',9,1),
			'950056' => array('9500569300901666',9,1),
			'950057' => array('9500579300292771',9,1),
			'950058' => array('9500589300939891',9,1),
			'950059' => array('9500599300308525',9,1),
			'950060' => array('9500609300502875',9,1),
			'950061' => array('9500619300525057',9,1),
			'950062' => array('9500629300291068',9,1),
			'950063' => array('9500639300800628',9,1),
			'950064' => array('9500649300993926',9,1),
			
			// 2013 standard - normál
			'980104' => array('9801047300709739',7,0),
			'980105' => array('9801057300249936',7,0),
			'980106' => array('9801067300119100',7,0),
			'980107' => array('9801077300009403',7,0),
			'980108' => array('9801087300176636',7,0),
			'980109' => array('9801097300173361',7,0),
			'980110' => array('9801107300987491',7,0),
			'980111' => array('9801117300041608',7,0),
			'980112' => array('9801127300907455',7,0),
			
			// 2013 studio - normál
			'980113' => array('9801136300019297',6,0),
			'980114' => array('9801146300953568',6,0),
			'980115' => array('9801156300054608',6,0),
			'980116' => array('9801166300387538',6,0),
			'980117' => array('9801176300559245',6,0),
			'980118' => array('9801186300983875',6,0),
			'980119' => array('9801196300445516',6,0),
			'980120' => array('9801206300502309',6,0),
			'980121' => array('9801216300152005',6,0)
		);
	}
	
	function ujdonsagok2013(){
		if(hun()){
			$lap = $this->mpages->get_row(752);
			$data['title'] ='ARCHLine.XP 2013 Újdonságok';
			$data['csik'] = array('home','2013 Újdonságok');
		}else{
			$lap = $this->mpages->get_row(753);
			$data['title'] ='ARCHLine.XP 2013 New features';
			$data['csik'] = array('home','ARCHLine.XP 2013 New features');
		}
		
		$data['style'] = array('fancybox2');
		$data['javascript'] = array('fancybox/jquery-1.3.2.min','fancybox/jquery.easing.1.3','fancybox/jquery.fancybox-1.2.1.pack','fancybox/fancy');
		$data['tartalom'] = 'other/ujdonsagok2013';
		$data['oldal'] = $lap;
		
		$this->load->view('site',$data);
	}
	
	function ujdonsagok2014(){
		if(hun()){
			$lap = $this->mpages->get_row(848);
			$data['title'] ='ARCHLine.XP 2014 Újdonságok';
			$data['csik'] = array('home','2014 Újdonságok');
		}else{
			$lap = $this->mpages->get_row(849);
			$data['title'] ='ARCHLine.XP 2014 New features';
			$data['csik'] = array('home','ARCHLine.XP 2014 New features');
		}
		
		$data['style'] = array('fancybox2');
		$data['javascript'] = array('fancybox/jquery.easing.1.3','fancybox/jquery.fancybox-1.2.1.pack','fancybox/fancy');
		$data['tartalom'] = 'other/ujdonsagok2013';
		$data['oldal'] = $lap;
		
		$this->load->view('site',$data);
	}
	
		function kbb(){
		if(hun()){
			$lap = $this->mpages->get_row(872);
			$data['title'] ='Konyha és tárolóbútorok';
			$data['csik'] = array('home','Konyha és tárolóbútorok');
		}else{
			$lap = $this->mpages->get_row(874);
			$data['title'] ='Kitchen Bathroom Bedroom';
			$data['csik'] = array('home','Kitchen Bathroom Bedroom');
		}
		
		$data['style'] = array('fancybox2');
		$data['javascript'] = array('fancybox/jquery.easing.1.3','fancybox/jquery.fancybox-1.2.1.pack','fancybox/fancy');
		$data['tartalom'] = 'other/ujdonsagok2013';
		$data['oldal'] = $lap;
		
		$this->load->view('site',$data);
	}
	
			function kitchen(){
		if(hun()){
			$lap = $this->mpages->get_row(864);
			$data['title'] ='Konyha';
			$data['csik'] = array('home','Konyha');
		}else{
			$lap = $this->mpages->get_row(865);
			$data['title'] ='Kitchen';
			$data['csik'] = array('home','Kitchen');
		}
		
		$data['style'] = array('fancybox2');
		$data['javascript'] = array('fancybox/jquery.easing.1.3','fancybox/jquery.fancybox-1.2.1.pack','fancybox/fancy');
		$data['tartalom'] = 'other/ujdonsagok2013';
		$data['oldal'] = $lap;
		
		$this->load->view('site',$data);
	}
	
	function nsinteriors(){
		$data['javascript'] = array(
					'jquery.mousewheel.min',
					
					'fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack',
					
				);
				
		$data['style'] = array(
					
					'../js/fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4v2'
				);
		
		$data['title'] = "ARCHLine.XP, NS interiors: Press release";
		
		$data['page']  = $this->mpages->get_row(708);
		
		$data['tartalom'] = 'other/nsinteriors';
		
		$this->load->view('site', $data);
	
	}
	
	function designbydeborah(){
		
		$data['title'] = "Deborah Heath, Design By Deborah";
		
		$data['page']  = $this->mpages->get_row(847);
		
		$data['tartalom'] = 'other/designbydeborah';
		
		$this->load->view('site', $data);
	
	}
	
	function ilariacoppola(){
		$data['javascript'] = array(
					'jquery.mousewheel.min',
					
					'fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack',
					
				);
				
		$data['style'] = array(
					
					'../js/fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4v2'
				);
		
		$data['title'] = "ARCHLine.XP, Introducing Ilaria Coppola";
		
		$data['page']  = $this->mpages->get_row(839);
		
		$data['tartalom'] = 'other/ilariacoppola';
		
		$this->load->view('site', $data);
	
	}
	
	function farsanglaszlo(){
		$data['javascript'] = array(
					'jquery.mousewheel.min',
					
					'fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack',
					
				);
				
		$data['style'] = array(
					
					'../js/fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4v2'
				);
		
		$data['title'] = "ARCHLine.XP, A zalapáti templom felújítása - Farsang László építész tervei alapján";
		
		$data['page']  = $this->mpages->get_row(845);
		
		$data['tartalom'] = 'other/farsanglaszlo';
		
		$this->load->view('site', $data);
	
	}
	
	function farsanglaszlo_eng(){
		$data['javascript'] = array(
					'jquery.mousewheel.min',
					
					'fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack',
					
				);
				
		$data['style'] = array(
					
					'../js/fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4v2'
				);
		
		$data['title'] = "ARCHLine.XP, A zalapáti templom felújítása - Farsang László építész tervei alapján";
		
		$data['page']  = $this->mpages->get_row(846);
		
		$data['tartalom'] = 'other/farsanglaszlo';
		
		$this->load->view('site', $data);
	
	}
	
	function nsinteriorsawards(){
		$data['javascript'] = array(
					'jquery.mousewheel.min',
					'fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack',
				);
				
		$data['style'] = array(
					'../js/fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4v2'
				);
		
		$data['title'] = "NSInteriors win Prestigious International Property Awards";
		
		$data['page']  = $this->mpages->get_row(734);
		
		$data['tartalom'] = 'other/nsinteriorsawards';
		
		$this->load->view('site', $data);
	
	}
	
	function freeapp(){
		$data['title'] = "ARCHLine View App free";
		
		$data['tartalom'] = 'other/freeapp';
		
		$this->load->view('site', $data);
	}
	
	
	// ez csak teszt
	function archlineklub(){
		$this->load->library('dateclass');
		
		$anyagkezeles = new stdClass();
			$anyagkezeles->cim = "ARCHLine Klub: Anyagok, textúrák kezelése";
			$anyagkezeles->pdf = "AL_Klub_Anyagok.pdf";
		$burkolatkiosztas = new stdClass();
			$burkolatkiosztas->cim = "ARCHLine Klub: Burkolatkiosztás";
			$burkolatkiosztas->pdf = "AL_Klub_Burkolas.pdf";
		$objektumkezeles = new stdClass();
			$objektumkezeles->cim = "ARCHLine Klub: Objektumkezelés";
			$objektumkezeles->pdf = "AL_Klub_Objektumok.pdf";
		$fenykezeles = new stdClass();
			$fenykezeles->cim = "ARCHLine Klub: Fénykezelés";
			$fenykezeles->pdf = "AL_Klub_Fenykezeles.pdf";
		$dokumentacio = new stdClass();
			$dokumentacio->cim = "ARCHLine Klub: Dokumentáció készítés";
			$dokumentacio->pdf = "AL_Klub_Dokumentacio_keszites.pdf";
		$karpitozottbutorok = new stdClass();
			$karpitozottbutorok->cim = "ARCHLine Klub: Kárpitozott bútorok tervezése";
			$karpitozottbutorok->pdf = "AL_Klub_Butortervezo.pdf";
		$a3D_elemek = new stdClass();
			$a3D_elemek->cim = "ARCHLine Klub: Egyedi 3D elemek készítése";
		$animacio = new stdClass();
			$animacio->cim = "ARCHLine Klub: Animáció készítése";
		
		$temak = array(
			'anyagkezeles'     => $anyagkezeles,
			'burkolatkiosztas' => $burkolatkiosztas,
			'objektumkezeles'  => $objektumkezeles,
			'fenykezeles'      => $fenykezeles,
			'dokumentacio'     => $dokumentacio,
			'karpitozottbutorok' => $karpitozottbutorok,
			'3D_elemek'        => $a3D_elemek,
			'animacio'         => $animacio
		);
		$data['temak']   = $temak;
		
		
		$archlineklubesem = $this->cache->get('archline-klub-idopontok');
		
		if( !$archlineklubesem ){
		
			$this->load->model('mevents');
			
			$data['event'] = $this->db->query("SELECT * FROM events_new_main WHERE event_main_id = 56 ")->row();
			
			if( $data['event'] ){
				$data['dates'] = $this->db->query("SELECT * FROM events_new WHERE event_main_id = 56 AND start_ts > ".time()." AND (online IS NULL OR online = '0') AND active = 1 AND deleted = 0 ORDER BY start_ts")->result();
				
				$results = $this->mevents->getEventDatesByDay($data['event']->event_main_id, true);
				$data['dates']->events = $results['events'];
				$data['dates']->times = $results['times'];
				foreach($data['dates'] as $date){
					$date->times->able_to_reg = $this->mevents->checkEventLimit($date->event_id);
				}
			}
			
			$this->cache->write($data['dates'], 'archline-klub-idopontok', (3600*24));	//naponta frissül, ha nincs jelentkező
			
		}else{
			$data['dates'] = $archlineklubesem;
		}
		
		$data['page'] = $this->mpages->get_row(745);
		
		
		$data['style']    = array('workshop_min');
		$data['title']    = "ARCHLine Klub információk és jelentkezés";
		$data['tartalom'] = 'other/archlineklubteszt';
		$this->load->view('site', $data);
	}
	
	function checkrequirements(){
		$data['tartalom'] = 'other/checkrequirements';
			$this->load->view('site', $data);
	}
	
	// ez a tényleges ARCHLine Klub / ARCHLine Evening
	function archlineklub2(){
		$this->load->library('dateclass');
		
		$nyelv = hun() ? 'hun' : 'eng';
		$mainid = hun() ? 56 : 63;
		
		$temakres = $this->db->query("SELECT * FROM archline_klub WHERE nyelv='{$nyelv}'")->result();
		$temak = array();
		foreach($temakres as $tema){
			$temak[$tema->url] = $tema;
		}
		
		if($this->uri->rsegment(3)!=""){
			$valtema         = $this->uri->segment(2);
			$data['temacim'] = $temak[$valtema]->cim;
			$data['page']    = $this->mpages->get_row($temak[$valtema]->page);
			if($data['page']===false)
				header("HTTP/1.1 404 Not Found");
			
			
			
			if($temak[$valtema]->pdf!="" && file_exists("public/downloads/hun/archlineklub/".$temak[$valtema]->pdf)){
				$csere .= "<a href='/public/downloads/hun/archlineklub/{$temak[$valtema]->pdf}' class='pdfbutton'><b>".lang('al-klub-jegyzletolt')."</b></a><br />";
				
				$data['page']->page_body = str_ireplace('#pdf#', $csere, $data['page']->page_body);
			}
			
			$metadesc = trim(str_replace("\n"," ",substr(($str=wordwrap(strip_tags($data['page']->page_body),140,'$$')),0,strpos($str,'$$'))." ..."));
			
			$dateformat = hun() ? "%Y. %m. %d" : "%d. %m. %Y";
			
			$korabbiak = $this->db->query("SELECT DATE_FORMAT(FROM_UNIXTIME(start_ts),'{$dateformat}') datum FROM `events_new` WHERE event_main_id={$mainid} AND location='{$valtema}' AND deleted=0 AND start_ts<".time())->result();
			$kesobbiek = $this->db->query("SELECT start_ts, end_ts FROM `events_new` WHERE event_main_id={$mainid} AND location='{$valtema}' AND deleted=0 AND active=1 AND start_ts>".time())->result();
			$hetnapok = lang('napok');
			foreach($kesobbiek as $datum){
				$ennyiedik = date('N',$datum->start_ts);
				$hetnap    = $hetnapok[($ennyiedik-1)];
				if(hun())
					$datum->datum = date('Y. m. d.',$datum->start_ts)." ({$hetnap}) ".date('H:i',$datum->start_ts)." - ".date('H:i',$datum->end_ts);
				else
					$datum->datum = date('d. m. Y.',$datum->start_ts)." ({$hetnap}) ".date('H:i',$datum->start_ts)." - ".date('H:i',$datum->end_ts);
			}
			
			$data['korabbiak']    = $korabbiak;
			$data['kesobbiek']    = $kesobbiek;
			$data['meta']['desc'] = $metadesc;
			$data['title']        = $data['page']->page_title;
			$data['tartalom']     = 'other/archlineklub_leiras_adatbazisbol';
			$this->load->view('site', $data);
			return;
		}
		
		$klubtemak = $this->db->query("SELECT url, menu_cim FROM archline_klub WHERE nyelv='{$nyelv}' AND aktiv=1 AND sorsz>0 ORDER BY sorsz DESC")->result();
		$data['klubtemak'] = $klubtemak;

		$archlineklubesem = $this->cache->get('archline-klub-idopontok-'.$nyelv);


		if( !$archlineklubesem ){
		
			$this->load->model('mevents');
			
			$data['event'] = $this->db->query("SELECT * FROM events_new_main WHERE event_main_id = {$mainid} ")->row();
			
			if( $data['event'] ){
				$data['dates'] = $this->db->query("SELECT * FROM events_new WHERE event_main_id = {$mainid} AND start_ts > ".time()." AND (online IS NULL OR online = '0') AND active = 1 AND deleted = 0 ORDER BY start_ts")->result();
				
				$results = $this->mevents->getEventDatesByDay($data['event']->event_main_id, true);

				$data['dates']->events = $results['events'];
				$data['dates']->times = $results['times'];
				foreach($data['dates'] as $date){
					$date->times->able_to_reg = $this->mevents->checkEventLimit($date->event_id);
				}
			}
			
			$this->cache->write($data['dates'], 'archline-klub-idopontok-'.$nyelv, (3600*24));	//naponta frissül, ha nincs jelentkező
			
		}else{
			$data['dates'] = $archlineklubesem;
		}
		
		$data['page'] = hun() ? $this->mpages->get_row(745) : $this->mpages->get_row(835);
		$data['conditions'] = hun() ? $this->mpages->get_row(858) : $this->mpages->get_row(857);
		
		
		$data['eventid']  = $mainid;
		$data['style']    = array('workshop_min');
		$data['title']    = hun() ? "ARCHLine Klub információk és jelentkezés" : "ARCHLine Evenings";
		$data['tartalom'] = 'other/archlineklub2';
		$this->load->view('site', $data);
	}
	
	
	
	
	function archlineklubadatbazisbol(){
		$this->load->library('dateclass');
		
		$temakres = $this->db->query("SELECT * FROM archline_klub")->result();
		$temak = array();
		foreach($temakres as $tema){
			$temak[$tema->url] = $tema;
		}
		
		
		if($this->uri->rsegment(3)!=""){
			$valtema         = $this->uri->segment(3); // $this->uri->segment(2);
			$data['temacim'] = $temak[$valtema]->cim;
			$data['page']    = $this->mpages->get_row($temak[$valtema]->page);
			if($data['page']===false)
				header("HTTP/1.1 404 Not Found");
			
			
			
			if($temak[$valtema]->pdf!="" && file_exists("public/downloads/hun/archlineklub/".$temak[$valtema]->pdf)){
				$csere .= "<a href='/public/downloads/hun/archlineklub/{$temak[$valtema]->pdf}' class='pdfbutton'><b>".lang('al-klub-jegyzletolt')."</b></a><br />";
				
				$data['page']->page_body = str_ireplace('#pdf#', $csere, $data['page']->page_body);
			}
			
			
			
			$korabbiak = $this->db->query("SELECT DATE_FORMAT(FROM_UNIXTIME(start_ts),'%Y. %m. %d') datum FROM `events_new` WHERE event_main_id=56 AND location='{$valtema}' AND deleted=0 AND start_ts<".time())->result();
			$kesobbiek = $this->db->query("SELECT start_ts, end_ts FROM `events_new` WHERE event_main_id=56 AND location='{$valtema}' AND deleted=0 AND active=1 AND start_ts>".time())->result();
			$hetnapok = lang('napok');
			foreach($kesobbiek as $datum){
				$ennyiedik = date('N',$datum->start_ts);
				$hetnap    = $hetnapok[($ennyiedik-1)];
				$datum->datum = date('Y. m. d.',$datum->start_ts)." ({$hetnap}) ".date('H:i',$datum->start_ts)." - ".date('H:i',$datum->end_ts);
			}
			$data['korabbiak'] = $korabbiak;
			$data['kesobbiek'] = $kesobbiek;
			$data['title']    = $data['page']->page_title;
			$data['tartalom'] = 'other/archlineklub_leiras_adatbazisbol';
			$this->load->view('site', $data);
			return;
		}
		
		$archlineklubesem = $this->cache->get('archline-klub-idopontok');
		
		if( !$archlineklubesem ){
		
			$this->load->model('mevents');
			
			$data['event'] = $this->db->query("SELECT * FROM events_new_main WHERE event_main_id = 56 ")->row();
			
			if( $data['event'] ){
				$data['dates'] = $this->db->query("SELECT * FROM events_new WHERE event_main_id = 56 AND start_ts > ".time()." AND (online IS NULL OR online = '0') AND active = 1 AND deleted = 0 ORDER BY start_ts")->result();
				
				$results = $this->mevents->getEventDatesByDay($data['event']->event_main_id, true);
				$data['dates']->events = $results['events'];
				$data['dates']->times = $results['times'];
				foreach($data['dates'] as $date){
					$date->times->able_to_reg = $this->mevents->checkEventLimit($date->event_id);
				}
			}
			
			//naponta automatikusan frissül ( + minden jelentkezés után)
			$this->cache->write($data['dates'], 'archline-klub-idopontok', (3600*24));
			
		}else{
			$data['dates'] = $archlineklubesem;
		}
		
		$data['page'] = $this->mpages->get_row(745);
		
		
		$data['style']    = array('workshop_min');
		$data['title']    = "ARCHLine Klub információk és jelentkezés";
		$data['tartalom'] = 'other/archlineklub2';
		$this->load->view('site', $data);
	}
	
	
	
	
	function construmaakcio(){
		$data['page'] = $this->mpages->get_row(782);
		
		$data['style']    = array('workshop_min');
		$data['title']    = "ARCHLine.XP akció: 2 program 1 áráért";
		$data['tartalom'] = 'other/construmaakcio';
		$this->load->view('site', $data);
	}
	
	function construmaakcioreg(){
		foreach($_POST as $k=>$v)
			$$k = $v;
		
		if($url){
			$record->osztaly = "other";
			$record->fv   = "construmaakcioreg";
			$record->hiba = "Robot? Új levél:";
			$record->hiba .= print_r($_POST,true);
			$record->datum = date('Y-m-d H:i:s',time());
			$this->db->insert('a_hibak',$record);
			$this->load->view('site',$data);
			return;
		}
		
		$mail_data = array(
			'name' => $nev,
			'company' => $company,
			'address' => $address,
			'phone' => $tel,
			'email' => $email,
			'subject' => $subject,
			'message' => $message
		);
		
		$this->load->library('email');
		$this->email->initialize();
		
		$this->email->message($this->load->view('mail/contact', $mail_data, true));
		
		$lang = "hun";
		$this->email->from('info@cadline.hu', 'CadLine Weboldal');
		$this->email->subject('Construma akció - jelentkezés');
		$this->email->send('info@cadline.hu', 'smtp');
		
		
	//	$this->email->send("eszter@cadline.hu", 'smtp');
		
		// Esemeny felvetele
		$this->load->model('mclusers');
		$nUserID = $this->mclusers->get_nUserIDByEmail($email,$lang);
		$message = preg_replace("/ő/", "&#337;", $message);
		$message = preg_replace("/ű/", "&#369;", $message);
		
		
		// ha nem volt vagy nem egyertelmu, akkor felvenni
		if( !$nUserID ){
			$tomb['strName'] = $nev;
			$tomb['strCompany'] = $company;
			$tomb['strTel'] = $tomb['strTel'] = $tel;
			$tomb['strEMail'] = $email;
			$tomb['strCity'] = $address;
			
			$tomb2['email'] = $email;
			
			$nUserID = $this->mclusers->addUserHun($tomb);
			$tomb2['nUserID'] = $nUserID;
			$this->mclusers->addUserEmailHun($tomb2);
		}
		
		$infotext = '"'.preg_replace("/<.+>/Usi", "", $message).'"';
		$infotext .= ", tel: ".$tel;
		
		$this->mclusers->addEvent($nUserID, 16, $infotext);
		
		$record->osztaly = "other";
		$record->fv    = "construmaakcioreg";
		$record->hiba  = "Új akció regisztráció: ".$message.",\n".$nev.",\n".$email;
		$record->datum = date('Y-m-d H:i:s',time());
		$this->db->insert('a_hibak',$record);
		
		$data['title']    = 'ARCHLine.XP akció';
		$data['tartalom'] = 'forum/kiir';
		$data['csik']=array('home','contact');
		
		$data['info'] = "<div style='text-align: center; font-size: 1.3em;'>Kérését rögzítettük.</div>";
		
		$this->load->view('site',$data);
	}
	
	
	// Viewerből törli a régi képeket. Minden nap 5-kor fut le.
	function viewerlejartaktorlese(){
		$timereguser = (60*60*24*30*6); //~6 hónap
		$timeguest   = (60*60*24*30*3); //~3 hónap
		$path        = 'public/img/collection/users/';
		$guests      = $path.'guest/';
		$trash       = 'public/img/collection/users/trash/';
		$now         = time();
		$elofizetokt = $this->db->query("SELECT user_id FROM forum_user WHERE viewsub=1")->result();
		$elofizetok  = array();
		foreach($elofizetokt as $elof){ $elofizetok[] = $elof->user_id; }
		$kiirni      = "";
		$log         = "\n".date('Y-m-d H:i',$now).":";
		$kivetelekt  = $this->db->query("SELECT mappa FROM collection_projects WHERE autodel=0")->result();
		$kivetelek   = array();
		foreach($kivetelekt as $kiv){
			$guestuser = current(explode("/",$kiv->mappa));
			if(!in_array($guestuser,$kivetelek))
				$kivetelek[] = $guestuser;
		}
		
	/*	$kivetelek   = array(
				'cadline',
				'antonio-perrone',
				'bea-antonin',
				'krisztina-harosi',
				'mood-board',
				'nicholas-sunderland',
				'patricia-dowling',
				'progeo',
				'sarah-buxton',
				'sas-ezekiel',
				'susan-brown'
		);*/
		
		// vendég userek utáni takarítás - projekt dátumát nézi
		$usermappak = scandir($guests);
		unset($usermappak[0],$usermappak[1]);	// . és .. törlése
		foreach($usermappak as $user){
			if(in_array($user,$kivetelek)){ $kiirni .= "\n<br />Kivetel: {$user}"; continue; }
			
			$userprojektekpath = $guests.$user."/";
			$userprojektek = scandir($userprojektekpath);
			unset($userprojektek[0],$userprojektek[1]);
			foreach($userprojektek as $projekt){
				$datumElemDir = filemtime($userprojektekpath.$projekt);
				$kiirni .= "\n<br>Datum {$projekt}:".date('Y-m-d H:i',$datumElemDir);
				
				if( !in_array($user,$kivetelek) && (($now-$timeguest) > $datumElemDir) ){
					mkdir("{$trash}guest/{$user}");
					mkdir("{$trash}guest/{$user}/".$projekt);
					exec("cp -R {$userprojektekpath}{$projekt} {$trash}guest/{$user}");
					exec("rm -R {$userprojektekpath}{$projekt}");
					$log .= "\nDeleted guest: ".$userprojektekpath.$projekt;
					$kiirni .= "\n <b style='color: red;'>toroltem:</b> {$userprojektekpath}{$projekt}";
					$tomb['deleted']=1;
					$this->db->update('collection_projects',$tomb,"userid='guest' AND mappa='{$user}/{$projekt}'");
				}
			}
		}
		
		// fórumos userek utáni takarítás - projekt dátumát nézi
		$usermappak = scandir($path);
		unset($usermappak[0],$usermappak[1]);
		$kiirni .= "\n\n\n<br /><br /><br />";
		foreach($usermappak as $user){
			if(!is_numeric($user)){ continue; }			// 'guest' mappát ne bántsa
			if(in_array($user,$elofizetok)){ $kiirni .= "\n<br />itt NEM nezem: {$user}"; continue; }	// akinek van előfizetése azt se törölje
			
			$userprojektekpath = $path.$user."/";
			$userprojektek = scandir($userprojektekpath);
			unset($userprojektek[0],$userprojektek[1]);
			foreach($userprojektek as $projekt){
				$datumElemDir = filemtime($userprojektekpath.$projekt);
				$kiirni .= "\n<br>Datum {$projekt}:".date('Y-m-d H:i',$datumElemDir);
				
				if( !in_array($user,$elofizetok) && (($now-$timereguser) > $datumElemDir) ){
					mkdir($trash.$user);
					mkdir($trash.$user."/".$projekt);
					exec("cp -R {$userprojektekpath}{$projekt} {$trash}{$user}");
					exec("chmod 777 -R {$trash}{$user}");
					exec("rm -R {$userprojektekpath}{$projekt}");
					$log .= "\nDeleted user: ".$userprojektekpath.$projekt;
					$tomb['deleted']=1;
					$this->db->update('collection_projects',$tomb,"userid={$user} AND mappa='{$projekt}'");
					$kiirni .= "\n <b style='color: red;'>toroltem:</b> {$userprojektekpath}{$projekt}";
				}
			}
		}
		
	//	$kiirni = "A lényeg még kommentben van";
		if(!$kiirni) $kiirni .= "Nem törölt semmit.";
		if(strlen($log)<20) $log .= " Nincs torles.";
		exec("echo '{$log}' >> public/img/collection/users/log.txt");
		
		/*$record['osztaly'] = "temp";
		$record['fv'] = "viewerlejartaktorlese";
		$record['hiba'] = strip_tags($kiirni);
		$record['datum'] = date('Y-m-d H:i',time());
		$this->db->insert('a_hibak',$record);*/
		print $kiirni;
		
	}
	
	
	function crash(){
		$hova = "public/crash/";
		$guid = $this->uri->segment(2);
		$error = false;
		
		$honnan = "/home/vendeg/crash/".$guid;
		$ide    = $hova.$guid;
		$p = "cp {$honnan}.* {$hova}";
		exec($p);
		$info = "";
		//print "parancs: ".$p." ; ";
		
		if($this->uri->segment(3)!="")
			$info = "build: ".$this->uri->segment(3);
		
		if(!file_exists($hova.$guid.".DMP") || !file_exists($hova.$guid.".TXT") ){
			$info = "Hiányzó fájlok! ";
			$error = true;
		}
		
		
		$crash = new stdClass();
		$crash->guid  = $guid;
		$crash->info  = $info;
		$crash->datum = date('Y-m-d H:i:s',time());
		if($guid!="DE304C60-F00D-40B8-A7FE-15037EC2F318" && $guid!="00EC8C3A-0FC6-7E4E-9817-C0A03FC42D70")
			$this->db->insert('crash',$crash);
		
		/*if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2)=="hu")
			$this->muser->user['lang']="hun";
		else
			$this->muser->user['lang']="eng";*/
		
		
		if(hun())
			$data['emailmegadas'] = $this->mpages->get_row(798);
		else
			$data['emailmegadas'] = $this->mpages->get_row(797);
		
		$data['guid']  = $guid;
		$data['id']    = mysql_insert_id();
		$data['error'] = $error;
		$this->load->view('other/crashform', $data);
			
		
	//	print "ok";
	}
	
	function crashformsubmit(){
		$guid = $this->input->post("guid");
		$info = mysql_escape_string($this->input->post("info"));
		$id   = $this->input->post("id");
		$mail = $this->input->post("email");
		
		$crash = $this->db->query("UPDATE `cadline2`.`crash` SET info=CONCAT(info,'{$info}'), email='{$mail}' WHERE `crash`.`guid`='{$guid}' AND `crash`.`deleted`=0");
		
		$page = $this->mpages->get_row(796);
		//print "thank you";
		print $page->page_body;
	}
	
	
	function crashlog(){
		$dir    = "public/crash/";
		$now    = time();
		$nap    = 60*60*24;
		$log    = "";
		$fajlok = scandir("public/crash/");
		unset($fajlok[0],$fajlok[1]);
		unset($userprojektek[0],$userprojektek[1]);
		foreach($fajlok as $fajl){
			$datumElem = filemtime($dir.$fajl);
			$kiirni .= "\n<br>Datum {$projekt}:".date('Y-m-d H:i',$datumElem);
			
			if( ($now-$nap) > $datumElem ){
				$log .= "\nÚj elem: ".$fajl;
			}
		}
		
	//	exec('echo "Új elszállások: '.$log.'" | mail -s "ARCHLine crash" -c bodnart@invitel.hu bodnart@cadline.hu');
		
	}
	
	
	
	/*
	Szeretnek egy uj oldalt http://www.archlinexp.com/registeronce
	[9:38:45] Tóth Zoltán: neven amivel egy uj bejegyzes jonne letre a Forumban (lenne angol/magyar) es a download mintajara lemenne egy ellenorzo level az email cim ellenorzesre
	[9:39:27] Tóth Zoltán: majd ha az helyes akkor a 2. levelben megkapna a download linke es a sajat 99 kezdodo 16 jegyu sorozatszamat
	[9:39:41] Tóth Zoltán: ami PRofessional valtozat lenne
	[9:41:49] Tóth Zoltán: A plusz az lenne hogy az ARCHLine ID - nek nevezett mezot le kell ellenorizni, hogy ket regisztracio ne tortenhessen egy sorozatszmra
	-- reg után hozzárendelni a felhasználóhoz a kulcsot a kék/sárga könyben.
	*/
	function registeronce(){
    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('registeronce');
		}
		$this->load->model('mctr');
		
		$data['ctr'] = hun() ? $this->mctr->get_all_ctr('ctrNameHun') : $this->mctr->get_all_ctr();
		
		if(hun())
		    $data['cimlap'] = $this->mpages->get_row(291);
		else
			$data['cimlap'] = $this->mpages->get_row(630);
		
		if(isset($_SESSION['default']['regonceadatok'])){
			$data['reonad'] = explode("#",$_SESSION['default']['regonceadatok']);
			unset($_SESSION['default']['regonceadatok']);
		}
		$data['noindex']    = true;
		$data['title']      = hun() ? 'ARCHLine.XP Regisztráció' : 'ARCHLine.XP Register';
		$data['javascript'] = array('regformcheck');
		$data['tartalom']   = 'other/registeronce';
		
		$this->load->view('site',$data);
	}
	
	function registeroncedealer(){
		$this->registeronce();
		return;
	}
	
	function registeroncesubmit(){
		
		$ip     = $_SERVER['REMOTE_ADDR'];
		$archid = substr($this->input->post("id"),0,6);
		$id_check = $this->input->post("id");
		$email  = $this->input->post("strEMail");
		
		$tomb['arch_id'] = $id_check;
		$tomb['nev']     = $this->input->post("strName1").' '.$this->input->post("strName2");
		$tomb['email']   = $email;
		$tomb['orszag']  = $this->input->post("ctrName");
		$tomb['telefon'] = $this->input->post("strTel");
		$tomb['jelszo']  = md5($this->input->post("passw1"));
		$tomb['kod']     = md5($this->input->post("id").$email.time()."AsDf");
		$tomb['datum']   = date('Y-m-d H:i:s');
		$tomb['ip']      = $ip;
		$tomb['info_json'] = json_encode($_POST);
		if(!$this->input->post('dealer'))
			$tomb['info']    = "subject: ".$this->input->post("tema")." \n".$this->input->post("uzenet");
		else
			$tomb['info']    = "dealer:".$this->input->post("email2");
		
		$tomb2 = $tomb;
		$tomb2["uzenet"] = $this->input->post("uzenet");
		
		if( !$archid || 
			!$email || 
			(substr($archid,0,2)!="99" && !array_key_exists(substr($archid,0,6),$this->kulcsprverzio)) || 
			$this->_archlineID($archid)!=$id_check
		){
			if( !$archid ) print "nincs archid: ".$archid;
			if( !$email )  print "nincs email: ".$email;
			if(substr($archid,0,2)!="99" && !array_key_exists(substr($archid,0,6),$this->kulcsprverzio)) print "komplikalt: ".$archid;
			if( $this->_archlineID($archid)!=$id_check ) print "hibas id: ".$archid." ".$this->_archlineID($archid)." ".$id_check." . ";
			return;
			
			$this->phpsession->save('regoncehiba',"Missing or invalid data!");
			unset($tomb2['jelszo'],$tomb2['kod'],$tomb2['datum'],$tomb2['info'],$tomb2['ip']);
			$this->phpsession->save('regonceadatok',implode("#",$tomb2));
			redirect("registeronce");
			return;
		}
		
		$query = $this->db->where('arch_id', $archid)->limit(1)->get('t_registeronce');
		$result = $query->result_array();
		
		
		// 24 órán belül egy ip-ről csak egyszer
		if(!$this->input->post('dealer')){
			$mikortol = date("Y-m-d H:i:s",time() - 60*60*24);
			$volte = $this->db->query("SELECT r_id FROM t_registeronce WHERE ip='{$ip}' AND datum>'{$mikortol}'")->result();
			if(count($volte)>0){
				$this->phpsession->save('regoncehiba',lang("regtobbreg"));
				unset($tomb2['jelszo'],$tomb2['kod'],$tomb2['datum'],$tomb2['info'],$tomb2['ip']);
				$this->phpsession->save('regonceadatok',implode("#",$tomb2));
				redirect("registeronce");
				return;
			}
		}
		
		
		// egy ID-t csak egyszer
		if( !empty($result) ){
			$this->phpsession->save('regoncehiba',"ID: {$archid} already registered!");
			unset($tomb2['jelszo'],$tomb2['kod'],$tomb2['datum'],$tomb2['info'],$tomb2['ip']);
			$this->phpsession->save('regonceadatok',implode("#",$tomb2));
			redirect("registeronce");
			return;
		}
		
		
		
		// ha benne van a fórumban akkor se regisztrálom ..
		/*$query2 = $this->db->where("login='{$email}' OR email='{$email}'")->limit(1)->get('forum_user');
		$result2 = $query2->result_array();
		if( !empty($result2) ){
			$this->phpsession->save('regoncehiba',"Warning: the login {$email} is already registered!");
			unset($tomb2['jelszo'],$tomb2['kod'],$tomb2['datum'],$tomb2['info']);
			$this->phpsession->save('regonceadatok',implode("#",$tomb2));
			redirect("registeronce");
			return;
		}*/
		
		// temp táblába elmenteni
		
		$tomb['arch_id']  = $archid;
		$tomb['id_check'] = $id_check;
		$this->db->insert('t_registeronce',$tomb);
		
		$this->load->library('email');
		$this->email->initialize();
		$this->email->addOfficialImages();
		
		$mail_vars['first'] = $this->muser->string_to_code($this->input->post('first'));
		$mail_vars['email'] = $email;
		//$mail_vars['confirm_link'] = 'http://www.archlinexp.com/other/registeronceconfirm/'.$archid.'/'.$tomb['kod'];
		$mail_vars['confirm_link'] = 'http://old.archlinexp.com/other/registeronceconfirm/'.$archid.'/'.$tomb['kod'];
		
		$this->email->setFrom('info@archlinexp.com', 'CadLine');
		if(hun()){
			$mail_vars['confirm_link'] = 'http://www.archline.hu/other/registeronceconfirm/'.$archid.'/'.$tomb['kod'];
			$mail_vars['mailcontent'] = 'mail/confirm_dl_hun';
		}else{
			//$mail_vars['confirm_link'] = 'http://www.archlinexp.com/other/registeronceconfirm/'.$archid.'/'.$tomb['kod'];
			$mail_vars['confirm_link'] = 'http://old.archlinexp.com/other/registeronceconfirm/'.$archid.'/'.$tomb['kod'];
			$mail_vars['mailcontent'] = 'mail/confirm_dl_eng';
		}
		$this->email->subject('ARCHLine.XP Register');
		$this->email->message($this->load->view('mail',$mail_vars,true));
		
		if(!$this->input->post('dealer')){
			$this->email->send($email,'smtp');
			redirect('downloads/sentconf');
		}else{
			/*$email2 = $this->input->post('email2');
			$this->email->send($email2,'smtp');*/
			header("Location: ".$mail_vars['confirm_link']); exit;
		}
		
		redirect('downloads/sentconf');
	//	redirect('page/show/registrationok');
		
	}
	
	function registeronceconfirm(){
		$this->load->model('mclusers');
		$arch_id = $this->uri->segment(3);
		$kod     = $this->uri->segment(4);
		$datum   = date("Y-m-d");
		$kekorszag = array(7,"07",30,31,32,33,34,36,38,39,40,41,42,43,48,49,52,81,82,88,91);
		$sargaorszag = array(0,"01",1,"02",2,44,61);
		$nyelv   = "eng";
		
		$query = $this->db->where('kod', $kod)->where('torolve', 0)->limit(1)->get('t_registeronce');
		$result = $query->result_array();
		$result = $result[0];
		$email = $result['email'];
		
		$szemadatok = json_decode($result['info_json']);
		$countries  = array();
		$orszagok   = $this->db->query('SELECT * FROM `'.CRMADATBAZIS.'`.`countries`')->result_array();
		foreach( $orszagok as $orszag )
			$countries[$orszag['ctrID']] = hun() ? strtolower($orszag['ctrName']) : strtolower($orszag['ctrNameEng']);
		
		
		if(empty($result) || $result['arch_id']!=$arch_id ){
			$data['title'] = hun() ? 'ARCHLine.XP Regisztráció - Hiba' : 'ARCHLine.XP Register - Error';
			$data['tartalom'] = 'error/mail_temp_notexists';
			$data['lang'] = $this->muser->user['lang'];
			$this->load->view('site', $data);
			return;
		}
		
		
		// fórumba, adatbázisba kerüljön be?? melyik adatbázisba?
		
		// kulcsot lekérni
		$adatbazis = "clusers";
		if(UJUGYFELKEZELO===true){
			$adatbazis = CRMADATBAZIS;
			$kulcs = $this->db->query("SELECT * FROM {$adatbazis}.hardlock WHERE hlNum='".$result['arch_id']."'")->row();
		}
		else
			$kulcs = $this->db->query("SELECT * FROM {$adatbazis}.cl_fo_hardlock WHERE hlNum='".$result['arch_id']."'")->row();
		
		if(!$kulcs || in_array($kulcs->hlCtrID,$sargaorszag)){
			$adatbazis = "clusers_eng";
			if(UJUGYFELKEZELO===true){
				$adatbazis = CRMADATBAZIS;
				$kulcs = $this->db->query("SELECT * FROM {$adatbazis}.hardlock WHERE hlNum='".$result['arch_id']."'")->row();
			}
			else
				$kulcs = $this->db->query("SELECT * FROM {$adatbazis}.cl_fo_hardlock WHERE hlNum='".$result['arch_id']."'")->row();
		}
		
		if(UJUGYFELKEZELO===true)
			$adatbazis = CRMADATBAZIS;
		
		// ha nincs meg a kulcs
		if(!$kulcs){
			$record->osztaly = "other";
			$record->fv = "registeronceconfirm";
			$record->hiba = "A a kulcs nem szerepel az adatbázisokban: ".$result['arch_id'];
			$record->datum = date('Y-m-d H:i:s',time());
			$this->db->insert('a_hibak',$record);
			print "Error: The ID is not in the databases!";
			return;
		}
		
		
		
		// ha van tulajdonos más e-mail címmel, akkor hiba
		$oatulaj = "?";
		if($kulcs->hlUser!="" && is_numeric($kulcs->hlUser) ){
			
			// tulajdonos e-mail címe megegyezik-e a regisztrálóéval
			if(UJUGYFELKEZELO===true)
				$sql01 = "SELECT email FROM {$adatbazis}.u_emails WHERE nUserID=".$kulcs->hlUser;
			else
				$sql01 = "SELECT email FROM {$adatbazis}.cl_users_emails WHERE nUserID=".$kulcs->hlUser;
			$tulajemailek = $this->db->query($sql01)->result();
			$oatulaj = false;
			foreach($tulajemailek as $email01){// print $sql01;
				if( $email01->email == $email ){
					$oatulaj = true;
					break;
				}
			}
		}
		
		if($kulcs->hlUser!="" && $oatulaj === false){
			$record->osztaly = "other";
			$record->fv = "registeronceconfirm";
			$record->hiba = "A kulcsnak már van tulajdonosa: ".$result['arch_id']."\nuj: ".print_r($result,true);
			$record->datum = date('Y-m-d H:i:s',time());
			$this->db->insert('a_hibak',$record);
			//print "Error: a kulcsnak mar van tulajdonosa!";
			if(hun())
				$data['info'] = "Hiba: ennek az ARCHLine ID-nek már van tulajdonosa!";
			else
				$data['info'] = "Error: other have this ARCHLine ID!";
			$data['tartalom']='forum/kiir';
			$this->load->view('site',$data);
			return;
		}
		
		
		// ha magyar, felvenni az adatbázisba, fórumba
		if( $kulcs->hlCtrID=="36" ){
			$nyelv = "hun";
			$nUserID = $this->mclusers->get_nUserIDByEmail($email,'hun');
			$eseminfo = "Weben regisztrálta a 2014 non-profit programot. tel: ".$result['telefon'].", nev: ".$result['nev'];
			if($result['info'])
				$eseminfo .= " \negyéb infó: ".$result['info'];
			
			// kékbe
			if(!$nUserID){
				$ujtomb['strName']   = $result['nev'];
				$ujtomb['strTel']    = $result['telefon'];
				$ujtomb['strEMail']  = $email;
				$ujtomb['strStreet'] = $szemadatok->strStreet;
				$ujtomb['strCity']   = $szemadatok->strCity;
				$ujtomb['strZip']    = $szemadatok->strZip;
				$ujtomb['strCompany']= $szemadatok->strCompany;
				$ujtomb['nUserProf'] = $szemadatok->nUserProf;
				$ujtomb['nCtrID']    = array_search(strtolower($szemadatok->ctrName), $countries);
				if($kulcs->hlUser=="")
					$ujtomb['nUserType'] = 1;
				$nUserID = $this->mclusers->addUserHun($ujtomb);
				
				$tomb2['nUserID'] = $nUserID;
				$tomb2['email']   = $email;
				$this->mclusers->addUserEmailHun($tomb2);
			}else{
				if($kulcs->hlUser==""){
					if(UJUGYFELKEZELO===true)
						$this->db->update($adatbazis.'.users',array('nUserType'=>1),"nUserID=".$nUserID);
					else
						$this->db->update($adatbazis.'.cl_users',array('nUserType'=>1),"nUserID=".$nUserID);
				}
			}
			// kékbe esemény
			if(UJUGYFELKEZELO===true)
				$query = "INSERT INTO `".CRMADATBAZIS."`.`u_history` VALUES (NULL,{$nUserID},116,'{$datum}','web','{$eseminfo}', 36, '', '','','', NULL)";
			else
				$query = "INSERT INTO `clusers`.`cl_history` VALUES (NULL,{$nUserID},167,'{$datum}','web','{$eseminfo}', 0)";
			$this->db->query($query);
			// fórumba
			$query2 = $this->db->where("login='{$email}' OR email='{$email}'")->limit(1)->get('forum_user');
			$result2 = $query2->result_array();
			if( empty($result2) ){
				$ujforum['nUserID'] = $nUserID;
				$ujforum['new_nUserID'] = $nUserID;
				$ujforum['login']   = $email;
				$ujforum['email']   = $email;
				$ujforum['nev']     = $result['nev'];
				$ujforum['jelszo']  = $result['jelszo'];
				$ujforum['rang']    = "user";
				$ujforum['nyelv']   = "hun";
				$this->db->insert('forum_user',$ujforum);
			}
			// userhez a program
			if($kulcs->hlUser==""){
				$ujhl['hlUser'] = $nUserID;
				if(UJUGYFELKEZELO===true)
					$this->db->update($adatbazis.'.hardlock',$ujhl,"hlID=".$kulcs->hlID);
				else
					$this->db->update($adatbazis.'.cl_fo_hardlock',$ujhl,"hlID=".$kulcs->hlID);
			}
		}
		elseif(in_array($kulcs->hlCtrID,$kekorszag)){
			$ujhl['hlUser'] = $result['nev'];
			$ujhl['hlInfo'] = $email;
			if(UJUGYFELKEZELO===true)
				$this->db->update($adatbazis.'.hardlock',$ujhl,"hlID=".$kulcs->hlID);
			else
				$this->db->update($adatbazis.'.cl_fo_hardlock',$ujhl,"hlID=".$kulcs->hlID);
		}
		elseif(in_array($kulcs->hlCtrID,$sargaorszag)){
			$nUserID = $this->mclusers->get_nUserIDByEmail($email,'eng');
			$eseminfo = "Weben regisztrálta a 2013 non-profit programot. tel: ".$result['telefon'].", name: ".$result['nev'];
			if($result['info'])
				$eseminfo .= " \nother info: ".$result['info'];
			
			// sárgába
			if(!$nUserID){
				$ujtomb['strName']   = $result['nev'];
				$ujtomb['strTel']    = $result['telefon'];
				$ujtomb['strEMail']  = $email;
				$ujtomb['strStreet'] = $szemadatok->strStreet;
				$ujtomb['strCity']   = $szemadatok->strCity;
				$ujtomb['strZip']    = $szemadatok->strZip;
				$ujtomb['strCompany']= $szemadatok->strCompany;
				$ujtomb['nUserProf'] = $szemadatok->nUserProf;
				$ujtomb['nCtrID']    = array_search(strtolower($szemadatok->ctrName), $countries);
				if($kulcs->hlUser=="")
					$ujtomb['nUserType'] = 1;
				$nUserID = $this->mclusers->addUserEng($ujtomb);
				
				$tomb2['nUserID'] = $nUserID;
				$tomb2['email']   = $email;
				$this->mclusers->addUserEmailEng($tomb2);
			}else{
				if($kulcs->hlUser==""){
					if(UJUGYFELKEZELO===true)
						$this->db->update($adatbazis.'.users',array('nUserType'=>1),"nUserID=".$nUserID);
					else
						$this->db->update($adatbazis.'.cl_users',array('nUserType'=>1),"nUserID=".$nUserID);
				}
			}
			// sárgába esemény
			if(UJUGYFELKEZELO===true)
				$query = "INSERT INTO `".CRMADATBAZIS."`.`u_history` VALUES (NULL,{$nUserID},219,'{$datum}','web','{$eseminfo}', 36, '', '','','', NULL)";
			else
				$query = "INSERT INTO `clusers_eng`.`cl_history` VALUES (NULL,{$nUserID},198,'{$datum}','web','{$eseminfo}', 0)";
			$this->db->query($query);
			// fórumba
			$query2 = $this->db->where("login='{$email}' OR email='{$email}'")->limit(1)->get('forum_user');
			$result2 = $query2->result_array();
			if( empty($result2) ){
				$ujforum['nUserID'] = $nUserID;
				$ujforum['new_nUserID'] = $nUserID;
				$ujforum['login']   = $email;
				$ujforum['email']   = $email;
				$ujforum['nev']     = $result['nev'];
				$ujforum['jelszo']  = $result['jelszo'];
				$ujforum['rang']    = "user";
				$ujforum['nyelv']   = "eng";
				$this->db->insert('forum_user',$ujforum);
			}
			// a most megadott jelszóval felülírom a jelenlegit
			elseif( $result2[0]['jelszo']!=$result['jelszo'] ){
				$this->db->update('cadline2.forum_user',array("jelszo"=>$result['jelszo']),"user_id=".$result2[0]['user_id']);
			}
			
			// userhez a program
			if($kulcs->hlUser==""){
				$ujhl['hlUser'] = $nUserID;
				if(UJUGYFELKEZELO===true)
					$this->db->update($adatbazis.'.hardlock',$ujhl,"hlID=".$kulcs->hlID);
				else
					$this->db->update($adatbazis.'.cl_fo_hardlock',$ujhl,"hlID=".$kulcs->hlID);
			}
		}
		else{
			$record->osztaly = "other";
			$record->fv = "registeronceconfirm";
			$record->hiba = "Nem tudom hova tenni (kék/sárga): ".$result['arch_id']." ".print_r($kulcs,true);
			$record->datum = date('Y-m-d H:i:s',time());
			$this->db->insert('a_hibak',$record);
			print "Nem tudom hova tenni (kék/sárga)";
		}
		
		// kulcs esemény
		$ujkulcsesem['hiHlNum']  = $result['arch_id'];
		$ujkulcsesem['hiDate']   = $datum;
		$ujkulcsesem['hiTime']   = date("Y-m-d H:i:s");
		if(UJUGYFELKEZELO!==true)
			$ujkulcsesem['hiCtrID']  = $kulcs->hlCtrID;
		if($adatbazis=="clusers" || UJUGYFELKEZELO===true)
		$ujkulcsesem['hiTypeID'] = 17;
		else
		$ujkulcsesem['hiTypeID'] = 19;
		
		if(UJUGYFELKEZELO===true)
			$this->db->insert($adatbazis.'.h_history',$ujkulcsesem);
		else
			$this->db->insert($adatbazis.'.cl_fo_history',$ujkulcsesem);
		
		
		
		// e-mail a sorozatszámmal
		if(UJUGYFELKEZELO===true)
			$program = $this->db->query("SELECT max(prPass) prPass, prStat, prVerID FROM {$adatbazis}.h_programs WHERE prHlNum='".$result['arch_id']."' ORDER BY prID DESC")->row();
		else
			$program = $this->db->query("SELECT max(prPass) prPass, prStat, prVerID FROM {$adatbazis}.cl_fo_programs WHERE prHlNum='".$result['arch_id']."' ORDER BY prID DESC")->row();
		
		if(!$program || !$program->prPass || $program->prVerID != "13"){
			$this->_ujtempprogram($adatbazis, $kulcs);
			if(UJUGYFELKEZELO===true)
				$program = $this->db->query("SELECT max(prPass) prPass, prStat FROM {$adatbazis}.h_programs WHERE prHlNum='".$result['arch_id']."' ORDER BY prID DESC")->row();
			else
				$program = $this->db->query("SELECT max(prPass) prPass, prStat FROM {$adatbazis}.cl_fo_programs WHERE prHlNum='".$result['arch_id']."' ORDER BY prID DESC")->row();
		}
		
		$this->load->library('email');
		$this->email->initialize();
		$this->email->addOfficialImages();
		$mail_vars['first'] = $result['nev'];
		$mail_vars['email'] = $email;
		$mail_vars['ser']   = $program->prPass;
		$mail_vars['mailcontent'] = 'mail/register_valid_'.$nyelv;
		
		$this->email->setFrom('info@archlinexp.com', 'CadLine');
		$this->email->subject('ARCHLine.XP Register');
		if( strstr($result['info'],"dealer:") ){
			$dealeremail = str_replace("dealer:","",$result['info']);
			$mail_vars['mailcontent'] = 'mail/register_valid_dealer';
			$mail_vars['dealeremail'] = $dealeremail;
			$this->email->message($this->load->view('mail',$mail_vars,true));
			$this->email->send($dealeremail,'smtp');
		}
		else{
		//	$mail_vars['mailcontent'] = 'mail/register_valid_hun';
			$this->email->message($this->load->view('mail',$mail_vars,true));
			$this->email->send($email,'smtp');
		}
		
		$this->email->clear();
		
		$this->email->setFrom('info@archlinexp.com', 'CadLine');
		$this->email->subject('ARCHLine.XP Register');
		$this->email->message($this->load->view('mail',$mail_vars,true));
		$this->email->send("edit@cadline.hu",'smtp');
		if( in_array($kulcs->hlCtrID,$sargaorszag) )
			$this->email->send("info@archlinexp.com",'smtp');
			//$this->email->send("eszter@cadline.hu",'smtp');
		
		
		// törölni a tempből
		$this->db->update('t_registeronce',array('torolve'=>1),"r_id=".$result['r_id']);
		
		if($nyelv=="hun")
			redirect('page/show/regisztraciook');
		else
			redirect('page/show/registrationok');
	}
	
	function semmi(){
		print "";
	}
	
	
	function _ujtempprogram($adatbazis, $kulcs){
/*
		$prVerCode = 71;	// 2014-as program
		$prVerID   = 14;	// 2014-as program
*/
		$prVerCode = 72;	// 2015-ös program
		$prVerID   = 15;	// 2015-ös program
		$prTypeID  = 8;		// Professional
		$prContact = 5;		// Nonprofit
		
		$hlNum = $kulcs->hlNum;
		$ctrID = $kulcs->hlCtrID;
		$hlLan = $kulcs->hlLan;
		
		if( substr($hlNum,0,2)!="99" )
    {
			if(array_key_exists($hlNum,$this->kulcsprverzio)){
				$adatok = $this->kulcsprverzio[$hlNum];
				$prTypeID  = $adatok[1];
				$prContact = $adatok[2];
			}else{
				// hiba, nincs beállítva hogy mit hozzon létre
				$record->osztaly = "other";
				$record->fv      = "_ujtempprogram";
				$record->hiba    = "Kulcs: {$hlNum}\nnincs beállítva hogy milyen programot hozzon létre";
				$record->datum   = date('Y-m-d H:i:s',time());
				$this->db->insert('a_hibak',$record);
			}
		}
		
		$password = $this->_password_gen($hlNum, $hlLan, $prTypeID, $prVerCode);
		
		// program felvétele
		$ujprogram = array(
			"prHlNum"   => $hlNum,
			"prTypeID"  => $prTypeID,
			"prSellDate" => date("Y-m-d"),
			"prContact" => $prContact,
			"prPass"    => $password,
			"prLan"     => $hlLan,
			"prLastMod" => date("Y-m-d"),
			"prVerID"   => $prVerID,
			"prInfo"    => "regisztralaskor letrehozva (weben)",
			"prCtrID"   => $ctrID
		);
	//	print", ujpr: "; print_r($ujprogram);
		if(UJUGYFELKEZELO===true)
			$this->db->insert("{$adatbazis}.h_programs",$ujprogram);
		else
			$this->db->insert("{$adatbazis}.cl_fo_programs",$ujprogram);
			
		// korábbi verziójú programok letiltása
		$this->db->update( "{$adatbazis}.h_programs", array('prStat'=>1), "prHlNum = '{$hlNum}' AND prVerID < {$prVerID}");
		
		
		// szoftveres kulcsnál annyi program, ahány lanos
		if( substr($hlNum,0,1)=="9" && $hlLan>1 ){
			for($i=1;$i<$hlLan;$i++){
				if(UJUGYFELKEZELO===true)
					$this->db->insert("{$adatbazis}.h_programs",$ujprogram);
				else
					$this->db->insert("{$adatbazis}.cl_fo_programs",$ujprogram);
			}
		}
		
		
		// magyar adatbazisba is szurja be
		/*if($adatbazis!="clusers")
			$this->db->insert("clusers.cl_fo_programs",$ujprogram);*/
		
		
		//rögzítés a historyban
		$ujhistory = array(
			"hiHlNum"  => $hlNum,
			"hiDate"   => date("Y-m-d"),
			"hiManID"  => 0,
			"hiTypeID" => 2,
			"hiCtrID"  => $ctrID
		);
		if(UJUGYFELKEZELO===true){
			unset($ujhistory['hiCtrID']);
			$this->db->insert("{$adatbazis}.h_history",$ujhistory);
		}else
			$this->db->insert("{$adatbazis}.cl_fo_history",$ujhistory);
		
		$ujhl['hlStat'] = 1;
		if(UJUGYFELKEZELO===true)
			$this->db->update($adatbazis.'.hardlock',$ujhl,"hlNum=".$hlNum);
		else
			$this->db->update($adatbazis.'.cl_fo_hardlock',$ujhl,"hlNum=".$hlNum);
		
		return true;
	}
	
	function _password_gen($hlNum, $lan, $type, $version = 64){
		$country = substr($hlNum, 0, 2);
		$number = substr($hlNum, 2, 4);
		
		if(substr($hlNum,0,1)=="9")
			$lan = 0;
		
		//photo edition
		if($type == 41){
			$type = 4;
		}
		
		if($country == '91'){
			return '9100014260913946';
		}
		
		if($type == 42){
			return '';
		}
		
		//if($type==81 || $type==82)
		if((int)substr($type,0,1)==8)
			$type = 8;
		
		if($type==71)
			$type = 7;

		if($type==61 || $type==62)
			$type = 6;
			
		if($type==91)
			$type = 9;
	//	print "itt . password<br />";
		$command = PATH_CODEGEN." -Password " . $country . $number . $version . $lan . $type;
		//print "parancs: ".$command;
		$ph = popen($command, "r")
			or die( "A 'codegen' paranccsal nem veheto fel kapcsolat" );
		  
		
		$password = fgets($ph, 1024);
		pclose($ph);
	//	print " , kapott pw: ".$password."<br />";

		return $password;
	}
	
	function _archlineID($kulcs){
		if(!$kulcs)
			return false;
		
		$ch = substr(md5($kulcs."Dc43dT"),5,2);
		if($ch[0]=="0")
			$ch[0]=1;
		if($ch[1]=="0")
			$ch[1]=1;
		
		return $kulcs.$ch;
	}
	
}
?>