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

class Free_lady_cron extends CI_Controller
{
	public function __construct()
	{ 
		parent:: __construct();
	}
	public function index(){
	  	//$currentDate = '2018-04-06';
	  	$currentDate = date('Y-m-d',time());
	    $qry = $this->db->query('select * from (select *, case when time = 365 then DATE(FROM_UNIXTIME(created + (365 * 86400))) when time = 182 then DATE(FROM_UNIXTIME(created + (182 * 86400))) end as required_date  from (SELECT feu_userdetails.username,feu_userdetails.accounttype,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` INNER JOIN `feu_userdetails` ON `usr_users`.`id` = `feu_userdetails`.`user_id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 365 then b.created <('.time().' - (365 * 86400)) when time = 182 then b.created <('.time().' - (182 * 86400)) end AND article_id in (5,4) AND required_date = "'.$currentDate.'" AND accounttype = "lady" order by b.created DESC');
	    $getUserListData = $qry->result_array();
	    //pr($getUserListData);
	    if(count($getUserListData)>0)
	    {
	    	foreach ($getUserListData as $key => $value) {
	    		/**********************MAIL**************************/
	    		//$to = 'sayan@digitalaptech.com';
	    		$to = $value['email'];
				$sub = getLang('FREE_Lady_Memberships_now_available');
				//$body= '<p>Dear '.$userData['username'].',</p>';
				$body= '<p>'.getLang('We_are_pleased_to_announce_that').'</p>';
				$body.= '<p>'.getLang('Try_it_out').'</p>';
				
				$bodys='<table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
                <tr>
                   	<td>
                      	<table cellspacing="0" cellpadding="0" border="0" width="100%">
                         	<tr>
	                            <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
	                               <h2>'.getLang('Dear').' <span style="text-transform:capitalize">'.$value['username'].'</span> </h2>
	                            </td>
                         	</tr>
                         	<tr>
	                            <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
	                               '.$body.'
	                            </td>
                         	</tr>
                         	<tr>
	                         	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
	                         		'.getLang('Best_wishes').' <br>
	                         		<p style="margin:5px 0 0">'.getLang('Your_Castleevents_Team').'</p> 
	                         	</td>
                         	</tr>
                      	</table>
                   	</td>
                </tr>
            	</table>';


				$this->utility->sendCIMail($to,$sub,$bodys);
		    	/**********************MAIL**************************/
	    	}
	    }
	}
}