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

class Profile_text extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('common_model');
		$this->load->library('Utility');
		if(!$this->session->userdata('admin_id'))
		{
			redirect('admin/login');
		}
	}
	public function list($page=''){
		$content_data = array();
		if($page=='')
		{
			$page=0;
		}
		$limit = 20;

		$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['profile_text'] = $this->common_model->getAll('feu_userdetails','','','feu_userdetails.created DESC','','',$page,$limit);
		$profile_text_list = $this->common_model->getAll('feu_userdetails','','','feu_userdetails.created DESC') ;
		if($this->input->post())
		{
			if($this->input->post('search') && $this->input->post('search_name'))
			{
				$content_data['profile_text'] = $this->common_model->getAll('feu_userdetails','','','feu_userdetails.created DESC','','',$page,$limit,array('about'=>$this->input->post('search'))) ;
				$profile_text_list = $this->common_model->getAll('feu_userdetails','','','feu_userdetails.created DESC','','','','',array('about'=>$this->input->post('search'),'username'=>$this->input->post('search_name'))) ;
			}
			if($this->input->post('search'))
			{
				$content_data['profile_text'] = $this->common_model->getAll('feu_userdetails','','','feu_userdetails.created DESC','','',$page,$limit,array('about'=>$this->input->post('search'))) ;
				$profile_text_list = $this->common_model->getAll('feu_userdetails','','','feu_userdetails.created DESC','','','','',array('about'=>$this->input->post('search'))) ;
			}
			if($this->input->post('search_name'))
			{
				$content_data['profile_text'] = $this->common_model->getAll('feu_userdetails','','','feu_userdetails.created DESC','','',$page,$limit,array('about'=>$this->input->post('search'))) ;
				$profile_text_list = $this->common_model->getAll('feu_userdetails','','','feu_userdetails.created DESC','','','','',array('username'=>$this->input->post('search_name'))) ;
			}
		}

		$this->load->library('pagination');
		$config['base_url'] = base_url().'admin/profile_text/list/';
		$config['total_rows'] = count($profile_text_list);
		$config['per_page'] = $limit;
		$this->pagination->initialize($config);

		$content_data['link'] = $this->pagination->create_links();

		$data['content'] = $this->load->view('admin/profile_text/list', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}*/
	/*public function delete($enc_userID='')
	{
		if($enc_userID!='')
		{
			$userId=base64_decode($enc_userID);
			$this->common_model->UpdateData('feu_userdetails',array('about'=>''),array('id'=>$userId));
			$this->utility->setMsg('Profile text deleted','SUCCESS');	
			redirect(base_url().'admin/profile_text/list');
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/profile_text/list');
		}
	}
	public function edit($enc_userID='')
	{
		if($enc_userID!='')
		{
			$archieveId=base64_decode($enc_userID);
			if($this->input->post())
			{
				$text=$this->utility->info_cleanQuery($this->input->post('text'));
				
				$archDetails_con=array(
							'about'=>$text
					);
				$this->common_model->UpdateData('feu_userdetails',$archDetails_con,array('id'=>$archieveId));

				$this->utility->setMsg('Profile text update','SUCCESS');	
				redirect(base_url().'admin/profile_text/edit/'.$enc_userID);
			}

			$content_data = array();
			$content_data['profile_text'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$archieveId)) ;
			$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/profile_text/edit', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/profile_text/list');
		}
	}
}