<?php
class rate extends Controller
{

	function rate()
	{

		parent::Controller();
	}


	function index()
	{
	    if($this->clogin->is_logged_in())
		{
			redirect("admin/cpanel", "Location");
		}
		else
		{
			redirect("login/index", "Location");
		}
	}

/**
 ***********************************************************************
 * @Start Rate Name  Section *******************************************
 ***********************************************************************
*/


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Rate Name List
 * @copyright 2011
 */

	function rateList($errorMessage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD == NO_ACCESS)
			redirect("admin/cpanel/accessDenied", "Location");
			
			
			$data['description'] = "NULL";
			$data['level'] = "NULL";
			$data['startoffset'] = "0";
			$data['limit'] = LIMIT_PERPAGE;
			$data['total'] = $this->rateModel->getTotalnumRate($description='NULL',$level='NULL');
			$data['rateList'] = $this->rateModel->rateList($startoffset = 0,$limit = LIMIT_PERPAGE,$description='NULL',$level='NULL');
			$data['titleMessage'] = TITLE017;
			if($errorMessage ==-1)
			$data['titleErrorMessage'] = "<span style='color:#BF0000'>:: Please at first Delete all Child Client</span>";
			elseif($errorMessage ==1)
			$data['titleErrorMessage'] = "<span style='color:#BF0000'>::You have sucessfull deleted Rate </span>";
			else
			$data['titleErrorMessage'] = "";
			$this->load->view('rate/rate_list',$data);
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Rate Name List Pagination
 * @copyright 2011
 */
 
