<?php
class generallib{

var $resultString = "Rows 0 - 0 from 0.";
var $pagingString = "";
var $limitString  = "";
var $startPositition = 0;

function generallib()
        {
                $this->obj1 =& get_instance();
        }



function showPaginationmy($url, $totalRow,  $limit=10 , $startOffset=0,$planid)
 {


   $totalPage 		= 1;
   $currentPage  	= 1;
   $prevPage 		= 0;
   $nextPage 		= 1;


	$totalPage 		= ceil($totalRow/$limit);
	$currentPage 	= ceil($startOffset);
	$prevPage 		= ($currentPage - 1) * $limit;
	$nextPage 		= ($currentPage + 1) * $limit;

	$starting 		= $startOffset * $limit  + 1;

	$ending 		= $starting+10;

//echo "<<<".$startOffset;
	if($ending>= $totalRow)
	 {
	   $ending 		= $totalRow;
	 }

    if($prevPage < 0)
     {
       $prevPage 	= 0;
     }

	if($nextPage >= $totalRow)
	 {
	   $nextPage 	= $startOffset;
	 }



$startPage = 1;

if($currentPage/2 > 10 )
{
  $startPage = $currentPage - 10;
}

if($totalPage>20)
{
  $totalPage = $startPage + 20;
}



	$txt ="";



	 if($currentPage >0)
       $txt .= "&nbsp;&nbsp;<a href='#' onclick = 'dopagination($planid,".($currentPage-1).",$limit)'  style='text-decoration:none;'>Previous</a>&nbsp;&nbsp;";

	for($i=$startPage;$i<$totalPage;$i++)
	    {
	     // echo $i." = ".$currentPage."<BR>";

	      $sta = ($i * $limit);
	      if($i-1==$currentPage)
	       {
	       //$txt .= "&nbsp;<a href='#' onclick = 'dopagination($planid,".($i-1).",$limit)' style='text-decoration:none;color:blue'><b><u>$i</u></b></a>&nbsp;";
$txt .= "&nbsp;<spin style='text-decoration:none;color:blue'><b><u>$i</u></b></spin>&nbsp;";
	       }
	      else
	       $txt .= "&nbsp;<a href='#' onclick = 'dopagination($planid,".($i-1).",$limit)' style='text-decoration:none;color:Black'><b>$i</b></a>&nbsp;";
	       //$txt .= "&nbsp; style='text-decoration:none;color:Black'><b>$i</b>&nbsp;";
        }




 if($currentPage + 1 < $totalPage)
	$txt .= "&nbsp;&nbsp;<a href='#' onclick = 'dopagination($planid,".($currentPage+1).",$limit)'  style='text-decoration:none;'>Next</a>&nbsp;&nbsp;";


return $txt;
//echo $txt;


 }






function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}






function sec_to_time($seconds) {
    $hours = floor($seconds / 3600);
    $minutes = floor($seconds % 3600 / 60);
    $seconds = $seconds % 60;

    return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
}






function addUserLog($id_reseller,$level,$narration,$description)
{
$ip_address = $this->getRealIpAddr();
$date_time = date('Y-m-d H:i:s');

$sql = "INSERT INTO userlog (id_reseller , level , narration , description , ip_address , date_time )
VALUES ('$id_reseller' , '$level' , '$narration' , '$description' , '$ip_address' , '$date_time')";

 $query = $this->obj1->db->query($sql);

}



/**
 * @Show All Reseller Base Tariff List
*/

	function getTariffList($idRate)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT * FROM ratename where id_rate='$idRate'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id_rate'>$row->description</option>";
		}
		$str .="<option value=''>--Select Tariff --</option>";
		$queryAll = $this->obj1->db->query("SELECT * FROM ratename order by description ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id_rate'>$rowAll->description</option>";
			}
		}

		return $str;
	}





