<?php
class Workshop extends Controller{
    function __construct(){
		parent::Controller();
        $this->load->model('mevents');
        //loading library for current date display
        $this->load->library('dateclass');
	}
    
    function index(){
		
		if(hun())
			redirect('interior/workshop/nappali');
		else
			redirect('interior/workshop/reception_room');
		
		
		$main_events = $this->mevents->getMainEvents($this->muser->user['lang'], true);
		
		if(!$main_events){
			redirect('workshop/no_main_event');
		}
		
		$data['lang'] = $this->muser->user['lang'];
		$data['title'] = hun() ? 'Workshop - ARCHLine.XP CAD Software' : 'Courses - ARCHLine.XP CAD Software';
		$data['tartalom'] = 'workshop/index';
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$data['csik'] = array('home', 'courses');
		$data['error'] = false;
		
		foreach($main_events as $key => $main_event){
			$results = $this->mevents->getEventDatesByDay($main_event->event_main_id, true);
			$main_events[$key]->events = $results['events'];
			$main_events[$key]->times = $results['times'];
		}
		
		$data['main_events'] = $main_events;
		
		$do = $this->input->post('do');
		
		if(!$do){
			$this->load->view('site', $data);
		} else {
			$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('event_id');
			$post['event_main_id'] = $this->input->post('event_main_id');
			
			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($post['event_main_id']);
				
				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' => $this->mevents->getMainEventDetails($post['event_main_id'])
					);
					
					//send an email to cadline
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@cadline.hu', 'Cadline Weboldal');
					$this->email->subject($main_event_details->name.' 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->clear();
					
					//send an email to the registered user
					$page = $this->mpages->get_row($main_event_details->reg_success_mail_page);
					
					//change the users name constans in the page body
					$page->page_body = str_ireplace('#reg_name#', $mail_data['nev'], $page->page_body);
					
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'ARCHLineXP.com');
					$this->email->subject($page->page_title);
					$this->email->message($page->page_body);
					
					$this->email->send($post['email'], 'smtp');
					
					//get the content of the success page
					$data['cimlap'] = $this->mpages->get_row($main_event_details->reg_success_page);
				} 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'] = 'courses/registration_success';
			}
			
			$this->load->view('site', $data);
		}
    }
    
	function no_main_event(){
		$data['lang'] = $this->muser->user['lang'];
		$data['title'] = hun() ? 'Bemutat�k - ARCHLine.XP CAD Software' : 'Events - ARCHLine.XP CAD Software';
		$data['tartalom'] = 'courses/no_main_event';
        $data['page'] = hun() ? $this->mpages->get_row(493) : $this->mpages->get_row(494);
		if(hun())
		    $data['csik'] = array('F�oldal', 'Bemutat�k');
        else
		   $data['csik'] = array('home', 'events');
        $this->load->view('site', $data);
    }
	
	function birmingham(){
		
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['javascript'] = array('regformcheck');
		$data['title'] = 'ARCHLine.XP Interior Design Software - Birmingham 2014';
		$data['tartalom']='workshop/decorex2010';
		
		$data['mainevent']  = $this->db->query("SELECT * FROM events_new_main WHERE event_main_id=38")->row();
		$results = $this->mevents->getEventDatesByDay(38, true);
		
		$events2 = array();
		$eventsxxx = $this->mevents->getEventsByMainEventID(38, 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('strName1').' '.$this->input->post('strName2');
			$post['cegnev'] = $this->input->post('strCompany');
			$post['varos'] = $this->input->post('strCity');
			$post['irsz'] = $this->input->post('strZip');
			$post['cim'] = $this->input->post('strStreet');
			$post['tel'] = $this->input->post('strTel');
			$post['email'] = $this->input->post('strEMail');
			$post['comment'] = $this->input->post('comment');
			$post['nUserProf']  = $this->input->post('nUserProf');
			$post['event_id'] = $this->input->post('decorex2011');
			$post['event_main_id'] = 38;
			
			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(38);
				
				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' => $this->mevents->getMainEventDetails(38)
					);
					
					//send an email to cadline
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'Cadline Website');
					$this->email->subject($main_event_details->name.' 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);
					
					//change the users name constans in the page body
					$page->page_body = str_ireplace('#reg_name#', $mail_data['nev'], $page->page_body);
					
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'ARCHLineXP.com');
					$this->email->subject($page->page_title);
					$this->email->message($page->page_body);
					
					$this->email->send($post['email'], 'smtp');
					
					
					// esemény felvétele a sárga könyvbe
					$this->load->model('mclusers');
					$nUserID = $this->mclusers->get_nUserIDByEmail($post['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']);
						
						$tomb->nCtrID = array_search(strtolower($this->input->post('ctrName')), $countries);
						
						// user beszúrás
						$tomb->strName  = $post['nev'];
						$tomb->strTel   = $post['tel'];
						$tomb->strMobil = $post['tel'];
						$tomb->strEMail = $post['email'];
						$tomb->strCity  = $post['varos'];
						$tomb->strStreet = $post['cim'];
						$tomb->strZip   = $post['irsz'];
						$tomb->nUserType = 0;
						$tomb->strCompany = $post['cegnev'];
						$tomb->strInfo = "";
						$tomb->nUserProf = $post['nUserProf'];
						
						$nUserID = $this->mclusers->addUserEng($tomb);
						
						
						// email beszúrás
						$tomb2->email = $post['email'];
						$tomb2->nUserID = $nUserID;
						$tomb2->default = "1";
						$tomb2->active = "1";
						$tomb2->deleted = "0";
						
						$this->mclusers->addUserEmailEng($tomb2);
					}
					$info = "B\'ham: ".$mail_data['start']." - ".$mail_data['end']." ".$post['comment'];
					$esemdatum = date('Y-m-d', $event_details->start_ts);
					$this->mclusers->addEvent($nUserID, "226", $info, '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 construma(){
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['title'] = 'ARCHLine.XP - Construma 2013';
		$data['tartalom']='workshop/construma2012';
		
		$this->load->view('site',$data);
	}
	
	// workshop
	function construmaregisztracio(){
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui','regformcheck');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['title'] = 'ARCHLine.XP workshopok - Construma 2014';
		$data['tartalom']='workshop/construma2012reg';
		
		$results = $this->mevents->getEventDatesByDay(48, true);
		
		$events2 = array();
		$eventsxxx = $this->mevents->getEventsByMainEventID(48, 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;
			
			if( time()+9*3600 < $event->start_ts )
				$idopontok[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;
		$data['idopontok'] = $idopontok;
		
		$do = $this->input->post('do');
		
		if($do){
			foreach($_POST as $k=>$v)
				$$k = $v;
			
			$post = array();
			
			$post['nev']    = $strName1.' '.$strName2;
			$post['cegnev'] = $strCompany;
			$post['varos']  = $strCity;
			$post['irsz']   = $strZip;
			$post['cim']    = $strStreet;
			$post['tel']    = $strTel;
			$post['email']  = $strEMail;
			$post['comment'] = $this->input->post('comment');
			$post['event_id'] = $this->input->post('construma2012');
			$post['event_main_id'] = 37;
			
			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(48);
				
				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']."<br>Workshop, Választott téma: ".$this->input->post('tema'),
						'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@cadline.hu', 'Cadline Website');
					$this->email->subject($main_event_details->name.' Regisztráció');
					$this->email->message($this->load->view('courses/mail/reg_success_to_cadline', $mail_data, true));
					
					$this->email->send('info@cadline.hu', 'smtp');
					$this->email->clear();
					
					
					//send an email to the registered user
					$page = $this->mpages->get_row($main_event_details->reg_success_mail_page);
					
					$hetnapok = array("hétfő", "kedd", "szerda", "csütörtök", "péntek", "szombat", "vasárnap");
					$ennyiedik = date('N',$event_details->start_ts);
					$hetnap = $hetnapok[($ennyiedik-1)];
					$idopontkimenolevelbe = date('Y. m. d. (', $event_details->start_ts);
					$idopontkimenolevelbe .= $hetnap;
					$idopontkimenolevelbe .= date(')  H:i - ', $event_details->start_ts);
					$idopontkimenolevelbe .= date('H:i', $event_details->end_ts);
					
					//change the users name constans in the page body
					$page->page_body = str_ireplace('#name#', $mail_data['nev'], $page->page_body);
					$page->page_body = str_ireplace('#idopont#', $idopontkimenolevelbe, $page->page_body);
			//		$page->page_body = str_ireplace('#tema#', $this->input->post('tema'), $page->page_body);
					
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@cadline.hu', 'ARCHLine.hu');
					$this->email->subject($page->page_title);
					$this->email->message($page->page_body);
					
					$this->email->send($post['email'], 'smtp');
					
					// crm esemeny
					$this->load->model('mclusers');
					$email = $post['email'];
					$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']] = strtolower($orszag['ctrName']);
						
						$tomb['nCtrID'] = array_search(strtolower($ctrName), $countries);
						
						$tomb['strName']    = $post['nev'];
						$tomb['strCompany'] = $post['cegnev'];
						$tomb['strCity']    = $post['varos'];
						$tomb['strStreet']  = $post['cim'];
						$tomb['strZip']     = $post['irsz'];
						$tomb['strMobil']   = 
						$tomb['strTel']     = $post['tel'];
						$tomb['nUserProf']  = $nUserProf;
						$nUserID = $this->mclusers->addUserHun($tomb);
						
						$tomb2['nUserID'] = $nUserID;
						$tomb2['email']   = $post['email'];
						$this->mclusers->addUserEmailHun($tomb2);
					}
					
					$this->mclusers->addEvent($nUserID, 123, "Construma ws, ".$this->input->post('tema')." ".$idopontkimenolevelbe." ".$comment, 'hun',date('Y-m-d', $event_details->start_ts));
					
					
					//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);
	}
	
	// előadás
	function construmaeloadasok(){
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui','regformcheck');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['title'] = 'ARCHLine.XP előadások - Construma 2013';
		$data['tartalom']='workshop/construmaeloadas';
		
		$results = $this->mevents->getEventDatesByDay(51, true);
	//	print_r($results);
		
		$events2 = array();
		$eventsxxx = $this->mevents->getEventsByMainEventID(51, 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){
			foreach($_POST as $k=>$v)
				$$k = $v;
			
			$post = array();
			
			$post['nev']    = $strName1.' '.$strName2;
			$post['cegnev'] = $strCompany;
			$post['varos']  = $strCity;
			$post['irsz']   = $strZip;
			$post['cim']    = $strStreet;
			$post['tel']    = $strTel;
			$post['email']  = $strEMail;
			$post['comment'] = $this->input->post('comment');
			$post['event_id'] = $this->input->post('construma2012');
			$post['event_main_id'] = 51;
			
			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(51);
				
				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@cadline.hu', 'Cadline Website');
					$this->email->subject($main_event_details->name.' Regisztráció');
					$this->email->message($this->load->view('courses/mail/reg_success_to_cadline', $mail_data, true));
					
					$this->email->send('info@cadline.hu', 'smtp');
					$this->email->clear();
					
					
					//send an email to the registered user
					$page = $this->mpages->get_row($main_event_details->reg_success_mail_page);
					
					$hetnapok = array("hétfő", "kedd", "szerda", "csütörtök", "péntek", "szombat", "vasárnap");
					$ennyiedik = date('N',$event_details->start_ts);
					$hetnap = $hetnapok[($ennyiedik-1)];
					$idopontkimenolevelbe = date('Y. m. d. (', $event_details->start_ts);
					$idopontkimenolevelbe .= $hetnap;
					$idopontkimenolevelbe .= date(')  H:i - ', $event_details->start_ts);
					$idopontkimenolevelbe .= date('H:i', $event_details->end_ts);
					
					//change the users name constans in the page body
					$page->page_body = str_ireplace('#name#', $mail_data['nev'], $page->page_body);
					$page->page_body = str_ireplace('#idopont#', $idopontkimenolevelbe, $page->page_body);
					$page->page_body = str_ireplace('#tema#', $event_details->name, $page->page_body);
					
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@cadline.hu', 'ARCHLine.hu');
					$this->email->subject($page->page_title);
					$this->email->message($page->page_body);
					
					$this->email->send($post['email'], 'smtp');
					
					// crm esemeny
					$this->load->model('mclusers');
					$email = $post['email'];
					$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']] = strtolower($orszag['ctrName']);
						
						$tomb['nCtrID'] = array_search(strtolower($ctrName), $countries);
						
						$tomb['strName']    = $post['nev'];
						$tomb['strCompany'] = $post['cegnev'];
						$tomb['strCity']    = $post['varos'];
						$tomb['strStreet']  = $post['cim'];
						$tomb['strZip']     = $post['irsz'];
						$tomb['strMobil']   = $post['tel'];
						$tomb['strTel']     = $post['tel'];
						$tomb['nUserProf']  = $nUserProf;
						$nUserID = $this->mclusers->addUserHun($tomb);
						
						$tomb2['nUserID'] = $nUserID;
						$tomb2['email']   = $post['email'];
						$this->mclusers->addUserEmailHun($tomb2);
					}
					
					$this->mclusers->addEvent($nUserID, 8, "Construma előadás, ".$event_details->name." ".$idopontkimenolevelbe." ".$comment, 'hun', date('Y-m-d', $event_details->start_ts));
					
					
					//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 kbb(){
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['title'] = 'ARCHLine.XP Interior workshops at KBB London 2014';
		$data['tartalom']='workshop/kbb';
		
		$results = $this->mevents->getEventDatesByDay(35, true);
		
		$events2 = array();
		$eventsxxx = $this->mevents->getEventsByMainEventID(35, 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;
			
			if( time()+9*3600 < $event->start_ts )
				$idopontok[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;
		$data['idopontok'] = $idopontok;
		
		$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'] = 37;
			
			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(35);
				
				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']."<br>Workshop, Választott téma: ".$this->input->post('tema'),
						'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', 'ARCHLine.XP Website');
					$this->email->subject('ARCHLine.XP Workshop 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 Workshop 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']  = 137;
					$tomb3['dateEvent'] = date('Y-m-d', $event_details->start_ts);
					$tomb3['strPlace']  = "web";
					$tomb3['strInfo']   = "KBB ws, ".$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 decorex(){
		
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['title'] = 'ARCHLine.XP Interior Design Software - Decorex 2013';
		$data['tartalom']='workshop/decorex2010';
		
		$results = $this->mevents->getEventDatesByDay(54, true);
		
		$events2 = array();
		$eventsxxx = $this->mevents->getEventsByMainEventID(54, 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('decorex2011');
			$post['event_main_id'] = 54;
			
			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(54);
				
				if($result == 'success'){
					$this->load->model('mclusers');
					$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' => $this->mevents->getMainEventDetails(54)
					);
					
					//send an email to cadline
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'Cadline Website');
					$this->email->subject($main_event_details->name.' 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);
					
					//change the users name constans in the page body
					$page->page_body = str_ireplace('#reg_name#', $mail_data['nev'], $page->page_body);
					
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'ARCHLineXP.com');
					$this->email->subject($page->page_title);
					$this->email->message($page->page_body);
					
					$this->email->send($post['email'], 'smtp');
					
					
					// sárgába
					$nUserID = $this->mclusers->get_nUserIDByEmail($post['email'],'eng');
				
					if(!$nUserID){
						$tomb['strName']    = $post['nev'];
						$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, ".date('Y-m-d H:i',$event_details->start_ts).", ".$post['comment'];
					$esemdatum = date('Y-m-d', $event_details->start_ts);
					$this->mclusers->addEvent($nUserID, 226, $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 = "workshop/decorex";
		$info = "Decorex regisztráció megtekintve: archlinexp.com/workshop/decorex";
		
		if(UJUGYFELKEZELO===true)
			$this->mclusers->levelesemeny($email, "workshop", "decorex2", 172, $egyezes, $info, "eng");
		else
			$this->mclusers->levelesemeny($email, "workshop", "decorex2", 155, $egyezes, $info, "eng");
		
		redirect("workshop/decorex");
	}
	
	function interiorsuk(){
		
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['title'] = 'ARCHLine.XP Interior Design Software - Interiors UK 2012';
		$data['tartalom']='workshop/interiorsuk';
		
		$results = $this->mevents->getEventDatesByDay(58, true);
		
		$events2 = array();
		$eventsxxx = $this->mevents->getEventsByMainEventID(58, 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('decorex2011');
			$post['event_main_id'] = 58;
			
			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(58);
				
				if($result == 'success'){
					$this->load->model('mclusers');
					$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' => $this->mevents->getMainEventDetails(58)
					);
					
					//send an email to cadline
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'Cadline Website');
					$this->email->subject($main_event_details->name.' 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);
					
					//change the users name constans in the page body
					$page->page_body = str_ireplace('#reg_name#', $mail_data['nev'], $page->page_body);
					$page->page_body = str_ireplace('#start#', date('d F Y H:i',$event_details->start_ts), $page->page_body);
					$page->page_body = str_ireplace('#end#', date('H:i',$event_details->end_ts), $page->page_body);
					
					$this->email->initialize();
					$this->email->from('info@archlinexp.com', 'ARCHLineXP.com');
					$this->email->subject($page->page_title);
					$this->email->message($page->page_body);
					
					$this->email->send($post['email'], 'smtp');
					
					
					// sárgába
					$nUserID = $this->mclusers->get_nUserIDByEmail($post['email'],'eng');
				
					if(!$nUserID){
						$tomb['strName']    = $post['nev'];
						$tomb['strMobil']   = $post['tel'];
						$tomb['strTel']     = $post['tel'];
						$nUserID = $this->mclusers->addUserEng($tomb);
						
						$tomb2['nUserID'] = $nUserID;
						$tomb2['email']   = $post['email'];
						$this->mclusers->addUserEmailEng($tomb2);
					}
					
					$query .= "INSERT INTO `clusers_eng`.`cl_history` VALUES (NULL, {$nUserID}, 137, '".date('Y-m-d',$event_details->start_ts)."', 'web', '".date('Y-m-d H:i',$event_details->start_ts).", ".$post['comment']."', 0)";
		
					$this->db->query($query);
					
					
					//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 interiorsuk2(){
		$this->load->model('mclusers');
		
		$temptomb = explode("/", $_SERVER[ 'REQUEST_URI'] );
		$email = str_replace("%40","@",end($temptomb));
		
		$egyezes = "workshop/interiorsuk";
		$info = "Interiors UK regisztráció megtekintve: archlinexp.com/workshop/interiorsuk";
		
		$this->mclusers->levelesemeny($email, "workshop", "interiorsuk2", 165, $egyezes, $info, "eng");
		
		redirect("workshop/interiorsuk");
	}
	
	function registrate(){
		redirect('courses');
	}
	
	function download(){
		$this->load->model('mdownloads');
		
		$data['heading']=$this->mdownloads->get_heading('workshop');
		$data['downloads']=$this->mdownloads->get_category('workshop',$this->muser->user['lang']);
		
		$data['lang']=$this->muser->user['lang'];
		
		$data['title'] = 'ARCHLine.XP Workshop';
		$data['tartalom']='downloads/list';
		$data['csik']=array('home','downloads');
		$this->load->view('site',$data);
    }
	
	function buy(){
		if(!isset($_POST['darab'])) $_POST['darab']=1;
		$temp = "=".$_POST['darab'];
		$temp .= '&language=English';
		$head = "https://secure.shareit.com/shareit/checkout.html?productid=300308301".$temp;
		$head = "https://secure.shareit.com/shareit/checkout.html?PRODUCT[300481975]".$temp;
		header("Location: ".$head);
		exit;
	}
	
	
	function bnv(){
		
		$data['lang'] = $this->muser->user['lang'];
		$data['javascript'] = array('jquery_ui');
		$data['style'] = array('jquery.ui');
		$data['error'] = false;
		$data['title'] = 'ARCHLine.XP Interior Design Software - Decorex 2012';
		$data['tartalom']='workshop/bnv2012';
		
		$results = $this->mevents->getEventDatesByDay(55, true);
		
		$events2 = array();
		$eventsxxx = $this->mevents->getEventsByMainEventID(55, 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('bnv2012');
			$post['event_main_id'] = 55;
			
			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(55);
				
				if($result == 'success'){
					$this->load->model('mclusers');
					$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' => $this->mevents->getMainEventDetails(55)
					);
					
					//send an email to cadline
					$this->load->library('email');
					$this->email->initialize();
					$this->email->from('info@archline.hu', 'Cadline Website');
					$this->email->subject($main_event_details->name.' Regisztráció');
					$this->email->message($this->load->view('courses/mail/reg_success_to_cadline', $mail_data, true));
					
					$this->email->send('info@archline.hu', '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);
					
					//change the users name constans in the page body
					$page->page_body = str_ireplace('#name#', $mail_data['nev'], $page->page_body);
					$page->page_body = str_ireplace('#idopont#',date('Y-m-d H:i',$event_details->start_ts),$page->page_body);
					
					$this->email->initialize();
					$this->email->from('info@archline.hu', 'ARCHLine.hu');
					$this->email->subject($page->page_title);
					$this->email->message($page->page_body);
					
					$this->email->send($post['email'], 'smtp');
					
					
					// kékbe
					$nUserID = $this->mclusers->get_nUserIDByEmail($post['email'],'hun');
				
					if(!$nUserID){
						$tomb['strName']    = $post['nev'];
						$tomb['strMobil']   = $post['tel'];
						$tomb['strTel']     = $post['tel'];
						$nUserID = $this->mclusers->addUserHun($tomb);
						
						$tomb2['nUserID'] = $nUserID;
						$tomb2['email']   = $post['email'];
						$this->mclusers->addUserEmailHun($tomb2);
					}
					
					$query .= "INSERT INTO `clusers`.`cl_history` VALUES (NULL, {$nUserID}, 156, '".date('Y-m-d',$event_details->start_ts)."', 'web', '".date('Y-m-d H:i',$event_details->start_ts).", ".$post['comment']."', 0)";
		
					$this->db->query($query);
					
					
					//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('#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);
	}
	
}