<?php
class Support extends Controller
{
	function Support()
	{
		parent::Controller();
	}
	
	function index()
	{
		$data['lang']=$this->muser->user['lang'];

        $data['title'] = hun() ? 'ARCHLine.XP Terméktámogatás' : 'ARCHLine.XP Support';
		$data['tartalom']='support/index';
		$data['javascript'] = array('prototype');
		$data['csik']=array('home','support');
		
		
		if(hun())
		{
			$keywords = $this->config->item('help_keywords');
			$data['keywords'] = $keywords['hun'];
		}
		if(eng())
		{
			$keywords = $this->config->item('help_keywords');
			$data['keywords'] = $keywords['eng'];
		}
		if(be())
		{
			$keywords = $this->config->item('help_keywords');
			$data['keywords'] = $keywords['eng'];
		}
		
		$data['cimlap'] = $this->mpages->get_row(295);
		$this->load->view('site',$data);
	}
	
	function faq()
	{
		$this->load->model('mfaq');
	
	
		$data['lang']=$this->muser->user['lang'];
		$data['title'] = hun() ? 'ARCHLine.XP CAD Software - Gy.I.K.' : 'ARCHLine.XP CAD Software - FAQ';
		$data['tartalom']='support/faq';
		$data['csik']=array('home','support');
		
		$data['aktiv']=3;
		
		$data['faqs'] = $this->mfaq->get_faqs($this->muser->user['lang'],'faq_date');
		
		$this->load->view('site',$data);
	}
	
	function downloads()
	{
		$this->load->model('mdownloads');
		
		$data['heading']=$this->mdownloads->get_heading('support');
		$data['downloads']=$this->mdownloads->get_category('support',$this->muser->user['lang']);
		$data['aktiv']=6;
		
		$data['support']=true;
		
		$data['lang']=$this->muser->user['lang'];
		$data['title'] = hun() ? 'ARCHLine.XP CAD Software - Letöltés' : 'ARCHLine.XP CAD Software - Downloads';
		$data['tartalom']='downloads/list';
		$data['csik']=array('home','downloads','support');
		$this->load->view('site',$data);
	}
	
	function showarticle()
	{
		$article_url = $this->uri->segment(3);
		if(!$article_url)
		{
			show_error();
		}
		
		$data['article_url'] = base64_decode($article_url);
		$data['csik'] = array('home','support');
		$data['tartalom'] = 'support/article';
		
		$this->load->view('site',$data);
		
	}
	
	function helpcontent()
	{
		$this->load->model('mhelp');
		$data['xml'] = $this->mhelp->render_nodes();
		$data['csik'] = array('home','support');
		$data['tartalom'] = 'support/helpcontent';
		
		$this->load->view('site',$data);
		
	}
	
	function keyword()
	{
		$needs_decode = true;
		
		$this->load->model('mhelp');
		
		$keyword = $this->uri->segment(3);
		if(!$keyword)
		{
			$keyword = $this->input->post('keyword');
			$needs_decode = false;
			if(!$keyword)
			{
				redirect('support');
			}
			
		}
		
		if(hun())
		{
			$keywords = $this->config->item('help_keywords');
			$data['keywords'] = $keywords['hun'];
		}
  		if(eng())
		{
			$keywords = $this->config->item('help_keywords');
			$data['keywords'] = $keywords['eng'];
		}
		if(be())
		{
			$keywords = $this->config->item('help_keywords');
			$data['keywords'] = $keywords['eng'];
		}
		
		if($needs_decode)
		{
			$keyword = base64_decode($keyword);
		}	
		
		
		
		$data['keyword'] = $keyword;
		
		$data['found'] = $this->mhelp->search($keyword);
		$data['csik'] = array('home','support');
		$data['title'] = hun() ? 'ARCHLine.XP Tudásközpont - '.$keyword : 'ARCHLine.XP Knowledge Center - '.$keyword;
		$data['tartalom'] = 'support/index';
		$data['javascript'] = array('prototype');
		
		$this->load->view('site',$data);
	}
	
