<?php

class Business extends Controller
{
	function Business()
	{
		parent::Controller();
	}
	
	
	function activate()
	{
		$ser = $this->uri->segment(3);
		$pwd = $this->uri->segment(4);
		
		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('/business/activate/'.$ser.'/'.$pwd);
		}
		
		if( $pwd == "hun" ){
		//	$CI = &get_instance();
			$user = $this->phpsession->get('user');
			$user['lang']="hun";
			$this->phpsession->save('user',$user);
		}
		
		$this->load->helper('serial');
		
		$do = $this->input->post('do');
		
		if($do)
		{
			$this->load->helper('email');
			
			$ser = $this->input->post('ser');
			$pwd = $this->input->post('pwd');
			$email = $this->input->post('email');
			$nev = $this->input->post('nev');
			
			
			if(!$ser || !valid_email($email))
			{
				show_error('Hibás/Hiányos adatok');
			}
			else
			{
				$this->load->helper('serial');
				
				$key = @serial($ser,$pwd);
				
				// E-Mail küldés
					$this->load->library('email');
					$this->email->initialize();
					$this->email->addOfficialImages();
	
					$this->email->from('info@cadline.hu', 'CadLine');
					
			
					$this->phpsession->flashsave('email',$email);
					
					$tomb['key']=$key;
					$tomb['ser']=$ser;
					$tomb['pwd']=$pwd;
					
					$tomb['version']='trial';
			
					$tomb['key'] = @serial($ser,$pwd);
				
					/*	
					if($this->muser->user['lang']=='hun')
					{
						$tomb['mailcontent']='business/mail_activate_full_hun';
						$this->email->subject('ARCHLine.XP Termekaktivalas');
						$this->email->message($this->load->view('mail',$tomb,true));
					}
					else
					{
						$tomb['mailcontent']='business/mail_activate_full_eng';
						$this->email->subject('ARCHLine.XP Product Activation');
						$this->email->message($this->load->view('business/mail_activate_full_eng',$tomb,true));
					}
					if(!$this->email->send($email,'smtp'))
					{
					}
				
					*/
										
					// ////////////////////////////////Levél neknünk
				
					
					
					$this->email->from('info@cadline.hu', 'CadLine');
					
					$this->phpsession->flashsave('email',$email);
					
					$this->email->subject("Aktivalas kerelem");
					$this->email->message($this->load->view('mail',array('nev'=>$nev,'act'=>$key,'serial'=>$ser,'email'=>$email,'mailcontent'=>"business/notify_act_request"),true));
			
					(substr($ser, 0, 2) == 44) ? $this->email->send('info@archlinexp.com','smtp') : $this->email->send('edit@cadline.hu','smtp');
				
				
					//adatbázis
					
					$record['act_ser']=$ser;
					$record['act_pwd']=$pwd;
					$record['act_name']=$nev;
					$record['act_email']=$email;
					$record['act_userlang']=$this->muser->user['lang'];
					$record['act_version']='full';
					$record['act_date']=time();
					
					$this->db->insert('activations',$record);
					
					// felhasznaloi adatbazis
					$this->load->model('mclusers');
					if($ctr == "36"){
						$nUserID = $this->mclusers->get_nUserIDByEmail($email,'hun');
						
						if(!$nUserID){
							$tomb3['strName']    = $nev;
							$nUserID = $this->mclusers->addUserHun($tomb3);
							
							$tomb2['nUserID'] = $nUserID;
							$tomb2['email']   = $email;
							$this->mclusers->addUserEmailHun($tomb2);
						}
						$info = "30 napos aktivalas, verzió: ".$verziotomb[$verzio];
						$this->mclusers->addEvent($nUserID, 165, $info);
					}elseif($ctr == "44"){
						$nUserID = $this->mclusers->get_nUserIDByEmail($email,'eng');
						
						if(!$nUserID){
							$tomb3['strName']    = $nev;
							$nUserID = $this->mclusers->addUserEng($tomb3);
							
							$tomb2['nUserID'] = $nUserID;
							$tomb2['email']   = $email;
							$this->mclusers->addUserEmailEng($tomb2);
						}
						$info = "30 napos aktivalas, verzió: ".$verziotomb[$verzio];
						$this->mclusers->addEvent($nUserID, 197, $info, "eng");
					}
					
					
					// email neki is
					
					$this->email->clear();
					
					$this->email->from('info@cadline.hu', 'CadLine');
					
					$tomb['mailcontent'] = 'business/mail_activate_full';
				
					$this->email->subject('ARCHLine.XP');
					$this->email->message($this->load->view('mail',$tomb,true));
				
					$this->email->send($email,'smtp');
					
					// redirect
					
					redirect('business/activate_ok_full');
				
			}
		}
		else
		{
			$data['csik']=array('home','Activation');
			$data['tartalom']='business/act';
			$data['javascript'] = array('focus');
			
			$data['pwd'] = $pwd;
			$data['ser'] = $ser;
		
			
			$this->load->view('site',$data);
		}
	}
	
	function interior_activate()
	{
		$ser = $this->uri->segment(3);
		$pwd = $this->uri->segment(4);
		$lang = $this->uri->segment(5);

		//setting the language
		if(isset($lang) && $lang!='' && ($lang=='hun' || $lang=='eng'))
		{
            $this->lang->load('site',$lang);
			$this->muser->user['lang']=$lang;
		}
		else
		{
            $this->lang->load('site','eng');
			$this->muser->user['lang']='eng';
		}

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

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

		if($do)
		{
			$this->load->helper('email');

			$ser = $this->input->post('ser');
			$pwd = $this->input->post('pwd');
			$email = $this->input->post('email');
			$nev = $this->input->post('nev');


			if(!$ser || !valid_email($email))
			{
				show_error('Hibás/Hiányos adatok');
			}
			else
			{
				$this->load->helper('serial');

				$key = @serial($ser,$pwd);

				// E-Mail küldés
				$this->load->library('email');
				$this->email->initialize();
				$this->email->addOfficialImages();

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


				$this->phpsession->flashsave('email',$email);

				$tomb['key']=$key;
				$tomb['ser']=$ser;
				$tomb['pwd']=$pwd;

				$tomb['version']='interior';

				// ////////////////////////////////Levél neknünk
				$this->email->from('info@cadline.hu', 'CadLine');

				$this->phpsession->flashsave('email',$email);
				if($lang=='hun')
					$this->email->subject("Aktivalas kerelem Interior");
				else
					$this->email->subject("Activation request Interior");
				$this->email->message($this->load->view('mail',array('nev'=>$nev,'serial'=>$ser,'email'=>$email,'mailcontent'=>"business/notify_act_request"),true));

				eng() ? $this->email->send('info@archlinexp.com','smtp') : $this->email->send('edit@cadline.hu','smtp');


				//adatbázis
				$record['act_ser']=$ser;
				$record['act_pwd']=$pwd;
				$record['act_name']=$nev;
				$record['act_email']=$email;
				$record['act_userlang']=$this->muser->user['lang'];
				$record['act_version']='interior';
				$record['act_date']=time();

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


				// email neki is
				$this->email->clear();

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

				$tomb['mailcontent'] = 'business/activate_ok_int';

				$this->email->subject('ARCHLine.XP');
				$this->email->message($this->load->view('mail',$tomb,true));

				$this->email->send($email,'smtp');

				// redirect

				redirect('business/activate_ok_int/'.$ser.'/'.$key);

			}
		}
		else
		{
			$data['csik']=array('home','Activation');
			$data['tartalom']='business/act_interior';
			$data['javascript'] = array('focus');

			$data['pwd'] = $pwd;
			$data['ser'] = $ser;
			$data['lang'] = $lang;

			$this->load->view('site',$data);
		}
	}
	
	function activate_mod()
	{
		$do = $this->input->post('do');
		if(!$do)
		{
			$data['ser'] = $this->uri->segment(3);
			$data['mod'] = $this->uri->segment(4);
			
			
			
			$data['csik']=array('home','Activation');
			$data['tartalom']='business/activate_mod';
			$this->load->view('site',$data);
			
		}
		else
		{
			$ser = $this->input->post('ser');
			$mod = $this->input->post('mod');
			$email = $this->input->post('email');
			
			
			if(!$email)
			{
				if(hun())
				{
					show_error('Nem adott meg e-mail címet');
				}
				else
				{
					show_error('No e-mail address given');
				}
			}
			
			$this->load->library('email');
			$this->email->initialize();
			$this->email->addOfficialImages();
	
			
			$this->email->from('info@cadline.hu', 'CadLine');
			
			
			$this->phpsession->flashsave('email',$email);
					
			$this->email->subject("Modul Aktivacios kerelem");
			$this->email->message($this->load->view("business/modmail",array('mod'=>$mod,'ser'=>$ser,'email'=>$email),true));
			
			$this->email->send('edit@cadline.hu','smtp');
			
			
			$data['csik'] = array('home','Module Aktivation');
			$data['tartalom'] = 'business/mod_ok';
			$this->load->view('site',$data);
		
		}
		
		
	}
	
	
	function activate_30()
	{
		$this->load->helper('serial');
		
		$ser = $this->uri->segment(3);
		$pwd = $this->uri->segment(4);
		
		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('/business/activate/'.$ser.'/'.$pwd);
		}
		
		$do = $this->input->post('do');
		
		if($do)
		{
			$this->load->helper('email');
			
			$ser = $this->input->post('ser');
			$pwd = $this->input->post('pwd');
			$email = $this->input->post('strEMail');
			
			$nev = $this->input->post('nev');
			
			
			if(!$ser || !$pwd || !valid_email($email))
			{
				show_error('Error/Missing dates');
			}
			else
			{
				$this->load->helper('serial');
				
				if(substr($ser,0,2)!=96 && substr($ser,0,2)!=97)
				{
					show_error('Invalid Serial NO.');
				}
				
				
				$ell1 = issoftwarekey($ser);
				if($ell1!==true){
					print "Hibas kulcs";
					//show_error('Hibás kulcs');
					return;
				}
				
				
				if( (int)substr($ser,7,2) < 30 ){
					$key = serial($ser,$pwd);
					$xp2013 = false;
				}else{
					$elteltnapok = idokod($pwd);
					$isid    = substr($pwd,5,4);
					$command = PATH_CODEGEN." -GenerateTimeCode ".$ser." ".$isid." 60";
			//			print "<br>parancs: ".$command;
					$ph = popen($command, "r")
						or die( "A 'codegen' paranccsal nem veheto fel kapcsolat" );
					$key = fgets($ph, 1024);
			//			print "<br>ered: ".$key."<br>";
					pclose($ph);
					$xp2013 = true;
				}
				
				// E-Mail küldés
				$this->load->library('email');
				$this->email->initialize();
				$this->email->addOfficialImages();


				$this->email->from('info@cadline.hu', 'CadLine');
				
				$tomb['key']=$key;
				$tomb['ser']=$ser;
				$tomb['pwd']=$pwd;
				$tomb['email']=$email;
				$tomb['xp2013']=$xp2013;
				$tomb['version']='trial';
				
				if($this->muser->user['lang']=='hun')
				{
					$tomb['mailcontent'] = 'business/mail_activate_trial_hun';
					$this->email->subject('ARCHlineXP.com aktiválasi kod keres');
					$this->email->message($this->load->view('mail',$tomb,true));
				}
				else
				{
					$tomb['mailcontent'] = 'business/mail_activate_trial_eng';
					$this->email->subject('ARCHlineXP.com Activation Code Request');
					$this->email->message($this->load->view('mail',$tomb,true));
				}
				
				$this->email->send($email,'smtp');
			//	$this->email->send('info@cadline.hu','smtp');
				
				
				
				//// email nekünk is
//					
//					$this->email->clear();
//					
//					$this->email->from('info@cadline.hu', 'CadLine');
//					$this->email->to('info@cadline.hu');
//				
//					$this->email->subject('30 Napos aktiválás történt');
//					$this->email->message($this->load->view('business/report_act_30',$tomb,true));
//				
//					$this->email->send();
					
				
				//adatbázis
				
				$record['act_ser']=$ser;
				$record['act_pwd']=$pwd;
				$record['act_name']=$nev;
				$record['act_email']=$email;
				$record['act_userlang']=$this->muser->user['lang'];
				$record['act_version']='trial';
				$record['act_date']=time();
				
				$this->db->insert('activations',$record);
				
				
				$verzio = (int)substr($ser,7,2);
				$tipus  = (int)substr($ser,6,1);
				$kulcs  = (int)substr($ser,0,6);
				$ctr    = (int)substr($ser,0,2);
				$verziotomb = array(
					30 => "2013",
					29 => "2013 Béta",
					28 => "2012",
					27 => "2011",
					26 => "2010"
				);
				$tipustomb = array(
					8 => "interior",
					9 => "építészet"
				);
				
				// felhasznaloi adatbazis
				$this->load->model('mclusers');
				if($ctr == "36"){
					$nUserID = $this->mclusers->get_nUserIDByEmail($email,'hun');
					
					if(!$nUserID){
						$tomb3['strName']    = $nev;
						$nUserID = $this->mclusers->addUserHun($tomb3);
						
						$tomb2['nUserID'] = $nUserID;
						$tomb2['email']   = $email;
						$this->mclusers->addUserEmailHun($tomb2);
					}
					$info = "30 napos aktivalas, verzió: ".$verziotomb[$verzio];
					$this->mclusers->addEvent($nUserID, 165, $info);
				}elseif($ctr == "44"){
					$nUserID = $this->mclusers->get_nUserIDByEmail($email,'eng');
					
					if(!$nUserID){
						$tomb3['strName']    = $nev;
						$nUserID = $this->mclusers->addUserEng($tomb3);
						
						$tomb2['nUserID'] = $nUserID;
						$tomb2['email']   = $email;
						$this->mclusers->addUserEmailEng($tomb2);
					}
					$info = "30 napos aktivalas, verzió: ".$verziotomb[$verzio];
					$this->mclusers->addEvent($nUserID, 197, $info, "eng");
				}
				
				// redirect
				
				redirect('business/activate_ok');
					
			}
			
		}
		else
		{
			$this->load->model('mctr');
			hun() ? $data['ctr']=$this->mctr->get_all_ctr('ctrNameHun') : $data['ctr']=$this->mctr->get_all_ctr();
			if(hun())
				$data['page'] = $this->mpages->get_row(778);
			else
				$data['page'] = $this->mpages->get_row(779);
			
			$data['csik']       = array('home','Activation');
			$data['javascript'] = array('regformcheck');
			$data['tartalom']   = 'business/act30';
			
			$data['pwd'] = $pwd;
			$data['ser'] = $ser;
			
			$this->load->view('site',$data);
			
		}
	}
	
	
	function activate_30_99(){
		$this->load->helper('email');
		$this->load->helper('serial');
			
		$ser     = $this->input->post('ser');
		$pwd     = $this->input->post('pwd');
		$email   = $this->input->post('strEMail');
		$nev     = $this->input->post('strName1').' '.$this->input->post('strName2');
		$country = $this->input->post('ctrName');
		$tel     = $this->input->post('strTel');
		$tema    = $this->input->post('tema');
		$uzenet  = $this->input->post('uzenet');
		
		$strCompany= $this->input->post('strCompany');
		$strCity   = $this->input->post('strCity');
		$strStreet = $this->input->post('strStreet');
		$strZip    = $this->input->post('strZip');
		$nUserProf = $this->input->post('nUserProf');
		
		
		if(!$ser || !$pwd || !valid_email($email)){
			show_error('Missing or invalid dates');
			return;
		}
		
		$ell1 = issoftwarekey($ser);
		if($ell1!==true){
			show_error('Error key');
			return;
		}
		
		
		$elteltnapok = idokod($pwd);
		$isid    = substr($pwd,5,4);
		$xp2013  = true;
		
		// ha van az adatbázisban kódja (és az legalább 60 napos) akkor azt, egyébként 60 napos kódot
		$programab = $this->db->query("SELECT prActCode FROM ".CRMADATBAZIS.".h_programs WHERE prPass='{$ser}'")->row();
		
		
		// Mindeképp generáljon egy 60 napos kódot - 2014. 03. 11.
		/*if( $programab->prActCode && idokod($programab->prActCode)>60 ){
			$key     = $programab->prActCode;
		}
		else{*/
			$command = PATH_CODEGEN." -GenerateTimeCode ".$ser." ".$isid." 60";
			$ph      = popen($command, "r")
						or die( "A 'codegen' paranccsal nem veheto fel kapcsolat" );
			$key     = fgets($ph, 1024);
			pclose($ph);
		//}
		
		
		//adatbázis
		$record['act_ser']=$ser;
		$record['act_pwd']=$pwd;
		$record['act_name']=$nev;
		$record['act_email']=$email;
		$record['act_userlang']=$this->muser->user['lang'];
		$record['act_version']='trial';
		$record['act_date']=time();
		
		$this->db->insert('activations',$record);
		
		
		// felhasznaloi adatbazis
		$this->load->model('mclusers');
		
		if($kulcsctr=="36"){
			$nUserID = $this->mclusers->get_nUserIDByEmail($email,'hun');
			
			if(!$nUserID){
				$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']);
				
				
				$tomb3['strName']    = $nev;
				$tomb3['strCompany'] = $strCompany;
				$tomb3['strTel']     = $tel;
				$tomb3['strCity']    = $strCity;
				$tomb3['strStreet']  = $strStreet;
				$tomb3['strZip']     = $strZip;
				$tomb3['nUserProf']  = $nUserProf;
				$tomb3['nCtrID']     = array_search(strtolower($country), $countries);
				$nUserID = $this->mclusers->addUserHun($tomb3);
				
				$tomb2['nUserID'] = $nUserID;
				$tomb2['email']   = $email;
				$this->mclusers->addUserEmailHun($tomb2);
			}
			$info = "aktivalasi kérelem, sorozatszám: ".$ser;
			$this->mclusers->addEvent($nUserID, 115, $info);
			
			// 60 napos kódot beírni, ha üres az aktiváló kód mező
			$datum = date("Y-m-d");
			/*if(UJUGYFELKEZELO===true)
				$this->db->update(CRMADATBAZIS.'.h_programs',array('prActCode'=>$key,'prActDate'=>$datum),"prPass='{$ser}' AND (prActCode IS NULL OR prActCode='')");
			else
				$this->db->update('clusers.cl_fo_programs',array('prActCode'=>$key,'prActDate'=>$datum),"prPass='{$ser}' AND (prActCode IS NULL OR prActCode='')");*/
			$this->db->limit(1);
			$this->db->where('prPass',$ser);
			$this->db->where('SUBSTRING(prActCode,6,4)',$isid);
			
			$this->db->update(CRMADATBAZIS.'.h_programs',array('prActCode'=>$key,'prActDate'=>$datum));
			
			if(!$this->db->affected_rows()){
				$this->db->limit(1);
				$this->db->where('prPass',$ser);
				$this->db->where(' (prActCode IS NULL OR prActCode="" )');
				$this->db->update(CRMADATBAZIS.'.h_programs',array('prActCode'=>$key,'prActDate'=>$datum));
				
				if(!$this->db->affected_rows())
					redirect('business/activate_error');
			}
			
			// kulcs esemény
			$kulcshistory['hiHlNum'] = substr($ser,0,6);
			$kulcshistory['hiTypeID'] = 16;
			$kulcshistory['hiDate'] = $datum;
			$kulcshistory['hiTime'] = date("Y-m-d H:i:s");
		//	$kulcshistory['hiCtrID'] = $kulcsctr;
			if(UJUGYFELKEZELO===true)
				$this->db->insert(CRMADATBAZIS.'.h_history',$kulcshistory);
			else
				$this->db->insert('clusers.cl_fo_history',$kulcshistory);
			
		}
		elseif($kulcsctr!="44"){
			// 60 napos kódot beírni, ha üres az aktiváló kód mező
			$datum = date("Y-m-d");
			$this->db->limit(1);
			$this->db->where('prPass',$ser);
			$this->db->where('SUBSTRING(prActCode,6,4)',$isid);
			
			$this->db->update(CRMADATBAZIS.'.h_programs',array('prActCode'=>$key,'prActDate'=>$datum));
			
			if(!$this->db->affected_rows()){
				$this->db->limit(1);
				$this->db->where('prPass',$ser);
				$this->db->where(' (prActCode IS NULL OR prActCode="" )');
				$this->db->update(CRMADATBAZIS.'.h_programs',array('prActCode'=>$key,'prActDate'=>$datum));
				
				if(!$this->db->affected_rows())
					redirect('business/activate_error');
			}
			
			// kulcs esemény
			$kulcshistory['hiHlNum'] = substr($ser,0,6);
			$kulcshistory['hiTypeID'] = 20;
			$kulcshistory['hiDate'] = $datum;
			$kulcshistory['hiTime'] = date("Y-m-d H:i:s");
		//	$kulcshistory['hiCtrID'] = $kulcsctr;
			if(UJUGYFELKEZELO===true){
				$kulcshistory['hiTypeID'] = 16;
				$this->db->insert(CRMADATBAZIS.'.h_history',$kulcshistory);
			}else
				$this->db->insert('clusers.cl_fo_history',$kulcshistory);
			
		}
		elseif($kulcsctr=="44"){
			$nUserID = $this->mclusers->get_nUserIDByEmail($email,'eng');
			
			if(!$nUserID){
				$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']);
				
				$tomb3['strName']    = $nev;
				$tomb3['strCompany'] = $strCompany;
				$tomb3['strTel']     = $tel;
				$tomb3['strCity']    = $strCity;
				$tomb3['strStreet']  = $strStreet;
				$tomb3['strZip']     = $strZip;
				$tomb3['nUserProf']  = $nUserProf;
				$tomb3['nCtrID']     = array_search(strtolower($country), $countries);
				$nUserID = $this->mclusers->addUserEng($tomb3);
				
				$tomb2['nUserID'] = $nUserID;
				$tomb2['email']   = $email;
				$this->mclusers->addUserEmailEng($tomb2);
			}
			$info = "aktivalasi kérelem, sorozatszám: ".$ser;
			$this->mclusers->addEvent($nUserID, 197, $info);
			
			// 60 napos kódot beírni, ha üres az aktiváló kód mező
			$datum = date("Y-m-d");
			$this->db->limit(1);
			$this->db->where('prPass',$ser);
			$this->db->where('SUBSTRING(prActCode,6,4)',$isid);
			
			$this->db->update(CRMADATBAZIS.'.h_programs',array('prActCode'=>$key,'prActDate'=>$datum));
			
			if(!$this->db->affected_rows()){
				$this->db->limit(1);
				$this->db->where('prPass',$ser);
				$this->db->where(' (prActCode IS NULL OR prActCode="" )');
				$this->db->update(CRMADATBAZIS.'.h_programs',array('prActCode'=>$key,'prActDate'=>$datum));
				
				if(!$this->db->affected_rows())
					redirect('business/activate_error');
			}
			
			// kulcs esemény
			$kulcshistory['hiHlNum'] = substr($ser,0,6);
			$kulcshistory['hiTypeID'] = 20;
			$kulcshistory['hiDate'] = $datum;
			$kulcshistory['hiTime'] = date("Y-m-d H:i:s");
		//	$kulcshistory['hiCtrID'] = $kulcsctr;
			if(UJUGYFELKEZELO===true){
				$kulcshistory['hiTypeID'] = 16;
				$this->db->insert(CRMADATBAZIS.'.h_history',$kulcshistory);
			}else
				$this->db->insert('clusers_eng.cl_fo_history',$kulcshistory);
		}
		
		
		
		
		
		
		// E-Mail küldés
		$this->load->library('email');
		$this->email->initialize();
		$this->email->addOfficialImages();


		$this->email->from('info@cadline.hu', 'CadLine');
		
		$tomb['key']=$key;
		$tomb['ser']=$ser;
		$tomb['pwd']=$pwd;
		$tomb['email']=$email;
		$tomb['nev']=$nev;
		$tomb['tel']=$tel;
		$tomb['orszag']=$country;
		$tomb['xp2013']=$xp2013;
		$tomb['version']='trial';
		$tomb['notitleimg']=true;
		$tomb['tema']=$tema;
		$tomb['uzenet']=$uzenet;
		
		$ttemp = $this->_akt99email($ser);
		$archlineemail = $ttemp[0];
		$kulcsctr = $ttemp[1];
		
		if($kulcsctr=="36")
			$tomb['nyelv'] = "hun";
		else
			$tomb['nyelv'] = "eng";
		
		$tomb['mailcontent'] = 'business/mail_activate_trial_cadline';
		$this->email->subject('ARCHlineXP.com Activation Code Request');
		$this->email->message($this->load->view('mail',$tomb,true));
		
		
		if($archlineemail){
			$this->email->send($archlineemail,'smtp');
		}
		
		
		//// email neki
		$this->email->clear();
		
		if($kulcsctr=="36")
			$this->email->from('info@cadline.hu', 'CadLine');
		else
			$this->email->from('info@archlinexp.com', 'CadLine');
		
		$this->email->subject('ARCHLineXP Activate');
		if($elteltnapok<=30){
			if($kulcsctr=="36")
				$emailpage = $this->mpages->get_row(776);
			else
				$emailpage = $this->mpages->get_row(777);
			$emailtext = str_ireplace('#serial#', $ser, $emailpage->page_body);
			$emailtext = str_ireplace('#aktkod#', $key, $emailtext);
			$this->email->message($emailtext);
		}
		else{
			if($kulcsctr=="36")
				$emailpage = $this->mpages->get_row(774);
			else
				$emailpage = $this->mpages->get_row(775);
			$emailtext = str_ireplace('#nev#', $nev, $emailpage->page_body);
			$this->email->message($emailtext);
		}
		
		$this->email->send($email,'smtp');
		
		
		
		
		// redirect
		
		redirect('business/activate_ok');
	}
	
	function activate_std()
	{
		$this->load->helper('serial');
		
		$ser = $this->uri->segment(3);
		$pwd = $this->uri->segment(4);
		
		$do = $this->input->post('do');
		
	
		if($do)
		{
			$this->load->helper('email');
			
			$ser = $this->input->post('ser');
			$pwd = $this->input->post('pwd');
			$email = $this->input->post('email');
			$name = $this->input->post('name');
			$birth = $this->input->post('birth');
			
			
			if(!$ser || !$pwd || !valid_email($email) || !$name || !$birth)
			{
				show_error('Hibás/Hiányos adatok');
			}
			else
			{
				$this->load->helper('serial');
				
				if(substr($ser,0,2)!=96 && substr($ser,0,2)!=97)
				{
					show_error('Invalid Serial NO.');
				}
				
				$key = serial($ser,$pwd);
				if(!$key)
				{
					show_error('Hibás kulcs');
				}
				else
				{
					// E-Mail küldés
					
					$this->load->library('email');
					$this->email->initialize();
					$this->email->addOfficialImages();
					/*
					$this->email->from('info@cadline.hu', 'CadLine');
					*/
				    $tomb['ser']=$ser;
					$tomb['pwd']=$pwd;
					$tomb['email']=$email;
					$tomb['version']='trial';
					$tomb['name']=$name;
					$tomb['birth']=$birth;

					if($this->muser->user['lang']=='hun')
					{
						$tomb['mailcontent'] = 'business/mail_activate_student_hun';
						$this->email->subject('ARCHlineXP.com aktiválasi kod keres');
						$this->email->message($this->load->view('mail',$tomb,true));
					}
					else
					{
						$tomb['mailcontent'] = 'business/mail_activate_student_eng';
						$this->email->subject('ARCHlineXP.com Activation Code Request');
						$this->email->message($this->load->view('mail',$tomb,true));
					}
					
					$this->email->send($email,'smtp');

					
					//email nekünk is
					
					$this->email->clear();

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

					$this->email->subject('Student aktivalasi kerelem');
					$this->email->message($this->load->view('business/report_act_student',$tomb,true));

					$this->email->send($to,'smtp');
						
					
					//adatbázis
					
					$record['act_ser']=$ser;
					$record['act_pwd']=$pwd;
					$record['act_name']=$name;
					$record['act_email']=$email;
					$record['act_userlang']=$this->muser->user['lang'];
					$record['act_version']='student';
					$record['act_date']=time();
					
					$this->db->insert('activations',$record);
					
					$this->phpsession->flashsave('email',$email);
					
					// redirect
					
					redirect('business/activate_ok_std');
					
				}
			}
		}
		else
		{
			$data['csik']=array('home','Activation');
			$data['tartalom']='business/actstd';
			
			$data['pwd'] = $pwd;
			$data['ser'] = $ser;
			
			$this->load->view('site',$data);
			
		}
	}
	
	function activate_ok_full()
	{
		$data['tartalom']='business/activate_ok_full';
		$data['csik']=array('home','Aktiválás');
		$data['lang']=$this->muser->user['lang'];
		$data['email']=$this->phpsession->flashget('email');
		
		$this->load->view('site',$data);
	}
	
	function activate_ok_int()
	{
		$data['tartalom']='business/activate_ok_int_web';
		if($this->uri->segment(3)=='hun')
			$data['csik']=array('home','Aktiválás');
		else
			$data['csik']=array('home','Activate');
		$data['lang']='eng';
		$data['ser'] = $this->uri->segment(3);
		$data['key'] = $this->uri->segment(4);
		$data['email']=$this->phpsession->flashget('email');

		$this->load->view('site',$data);
	}
	
	function activate_ok()
	{
		$data['tartalom']='business/activate_ok';
		$data['csik']=array('home','Aktiválás');
		$data['lang']=$this->muser->user['lang'];
		$data['email']=$this->phpsession->flashget('email');
		
		$this->load->view('site',$data);
	}
	
	function activate_ok_std()
	{
		$data['tartalom']='business/activate_ok_std';
		$data['csik']=array('home','Aktiválás');
		$data['lang']=$this->muser->user['lang'];
		$data['email']=$this->phpsession->flashget('email');

		$this->load->view('site',$data);
	}
	
	function activate_error()
	{
		$data['tartalom']='business/activate_error';
		$data['csik']=array('home','Aktiválás');
		$data['lang']=$this->muser->user['lang'];
		$data['email']=$this->phpsession->flashget('email');
		
		$this->load->view('site',$data);
	}
	
	function _akt99email($ser){
		$kulcssz = substr($ser,0,6);
		
		/*$kulcs = $this->db->query("SELECT hlCtrID FROM clusers.cl_fo_hardlock WHERE hlNum='{$kulcssz}'")->row();
		if(!$kulcs)
			$kulcs = $this->db->query("SELECT hlCtrID FROM clusers_eng.cl_fo_hardlock WHERE hlNum='{$kulcssz}'")->row();
		if(!$kulcs)
			$kulcs = $this->db->query("SELECT hlCtrID FROM clusers_spa.cl_fo_hardlock WHERE hlNum='{$kulcssz}'")->row();*/
		$kulcs = $this->db->query("SELECT hlCtrID FROM ".CRMADATBAZIS.".hardlock WHERE hlNum='{$kulcssz}'")->row();
		
		if(!$kulcs->hlCtrID)
			return false;
		
		switch($kulcs->hlCtrID){
			case '88':
				$ertesitoemail = "Khong@kdmac.com.my";
				break;
			case '82':
				$ertesitoemail = "carpenter@cadalog.co.kr";
				break;
			case '48':
				$ertesitoemail = "archlinexp@archlinexp.pl";
				break;
			case '41':
			case '43':
			case '30':
				$ertesitoemail = "office@it-concept.at";
				break;
			case '42':
				$ertesitoemail = "info@archline.cz";
				break;
			case '39':
				$ertesitoemail = "info@cadlinesw.com";
				break;
			case '38':
				$ertesitoemail = "info@digitalmedia.hr";
				break;
			case '36':
				$ertesitoemail = "edit@cadline.hu";
				break;
			// 44, 34, egyéb
			case '34':
			case '44':
			default:
				$ertesitoemail = "info@archlinexp.com";
				break;
			
		}
		
		//return array($ertesitoemail,$kulcs->hlCtrID);
		return array("edit@cadline.hu",$kulcs->hlCtrID);
	}
	
}
?>