<?php
class Presentation extends Controller
{
	function Presentation(){
		parent::Controller();
	}
	
	function index(){
		$this->online();
	}
	
	function online(){
		$data['title']      = 'ARCHLine.XP Online Presentation';
		$data['tartalom']   = 'presentation/online';
		$data['javascript'] = array('regformcheck');
		$data['csik']       = array('home','Presentation');
		$this->load->view('site',$data);
	}
	
	function submit(){
		$this->load->model('mclusers');
		
		foreach( $_POST as $k=>$v )
			$$k = $v;
		
		if( !$strEMail || $url ){
			$record->osztaly = "Presentation";
			$record->fv = "submit";
			$record->hiba = "Nincs e-mail: ".$strEMail."\nvagy van url: ".$url."\n".print_r($_POST,true);
			$record->datum = date('Y-m-d H:i:s',time());
			$this->db->insert('a_hibak',$record);
			return;
		}
		
		
		$nUserID = $this->mclusers->get_nUserIDByEmail($strEMail,'eng');
		
		if( !$nUserID ){
			// user beszúrás
			$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']);
			
			$tomb->strName    = $strName1.' '.$strName2;
			$tomb->strCompany = $strCompany;
			$tomb->strTel     = $strTel;
			$tomb->strEMail   = $strEMail;
			$tomb->strCity    = $strCity;
			$tomb->strStreet  = $strStreet;
			$tomb->strZip     = $strZip;
			$tomb->nUserProf  = $nUserProf;
			
			$tomb->nUserType  = 0;
			
			$tomb->nCtrID     = array_search(strtolower($ctrName), $countries);
			
			$nUserID = $this->mclusers->addUserEng($tomb);
			
			
			// email beszúrás
			$tomb2->email   = $strEMail;
			$tomb2->nUserID = $nUserID;
			$tomb2->default = "1";
			$tomb2->active  = "1";
			$tomb2->deleted = "0";
			
			$this->mclusers->addUserEmailEng($tomb2);
			
		}
		
		$info = "Phone: ".$strTel.", ";
		
		if( $time != "" )
			$info .= "\n Preferred times: ".$time.", ";
		
		if( $days != "" && $days != array() ){
			$info .= "\n Preferred days: ";
			foreach( $days as $v ){
				$info .= $v.", ";
			}
		}
		
		if( $softwares != "" && $softwares != array() ){
			$info .= " Software used: ";
			foreach( $softwares as $v ){
				$info .= $v.", ";
			}
		}
		
		if( $interested != "" && $interested != array() ){
			$info .= " Interested in: ";
			foreach( $interested as $v ){
				$info .= $v.", ";
			}
		}
		
		if( $purchase != "" ){
			$info .= "\n I intend to purchase a CAD: ".$purchase.", ";
		}
		
		if( $addnotes != "" && $addnotes != "Include any additional notes" ){
			$info .= "\nAdditional notes: ".$addnotes;
		}
		
		$this->mclusers->addEvent($nUserID, "133", $info, 'eng');
		
		$page = $this->mpages->get_row(642);
		
		
		$this->load->library('email');
		$this->email->initialize();
		$this->email->from('info@archlinexp.com', 'ARCHLineXP.com');
		$this->email->subject("ARCHLine.XP Online Presentation");
		$this->email->message("New Request: ".$strName1.' '.$strName2.", ".$strTel.", ".$strEMail."<br><br>".$info);
		
		$this->email->send('kitti.toth@cadline.hu', 'smtp');
		
		$this->email->clear();
		
		$this->load->library('email');
		$this->email->initialize();
		$this->email->from('info@archlinexp.com', 'Cadline Website');
		$this->email->subject('Request: Online Presentation');
		$this->email->message($page->page_body);
		
		$this->email->send($strEMail, 'smtp');
		
		if( !$this->input->post('mobile') )
			redirect('page/show/480');
		else
			redirect('mobile/page/480');
		
	}
	
