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

class Notification extends CI_Controller
{
	public function __construct()
	{ 
		parent:: __construct();
		$this->load->model('common_model');
		$this->load->model('users_model');
	}
	public function index(){
	  	//$currentDate = '2018-04-06';
	  	$currentDate = date("Y-m-d");
	  	$requiredDate = date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 month" ) );
	    $qry = $this->db->query("select * from feu_userdetails join usr_users on feu_userdetails.user_id = usr_users.id join sys_files on sys_files.id = feu_userdetails.avatar_file_id WHERE feu_userdetails.user_id = 25267 order by feu_userdetails.created DESC");
	    //$qry = $this->db->query("select user_id,username,email,accounttype,userlanguage from feu_userdetails join usr_users on feu_userdetails.user_id = usr_users.id join sys_files on sys_files.user_id = feu_userdetails.avatar_file_id WHERE DAY(monthly_summary_send_date) = '".date('d')."' AND (monthly_sended_date < ".$currentDate." OR monthly_sended_date is NULL) order by feu_userdetails.created DESC");
	    $getUserListData = $qry->result_array();
	    //echo $this->db->last_query(); die;
	    //pr($getUserListData);
	    if(count($getUserListData)>0)
	    {
	    	foreach ($getUserListData as $key => $value) {
	    		/**********************MAIL**************************/
	    		$this->common_model->UpdateData('usr_users',array('monthly_sended_date'=>date('Y-m-d')),array('id'=>$value['user_id']));
	    		$membership = $this->users_model->getMembershipDetails($value['user_id']);
	    		$profile_percent = profile_percent($value['user_id']);
	    		/*************************What happend last month*************************/
				$ConnectRequestRes = $this->db->query("SELECT count(*) as total FROM `notification` WHERE type= 1 AND from_id = ".$value['user_id']." AND DATE(FROM_UNIXTIME(created)) between '".$requiredDate."' AND '".$currentDate."'");
				$contactRequest = $ConnectRequestRes->result_array();
				$HotshotProfileRes = $this->db->query("SELECT count(*) as total FROM `notification` WHERE type= 8 AND from_id = ".$value['user_id']." AND DATE(FROM_UNIXTIME(created)) between '".$requiredDate."' AND '".$currentDate."'");
				$HotshotProfile = $HotshotProfileRes->result_array();
				$HotshotPictureRes = $this->db->query("SELECT count(*) as total FROM `notification` WHERE type= 9 AND from_id = ".$value['user_id']." AND DATE(FROM_UNIXTIME(created)) between '".$requiredDate."' AND '".$currentDate."'");
				$HotshotPicture = $HotshotPictureRes->result_array();
				$VisitRes = $this->db->query("SELECT count(*) as total FROM `notification` WHERE type= 10 AND from_id = ".$value['user_id']." AND DATE(FROM_UNIXTIME(created)) between '".$requiredDate."' AND '".$currentDate."'");
				$Visit = $VisitRes->result_array();
				$VisitHisProfileRes = $this->db->query("SELECT count(*) as total FROM `notification` WHERE type= 10 AND to_id = ".$value['user_id']." AND DATE(FROM_UNIXTIME(created)) between '".$requiredDate."' AND '".$currentDate."'");
				$VisitHisProfile = $VisitHisProfileRes->result_array();
				$UploadRes = $this->db->query("SELECT count(*) as total FROM `notification` WHERE type= 12 AND from_id = ".$value['user_id']." AND DATE(FROM_UNIXTIME(created)) between '".$requiredDate."' AND '".$currentDate."'");
				$Upload = $UploadRes->result_array();
				/*************************What happend last month*************************/

				/********************Get started by connecting people below***********************/
				$currWeekdate = date('Y-m-d');
				$SevenWeekdate = date("Y-m-d", strtotime( date( "Y-m-d", strtotime( date("Y-m-d") ) ) . "-1 week" ) );
				if($value['accounttype']=='gentleman')
				{
					$peoplesQry = $this->db->query("select * from feu_userdetails join feu_countries on feu_userdetails.country = feu_countries.country_code join sys_files on sys_files.id = feu_userdetails.avatar_file_id WHERE accounttype = 'lady' AND DATE(FROM_UNIXTIME(feu_userdetails.created)) between '".$SevenWeekdate."' AND '".$currWeekdate."' ORDER BY feu_userdetails.created DESC LIMIT 2");
					$peoples = $peoplesQry->result_array();
				}
				if($value['accounttype']=='couple')
				{
					$peoplesQry = $this->db->query("select * from feu_userdetails join feu_countries on feu_userdetails.country = feu_countries.country_code join sys_files on sys_files.id = feu_userdetails.avatar_file_id WHERE accounttype = 'couple' AND DATE(FROM_UNIXTIME(feu_userdetails.created)) between '".$SevenWeekdate."' AND '".$currWeekdate."' ORDER BY feu_userdetails.created DESC LIMIT 2");
					$peoples = $peoplesQry->result_array();
				}
				if($value['accounttype']=='lady')
				{
					$coupleQry = $this->db->query("select * from feu_userdetails join feu_countries on feu_userdetails.country = feu_countries.country_code join sys_files on sys_files.id = feu_userdetails.avatar_file_id WHERE accounttype = 'couple' AND DATE(FROM_UNIXTIME(feu_userdetails.created)) between '".$SevenWeekdate."' AND '".$currWeekdate."' ORDER BY feu_userdetails.created DESC LIMIT 1");
					$peoples = $coupleQry->result_array();
					$gentlemanQry = $this->db->query("select * from feu_userdetails join feu_countries on feu_userdetails.country = feu_countries.country_code join sys_files on sys_files.id = feu_userdetails.avatar_file_id WHERE accounttype = 'gentleman' AND DATE(FROM_UNIXTIME(feu_userdetails.created)) between '".$SevenWeekdate."' AND '".$currWeekdate."' ORDER BY feu_userdetails.created DESC LIMIT 1");
					$gentlemans = $gentlemanQry->result_array();
					array_merge($peoples,$gentlemans);
				}
				/********************Get started by connecting people below***********************/
				
				/********************Get started by connecting people below***********************/
				$adverts = $this->common_model->getAllMultipleJoin('adverts',array('visible'=>1,'adverts_lang_values.lang_id'=>$value['userlanguage']),array(array('adverts_lang_values','adverts_lang_values.adverts_id = adverts.id')),'display_order ASC','','',0,2);
				//pr($adverts);
				/********************Get started by connecting people below***********************/
	    		

	    		$to = 'sayan@digitalaptech.com';
	    		if(file_exists($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$value['path'].'/320/'.$value['filename'].'.'.$value['extension']))
				{
					$usercidurl = base_url().'/newsletter_image/'.$value['filename'].'.'.$value['extension'];
					$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$value['path'].'/320/'.$value['filename'].'.'.$value['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$value['filename'].'.'.$value['extension']);
				}
	    		else
	    		{
	    			$usercidurl = base_url().'newsletter_image/crown_log.svg';
	    		}
                $site_address_name = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
                $site_address_city = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
                $site_address_country_zip = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));
	    		$to = 'milanmal123@rediffmail.com';
	    		//$to = $value['email'];
				$sub = 'Notification mail';
				$body= '<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8"> 
	<meta  name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0," /> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="x-apple-disable-message-reformatting">  
	<title></title> 

	
    <style>

		html,
        body {
	        margin: 0 auto !important;
            padding: 0 !important;
            height: 100% !important;
            width: 100% !important;
        }

       
        * {
            -ms-text-size-adjust: 100%;
            -webkit-text-size-adjust: 100%;
        }

       
        div[style*="margin: 16px 0"] {
            margin:0 !important;
        }

       
        table,
        td {
            mso-table-lspace: 0pt !important;
            mso-table-rspace: 0pt !important;
        }

       
        table {
            border-spacing: 0 !important;
            border-collapse: collapse !important;
            table-layout: fixed !important;
            margin: 0 auto !important;
        }
        table table table {
            table-layout: auto;
        }

        
        img {
            -ms-interpolation-mode:bicubic;
        }

        
        *[x-apple-data-detectors] {
            color: inherit !important;
            text-decoration: none !important;
        }

        
        .x-gmail-data-detectors,
        .x-gmail-data-detectors *,
        .aBn {
            border-bottom: 0 !important;
            cursor: default !important;
        }

        
        .a6S {
	        display: none !important;
	        opacity: 0.01 !important;
        }
        
        img.g-img + div {
	        display:none !important;
	   	}

        
        .button-link {
            text-decoration: none !important;
        }

       
        @media only screen and (min-device-width: 375px) and (max-device-width: 413px) {
            table.email-container {
                min-width: 375px !important;
            }
        }

    </style>
    
   
    <style>

        
        .button-td,
        .button-a {
            transition: all 100ms ease-in;
        }
        .button-td:hover,
        .button-a:hover {
            background: #555555 !important;
            border-color: #555555 !important;
        }

       
        @media screen and (max-device-width: 600px) {

            table.email-container {
                width: 100% !important;
                margin: auto !important;
            }

           
            img.fluid {
                max-width: 100% !important;
                height: auto !important;
                margin-left: auto !important;
                margin-right: auto !important;
            }

            
            
            td.stack-column-center {
                display: block !important;
                width: 100% !important;
                max-width: 100% !important;
                direction: ltr !important;
                padding: 20px 0 !important;
            }
           
            td.stack-column-center {
                text-align: center !important;
            }

            
            td.center-on-narrow {
                text-align: center !important;
                display: block !important;
                margin-left: auto !important;
                margin-right: auto !important;
                float: none !important;
            }
            table.center-on-narrow {
                display: inline-block !important;
            }

           
			table.email-container p {
				font-size: 17px !important;
				line-height: 22px !important;
			}

            img.logocastle{
                width: 90% !important;
            }
            a.community{ width: 40% !important; margin-bottom: 30px !important; }
            td.paddingnormal{ padding: 20px 10px !important; }
			
        }

    </style>

</head>
<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;">     
             

        
        <table role="presentation" aria-hidden="true" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" align="center" width="700" style="margin: auto; color: #656565;" 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" border="0" align="center" style="margin: auto; color: #656565;">
                        <tbody>
                        <tr>
                            <td class="stack-column-center"  style="padding:20px 40px; vertical-align:top; background: #c3c3c3;width: 620px;">     
                                <img src="'.base_url().'newsletter_image/castlecrown.svg" width="70" alt="" style="display: inline-block; -webkit-filter: brightness(100); filter: brightness(100); vertical-align: middle;"> 
                                <span style="color: #fff; font-size: 20px; padding-left: 20px">Monthly news</span>                              
                            </td>
                            
                        </tr>                    
                       </tbody>
                    </table>
                </td>
            </tr>

            
			<tr>
				<td style=" background: #f1f1f1; padding: 0 0 20px; text-align: center; position: relative; min-height: 100px; height: 100px;">
					<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%; position: absolute; top: -40px; left: 50%; margin-left: -60px;">
                       <img width="100%" height="120px" src="'.$usercidurl.'" alt="userpic">
                   </div>

                   <h2 style=" margin: 0; padding-top: 100px; font-weight: normal;font-size: 30px; color: #656565;"><span style="text-transform: uppercase;">'.$value['username'].'</span>\'s. monthly summary</h2>

                    <button style="text-transform: uppercase; color: #fff;background: #b3975b; padding: 7px 20px; -webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px; margin-top: 20px; border: none;    font-size: 17px; cursor: pointer;">';
                if($membership)
                {
                	if($membership['id']==4)
                	{
        $body.=        		'Basic membership';
                	}
                	else
                	{
        $body.=        		'Premium membership';
                	}
                } 
                elseif($value['free_member']==1)
                {
        $body.=         	'Free membership';
                } 
                else
                {
        $body.=         	'No membership';
                } 	
        $body.= 		'</button><br>

                    <a href="#" style="font-size: 20px; margin: 30px 10px 0; display: inline-block; color: #656565; text-decoration: underline;">
                        <img src="'.base_url().'newsletter_image/hourglass.svg" width="30px" alt="" style=" float: none; display: inline-block;
                        vertical-align: middle; margin-right: 10px;"> Profile is '.$profile_percent.'% complete
                    </a> 
                    <a href="'.base_url().'settings'.'" style="font-size: 20px; margin: 30px 10px 0; display: inline-block; color: #656565; text-decoration: underline;"> <img src="'.base_url().'newsletter_image/settings.svg" width="30px" alt="" style=" float: none; display: inline-block;
                        vertical-align: middle; margin-right: 10px;"> Settings</a>
				</td>
			</tr>
        </table>
        

        
        <table role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" align="center" width="700" style="margin: auto; color: #656565" class="email-container">
           
              <tr>
                  <td style="background: #f1f1f1; text-align:center;  padding-bottom: 15px;">
                        <h2 style=" margin: 0; padding-top: 30px;  padding-bottom: 40px; font-weight: normal; font-size: 30px; color: #656565;">What happened last month</h2>

                        <span style=" display: inline-block; width: 30%; font-size: 20px; color: #656565;">
                            <img src="'.base_url().'newsletter_image/eye.svg" width="60px" alt="" style=" display: inline-block; vertical-align: middle; margin-right: 15px;"> Visitors '.count($Visit).'
                        </span>
                        <span style=" display: inline-block; width: 30%; font-size: 20px; color: #656565;">
                            <img src="'.base_url().'newsletter_image/fire.svg" width="60px" alt="" style=" display: inline-block; vertical-align: middle; margin-right: 15px;"> Hotshots '.(count($HotshotPicture)+count($HotshotProfile)).'
                        </span>
                        <span style=" display: inline-block; width: 30%; font-size: 20px; color: #656565;">
                            <img src="'.base_url().'newsletter_image/two-men.svg" width="60px" alt="" style=" display: inline-block; vertical-align: middle; margin-right: 15px;"> Requests '.count($contactRequest).'
                        </span>

                        <a href="#" style="display: inline-block; text-decoration: none; margin-top: 40px; background: #fff; color: #656565; padding: 7px 20px;    -webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px;  border: none; font-size: 17px; cursor: pointer;">See all yours statistics</a>
                  </td>                  
               </tr>

               <tr>
                  	<td style="background: #f1f1f1; text-align:center;  padding-bottom: 15px;">
                        <h2 style=" margin: 0; padding-top: 30px;  padding-bottom: 10px; font-weight: normal; font-size: 30px; color: #656565;">Who Looked at your profile</h2>';
                    	if(count($VisitHisProfile)==0)
                        {  
        $body.=				'<p style="">You\'ve had no new profile views this month . See our tips below on how to get people and companies to find you.</p>';
                        }
                        else
                        {  
        $body.=				'<p style="">You\'ve had profile views this month. After entering our website you will find all visitors in your dashboard.</p>';
                        }
        $body.=     '</td>                  
               </tr>

               <tr>
                  <td style="background: #f1f1f1; padding: 0 20px; text-align:center;  padding-bottom: 15px;">
                        <h2 style=" margin: 0; padding-top: 30px;  padding-bottom: 40px; font-weight: normal; font-size: 30px; color: #656565;">Tips on getting more profile views</h2>

                        <span style="display: inline-block; text-align: left; margin-bottom: 20px; width: 49%; float: left;">
                           <img src="'.base_url().'newsletter_image/play-button.svg" alt="" width="25px" style="display: inline-block;
                         margin-right: 10px; vertical-align: middle;"> Upgrade to Besic Membership
                        </span>

                        <span style="display: inline-block; text-align: left; margin-bottom: 20px; width: 49%; float: left;">
                           <img src="'.base_url().'newsletter_image/fire2.svg" alt="" width="25px" style="display: inline-block;
                         margin-right: 10px; vertical-align: middle;"> Give Hotshots <label style="font-weight: normal; font-size: 12px;">(more than 10,000 pictures)</label>
                        </span>

                        <span style="display: inline-block; text-align: left; margin-bottom: 20px; width: 49%; float: left;">
                           <img src="'.base_url().'newsletter_image/instagram.svg" alt="" width="25px" style="display: inline-block;
                         margin-right: 10px; vertical-align: middle;"> Upload more pictures
                        </span>

                        <span style="display: inline-block; text-align: left; margin-bottom: 20px; width: 49%; float: left;">
                           <img src="'.base_url().'newsletter_image/video-camera.svg" alt="" width="25px" style="display: inline-block;
                         margin-right: 10px; vertical-align: middle;"> Upload Videos <label style="font-weight: normal; font-size: 12px;">(New)</label>
                        </span>

                        <p style="color: #b3975b;">(<strong>New</strong>) Hottest Shot of the months win amazing prices</p>                                           
                        
                  </td>                  
               </tr>

               <tr>
                  <td style="background: #f1f1f1; padding: 0 20px; text-align:center;  padding-bottom: 15px;">
                        <h2 style=" margin: 0; padding-top: 30px;  padding-bottom: 10px; font-weight: normal; font-size: 30px; color: #656565;">Updates from who you follow</h2>
                        <p style="line-height: 22px;">We can\'t let you know about any updates in your network as you aren\'t following or connected with anyone</p>                       
                        
                  </td>                  
               </tr>

               <tr>
                  <td style="background: #f1f1f1; padding: 0 20px; text-align:center;  padding-bottom: 15px;">
                        <h3 style=" margin: 0; padding-top: 30px;  padding-bottom: 10px; font-weight: normal; font-size: 20px; color: #656565;">Get started by connecting people below</h3>                                  
                        
                  </td>                                   
               </tr>

               <tr>
                   <td>
                      
                      <table style="background: #f1f1f1;" role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" align="center" width="700" style="margin: auto; color: #656565" class="email-container">
                          <tr>';
                          	if(count($peoples)>0)
                          	{
            					foreach ($peoples as $key => $peoplesval) {
	            					$peoplesurl.$key = base_url().'/newsletter_image/'.$peoplesval['filename'].'.'.$peoplesval['extension'];
		    						$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/'.$peoplesval['path'].'/320/'.$peoplesval['filename'].'.'.$peoplesval['extension'],$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$peoplesval['filename'].'.'.$peoplesval['extension']);
	            $body.=				'<td align="center">
		                                 <div style="text-align: left; background: #fff; margin: 10px 20px; border-radius: 10px; padding: 15px;">
		                                    <div style="width:80px; 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 width="100%" height="80px" style="margin-right: 20px;" src="'.$peoplesurl.$key.'" alt="userpic">                                                   
		                                    </div>
		                                     <div style="display: inline-block; padding-left: 10px; padding-top:15px ">
		                                         <h3 style=" margin:0 0 5px;font-weight: normal; color: #b3975b;">'.$peoplesval['username'].'</h3>
		                                         <p style="margin: 0;">'.ucfirst($peoplesval['accounttype']).'/'.$peoplesval['country_name'].'</p>
		                                     </div>
		                                     <a href="'.base_url().'profil/'.$peoplesval['alias'].'" style="color: #fff; background: #d4d4d4; text-transform: uppercase; padding: 10px 15px; margin-top: 25px; -webkit-border-radius: 6px; -moz-border-radius: 6px; -ms-border-radius: 6px; border-radius: 6px; display: block; text-decoration: none; text-align: center;">Visit profile</a>
		                                 </div>
		                              </td>';  
		                        }                  		
                          	}  

            $body.=     '</tr>


                      </table>
               
                   </td>
               </tr> 

               <tr>
                  <td style="background: #f1f1f1; padding: 0 20px; text-align:center;  padding-bottom: 15px;">
                        <h3 style=" margin: 0; padding-top: 30px;  padding-bottom: 10px; font-weight: normal; font-size: 20px; color: #656565;">News from our network</h3>
                        <p style="line-height: 22px;">See Whats new in our parties and community</p>                                    
                        
                  </td>                                   
               </tr> 
               <tr>
                   <td>
                      
                      <table style="background: #f1f1f1;" role="presentation" aria-hidden="true" cellspacing="0" cellpadding="0" border="0" align="center" width="700" style="margin: auto; color: #656565" class="email-container">
                          <tr>';
                          	if(count($adverts)>0)
                          	{
            					foreach ($adverts as $advertskey => $advertsval) {
	            					$str = explode('/',$advertsval['image']);
			  						$advimage = end($str);
	            					$advertsurl.$advertskey = base_url().'/newsletter_image/'.$advimage;
		    						$this->putContent($_SERVER['DOCUMENT_ROOT'].'/assets/userfiles/adverts/160/'.$advimage,$_SERVER['DOCUMENT_ROOT'].'/newsletter_image/'.$advimage);
	        $body.=					'<td align="center">
		                                 <div style="text-align: left; background: #fff; margin: 10px 20px; border-radius: 10px; padding: 15px;">
		                                    
		                                          <img src="'.$advertsurl.$advertskey.'" style="width: 100%; margin-bottom: 20px;" alt="">
		                                         <h2 style="font-weight: normal; font-size: 22px; margin: 0; color: #b3975b;">'.$advertsval['title'].'</h2>
		                                         <p style="margin: 5px 0 0;">'.$advertsval['intro_text'].'</p> 
		                                     <a href="'.$advertsval['link'].'" style="color: #fff; background: #d4d4d4; text-transform: uppercase; padding: 10px 15px; margin-top: 25px; -webkit-border-radius: 6px; -moz-border-radius: 6px; -ms-border-radius: 6px; border-radius: 6px; display: block; text-decoration: none; text-align: center;">Read more</a>
		                                 </div>
		                            </td>';  
		                        }                  		
                          	}
            $body.=     '</tr>
                      </table>
               
                   </td>
               </tr>



               <tr>
                  <td style="background: #f1f1f1; padding:50px 20px 15px; text-align:center;  ">                 
                        <p style="line-height: 22px;">These is automated email send by castleevents website. Please do not reply.</p>               
                        
                  </td>                                   
               </tr> 

               <tr>
                  <td style="background: #f1f1f1; padding: 0 20px; text-align: center; border-top: 2px solid #fff;
                     border-bottom: 2px solid #fff;">                 
                        <p style="line-height: 22px;">Copyright 2018 &copy; Anexus AG. All rights reserved.</p>
                        <p>'.$site_address_name['value'].', '.$site_address_city['value'].', '.$site_address_country_zip['value'].'</p>               
                        
                  </td>                                   
               </tr> 

                <tr>
                  <td style="background: #f1f1f1; padding: 10px 20px 40px; text-align: center;">                 
                        <a href="'.base_url().'notification/unsubscribe/'.$value['user_id'].'" style="color: #656565; display: inline-block; margin: 0 10px; border-right: 1px solid #656565; padding-right: 10px;text-decoration: none;">Unsubscribe</a>
                        <a href="'.base_url().'settings" style="color: #656565; display: inline-block; margin: 0; text-decoration: none;">Edit your Details</a>              
                        
                  </td>                                   
               </tr>           
        
        </table>
        

    </center>
</body>
</html>
';
				
				
            	echo $body; die;
            	$from='noreply@castleevents.com';
				$email_config = Array(
					'protocol' => 'smtp',
		              'smtp_host' => 'smtp.mandrillapp.com',
		              'smtp_user' => 'castleevents',
		              'smtp_pass' => 'TveFwCTbtHjorrsBDKwJ8Q',
		              'smtp_port' => 587,
		              'mailtype' => 'html',
		              'crlf' => "rn",
		              'newline' => "rn",
		              'charset' => 'utf-8',
		              'wordwrap' => TRUE
				);

				$this->load->library('email');
				$this->email->initialize($email_config);
				$this->email->from($from, 'Castleevents');
				$this->email->to($to);
				$this->email->subject($sub);
				$this->email->message($body);
				$mail = $this->email->send();

				die;
		    	/**********************MAIL**************************/
	    	}
	    }
	}
	public function unsubscribe($user_id)
	{
		$this->common_model->UpdateData('usr_users',array('monthly_summary_status'=>0),array('id'=>$user_id));
		redirect(base_url());
	}
	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;
	}
}