<?php
class Kezzeltervez extends Controller
{
	
	function Kezzeltervez()
	{
		parent::Controller();
	}
	
	function index(){
		Header("HTTP/1.1 301 Moved Permanently");
		Header("Location: http://www.archline.hu/services/sketch");
		
		
		
		
		$this->load->model('mctr');
		
		$data['tema'] = "Kézzel tervez";
		
		if(hun())
			$data['page'] = $this->mpages->get_row(596);
		else
			$data['page'] = $this->mpages->get_row(618);
		
		hun() ? $data['ctr']=$this->mctr->get_all_ctr('ctrNameHun') : $data['ctr']=$this->mctr->get_all_ctr();
		
		$data['title'] = 'ARCHLine.XP - '.lang('kt_oldalcim')." tervek feltöltése";
		$data['tartalom']='kezzeltervez/index';
		$data['csik']=array('home','kezzeltervez');
		$this->load->view('site',$data);
	}
	
	function index2(){
		$this->load->model('mclusers');
		
		$temptomb = explode("/", $_SERVER[ 'REQUEST_URI'] );
		$email = str_replace("%40","@",end($temptomb));
		
		$egyezes = "kezzeltervez/index";
		$info = "Kézzel tervez, tervek beküldési oldala megtekintve: archline.hu/kezzeltervez/index";
		
		$this->mclusers->levelesemeny($email, "kezzeltervez", "index2", 136, $egyezes, $info, "hun");
		
		redirect("kezzeltervez");
	}
	
	function submit(){
		$this->load->model('mclusers');
		
		if(hun())
			$nyelv = "hun";
		else
			$nyelv = "eng";
		
		foreach($_POST as $k=>$v)
			$$k = $v;
		
		
		$config['upload_path'] = '/var/www/hosting/cadline.hu/www/public/img/kezzeltervez/bekuldott_kepek/'.$nyelv.'/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|tif';
		
		$kep = "<br>";
		
		$this->load->library('upload', $config);
		
		$hovakep = '/var/www/hosting/cadline.hu/www/public/img/kezzeltervez/bekuldott_kepek/'.$nyelv.'/';
		
		include('application/helpers/sajatfeltolto.php');
		for($i=1;$i<=5;$i++){
			$asd = "kep".$i;
			if(isset($_FILES, $_FILES[$asd]['name']) && $_FILES[$asd]['name'] != ''){
				$ered = feltolt($asd,$hovakep,$name."_".$_FILES[$asd]['name'],true);
				if($ered)
					$kep .= $i.". ".lang('kt_kep').": ".basename($ered)."<br> ";
				else
					$kep .= $i.". kép feltöltési hiba: ".$name."_".$_FILES[$asd]['name']."<br> ";
			}else{
				if(hun())
					$kep .= "nincs ".$i.". kép"."<br> ";
				else
					$kep .= "no ".$i.". image<br />";
			}
		}
		
		
		$message = preg_replace("/<.+>/Usi", "", $message);
	//	$message .= "<br><br><br><strong>Képek:</strong><br><br>".$kep;
		
		$nUserID = $this->mclusers->get_nUserIDByEmail($email,$nyelv);
		
		if($nUserID > 0){
			if(hun())
				$this->mclusers->addEvent($nUserID, 121, '"'.$message.'"<br>'.$kep);
			else
				$this->mclusers->addEvent($nUserID, 150, '"'.$message.'"<br>'.$kep,"eng");
		}else{
			$tomb->strName = $name;
			$tomb->strEMail = $email;
			$tomb->strTel = $tel;
			
			if(hun()){
				$nUserID = $this->mclusers->addUserHun($tomb);
				$this->mclusers->addEvent($nUserID, 121, '"'.$message.'"<br>'.$kep);
			}else{
				$nUserID = $this->mclusers->addUserEng($tomb);
				$this->mclusers->addEvent($nUserID, 150, '"'.$message.'"<br>'.$kep,"eng");
			}
			
			$tomb2->email = $email;
			$tomb2->nUserID = $nUserID;
			if(hun())
				$this->db->insert('clusers.cl_users_emails',$tomb2);
			else
				$this->db->insert('clusers_eng.cl_users_emails',$tomb2);
		}
		
		if(!hun())
			$subject = "Still drawing by hand?";
		
		$mail_data = array(
			'mailcontent' => 'mail/contact',
			'name' => $name,
			'email' => $email,
			'phone' => $tel,
			'subject' => $subject,
			'message' => $message.$kep,
			'eleje' => lang('kt_kedves')." ".$name.lang('kt_kitoltottadatok')."<br /><br />",
			'vege' => "<br />".lang('kt_udvozlettel')
		);
		
		$this->load->library('email');
		$this->email->initialize();
		
		$this->email->message($this->load->view('mail/contact', $mail_data, true));
		
		$this->email->subject(lang('kt_emailsubject'));
		if(hun()){
			$this->email->from('info@cadline.hu', 'CadLine Weboldal');
			$this->email->send('info@cadline.hu', 'smtp');
		}else{
			$this->email->from('info@archlinexp.com', 'CadLine Website');
			$this->email->send('info@archlinexp.com', 'smtp');
	//		$this->email->send('sztikee@gmail.com', 'smtp');
		}
		
		
		//Kintre:
		$this->email->clear();
		
		if(hun())
			$this->email->from('info@cadline.hu', 'CadLine Weboldal');
		else
			$this->email->from('info@archlinexp.com', 'CadLine Website');
		$this->email->subject(lang('kt_emailsubject'));
		$this->email->message($this->load->view('mail', $mail_data, true));
		$this->email->send($email,'smtp');
		
		
		$record->osztaly = "kezzeltervez";
		$record->fv = "submit";
		$record->hiba = $subject."\n".$name."\n".$email."\n".$tel."\n".$message."\n".$kep."\nország: ".$country;
		$record->datum = date('Y-m-d H:i:s',time());
		$this->db->insert('a_hibak',$record);
		
		$data['title'] = hun() ? 'Jelentkezés' : 'Jelentkezés';
		$data['tartalom'] = 'forum/kiir';
		$data['csik']=array('home');
		
		$data['info'] = "<div style='text-align: center; font-size: 1.3em;'>".lang('contact_elkuldve')."<br />".lang('kt_submit')."</div>";
		
		$this->load->view('site',$data);
	}
	