	function webinar(){
		$this->load->model('mevents');
		$this->load->library('dateclass');
		
		if($this->muser->user['lang'] == "hun")
			$lang = 1;
		else
			$lang = 2;
		
		$main_events = $this->mevents->getWorkshop($lang, true);
		
		$urlveg = $this->uri->segment(3);
		
		$data['event'] = $this->db->query("SELECT * FROM events_new_main WHERE urlname = '".$urlveg."' AND language_id = ".$lang)->row();
		
		if( $data['event'] ){
			$data['dates'] = $this->db->query("SELECT * FROM events_new WHERE event_main_id = '".$data['event']->event_main_id."' AND start_ts > ".time()." AND (online IS NULL OR online = '0') AND active = 1 AND deleted = 0 ORDER BY start_ts")->result();
			$data['datesonline'] = $this->db->query("SELECT * FROM events_new WHERE event_main_id = '".$data['event']->event_main_id."' AND start_ts > ".time()." AND online = '1' AND active = 1 AND deleted = 0 ORDER BY start_ts")->result();
			
			$results = $this->mevents->getEventDatesByDay($data['event']->event_main_id, true);
			$resultsonline = $this->mevents->getEventDatesByDay($data['event']->event_main_id, true, true);
			$data['dates']->events = $results['events'];
			$data['dates']->times = $results['times'];
			$data['datesonline']->events = $resultsonline['events'];
			$data['datesonline']->times = $resultsonline['times'];
			foreach($data['dates'] as $date){
				$date->times->able_to_reg = $this->mevents->checkEventLimit($date->event_id);
			}
			foreach($data['datesonline'] as $date){
				$date->times->able_to_reg = $this->mevents->checkEventLimit($date->event_id);
			}
			
			$data['altalanos'] = false;
			
			if( $this->uri->segment(4) == "register" ){
				$this->phpsession->save('wshiba'," ");
			}
			
			if(in_array($urlveg,$kezdo))
				$data['arkat'] = 'event_arkezdo';
			else
				$data['arkat'] = 'event_arhalado';
			
		} // Ha nem workshop tema
		else{
			$data['event'] = $this->db->query("SELECT * FROM pages WHERE page_url = '".$urlveg."' AND page_lang = '".$this->muser->user['lang']."'")->row();
			
			$data['altalanos'] = true;
		}
		
		$data['akt'] = $urlveg;
		
		$data['tartalom'] = 'presentation/webinar';
		
		$cimfolyt = $data['event']->name;
		if( strstr($_SERVER[ 'REQUEST_URI'], "/hu/") )
			$cimfolyt = str_replace(array("(1-es szint)","(2-es szint)","(3-as szint)"),array("","",""),$data['event']->name);
		
		$data['title'] = hun() ? 'ARCHLine.XP Interior Workshop - '.$cimfolyt : 'ARCHLine.XP Interior - '.$data['event']->name;
		$data['javascript'] = array('jquery_ui','fancybox/jquery-1.3.2.min','fancybox/jquery.easing.1.3','fancybox/jquery.fancybox-1.2.1.pack','fancybox/fancy');
		$data['style'] = array('jquery.ui','fancybox2','workshop');
	//	$data['csik'] = array('home', 'courses');
		
		$this->load->view('site',$data);
	
	}
	
