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

	if(!function_exists('find_images'))
	{
		function find_images($string)
		{
			preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $string, $image);
			
			if($image == TRUE)
			{
				return $image['src'];	
			}
			else
			{
				return base_url('assets/img/no_image_available.jpg');
			}
		}
	}
	
	if(!function_exists('public_url'))
	{
		function public_url($path = NULL) {
		  return base_url() . $path . '.html';
		}	
	}
	
	if (!function_exists('clean')) 
	{
		function clean($string) 
		{
			$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
			$url = pathinfo($string, PATHINFO_FILENAME);
			if($url == TRUE)
			{
				$filename = $url;
			}
			else
			{
				$filename = $string;
			}
			
			return preg_replace('/[^A-Za-z0-9\-]/', '', $filename); // Removes special chars.
		}
	}
	
	if (!function_exists('get_servicename')) 
	{
		function get_servicename($service_id)
		{
			$ci =& get_instance();
			$results = "";
			$sql = $ci->db->query("SELECT `typename` FROM `tblservices` WHERE `status`= 1 AND `id` LIKE '".$service_id."'");
			
			if($sql->num_rows() > 0)
			{
				$v = $sql->row(); 
				$results = $v->typename;	
		  		return $results;
			}else{
		 		return $results;
			}
		}	
	}
	
	
	if (!function_exists('get_carname')) 
	{
		function get_carname($car_id)
		{
			$ci =& get_instance();
			$results = "";
			$sql = $ci->db->query("SELECT `fullname` FROM `tblcar` WHERE `status`= 1 AND `id` = '".$car_id."'");
			
			if($sql->num_rows() > 0)
			{
				$v = $sql->row(); 
				$results = $v->fullname;	
		  		return $results;
			}else{
		 		return $results;
			}
		}	
	}
	
	if (!function_exists('getlocationname'))
	  {
		  function getlocationname($id)
		  {
				$ci = & get_instance();
				//$sql = $ci->db->query("SELECT `locationname` FROM `tbllocation` WHERE `status` = 1 and `id` ='".$id."'");
				$sql = $ci->db->query("SELECT `locationname` FROM `tbllocation` WHERE `id` ='".$id."'");
				$results = '';
				if($sql->num_rows() > 0)
				{
					$v = $sql->row(); 
					$results = $v->locationname;	
					return $results;
				}else{
					return $results;
				}		
		  }
	  }
	  
	  if (!function_exists('getRoute'))
	  {
		  function getRoute($id)
		  {
				$ci = & get_instance();
				$sql = $ci->db->query("SELECT `locationfrom`,`locationto` FROM `tblroutes` WHERE `status` = 1 and `id` ='".$id."'");
				$results = '';
				if($sql->num_rows() > 0)
				{
					$v = $sql->row(); 
					return array(
						'locationfrom'	=>	$v->locationfrom,
						'locationto'	=>	$v->locationto,
					);	
				}else{
					return array(
						'locationfrom'	=>	'',
						'locationto'	=>	'',
					);	
				}		
		  }
	  }
	  
	  if (!function_exists('paymentMethod'))
	  {
		  function paymentMethod($method)
		  {
			if($method == 0){
				$payMethod = "Pay at Agent";
			}elseif($method == 1){
				$payMethod = "Credit Balance";
			}elseif($method == 2){
				$payMethod = "Credit Card";
			}elseif($method == 3){
				$payMethod = "ACLEDA ToanChet";
			}elseif($method == 4 || $method ==11){
				$payMethod = "PiPay";
			}elseif($method == 5){
				$payMethod = "Asia Weiluy";
			}elseif($method == 9||$method == 10){
				$payMethod = "emoney";
			}elseif($method == 123||$method == 124){
				$payMethod = "Wing";
			}elseif($method == 233){
				$payMethod = "Alipay QR Code";
			}elseif($method == 234){
				$payMethod = "Alipay Barcode";
			}elseif($method == 15){
				$payMethod = "Unionpay";
			}elseif($method == 9168){
				$payMethod = "Pay Way (ABA Pay or QR Code)";
			}elseif($method == 9169){
				$payMethod = "Pay Way (Credit Card)";
			}elseif($method == 9170){
				$payMethod = "ABA APP";
			}else{
				return $payMethod = "";
			}
			return $payMethod;	
		 }	
	  }
	  
	  if (!function_exists('moneyFormat')) 
	  {
		  function moneyFormat($amount, $dec=2) 
		  {
			  if($amount ==''){
				 return number_format(0, $dec);
			  }else{
				 $result = number_format($amount, $dec);
				 return $result;
			  }
		  }
	  }
	  
	  if (!function_exists('get_user_info_update'))
	  {
		  function get_user_info_update($id,$data)
		  {
		   	  return'<div class="modal fade" id="myUser'.$id.'" role="dialog">
				  <div class="modal-dialog"> 
					<div class="modal-content">
					  <div class="modal-header">
						<button type="button" class="close" data-dismiss="modal">&times;</button>
						<h4 class="modal-title">Edit User</h4>
					  </div>
					  <div class="modal-body">
						<form​​​ method="post">
						   <input type="hidden" id="id'.$id.'" name="id'.$id.'" class="form-control" value="'.$data['id'].'">
						   <div class="form-group col-lg-12">
							<label>Username</label>
								<input id="username'.$id.'" name="username'.$id.'" class="form-control" type="text" placeholder="Enter Username" value="'.$data['username'].'">
						   </div>

						   <div class="form-group col-lg-12">
								<label>FullName</label>
								<input id="fullname'.$id.'" name="fullname'.$id.'" class="form-control" type="text" placeholder="Enter FullName" value="'.$data['fullname'].'">
						   </div>
							
						   <div class="form-group col-lg-12">
								<label>Email</label>
								<input id="email'.$id.'" name="email'.$id.'" class="form-control" type="text" placeholder="Enter Email" value="'.$data['email'].'">
						   </div>
							
						   <div class="form-group col-lg-12">
								<label>Phone</label>
								<input id="phone'.$id.'" name="phone'.$id.'" class="form-control" type="text" placeholder="Enter Phone" value="'.$data['phone'].'">
						   </div>
							
						   <div class="form-group col-lg-12">
								<label>Remark</label>
								<textarea id="remark'.$id.'" name="remark'.$id.'" class="textarea" placeholder="Place some text here" style="width: 100%; height: 80px;">'.$data['remark'].'</textarea>
						   </div>
						   <div class="form-group col-lg-12" style="margin-top:10px;">
						   		<input type="button" name="update_user" value="Update" class="btn btn-primary"  onclick="SubmitForm'.$id.'();"/>
						   </div>
						</form>
					  </div>
					  <div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					  </div>
					</div>
				  </div>
			  </div>
			  <script type="text/javascript">
				function SubmitForm'.$id.'() 
				{
					var id =  $("#id'.$id.'").val();
					var username = $("#username'.$id.'").val();
					var fullname = $("#fullname'.$id.'").val();
					var email = $("#email'.$id.'").val();
					var phone = $("#phone'.$id.'").val();
					var remark = $("#remark'.$id.'").val();
					$.post("'.base_url('/admin/partnership/update_user').'",{id:id,username:username,fullname:fullname,email:email,phone:phone,remark:remark},
					function(data) {
						alert(data);
						location.reload(); 
					});
				}
			 </script>';  
		  }
	  }
	  