/**
 * @Show All Country List
*/

	function getCountryList($countrycode)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT * FROM country where countrycode='$countrycode'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->countrycode'>$row->countryname</option>";
		}
		$str .="<option value=''>--Select One Country --</option>";
		$queryAll = $this->obj1->db->query("SELECT * FROM country order by countryname ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->countrycode'>$rowAll->countryname</option>";
			}
		}

		return $str;
	}






/**
 * @Show All Reseller III  List
*/

	function getResellerLeve3List($idReseller)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT id,login FROM resellers3 where id='$idReseller'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->login</option>";
		}
		$str .="<option value=''>--Select One --</option>";
		$queryAll = $this->obj1->db->query("SELECT id,login FROM resellers3 order by login ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->login</option>";
			}
		}

		return $str;
	}



/**
 * @Show All Reseller II  List
*/

	function getResellerLeve2List($idReseller)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT id,login FROM resellers2 where id='$idReseller'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->login</option>";
		}
		$str .="<option value=''>--Select One --</option>";
		$queryAll = $this->obj1->db->query("SELECT id,login FROM resellers2 order by login ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->login</option>";
			}
		}

		return $str;
	}




/**
 * @Show All Reseller I  List
*/

	function getResellerLeve1List($idReseller)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT id,login FROM resellers1 where id='$idReseller'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->login</option>";
		}
		$str .="<option value=''>--Select One --</option>";
		$queryAll = $this->obj1->db->query("SELECT id,login FROM resellers1 order by login ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->login</option>";
			}
		}

		return $str;
	}




	function getReseller3Name($idReseller)
	{
 		$query = $this->obj1->db->query("SELECT full_name FROM bb_resellers3 WHERE id = '$idReseller'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->full_name;
	 	}
	 	else
	 	return "Admin";
	}



	function getReseller2Name($idReseller)
	{
 		$query = $this->obj1->db->query("SELECT full_name FROM bb_resellers2 WHERE id = '$idReseller'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->full_name;
	 	}
	 	else
	 	return "Admin";
	}


	function getReseller1Name($idReseller)
	{
 		$query = $this->obj1->db->query("SELECT full_name FROM bb_resellers1 WHERE id = '$idReseller'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->full_name;
	 	}
	 	else
	 	return "Admin";
	}



	function getResellerName($idReseller,$level)
	{
 		$tableName = "resellers".$level;
		 $query = $this->obj1->db->query("SELECT full_name FROM $tableName WHERE id = '$idReseller'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->full_name;
	 	}
	 	else
	 	return "Admin";
	}

	function getIDReseller($idReseller,$level)
	{
 		$tableName = "resellers".$level;
		 $query = $this->obj1->db->query("SELECT id_reseller FROM $tableName WHERE id = '$idReseller'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->id_reseller;
	 	}
	 	else
	 	return "-1";
	}


	function getResellerLogin($idReseller,$level)
	{
 		$tableName = "resellers".$level;
		 $query = $this->obj1->db->query("SELECT login FROM $tableName WHERE id = '$idReseller'");
		 //echo $this->obj1->db->last_query();
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->login;
	 	}
	 	else
	 	return "Admin";
	}





	function getReteName($idRate)
	{
 		$query = $this->obj1->db->query("SELECT description FROM ratename WHERE id_rate = '$idRate'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->description;
	 	}
	 	else
	 	return "Not Define";
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Return Reseller I Balance Limit
 * @copyright 2011
 */


	function getReseller1BalanceLimit($id)
	{
 		$query = $this->obj1->db->query("SELECT limit_balance FROM resellers1 WHERE id = '$id'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->limit_balance;
	 	}
	 	else
	 	return 0;
	}




/**
 * @Show All Provider List
*/

	function getProviderList($id)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT * FROM gatwayprovider where id='$id'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->provider_name</option>";
		}
		$str .="<option value=''>--Select Provider --</option>";
		$queryAll = $this->obj1->db->query("SELECT * FROM gatwayprovider order by provider_name ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->provider_name</option>";
			}
		}

		return $str;
	}



	function getTrunkList($idTrunk)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT * FROM trunk where id_trunk='$idTrunk'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id_trunk'>$row->description</option>";
		}
		$str .="<option value=''>--Select One --</option>";
		$queryAll = $this->obj1->db->query("SELECT * FROM trunk order by description ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id_trunk'>$rowAll->description</option>";
			}
		}

		return $str;
	}



	function getWholesaleList($idTrunk)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT * FROM clientsip where id='$idTrunk'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->login</option>";
		}
		$str .="<option value=''>--Select One --</option>";
		$queryAll = $this->obj1->db->query("SELECT * FROM clientsip order by login ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->login</option>";
			}
		}

		return $str;
	}
	
	

	function getTrunkName($id_trunk)
	{
 		$query = $this->obj1->db->query("SELECT description FROM trunk WHERE id_trunk = '$id_trunk'");
 		//echo $this->obj1->db->last_query();
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->description;
	 	}
	 	else
	 	return "--";
	}


	function getTariffPlanList($id)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT * FROM cc_tariffplan where id='$id'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->tariffname</option>";
		}
		$str .="<option value=''>--Select One Plan --</option>";
		$queryAll = $this->obj1->db->query("SELECT * FROM cc_tariffplan order by tariffname ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->tariffname</option>";
			}
		}

		return $str;
	}



	function getPriorityList($priority)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT * FROM bb_priority where priority='$priority'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->priority'>$row->priority</option>";
		}
		$str .="<option value=''>--Select One Priority --</option>";
		$queryAll = $this->obj1->db->query("SELECT * FROM bb_priority order by priority ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->priority'>$rowAll->priority</option>";
			}
		}

		return $str;
	}


	function getDeleteResellerInformation($level,$idReseller)
	{
 		$tableName = "resellers".$level;
		 $query = $this->obj1->db->query("SELECT login,password,balance,id_rate,full_name FROM $tableName WHERE id = '$idReseller'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	 		$login = $row->login;
	 		$password = $row->password;
	 		$id_rate = $row->id_rate;
	 		$balance = $row->balance;
	 		$full_name = $row->full_name;
	 		return "Reseller Level:".$level.". Login:".$login.",Password:".$password.",Base Rate ID:".$id_rate.", Full Name:".$full_name." and Balance:".$balance;
	 	}
	 	else
	 	return "";
	}