	function submitwebinar(){
		$this->load->model('mclusers');
		$this->load->model('mevents');
		
		foreach( $_POST as $k=>$v )
			$$k = $v;
		
		if( !$email || $url ){
			$record->osztaly = "Presentation";
			$record->fv = "submitwebinar";
			$record->hiba = "Nincs e-mail: ".$email."\nvagy van url: ".$url."\n".print_r($_POST,true);
			$record->datum = date('Y-m-d H:i:s',time());
			$this->db->insert('a_hibak',$record);
			return;
		}
		
		$info = "Phone: ".$tel.", ";
		
		if( $softwares != "" && $softwares != array() ){
			$info .= " Software used: ";
			foreach( $softwares as $v ){
				$info .= $v.", ";
			}
		}
		
		if( $purchase != "" ){
			$info .= "\n I intend to purchase a CAD: ".$purchase.", ";
		}
		
		
		if( $comment != "" ){
			$info .= "\nComment: ".mysql_real_escape_string($comment);
		}
		
		if(hun())
			$nUserID = $this->mclusers->get_nUserIDByEmail($email,'hun');
		else
			$nUserID = $this->mclusers->get_nUserIDByEmail($email,'eng');
		
		if( !$nUserID ){
			// user beszúrás
			$tomb->strName  = $nev;
			$tomb->strTel   = $tel;
			$tomb->strMobil = $tel;
			$tomb->strEMail = $email;
			$tomb->strZip   = $irsz;
			$tomb->strCity  = $varos;
			$tomb->strStreet = $cim;
			$tomb->nUserType = 0;
			$tomb->nCtrID    = 0;
			$tomb->strCompany = $cegnev;
			$tomb->strInfo    = "";
			
			if(hun())
				$nUserID = $this->mclusers->addUserHun($tomb);
			else
				$nUserID = $this->mclusers->addUserEng($tomb);
			
			
			// email beszúrás
			$tomb2->email = $email;
			$tomb2->nUserID = $nUserID;
			$tomb2->default = "1";
			$tomb2->active = "1";
			$tomb2->deleted = "0";
			
			if(hun())
				$this->mclusers->addUserEmailHun($tomb2);
			else
				$this->mclusers->addUserEmailEng($tomb2);
			
		}
		
		$main_event_details = $this->mevents->getMainEventDetails($event_main_id);
		
		// ha nincs időpont
		if(!$event_id){
			header("Location: ".$_SERVER['HTTP_REFERER']);
			
		}// ha időpontot kér
		elseif($event_id=="online"){
			$info .= "Request an appointment ";
			
			$info .= "Webinar kérés".", subject: ".$main_event_details->name;
		//	$this->mclusers->levelesemeny($email, "presentation", "submitwebinar", 172, "adf89dfdDEd", $info, "eng", $info);
			
			$lap = $this->mpages->get_row($main_event_details->reg_success_mail_page);
			$lap->page_body = str_ireplace('#reg_name#', $nev, $lap->page_body);
			$data['cimlap'] = $lap;
			
		}// ha egy kiírt időpontra jelentkezik
		else{
			
			$post['event_main_id'] = $event_main_id;
			$post['event_id']      = $event_id;
			$post['nev']    = $nev;
			$post['cegnev'] = $cegnev;
			$post['irsz']   = $irsz;
			$post['varos']  = $varos;
			$post['cim']    = $cim;
			$post['tel']    = $tel;
			$post['comment'] = $comment;
			$post['email']  = $email;
			
			$result = $this->mevents->EventRegistration($post);
			$datum = date('Y-m-d', time());
			
			if($result == 'limit'){
				//get the content of the limit page
				$data['cimlap'] = hun() ? $this->mpages->get_row(489) : $this->mpages->get_row(481);
			}elseif($result == 'multiple'){
				//get the content of the multiple registration page
				$data['cimlap'] = hun() ? $this->mpages->get_row(488) : $this->mpages->get_row(482);
			}else{
				$event_details = $this->mevents->getEventDetailsByID($event_id);
				$start = date('Y-m-d H:i',$event_details->start_ts);
				$end = date('Y-m-d H:i',$event_details->end_ts);
				
				$lap = $this->mpages->get_row($main_event_details->reg_success_page);
				$lap->page_body = str_ireplace('#reg_name#', $nev, $lap->page_body);
				$data['cimlap'] = $lap;
				
				$datum = date('F d, Y \&\n\b\s\p\;\&\n\b\s\p\;H:i a',$event_details->start_ts)." - ".date('H:i a',$event_details->end_ts)." GMT";
				$page = $this->mpages->get_row($main_event_details->reg_success_mail_page);
				$page->page_body = str_ireplace('#webinarcim#', $main_event_details->name, $page->page_body);
				$page->page_body = str_ireplace('#datum#', $datum, $page->page_body);
				
				$info .= $main_event_details->name;
				$datum = date('Y-m-d', $event_details->start_ts);
			}
		}
		
		
		
		if(hun()){
			$query = "INSERT INTO `clusers`.`cl_history` VALUES (NULL, ".$nUserID.", 0, '".$datum."', 'web', '".$info."', 0)";
			$this->db->query($query);
		}
		else{
			$this->mclusers->addEvent($nUserID, 172, $info, 'eng', $datum);
		}
		
		if(!$page) $page = $this->mpages->get_row(642);
		
		$this->load->library('email');
		$this->email->initialize();
		$this->email->from('info@archlinexp.com', 'ARCHLineXP.com');
		$this->email->subject("ARCHLine.XP Webinar");
		$this->email->message("New Request: ".$nev.", ".$tel.", ".$email."<br><br>".$info);
		
		$this->email->send('kitti.toth@cadline.hu', 'smtp');
	//	$this->email->send('sztikee@gmail.com', 'smtp');
		
		$this->email->clear();
		
		$this->load->library('email');
		$this->email->initialize();
		$this->email->from('info@archlinexp.com', 'ARCHLineXP.com');
		$this->email->subject('ARCHLine.XP Webinar');
		$this->email->message($page->page_body);
		
		$this->email->send($email, 'smtp');
		
		$data['tartalom'] = 'events/registration_success';
		
		$this->load->view('site', $data);
		
		//redirect('page/show/480');
	}
	
	
	function kbb(){
		$this->load->model('mevents');
        $this->load->library('dateclass');
		
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['title'] = 'ARCHLine.XP presentations at KBB London 2013';
		$data['tartalom']='presentation/kbb';
		
		$results = $this->mevents->getEventDatesByDay(60, true);
	//	print_r($results);
		
		$events2 = array();
		$eventsxxx = $this->mevents->getEventsByMainEventID(60, true);
		foreach($eventsxxx as $event){
			$event->able_to_reg = $this->mevents->checkEventLimit($event->event_id);
			$return_events[strtotime(date('Y-m-d', $event->start_ts))][date('H:i', $event->start_ts).' - '.date('H:i', $event->end_ts)] = $event;
		}
	//	print_r($return_events);
		
		$data['times'] = $results['times'];
		$data['esemenyek'] = $return_events;
		
		$do = $this->input->post('do');
		
		if($do){
			$post = array();
			
			$post['nev'] = $this->input->post('nev');
			$post['cegnev'] = $this->input->post('cegnev');
			$post['varos'] = $this->input->post('varos');
			$post['irsz'] = $this->input->post('irsz');
			$post['cim'] = $this->input->post('cim');
			$post['tel'] = $this->input->post('tel');
			$post['email'] = $this->input->post('email');
			$post['comment'] = $this->input->post('comment');
			$post['event_id'] = $this->input->post('construma2012');
			$post['event_main_id'] = 60;
			
			if($error = $this->mevents->eventFormCheck($post, $this->muser->user['lang'])){
				$data['error'] = implode('<br />', $error);
			} else {
				//insert registration into the database
				$result = $this->mevents->EventRegistration($post);
				
				//collecting main event details
				$main_event_details = $this->mevents->getMainEventDetails(60);
				
				if($result == 'success'){
					$event_details = $this->mevents->getEventDetailsByID($post['event_id']);
					
					//collect the event's and user's data for the emails
					$mail_data = array(
						'nev' => $post['nev'],
						'cegnev' => $post['cegnev'],
						'varos' => $post['varos'],
						'irsz' => $post['irsz'],
						'cim' => $post['cim'],
						'tel' => $post['tel'],
						'email' => $post['email'],
						'comment' => $post['comment'],
						'start' => date('Y-m-d H:i',$event_details->start_ts),
						'end' => date('Y-m-d H:i',$event_details->end_ts),
						'event_details' => $this->mevents->getEventDetailsByID($post['event_id']),
						'main_event_details' => $main_event_details
					);
					
					//send an email to cadline
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'Cadline Website');
					$this->email->subject('ARCHLine.XP Presentation Registration');
					$this->email->message($this->load->view('courses/mail/reg_success_to_cadline', $mail_data, true));
					
					$this->email->send('info@archlinexp.com', 'smtp');
				//	$this->email->send('sztikee@gmail.com', 'smtp');
					$this->email->clear();
					
					//send an email to the registered user
					$page = $this->mpages->get_row($main_event_details->reg_success_mail_page);
					$page->page_body = str_ireplace('#reg_name#',$post['nev'],$page->page_body);
					
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'ARCHLine.XP');
					$this->email->subject('ARCHLine.XP Presentation Registration');
					$this->email->message($page->page_body);
					
					$this->email->send($post['email'], 'smtp');
					
					// kek konyv esemeny
					$this->load->model('mclusers');
					$email = $post['email'];
					$nUserID = $this->mclusers->get_nUserIDByEmail($email,'eng');
					
					if(!$nUserID){
						$tomb['strName']    = $post['nev'];
						$tomb['strCompany'] = $post['cegnev'];
						$tomb['strCity']    = $post['varos'];
						$tomb['strZip']     = $post['irsz'];
						$tomb['strMobil']   = $post['tel'];
						$tomb['strTel']     = $post['tel'];
						$nUserID = $this->mclusers->addUserEng($tomb);
						
						$tomb2['nUserID'] = $nUserID;
						$tomb2['email']   = $post['email'];
						$this->mclusers->addUserEmailEng($tomb2);
					}
					
					
					$tomb3['nUserID']   = $nUserID;
					$tomb3['nTopicID']  = 113;
					$tomb3['dateEvent'] = date('Y-m-d', $event_details->start_ts);
					$tomb3['strPlace']  = "web";
					$tomb3['strInfo']   = "KBB presentation, ".$event_details->name." ".$idopontkimenolevelbe;
					$tomb3['nManagerID'] = 0;
					$this->db->insert('clusers_eng.cl_history',$tomb3);
					
					//get the content of the success page
					$data['cimlap'] = $this->mpages->get_row($main_event_details->reg_success_page);
					$data['cimlap']->page_body = str_ireplace('#reg_name#',$post['nev'],$data['cimlap']->page_body);
				} elseif($result == 'limit') {
					//get the content of the limit page
					$data['cimlap'] = hun() ? $this->mpages->get_row(489) : $this->mpages->get_row(481);
				} elseif($result == 'multiple') {
					//get the content of the multiple registration page
					$data['cimlap'] = hun() ? $this->mpages->get_row(488) : $this->mpages->get_row(482);
				}
				
				$data['tartalom'] = 'events/registration_success';
			}
		}
		
		$this->load->view('site',$data);
	}
	
	function birmingham(){
		$this->load->model('mevents');
		$this->load->library('dateclass');
		
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['title'] = 'ARCHLine.XP presentations at Ineriors UK 2014';
		$data['tartalom']='presentation/birmingham';
		
		$data['mainevent']  = $this->db->query("SELECT * FROM events_new_main WHERE event_main_id=64")->row();
		
		$results = $this->mevents->getEventDatesByDay(64, true);
		
		$events2 = array();
		$eventsxxx = $this->mevents->getEventsByMainEventID(64, true);
		foreach($eventsxxx as $event){
			$event->able_to_reg = $this->mevents->checkEventLimit($event->event_id);
			$return_events[strtotime(date('Y-m-d', $event->start_ts))][date('H:i', $event->start_ts).' - '.date('H:i', $event->end_ts)] = $event;
		}
		
		$data['times'] = $results['times'];
		$data['esemenyek'] = $return_events;
		
		$do = $this->input->post('do');
		
		if($do){
			$post = array();
			
			$post['nev'] = $this->input->post('nev');
			$post['cegnev'] = $this->input->post('cegnev');
			$post['varos'] = $this->input->post('varos');
			$post['irsz'] = $this->input->post('irsz');
			$post['cim'] = $this->input->post('cim');
			$post['tel'] = $this->input->post('tel');
			$post['email'] = $this->input->post('email');
			$post['comment'] = $this->input->post('comment');
			$post['event_id'] = $this->input->post('construma2012');
			$post['event_main_id'] = 62;
			
			if($error = $this->mevents->eventFormCheck($post, $this->muser->user['lang'])){
				$data['error'] = implode('<br />', $error);
			} else {
				//insert registration into the database
				$result = $this->mevents->EventRegistration($post);
				
				//collecting main event details
				$main_event_details = $this->mevents->getMainEventDetails(62);
				
				if($result == 'success'){
					$event_details = $this->mevents->getEventDetailsByID($post['event_id']);
					
					//collect the event's and user's data for the emails
					$mail_data = array(
						'nev' => $post['nev'],
						'cegnev' => $post['cegnev'],
						'varos' => $post['varos'],
						'irsz' => $post['irsz'],
						'cim' => $post['cim'],
						'tel' => $post['tel'],
						'email' => $post['email'],
						'comment' => $post['comment'],
						'start' => date('Y-m-d H:i',$event_details->start_ts),
						'end' => date('Y-m-d H:i',$event_details->end_ts),
						'event_details' => $this->mevents->getEventDetailsByID($post['event_id']),
						'main_event_details' => $main_event_details
					);
					
					//send an email to cadline
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'Cadline Website');
					$this->email->subject('ARCHLine.XP Presentation Registration');
					$this->email->message($this->load->view('courses/mail/reg_success_to_cadline', $mail_data, true));
					
					$this->email->send('info@archlinexp.com', 'smtp');
				//	$this->email->send('sztikee@gmail.com', 'smtp');
					$this->email->clear();
					
					//send an email to the registered user
					$page = $this->mpages->get_row($main_event_details->reg_success_mail_page);
					$page->page_body = str_ireplace('#reg_name#',$post['nev'],$page->page_body);
					
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'ARCHLine.XP');
					$this->email->subject('ARCHLine.XP Presentation Registration');
					$this->email->message($page->page_body);
					
					$this->email->send($post['email'], 'smtp');
					
					// kek konyv esemeny
					$this->load->model('mclusers');
					$email = $post['email'];
					$nUserID = $this->mclusers->get_nUserIDByEmail($email,'eng');
					
					if(!$nUserID){
						$tomb['strName']    = $post['nev'];
						$tomb['strCompany'] = $post['cegnev'];
						$tomb['strCity']    = $post['varos'];
						$tomb['strZip']     = $post['irsz'];
						$tomb['strMobil']   = $post['tel'];
						$tomb['strTel']     = $post['tel'];
						$nUserID = $this->mclusers->addUserEng($tomb);
						
						$tomb2['nUserID'] = $nUserID;
						$tomb2['email']   = $post['email'];
						$this->mclusers->addUserEmailEng($tomb2);
					}
					
					$eseminfo  = "Birmingham presentation, ".$event_details->name.", ".$post['comment'];
					$esemdatum = date('Y-m-d', $event_details->start_ts);
					$this->mclusers->addEvent($nUserID, 134, $eseminfo, 'eng', $esemdatum);
					
					
					//get the content of the success page
					$data['cimlap'] = $this->mpages->get_row($main_event_details->reg_success_page);
					$data['cimlap']->page_body = str_ireplace('#reg_name#',$post['nev'],$data['cimlap']->page_body);
				} elseif($result == 'limit') {
					//get the content of the limit page
					$data['cimlap'] = hun() ? $this->mpages->get_row(489) : $this->mpages->get_row(481);
				} elseif($result == 'multiple') {
					//get the content of the multiple registration page
					$data['cimlap'] = hun() ? $this->mpages->get_row(488) : $this->mpages->get_row(482);
				}
				
				$data['tartalom'] = 'events/registration_success';
			}
		}
		
		$this->load->view('site',$data);
	}
	
	function decorex(){
		$this->load->model('mevents');
        $this->load->library('dateclass');
		
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['title'] = 'ARCHLine.XP presentations at Decorex 2013';
		$data['tartalom']='presentation/decorex';
		
		$results = $this->mevents->getEventDatesByDay(62, true);
	//	print_r($results);
		
		$events2 = array();
		$eventsxxx = $this->mevents->getEventsByMainEventID(62, true);
		foreach($eventsxxx as $event){
			$event->able_to_reg = $this->mevents->checkEventLimit($event->event_id);
			$return_events[strtotime(date('Y-m-d', $event->start_ts))][date('H:i', $event->start_ts).' - '.date('H:i', $event->end_ts)] = $event;
		}
	//	print_r($return_events);
		
		$data['times'] = $results['times'];
		$data['esemenyek'] = $return_events;
		
		$do = $this->input->post('do');
		
		if($do){
			$post = array();
			
			$post['nev'] = $this->input->post('nev');
			$post['cegnev'] = $this->input->post('cegnev');
			$post['varos'] = $this->input->post('varos');
			$post['irsz'] = $this->input->post('irsz');
			$post['cim'] = $this->input->post('cim');
			$post['tel'] = $this->input->post('tel');
			$post['email'] = $this->input->post('email');
			$post['comment'] = $this->input->post('comment');
			$post['event_id'] = $this->input->post('construma2012');
			$post['event_main_id'] = 62;
			
			if($error = $this->mevents->eventFormCheck($post, $this->muser->user['lang'])){
				$data['error'] = implode('<br />', $error);
			} else {
				//insert registration into the database
				$result = $this->mevents->EventRegistration($post);
				
				//collecting main event details
				$main_event_details = $this->mevents->getMainEventDetails(62);
				
				if($result == 'success'){
					$event_details = $this->mevents->getEventDetailsByID($post['event_id']);
					
					//collect the event's and user's data for the emails
					$mail_data = array(
						'nev' => $post['nev'],
						'cegnev' => $post['cegnev'],
						'varos' => $post['varos'],
						'irsz' => $post['irsz'],
						'cim' => $post['cim'],
						'tel' => $post['tel'],
						'email' => $post['email'],
						'comment' => $post['comment'],
						'start' => date('Y-m-d H:i',$event_details->start_ts),
						'end' => date('Y-m-d H:i',$event_details->end_ts),
						'event_details' => $this->mevents->getEventDetailsByID($post['event_id']),
						'main_event_details' => $main_event_details
					);
					
					//send an email to cadline
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'Cadline Website');
					$this->email->subject('ARCHLine.XP Presentation Registration');
					$this->email->message($this->load->view('courses/mail/reg_success_to_cadline', $mail_data, true));
					
					$this->email->send('info@archlinexp.com', 'smtp');
				//	$this->email->send('sztikee@gmail.com', 'smtp');
					$this->email->clear();
					
					//send an email to the registered user
					$page = $this->mpages->get_row($main_event_details->reg_success_mail_page);
					$page->page_body = str_ireplace('#reg_name#',$post['nev'],$page->page_body);
					
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'ARCHLine.XP');
					$this->email->subject('ARCHLine.XP Presentation Registration');
					$this->email->message($page->page_body);
					
					$this->email->send($post['email'], 'smtp');
					
					// kek konyv esemeny
					$this->load->model('mclusers');
					$email = $post['email'];
					$nUserID = $this->mclusers->get_nUserIDByEmail($email,'eng');
					
					if(!$nUserID){
						$tomb['strName']    = $post['nev'];
						$tomb['strCompany'] = $post['cegnev'];
						$tomb['strCity']    = $post['varos'];
						$tomb['strZip']     = $post['irsz'];
						$tomb['strMobil']   = $post['tel'];
						$tomb['strTel']     = $post['tel'];
						$nUserID = $this->mclusers->addUserEng($tomb);
						
						$tomb2['nUserID'] = $nUserID;
						$tomb2['email']   = $post['email'];
						$this->mclusers->addUserEmailEng($tomb2);
					}
					
					$eseminfo  = "Decorex presentation, ".$event_details->name.", ".$post['comment'];
					$esemdatum = date('Y-m-d', $event_details->start_ts);
					$this->mclusers->addEvent($nUserID, 134, $eseminfo, 'eng', $esemdatum);
					
					
					//get the content of the success page
					$data['cimlap'] = $this->mpages->get_row($main_event_details->reg_success_page);
					$data['cimlap']->page_body = str_ireplace('#reg_name#',$post['nev'],$data['cimlap']->page_body);
				} elseif($result == 'limit') {
					//get the content of the limit page
					$data['cimlap'] = hun() ? $this->mpages->get_row(489) : $this->mpages->get_row(481);
				} elseif($result == 'multiple') {
					//get the content of the multiple registration page
					$data['cimlap'] = hun() ? $this->mpages->get_row(488) : $this->mpages->get_row(482);
				}
				
				$data['tartalom'] = 'events/registration_success';
			}
		}
		
		$this->load->view('site',$data);
	}
	
	function decorex2(){
		$this->load->model('mclusers');
		
		$temptomb = explode("/", $_SERVER[ 'REQUEST_URI'] );
		$email = str_replace("%40","@",end($temptomb));
		
		$egyezes = "presentation/decorex";
		$info = "Decorex regisztráció megtekintve: archlinexp.com/presentation/decorex";
		
		if(UJUGYFELKEZELO===true)
			$this->mclusers->levelesemeny($email, "presentation", "decorex2", 172, $egyezes, $info, "eng");
		else
			$this->mclusers->levelesemeny($email, "presentation", "decorex2", 155, $egyezes, $info, "eng");
		
		redirect("presentation/decorex");
	}
	
	// online-short-course
	function shortcourse(){
		$data['page'] = $this->mpages->get_row(732);
		$data['title'] = 'ARCHLine.XP Short Course';
		$data['tartalom'] = 'page/show';
		$data['csik']=array('home','Short course');
		$this->load->view('site',$data);
	}
	
	/* 2012-es ujdonsagok: leiras + bemutatora jelentkezes */
	function mindegymi(){
		$data['mobilink'] = "/mobile/newfeatures";
		
		$data['tartalom'] = 'interior/ujdonsagok';
		
		$data['title'] ='ARCHLine.XP 2012 Újdonságok és bemutatók';
		$data['javascript'] = array('jquery_ui','fancybox/jquery-1.3.2.min','fancybox/jquery.easing.1.3','fancybox/jquery.fancybox-1.2.1.pack','fancybox/fancy');
		$data['style'] = array('jquery.ui','fancybox2');
		$data['csik'] = array('home','2012 Újdonságok');
		
		$this->load->view('site',$data);
	}
	
}
?>