<?php
class reseller extends Controller
{

	function reseller()
	{

		parent::Controller();
	}


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


/**
*User Name Validation
*By Md. Golam Robbany
*Date : 2010-08-07
*Email : mgrnahid@gmail.com
*/

	function validateUser()
	{

	/* RECEIVE VALUE */
	$validateValue=$_POST['validateValue'];
	$validateId=$_POST['validateId'];
	$validateError=$_POST['validateError'];
	/* RETURN VALUE */
	$arrayToJs = array();
	$arrayToJs[0] = $validateId;
	$arrayToJs[1] = $validateError;
	if($this->resellerModel->checkResellerLogin($validateValue) =="0"){		// validate??
	$arrayToJs[2] = "true";			// RETURN TRUE
	echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}';			// RETURN ARRAY WITH success
	}else{
	for($x=0;$x<1000000;$x++){
		if($x == 990000){
			$arrayToJs[2] = "false";
			echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}';		// RETURN ARRAY WITH ERROR
			}
		}

	}

}


/**
 ***********************************************************************
 * @Start Reseller IV Section *****************************************
 ***********************************************************************
*/

/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Reseller IV List
 * @copyright 2011
 */

	function resellerLevel4List($errorMessage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			redirect("admin/cpanel/accessDenied", "Location");
			
			$data['login'] = "NULL";
			$data['password'] = "NULL";
			$data['rateList'] = $this->generallib->getTariffList($id_rate='NULL');
			$data['full_name'] = "NULL";
			$data['startoffset'] = "0";
			$data['limit'] = LIMIT_PERPAGE;
			$data['id_rate'] = "NULL";
			$data['type'] = -1;
			$data['typeValue'] = 'NULL';
			$data['callPhone'] = "NULL";
			$data['total'] = $this->resellerModel->getTotalnumResellerLeve4($login='NULL',$password='NULL',$full_name='NULL',$id_rate='NULL',$callPhone = 'NULL',$type = '-1',$typeValue = 0);
			$data['resellerList'] = $this->resellerModel->resellerLevel4List($startoffset = 0,$limit = LIMIT_PERPAGE,$login='NULL',$password='NULL',$full_name='NULL',$id_rate='NULL',$callPhone = 'NULL',$type = '-1',$typeValue = 0);
			$data['titleMessage'] = TITLE007;
			if($errorMessage ==-1)
			$data['titleErrorMessage'] = FROMMESSAGE004;
			elseif($errorMessage ==1)
			$data['titleErrorMessage'] = FROMMESSAGE005;
			elseif($errorMessage ==22)
			$data['titleErrorMessage'] = FROMMESSAGE022;
			elseif($errorMessage ==24)
			$data['titleErrorMessage'] = FROMMESSAGE024;
			else
			$data['titleErrorMessage'] = "";
			$this->load->view('reseller/reseller4_list',$data);
		}
		else
		{
			redirect("logout", "Location");
		}
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Reseller IV List Pagination
 * @copyright 2011
 */

	function resellerLevel4ListPagination($startoffset,$limit,$id_rate,$login,$password,$full_name,$typeValue,$callPhone,$type,$myRandom=0)
	{
		if($this->clogin->is_logged_in())
		{

			$data['login'] = $login;
			$data['password'] = $password;
			$data['full_name'] = $full_name;
			$data['startoffset'] = $startoffset;
			$data['limit'] = $limit;
			$data['id_rate'] = $id_rate;
			$data['typeValue'] = $typeValue;
			$data['type'] = $type;
			$data['callPhone'] = $callPhone;
			$data['total'] = $this->resellerModel->getTotalnumResellerLeve4($login,$password,$full_name,$id_rate,$callPhone,$type,$typeValue);
			$data['resellerList'] = $this->resellerModel->resellerLevel4List($startoffset,$limit,$login,$password,$full_name,$id_rate,$callPhone,$type,$typeValue);
			$data['titleMessage'] = TITLE007;
			$data['titleErrorMessage'] = "";
			$this->load->view('reseller/reseller4_list_pagi',$data);
		}
		else
		{
			redirect("logout", "Location");
		}
	}



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

	function addFormReseller4($errorMesssage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{

				$data['id']		= '';
				$data['login']		= '';
				$data['password']		= '';
				$data['balance']		= INIT_BALANCE;
				$data['rateList']		= $this->generallib->getTariffList($id_rate='NULL');
				$data['limit_user']		= INIT_USER_LIMIT;
				$data['limit_rate']		= INIT_RATE_LIMIT;
				$data['limit_balance']		= INIT_BALANCE_LIMIT;
				$data['limit_fnf']		= INIT_FNF_LIMIT;
				$data['sipuser']		= '1';
				$data['aniuser']		= '1';
				$data['type']		= '';
				$data['commission'] = '0.00';
				$data['full_name']		= '';
				$data['email']		= '';
				$data['cell']		= '';
				$data['phone']		= '';
				$data['city']		= '';
				$data['countryList']		= $this->generallib->getCountryList($country='NULL');
				$data['state']		= '';
				$data['address']		= '';
				$data['status']		= '1';
				$data['action']		= 'Add';
				$data['titleAccountMessage'] = TITLE008;
				$data['titlePersonalMessage'] = TITLE009;

				if($errorMesssage==0)
				$data['titleErrorMessage'] = FROMMESSAGE001;
				elseif($errorMesssage==-1)
				$data['titleErrorMessage'] = FROMMESSAGE001;
				elseif($errorMesssage==-2)
				$data['titleErrorMessage'] = FROMMESSAGE002;
				elseif($errorMesssage==-3)
				$data['titleErrorMessage'] = FROMMESSAGE003;
				else
				$data['titleErrorMessage'] = "";



				$this->load->view('reseller/add_form_reseller4',$data);

			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Add/Edit Reseller IV
 * @copyright 2011
 */
 
	function addEditReseller4()
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $id = $this->input->post('id');
               $action = $this->input->post('action');
               $login = $this->input->post('login');
               $password = $this->input->post('password');
               $id_rate = $this->input->post('id_rate');
               $full_name = $this->input->post('full_name');

               $checkResellerLoginName = $this->resellerModel->checkResellerLogin($login);

               $addDscripttion = "Add Reseller Level IV,  Login: ".$login;
			   $editDescripttion = "Edit  Reseller Level IV,  Login: ".$login;

			   if($action=="Add")
			   {

                  if(empty($login) OR empty($password) OR empty($id_rate) OR empty($full_name))
                  redirect("reseller/addFormReseller4/-1", "Location");

	              if($login==$password)
	              redirect("reseller/addFormReseller4/-3", "Location");	              

	              if($checkResellerLoginName==1)
	              redirect("reseller/addFormReseller4/-2", "Location");	              

			      $this->resellerModel->addReseller4($userID);
			      $this->generallib->addUserLog($userID,'-1','Insert',$addDscripttion);
			      redirect("reseller/resellerLevel4List/22", "Location");
			   }
			   else
			   {
                  if(empty($password) OR empty($id_rate) OR empty($full_name))
                  redirect("reseller/editFormReseller4/".$id."/-1", "Location");

	              if($login==$password)
	              redirect("reseller/editFormReseller4/".$id."/-3", "Location");	              

			      $this->resellerModel->editReseller4($userID);
			      $this->generallib->addUserLog($userID,'-1','Edit',$editDescripttion);
			      redirect("reseller/resellerLevel4List/24", "Location");
			   }

			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}




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

	function editFormReseller4($id=0,$errorMesssage = 0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $editInfo = $this->resellerModel->reseller4EditInfo($id);
                if($editInfo==0)
                {
                   redirect("reseller/resellerLevel4List", "Location");
                }
                else
                {
                   foreach($editInfo as $row)
                   {
						$data['id']		 = $row->id;
						$data['login']		 = $row->login;
						$data['password']		 = $row->password;
						$data['balance']		 = $row->balance;
						$data['rateList']		 = $this->generallib->getTariffList($row->id_rate);
						$data['limit_user']		 = $row->limit_user;
						$data['limit_rate']		 = $row->limit_rate;
						$data['limit_balance']		 = $row->limit_balance;
						$data['limit_fnf']		 = $row->limit_fnf;
						$data['commission']		 = $row->commission;
						$data['type']		 = $row->type;
						$data['sipuser']		 = $row->sipuser;
						$data['aniuser']		 = $row->aniuser;
						$data['full_name']		 = $row->full_name;
						$data['email']		 = $row->email;
						$data['cell']		 = $row->cell;
						$data['phone']		 = $row->phone;
						$data['city']		 = $row->city;
						$data['countryList']		= $this->generallib->getCountryList($row->country);
						$data['state']		 = $row->state;
						$data['address']		 = $row->address;
						$data['status']		 = $row->status;
                   }
                   $data['action']		= 'edit';
   				   if($errorMesssage==-3)
				   $data['titleErrorMessage'] = FROMMESSAGE003;
				   elseif($errorMesssage==-1)
				   $data['titleErrorMessage'] = FROMMESSAGE001;				   
				   elseif($errorMesssage==23)
				   $data['titleErrorMessage'] = FROMMESSAGE023;				   
				   else
                   $data['titleErrorMessage'] = FROMMESSAGE001;
                   
                   
                   $data['titleAccountMessage'] = TITLE008;
				   $data['titlePersonalMessage'] = TITLE009;
                   $this->load->view('reseller/edit_form_reseller4',$data);
                }
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Reseller IV Payment Form
 * @copyright 2011
 */
 


	function showPaymentFormLevel4($idReseller,$lastBalance=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $data['paymentHistory'] = $this->resellerModel->resellerPaymentHistory($idReseller,4);
                $data['id'] = "";
                $data['id_reseller'] = $idReseller;
                $data['lastBalance'] = $lastBalance;
                $data['level'] = 4;
                $data['amount'] = INIT_ADD_BALANCE;
                $data['type'] = "1";
                $data['user_id'] = $userID;
                $data['description'] = "";
                $data['usertype'] = ADMIN_TYPE;
                $data['creationdate'] = date('Y-m-d H:i:s');
                $this->load->view('reseller/add_payment_form_level4',$data);
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Reseller IV Payment
 * @copyright 2011
 */
 
	function addReseller4Payment()
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $idReseller = $this->input->post('id_reseller');
               $addDscripttion = "Add Reseller Payment Level IV,  idReseller: ".$idReseller;
			   $this->resellerModel->addResellerPayment($userID,4);
			   $this->generallib->addUserLog($userID,'-1','Insert',$addDscripttion);
			   redirect("reseller/editFormReseller4/".$idReseller.'/23', "Location");
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}





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

	function deleteReseller4($idReseller)
	{
		set_time_limit(36000);
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $checkChildReseller = $this->resellerModel->checkChildReseller4($idReseller);
                if($checkChildReseller==1)
                redirect("reseller/resellerLevel4List/-1", "Location");
                else
                {
                    $deleteInfo = $this->generallib->getDeleteResellerInformation(4,$idReseller);
					$this->resellerModel->deleteReseller4($idReseller);
					$this->generallib->addUserLog($userID,'-1','Delete',$deleteInfo);
                    redirect("reseller/resellerLevel4List/1", "Location");

                }
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}

	


/**
 ***********************************************************************
 * @End Reseller IV Section *****************************************
 ***********************************************************************
*/



/**
 ***********************************************************************
 * @Start Reseller III Section *****************************************
 ***********************************************************************
*/


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Reseller III List
 * @copyright 2011
 */
 
	function resellerLevel3List($errorMessage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			redirect("admin/cpanel/accessDenied", "Location");
			
			$data['login'] = "NULL";
			$data['password'] = "NULL";
			$data['rateList'] = $this->generallib->getTariffList($id_rate='NULL');
			$data['reseller4List'] = $this->generallib->getResellerLeve4LoginList($idReseller='NULL');
			$data['full_name'] = "NULL";
			$data['startoffset'] = "0";
			$data['limit'] = LIMIT_PERPAGE;
			$data['id_rate'] = "NULL";
			$data['idReseller'] = "NULL";
			$data['type'] = -1;
			$data['typeValue'] = 'NULL';

			$data['total'] = $this->resellerModel->getTotalnumResellerLeve3($login='NULL',$password='NULL',$full_name='NULL',$id_rate='NULL',$idReseller='NULL',$type = -1,$typeValue = 'NULL');
			$data['resellerList'] = $this->resellerModel->resellerLevel3List($startoffset = 0,$limit = LIMIT_PERPAGE,$login='NULL',$password='NULL',$full_name='NULL',$id_rate='NULL',$idReseller='NULL',$type = -1,$typeValue = 'NULL');
			$data['titleMessage'] = TITLE007;
			if($errorMessage ==-1)
			$data['titleErrorMessage'] = FROMMESSAGE004;
			elseif($errorMessage ==1)
			$data['titleErrorMessage'] = FROMMESSAGE005;
			elseif($errorMessage ==26)
			$data['titleErrorMessage'] = FROMMESSAGE026;
			elseif($errorMessage ==27)
			$data['titleErrorMessage'] = FROMMESSAGE027;
			else
			$data['titleErrorMessage'] = "";
			$this->load->view('reseller/reseller3_list',$data);
		}
		else
		{
			redirect("logout", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Reseller III List Pagination
 * @copyright 2011
 */
 
	function resellerLevel3ListPagination($startoffset,$limit,$id_rate,$login,$password,$full_name,$idReseller,$typeValue,$type,$myRandom=0)
	{
		if($this->clogin->is_logged_in())
		{

			$data['login'] = $login;
			$data['password'] = $password;
			$data['full_name'] = $full_name;
			$data['startoffset'] = $startoffset;
			$data['limit'] = $limit;
			$data['id_rate'] = $id_rate;
			$data['idReseller'] = $idReseller;
			$data['type'] = $type;
			$data['typeValue'] = $typeValue;

			$data['total'] = $this->resellerModel->getTotalnumResellerLeve3($login,$password,$full_name,$id_rate,$idReseller,$type,$typeValue);
			$data['resellerList'] = $this->resellerModel->resellerLevel3List($startoffset,$limit,$login,$password,$full_name,$id_rate,$idReseller,$type,$typeValue);
			$data['titleMessage'] = TITLE007;
			$data['titleErrorMessage'] = "";
			$this->load->view('reseller/reseller3_list_pagi',$data);
		}
		else
		{
			redirect("logout", "Location");
		}
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Add Form of Reseller III
 * @copyright 2011
 */
 

	function addFormReseller3($errorMesssage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{

				$data['id']		= '';
				$data['login']		= '';
				$data['password']		= '';
				$data['balance']		= INIT_BALANCE;
				$data['rateList']		= $this->generallib->getTariffList($id_rate='NULL');
				$data['reseller4List'] = $this->generallib->getResellerLeve4LoginList($id_reseller='NULL');
				$data['limit_user']		= INIT_USER_LIMIT;
				$data['limit_rate']		= INIT_RATE_LIMIT;
				$data['limit_balance']		= INIT_BALANCE_LIMIT;
				$data['limit_fnf']		= INIT_FNF_LIMIT;
				$data['commission']		= '0.00';
				$data['sipuser']		= '1';
				$data['aniuser']		= '1';
				$data['type']		= '';
				$data['full_name']		= '';
				$data['email']		= '';
				$data['cell']		= '';
				$data['phone']		= '';
				$data['city']		= '';
				$data['countryList']		= $this->generallib->getCountryList($country='NULL');
				$data['state']		= '';
				$data['address']		= '';
				$data['status']		= '1';
				$data['action']		= 'Add';
				$data['titleAccountMessage'] = TITLE008;
				$data['titlePersonalMessage'] = TITLE009;

				if($errorMesssage==0)
				$data['titleErrorMessage'] = FROMMESSAGE001;
				elseif($errorMesssage==-1)
				$data['titleErrorMessage'] = FROMMESSAGE001;
				elseif($errorMesssage==-2)
				$data['titleErrorMessage'] = FROMMESSAGE002;
				elseif($errorMesssage==-3)
				$data['titleErrorMessage'] = FROMMESSAGE003;
				else
				$data['titleErrorMessage'] = "";



				$this->load->view('reseller/add_form_reseller3',$data);

			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}



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

	function addEditReseller3()
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $id = $this->input->post('id');
               $action = $this->input->post('action');
               $login = $this->input->post('login');
               $password = $this->input->post('password');
               $id_rate = $this->input->post('id_rate');
               $full_name = $this->input->post('full_name');
               $id_reseller = $this->input->post('id_reseller');
               $balance = $this->input->post('balance');

               $checkResellerLoginName = $this->resellerModel->checkResellerLogin($login);


               $addDscripttion = "Add Reseller Level III,  Login: ".$login;
			   $editDescripttion = "Edit  Reseller Level III,  Login: ".$login;

			   if($action=="Add")
			   {

                  if(empty($login) OR empty($password) OR empty($id_rate) OR empty($full_name))
                  redirect("reseller/addFormReseller3/-1", "Location");

	              if($login==$password)
	              redirect("reseller/addFormReseller3/-3", "Location");	              

	              if($checkResellerLoginName==1)
	              redirect("reseller/addFormReseller3/-2", "Location");

			      $this->resellerModel->addReseller3($userID);
			      $this->generallib->addUserLog($userID,'-1','Insert',$addDscripttion);
			      redirect("reseller/resellerLevel3List/26", "Location");
			   }
			   else
			   {
                  if(empty($password) OR empty($id_rate) OR empty($full_name))
                  redirect("reseller/editFormReseller3/".$id."/-1", "Location");

	              if($login==$password)
	              redirect("reseller/editFormReseller3/".$id."/-3", "Location");	              

			      $this->resellerModel->editReseller3($userID);
			      $this->generallib->addUserLog($userID,'-1','Edit',$editDescripttion);
			      redirect("reseller/resellerLevel3List/27", "Location");
			   }

			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Reseller III Edit Form
 * @copyright 2011
 */
 
	function editFormReseller3($id=0,$errorMesssage = 0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $editInfo = $this->resellerModel->reseller3EditInfo($id);
                if($editInfo==0)
                {
                   redirect("reseller/resellerLevel3List", "Location");
                }
                else
                {
                   foreach($editInfo as $row)
                   {
						$data['id']		 = $row->id;
						$data['login']		 = $row->login;
						$data['password']		 = $row->password;
						$data['balance']		 = $row->balance;
						$data['rateList']		 = $this->generallib->getTariffList($row->id_rate);
						$data['reseller4List'] = $this->generallib->getResellerLeve4LoginList($row->id_reseller);
						$data['limit_user']		 = $row->limit_user;
						$data['limit_rate']		 = $row->limit_rate;
						$data['limit_balance']		 = $row->limit_balance;
						$data['limit_fnf']		 = $row->limit_fnf;
						$data['commission']		 = $row->commission;
						$data['type']		 = $row->type;
						$data['sipuser']		 = $row->sipuser;
						$data['aniuser']		 = $row->aniuser;
						$data['full_name']		 = $row->full_name;
						$data['email']		 = $row->email;
						$data['cell']		 = $row->cell;
						$data['phone']		 = $row->phone;
						$data['city']		 = $row->city;
						$data['countryList']		= $this->generallib->getCountryList($row->country);
						$data['state']		 = $row->state;
						$data['address']		 = $row->address;
						$data['status']		 = $row->status;
                   }
                   $data['action']		= 'edit';
   				   if($errorMesssage==-3)
				   $data['titleErrorMessage'] = FROMMESSAGE003;
				   elseif($errorMesssage==-1)
				   $data['titleErrorMessage'] = FROMMESSAGE001;				   
				   elseif($errorMesssage==23)
				   $data['titleErrorMessage'] = FROMMESSAGE023;				   
				   else
                   $data['titleErrorMessage'] = FROMMESSAGE001;
                   $data['titleAccountMessage'] = TITLE008;
				   $data['titlePersonalMessage'] = TITLE009;
                   $this->load->view('reseller/edit_form_reseller3',$data);
                }
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Reseller III Payment Form
 * @copyright 2011
 */
 
	function showPaymentFormLevel3($idReseller,$lastBalance = 0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $data['paymentHistory'] = $this->resellerModel->resellerPaymentHistory($idReseller,3);
                $data['id'] = "";
                $data['id_reseller'] = $idReseller;
                $data['level'] = 3;
                $data['amount'] = INIT_ADD_BALANCE;
                $data['lastBalance'] = $lastBalance;
                $data['type'] = "1";
                $data['user_id'] = $userID;
                $data['description'] = "";
                $data['usertype'] = ADMIN_TYPE;
                $data['creationdate'] = date('Y-m-d H:i:s');
                $this->load->view('reseller/add_payment_form_level3',$data);
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Add Reseller III Payment
 * @copyright 2011
 */
 

	function addReseller3Payment()
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $idReseller = $this->input->post('id_reseller');
               $addDscripttion = "Add Reseller Payment Level III,  idReseller: ".$idReseller;
			   $this->resellerModel->addResellerPayment($userID,3);
			   $this->generallib->addUserLog($userID,'-1','Insert',$addDscripttion);
			   redirect("reseller/editFormReseller3/".$idReseller.'/23', "Location");
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Delete Reseller III
 * @copyright 2011
 */
 
	function deleteReseller3($idReseller)
	{
		set_time_limit(36000);
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $checkChildReseller = $this->resellerModel->checkChildReseller3($idReseller);
                if($checkChildReseller==1)
                redirect("reseller/resellerLevel3List/-1", "Location");
                else
                {
                    $deleteInfo = $this->generallib->getDeleteResellerInformation(3,$idReseller);
					$this->resellerModel->deleteReseller3($idReseller);
					$this->generallib->addUserLog($userID,'-1','Delete',$deleteInfo);
                    redirect("reseller/resellerLevel3List/1", "Location");

                }
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}



/**
 ***********************************************************************
 * @Start Reseller II Section ******************************************
 ***********************************************************************
*/



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Reseller II List
 * @copyright 2011
 */
 
	function resellerLevel2List($errorMessage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			redirect("admin/cpanel/accessDenied", "Location");
			
			$data['login'] = "NULL";
			$data['password'] = "NULL";
			$data['rateList'] = $this->generallib->getTariffList($id_rate='NULL');
			$data['full_name'] = "NULL";
			$data['startoffset'] = "0";
			$data['limit'] = LIMIT_PERPAGE;
			$data['id_rate'] = "NULL";
			$data['id_reseller'] = "NULL";
			$data['type'] = -1;
			$data['typeValue'] = 'NULL';

			$data['resellerLevel3List'] = $this->generallib->getResellerLeve3List($id_reseller='NULL');
			$data['total'] = $this->resellerModel->getTotalnumResellerLeve2($login='NULL',$password='NULL',$full_name='NULL',$id_rate='NULL',$id_reseller='NULL',$type = -1, $typeValue = 'NULL');
			$data['resellerList'] = $this->resellerModel->resellerLevel2List($startoffset = 0,$limit = LIMIT_PERPAGE,$login='NULL',$password='NULL',$full_name='NULL',$id_rate='NULL',$id_reseller='NULL',$type = -1, $typeValue = 'NULL');
			$data['titleMessage'] = TITLE014;
			if($errorMessage ==-1)
			$data['titleErrorMessage'] = FROMMESSAGE004;
			elseif($errorMessage ==1)
			$data['titleErrorMessage'] = FROMMESSAGE005;
			elseif($errorMessage ==28)
			$data['titleErrorMessage'] = FROMMESSAGE028;
			elseif($errorMessage ==29)
			$data['titleErrorMessage'] = FROMMESSAGE029;
			else
			$data['titleErrorMessage'] = "";
			$this->load->view('reseller/reseller2_list',$data);
		}
		else
		{
			redirect("logout", "Location");
		}
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Reseller II List Pagination
 * @copyright 2011
 */

	function resellerLevel2ListPagination($startoffset,$limit,$id_rate,$login,$password,$full_name,$id_reseller,$typeValue,$type,$myRandom=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			$data['login'] = $login;
			$data['password'] = $password;
			$data['full_name'] = $full_name;
			$data['startoffset'] = $startoffset;
			$data['limit'] = $limit;
			$data['id_rate'] = $id_rate;
			$data['id_reseller'] = $id_reseller;
			$data['type'] = $type;
			$data['typeValue'] = $typeValue;

			$data['total'] = $this->resellerModel->getTotalnumResellerLeve2($login,$password,$full_name,$id_rate,$id_reseller,$type,$typeValue);
			$data['resellerList'] = $this->resellerModel->resellerLevel2List($startoffset,$limit,$login,$password,$full_name,$id_rate,$id_reseller,$type,$typeValue);
			$data['titleMessage'] = TITLE014;
			$data['titleErrorMessage'] = "";
			$this->load->view('reseller/reseller2_list_pagi',$data);
		}
		else
		{
			redirect("logout", "Location");
		}
	}
	
	
/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Add Form of  Reseller II
 * @copyright 2011
 */
 
	function addFormReseller2($errorMesssage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{

				$data['id']		= '';
				$data['login']		= '';
				$data['password']		= '';
				$data['resellerLevel3List'] = $this->generallib->getResellerLeve3List($id_reseller='NULL');
				$data['balance']		= INIT_BALANCE;
				$data['rateList']		= $this->generallib->getTariffList($id_rate='NULL');
				$data['limit_user']		= INIT_USER_LIMIT;
				$data['limit_rate']		= INIT_RATE_LIMIT;
				$data['limit_balance']		= INIT_BALANCE_LIMIT;
				$data['limit_fnf']		= INIT_FNF_LIMIT;
				$data['commission']		= '0.00';
				$data['type']		= '';
				$data['sipuser']		= '1';
				$data['aniuser']		= '1';
				$data['full_name']		= '';
				$data['email']		= '';
				$data['cell']		= '';
				$data['phone']		= '';
				$data['city']		= '';
				$data['countryList']		= $this->generallib->getCountryList($country='NULL');
				$data['state']		= '';
				$data['address']		= '';
				$data['status']		= '1';
				$data['action']		= 'Add';
				$data['titleAccountMessage'] = TITLE008;
				$data['titlePersonalMessage'] = TITLE009;

				if($errorMesssage==0)
				$data['titleErrorMessage'] = FROMMESSAGE001;
				elseif($errorMesssage==-1)
				$data['titleErrorMessage'] = FROMMESSAGE001;
				elseif($errorMesssage==-2)
				$data['titleErrorMessage'] = FROMMESSAGE002;
				elseif($errorMesssage==-3)
			    $data['titleErrorMessage'] = FROMMESSAGE003;
				else
				$data['titleErrorMessage'] = FROMMESSAGE001;



				$this->load->view('reseller/add_form_reseller2',$data);

			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Add/Edit Reseller II
 * @copyright 2011
 */
 
	function addEditReseller2()
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $id = $this->input->post('id');
               $action = $this->input->post('action');
               $login = $this->input->post('login');
               $password = $this->input->post('password');
               $id_rate = $this->input->post('id_rate');
               $balance = $this->input->post('balance');


               $checkResellerLoginName = $this->resellerModel->checkResellerLogin($login);


               $addDscripttion = "Add Reseller Level II,  Login: ".$login;
			   $editDescripttion = "Edit  Reseller Level II,  Login: ".$login;

			   if($action=="Add")
			   {
	              if(empty($login) OR empty($password) OR empty($id_rate) OR empty($balance))
    	          redirect("reseller/addFormReseller2/-1", "Location");
    	          if($login==$password)
                  redirect("reseller/addFormReseller2/-3", "Location");
	              if($checkResellerLoginName==1)
	              redirect("reseller/addFormReseller2/-2", "Location");

			      $this->resellerModel->addReseller2($userID);
			      $this->generallib->addUserLog($userID,'-1','Insert',$addDscripttion);
			      redirect("reseller/resellerLevel2List/28", "Location");
			   }
			   else
			   {

	              if(empty($password) OR empty($id_rate))
    	          redirect("reseller/editFormReseller2/".$id."/-1", "Location");
    	          if($login==$password)
                  redirect("reseller/editFormReseller2/".$id."/-3", "Location");

			      $this->resellerModel->editReseller2($userID);
			      $this->generallib->addUserLog($userID,'-1','Edit',$editDescripttion);
			      redirect("reseller/resellerLevel2List/29", "Location");
			   }

			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}




/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Reseller II Edit Form
 * @copyright 2011
 */
 
	function editFormReseller2($id=0,$errorMesssage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $editInfo = $this->resellerModel->reseller2EditInfo($id);
                if($editInfo==0)
                {
                   redirect("reseller/resellerLevel2List", "Location");
                }
                else
                {
                   foreach($editInfo as $row)
                   {
						$data['id']		 = $row->id;
						$data['resellerLevel3List'] = $this->generallib->getResellerLeve3List($row->id_reseller);
						$data['login']		 = $row->login;
						$data['password']		 = $row->password;
						$data['balance']		 = $row->balance;
						$data['rateList']		 = $this->generallib->getTariffList($row->id_rate);
						$data['limit_user']		 = $row->limit_user;
						$data['limit_rate']		 = $row->limit_rate;
						$data['limit_balance']		 = $row->limit_balance;
						$data['limit_fnf']		 = $row->limit_fnf;
						$data['type']		 = $row->type;
						$data['sipuser']		 = $row->sipuser;
						$data['aniuser']		 = $row->aniuser;
						$data['full_name']		 = $row->full_name;
						$data['email']		 = $row->email;
						$data['cell']		 = $row->cell;
						$data['phone']		 = $row->phone;
						$data['city']		 = $row->city;
						$data['countryList']		= $this->generallib->getCountryList($row->country);
						$data['state']		 = $row->state;
						$data['address']		 = $row->address;
						$data['status']		 = $row->status;
                   }
                   $data['action']		= 'edit';
				   if($errorMesssage==0)
				   $data['titleErrorMessage'] = FROMMESSAGE001;
				   elseif($errorMesssage==-1)
				   $data['titleErrorMessage'] = FROMMESSAGE001;
				   elseif($errorMesssage==-3)
			       $data['titleErrorMessage'] = FROMMESSAGE003;
				   elseif($errorMesssage==23)
			       $data['titleErrorMessage'] = FROMMESSAGE023;
				   else
				   $data['titleErrorMessage'] = FROMMESSAGE001;
                   $data['titleAccountMessage'] = TITLE008;
				   $data['titlePersonalMessage'] = TITLE009;
                   $this->load->view('reseller/edit_form_reseller2',$data);
                }
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}
	


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Reseller II Payment Form
 * @copyright 2011
 */
 

	function showPaymentFormLevel2($idReseller,$lastBalance = 0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $data['paymentHistory'] = $this->resellerModel->resellerPaymentHistory($idReseller,2);
                $data['id'] = "";
                $data['id_reseller'] = $idReseller;
                $data['level'] = 2;
                $data['amount'] = INIT_ADD_BALANCE;
                $data['lastBalance'] = $lastBalance;
                $data['type'] = "1";
                $data['user_id'] = $userID;
                $data['description'] = "";
                $data['usertype'] = ADMIN_TYPE;
                $data['creationdate'] = date('Y-m-d H:i:s');
                $this->load->view('reseller/add_payment_form_level2',$data);
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}
	


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Add Reseller II Payment
 * @copyright 2011
 */
 
	function addReseller2Payment()
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $idReseller = $this->input->post('id_reseller');
               $addDscripttion = "Add Reseller Payment Level II,  idReseller: ".$idReseller;
			   $this->resellerModel->addResellerPayment($userID,2);
			   $this->generallib->addUserLog($userID,'-1','Insert',$addDscripttion);
			   redirect("reseller/editFormReseller2/".$idReseller.'/23', "Location");
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Delete Reseller II 
 * @copyright 2011
 */
 
	function deleteReseller2($idReseller)
	{
		set_time_limit(36000);
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $checkChildReseller = $this->resellerModel->checkChildReseller2($idReseller);
                if($checkChildReseller==1)
                redirect("reseller/resellerLevel2List/-1", "Location");
                else
                {
                    $deleteInfo = $this->generallib->getDeleteResellerInformation(2,$idReseller);
					$this->resellerModel->deleteReseller2($idReseller);
					$this->generallib->addUserLog($userID,'-1','Delete',$deleteInfo);
                    redirect("reseller/resellerLevel2List/1", "Location");

                }
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}


/**
 ***********************************************************************
 * @Start Reseller I Section *******************************************
 ***********************************************************************
*/


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Reseller I List
 * @copyright 2011
 */
 
	function resellerLevel1List($errorMessage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			redirect("admin/cpanel/accessDenied", "Location");
			
			$data['login'] = "NULL";
			$data['password'] = "NULL";
			$data['rateList'] = $this->generallib->getTariffList($id_rate='NULL');
			$data['full_name'] = "NULL";
			$data['startoffset'] = "0";
			$data['limit'] = LIMIT_PERPAGE;
			$data['id_rate'] = "NULL";
			$data['id_reseller'] = "NULL";
			$data['type'] = -1;
			$data['typeValue'] = 'NULL';

			$data['resellerLevel2List'] = $this->generallib->getResellerLeve2List($id_reseller='NULL');
			$data['total'] = $this->resellerModel->getTotalnumResellerLeve1($login='NULL',$password='NULL',$full_name='NULL',$id_rate='NULL',$id_reseller='NULL',$type=-1,$typeValue = 'NULL');
			$data['resellerList'] = $this->resellerModel->resellerLevel1List($startoffset = 0,$limit = LIMIT_PERPAGE,$login='NULL',$password='NULL',$full_name='NULL',$id_rate='NULL',$id_reseller='NULL',$type=-1,$typeValue = 'NULL');
			$data['titleMessage'] = TITLE017;
			if($errorMessage ==-1)
			$data['titleErrorMessage'] = FROMMESSAGE004;
			elseif($errorMessage ==1)
			$data['titleErrorMessage'] = FROMMESSAGE005;
			elseif($errorMessage ==30)
			$data['titleErrorMessage'] = FROMMESSAGE030;
			elseif($errorMessage ==31)
			$data['titleErrorMessage'] = FROMMESSAGE031;


			else
			$data['titleErrorMessage'] = "";
			$this->load->view('reseller/reseller1_list',$data);
		}
		else
		{
			redirect("logout", "Location");
		}
	}
	

/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Reseller I List Pagination
 * @copyright 2011
 */
 
	function resellerLevel1ListPagination($startoffset,$limit,$id_rate,$login,$password,$full_name,$id_reseller,$typeValue,$type,$myRandom=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			$data['login'] = $login;
			$data['password'] = $password;
			$data['full_name'] = $full_name;
			$data['startoffset'] = $startoffset;
			$data['limit'] = $limit;
			$data['id_rate'] = $id_rate;
			$data['id_reseller'] = $id_reseller;
			$data['type'] = $type;
			$data['typeValue'] = $typeValue;

			$data['total'] = $this->resellerModel->getTotalnumResellerLeve1($login,$password,$full_name,$id_rate,$id_reseller,$type,$typeValue);
			$data['resellerList'] = $this->resellerModel->resellerLevel1List($startoffset,$limit,$login,$password,$full_name,$id_rate,$id_reseller,$type,$typeValue);
			$data['titleMessage'] = TITLE014;
			$data['titleErrorMessage'] = "";
			$this->load->view('reseller/reseller1_list_pagi',$data);
		}
		else
		{
			redirect("logout", "Location");
		}
	}


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

				$data['id']		= '';
				$data['login']		= '';
				$data['password']		= '';
				$data['resellerLevel2List'] = $this->generallib->getResellerLeve2List($id_reseller='NULL');
				$data['balance']		= INIT_BALANCE;
				$data['rateList']		= $this->generallib->getTariffList($id_rate='NULL');
				$data['limit_user']		= INIT_USER_LIMIT;
				$data['limit_rate']		= INIT_RATE_LIMIT;
				$data['limit_balance']		= INIT_BALANCE_LIMIT;
				$data['limit_fnf']		= INIT_FNF_LIMIT;
				$data['commission']		= '0.00';
				$data['type']		= '';
				$data['sipuser']		= '1';
				$data['aniuser']		= '1';
				$data['full_name']		= '';
				$data['email']		= '';
				$data['cell']		= '';
				$data['phone']		= '';
				$data['city']		= '';
				$data['countryList']		= $this->generallib->getCountryList($country='NULL');
				$data['state']		= '';
				$data['address']		= '';
				$data['status']		= '1';
				$data['action']		= 'Add';
				$data['titleAccountMessage'] = TITLE008;
				$data['titlePersonalMessage'] = TITLE009;

				if($errorMesssage==0)
				$data['titleErrorMessage'] = FROMMESSAGE001;
				elseif($errorMesssage==-1)
				$data['titleErrorMessage'] = FROMMESSAGE001;
				elseif($errorMesssage==-2)
				$data['titleErrorMessage'] = FROMMESSAGE002;
				elseif($errorMesssage==-3)
			    $data['titleErrorMessage'] = FROMMESSAGE003;				
				else
				$data['titleErrorMessage'] = FROMMESSAGE001;



				$this->load->view('reseller/add_form_reseller1',$data);

			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}

/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Add/Edit Reseller I
 * @copyright 2011
 */
 
	function addEditReseller1()
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $id = $this->input->post('id');
               $action = $this->input->post('action');
               $login = $this->input->post('login');
               $password = $this->input->post('password');
               $id_rate = $this->input->post('id_rate');
               $full_name = $this->input->post('full_name');

               $checkResellerLoginName = $this->resellerModel->checkResellerLogin($login);

               $addDscripttion = "Add Reseller Level I,  Login: ".$login;
			   $editDescripttion = "Edit  Reseller Level I,  Login: ".$login;

			   if($action=="Add")
			   {
	              if(empty($login) OR empty($password) OR empty($id_rate) OR empty($full_name))
                  redirect("reseller/addFormReseller1/-1", "Location");

	              if($login==$password)
                  redirect("reseller/addFormReseller1/-3", "Location");

	              if($checkResellerLoginName==1)
	              redirect("reseller/addFormReseller1/-2", "Location");

			      $this->resellerModel->addReseller1($userID);
			      $this->generallib->addUserLog($userID,'-1','Insert',$addDscripttion);
			      redirect("reseller/resellerLevel1List/30", "Location");
			   }
			   else
			   {
	              if($login==$password)
                  redirect("reseller/editFormReseller1/".$id."/-3", "Location");

	              if(empty($login) OR empty($password) OR empty($id_rate) OR empty($full_name))
                  redirect("reseller/editFormReseller1/".$id."/-1", "Location");
			      
				  $this->resellerModel->editReseller1($userID);
			      $this->generallib->addUserLog($userID,'-1','Edit',$editDescripttion);
			      redirect("reseller/resellerLevel1List/31", "Location");
			   }

			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Add Form of Reseller I
 * @copyright 2011
 */
 
	function editFormReseller1($id=0,$errorMesssage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $editInfo = $this->resellerModel->reseller1EditInfo($id);
                if($editInfo==0)
                {
                   redirect("reseller/resellerLevel1List", "Location");
                }
                else
                {
                   foreach($editInfo as $row)
                   {
						$data['id']		 = $row->id;
						$data['resellerLevel2List'] = $this->generallib->getResellerLeve2List($row->id_reseller);
						$data['login']		 = $row->login;
						$data['password']		 = $row->password;
						$data['balance']		 = $row->balance;
						$data['rateList']		 = $this->generallib->getTariffList($row->id_rate);
						$data['limit_user']		 = $row->limit_user;
						$data['limit_rate']		 = $row->limit_rate;
						$data['limit_balance']		 = $row->limit_balance;
						$data['limit_fnf']		 = $row->limit_fnf;
						$data['commission']		 = $row->commission;
						$data['type']		 = $row->type;
						$data['aniuser']		 = $row->aniuser;
						$data['sipuser']		 = $row->sipuser;
						$data['full_name']		 = $row->full_name;
						$data['email']		 = $row->email;
						$data['cell']		 = $row->cell;
						$data['phone']		 = $row->phone;
						$data['city']		 = $row->city;
						$data['countryList']		= $this->generallib->getCountryList($row->country);
						$data['state']		 = $row->state;
						$data['address']		 = $row->address;
						$data['status']		 = $row->status;
                   }
                   $data['action']		= 'edit';
 				   if($errorMesssage==0)
				   $data['titleErrorMessage'] = FROMMESSAGE001;
				   elseif($errorMesssage==-1)
				   $data['titleErrorMessage'] = FROMMESSAGE001;
				   elseif($errorMesssage==-2)
				   $data['titleErrorMessage'] = FROMMESSAGE002;
				   elseif($errorMesssage==-3)
			       $data['titleErrorMessage'] = FROMMESSAGE003;	
				   elseif($errorMesssage==23)
			       $data['titleErrorMessage'] = FROMMESSAGE023;				
				   else
				   $data['titleErrorMessage'] = "";

                   $data['titleAccountMessage'] = TITLE008;
				   $data['titlePersonalMessage'] = TITLE009;
                   $this->load->view('reseller/edit_form_reseller1',$data);
                }
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show Reseller I Payment Form
 * @copyright 2011
 */
 
	function showPaymentFormLevel1($idReseller,$lastBalance = 0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED == NO_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $data['paymentHistory'] = $this->resellerModel->resellerPaymentHistory($idReseller,1);
                $data['id'] = "";
                $data['id_reseller'] = $idReseller;
                $data['lastBalance'] = $lastBalance;
                $data['level'] = 1;
                $data['amount'] = INIT_ADD_BALANCE;
                $data['type'] = "1";
                $data['user_id'] = $userID;
                $data['description'] = "";
                $data['usertype'] = ADMIN_TYPE;
                $data['creationdate'] = date('Y-m-d H:i:s');
                $this->load->view('reseller/add_payment_form_level1',$data);
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Add Reseller I Payment
 * @copyright 2011
 */
 

	function addReseller1Payment()
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
               $idReseller = $this->input->post('id_reseller');
               $addDscripttion = "Add Reseller Payment Level I,  idReseller: ".$idReseller;
			   $this->resellerModel->addResellerPayment($userID,1);
			   $this->generallib->addUserLog($userID,'-1','Insert',$addDscripttion);
			   redirect("reseller/editFormReseller1/".$idReseller.'/23', "Location");
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Reseller I Delete
 * @copyright 2011
 */
 
	function deleteReseller1($idReseller)
	{
		set_time_limit(36000);
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
			$resellerCUED = $this->session->userdata('resellerCURD');
			if($resellerCUED != ALL_ACCESS)
			{
			  redirect("admin/cpanel/accessDenied", "Location");
			}
			else
			{
                $checkChildResellerSIP = $this->resellerModel->checkChildReseller1SIP($idReseller);
                $checkChildResellerPIN = $this->resellerModel->checkChildReseller1PIN($idReseller);
                $checkChildResellerIP = $this->resellerModel->checkChildReseller1IP($idReseller);
                if($checkChildResellerSIP==1 OR $checkChildResellerPIN==1 OR $checkChildResellerIP==1)
                redirect("reseller/resellerLevel1List/-1", "Location");
                else
                {
                    $this->resellerModel->deleteReseller1($idReseller);
                    redirect("reseller/resellerLevel1List/1", "Location");

                }
			}
		}
		else
		{
			redirect("logout", "Location");
		}
	}
	
	
			

}
?>