	function rateListPagination($startoffset,$limit,$description,$level,$myRandom=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			$data['description'] = $description;
			$data['level'] = $level;
			$data['startoffset'] = $startoffset;
			$data['limit'] = $limit;
			$data['total'] = $this->rateModel->getTotalnumRate($description,$level);
			$data['rateList'] = $this->rateModel->rateList($startoffset,$limit,$description,$level);
			$data['titleMessage'] = TITLE017;
			$data['titleErrorMessage'] = "";
			$this->load->view('rate/rate_list_pagi',$data);
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	

/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Add Form of Rate Name
 * @copyright 2011
 */
	
	function addForm($errorMesssage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{

				$data['id_rate']		= '';
				$data['description']		= '';
				$data['action']		= 'Add';
				$data['titleMessage'] = TITLE025;

				if($errorMesssage==0)
				$data['titleErrorMessage'] = "";
				elseif($errorMesssage==-1)
				$data['titleErrorMessage'] = "<span style='color:#BF0000'>:: Please fill up all mandatory filed</span>";
				else
				$data['titleErrorMessage'] = "";



				$this->load->view('rate/add_form',$data);

			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Add/Edit Rate Name
 * @copyright 2011
 */
 

	function addEdit()
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $action = $this->input->post('action');
               $description = $this->input->post('description');
 
               if(empty($description))
               redirect("rate/addForm/-1", "Location");

               $addDscripttion = "Add New Rate,  Description: ".$description;
			   $editDescripttion = "Edit  Rate,  Description: ".$description;

			   if($action=="Add")
			   {
			      $this->rateModel->addRate($userID);
			      $this->generallib->addUserLog($userID,'-1','Insert',$addDscripttion);
			      redirect("rate/rateList", "Location");
			   }
			   else
			   {
			      $this->rateModel->editRate();
			      $this->generallib->addUserLog($userID,'-1','Edit',$editDescripttion);
			      redirect("rate/rateList", "Location");
			   }

			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Edit Form of Rate name 
 * @copyright 2011
 */
 
	function editForm($idRate=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $editInfo = $this->rateModel->rateEditInfo($idRate);
                if($editInfo==0)
                {
                   redirect("rate/rateList", "Location");
                }
                else
                {
                   foreach($editInfo as $row)
                   {
				   	 $data['id_rate']		= $row->id_rate;
					 $data['description']		= $row->description;
                   }
                   
                   $data['titleErrorMessage'] = "";
                   $data['titleMessage'] = TITLE025;
				   $data['titlePersonalMessage'] = TITLE009;
				   $data['action']		= 'Edit';
                   $this->load->view('rate/add_form',$data);
                }
			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Rate Name Delete
 * @copyright 2011
 */
 

	function deleteRate($idRate)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $this->rateModel->deleteRate($idRate);
               redirect("rate/rateList/1", "Location");
			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Export Of Rate Chart
 * @copyright 2011
 */
 

	function exportRate($idRate=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $strRate = "SL,Prefix,Description,Rate,Rate Mult, GracePeriod,MinimalTime,Resolution,ISDisable"."\n";
				$rateInfo = $this->rateModel->rateChartInfo($idRate);
                if($rateInfo == 0)
                {
                   redirect("rate/rateList", "Location");
                }
                else
                {
                   $k =1;
				   foreach($rateInfo as $row)
                   {
				   	 $id_rate		= $row->id_rate;
				   	 $prefix		= $row->prefix;
				   	 $description		= $row->description;
				   	 $voice_rate		= $row->voice_rate;
				   	 $rate_mult 		= $row->rate_mult;
				   	 $grace_period		= $row->grace_period;
				   	 $minimal_time		= $row->minimal_time;
				   	 $resolution		= $row->resolution;
				   	 $is_disable		= $row->is_disable;
				   	 $strRate .=$k.",".$prefix.",".$description.",".$voice_rate.",".$rate_mult.",".$grace_period.",".$minimal_time.",".$resolution.",".$is_disable."\n";
                     $k++;
				   }
				   header("Content-type: application/vnd.ms-excel");
  				   header("Content-disposition: csv; filename=rate_" . date("Ymd") .".csv");
  				   print $strRate;
  				   exit;				   
                }
			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}


/**
 ***********************************************************************
 * @Start Rate Chart  Section *******************************************
 ***********************************************************************
*/




/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Rate Chart List
 * @copyright 2011
 */


	function rateChartListPOPup($idRate,$errorMessage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			$data['rateName'] = $this->generallib->getReteName($idRate);
			$data['description'] = "NULL";
			$data['prefix'] = "NULL";
			$data['idRate'] = $idRate;
			$data['grace_period'] = "NULL";
			$data['resolution'] = "NULL";
			$data['startoffset'] = "0";
			$data['limit'] = LIMIT_PERPAGE;
			$data['total'] = $this->rateModel->getTotalnumRateChart($idRate,$description='NULL',$prefix='NULL',$grace_period='NULL',$resolution='NULL');
			$data['rateChartList'] = $this->rateModel->rateChartList($startoffset = 0,$limit = LIMIT_PERPAGE,$idRate,$description='NULL',$prefix='NULL',$grace_period='NULL',$resolution='NULL');			
			$data['titleMessage'] = TITLE017;
			if($errorMessage ==-1)
			$data['titleErrorMessage'] = "<span style='color:#BF0000'>:: Please Check your CSV File</span>";
			elseif($errorMessage ==1)
			$data['titleErrorMessage'] = "<span style='color:#BF0000'>::You have sucessfull deleted Rate Chart </span>";
			elseif($errorMessage ==2)
			$data['titleErrorMessage'] = "<span style='color:#BF0000'>::You have sucessfull Uploaded Rate Chart </span>";
			else
			$data['titleErrorMessage'] = "";
			$this->load->view('rate/rate_chart_list_popup',$data);
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Rate Chart List Pagination
 * @copyright 2011
 */
 
	function rateChartPOPupPagination($startoffset,$limit,$description,$prefix,$grace_period,$resolution,$idRate,$myRandom=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			$data['rateName'] = $this->generallib->getReteName($idRate);
			$data['description'] = $description;
			$data['prefix'] = $prefix;
			$data['idRate'] = $idRate;
			$data['grace_period'] = $grace_period;
			$data['resolution'] = $resolution;
			$data['startoffset'] = $startoffset;
			$data['limit'] = $limit;
			$data['total'] = $this->rateModel->getTotalnumRateChart($idRate,$description,$prefix,$grace_period,$resolution);
			$data['rateChartList'] = $this->rateModel->rateChartList($startoffset,$limit,$idRate,$description,$prefix,$grace_period,$resolution);	
			$data['titleMessage'] = TITLE017;
			$data['titleErrorMessage'] = "";
			$this->load->view('rate/rate_chart_list_popup_pagi',$data);
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	
	
	



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Rate Chart List
 * @copyright 2011
 */


	function rateChartList($idRate,$errorMessage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD == NO_ACCESS)
			redirect("admin/cpanel/accessDenied", "Location");
			
			$data['rateName'] = $this->generallib->getReteName($idRate);
			$data['description'] = "NULL";
			$data['prefix'] = "NULL";
			$data['idRate'] = $idRate;
			$data['grace_period'] = "NULL";
			$data['resolution'] = "NULL";
			$data['startoffset'] = "0";
			$data['limit'] = LIMIT_PERPAGE;
			$data['total'] = $this->rateModel->getTotalnumRateChart($idRate,$description='NULL',$prefix='NULL',$grace_period='NULL',$resolution='NULL');
			$data['rateChartList'] = $this->rateModel->rateChartList($startoffset = 0,$limit = LIMIT_PERPAGE,$idRate,$description='NULL',$prefix='NULL',$grace_period='NULL',$resolution='NULL');			
			$data['titleMessage'] = TITLE017;
			if($errorMessage ==-1)
			$data['titleErrorMessage'] = "<span style='color:#BF0000'>:: Please Check your CSV File</span>";
			elseif($errorMessage ==1)
			$data['titleErrorMessage'] = "<span style='color:#BF0000'>::You have sucessfull deleted Rate Chart </span>";
			elseif($errorMessage ==2)
			$data['titleErrorMessage'] = "<span style='color:#BF0000'>::You have sucessfull Uploaded Rate Chart </span>";
			else
			$data['titleErrorMessage'] = "";
			$this->load->view('rate/rate_chart_list',$data);
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Rate Chart List Pagination
 * @copyright 2011
 */
 
	function rateChartPagination($startoffset,$limit,$description,$prefix,$grace_period,$resolution,$idRate,$myRandom=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			$data['rateName'] = $this->generallib->getReteName($idRate);
			$data['description'] = $description;
			$data['prefix'] = $prefix;
			$data['idRate'] = $idRate;
			$data['grace_period'] = $grace_period;
			$data['resolution'] = $resolution;
			$data['startoffset'] = $startoffset;
			$data['limit'] = $limit;
			$data['total'] = $this->rateModel->getTotalnumRateChart($idRate,$description,$prefix,$grace_period,$resolution);
			$data['rateChartList'] = $this->rateModel->rateChartList($startoffset,$limit,$idRate,$description,$prefix,$grace_period,$resolution);	
			$data['titleMessage'] = TITLE017;
			$data['titleErrorMessage'] = "";
			$this->load->view('rate/rate_chart_list_pagi',$data);
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Add Form of Rate Chart 
 * @copyright 2011
 */
 

	function addRateForm($idRate,$errorMesssage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
				$data['id']		= '';
				$data['id_rate']		= $idRate;
				$data['prefix']		= '';
				$data['description']		= '';
				$data['voice_rate']		= '';
				$data['rate_mult']		= '1';
				$data['grace_period']		= '0';
				$data['minimal_time']		= '60';
				$data['resolution']		= '60';
				$data['is_disable']		= '0';			
				$data['action']		= 'Add';
				$data['titleMessage'] = TITLE028;
				$data['titleFormMessage'] = TITLE029;

				if($errorMesssage==0)
				$data['titleErrorMessage'] = "";
				elseif($errorMesssage==-1)
				$data['titleErrorMessage'] = "<span style='color:#BF0000'>:: Please fill up all mandatory filed</span>";
				else
				$data['titleErrorMessage'] = "";



				$this->load->view('rate/rate_chart_form',$data);

			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Add/Edit Rate Chart
 * @copyright 2011
 */
 

	function addEditRateChart()
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $action = $this->input->post('action');
               $id_rate = $this->input->post('id_rate');
               $prefix = $this->input->post('prefix');
               $voice_rate = $this->input->post('voice_rate');
               $grace_period = $this->input->post('grace_period');
               $minimal_time = $this->input->post('minimal_time');
               $resolution = $this->input->post('resolution');
               $description = $this->input->post('description');
 
               if(empty($id_rate) OR empty($prefix) OR empty($voice_rate) OR empty($minimal_time) OR empty($resolution) OR empty($description))
               redirect("rate/addRateForm/".$id_rate."/-1", "Location");
               
               if(!is_numeric($voice_rate) OR !is_numeric($grace_period) OR !is_numeric($minimal_time) OR !is_numeric($resolution))
               redirect("rate/addRateForm/".$id_rate."/-1", "Location");
               

               $addDscripttion = "Add New Rate Chart,  Description: ".$description." Prefix: ".$prefix." Rate: ".$voice_rate;
			   $editDescripttion = "Edit Rate Chart,  Description: ".$description." Prefix: ".$prefix." Rate: ".$voice_rate;

			   if($action=="Add")
			   {
			      $this->rateModel->addRateChart($id_rate,$userID);
			      $this->generallib->addUserLog($userID,'-1','Insert',$addDscripttion);
			      redirect("rate/rateChartList/".$id_rate, "Location");
			   }
			   else
			   {
			      $this->rateModel->editRateChart($userID);
			      $this->generallib->addUserLog($userID,'-1','Edit',$editDescripttion);
			      redirect("rate/rateChartList/".$id_rate, "Location");
			   }

			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Edit Form of Rate Chart
 * @copyright 2011
 */
 

	function editRateChartForm($idRate=0,$id=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $editInfo = $this->rateModel->rateChartEditInfo($id,$idRate);
                if($editInfo==0)
                {
                   redirect("rate/rateChartList/".$idRate, "Location");
                }
                else
                {
                   foreach($editInfo as $row)
                   {
						$data['id']		= $row->id;
						$data['id_rate']		= $row->id_rate;
						$data['prefix']		= $row->prefix;
						$data['description']		= $row->description;
						$data['voice_rate']		= $row->voice_rate;
						$data['rate_mult']		= $row->rate_mult;
						$data['grace_period']		= $row->grace_period;
						$data['minimal_time']		= $row->minimal_time;
						$data['resolution']		= $row->resolution;
						$data['is_disable']		= $row->is_disable;
                   }
                   
                   $data['titleErrorMessage'] = "";
				   $data['titleMessage'] = TITLE030;
				   $data['titleFormMessage'] = TITLE029;
				   $data['action']		= 'Edit';
                   $this->load->view('rate/rate_chart_form',$data);
                }
			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Delete Rate Chart Prefix
 * @copyright 2011
 */
 

	function deleteRateChart($idRate,$id)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $this->rateModel->deleteRateChart($idRate,$id);
               redirect("rate/rateChartList/".$idRate."/1", "Location");
			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Export Rate Chart
 * @copyright 2011
 */
 

	function exportSearchRateChart($description,$prefix,$grace_period,$resolution,$idRate,$myRandom=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD == NO_ACCESS)
			redirect("admin/cpanel/accessDenied", "Location");
			
			$rateName = $this->generallib->getReteName($idRate);
			$rateChartList = $this->rateModel->exportSearchRateChartList($idRate,$description,$prefix,$grace_period,$resolution);
			
			    $strRate = "SL,Prefix,Description,Rate,Rate Multi, GracePeriod,MinimalTime,Resolution,ISDisable"."\n";
                if($rateChartList==0)
                {
                   redirect("rate/rateChartList/".$idRate, "Location");
                }
                else
                {
                   $k =1;
				   foreach($rateChartList as $row)
                   {
				   	 $id_rate		= $row->id_rate;
				   	 $prefix		= $row->prefix;
				   	 $description		= $row->description;
				   	 $voice_rate		= $row->voice_rate;
				   	 $rate_mult 	    = $row->rate_mult;
				   	 $grace_period		= $row->grace_period;
				   	 $minimal_time		= $row->minimal_time;
				   	 $resolution		= $row->resolution;
				   	 $is_disable		= $row->is_disable;
				   	 $strRate .=$k.",".$prefix.",".$description.",".$voice_rate.",".$rate_mult.",".$grace_period.",".$minimal_time.",".$resolution.",".$is_disable."\n";
                     $k++;
				   }
				   header("Content-type: application/vnd.ms-excel");
  				   header("Content-disposition: csv; filename=export_rate.csv");
  				   print $strRate;
  				   exit;				   
                }

	
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	
	


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Import Form of Rate Chart
 * @copyright 2011
 */


	function importRateForm($idRate)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{

				$data['id_rate']		= $idRate;
				$data['titleMessage'] = TITLE031;
				$this->load->view('rate/import_form',$data);

			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}




/**
 * @Show Import Form of Rate Chart
*/

	function importRate()
	{
		if($this->clogin->is_logged_in())
		{
			set_time_limit(36000);
			$userID = $this->session->userdata('userID');
			$rateCURD = $this->session->userdata('rateCURD');
			if($rateCURD != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $id_rate = $this->input->post('id_rate');
                $config['upload_path'] = './rate/';
		        $config['allowed_types'] = 'csv';
				$config['max_size']	= '10000000';
				$config['max_width']  = '1024';
				$config['max_height']  = '768';
				$this->load->library('upload', $config);
				if ( ! $this->upload->do_upload())
				{
					$error = array('error' => $this->upload->display_errors());
					redirect("rate/rateChartList/".$id_rate."/-1", "Location");
				}
				else
				{
					$data = array('upload_data' => $this->upload->data());
					$fileName = $data['upload_data']['full_path'];
					$row = 0;
					if (($handle = fopen($fileName, "r")) !== FALSE)
					 {
					   while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
					   {
					   	  $num = count($data);
					   	  $row++;
					   	  if($num >= 8)
					   	  {
							if($row !=1)
							{
								$dataRate['id_rate']		= $id_rate;
								$prefix		= $data[1];
								$dataRate['prefix']		= $prefix;
								$dataRate['description']		= $data[2];
								$dataRate['voice_rate']		= $data[3];
								$dataRate['rate_mult']		= $data[4];
								$dataRate['grace_period']		= $data[5];
								$dataRate['minimal_time']		= $data[6];
								$dataRate['resolution']		= $data[7];
								$dataRate['is_disable']		= $data[8];
								$data['creationdate']		= date('Y-m-d H:i:s');
								$dataRate['user_id']		= $userID;
								$dataRate['usertype']		= ADMIN_TYPE;
								$dataRate['ipaddress']		= $this->rateModel->getRealIpAddr();
								//echo "<br>";

								
								$this->rateModel->checkRatePrefix($id_rate,$prefix);
								$sql = $this->db->insert_string('ratechart', $dataRate);
								$query = $this->db->query($sql);
								$idInsert = $this->db->insert_id();
								
								
							}	
						  }
					   }
					   	
					   	redirect("rate/rateChartList/".$id_rate."/2", "Location");
					 }
					 else
					 {
					 	//echo "I am here";
						 redirect("rate/rateChartList/".$id_rate."/-1", "Location");					 	
					 }
						
				}

 
			}
		}
		else
		{
			redirect("login/index", "Location");
		}
	}




/**
 ***********************************************************************
 * @Start Feature Tariff Plan ******************************************
 ***********************************************************************
*/



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Feature Tariff Plan List
 * @copyright 01 Jun 2014
 */



	function featureTariffPlan($errorMessage=0,$prefix='NULL')
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$accessGroup = $accessLevel = $this->session->userdata('accessLevel');
			$accessPrivilege = $accessGroup['tariff']['Action'];
			if($accessPrivilege == NO_ACCESS)
			redirect("admin/cpanel/accessDenied", "Location");
			
			$startTimeStr = mktime(0,0,0,date("m"),date("d")-15,date("Y"));
  			$starttime = date("Y-m-d", $startTimeStr)." 00:00";
			$endTimeStr = mktime(0,0,0,date("m"),date("d") + 15,date("Y"));
  			$stoptime = date("Y-m-d", $endTimeStr)." 23:59";
  			$prefix = "NULL";
  			$idRate = 'NULL';
  			$codeType = 1;
  			$startoffset = 0;
  			$limit = LIMIT_PERPAGE;
  			
  			
			$data['rateList'] = $this->generallib->getTariffList($idRate = 'NULL');
			$data['starttime'] = $starttime;
			$data['stoptime'] = $stoptime;
			$data['prefix'] = $prefix;
			$data['idRate'] = $idRate;
			$data['codeType'] = $codeType;
			$data['startoffset'] = $startoffset;
			$data['limit'] = $limit;
			
			$data['total'] = $this->rateModel->getNumRatePlan($idRate,$prefix,$codeType,$starttime,$stoptime);
			$data['planList'] = $this->rateModel->ratePlanList($startoffset,$limit,$idRate,$prefix,$codeType,$starttime,$stoptime);

			$data['titleMessage'] = TITLE017;
			
			if($errorMessage == 1)
			$data['titleErrorMessage'] = FROMMESSAGE106;
			elseif($errorMessage == 2)
			$data['titleErrorMessage'] = FROMMESSAGE108;
			elseif($errorMessage == 3)
			$data['titleErrorMessage'] = FROMMESSAGE109;
			elseif($errorMessage == 4)
			$data['titleErrorMessage'] = FROMMESSAGE110;
			else
			$data['titleErrorMessage'] = "";
			$this->load->view('rate/feature_tariffplan_list',$data);
		}
		else
		{
			redirect("login/index", "Location");
		}
	}




/**
 ***********************************************************************
 * @Start Tariff Analysis  *********************************************
 ***********************************************************************
*/
				

/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Feature Tariff Analysis
 * @copyright 01 Jun 2014
 */


	function tariffAnalysis($errorMessage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$accessGroup = $accessLevel = $this->session->userdata('accessLevel');
			$accessPrivilege = $accessGroup['tariff']['Action'];
			if($accessPrivilege == NO_ACCESS)
			redirect("admin/cpanel/accessDenied", "Location");
			$data['rateList'] = $this->generallib->getTariffList($idRate = 'NULL');
			$data['titleMessage'] = TITLE017;			
			$data['titleErrorMessage'] = "";
			$this->load->view('rate/tariff_analysis',$data);
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	
	
	
	
		
			

}
?>