<?php
include_once("header.php");
if($login==1)
{
if($action=="add")
{
  if(isset($submit)&&$cat!=0)
  {
   if(in_array(strtolower(end(explode(".",$_FILES['host_pic']['name']))), $pic_types)
            && strlen($_FILES['host_pic']['name'])!=0
            &&move_uploaded_file($_FILES["host_pic"]["tmp_name"],"../up/banner/".time().$_FILES["host_pic"]["name"]))
               {
                $pic_name = time().$_FILES["host_pic"]["name"];
               }
    mysql_query("insert into host_plan values('','$cat','$name','$mprice',
    '$yprice','$space','$traffic','$database','$subdomain','$ftp','$pic_name',
    '$content','1')");
    $msg="تم الاضافه بنجاح";
    $sub =host();
    header( 'refresh: 2; url=host.php' );
  }
  else
  {
     if(isset($submit)&&$cat==0)
     {
       $msg="يرجى اختيار القسم";
     }
      $textarea="content";
    $sub=Template_Array("$site_template/admin/host_add.html",0);
  }
}
elseif($action=="edit")
{
  if(isset($submit)&&$cat!=0)
  {
     
      mysql_query("update host_plan set host_name='$name',host_cat='$cat',
   host_name='$name',host_month_price='$mprice',host_year_price='$yprice',
   host_space='$space',host_traffic='$traffic',host_database='$database',
   host_subdomain='$subdomain',host_ftp='$ftp',
   host_comment='$content' where host_id=$id");
    $msg="تم التعديل";
    $sub=host();
  }
  else
  {
    $editqu=mysql_query("select * from host_plan where host_id='$id'");
    while($row=mysql_fetch_array($editqu))
    {
      extract($row);
    }
    if(isset($submit)&&$cat==0)
     {
       $msg="يرجى اختيار القسم";
     }
    $textarea="content";
     $sub = Template_Array("$site_template/admin/host_edit.html",0);
  }
}
elseif($action=="delete")
{
  mysql_query("delete from host_plan where host_id='$id'");
  $msg="تم الحذف بنجاح";
  $sub=host();
}
elseif($action=="state")
{
    $pages_query = mysql_query("SELECT * FROM host_plan where host_id='$id'",$connection);
        $pages_fetch = mysql_fetch_array($pages_query);
        extract($pages_fetch);
        if($state==1)
         {
            $state=0;
            $msg = "تم التعطيل";
         }
        else
         {
           $state=1;
           $msg = "تم التنشيط ";
         }
        mysql_query("update host_plan set state='$state' where host_id='$id'"); 
        $sub = host();
}
elseif($action=="editpic")
{
   if(isset($submit))
   {
      if(in_array(strtolower(end(explode(".",$_FILES['host_pic']['name']))), $pic_types)
            && strlen($_FILES['host_pic']['name'])!=0
            &&move_uploaded_file($_FILES["host_pic"]["tmp_name"],"../up/banner/".time().$_FILES["host_pic"]["name"]))
              {
                $pic_name = time().$_FILES["host_pic"]["name"];
               }  
     mysql_query("update host_plan set host_pic='$pic_name' where host_id='$id'");
       $msg="تم تعديل الصوره";
      $sub = host();
       
   }
   else
   {
      $sub = Template_Array("$site_template/admin/host_edit.html",1);
   }
}
else
{
    if($action=="reseller")
    {
       $sub=reseller();
    }
    else  $sub = host();
    
}
}
else
{
    echo Template_Array("$site_template/admin/login.html");
    die();
}
 include_once("footer.php");
 ?>