<?php
function admin_login()
{
	global $connection, $username, $password, $login, $admin_registerdate, $admin_lastlogin, $admin_lastip, $admin_note;
	$password = md5($password);
	$admin_query = mysql_query("SELECT * FROM admin WHERE admin_name='$username'",$connection);
	if($admin_fetch = mysql_fetch_array($admin_query))
	{
		extract($admin_fetch);
		if($password==$admin_password)
		{
			$login = 1;
			mysql_query("UPDATE admin SET admin_lastlogin='".time()."', admin_lastip='".$_SERVER['REMOTE_ADDR']."' WHERE admin_name='$admin_name'");
			setcookie("adminpass", $password, time()+3600);
			setcookie("adminname", $admin_name, time()+3600);
		}
		else
		{
			$login = 2;
		}
	}
	else
	{
		$login = 0;
	}
}
//////////////////////////////////////////////////////////////////////////
function admin_check()
{
	global $connection, $login, $admin_registerdate, $admin_lastlogin, $admin_lastip, $admin_note;
	$admin_query = mysql_query("SELECT * FROM admin WHERE admin_name='$_COOKIE[adminname]' && admin_password='$_COOKIE[adminpass]'",$connection);
	if($admin_fetch = mysql_fetch_array($admin_query))
	{
		extract($admin_fetch);
		$login = 1;
		setcookie("adminpass", $admin_password, time()+3600);
		setcookie("adminname", $admin_name, time()+3600);
	}
	else
	{
		$login = 0;
	}
}
//////////////////////////////////////////////////////////////////////////
function siteword()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $name;  
  $sitequery=mysql_query("select * from site_word");
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
  if($state==1)
        {
            $state = "<img src=\"../images/buttons/active.png\" title=نشط  border=0>";
            $state0 = "<img src=\"../images/buttons/inactive.png\" title=معطل  border=0>";
            $statet = "تعطيل";
        }
        else
        {
            $state = "<img src=\"../images/buttons/inactive.png\" title=معطل border=0>";
            $state0 = "<img src=\"../images/buttons/active.png\" title=نشط border=0>";
            $statet = "تنشيط";
        }
}
 $site = Template_Array("$site_template/admin/site.html",0);
 return $site;
}
//////////////////////////////////////////////////////////////////////////
function sitemeta()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $site_name,$meta;  
  $sitequery=mysql_query("select * from site_meta");
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
}
 $site = Template_Array("$site_template/admin/site.html",1);
 return $site;
}
//////////////////////////////////////////////////////////////////////////
function headmenu()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $head_id,$name,$content,$place;  
  $sitequery=mysql_query("select * from head_menu order by head_id asc LIMIT $start,$per_page");
  $head .= Template_Array("$site_template/admin/head_all.html",0);
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
  if($view_place==1) $place="اعلى";
  elseif($view_place==2) $place="اسفل";
  elseif($view_place==3) $place="يمين";
  else $place="يسار";
  if($state==1)
        {
            $state = "<img src=\"../images/buttons/active.png\" title=نشط  border=0>";
            $state0 = "<img src=\"../images/buttons/inactive.png\" title=معطل  border=0>";
            $statet = "تعطيل";
        }
        else
        {
            $state = "<img src=\"../images/buttons/inactive.png\" title=معطل border=0>";
            $state0 = "<img src=\"../images/buttons/active.png\" title=نشط border=0>";
            $statet = "تنشيط";
        }
    $head .= Template_Array("$site_template/admin/head_all.html",1);
}
 $pages = pages("SELECT * FROM head_menu", $per_page, $_GET['start'], "");
 $head .= Template_Array("$site_template/admin/head_all.html",2);
 return $head;
}
///////////////////////////////////////////////////////////////////////////
function works()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $work_id,$name,$type;  
  $sitequery=mysql_query("select * from works order by work_id asc LIMIT $start,$per_page");
  $head .= Template_Array("$site_template/admin/works_all.html",0);
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
   switch($type)
   {
     case 1:
     $type="موقع كامل";
     break;
     case 2:
     $type="برمجه فقط";
     break;
     case 3:
     $type="تصميم فقط";
     break;
     case 4:
     $type="استضافه فقط";
   }
    $head .= Template_Array("$site_template/admin/works_all.html",1);
}
 $pages = pages("SELECT * FROM works", $per_page, $_GET['start'], "");
 $head .= Template_Array("$site_template/admin/works_all.html",2);
 return $head;
}
///////////////////////////////////////////////////////////////////////////
function host()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $host_id,$host_name,$place,$host_cat;  
  $sitequery=mysql_query("select * from host_plan where host_cat='1' order by host_id asc LIMIT $start,$per_page");
  $head .= Template_Array("$site_template/admin/host_all.html",0);
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
  if($view_place==1) $place="اعلى";
  elseif($view_place==2) $place="اسفل";
  elseif($view_place==3) $place="يمين";
  else $place="يسار";
  if($state==1)
        {
            $state = "<img src=\"../images/buttons/active.png\" title=نشط  border=0>";
            $state0 = "<img src=\"../images/buttons/inactive.png\" title=معطل  border=0>";
            $statet = "تعطيل";
        }
        else
        {
            $state = "<img src=\"../images/buttons/inactive.png\" title=معطل border=0>";
            $state0 = "<img src=\"../images/buttons/active.png\" title=نشط border=0>";
            $statet = "تنشيط";
        }
    $head .= Template_Array("$site_template/admin/host_all.html",1);
}
 $pages = pages("SELECT * FROM host_plan", $per_page, $_GET['start'], "");
 $head .= Template_Array("$site_template/admin/host_all.html",2);
 return $head;
}
//////////////////////////////////////////////////////////////////////////
function reseller()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $host_id,$host_name,$place;  
  $sitequery=mysql_query("select * from host_plan where host_cat='2' order by host_id asc LIMIT $start,$per_page");
  $head .= Template_Array("$site_template/admin/host_all.html",0);
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
  if($view_place==1) $place="اعلى";
  elseif($view_place==2) $place="اسفل";
  elseif($view_place==3) $place="يمين";
  else $place="يسار";
  if($state==1)
        {
            $state = "<img src=\"../images/buttons/active.png\" title=نشط  border=0>";
            $state0 = "<img src=\"../images/buttons/inactive.png\" title=معطل  border=0>";
            $statet = "تعطيل";
        }
        else
        {
            $state = "<img src=\"../images/buttons/inactive.png\" title=معطل border=0>";
            $state0 = "<img src=\"../images/buttons/active.png\" title=نشط border=0>";
            $statet = "تنشيط";
        }
    $head .= Template_Array("$site_template/admin/host_all.html",1);
}
 $pages = pages("SELECT * FROM host_plan", $per_page, $_GET['start'], "");
 $head .= Template_Array("$site_template/admin/host_all.html",2);
 return $head;
}
//////////////////////////////////////////////////////////////////////////
function group()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $group_id,$name;  
  $sitequery=mysql_query("select * from groups order by group_id asc LIMIT $start,$per_page");
  $head .= Template_Array("$site_template/admin/group_all.html",0);
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
  if($state==1)
        {
            $state = "<img src=\"../images/buttons/active.png\" title=نشط  border=0>";
            $state0 = "<img src=\"../images/buttons/inactive.png\" title=معطل  border=0>";
            $statet = "تعطيل";
        }
        else
        {
            $state = "<img src=\"../images/buttons/inactive.png\" title=معطل border=0>";
            $state0 = "<img src=\"../images/buttons/active.png\" title=نشط border=0>";
            $statet = "تنشيط";
        }
    $head .= Template_Array("$site_template/admin/group_all.html",1);
}
 $pages = pages("SELECT * FROM groups", $per_page, $_GET['start'], "");
 $head .= Template_Array("$site_template/admin/group_all.html",2);
 return $head;
}
/////////////////////////////////////////////////////////////////////////
function user()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $user_id,$user_name,$id;  
  $sitequery=mysql_query("select * from user where id='$id' order by id asc LIMIT $start,$per_page");
  $head .= Template_Array("$site_template/admin/user_all.html",0);
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
  if($state==1)
        {
            $state = "<img src=\"../images/buttons/active.png\" title=نشط  border=0>";
            $state0 = "<img src=\"../images/buttons/inactive.png\" title=معطل  border=0>";
            $statet = "تعطيل";
        }
        else
        {
            $state = "<img src=\"../images/buttons/inactive.png\" title=معطل border=0>";
            $state0 = "<img src=\"../images/buttons/active.png\" title=نشط border=0>";
            $statet = "تنشيط";
        }
    $head .= Template_Array("$site_template/admin/user_all.html",1);
}
 $pages = pages("SELECT * FROM user", $per_page, $_GET['start'], "");
 $head .= Template_Array("$site_template/admin/user_all.html",2);
 return $head;
}
/////////////////////////////////////////////////////////////////////////
function support_cat()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $id,$name;  
  $sitequery=mysql_query("select * from support_cat order by id asc LIMIT $start,$per_page");
  $head .= Template_Array("$site_template/admin/supportcat_all.html",0);
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
  if($state==1)
        {
            $state = "<img src=\"../images/buttons/active.png\" title=نشط  border=0>";
            $state0 = "<img src=\"../images/buttons/inactive.png\" title=معطل  border=0>";
            $statet = "تعطيل";
        }
        else
        {
            $state = "<img src=\"../images/buttons/inactive.png\" title=معطل border=0>";
            $state0 = "<img src=\"../images/buttons/active.png\" title=نشط border=0>";
            $statet = "تنشيط";
        }
    $head .= Template_Array("$site_template/admin/supportcat_all.html",1);
}
 $pages = pages("SELECT * FROM support_cat", $per_page, $_GET['start'], "");
 $head .= Template_Array("$site_template/admin/supportcat_all.html",2);
 return $head;
}
///////////////////////////////////////////////////////////////////////////
function ticket()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $id,$title,$user,$user_id,$ticket_date;  
  $sitequery=mysql_query("select * from support_ticket where cat_id='$id'  order by id asc LIMIT $start,$per_page");
  $head .= Template_Array("$site_template/admin/ticket_all.html",0);
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
  $ticket_date=date("Y-m-d",$ticket_date);
  $user=mysql_result(mysql_query("select user_name as name from user where id='$row[user_id]'"),"name");
  if($state==1)
        {
            $state = "<img src=\"../images/buttons/active.png\" title=نشط  border=0>";
            $state0 = "<img src=\"../images/buttons/inactive.png\" title=معطل  border=0>";
            $statet = "تعطيل";
        }
        else
        {
            $state = "<img src=\"../images/buttons/inactive.png\" title=معطل border=0>";
            $state0 = "<img src=\"../images/buttons/active.png\" title=نشط border=0>";
            $statet = "تنشيط";
        }
    $head .= Template_Array("$site_template/admin/ticket_all.html",1);
}
 $pages = pages("SELECT * FROM support_ticket where cat_id='$id'", $per_page, $_GET['start'], "");
 $head .= Template_Array("$site_template/admin/ticket_all.html",2);
 return $head;
}
///////////////////////////////////////////////////////////////
function product()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $id,$name,$content,$place;  
  $sitequery=mysql_query("select * from product order by id asc LIMIT $start,$per_page");
  $head .= Template_Array("$site_template/admin/product_all.html",0);
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
  if($state==1)
        {
            $state = "<img src=\"../images/buttons/active.png\" title=نشط  border=0>";
            $state0 = "<img src=\"../images/buttons/inactive.png\" title=معطل  border=0>";
            $statet = "تعطيل";
        }
        else
        {
            $state = "<img src=\"../images/buttons/inactive.png\" title=معطل border=0>";
            $state0 = "<img src=\"../images/buttons/active.png\" title=نشط border=0>";
            $statet = "تنشيط";
        }
    $head .= Template_Array("$site_template/admin/product_all.html",1);
}
 $pages = pages("SELECT * FROM product", $per_page, $_GET['start'], "");
 $head .= Template_Array("$site_template/admin/product_all.html",2);
 return $head;
}
/////////////////////////////////////////////////////////////////
function ads()
{
  global $connection, $site_template, $msg, $sub,$langdata, $pages, $templates, $start, $state, $statet, $state0, $cat,$langdata,$admin_template,$per_page,$_GET,$numoflang;
  global $id,$name,$content,$place;  
  $sitequery=mysql_query("select * from ads order by id asc LIMIT $start,$per_page");
  $head .= Template_Array("$site_template/admin/ads_all.html",0);
while($row=mysql_fetch_array($sitequery))
{
  extract($row);
   if($view_place==1) $place="اعلى";
  elseif($view_place==2) $place="اسفل";
  elseif($view_place==3) $place="يمين";
  else $place="يسار";
  if($state==1)
        {
            $state = "<img src=\"../images/buttons/active.png\" title=نشط  border=0>";
            $state0 = "<img src=\"../images/buttons/inactive.png\" title=معطل  border=0>";
            $statet = "تعطيل";
        }
        else
        {
            $state = "<img src=\"../images/buttons/inactive.png\" title=معطل border=0>";
            $state0 = "<img src=\"../images/buttons/active.png\" title=نشط border=0>";
            $statet = "تنشيط";
        }
    $head .= Template_Array("$site_template/admin/ads_all.html",1);
}
 $pages = pages("SELECT * FROM ads", $per_page, $_GET['start'], "");
 $head .= Template_Array("$site_template/admin/ads_all.html",2);
 return $head;
}

?>