<?php
class Mevents extends Model
{
	var $ev;
	var $ho;
	var $nap;
	
	var $today;
    var $registration;
	
	function __construct(){
		parent::Model();
		$now = time();
		
		$this->ev = date('Y',$now);
		$this->ho = date('m',$now);
		$this->nap = date('d',$now);
		
		$this->today = mktime(0,0,0,$this->ho,$this->nap+1,$this->ev);
		
        $this->registration->error_messages = array(
            'nev'           => array('hun' => 'A név kitöltése kötelező!', 'eng' => 'You must fill out your name!'),
            //'varos'         => array('hun' => 'A város kitöltése kötelező!', 'eng' => 'You must fill out your city!'),
            //'irsz'          => array('hun' => 'Az irányítószám kitöltése kötelező!', 'eng' => 'You must fill out your zip code!'),
            //'cim'           => array('hun' => 'A cím kitöltése kötelező!', 'eng' => 'You must fill out your address!'),
            'tel'           => array('hun' => 'A telefon szám kitöltése kötelező!', 'eng' => 'You must fill out your phone number!'),
            'email'         => array('hun' => 'Az e-mail kitöltése kötelező!', 'eng' => 'You must fill out your e-mail!'),
            'email_valid'   => array('hun' => 'Hibás e-mail címet adott meg!', 'eng' => 'You must enter a valid e-mail!'),
            'event_id'      => array('hun' => 'Az időpont kiválasztása kötelező!', 'eng' => 'You must choose an event!'),
            'event_main_id' => array('hun' => 'Az esemény kiválasztása kötelező!', 'eng' => 'You must choose a main event!')
        );
	}
	
	
	function get_latest($num=10,$lang=false,$simple=false,$future=true)
	{
		if($lang)
		{
			$query = $this->db->from('events')->where('event_lang',$lang);
			
		}
		else
		{
			$query = $this->db->from('events');
			
		}  
		
		if($simple)
		{
			$query = $query->select('event_id, event_title');
		}
		if($future)
		{
			$query = $query->where('event_stamp >'.$this->today);
		}
				
		$query = $query->orderby('event_stamp','asc')->limit($num)->get();
		
		if($query->num_rows()==0)
		{
			return false;
		}
		else
		{
			return $query->result();
		}
		
	}
	
	
	function get_row($faq_id)
	{
		$query = $this->db->where('event_id',$faq_id)->get('events');
		
		if($query->num_rows()!=1)
		{
			return false;
		}
		else
		{
			//$a = $query->result(); print_r($a);
			return $query->row();
		}
	}
	
	function get_row2($faq_id)
	{
		$query = $this->db->where('event_id',$faq_id)->get('events2');
		if($query->num_rows()!=1)
		{
			return false;
		}
		else
		{
			return $query->row();
		}
	}
	
    function eventFormCheck($post, $lang = 'eng'){
        $error = array();
        
        if(!isset($post['nev']) || trim($post['nev']) == ''){
            $error[] = $this->registration->error_messages['nev'][$lang];
        }
        /*if(!isset($post['varos']) || $post['varos'] == ''){
            $error[] = $this->registration->error_messages['varos'][$lang];
        }*/
        /*if(!isset($post['irsz']) || $post['irsz'] == ''){
            $error[] = $this->registration->error_messages['irsz'][$lang];
        }*/
        /*if(!isset($post['cim']) || $post['cim'] == ''){
            $error[] = $this->registration->error_messages['cim'][$lang];
        }*/
        if(!isset($post['tel']) || $post['tel'] == ''){
            $error[] = $this->registration->error_messages['tel'][$lang];
        }
        if(!isset($post['email']) || $post['email'] == ''){
            $error[] = $this->registration->error_messages['email'][$lang];
        } else {
            $this->load->helper('email');
            
            if(!valid_email($post['email'])){
                $error[] = $this->registration->error_messages['email_valid'][$lang];
            }
        }
        if(!isset($post['event_id']) || !is_numeric($post['event_id'])){
            $error[] = $this->registration->error_messages['event_id'][$lang];
        }
        if(!isset($post['event_main_id']) || !is_numeric($post['event_main_id'])){
            $error[] = $this->registration->error_messages['event_main_id'][$lang];
        }
        
        if(empty($error)){
            return false;
        } else {
            return $error;
        }
	}
    