	function toc()
	{
		
		$this->load->model('mhelp');		
		
		$data['toc'] = $this->mhelp->render_nodes();
		$data['csik'] = array('home','support');
		$data['title'] = hun() ? 'ARCHLine.XP Tudásközpont' : 'ARCHLine.XP Knowledge Center';
		$data['tartalom'] = 'support/toc';
		
		if(hun())
		{
			$keywords = $this->config->item('help_keywords');
			$data['keywords'] = $keywords['hun'];
		}
  		if(eng())
		{
			$keywords = $this->config->item('help_keywords');
			$data['keywords'] = $keywords['eng'];
		}
		if(be())
		{
			$keywords = $this->config->item('help_keywords');
			$data['keywords'] = $keywords['eng'];
		}
		
		$this->load->view('site',$data);
 		
	}
	
	function events()
	{
		$this->load->model('mevents');
		
		$data['counties'] = array(
						-1 => '-- válassz --',
						'Bács-Kiskun' => 'Bács-Kiskun',
						'Baranya' => 'Baranya',
						'Békés' => 'Békés',
						'Borsod-Abaúj-Zemplén' => 'Borsod-Abaúj-Zemplén',
						'Budapest' => 'Budapest',
						'Csongrád' => 'Csongrád',
						'Fejér' => 'Fejér',
						'Győr-Moson-Sopron' => 'Győr-Moson-Sopron',
						'Hajdú-Bihar' => 'Hajdú-Bihar',
						'Heves' => 'Heves',
						'Jász-Nagykun-Szolnok' => 'Jász-Nagykun-Szolnok',
						'Komárom-Esztergom' => 'Komárom-Esztergom',
						'Nógrád' => 'Nógrád',
						'Pest' => 'Pest',
						'Somogy' => 'Somogy',
						'Szabolcs-Szatmár-Bereg' => 'Szabolcs-Szatmár-Bereg',
						'Tolna' => 'Tolna',
						'Vas' => 'Vas',
						'Veszprém' => 'Veszprém',
						'Zala' => 'Zala'
						);

		$data['lang']=$this->muser->user['lang'];
		$data['title'] = hun() ? 'ARCHLine.XP CAD Software - Bemutatók' : 'ARCHLine.XP CAD Software - Events';
		$data['tartalom']='support/events';
		$data['csik']=array('home','support');

		if(hun())
			$data['javascript'] = array('events');
		
		$data['events'] = $this->mevents->get_latest('30',$this->muser->user['lang']);
		
		$data['aktiv']=2;
		
		$data['faqs'] = $this->mevents->get_latest('faq_date');
		
		$error = false;
		
		if($this->input->post('do')!=false)
		{
			if(hun())
			{
				$arr = array('event_id','nev','cegnev','varos','irsz','tel','kamsz','county','fax','email','comment','cim');
				foreach($arr as $a)
				{
					$tomb[$a] = $this->input->post($a);
					
					if($tomb[$a]==false && $a!='fax' && $a !='comment' && $a!='cegnev' && $a!='kamsz' && $a!='county')
					{
						$error = "Minden vastaggal jelölt mezőt ki kell tölteni ($a hiányzik)";
					}
					else
					{
						$event_id = explode('|',$tomb['event_id']);
						$event_id = $event_id[0];
						
						if($a=='event_id' && !is_numeric($event_id))
						{
							$error = 'Hibás azonosító: '.$a;
						}
					}
				}
				
				if($tomb['kamsz']!='' && $tomb['county']==-1)
				{
					$error = "A kamarai névjegyzéki számhoz meg kell adnia a megyét is.";
				}
				
				$event_id = explode('|',$tomb['event_id']);
				$event_id = $event_id[0];
				
				if(!is_numeric($event_id))
				{
					$error = 'Hiábás esemény azonosító';
				}
				else
				{
					$tomb['esemeny']=$this->mevents->get_row($event_id);
				}	
			}
			elseif(jap())
			{
				$arr = array('event_id','nev','pron','cegnev','cim','tel','fax','email','comment','other');
				foreach($arr as $a)
				{
					$tomb[$a] = $this->input->post($a);
					
					if($tomb[$a]==false && $a=='tel' && $a =='nev' && $a=='cegnev')
					{
						$error = "You have to fill all form fields marked with bold text ($a is missing)";
					}
					else
					{
						if($a=='event_id' && !is_numeric($tomb[$a]))
						{
							$error = 'Invalid id: '.$a;
						}
					}
				}
				
				if(!is_numeric($tomb['event_id']))
				{
					$error = 'You have not selected an event, please select one!';
				}
				else
				{
					$tomb['esemeny']=$this->mevents->get_row($tomb['event_id']);
				}
				
				
				$egyebcad = array('AutoCAD','VectorWorks','ArchiCAD','JWCAD','ARCHITREND','GoogleSketchup','DRACAD','SuperSoft','その他');
				
				$valasztott = array();
				
				foreach($egyebcad as $key => $cad)
				{
					$no = $key+1;
					$keres = 'cb'.$no;
					
					if($this->input->post($keres)=='on')
					{
						$valasztott[]=$cad;
					}
				}
				
				if(count($valasztott)==0)
				{
					$tomb['egyebcad']=false;
				}
				else
				{
					$tomb['egyebcad']=$valasztott;
				}
			}
			else
			{
				$arr = array('event_id','nev','cegnev','varos','irsz','tel','fax','email','comment','cim');
				$names = array('event_id' => 'event id', 'nev' => 'name', 'cegnev' => 'company name', 'varos' => 'city', 'irsz' => 'zip code', 'tel' => 'phone number', 'fax' => 'fax number', 'email' => 'e-mail', 'comment' => 'comment', 'cim' => 'address');
				foreach($arr as $a)
				{
					$tomb[$a] = $this->input->post($a);

					if($tomb[$a]==false && $a!='fax' && $a !='comment' && $a!='cegnev')
					{
						$error = "Fill out every bold field ({$names[$a]} missing)";
					}
					else
					{
						$event_id = explode('|',$tomb['event_id']);
						$event_id = $event_id[0];

						if($a=='event_id' && !is_numeric($event_id))
						{
							$error = 'Wrong identifier: '.$a;
						}
					}
				}

				$event_id = explode('|',$tomb['event_id']);
				$event_id = $event_id[0];

				if(!is_numeric($event_id))
				{
					$error = 'You have to specify an event!';
				}
				else
				{
					$tomb['esemeny']=$this->mevents->get_row($event_id);
				}
			}
			
			
		
			
			if(!$error)
			{
				$this->load->library('email');
				$this->load->helper('email');
				$this->email->initialize();
				$this->email->addOfficialImages();
				
		
				if(hun())
				{
					
					$e = explode('|',$tomb['event_id']);
					
					$tomb['egyeb'] = $e[1];
					$tomb['mailcontent'] = 'support/eventmail';
					
					$this->email->from('info@cadline.hu', 'Cadline Weboldal');
					$this->email->subject('Esemenyek jelentkezes');
					$this->email->message($this->load->view('mail',$tomb,true));
					$this->email->send('info@cadline.hu','smtp');
				}
				elseif(jap())
				{
					$this->email->from('info@cadline.hu', 'Cadline Weboldal');
					$this->email->subject('Event SignUp Notification');
					$this->email->message($this->load->view('support/eventmail',$tomb,true));
					$this->email->send('living-cg@leaf.ocn.ne.jp','smtp');
				}
				else
				{

					$e = explode('|',$tomb['event_id']);

					$tomb['egyeb'] = $e[1];
					$tomb['mailcontent'] = 'support/eventmail';

					$this->email->from('info@cadline.hu', 'Cadline Weboldal');
					$this->email->subject('Esemenyek jelentkezes');
					$this->email->message($this->load->view('mail',$tomb,true));
					$this->email->send('info@archlinexp.com','smtp');
				}
		
			
			
			
				redirect('support/eventok');
			}
			
			
		}
		
		
		$data['error']=$error;
		$this->load->view('site',$data);
	}
	
	
	function eventok()
	{
		$data['lang']=$this->muser->user['lang'];
		$data['tartalom']='support/eventok';
		$data['csik']=array('home','support');
		$data['aktiv']=2;
		
		$this->load->view('site',$data);
	}
	
