<?php
class Monthpicture extends Controller
{
	
	function Monthpicture()
	{
		parent::Controller();
	}
	
	function index(){
		$this->kep();
	}
	
	function kep(){
		$data['tema'] = "Hónap képe";
		
		if(hun())
			$data['page'] = $this->mpages->get_row(594);
		else
			$data['page'] = $this->mpages->get_row(623);
		
		$data['title'] = 'ARCHLine.XP - Picture of the month, send pictures';
		$data['tartalom']='palyazat/kep';
		$data['csik']=array('home','palyazat');
		$this->load->view('site',$data);
	}
	
	function gallery(){
		// ha magyar
		if(hun()){
			$link = "http://www.archline.hu/palyazat/gallery/".$this->uri->segment(3);
			if( $this->uri->segment(4)!="" )
				$link .= "/".$this->uri->segment(4);
			Header("Location: ".$link);
			exit;
		}
		
		// ha van e-mail cím
		$email = $this->uri->segment(4);
		if( $email && !is_numeric($email) ){
			
			$this->load->model('mclusers');
			
			$gal_honap = $this->uri->segment(3);
			
			// email atalakitasa
			$temptomb = explode("/", $_SERVER[ 'REQUEST_URI'] );
			$email = str_replace("%40","@",end($temptomb));
			
			
			$egyezes = "monthpicture/gallery/".$gal_honap;
			$info = "Gallery viewed: http://archlinexp.com/monthpicture/gallery/".$gal_honap;
			$hibainfo = "Eng, hónap képe: ".$gal_honap;
			
			if(UJUGYFELKEZELO===true)
				$this->mclusers->levelesemeny($email, "monthpicture", "gallery2", 185, $egyezes, $info, "eng", $hibainfo);
			else
				$this->mclusers->levelesemeny($email, "monthpicture", "gallery2", 153, $egyezes, $info, "eng", $hibainfo);
			
			redirect("monthpicture/gallery/".$gal_honap);
			return;
		}
		
		
		$this->load->model('mgallery');
		
		$data['tema'] = "Hónap képe";
		
		$data['page'] = $this->mpages->get_row(594);
		
		$honap = $this->uri->segment(3);
		if( !is_numeric($honap) ){
			$data['galeriak'] = $this->mgallery->get_all('hun','honapkepe');
			
			//redirect('monthpicture/gallery/'.(date('m',time())-1+36));
			redirect('monthpicture/gallery/'.(date('m',time())-1+48));
		}else{
			$data['galeria'] = $this->mgallery->get_rowHonapSorszam($honap, 'hun');
			//if( date('m',time()) <= ($honap-36) && date('j',time()) <= 26 )	/*if( date('m',time()) <= $honap )*/
			//{
			//	redirect('monthpicture/gallery/'.(date('m',time())-1+35));
			//}
			if( date('m',time()) <= ($honap-48) && date('j',time()) <= 26 )	/*if( date('m',time()) <= $honap )*/
			{
				redirect('monthpicture/gallery/'.(date('m',time())-1+47));
			}
		}
		
		// amíg nincs feltölve, nem lehet megnézni
		if(!$data['galeria']){
			//redirect('palyazat/gallery/'.(date('m',time())-1+35));
			redirect('palyazat/gallery/'.(date('m',time())-1+47));
		}
		
		$honapok = lang('honapok');
		
		
		$data['javascript'] = array(
								'fancybox/jquery-1.3.2.min',
								'fancybox/jquery.easing.1.3',
								'fancybox/jquery.fancybox-1.2.1.pack',
								'fancybox/fancy',
								'lnkbuilding-eng'
							);
		$data['style'] = array('fancybox_gal');
		
		//$kivhonap = (($this->uri->segment(3)-1)%24+1);
		$kivhonap = (($honap-1)%12+1);
		$ev       = 2011 + (int)(($honap-0.1)/12);
		
		$data['title'] = 'ARCHLine.XP Interior - "Picture of the month", '.$honapok[$kivhonap]." ".$ev;
		$data['tartalom']='palyazat/gallery';
		$data['csik']=array('home','palyazat');
		$this->load->view('site_new',$data);
	}
	
	function gallery2esp(){
		$this->load->model('mclusers');
		
		$gal_honap = $this->uri->segment(3);
		
		// email atalakitasa
		$temptomb = explode("/", $_SERVER[ 'REQUEST_URI'] );
		$email = str_replace("%40","@",end($temptomb));
		
		
		$egyezes = "monthpicture/gallery/".$gal_honap;
		$info = "Galéria megtekintve: http://archlinexp.com/monthpicture/gallery/".$gal_honap;
		$hibainfo = "Spanyol, hónap képe: ".$gal_honap;
		
		if(UJUGYFELKEZELO===true)
			$this->mclusers->levelesemeny($email, "monthpicture", "gallery2esp", 254, $egyezes, $info, "esp", $hibainfo);
		else
			$this->mclusers->levelesemenyEsp($email, "monthpicture", "gallery2esp", 133, $egyezes, $info, "esp", $hibainfo);
		
		redirect("monthpicture/gallery/".$gal_honap);
	}
	
}