    function checkEventMainLimit($event_main_id){
        $query = $this->db->query("SELECT f_check_event_main_limit(".$this->db->escape($event_main_id).") AS able_to_reg");
        
        if($result = $query->row()){
            if($result->able_to_reg){
                return true;
            }
        }
        
        return false;
    }
    
    function checkEventLimit($event_id){
        if ($event_id==1313)
        {
          $result = $this->db->query("SELECT 
          	(SELECT `limit` FROM cadline2.events_new WHERE event_id=1313) as `limit`,
          	(SELECT COUNT(*) AS darab FROM cadline2.events_new_registrations WHERE event_id=1313 AND active=1 AND deleted=0) AS `foglalt`")->row();
          $ret=($result->limit > $result->foglalt ? TRUE : FALSE);
          return ($ret);            
        }
        else 
        {
          $query = $this->db->query("SELECT f_check_event_limit(".$this->db->escape($event_id).") AS able_to_reg");
          
          if($result = $query->row()){
              if($result->able_to_reg){
                  return true;
              }
          }
          
          return false;
        }
    }
    
    function checkEventMultpileRegistration($email, $event_id){
        $query = $this->db->query("SELECT f_check_event_multiple_registration(".$this->db->escape($email).", ".$this->db->escape($event_id).") AS able_to_reg");
        
        if($result = $query->row()){
            if($result->able_to_reg){
                return true;
            }
        }
        
        return false;
    }
    
    function EventRegistration($details){
        $data = array(
            'event_main_id' => $details['event_main_id'],
            'event_id' => $details['event_id'],
            'name' => $details['nev'],
            'company_name' => $details['cegnev'],
            'zip' => $details['irsz'],
            'city' => $details['varos'],
            'address' => $details['cim'],
            'phone' => $details['tel'],
            'comment' => $details['comment'],
            'email' => $details['email']
        );
		
		if( isset($details['nolimit']) && $details['nolimit']===true )
			$data['name'] = $data['name']." (vl)";
		
		if( isset($details['parkolo']) && $details['parkolo']>0 )
			$data['parkolo'] = 1;
		
		if(isset($details['gep']) && $details['gep']>0)
			$data['gep'] = 1;
        
        if( $details['nolimit']!==true && !$this->checkEventLimit($details['event_id']) ){
            return 'limit';
        } elseif(!$this->checkEventMultpileRegistration($details['email'], $details['event_id'])){
            return 'multiple';
        } else {
            $this->db->insert('events_new_registrations', $data);
            return 'success';
        }
    }
    
    function getEvents($event_main_id = false){
        if($event_main_id){
            $this->db->where('event_main_id', $event_main_id)->order_by("start_ts DESC");
        }
        
        $query = $this->db->get('v_events');
        
        if($query->num_rows() == 0){
            return false;
        } else {
            foreach($query->result() as $row){
                $row->able_to_reg = $this->checkEventLimit($row->event_id);
				$query2 = $this->db->query("SELECT online, location, csoport FROM events_new WHERE event_id = ".$row->event_id)->row();
				$row->online   = $query2->online;
				$row->location = $query2->location;
				$row->csoport  = $query2->csoport;
            }
            
            return $query->result();
        }
    }
    
    function getEventDetailsByID($event_id){
        $query = $this->db->where('event_id', $event_id)->get('v_events');
        
        if($query->num_rows() == 0){
            return false;
        } else {   
            return $query->row();
        }
    }
    
    function getMainEvents($lang = 'hun', $public = false){
        if($public){
            $this->db->where('active', true);
        }
        
        $query = $this->db->where('sort_language_name', $lang)->order_by('event_main_start_ts', 'asc')->get('v_events_main');
        
        if($query->num_rows() == 0){
            return false;
        } else {
            foreach($query->result() as $row){
                $row->able_to_reg = $this->checkEventMainLimit($row->event_main_id);
                $query2 = " SELECT rss, fokep, shorttext FROM events_new_main WHERE event_main_id = " . $row->event_main_id;
                $query2 = $this->db->query($query2)->result();
                $row->rss = $query2[0]->rss;
                $row->fokep = $query2[0]->fokep;
                $row->shorttext = $query2[0]->shorttext;
            }
            
            return $query->result();
        }
    }
    
    function getEventImages($main_id){
    	return $this->db->query(" SELECT * FROM `cadline2`.`events_new_main` WHERE event_main_id = ".$main_id)->row();
    }
    
    
    function getWorkshop($lang = 'hun', $public = false){
        if($public){
            $this->db->where('active', true);
        }
        
        $ido = time();
        $felt = 'event_main_start_ts > '.$ido;
        
        if( is_numeric($lang) ){
        	$query = $this->db->where('language_id', $lang);
        	$query = $this->db->where('event_main_id != 33')->where('deleted',0)->order_by('start_ts', 'asc')->get('events_new_main');
        }
        else{
        	$query = $this->db->where('sort_language_name', $lang);
        	$query = $this->db->where('event_main_id != 33')->order_by('event_main_start_ts', 'asc')->get('v_events_main');
        }
        
       // $query = $this->db->where('event_main_id != 33')->order_by('event_main_start_ts', 'asc')->/*get('events_new_main');*/get('v_events_main');
        
        if($query->num_rows() == 0){
            return false;
        } else {
            foreach($query->result() as $row){
                $row->able_to_reg = $this->checkEventMainLimit($row->event_main_id);
                $query2 = " SELECT rss FROM events_new_main WHERE event_main_id = " . $row->event_main_id;
                $query2 = $this->db->query($query2)->result();
                $row->leiras = "Leírás<br><br>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
                
                $page=$this->mpages->get_row($row->archline_page);
                //$row->leiras = $page->page_body;
                
                
                $row->rss = $query2[0]->rss;
                
                /* .. */
                /* angol es magyar */
                $leirasok = array(
                	14 => 533,
                	15 => 532,
                	16 => 534,
                	19 => 536,
                	20 => 537,
                	21 => 538,
                	22 => 535,
                	23 => 539,
                	30 => 562,
                	35 => 583,
                	59 => 763,
                	
                	
                	
                	10 => 546,
                	11 => 545,
                	13 => 547,
                	24 => 548,
                	25 => 549,
                	26 => 550,
                	27 => 551,
                	28 => 552,
                	29 => 561,
                	31 => 564,
                	32 => 573,
                	34 => 581,
                	55 => 729
                );
                
                $id = $row->event_main_id;
                $id2 = $leirasok[$id];
                $page = $this->mpages->get_row($id2);
                $row->leiras = $page->page_body;
                /* .. */
            }
            
            return $query->result();
        }
    }
    
    
    function getMainEventDetails($event_main_id){
        $query = $this->db->where('event_main_id', $event_main_id)->limit(1)->get('v_event_details');
        
        if($query->num_rows() == 0){
            return false;
        } else {
            $row = $query->row();
            
            $row->able_to_reg = $this->checkEventMainLimit($row->event_main_id);
            
            return $row;
        } 
    }
    
    function getRegistrations($event_id){
        $query = $this->db->where('event_id', $event_id)->get('v_event_registrations2');
        
        if($query->num_rows() == 0){
            return false;
        } else {
            return $query->result();
        }
    }
    
    function getRegistrationDetails($reg_id){
        $query = $this->db->where('reg_id', $reg_id)->get('v_event_registrations');
        
        if($query->num_rows() == 0){
            return false;
        } else {
            return $query->row();
        }
    }
    
    function getEventsByMainEventID($event_main_id, $public = false){
        if($public){
            $this->db->where('active', true);
        }
        
        $felt = "start_ts > ".time();
        $query = $this->db->where('event_main_id', $event_main_id)->where($felt)->order_by('start_ts')->get('v_events');
        
        if($query->num_rows() == 0){
            return false;
        } else {
            return $query->result();
        }
    }
    
    function getEventDatesByDay($event_main_id, $public = false, $online = false){
		
		if($online){
			
			if($public){
				$this->db->where('active', true);
			}
			if($online){
				$this->db->where('online', true);
			}
			
			$felt = "start_ts > ".time();
			$query = $this->db->where('event_main_id', $event_main_id)->where($felt)->order_by('start_ts')->get('events_new');
			
			if($query->num_rows() == 0){
				$events = false;
			} else {
				$events = $query->result();
			}
				
		//	$events = $this->getEventsByMainEventID($event_main_id, $public);
        
			if($events){
				$return_events = array();
				
				foreach($events as $event){
					//insert registrated users
					$event->able_to_reg = $this->checkEventLimit($event->event_id);
					
					$return_events['events'][strtotime(date('Y-m-d', $event->start_ts))][date('H:i', $event->start_ts).' - '.date('H:i', $event->end_ts)] = $event;
					$return_events['times'][date('H:i', $event->start_ts).' - '.date('H:i', $event->end_ts)] = date('H:i', $event->start_ts).' - '.date('H:i', $event->end_ts);
				}
				
				return $return_events;
			}
			return false;
		}
		
		
		// ha nem online
		
        $events = $this->getEventsByMainEventID($event_main_id, $public);
        
        if($events){
            $return_events = array();
            
            foreach($events as $event){
                //insert registrated users
                $event->able_to_reg = $this->checkEventLimit($event->event_id);
                
                $return_events['events'][strtotime(date('Y-m-d', $event->start_ts))][date('H:i', $event->start_ts).' - '.date('H:i', $event->end_ts)] = $event;
                $return_events['times'][date('H:i', $event->start_ts).' - '.date('H:i', $event->end_ts)] = date('H:i', $event->start_ts).' - '.date('H:i', $event->end_ts);
            }
            
            return $return_events;
        }
        
        return false;
    }
    
    
    
    function getEventDatesByMonth($honap, $ev = "2011", $public = false){
        //$events = $this->getEventsByMainEventID($event_main_id, $public);
        $events = $this->db->query(" SELECT * FROM `cadline2`.`events_new` ")->result();
        
        
        if($events){
            $return_events = array();
            if(hun())
            	$nyelv = 1;
            else
            	$nyelv = 2;
            
            
            foreach($events as $event){
                $query = " SELECT * FROM `cadline2`.`events_new_main`  WHERE event_main_id = '".$event->event_main_id."' AND language_id = '".$nyelv."'";
                $foesemeny = $this->db->query($query)->row();
                
                if( isset($foesemeny->name) )
                	$foesemenyneve = $foesemeny->name;
                else
                	$foesemenyneve = false;
                
                if( $foesemenyneve && date('Y', $event->start_ts) == $ev  &&  date('m', $event->start_ts) == $honap ){
                	$uj['nap'] = date('d', $event->start_ts);
                	$uj['nev'] = $foesemenyneve;
                	$uj['foid'] = $foesemeny->event_main_id;
                	$return_events[] = $uj;
                }
            }
            
            return $return_events;
        }
        
        return false;
    }
    
    
    function deleteRegistrationByID($events_new_registration_id){
        $this->db->query("SELECT f_event_registration_delete(".$this->db->escape($events_new_registration_id).")");
    }
    
    function deleteEventByID($event_id){
        $this->db->query("SELECT f_event_delete(".$this->db->escape($event_id).")");
    }
    
    function deleteMainEventByID($event_main_id){
        $this->db->query("SELECT f_event_main_delete(".$this->db->escape($event_main_id).")");
    }
    
    function checkModifyEvent($post){
        $error = array();
        
        if(!isset($post['datum']) || trim($post['datum']) == ''){
            $error[] = 'A dátum kitöltése kötelező!';
        }
        if(!isset($post['ora_kezdet']) || $post['ora_kezdet'] == ''){
            $error[] = 'Az esemény kezdetének (óra) kitöltése kötelező!';
        }
        if(!isset($post['ora_veg']) || $post['ora_veg'] == ''){
            $error[] = 'Az esemény végének (óra) kitöltése kötelező!';
        }
        if(!isset($post['perc_kezdet']) || $post['perc_kezdet'] == ''){
            $error[] = 'Az esemény kezdetének (perc) kitöltése kötelező!';
        }
        if(!isset($post['perc_veg']) || $post['perc_veg'] == ''){
            $error[] = 'Az esemény végének (perc) kitöltése kötelező!';
        }
        if(!isset($post['event_id']) || !is_numeric($post['event_id'])){
            $error[] = 'Hibás esemény azonosító!';
        }
        if(!isset($post['event_main_id']) || !is_numeric($post['event_main_id'])){
            $error[] = 'Hibás főesemény azonosító!';
        }
        
        if(empty($error)){
            return false;
        } else {
            return $error;
        }
    }
    
    function modifyEvent($post){
        if($error = $this->checkModifyEvent($post)){
            $error_str = implode('<br />', $error);
            return $error_str;
        }
        
        $post['active'] = $post['active'] ? true : false;
        $post['limit'] = $post['limit'] ? $post['limit'] : 0;
        
        $data = array(
            'start_ts' => strtotime($post['datum'].' '.$post['ora_kezdet'].':'.$post['perc_kezdet']),
            'end_ts'   => strtotime($post['datum'].' '.$post['ora_veg'].':'.$post['perc_veg']),
            'name'     => $post['nev'],
            'limit'    => $post['event_limit'],
            'active'   => $post['active'],
            'online'   => $post['online'],
            'location' => $post['location'],
            'csoport'  => $post['csoport']
        );
        
        $this->db->where('event_id', $post['event_id']);
        $this->db->update('events_new', $data);
        
        return false;
    }
    
    function checkCreateEvent($post){
        $error = array();
        
        if(!isset($post['datum']) || trim($post['datum']) == ''){
            $error[] = 'A dátum kitöltése kötelező!';
        }
        if(!isset($post['ora_kezdet']) || $post['ora_kezdet'] == ''){
            $error[] = 'Az esemény kezdetének (óra) kitöltése kötelező!';
        }
        if(!isset($post['ora_veg']) || $post['ora_veg'] == ''){
            $error[] = 'Az esemény végének (óra) kitöltése kötelező!';
        }
        if(!isset($post['perc_kezdet']) || $post['perc_kezdet'] == ''){
            $error[] = 'Az esemény kezdetének (perc) kitöltése kötelező!';
        }
        if(!isset($post['perc_veg']) || $post['perc_veg'] == ''){
            $error[] = 'Az esemény végének (perc) kitöltése kötelező!';
        }
        if(!isset($post['event_main_id']) || !is_numeric($post['event_main_id'])){
            $error[] = 'Hibás főesemény azonosító!';
        }
        
        if(empty($error)){
            return false;
        } else {
            return $error;
        }
    }
    
    function createEvent($post){
        if($error = $this->checkCreateEvent($post)){
            $error_str = implode('<br />', $error);
            return $error_str;
        }
        
        $post['active'] = $post['active'] ? true : false;
        $post['limit'] = $post['limit'] ? $post['limit'] : 0;
        
        $data = array(
            //'event_id' => $post['event_id'],
            'event_main_id' => $post['event_main_id'],
            'start_ts' => strtotime($post['datum'].' '.$post['ora_kezdet'].':'.$post['perc_kezdet']),
            'end_ts'   => strtotime($post['datum'].' '.$post['ora_veg'].':'.$post['perc_veg']),
            'name'     => $post['nev'],
            'limit'    => $post['event_limit'],
            'active'   => $post['active'],
            'online'   => $post['online'],
            'location' => $post['location'],
            'csoport'  => $post['csoport']
        );
        
        $this->db->insert('events_new', $data);
        
        return false;
    }
    
    function checkModifyMainEvent($post){
        $error = array();
        
        if(!isset($post['nev']) || trim($post['nev']) == ''){
            $error[] = 'Az esemény nevének kitöltése kötelező!';
        }
        if(!isset($post['datum_kezdet']) || trim($post['datum_kezdet']) == ''){
            $error[] = 'A dátum kezdetének kitöltése kötelező!';
        }
        if(!isset($post['datum_veg']) || trim($post['datum_veg']) == ''){
            $error[] = 'A dátum végének kitöltése kötelező!';
        }
        if(!isset($post['ora_kezdet']) || $post['ora_kezdet'] == ''){
            $error[] = 'Az esemény kezdetének (óra) kitöltése kötelező!';
        }
        if(!isset($post['ora_veg']) || $post['ora_veg'] == ''){
            $error[] = 'Az esemény végének (óra) kitöltése kötelező!';
        }
        if(!isset($post['perc_kezdet']) || $post['perc_kezdet'] == ''){
            $error[] = 'Az esemény kezdetének (perc) kitöltése kötelező!';
        }
        if(!isset($post['perc_veg']) || $post['perc_veg'] == ''){
            $error[] = 'Az esemény végének (perc) kitöltése kötelező!';
        }
        if(!isset($post['event_main_id']) || !is_numeric($post['event_main_id'])){
            $error[] = 'Hibás főesemény azonosító!';
        }
        
        if(empty($error)){
            return false;
        } else {
            return $error;
        }
    }
    
    function modifyMainEvent($post){
        if($error = $this->checkModifyMainEvent($post)){
            $error_str = implode('<br />', $error);
            return $error_str;
        }
        
        $post['active'] = $post['active'] ? true : false;
        $post['event_view_id'] = !isset($post['event_view_id']) || !is_numeric($post['event_view_id']) ? 1 : $post['event_view_id'];
        $post['limit'] = $post['limit'] ? $post['limit'] : 0;
        
        if($post['rss'] == "on") $post['rss'] = 1; else $post['rss'] = 0;
        
        $data = array(
            'name'                  => $post['nev'],
            'description'           => $post['leiras'],
            'picture_name'          => $post['kep'],
            'thumbnail_name'        => $post['thumb'],
            'homepage'              => $post['weboldal'],
            'archline_page'         => $post['archline_oldal'],
            'reg_success_page'      => $post['sikeres_reg_oldal'],
            'reg_success_mail_page' => $post['sikeres_reg_mail'],
            'reg_delete_page'       => $post['reg_torles_oldal'],
            'start_ts'              => strtotime($post['datum_kezdet'].' '.$post['ora_kezdet'].':'.$post['perc_kezdet']),
            'end_ts'                => strtotime($post['datum_veg'].' '.$post['ora_veg'].':'.$post['perc_veg']),
            'limit'                 => $post['limit'],
            'active'                => $post['active'],
            'event_view_id'         => $post['event_view_id'],
            'rss'                   => $post['rss'],
            
            'fokep'                 => $post['fokep'],
            'shorttext'             => $post['shorttext'],
            'project'               => $post['project'],
            'video'                 => $post['video'],
            'guide'                 => $post['guide'],
            'shortfile'             => $post['shortfile']
        );
        
        $this->db->where('event_main_id', $post['event_main_id']);
        $this->db->update('events_new_main', $data);
        
        return false;
    }
    
    function checkCreateMainEvent($post){
        $error = array();
        
        if(!isset($post['nev']) || trim($post['nev']) == ''){
            $error[] = 'Az esemény nevének kitöltése kötelező!';
        }
        if(!isset($post['datum_kezdet']) || trim($post['datum_kezdet']) == ''){
            $error[] = 'A dátum kezdetének kitöltése kötelező!';
        }
        if(!isset($post['datum_veg']) || trim($post['datum_veg']) == ''){
            $error[] = 'A dátum végének kitöltése kötelező!';
        }
        if(!isset($post['ora_kezdet']) || $post['ora_kezdet'] == ''){
            $error[] = 'Az esemény kezdetének (óra) kitöltése kötelező!';
        }
        if(!isset($post['ora_veg']) || $post['ora_veg'] == ''){
            $error[] = 'Az esemény végének (óra) kitöltése kötelező!';
        }
        if(!isset($post['perc_kezdet']) || $post['perc_kezdet'] == ''){
            $error[] = 'Az esemény kezdetének (perc) kitöltése kötelező!';
        }
        if(!isset($post['perc_veg']) || $post['perc_veg'] == ''){
            $error[] = 'Az esemény végének (perc) kitöltése kötelező!';
        }
        
        if(empty($error)){
            return false;
        } else {
            return $error;
        }
    }
    
    function getLanguageIDBySortName($sort_name){
        $query = $this->db->where('sort_name', $sort_name)->limit(1)->get('language');
        
        if($query->num_rows() == 0){
            return false;
        } else {
            return $query->row()->language_id;
        }
    }
    
    function createMainEvent($post){
        if($error = $this->checkCreateMainEvent($post)){
            $error_str = implode('<br />', $error);
            return $error_str;
        }
        
        $post['active'] = $post['active'] ? true : false;
        $post['event_view_id'] = !isset($post['event_view_id']) || !is_numeric($post['event_view_id']) ? 1 : $post['event_view_id'];
        $post['limit'] = $post['limit'] ? $post['limit'] : 0;
        $post['language_id'] = $this->getLanguageIDBySortName($post['lang']);
        
        if($post['rss'] == "on") $post['rss'] = 1; else $post['rss'] = 0;
        
        $data = array(
            'name'                  => $post['nev'],
            'description'           => $post['leiras'],
            'picture_name'          => $post['kep'],
            'thumbnail_name'        => $post['thumb'],
            'homepage'              => $post['weboldal'],
            'archline_page'         => $post['archline_oldal'],
            'reg_success_page'      => $post['sikeres_reg_oldal'],
            'reg_success_mail_page' => $post['sikeres_reg_mail'],
            'reg_delete_page'       => $post['reg_torles_oldal'],
            'start_ts'              => strtotime($post['datum_kezdet'].' '.$post['ora_kezdet'].':'.$post['perc_kezdet']),
            'end_ts'                => strtotime($post['datum_veg'].' '.$post['ora_veg'].':'.$post['perc_veg']),
            'limit'                 => $post['limit'],
            'active'                => $post['active'],
            'language_id'           => $post['language_id'],
            'event_view_id'         => $post['event_view_id'],
            
            'rss_date'              => $post['rss_date'],
            'rss'                   => $post['rss']
        );
        
        $this->db->insert('events_new_main', $data);
        
        return false;
    }
    
    function getEventViews(){
        $query = $this->db->get('events_new_event_views');
        
        if($query->num_rows() == 0){
            return false;
        } else {
            return $query->result();
        }
    }
    
    function get_rss($lang){
    	$lang = $this->getLanguageIDBySortName($lang);
    	$query = " SELECT rss_date datum, name title, description short, event_main_id id, archline_page page FROM events_new_main WHERE language_id = ".$lang." AND rss = 1 AND active = 1";
    	$query = $this->db->query($query)->result();
    	return $query;
    }

}
?>