	<?php
/*
	Hezecom Email Solution
	Author: Hezecom Technologies (http://hezecom.com) info@hezecom.net
	COPYRIGHT 2014 ALL RIGHTS RESERVED
	
	You must have purchased a valid license from CodeCanyon.com in order to have 
	access this file.

	You may only use this file according to the respective licensing terms 
	you agreed to when purchasing this item.
	*/
if(!defined('VALID_DIR')) die('You are not allowed to execute this file directly');
	//post
  function post($var)
  {
      if (isset($_POST[$var]))
          return $_POST[$var];
  }
  //get
  function get($var)
  {
      if (isset($_GET[$var]))
          return $_GET[$var];
  }
  
  //session
  function session($var)
  {
      if (isset($_SESSION[$var]))
          return $_SESSION[$var];
  }
  //send headers
  function send_to($direction)
  	{
      if (!headers_sent()) {
          header('Location: ' . $direction);
		  exit;
	  } else
          print '<script type="text/javascript">';
          print 'window.location.href="' . $direction . '";';
          print '</script>';
          print '<noscript>';
          print '<meta http-equiv="refresh" content="0;url=' . $direction . '" />';
          print '</noscript>';
  	}
	 //msgs
	function success_msg($dmsg){
	print('<div class="heze-notify progress-bar-success">
  <p>'.$dmsg.'</p>
  </div>
	');	
	}
	function error_msg($dmsg){
	print('<div class="heze-notify progress-bar-danger">
  <p>'.$dmsg.'</p>
  </div>
	');	
	}
	//editor
	function HezecomEditor($txteditor){
	print('
<script>
tinymce.init({
    selector: "textarea#'.$txteditor.'",
    theme: "modern",
    width: "auto",
    height: 200,
    plugins: [
         "advlist autolink link image lists charmap  preview hr anchor pagebreak spellchecker",
         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "save table contextmenu directionality   paste textcolor jbimages"
   ],
   toolbar: "styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l      ink  jbimages | print preview ", 
  
		relative_urls: false
 }); 
</script>
	');	
	}
	
	//File
	function delete_files($folder){
	  if(is_file($folder))
	unlink($folder);
		}
	//dir
	function app_dir($folder=NULL){
	$base = str_replace($folder,'',dirname(__FILE__));
	return str_replace('\\','/',$base);
	}

	//paging
	function pagination($query,$per_page = 10,$url=NULL,$page = 1){ 
		$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
    	$total = $query;
        $splitter = "2";
		$url1=$url."&page=";
    	$page = ($page == 0 ? 1 : $page);  
    	$start = ($page - 1) * $per_page;
		
		$firstPage = 1;
		$prev = ($page == 1)? 1:$page - 1;
								
    	$prev = $page - 1;							
    	$next = $page + 1;
        $lastpage = ceil($total/$per_page);
    	$lpm1 = $lastpage - 1;
    	$hezpaging = "";
    	if($lastpage > 1)
    	{	
    	$hezpaging .= "<ul class='hezpaging'>";
        $hezpaging .= "<li class='details'>".LANG_PAGE." $page of $lastpage</li>";

		if ($page == 1)
		{
		$hezpaging.= "<li><a class='current'>".LANG_FIRST."</a></li>";
		$hezpaging.= "<li><a class='current'>".LANG_PREVIOUS."</a></li>";
		}
		else
		{
		$hezpaging.= "<li><a href='".$url1."$firstPage'>".LANG_FIRST."</a></li>";
		$hezpaging.= "<li><a href='".$url1."$prev'>".LANG_PREVIOUS."</a></li>"; 
		}

    		if ($lastpage < 7 + ($splitter * 2)){	
    		for ($counter = 1; $counter <= $lastpage; $counter++){
    		if ($counter == $page)
    		$hezpaging.= "<li><a class='current'>$counter</a></li>";
    		else
    		$hezpaging.= "<li><a href='".$url1."$counter'>$counter</a></li>";					
    		}}
    		elseif($lastpage > 5 + ($splitter * 2)){
    		if($page < 1 + ($splitter * 2)){
    		for ($counter = 1; $counter < 4 + ($splitter * 2); $counter++){
    		if ($counter == $page)
    		$hezpaging.= "<li><a class='current'>$counter</a></li>";
    		else
    		$hezpaging.= "<li><a href='".$url1."$counter'>$counter</a></li>";					
    		}
    		$hezpaging.= "<li class='dot'>...</li>";
    		$hezpaging.= "<li><a href='".$url1."$lpm1'>$lpm1</a></li>";
    		$hezpaging.= "<li><a href='".$url1."$lastpage'>$lastpage</a></li>";		
    		}
    		elseif($lastpage - ($splitter * 2) > $page && $page > ($splitter * 2)){
    		$hezpaging.= "<li><a href='".$url1."1'>1</a></li>";
    		$hezpaging.= "<li><a href='".$url1."2'>2</a></li>";
    		$hezpaging.= "<li class='dot'>...</li>";
    		for ($counter = $page - $splitter; $counter <= $page + $splitter; $counter++){
    		if ($counter == $page)
    		$hezpaging.= "<li><a class='current'>$counter</a></li>";
    		else
    		$hezpaging.= "<li><a href='".$url1."$counter'>$counter</a></li>";					
    		}
    		$hezpaging.= "<li class='dot'>..</li>";
    		$hezpaging.= "<li><a href='".$url1."$lpm1'>$lpm1</a></li>";
    		$hezpaging.= "<li><a href='".$url1."$lastpage'>$lastpage</a></li>";		
    		}else{
    		$hezpaging.= "<li><a href='".$url1."1'>1</a></li>";
    		$hezpaging.= "<li><a href='".$url1."2'>2</a></li>";
    		$hezpaging.= "<li class='dot'>..</li>";
    		for ($counter = $lastpage - (2 + ($splitter * 2)); $counter <= $lastpage; $counter++){
    		if ($counter == $page)
    		$hezpaging.= "<li><a class='current'>$counter</a></li>";
    		else
    		$hezpaging.= "<li><a href='".$url1."$counter'>$counter</a></li>";					
    		}}}
    		if ($page < $counter - 1){ 
    		$hezpaging.= "<li><a href='".$url1."$next'>".LANG_NEXT."</a></li>";
            $hezpaging.= "<li><a href='".$url1."$lastpage'>".LANG_LAST."</a></li>";
    		}else{
    		$hezpaging.= "<li><a class='current'>".LANG_NEXT."</a></li>";
            $hezpaging.= "<li><a class='current'>".LANG_NEXT."</a></li>";
            }
    		$hezpaging.= "</ul>\n";		
    	}
        return $hezpaging;
    }
	function pageparam($limit){
	$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
    return ($page * $limit) - $limit;
	}
	
	//Form Messages
	function form_errors($errors){
	if(empty($errors) === false){
	echo '<div class="alert alert-danger">'.implode($errors).'</div>';	
	}	
	}
	
	function ValidEmail($email){
	$es= filter_var($email,FILTER_SANITIZE_EMAIL);
	return filter_var($es,FILTER_VALIDATE_EMAIL);
	}

function ValidNumber($number){
	$nu= filter_var($number,FILTER_SANITIZE_NUMBER_FLOAT);
	return filter_var($nu,FILTER_VALIDATE_FLOAT);
	}
	
 
function generate_options($from,$to,$callback=false)
{
	$reverse=false;
	
	if($from>$to)
	{
		$tmp=$from;
		$from=$to;
		$to=$tmp;
		
		$reverse=true;
	}
	
	$return_string=array();
	for($i=$from;$i<=$to;$i++)
	{
		$return_string[]='
		<option value="'.$i.'">'.($callback?$callback($i):$i).'</option>
		';
	}
	
	if($reverse)
	{
		$return_string=array_reverse($return_string);
	}
	
	
	return join('',$return_string);
}
function callback_month($month)
{
	return date('M',mktime(0,0,0,$month,1));
}

//captcha
function captcha_validation($limit=7){
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $limit; $i++) 
    {
        $randomString .= $chars[rand(0, strlen($chars)-1)];
    }
	return $_SESSION['captcha'] = strtoupper($randomString);
	 	
}
	//unser info
	function UserProfile($id)
	{
	$db=DB::getInstance();
	$stmt=$db->prepare("SELECT * FROM mailusers WHERE cusername=:id");
	$stmt->bindParam(':id',$id);
	$stmt->execute();
	return $stmt->fetch(PDO::FETCH_OBJ);
	}
?>
