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

class Discount_users 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 index(){
		$content_data = array();
		$content_data['discounted_users'] = $this->common_model->getAllMultipleJoin('feu_user_discounts', array('discount > '=>0), array(array('feu_userdetails','feu_userdetails.user_id = feu_user_discounts.user_id'), array('usr_users','usr_users.id = feu_userdetails.user_id')),'usr_users.created DESC','*, usr_users.created');
		$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')) ;
		
		$data['content'] = $this->load->view('admin/users/discounted_users', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function update(){
		$user_id = $this->input->post('user_id');
		$discount = $this->input->post('discount');
		$details = $this->common_model->getAllRow('feu_user_discounts', array('user_id'=>$user_id));
		if($details){
			$this->common_model->UpdateData('feu_user_discounts', array('discount'=>$discount), array('user_id'=>$user_id));
		}
		echo 1; die;
	}
}