<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Spanish extends CI_Controller {
	public function __construct()
	{
		parent::__construct();
		$this->load->model('common_model');
		/*if($this->session->userdata('user_id'))
		{
			redirect('profile');
		}*/
		$this->load->library('Mobile_detect');
		//$this->load->library('Excel');
		$this->load->helper('text');
	}
	function send()
	{
		include APPPATH.'libraries/mail.php';
		$your_api_key = '9a1d414f170b904492f76c4b4aaad59c-us14';
		$MailChimp = new MailChimp($your_api_key);

		$apiKey = "9a1d414f170b904492f76c4b4aaad59c-us14";
		$url = "https://us14.api.mailchimp.com/3.0/campaigns/";
		//$html = file_get_contents('https://castleevents.com/test_1/content');
		$operation = array(
	            'type'=> 'regular',
	            'recipients'=>array('list_id' => '8be54dca74'),
	            'settings'=>array('subject_line' => '🔥'.' las noticias mas calientes   ',
		           'reply_to' => 'info@castleevents.com',
		           'from_name' => 'CASTLEEVENTS')
	            );
	        
	    $request_encoded = json_encode($operation);
	    //var_dump($batch_operations);
	    //var_dump($request_encoded);
	    $curl = curl_init($url);
	    curl_setopt($curl, CURLOPT_USERPWD, 'user:' . $apiKey);    
	    curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//raw output
	    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
	    curl_setopt($curl, CURLOPT_POSTFIELDS, $request_encoded); 
		$result = curl_exec($curl);
		
		$campaigns = json_decode($result,true);

		//print_r($campaigns); die;
		$template = $this->content();
		$template_details = json_decode($template,true);
		//echo $template_details['id']; die;
		$apiKey = "9a1d414f170b904492f76c4b4aaad59c-us14";
		$url = "https://us14.api.mailchimp.com/3.0/campaigns/".$campaigns['id']."/content";
		//$html = file_get_contents('https://castleevents.com/test_1/content');
		$operation = array(
	            'template'=> array('id' => $template_details['id'])
	            );
	        
	    $request_encoded = json_encode($operation);
	    //var_dump($batch_operations);
	    //var_dump($request_encoded);
	    $curl = curl_init($url);
	    curl_setopt($curl, CURLOPT_USERPWD, 'user:' . $apiKey);    
	    curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//raw output
	    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
	    curl_setopt($curl, CURLOPT_POSTFIELDS, $request_encoded); 
		$result = curl_exec($curl);
		

		$sendresult = $MailChimp->post('campaigns/' . $campaigns['id'] . '/actions/send');
		//var_dump($sendresult);

		$url = "https://us14.api.mailchimp.com/3.0/campaigns/".$campaigns['id']."/send-checklist";
		$operation = array();
		//$request_encoded = json_encode($operation);
	    $curl = curl_init($url);
	    curl_setopt($curl, CURLOPT_USERPWD, 'user:' . $apiKey);    
	    curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//raw output
	    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
	    //curl_setopt($curl, CURLOPT_POSTFIELDS, $request_encoded); 
		$checkresult = curl_exec($curl);
		$output = json_decode($checkresult,true);
		var_dump($output);
		$this->common_model->insertData('bouncing_system',array('date'=>date('Y-m-d'),'type'=>'Spanish Newsletter','details'=>$output['items'][0]['details'],'campaign_id'=>$campaigns['id']));
		die;
	}
	function create_list_spanish()
	{
		$apiKey = "9a1d414f170b904492f76c4b4aaad59c-us14";
		$this->load->model('common_model');
		$where = "subscribe = 1 and userlanguage = 3 and (email_status = 'sent' or email_status = '')";
		$userlist = $this->common_model->getAllMultipleJoin('feu_userdetails',$where,array(array('usr_users','feu_userdetails.user_id = usr_users.id')),'id ASC');
		//echo '<pre>';print_r($userlist); die;
		$arr = array();
		$arr_final = array();
		if(!empty($userlist))
		{
			foreach ($userlist as $key => $value) {
				//echo $value['email'].$value['username'].$value['alias'];
				$arr['email_address'] = $value['email'];
				$arr['status'] = 'subscribed';
				$arr['email_address'] = $value['email'];
				$arr['merge_fields']['FNAME'] = $value['username'];
				$arr['merge_fields']['LNAME'] = $value['alias'];
				
				array_push($arr_final, $arr);
			}
		}
		$arr = array();
		$arr_final = array();
		if(!empty($userlist))
		{
			foreach ($userlist as $key => $value) {
				//echo $value['email'].$value['username'].$value['alias'];
				$arr['email_address'] = $value['email'];
				$arr['status'] = 'subscribed';
				$arr['email_address'] = $value['email'];
				$arr['merge_fields']['FNAME'] = $value['username'];
				$arr['merge_fields']['LNAME'] = $value['alias'];
				
				array_push($arr_final, $arr);
			}
		}
		$subscribers = $arr_final;
		//print_r($subscribers); die;
		$listId = "8be54dca74";
		$batch_operations = array();
		$url = "https://us14.api.mailchimp.com/3.0/batches";
		$id = 1;
	    foreach ($subscribers as $subscriber) {
	        #echo $subscriber['email_address'];
	        $operation = array(
	            'method'=>'PUT',
	            'path'=>'lists/'.$listId.'/members/'.md5(strtolower($subscriber['email_address'])),
	            'body'=>json_encode($subscriber));
	        $id++;
	        array_push($batch_operations, $operation);
	    }

	    $request_encoded = json_encode(array('operations'=>$batch_operations));
	    //var_dump($batch_operations);
	    //var_dump($request_encoded);
	    $curl = curl_init($url);
	    curl_setopt($curl, CURLOPT_USERPWD, 'user:' . $apiKey);    
	    curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//raw output
	    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
	    curl_setopt($curl, CURLOPT_POSTFIELDS, $request_encoded); 
		$result = curl_exec($curl);
		//return $result;
		var_dump($result);
		die;
	}
	
	public function content()
	{//echo date('d-m-y H:i:s'); die;
		$this->load->model('common_model');
		$this->load->library('Utility');
		$this->load->library('email');
		$langId = 3;
		
				
				$adverts = $this->common_model->getAllRowMultipleJoin('adverts',array('visible'=>1,'adverts_lang_values.lang_id'=>$langId),array(array('adverts_lang_values','adverts_lang_values.adverts_id = adverts.id')),'display_order ASC');
				$latestUsers = $this->common_model->getAllMultipleJoin('feu_userdetails',array('avatar_file_id >'=>0,'filename !='=>''),array(array('sys_files','feu_userdetails.avatar_file_id = sys_files.id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country')),'feu_userdetails.created DESC','','',0,5);
				$upcomingEvents = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title,evt_language_values.teasertext as teasertext,sys_files.filename,sys_files.path,sys_files.extension','id',0,4) ;
				//echo $this->db->last_query(); die;
				$lastEvents = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title,evt_language_values.teasertext as teasertext,sys_files.filename,sys_files.path,sys_files.extension','id',0,4) ;
				//print_r($upcomingEvents); die;
				if(empty($upcomingEvents))
				{
					$upcomingEvents = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title,sys_files.filename,sys_files.path,sys_files.extension','id',0,4) ;
				}
				if(empty($lastEvents))
				{
					$lastEvents = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title,sys_files.filename,sys_files.path,sys_files.extension','id',0,4) ;
				}
				$monday = date( 'Y-m-d', strtotime( 'last friday' ) );
				$saturday = date( 'Y-m-d', strtotime( 'thursday this week' ) );
				$ladyOfTheMonth = $this->common_model->getAllRowMultipleJoin('newsletter_couple_lady',array('avatar_file_id >'=>0,'end_date'=>date('Y-m-d')),array(array('feu_userdetails','feu_userdetails.user_id = newsletter_couple_lady.lady'),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id')),'newsletter_couple_lady.id DESC');
				if(empty($ladyOfTheMonth))
				{
					$ladyOfTheMonth = $this->common_model->getAllRowMultipleJoin('newsletter_couple_lady',array('avatar_file_id >'=>0),array(array('feu_userdetails','feu_userdetails.user_id = newsletter_couple_lady.lady'),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id')),'newsletter_couple_lady.id DESC');
				}
				//echo $this->db->last_query(); die;
				$coupleOfTheWeek = $this->common_model->getAllRowMultipleJoin('newsletter_couple_lady',array('avatar_file_id >'=>0,'end_date'=>date('Y-m-d')),array(array('feu_userdetails','feu_userdetails.user_id = newsletter_couple_lady.couple'),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id')),'newsletter_couple_lady.id DESC');
				if(empty($coupleOfTheWeek))
				{
					$coupleOfTheWeek = $this->common_model->getAllRowMultipleJoin('newsletter_couple_lady',array('avatar_file_id >'=>0),array(array('feu_userdetails','feu_userdetails.user_id = newsletter_couple_lady.couple'),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id')),'newsletter_couple_lady.id DESC');
				}
				$visitorOfTheWeek = $this->common_model->getAllRowMultipleJoin('newsletter_couple_lady',array('avatar_file_id >'=>0,'end_date'=>date('Y-m-d')),array(array('feu_userdetails','feu_userdetails.user_id = newsletter_couple_lady.gentleman'),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id')),'newsletter_couple_lady.id DESC');
				//$visitorOfTheWeek = $this->common_model->getAllRowMultipleJoin('feu_profilevisits',array('filename!='=>'','about !'=>'','LENGTH(about) >'=>10,'from_user_id'=>$users['user_id']),array(array('feu_userdetails','feu_userdetails.user_id = feu_profilevisits.to_user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country')),'','*,feu_userdetails.alias');
				if(empty($visitorOfTheWeek))
				{
					$visitorOfTheWeek = $this->common_model->getAllRowMultipleJoin('newsletter_couple_lady',array('avatar_file_id >'=>0),array(array('feu_userdetails','feu_userdetails.user_id = newsletter_couple_lady.gentleman'),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id')),'newsletter_couple_lady.id DESC');
				}
				
				$testimonials = $this->common_model->getAllRow('trigger_table');
				$where = "status =1 and lang_id =".$langId." and testimonials.id not in (".trim($testimonials['testimonials'],',').")";
				
				$testimonial = $this->common_model->getAllRowMultipleJoin('testimonials',$where,array(array('sys_files','sys_files.id = testimonials.image_id'),array('testimonial_values','testimonial_values.testimonial_id = testimonials.id')),'testimonials.id DESC','*,testimonials.id');
				$update = $this->common_model->UpdateData('trigger_table',array('testimonials'=>trim($testimonials['testimonials'],',').','.$testimonial['id']),array('id'=>1));
				if(empty($testimonial))
				{
					$testimonial = $this->common_model->getAllRowMultipleJoin('testimonials',array('status'=>1,'lang_id'=>$langId),array(array('sys_files','sys_files.id = testimonials.image_id'),array('testimonial_values','testimonial_values.testimonial_id = testimonials.id')),'testimonials.id DESC','*,testimonials.id');
					$update = $this->common_model->UpdateData('trigger_table',array('testimonials'=>$testimonial['id']),array('id'=>1));
				}
				


				$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/images/logocastle_news.svg', 'inline');
		  		$cid = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/images/logocastle_news.svg');
		  		$cidurl = base_url().'/assets/images/logocastle_news.svg';

		  		$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/images/new-logo-mail.png', 'inline');
		  		$cid1 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/images/new-logo-mail.png');
		  		$cid1url = base_url().'/newsletter_image/new-logo-mail.png';
		  		$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/images/new-logo-mail.png',$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/new-logo-mail.png');
		  		$advertcid = '';
		  		if(!empty($adverts))
				{
			  		$str = explode('/',$adverts['image']);
			  		$advimage = end($str);
			  		$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/adverts/160/'.$advimage, 'inline');
			  		$advertcid = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/adverts/160/'.$advimage);
			  		$advertcidurl = base_url().'/newsletter_image/'.$advimage;
			  		$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/adverts/160/'.$advimage,$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$advimage);
			  	}

			  	$testimonialcid = '';
		  		if(!empty($testimonial))
				{
			  		$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$testimonial['path'].'/'.$testimonial['filename'].'.'.$testimonial['extension'], 'inline');
			  		$testimonialcid = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$testimonial['path'].'/'.$testimonial['filename'].'.'.$testimonial['extension']);
			  		$testimonialcidurl = base_url().'/newsletter_image/'.$testimonial['filename'].'.'.$testimonial['extension'];
			  		$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$testimonial['path'].'/'.$testimonial['filename'].'.'.$testimonial['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$testimonial['filename'].'.'.$testimonial['extension']);
			  	}
			  	if(!empty($upcomingEvents)){ 
			  		foreach ($upcomingEvents as $keys => $upcoming) {
			  			if($keys==0)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/500/'.$upcoming['filename'].'.'.$upcoming['extension'], 'inline');
				  			$upcomingcid0 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/500/'.$upcoming['filename'].'.'.$upcoming['extension']);
				  			$upcomingcid0url = base_url().'/newsletter_image/'.$upcoming['filename'].'.'.$upcoming['extension'];
				  			$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/500/'.$upcoming['filename'].'.'.$upcoming['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$upcoming['filename'].'.'.$upcoming['extension']);
			    		}
			    		if($keys==1)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/750/'.$upcoming['filename'].'.'.$upcoming['extension'], 'inline');
				  			$upcomingcid1 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/750/'.$upcoming['filename'].'.'.$upcoming['extension']);
				  			$upcomingcid1url = base_url().'/newsletter_image/'.$upcoming['filename'].'.'.$upcoming['extension'];
				  			$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/750/'.$upcoming['filename'].'.'.$upcoming['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$upcoming['filename'].'.'.$upcoming['extension']);
			    		}
			    		if($keys==2)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/250/'.$upcoming['filename'].'.'.$upcoming['extension'], 'inline');
				  			$upcomingcid2 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/250/'.$upcoming['filename'].'.'.$upcoming['extension']);
				  			$upcomingcid2url = base_url().'/newsletter_image/'.$upcoming['filename'].'.'.$upcoming['extension'];
				  			$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/250/'.$upcoming['filename'].'.'.$upcoming['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$upcoming['filename'].'.'.$upcoming['extension']);
			    		}
			    		if($keys==3)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/250/'.$upcoming['filename'].'.'.$upcoming['extension'], 'inline');
				  			$upcomingcid3 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/250/'.$upcoming['filename'].'.'.$upcoming['extension']);
				  			$upcomingcid3url = base_url().'/newsletter_image/'.$upcoming['filename'].'.'.$upcoming['extension'];
				  			$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/250/'.$upcoming['filename'].'.'.$upcoming['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$upcoming['filename'].'.'.$upcoming['extension']);
			    		}
			    		if($keys==4)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/250/'.$upcoming['filename'].'.'.$upcoming['extension'], 'inline');
				  			$upcomingcid4 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/250/'.$upcoming['filename'].'.'.$upcoming['extension']);
				  			$upcomingcid4url = base_url().'/newsletter_image/'.$upcoming['filename'].'.'.$upcoming['extension'];
				  			$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$upcoming['path'].'/250/'.$upcoming['filename'].'.'.$upcoming['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$upcoming['filename'].'.'.$upcoming['extension']);
			    		}
				  		
			  		}
			  	}

			  	if(!empty($lastEvents)){ 
                    for($i=0;$i<=(count($lastEvents)-count($upcomingEvents));$i++) {           
				  		if($i==0)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'], 'inline');
				  			$lastEventscid0 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension']);
				  			$lastEventscid0url = base_url().'/newsletter_image/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'];
			    			$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension']);
			    		}
			    		if($i==1)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'], 'inline');
				  			$lastEventscid1 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension']);
				  			$lastEventscid1url = base_url().'/newsletter_image/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'];
				  			$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension']);
			    		}
			    		if($i==2)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'], 'inline');
				  			$lastEventscid2 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension']);
				  			$lastEventscid2url = base_url().'/newsletter_image/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'];
				  			$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension']);
			    		}
			    		if($i==3)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'], 'inline');
				  			$lastEventscid3 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension']);
				  			$lastEventscid3url = base_url().'/newsletter_image/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'];
				  			$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension']);
			    		}
			    		if($i==4)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'], 'inline');
				  			$lastEventscid4 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension']);
				  			$lastEventscid4url = base_url().'/newsletter_image/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'];
				  			$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$lastEvents[$i]['path'].'/250/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$lastEvents[$i]['filename'].'.'.$lastEvents[$i]['extension']);
			    		}
				  		
			  		}
			  	}
			  	
			  	$ladyOfTheMonthcid = '';
		  		if(!empty($ladyOfTheMonth))
				{
			  		$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$ladyOfTheMonth['path'].'/320/'.$ladyOfTheMonth['filename'].'.'.$ladyOfTheMonth['extension'], 'inline');
			  		$ladyOfTheMonthcid = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$ladyOfTheMonth['path'].'/320/'.$ladyOfTheMonth['filename'].'.'.$ladyOfTheMonth['extension']);
			  		$ladyOfTheMonthcidurl = base_url().'/newsletter_image/'.$ladyOfTheMonth['filename'].'.'.$ladyOfTheMonth['extension'];
			  		$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$ladyOfTheMonth['path'].'/320/'.$ladyOfTheMonth['filename'].'.'.$ladyOfTheMonth['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$ladyOfTheMonth['filename'].'.'.$ladyOfTheMonth['extension']);
			  	}

			  	$coupleOfTheWeekcid = '';
		  		if(!empty($coupleOfTheWeek))
				{
			  		$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$coupleOfTheWeek['path'].'/320/'.$coupleOfTheWeek['filename'].'.'.$coupleOfTheWeek['extension'], 'inline');
			  		$coupleOfTheWeekcid = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$coupleOfTheWeek['path'].'/320/'.$coupleOfTheWeek['filename'].'.'.$coupleOfTheWeek['extension']);
			  		$coupleOfTheWeekcidurl = base_url().'/newsletter_image/'.$coupleOfTheWeek['filename'].'.'.$coupleOfTheWeek['extension'];
			  		$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$coupleOfTheWeek['path'].'/320/'.$coupleOfTheWeek['filename'].'.'.$coupleOfTheWeek['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$coupleOfTheWeek['filename'].'.'.$coupleOfTheWeek['extension']);
			  	}
			  	$visitorOfTheWeekcid = '';
		  		if(!empty($visitorOfTheWeek))
				{
			  		$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$visitorOfTheWeek['path'].'/320/'.$visitorOfTheWeek['filename'].'.'.$visitorOfTheWeek['extension'], 'inline');
			  		$visitorOfTheWeekcid = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$visitorOfTheWeek['path'].'/320/'.$visitorOfTheWeek['filename'].'.'.$visitorOfTheWeek['extension']);
			  		$visitorOfTheWeekcidurl = base_url().'/newsletter_image/'.$visitorOfTheWeek['filename'].'.'.$visitorOfTheWeek['extension'];
			  		$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$visitorOfTheWeek['path'].'/320/'.$visitorOfTheWeek['filename'].'.'.$visitorOfTheWeek['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$visitorOfTheWeek['filename'].'.'.$visitorOfTheWeek['extension']);
			  	}

			  	$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/images/link.png', 'inline');
		  		$linkcid = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/images/link.png');
		  		$linkcidurl = base_url().'/newsletter_image/link.png';

		  		$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/images/link.png',$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/link.png');

		  		$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/images/internet.png', 'inline');
		  		$internetcid = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/images/internet.png');
		  		$internetcidurl = base_url().'/newsletter_image/internet.png';

		  		$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/images/internet.png',$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/internet.png');

		  		$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/images/support-box-ico.png', 'inline');
		  		$supportcid = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/images/support-box-ico.png');
		  		$supportcidurl = base_url().'/newsletter_image/support-box-ico.png';
		  		$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/images/support-box-ico.png',$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/support-box-ico.png');
			  	
			  	if(!empty($latestUsers))
			    {
			    	foreach ($latestUsers as $key => $latest) {
			    		if($key==0)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension'], 'inline');
			  				$usercid0 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension']);
			  				$usercid0url = base_url().'/newsletter_image/'.$latest['filename'].'.'.$latest['extension'];
			  				$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$latest['filename'].'.'.$latest['extension']);
			    		}
			    		if($key==1)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension'], 'inline');
			  				$usercid1 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension']);
			  				$usercid1url = base_url().'/newsletter_image/'.$latest['filename'].'.'.$latest['extension'];
			  				$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$latest['filename'].'.'.$latest['extension']);
			    		}
			    		if($key==2)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension'], 'inline');
			  				$usercid2 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension']);
			  				$usercid2url = base_url().'/newsletter_image/'.$latest['filename'].'.'.$latest['extension'];
			  				$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$latest['filename'].'.'.$latest['extension']);
			    		}
			    		if($key==3)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension'], 'inline');
			  				$usercid3 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension']);
			  				$usercid3url = base_url().'/newsletter_image/'.$latest['filename'].'.'.$latest['extension'];
			  				$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$latest['filename'].'.'.$latest['extension']);
			    		}
			    		if($key==4)
			    		{
			    			$this->email->attach($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension'], 'inline');
			  				$usercid4 = $this->email->attachment_cid($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension']);
			  				$usercid4url = base_url().'/newsletter_image/'.$latest['filename'].'.'.$latest['extension'];
			  				$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$latest['path'].'/320/'.$latest['filename'].'.'.$latest['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$latest['filename'].'.'.$latest['extension']);
			    		}
			    	
			    	}
			    }
	$html='<!DOCTYPE html>
				<html lang="en">
				<head>
					<meta charset="utf-8"> 
					<meta name="viewport" content="width=device-width">
					<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
				    <meta name="x-apple-disable-message-reformatting">  
					<title></title>

					<style type="text/css">
					  
						#button001 {text-align: center;}
						#button001 > a {
							display: inline-block;
							background: #b3975b;
							color: #fff;
							padding: 10px 30px;
							-webkit-border-radius: 8px;
							-moz-border-radius: 8px;
							border-radius: 8px;
							text-decoration:none;
						} 
						@media screen and (max-width: 761px) {
					        #button001 {
					          text-align: center;
					        }
				      	}
				      	/*center + center {
						    display: none;
						}*/
					</style>
				</head>
				<body id="body" width="100%" bgcolor="#ffffff" style="margin: 0; mso-line-height-rule: exactly; font-family:Arial;">
				    <center style="width: 100%; background: #ffffff; text-align: left;">';

				        			if($langId==1)
				                    {
			$html.='                    <div style="display:none;font-size:1px;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden;mso-hide:all;font-family: sans-serif;">
									        '.$adverts['sub_title'].'</span> '.$adverts['intro_text'].'
									    </div>';	                    		
				                    }
									else
									{
			$html.='	                <div style="display:none;font-size:1px;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden;mso-hide:all;font-family: sans-serif;">
									        '.$adverts['sub_title'].'</span> '.$adverts['intro_text'].'
									    </div>';
									}
				        
			$html.='	<table role="presentation" aria-hidden="true" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" align="center" width="700" style="margin: auto;" class="email-container">
							<tr>
					                <td height="30" style="font-size: 0; line-height: 0;">
					                    &nbsp;
					                </td>
					            </tr>
					        <tr>
					                <td style="">
					                    <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" width="100%" border="0" align="center" style="margin: auto; width: 100%">
					                        <tbody>
					                        <tr>
					                           
					                            <td class="stack-column-center" align="right" width="100%" style="padding:0; vertical-align:top;" >
					                                
					                                <p style="color:#b3975b; margin:0; font-size:14px; line-height:20px;">Hola *|FNAME|*, Recibes nuestro boletín semanal</p>
					                            </td>
					                        </tr>                    
					                       </tbody>
					                    </table>
					                </td>
					            </tr>

					            <tr>
					                <td height="50" style="font-size: 0; line-height: 0;">
					                    &nbsp;
					                </td>
					            </tr>
							<tr>
								<td style="padding: 20px 0; text-align: center">
									<div style="width: 90%; padding: 0 15px; text-align: center;" class="logosvg">
										<a href="'.base_url().'"><img src="'.$cid1url.'" alt="CASTLEEVENTS.COM"></a>
										
				                    </div>';
				                    if($langId==1)
				                    {
			$html.='	                    <p style="color:#b3974b; margin-top:10px; margin-bottom:0;">"Eines der Dinge, die man tun muss, bevor man stirbt.."</p>
				                      		<span style="color:#b3974b;"> - DT Magazin, Spanien - </span>';	                    		
				                    }
									elseif($langId==2)
									{
			$html.='	                    <p style="color:#b3974b; margin-top:10px; margin-bottom:0;">"One of the things you have to do before you die.."</p>
				                      		<span style="color:#b3974b;"> - DT Magazin, Spanien - </span>';							
									}
									else
									{
			$html.='	                    <p style="color:#b3974b; margin-top:10px; margin-bottom:0;">"Uno de las cosas que tienes que hacer antes de morir.."</p>
				                      		<span style="color:#b3974b;"> - DT Magazin, Spanien - </span>';							
									}
			$html.='			</td>
							</tr>
				        </table>
				        

				        
				        <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" align="center" width="700" style="margin: auto;" class="email-container">';
				        		if($langId==1)
				        		{
			$html.='	                    <tr>
				                  <td style="text-align:center;  padding-bottom: 15px;">
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'all-parties">Parties</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/castleevents">Einblicke</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/einfuhrung">Community</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/venezianischen-masken">Shop</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/geschichte">Uber uns</a>
				                  </td>                  
				               </tr> ';	                    		
				                    }
									elseif($langId==2)
									{
			$html.='	                    <tr>
				                  <td style="text-align:center;  padding-bottom: 15px;">
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'all-parties">Parties</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/castleevents">Insights</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/introduction">Community</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/venetian-masks">Shop</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/team">About Us</a>
				                  </td>                  
				               </tr> ';							
									}
									else
									{
			$html.='	                    <tr>
				                  <td style="text-align:center;  padding-bottom: 15px;">
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'all-parties">Fiestas</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/castleevents">Vistazo</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/introduction">Comunidad</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/venetian-masks">Tienda</a>
				                    <a style="padding: 8px 10px; display: inline-block; margin: 0 18px; text-decoration: none; color: #000000;
				    text-transform: uppercase; font-size: 12px;" href="'.base_url().'events/team">Sobre Nosotros</a>
				                  </td>                  
				               </tr> ';							
									}
				           
				               
				           
			if(!empty($adverts))
			{
				$link = explode('https://', $adverts['link']);
				$links = '';
				if(count($link)>0)
				{
					if(count($link)>1)
					{
						$links = 'https://'.$link[1];
					}
					else
					{
						$links = $link[0];
					}
				}
				$html.='	        <tr>
				                <td bgcolor="#131218" dir="ltr" align="center" valign="top" width="100%" style="padding: 10px;">
				                    <table role="presentation" aria-hidden="true" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
				                        <tbody><tr>
				                            

				                            <td width="33.33%" class="stack-column-center">
				                                <table role="presentation" aria-hidden="true" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
				                                    <tbody><tr>
				                                        <td align="center" valign="top" style="padding: 0 10px;">
				                                          <div style="width:120px; display: inline-block; vertical-align: top; height:120px; overflow:hidden; -webkit-border-radius:100%; -moz-border-radius:100%; -khtml-border-radius:100%; -ms-border-radius:100%; border-radius:100%;">';
														    if($adverts['image']) {
				$html.='                                       <img width="100%" height="120px" src="'.$advertcidurl.'" alt="userpic">';
														    }
				$html.='                                  </div>
				                                        </td>
				                                    </tr>
				                                </tbody></table>
				                            </td>
				                            
				                            
				                            <td width="66.66%" class="stack-column-center">
				                                
				                                <table role="presentation" aria-hidden="true" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
				                                     
				                                    <tbody><tr>
				                                        <td dir="ltr" valign="top" style="font-family: sans-serif; font-size: 15px; line-height: 20px; color: #555555; padding: 10px; text-align: left;" class="center-on-narrow">
				                                                    <h2 style="margin: 0 0 10px 0; font-family: sans-serif; font-size: 18px; line-height: 21px; color: #ffffff; font-weight: normal; text-transform:uppercase;">'.$adverts['title'].'</h2>
				                                                    <p style="margin: 0 0 10px 0; color:#e2e2e2;"><span style="color:#b3975b; font-weight:bold;">'.$adverts['sub_title'].'</span> '.$adverts['intro_text'].'</p>
				                                                    <p id="button001"><a href="'.$links.'">Leer Más</a></p>
				                                            
				                                            
				                                            
				                                        </td>
				                                    </tr>
				                                </tbody></table>
				                            </td>
				                            
				                        </tr>
				                    </tbody></table>
				                </td>
				            </tr>';
			}	            
				$html.='            <tr>
				                <td bgcolor="#131218" style="padding: 20px; text-align: center;">
				                    
				                    ';

				    if(!empty($latestUsers))
				    {
				    	foreach($latestUsers as $key => $latest) {
				    		$html.= '<div  class="community" href="'.base_url().'" style="margin:0 10px; display:inline-block; vertical-align:top; color:#e2e2e2; text-decoration:none;">
				                        <h5 style="margin: 0 0 5px; color:#b3975b; text-transform: uppercase;">'.$latest['username'].'</h5>';
				            if($key==0)
				            {
				            	$html.= '<div style="width:80px; position: relative; display: inline-block; vertical-align: top; height:80px; overflow:hidden; -webkit-border-radius:100%; -moz-border-radius:100%; -khtml-border-radius:100%; -ms-border-radius:100%; border-radius:100%;">
				                          <img height="80" width="80"  width="80px" height="80px" style="height: 80px; width: 80px; min-width: 80px; position: absolute; min-height: 80px; width: auto; display: block;" src="'.$usercid0url.'" alt="userpic">
				                          
				                        </div>';
				            }
				            if($key==1)
				            {
				            	$html.= '<div style="width:80px; position: relative; display: inline-block; vertical-align: top; height:80px; overflow:hidden; -webkit-border-radius:100%; -moz-border-radius:100%; -khtml-border-radius:100%; -ms-border-radius:100%; border-radius:100%;">
				                          <img height="80" width="80"  width="80px" height="80px" style="height: 80px; width: 80px; min-width: 80px; position: absolute; min-height: 80px; width: auto; display: block;" src="'.$usercid1url.'" alt="userpic">
				                          
				                        </div>';
				            }
				            if($key==2)
				            {
				            	$html.= '<div style="width:80px; position: relative; display: inline-block; vertical-align: top; height:80px; overflow:hidden; -webkit-border-radius:100%; -moz-border-radius:100%; -khtml-border-radius:100%; -ms-border-radius:100%; border-radius:100%;">
				                          <img height="80" width="80"  width="80px" height="80px" style="height: 80px; width: 80px; min-width: 80px; position: absolute; min-height: 80px; width: auto; display: block;" src="'.$usercid2url.'" alt="userpic">
				                          
				                        </div>';
				            }
				            if($key==3)
				            {
				            	$html.= '<div style="width:80px; position: relative; display: inline-block; vertical-align: top; height:80px; overflow:hidden; -webkit-border-radius:100%; -moz-border-radius:100%; -khtml-border-radius:100%; -ms-border-radius:100%; border-radius:100%;">
				                          <img height="80" width="80"  width="80px" height="80px" style="height: 80px; width: 80px; min-width: 80px; position: absolute; min-height: 80px; width: auto; display: block;" src="'.$usercid3url.'" alt="userpic">
				                          
				                        </div>';
				            }
				            if($key==4)
				            {
				            	$html.= '<div style="width:80px; position: relative; display: inline-block; vertical-align: top; height:80px; overflow:hidden; -webkit-border-radius:100%; -moz-border-radius:100%; -khtml-border-radius:100%; -ms-border-radius:100%; border-radius:100%;">
				                          <img height="80" width="80"  width="80px" height="80px" style="height: 80px; width: 80px; min-width: 80px; position: absolute; min-height: 80px; width: auto; display: block;" src="'.$usercid4url.'" alt="userpic">
				                          
				                        </div>';
				            }
				            
				                        
				            $html.= '<p style="margin: 5px 0 5px; font-size:11px; text-transform: capitalize;" >'.$latest['accounttype'].'</p>
				                     </div>';
				    	}
				    }                


				$html.='                </td>
				            </tr>

				            <tr>
				                <td height="20" style="font-size: 0; line-height: 0;">
				                    &nbsp;
				                </td>
				            </tr>';
				        
				        if(!empty($upcomingEvents))
				        {
			$html.='    <tr>
				                <td bgcolor="#eeeeee" style="">
				                    <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" align="center" style="margin: auto">
				                        <tr>
				                            <td class="stack-column-center" align="center" width="50%" style="padding:20px;">
				                                <h3 style="font-size:20px; font-weight: normal; text-transform:uppercase; margin:0; text-align:center; color: #333333;">'.$upcomingEvents[0]['title'].'</h3>
				                                <h5 style="font-size:15px; text-transform:uppercase; margin:0 0 10px; text-align:center; color: #b3975b; font-weight: normal;">'.$upcomingEvents[0]['city'].' '.date('d, M Y',$upcomingEvents[0]['time_from']).'</h5>
				                                <p style="text-align:center; color: #333333;">'.word_limiter($upcomingEvents[0]['teasertext'], 25).'</p>
				                                <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" class="center-on-narrow" >
				                                                <tbody><tr>
				                                                    <td style="-webkit-border-radius: 8px; -moz-border-radius: 8px; -ms-border-radius: 8px; -o-border-radius: 8px; -khtml-border-radius: 8px; border-radius: 8px; background: #b3975b; text-align: center;" class="button-td">
				                                                        <a href="'.base_url().'parties/'.$upcomingEvents[0]['alias'].'" style="background: #b3975b; border: 10px solid #b3975b; font-family: sans-serif; font-size: 13px; line-height: 1.1; text-align: center; text-decoration: none; display: block; -webkit-border-radius: 8px; -moz-border-radius: 8px; -ms-border-radius: 8px; -o-border-radius: 8px; -khtml-border-radius: 8px; border-radius: 8px; font-weight: bold;" class="button-a">
				                                                            <span style="color:#ffffff;" class="button-link">&nbsp;&nbsp;&nbsp;&nbsp;Leer Más&nbsp;&nbsp;&nbsp;&nbsp;</span>
				                                                        </a>
				                                                    </td>
				                                                </tr>
				                                            </tbody>
				                                            </table>
				                            </td>
				                            <td class="stack-column-center" align="right" width="50%">
				                                <div style="overflow:hidden;">
				                                    <img width="100%" style="display:block; height:228px;" src="'.$upcomingcid0url.'" alt="">
				                                </div>
				                            </td>
				                        </tr>
				                    </table>
				                </td>
				            </tr>';
				        }    
				
				            
				$html.='    <tr>
				                <td height="20" style="font-size: 0; line-height: 0;">
				                    &nbsp;
				                </td>
				            </tr>';
						if(!empty($upcomingEvents))
				        {            
				            
				$html.='    <tr>
				               
				                <td>
				                	<div style="position: relative; display:block; overflow: hidden; min-height: 196px;">
				                  	 <img src="'.$upcomingcid1url.'" width="100%"  style="display:block; min-height:400px; width:700px; min-width:700px; position: absolute;" alt="">                   
				                	</div>
				                </td>
				            </tr>

				            <tr>               
				                <td bgcolor="#eeeeee" align="center" style="padding:30px">
				                   <h3 style="margin:0; font-size:20px; text-transform:uppercase; font-weight:normal; color: #333333;">'.$upcomingEvents[1]['title'].'</h3>
				                   <h5 style=" color:#b3975b; font-size: 16px; margin:5px 0 15px; text-transform:uppercase; font-weight:normal;">'.$upcomingEvents[1]['city'].' '.date('d, M Y',$upcomingEvents[1]['time_from']).'</h5>
				                   <p style=" color: #333333;">'.word_limiter($upcomingEvents[1]['teasertext'], 25).'</p>  
				                   		<table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" class="center-on-narrow">
                                                <tbody><tr>
                                                    <td style="-webkit-border-radius: 8px; -moz-border-radius: 8px; -ms-border-radius: 8px; -o-border-radius: 8px; -khtml-border-radius: 8px; border-radius: 8px; background: #b3975b; text-align: center;" class="button-td">
                                                        <a href="'.base_url().'parties/'.$upcomingEvents[1]['alias'].'" style="background: #b3975b; border: 10px solid #b3975b; font-family: sans-serif; font-size: 13px; line-height: 1.1; text-align: center; text-decoration: none; display: block; -webkit-border-radius: 8px; -moz-border-radius: 8px; -ms-border-radius: 8px; -o-border-radius: 8px; -khtml-border-radius: 8px; border-radius: 8px; font-weight: bold;" class="button-a">
                                                            <span style="color:#ffffff;" class="button-link">&nbsp;&nbsp;&nbsp;&nbsp;Leer Más&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                                        </a>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>                 
				                </td>
				            </tr>';
				        }   
				             
				$html.='    <tr>
				                <td height="20" style="font-size: 0; line-height: 0;">
				                    &nbsp;
				                </td>
				            </tr>

				            
				            <tr>
				                <td bgcolor="#ffffff" align="center" valign="top" style="padding: 10px 0;">
				                    <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" width="100%">
				                        <tr>';
				                    if(!empty($upcomingEvents)){ 
                                        foreach ($upcomingEvents as $keys => $upcoming) {
				                           if($keys>1)
				                           { 
				$html.='                    <td width="33.33%" class="stack-column-center" style="padding: 0 10px 0 0;">
				                                <table width="100%" role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0">';
				                                   
				                                   if($keys==2)
				                                   {
				$html.='                            <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                            <img src="'.$upcomingcid2url.'" aria-hidden="true" width="100%" height="170" alt="alt_text" border="0" class="fluid" style="display:block;">
				                                        </td>
				                                    </tr>';                                   	
				                                   }  
				                                   if($keys==3)
				                                   {
				$html.='                            <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                            <img src="'.$upcomingcid3url.'" aria-hidden="true" width="100%" height="170" alt="alt_text" border="0" class="fluid" style="display:block;">
				                                        </td>
				                                    </tr>';                                   	
				                                   }  
				                                   if($keys==4)
				                                   {
				$html.='                            <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                            <img src="'.$upcomingcid4url.'" aria-hidden="true" width="100%" height="170" alt="alt_text" border="0" class="fluid" style="display:block;">
				                                        </td>
				                                    </tr>';                                   	
				                                   }  
				
				$html.='                                    <tr>
				                                        <td align="center" bgcolor="#eeeeee" style="font-family: sans-serif; height: 275px; font-size: 15px; line-height: 20px; color: #555555; padding:20px 10px; " >
				                                            <h3 style="margin:0; font-size:18px; text-transform:uppercase; font-weight:normal; color: #333333;min-height: 60px;">'.$upcoming['title'].'</h3>
				                                            
				                                            <h5 style=" color:#b3975b; font-size: 16px; margin:5px 0 15px; text-transform:uppercase; font-weight:normal;">'.date('d, M Y',$upcoming['time_from']).'</h5>
				                                            <div style="min-height:150ox; max-height: 150px; height: 150px; ">
				                                            	<p style="margin: 0 0 20px; color: #333333;">'.word_limiter($upcoming['teasertext'], 20).'</p>
				                                            </div>
				                                            <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" class="center-on-narrow" >
				                                                <tbody><tr>
				                                                    <td style="-webkit-border-radius: 8px; -moz-border-radius: 8px; -ms-border-radius: 8px; -o-border-radius: 8px; -khtml-border-radius: 8px; border-radius: 8px; background: #b3975b; text-align: center;" class="button-td">
				                                                        <a href="'.base_url().'parties/'.$upcoming['alias'].'" style="background: #b3975b; border: 10px solid #b3975b; font-family: sans-serif; font-size: 13px; line-height: 1.1; text-align: center; text-decoration: none; display: block; -webkit-border-radius: 8px; -moz-border-radius: 8px; -ms-border-radius: 8px; -o-border-radius: 8px; -khtml-border-radius: 8px; border-radius: 8px; font-weight: bold;" class="button-a">
				                                                            <span style="color:#ffffff;" class="button-link">&nbsp;&nbsp;&nbsp;&nbsp;Leer Más&nbsp;&nbsp;&nbsp;&nbsp;</span>
				                                                        </a>
				                                                    </td>
				                                                </tr>
				                                            </tbody>
				                                            </table>
				                                        </td>
				                                    </tr>
				                                </table>
				                            </td>';
				                        	}
				                        } }   
				                if(!empty($lastEvents)){ 
                                       for($i=0;$i<=(count($lastEvents)-count($upcomingEvents));$i++) {           
				                           
				                            
				$html.='                    <td width="33.33%" class="stack-column-center" style="padding: 0 10px 0 0;">
				                                <table width="100%" role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0">';
				                                   if($i==0)
				                                   { 
				$html.='                            <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                            <img src="'.$lastEventscid0url.'" aria-hidden="true" width="100%" height="170" alt="alt_text" border="0" class="fluid" style="display:block;">
				                                        </td>
				                                    </tr>';                                   	
				                                   }  
				                                   if($i==1)
				                                   { 
				$html.='                            <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                            <img src="'.$lastEventscid1url.'" aria-hidden="true" width="100%" height="170" alt="alt_text" border="0" class="fluid" style="display:block;">
				                                        </td>
				                                    </tr>';                                   	
				                                   }  
				                                   if($i==2)
				                                   {
				$html.='                            <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                            <img src="'.$lastEventscid2url.'" aria-hidden="true" width="100%" height="170" alt="alt_text" border="0" class="fluid" style="display:block;">
				                                        </td>
				                                    </tr>';                                   	
				                                   }  
				                                   if($i==3)
				                                   {
				$html.='                            <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                            <img src="'.$lastEventscid3url.'" aria-hidden="true" width="100%" height="170" alt="alt_text" border="0" class="fluid" style="display:block;">
				                                        </td>
				                                    </tr>';                                   	
				                                   }  
				                                   if($i==4)
				                                   {
				$html.='                            <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                            <img src="'.$lastEventscid4url.'" aria-hidden="true" width="100%" height="170" alt="alt_text" border="0" class="fluid" style="display:block;">
				                                        </td>
				                                    </tr>';                                   	
				                                   } 
				$html.='                            <tr>
				                                        <td align="center" bgcolor="#eeeeee" style="font-family: sans-serif; height: 275px; font-size: 15px; line-height: 20px; color: #555555; padding:20px 10px; " >
				                                            <h3 style="margin:0; font-size:18px; text-transform:uppercase; font-weight:normal; color: #333333;min-height: 60px;">'.$lastEvents[$i]['title'].'</h3>
				                                            <h5 style=" color:#b3975b; font-size: 16px; margin:5px 0 15px; text-transform:uppercase; font-weight:normal;">'.date('d, M Y',$lastEvents[$i]['time_from']).'</h5>
				                                            <div style="min-height:150ox; max-height: 150px; height: 150px; ">
				                                            	<p style="margin: 0 0 20px; color: #333333;">'.word_limiter($lastEvents[$i]['teasertext'], 20).'</p>
				                                            </div>
				                                            <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" class="center-on-narrow" >
				                                                <tbody><tr>
				                                                    <td style="-webkit-border-radius: 8px; -moz-border-radius: 8px; -ms-border-radius: 8px; -o-border-radius: 8px; -khtml-border-radius: 8px; border-radius: 8px; background: #b3975b; text-align: center;" class="button-td">
				                                                        <a href="'.base_url().'reviews/'.$lastEvents[$i]['alias'].'" style="background: #333; border: 10px solid #333; font-family: sans-serif; font-size: 13px; line-height: 1.1; text-align: center; text-decoration: none; display: block; -webkit-border-radius: 8px; -moz-border-radius: 8px; -ms-border-radius: 8px; -o-border-radius: 8px; -khtml-border-radius: 8px; border-radius: 8px; font-weight: bold;" class="button-a">
				                                                            <span style="color:#ffffff;" class="button-link">&nbsp;&nbsp;&nbsp;&nbsp;Ver resumen&nbsp;&nbsp;&nbsp;&nbsp;</span>
				                                                        </a>
				                                                    </td>
				                                                </tr>
				                                            </tbody>
				                                            </table>
				                                        </td>
				                                    </tr>
				                                </table>
				                            </td>';                        
				                        } }      

				$html.='                </tr>
				                    </table>
				                </td>
				            </tr>';
				            
				            if($langId==1)
				            {
				          
				$html.='    <tr>
				                <td bgcolor="#ffffff">
				                    <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" width="100%">
				                        <tr>
				                            <td class="paddingnormal" align="center" style="padding: 40px 110px; font-family: sans-serif; font-size: 15px; line-height: 20px; color: #000000;">
				                            <h3 style="margin:0 0 10px; font-size:20px; text-transform:uppercase; font-weight:normal;  color: #333333">Spannendes Bei CastleEvents</h3>
				                            <h5 style="margin:0; font-size:16px; font-style: italic;  font-weight:normal;  color: #333333">Tauchen Sie ein in eine Welt voller Gefühle und Leidenschaften unserer Parties und Ihrer Mitglieder</h5>
				                                
				                            </td>
				                            </tr>
				                    </table>
				                </td>
				            </tr>';
				            }
				            elseif($langId==2)
				            {
				$html.='    <tr>
				                <td bgcolor="#ffffff">
				                    <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" width="100%">
				                        <tr>
				                            <td class="paddingnormal" align="center" style="padding: 40px 130px; font-family: sans-serif; font-size: 15px; line-height: 20px; color: #000000;">
				                            <h3 style="margin:0 0 10px; font-size:20px; text-transform:uppercase; font-weight:normal; color: #333333">Exciting CastleEvents</h3>
				                            <h5 style="margin:0; font-size:16px; font-style: italic;  font-weight:normal; color: #333333">Entering our community and join the most exclusive parties in the world of emotions and passions</h5>
				                                
				                            </td>
				                            </tr>
				                    </table>
				                </td>
				            </tr>';            	
				            }
				            else
				            {
				$html.='    <tr>
				                <td bgcolor="#ffffff">
				                    <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" width="100%">
				                        <tr>
				                            <td class="paddingnormal" align="center" style="padding: 40px 130px; font-family: sans-serif; font-size: 15px; line-height: 20px; color: #000000;">
				                            <h3 style="margin:0 0 10px; font-size:20px; text-transform:uppercase; font-weight:normal; color: #333333">emocionantes eventos en castillos</h3>
				                            <h5 style="margin:0; font-size:16px; font-style: italic;  font-weight:normal; color: #333333">Entrar en nuestra comunidad y unirse a las fiestas más exclusivas en el mundo de las emociones y las pasiones</h5>
				                                
				                            </td>
				                            </tr>
				                    </table>
				                </td>
				            </tr>';            	
				            }

				            
				$html.='    <tr>
				                <td bgcolor="#ffffff" align="center" valign="top" style="padding: 10px 0;">
				                    <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" width="100%">
				                        <tr>';
				                        if(!empty($coupleOfTheWeek))
				                        {
				                        	$countryData = getValue('feu_countries',array('country_code'=>$coupleOfTheWeek['country']));
				                        	$country_name = '';
				                        	if($countryData)
				                        	{
				                        		//$country_name = $countryData['country_name'];
				                        	}
				$html.='                	<td width="33.33%" class="stack-column-center" style="padding: 0 10px 0 0;">
				                                <table width="100%" bgcolor="#eeeeee" role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0">
				                                <tr>
				                                    <td align="center" style="padding:20px">
				                                        <h3 style="margin:0; color:#b3975b; font-size:18px; text-transform:uppercase; font-weight:normal;">'.$coupleOfTheWeek['username'].'</h3>
				                                        <h5 style=" font-size: 14px; color: #000000; margin:0; text-transform:uppercase; font-weight:normal;">'.$coupleOfTheWeek['accounttype'].', '.$country_name.'</h5>

				                                    </td>
				                                </tr>
				                                    <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                           <div style="width:150px; height:150px; overflow: hidden; display: inline-block; vertical-align: top; -webkit-border-radius:100%; -moz-border-radius:100%; -ms-border-radius:100%; -khtml-border-radius:100%; border-radius:100%;">
				                                               <img src="'.$coupleOfTheWeekcidurl.'" aria-hidden="true" width="100%" height="150px" alt="alt_text" border="0"  style="display:block;">
				                                           </div>
				                                            
				                                        </td>
				                                    </tr>
				                                    <tr>
				                                        <td align="center" bgcolor="#eeeeee" style=" height: 213px; font-family: sans-serif; font-size: 15px; line-height: 20px; color: #555555; padding:20px 10px; " >
				                                            <h3 style="margin:0 0 15px; font-family: times; font-size:21px; font-style: italic; font-weight:normal;">Pareja de la semana</h3>
				                                            
				                                            

				                                            <p style="margin: 0; font-style: italic;">'.word_limiter($coupleOfTheWeek['about'], 20).'..</p>
				                                           
				                                        </td>
				                                    </tr>
				                                </table>
				                            </td>';                        	
				                        }

				                        if(!empty($ladyOfTheMonth))
				                        {
				                        	$countryData = getValue('feu_countries',array('country_code'=>$ladyOfTheMonth['country']));
				                        	$country_name = '';
				                        	if($countryData)
				                        	{
				                        		//$country_name = $countryData['country_name'];
				                        	}
				$html.='                	<td width="33.33%" class="stack-column-center" style="padding: 0 10px 0 0;">
				                                <table width="100%" bgcolor="#eeeeee" role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0">
				                                <tr>
				                                    <td align="center" style="padding:20px">
				                                        <h3 style="margin:0; color:#b3975b; font-size:18px; text-transform:uppercase; font-weight:normal;">'.$ladyOfTheMonth['username'].'</h3>
				                                        <h5 style=" font-size: 14px; color: #000000; margin:0; text-transform:uppercase; font-weight:normal;">'.$ladyOfTheMonth['accounttype'].', '.$country_name.'</h5>

				                                    </td>
				                                </tr>
				                                    <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                           <div style="width:150px; height:150px; overflow: hidden; display: inline-block; vertical-align: top; -webkit-border-radius:100%; -moz-border-radius:100%; -ms-border-radius:100%; -khtml-border-radius:100%; border-radius:100%;">
				                                               <img src="'.$ladyOfTheMonthcidurl.'" aria-hidden="true" width="100%" height="150px" alt="alt_text" border="0"  style="display:block;">
				                                           </div>
				                                            
				                                        </td>
				                                    </tr>
				                                    <tr>
				                                        <td align="center" bgcolor="#eeeeee" style="  height: 213px; font-family: sans-serif; font-size: 15px; line-height: 20px; color: #555555; padding:20px 10px; " >
				                                            <h3 style="margin:0 0 15px;  font-family: times; font-size:21px; font-style: italic; font-weight:normal;">Señora de la semana</h3>
				                                            
				                                            

				                                            <p style="margin: 0; font-style: italic;">'.word_limiter($ladyOfTheMonth['about'], 20).'..</p>
				                                           
				                                        </td>
				                                    </tr>
				                                </table>
				                            </td>';                        	
				                        }
				                        if(!empty($visitorOfTheWeek))
				                        {
				                        	$countryData = getValue('feu_countries',array('country_code'=>$visitorOfTheWeek['country']));
				                        	$country_name = '';
				                        	if($countryData)
				                        	{
				                        		//$country_name = $countryData['country_name'];
				                        	}
				$html.='                	<td width="33.33%" class="stack-column-center" style="padding: 0 10px 0 0;">
				                                <table width="100%" bgcolor="#eeeeee" role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0">
				                                <tr>
				                                    <td align="center" style="padding:20px">
				                                        <h3 style="margin:0; color:#b3975b; font-size:18px; text-transform:uppercase; font-weight:normal;">'.$visitorOfTheWeek['username'].'</h3>
				                                        <h5 style=" font-size: 14px; color: #000000; margin:0; text-transform:uppercase; font-weight:normal;">'.$visitorOfTheWeek['accounttype'].', '.$country_name.'</h5>

				                                    </td>
				                                </tr>
				                                    <tr>
				                                        <td style="margin: 10px 10px 0; text-align: center">
				                                           <div style="width:150px; height:150px; overflow: hidden; display: inline-block; vertical-align: top; -webkit-border-radius:100%; -moz-border-radius:100%; -ms-border-radius:100%; -khtml-border-radius:100%; border-radius:100%;">
				                                               <img src="'.$visitorOfTheWeekcidurl.'" aria-hidden="true" width="100%" height="150px" alt="alt_text" border="0"  style="display:block;">
				                                           </div>
				                                            
				                                        </td>
				                                    </tr>
				                                    <tr>
				                                        <td align="center" bgcolor="#eeeeee" style="height: 213px; font-family: sans-serif; font-size: 15px; line-height: 20px; color: #555555; padding:20px 10px; " >
				                                            <h3 style="margin:0 0 15px; font-family: times; font-size:21px; font-style: italic; font-weight:normal;">Señor de la semana</h3>
				                                            
				                                            

				                                            <p style="margin: 0; font-style: italic;">'.word_limiter($visitorOfTheWeek['about'], 20).'..</p>
				                                           
				                                        </td>
				                                    </tr>
				                                </table>
				                            </td>';                        	
				                        }  

				$html.='                </tr>
				                    </table>
				                </td>
				            </tr>
				           
				            
				           
				            <tr>
				                <td height="20" style="font-size: 0; line-height: 0;">
				                    &nbsp;
				                </td>
				            </tr>';
				            if(!empty($testimonial))
				            {
				             
				$html.='    <tr>
				                <td bgcolor="#131218" dir="ltr" align="center" valign="top" width="100%" style="padding: 10px;">
				                    <table role="presentation" aria-hidden="true" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
				                        <tbody><tr>
				                            

				                            <td width="33.33%" class="stack-column-center">
				                                <table role="presentation" aria-hidden="true" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
				                                    <tbody><tr>
				                                        <td align="center" valign="top" style="padding: 0 10px;">
				                                          <a href="'.base_url().'testimonials">
				                                          <div style="width:120px; display: inline-block; vertical-align: top; height:120px; overflow:hidden; -webkit-border-radius:100%; -moz-border-radius:100%; -khtml-border-radius:100%; -ms-border-radius:100%; border-radius:100%;">
				                                               <img width="100%" height="120px" src="'.$testimonialcidurl.'" alt="userpic">
				                                           </div>
				                                           </a>
				                                        </td>
				                                    </tr>
				                                </tbody></table>
				                            </td>
				                            
				                            
				                            <td width="66.66%" class="stack-column-center">
				                                <table role="presentation" aria-hidden="true" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
				                                    <tbody><tr>
				                                        <td dir="ltr" valign="top" style="font-family: sans-serif; font-size: 15px; line-height: 20px; color: #555555; padding: 10px; text-align: left;" class="center-on-narrow">
				                                                    <h2 style="margin: 0 0 10px 0; font-family: sans-serif; font-size: 18px; line-height: 21px; color: #ffffff; font-weight: normal; text-transform:uppercase;"><span style="color:#b3975b;">'.$testimonial['name'].'</h2>
				                                                    <div style="margin: 0 0 10px 0; color:#e2e2e2; font-family:times; font-style:italic; font-size:16px;">'.$testimonial['text'].'</div>
				                                            
				                                            
				                                        </td>
				                                    </tr>
				                                </tbody></table>
				                            </td>
				                            
				                        </tr>
				                    </tbody></table>
				                </td>
				            </tr>';     
				        }


				           
				$html.='    <tr>
				                <td height="20" style="font-size: 0; line-height: 0;">
				                    &nbsp;
				                </td>
				            </tr>


				            <tr>
				                <td bgcolor="#eeeeee" dir="ltr" align="center" valign="top" width="100%" style="padding: 10px;">
				                    <table role="presentation" aria-hidden="true" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
				                        <tbody><tr>
				                            

				                            <td width="33.33%" class="stack-column-center">
				                                <table role="presentation" aria-hidden="true" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
				                                    <tbody><tr>
				                                        <td align="center" valign="top" style="padding: 0 10px;">
				                                          <div style="width:120px; display: inline-block; vertical-align: top; height:120px; overflow:hidden; -webkit-border-radius:100%; -moz-border-radius:100%; -khtml-border-radius:100%; -ms-border-radius:100%; border-radius:100%;">
				                                               <img width="100%" height="120px" src="'.$supportcidurl.'" alt="userpic">
				                                           </div>
				                                        </td>
				                                    </tr>
				                                </tbody></table>
				                            </td>
				                            
				                            
				                            <td width="66.66%" class="stack-column-center">
				                                <table role="presentation" aria-hidden="true" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
				                                    <tbody>
				                                      <tr>
				                                        <td dir="ltr" valign="top" style="font-family: sans-serif; font-size: 15px; line-height: 20px; color: #555555; padding: 10px; text-align: left;" class="center-on-narrow">
				                                                    <h2 style="margin: 0 0 10px 0; font-family: sans-serif; font-size: 18px; line-height: 21px; color: #ffffff; font-weight: normal; text-transform:uppercase;"><span style="color:#b3975b;">Contáctenos</span></h2>';
				                                                if($langId==1)
				                                                {
				                $html.='                             <p style="margin: 0 0 20px 0; color:#000; font-family:times; font-style:italic; font-size:18px;"><strong>Buchen</strong> Sie direkt per E-Mail <a href="mailto:info@castleevents.com" style="color:#000;">info@castleevents.com</a> wir beantworten Ihre Anfragen unverzüglich.</p>';   	
				                                                } 
				                                                elseif($langId==2)
				                                                {
				                $html.='                             <p style="margin: 0 0 20px 0; color:#000; font-family:times; font-style:italic; font-size:18px;"><strong>Book</strong> directly by email <a href="mailto:info@castleevents.com" style="color:#000;">info@castleevents.com</a> we will answer your request immediately.</p>';
				                                                }  
				                                                else
				                                                {
				                $html.='                             <p style="margin: 0 0 20px 0; color:#000; font-family:times; font-style:italic; font-size:18px;"><strong>Libro</strong> directamente por correo electrónico <a href="mailto:info@castleevents.com" style="color:#000;">info@castleevents.com</a> responderemos a su solicitud inmediatamente.</p>';
				                                                }  
				                                                    
				                                                    
				                $html.='                        <table role="presentation" aria-hidden="true" align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
				                                                        <tr>
				                                                            <td>
				                                                              <a href="'.base_url().'" style="color:#b3975b; text-decoration:none; margin-right:20px;"><img src="'.$linkcidurl.'" valign="middle" style="margin-right:8px" alt=""> Visita el sitio web</a>  
				                                                              <a href="'.base_url().'home/language" style="color:#b3975b; text-decoration:none;"><img src="'.$internetcidurl.'" valign="middle" style="margin-right:8px" alt=""> Cambiar idioma</a>  
				                                                            </td>
				                                                        </tr>
				                                                    </table>
				                                            
				                                            
				                                        </td>
				                                    </tr>
				                                </tbody></table>
				                            </td>
				                            
				                        </tr>
				                    </tbody></table>
				                </td>
				            </tr>



				            <!--<tr>
				                <td height="20" style="font-size: 0; line-height: 0;">
				                    &nbsp;
				                </td>
				            </tr>

				            <tr>
				                <td align="right"><p style="color:#a7a7a7; font-style:italic; font-family: times; font-size:16px;"><a href="'.base_url().'home/unsubscribe/8be54dca74" style="color:#a7a7a7;">Darse de baja del boletín</a></p></td>
				            </tr>

				            <tr>
				                <td height="20" style="font-size: 0; line-height: 0;">
				                    &nbsp;
				                </td>
				            </tr>-->
				            

				            

				        </table>
				    </center>
				</body>
				</html>
				';  
		//echo $html; die;
		$apiKey = "9a1d414f170b904492f76c4b4aaad59c-us14";
		$url = "https://us14.api.mailchimp.com/3.0/templates";
		//$html = file_get_contents('https://castleevents.com/test_1/content');
		$operation = array(
	            'name'=>'Spanish template dated '.date('d-m-Y'),
	            //'html'=>'<p>test</p>'
	            'html'=>$html
	            );
	        
	    $request_encoded = json_encode($operation);
	    //var_dump($batch_operations);
	    //var_dump($request_encoded);
	    $curl = curl_init($url);
	    curl_setopt($curl, CURLOPT_USERPWD, 'user:' . $apiKey);    
	    curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//raw output
	    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
	    curl_setopt($curl, CURLOPT_POSTFIELDS, $request_encoded); 
		$result = curl_exec($curl);
		return $result;
		//print_r($result);
		//die;
	}
	function putContent($source='',$dest='')
	{
		//$source = $_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/avatars//80/d8638342de86a99346c1cb8eaa67f8ed.png';
		//$dest = $_SERVER['DOCUMENT_ROOT'].'/newsletter_image/d8638342de86a99346c1cb8eaa67f8ed.png';
		$size = getimagesize($source);
		$this->load->library('Utility');
		$this->utility->pic_resize($source,$dest,$size[0],$size[1]);
		//print_r($size);
		//die;
	}
}
	

