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

class Newsletterlog extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('common_model');
		if(get_cookie('admin_id'))
		{
			$this->session->set_userdata('admin_id',get_cookie('admin_id'));
		}
		if(!$this->session->userdata('admin_id'))
		{
			redirect('admin/login');
		}
	}

	public function alllist($page=''){
		$content_data = array();
		if($page=='')
		{
			$page=0;
		}
		$limit = 10;

		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$where = "subscribe = 1 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','','');
		$content_data['totalusers'] = count($userlist);
		//$qry = "select subscription_mail_send_date,count(id) from usr_users where subscription_mail_send > 0 group by subscription_mail_send_date";
		$content_data['users'] = $this->common_model->getAllMultipleJoin('usr_users',array('subscription_mail_send >'=>0),'','id ASC','subscription_mail_send_date,count(id) as count','subscription_mail_send_date');
		
		$data['content'] = $this->load->view('admin/users/newletterlog', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function alllists($page=''){
		$content_data = array();
		if($page=='')
		{
			$page=0;
		}
		$limit = 10;

		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$content_data['users'] = $this->common_model->getAllMultipleJoin('bouncing_system','','','id ASC','','');
		if(!empty($content_data['users']))
		{
			foreach ($content_data['users'] as $key => $value) {
				if(strtolower($value['type'])==strtolower('English Newsletter'))
				{
					$where = "subscribe = 1 and userlanguage in (2,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 DESC');
				}
				else
				{
					$where = "subscribe = 1 and userlanguage = 1 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 DESC');
				}
				$content_data['users'][$key]['total'] = count($userlist);
				if(count($userlist)==2070)
				{
					$content_data['users'][$key]['total'] = '2090';
				}
			}
		}
		//print_r($content_data['users']); die;
		$data['content'] = $this->load->view('admin/users/newletterlogs', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	
}