	function show_faq()
	{
		$this->load->model('mfaq');
		
		$faq_id = $this->uri->segment(3);
		
		if(!$faq_id || !is_numeric($faq_id))
		{
			show_404();
		}
		
		
	
		$data['lang']=$this->muser->user['lang'];
		$data['tartalom']='support/show_faq';
		$data['csik']=array('home','support');
		
		$data['aktiv']=3;
		
		$data['faq'] = $this->mfaq->get_row($faq_id);
		
		$this->load->view('site',$data);
	}
	
	
	function fileup()
	{  
		$this->load->helper('email');
		
		$uzenet = $this->input->post('uzenet');
		$email = $this->input->post('email');
		
		if(!valid_email($email))
		{
			show_error("Érvénytelen E-Mail címet adott meg!");
		}
		
		if(isset($_FILES['file']))
		{
			if($_FILES['file']['tmp_name'])
			{
				// VAN FILE CSATOLVA
				// FÁJLNÉV ELLENŐRZÉSE
				
				$name = $_FILES['file']['name'];
				$tmp = $_FILES['file']['tmp_name'];
				
				if(strstr($name,'~')!==false || strstr($name,'..')!==false || strstr($name,'/')!==false)
				{
					show_error("A fájlnév nem megengedett karaktereket tartalmaz: ".$name);
				}
				else
				{
					$put_dir = 'public/ugyfelupload/'.$email;
					
					if(!is_dir($put_dir))
					{
						mkdir($put_dir);
						chmod($put_dir,0777);
					}
					
					if(is_file($put_dir.'/'.$name))
					{
						$name = date('Y.m.d').'-'.$name.rand(0,100);
					}
					
					
					if(!move_uploaded_file($tmp,$put_dir.'/'.$name))
					{
						$file = 'hiba';
					}
					else
					{
						$file = $put_dir.'/'.$name;
						chmod($file,0777);
					}
					
				}
			}
			else
			{
				//NINCS FILE CSATOLVA
				$msg_file = false;
			}
			
			$data['file'] = $file;
			$data['uzenet'] = $uzenet;
			$data['email'] = $email;
			$data['mailcontent'] = 'support/helpmail';
			
			
			$this->load->library('email');
			$this->email->initialize();
			$this->email->addOfficialImages();
			
			
			
			$this->email->from('info@cadline.hu');
			$this->email->setReturnPath($email);
			
			$this->email->subject('Segitsegkeres Weboldalon Keresztul');
			$this->email->message($this->load->view('mail',$data,true));
			
			if(!$this->email->send('info@cadline.hu','smtp'))
			{
				show_error("Nem tudtuk elküldeni a kérését, kérjük próbálja meg újra, vagy lépjen kapcsolatba velünk telefonon keresztül.");
			}
			
			$this->load->view('site',array('tartalom'=>'support/helpmailok','csik'=>'Üzenet elküldve'));
			
			
		}
		else
		{
			show_404();
		}
	}
	
	function links()
	{
		$data['lang']=$this->muser->user['lang'];
		$data['title'] = hun() ? 'ARCHLine.XP CAD Software - Linkek' : 'ARCHLine.XP CAD Software - Links';
		$data['tartalom']='support/links';
		$data['csik']=array('home','support');
		
		$data['aktiv']=2;
		
		$this->load->view('site',$data);
	}
	
	
	
	
	function help()
	{
		$data['lang']=$this->muser->user['lang'];
		$data['tartalom']='support/help';
		$data['csik']=array('home','support');
		$data['javascript'] = array('prototype');
		
		$data['aktiv']=4;
		
		$this->load->view('site',$data);
	}
}
?>