	function galeria(){
		$this->load->model('mgallery');
		
		$honap = $this->uri->segment(3);
		
	//	$data['galeriak'] = $this->mgallery->get_all('hun','kezzel');
	//	usort( $data['galeriak'], "hasonlitoId" );
		
		$data['galeriak'] = $this->db->query("SELECT * FROM `cadline2`.`gallerys` WHERE terulet='kezzel' AND deleted = 0 AND mappa = '".$honap."' ORDER BY sorszam")->result();
		
		$data['javascript'] = array(
								'fancybox/jquery-1.3.2.min',
								'fancybox/jquery.easing.1.3',
								'fancybox/jquery.fancybox-1.2.1.pack',
								'fancybox/fancy'
							);
		$data['style'] = array('fancybox_gal');
		
		$data['title'] = 'ARCHLine.XP - Még mindig kézzel tervez pályázat galéria';
		$data['tartalom']='kezzeltervez/galeria';
		$data['csik']=array('home');
		$this->load->view('site_new',$data);
	}
	
	function galeria2(){
		$this->load->model('mclusers');
		
		$temptomb = explode("/", $_SERVER[ 'REQUEST_URI'] );
		$email = str_replace("%40","@",end($temptomb));
		
		$honap = $this->uri->segment(3);
		
		$egyezes = "kezzeltervez/galeria/".$honap;
		$info = "Kézzel tervez galéria megtekintve: (http://archline.hu/kezzeltervez/galeria/".$honap.")";
		
		if(UJUGYFELKEZELO===true)
			$this->mclusers->levelesemeny($email, "kezzeltervez", "galeria2", 68, $egyezes, $info, "hun");
		else
			$this->mclusers->levelesemeny($email, "kezzeltervez", "galeria2", 130, $egyezes, $info, "hun");
		
		// atiranyitas a palyazatra
		redirect("kezzeltervez/galeria/".$honap);
		return;
	}
	
	
}

function hasonlitoId( $a, $b ){
	if ( $a->gal_id == $b->gal_id )
		return 0;
	if ( $a->gal_id < $b->gal_id )
		return -1;
	return 1;
}

?>