/**
 * @Show All Reseller III Login  List
*/

	function getResellerLeve4LoginList($idReseller)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT id,login FROM resellers4 where id='$idReseller'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->login</option>";
		}
		$str .="<option value=''>--Select One --</option>";
		$queryAll = $this->obj1->db->query("SELECT id,login FROM resellers4 order by login ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->login</option>";
			}
		}

		return $str;
	}





/**
 * @Show All Reseller III Login  List
*/

	function getResellerLeve3LoginList($idReseller)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT id,login FROM bb_resellers3 where id='$idReseller'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->login</option>";
		}
		$str .="<option value=''>--Select One --</option>";
		$queryAll = $this->obj1->db->query("SELECT id,login FROM bb_resellers3 order by login ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->login</option>";
			}
		}

		return $str;
	}


/**
 * @Show All Reseller II Login  List
*/

	function getResellerLeve2LoginList($idReseller)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT id,login FROM bb_resellers2 where id='$idReseller'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->login</option>";
		}
		$str .="<option value=''>--Select One --</option>";
		$queryAll = $this->obj1->db->query("SELECT id,login FROM bb_resellers2 order by login ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->login</option>";
			}
		}

		return $str;
	}





/**
 * @Show All Reseller I Login  List
*/

	function getResellerLeve1LoginList($idReseller)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT id,login FROM bb_resellers1 where id='$idReseller'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->login</option>";
		}
		$str .="<option value=''>--Select One --</option>";
		$queryAll = $this->obj1->db->query("SELECT id,login FROM bb_resellers1 order by login ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->login</option>";
			}
		}

		return $str;
	}




