<?php
//////////////////////////////////////// 
function Template_Array($filepath,$index=0)
{
    if(file_exists($filepath))
    {
        $contents=file_get_contents($filepath);
        $contents=addslashes($contents);
        $contents=explode("%%",$contents);
        $eval_string = "\$strtoprint=\"".$contents[$index]."\";";
        extract($GLOBALS);
        eval($eval_string);
        $strtoprint=str_replace("\'","'",$strtoprint);
        $strtoprint=str_replace('\"','"',$strtoprint);
        return $strtoprint;
    }
    else return " Template File Is Not Existed $filepath<br />";
}
////////////////////////////////////////
function pages($query, $per_page, $start, $links="")
{
    global $link,$connection,$site_template,$Previous,$previousClass,$classname,$number,$Next,$NextClass;
    $myquery_query = mysql_query($query, $connection);
    $numz = mysql_num_rows($myquery_query);
    $pages_num = ceil($numz / $per_page);
    $current = ceil(($start + 1)/$per_page);
    if($start>=$per_page)
    {
        $start = $start - $per_page;
        $Previous = "<a href=\"?$links&start=$start\">السابق</a>";
        
        $pages .= Template_Array("$site_template/admin/pagenation.html"); 
        $start = $start + $per_page;
    }
    else
    {

        $Previous = "السابق";
        $previousClass = "previous-off";
      

        $pages .= Template_Array("$site_template/admin/pagenation.html"); 
    }
    
    $start = $start + $per_page;
    $pages_num = ceil($numz/$per_page);
    for($i=0;$i<$pages_num;$i++)
    {
        $nums = $i*$per_page;
        if($i+1!=$current)
        {
            $classname="";
            $number = "<a href=\"?$links&start=$nums\">".($i+1)."</a>";
            $pages .= Template_Array("$site_template/admin/pagenation.html",1);
        }
        else
        {
           $classname="active";
           $number = ($i+1);
           $pages .= Template_Array("$site_template/admin/pagenation.html",1); 
        } 
    } 
    if($numz>$start)
    {
        $Next .= "<a href=\"?$links&start=$start\">التالي</a>";
        $pages .= Template_Array("$site_template/admin/pagenation.html",2);
    }
    else
    {
        $Next .= "التالي";
        $NextClass = "next-off";
        $pages .= Template_Array("$site_template/admin/pagenation.html",2);
    }
    if($numz>$per_page) return $pages;
    else return "";
}
////////////////////////////////////////
function ajaxpages($query, $per_page, $start, $links="")
{
    global $link,$connection,$site_template,$Previous,$previousClass,$classname,$number,$Next,$NextClass;
    $myquery_query = mysql_query($query, $connection);
    $numz = mysql_num_rows($myquery_query);
    $pages_num = ceil($numz / $per_page);
    $current = ceil(($start + 1)/$per_page);
    $pagename = strtolower(end(explode('/',$_SERVER[PHP_SELF])));
    if($start>=$per_page)
    {
        $start = $start - $per_page;
        $Previous = "<a href=\"javascript:void(0);\" onclick=\"getData('$pagename?$links&start=$start','lastarticaldata');\">السابق</a>";
        
        $pages .= Template_Array("$site_template/admin/pagenation.html"); 
        $start = $start + $per_page;
    }
    else
    {
        $Previous = "السابق";
        $previousClass = "previous-off";
        $pages .= Template_Array("$site_template/admin/pagenation.html"); 
    }
    
    $start = $start + $per_page;
    $pages_num = ceil($numz/$per_page);
    for($i=0;$i<$pages_num;$i++)
    {
        $nums = $i*$per_page;
        if($i+1!=$current)
        {
            $classname="";
            $number = "<a href=\"javascript:void(0);\" onclick=\"getData('$pagename?$links&start=$nums','lastarticaldata'); \">".($i+1)."</a>";
            $pages .= Template_Array("$site_template/admin/pagenation.html",1);
        }
        else
        {
           $classname="active";
           $number = ($i+1);
           $pages .= Template_Array("$site_template/admin/pagenation.html",1); 
        } 
    }
    if($numz>$start)
    {
        $Next .= "<a href=\"javascript:void(0);\" onclick=\"getData('$pagename?$links&start=$start','lastarticaldata'); \">التالي</a>";
        $pages .= Template_Array("$site_template/admin/pagenation.html",2);
    }
    else
    {
        $Next .= "التالي";
        $NextClass = "next-off";
        $pages .= Template_Array("$site_template/admin/pagenation.html",2);
    }
    if($numz>$per_page) return $pages;
    else return "";
}
/////////////////////////////////////////////////////////////////////////////////
?>