/**
 * @Show All Lots Lists
*/

	function getLotsList($lot_id,$clientType = 2)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT lot_id,description FROM lotsname where lot_id='$lot_id'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->lot_id'>$row->description</option>";
		}
		$str .="<option value=''>--Select One Lot --</option>";
		$queryAll = $this->obj1->db->query("SELECT lot_id,description FROM lotsname where clienttype = '$clientType' order by description ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->lot_id'>$rowAll->description</option>";
			}
		}

		return $str;
	}



/**
 * @Show All Plan List
*/

	function getPlanList($plan_id)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT plan_id,description FROM billingplan where plan_id='$plan_id'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->plan_id'>$row->description</option>";
		}
		$str .="<option value=''>--Select Plan --</option>";
		$queryAll = $this->obj1->db->query("SELECT plan_id,description FROM billingplan order by description ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->plan_id'>$rowAll->description</option>";
			}
		}

		return $str;
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show All Client IP List
 * @copyright 2011
 */


	function getClientIPList($id)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT id,login,full_name FROM clientsip where id='$id'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->full_name</option>";
		}
		$str .="<option value=''>--Select One Client --</option>";
		$queryAll = $this->obj1->db->query("SELECT id,login,full_name FROM clientsip order by full_name ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->full_name</option>";
			}
		}

		return $str;
	}



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


	function getDIDTypeList($id)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT id,description FROM didtype where id='$id'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->description</option>";
		}
		$str .="<option value=''>--Select Type --</option>";
		$queryAll = $this->obj1->db->query("SELECT id,description FROM didtype order by description ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->description</option>";
			}
		}

		return $str;
	}


/**
 * @Show Get DID Number Type
*/

	function getDIDNumberType($id)
	{
 		$query = $this->obj1->db->query("SELECT description FROM didtype WHERE id = '$id'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->description;
	 	}
	 	else
	 	return "Not Define";
	}




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


	function getDayList($id)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT id,description FROM days where id='$id'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->description</option>";
		}
		$queryAll = $this->obj1->db->query("SELECT id,description FROM days Where id !='$id' order by id ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->description</option>";
			}
		}

		return $str;
	}



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


	function getProtocalList($protocal)
	{
		$str = "";
		$query = $this->obj1->db->query("SELECT protocol_name FROM protocol where protocol_name='$protocal'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->protocol_name'>$row->protocol_name</option>";
		}
		$queryAll = $this->obj1->db->query("SELECT protocol_name FROM protocol Where protocol_name !='$protocal' order by protocol_name ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->protocol_name'>$rowAll->protocol_name</option>";
			}
		}

		return $str;
	}




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

	function getDay($id)
	{
 		$query = $this->obj1->db->query("SELECT description FROM days WHERE id = '$id'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->description;
	 	}
	 	else
	 	return "--";
	}




/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Get SIP Register IP Address
 * @copyright 2011
 */

	function getRegisterIPAddress($id,$type = 1)
	{
 		$query = $this->obj1->db->query("SELECT ipaddr,port FROM sipusers WHERE id_client = '$id' AND clienttype = '$type'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	 		$ipAddress = $row->ipaddr;
	 		$port = $row->port;

	 		if($ipAddress == '')
	 		$ipAddress = "0.0.0.0";

	 		if($port == '0')
	 		$port == '0000';


	  		//return $ipAddress.":".$port;
	  		return $ipAddress;
	 	}
	 	else
	 	return "";
	}





/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Get SIP Full Contact Details
 * @copyright 2011
 */

	function getfullContactDetails($id,$type = 1)
	{
 		$query = $this->obj1->db->query("SELECT fullcontact FROM sipusers WHERE id_client = '$id' AND clienttype = '$type'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		//return $ipAddress.":".$port;
	  		return $row->fullcontact;
	 	}
	 	else
	 	return "NULL";
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Get SIP Full Contact Details
 * @copyright 2011
 */

	function getSipClientConfiguration($id,$type = 1)
	{
 		$query = $this->obj1->db->query("SELECT fullcontact FROM sipusers WHERE id_client = '$id' AND clienttype = '$type'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		//return $ipAddress.":".$port;
	  		return $row->fullcontact;
	 	}
	 	else
	 	return "NULL";
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Get Total Number of Rate Chart
 * @copyright 2011
 */

	function getNumRateChartList($idRate)
	{
 		$query = $this->obj1->db->query("SELECT COUNT(id) as totalRow FROM ratechart WHERE id_rate = '$idRate'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->totalRow;
	 	}
	 	else
	 	return 0;
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Get Total Number of Rate Chart
 * @copyright 2011
 */

	function getTotalFaildCall($callDate)
	{
 		$query = $this->obj1->db->query("SELECT COUNT(id_call) as totalRow FROM calls WHERE callstart LIKE '$callDate%' AND duration = 0");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->totalRow;
	 	}
	 	else
	 	return 0;
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Get Total Number of CurrentCall
 * @copyright 2011
 */

	function getTotalCurrentCall()
	{
 		$query = $this->obj1->db->query("SELECT COUNT(id) as totalRow FROM activecall");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->totalRow;
	 	}
	 	else
	 	return 0;
	}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Get Total Number of Admin Online
 * @copyright 2011
 */

	function getTotalAdminOnline($userID)
	{
 		$query = $this->obj1->db->query("SELECT COUNT(id) as totalRow FROM admin where is_login = 1 AND id != '$userID'");
		if ($query->num_rows() > 0)
	 	{
	 		$row = $query->row();
	  		return $row->totalRow;
	 	}
	 	else
	 	return 0;
	}


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: This function return Online Admin Users
 * @copyright 2011
 */
	function onlineAdminuserList($userID)
	{


        $sql = "SELECT *FROM admin
				where id !='$userID' AND is_login = 1 order by full_name ASC";

			   //echo $sql;

	    $query = $this->obj1->db->query($sql);
	    if($query->num_rows()>0)
		  return $query->result();
	    else
		 return 0;
	}




/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: This function return All Reseller List
 * @copyright 2011
 */
 

	function getResellerList($idReseller,$level)
	{
		if($level == 4)
		$tableName = "resellers4";
		elseif($level == 3)
		$tableName = "resellers3";
		elseif($level == 2)
		$tableName = "resellers2";
		else
		$tableName = "resellers1";
		
		$str = "";
		$query = $this->obj1->db->query("SELECT id,login FROM $tableName where id='$idReseller'");
		if($query->num_rows() > 0)
		{
			$row = $query->row();
			$str .="<option value='$row->id'>$row->login</option>";
		}
		$str .="<option value=''>--Select Reseller --</option>";
		$queryAll = $this->obj1->db->query("SELECT id,login FROM $tableName order by login ASC");
		if($queryAll->num_rows() > 0)
		{
			foreach ($queryAll->result() as $rowAll)
			{
			$str .="<option value='$rowAll->id'>$rowAll->login</option>";
			}
		}

		return $str;
	}


	### added by Md. Sabbir Ali ###
	function get_reseller_name($id_reseller='',$level='')
    {
        if(empty($id_reseller) OR empty($level))
        {
            return 'N/A';
        }
        
        switch($level)
        {
            case '1':
                $sql = "SELECT * FROM resellers1 WHERE id=$id_reseller LIMIT 1";
                break;
            
            case '2':
                $sql = "SELECT * FROM resellers2 WHERE id=$id_reseller LIMIT 1";
                break;
                
            case '3':
                $sql = "SELECT * FROM resellers3 WHERE id=$id_reseller LIMIT 1";
                break;
                
            default:
                $sql = "SELECT * FROM resellers4 WHERE id=$id_reseller LIMIT 1";
                break;
        }
        
        $query = $this->obj1->db->query($sql);
        if($query->num_rows()>0)
        {
            $row = $query->row();
            return $row->login;
        }
        else
        {
            return 'N/A';
        }
    }


}
?>