<?php
include_once("header.php");
if($login==1)
{
if($action=="add")
{
  if(isset($submit))
  {
   if(in_array(strtolower(end(explode(".",$_FILES['pic']['name']))), $pic_types)
            && strlen($_FILES['pic']['name'])!=0
            &&move_uploaded_file($_FILES["pic"]["tmp_name"],"../up/banner/".time().$_FILES["pic"]["name"]))
               {
                $pic_name = time().$_FILES["pic"]["name"];
               }
    mysql_query("insert into product values('','$name','$link','$price','$pic_name','$comment','1')");
    $msg="تم الاضافه بنجاح";
    $sub =product();
    header( 'refresh: 2; url=product.php' );
  }
  else
  {
      $textarea="comment";
    $sub=Template_Array("$site_template/admin/product_add.html",0);
  }
}
elseif($action=="edit")
{
  if(isset($submit))
  {
      if(in_array(strtolower(end(explode(".",$_FILES['pic']['name']))), $pic_types)
            && strlen($_FILES['pic']['name'])!=0
            &&move_uploaded_file($_FILES["pic"]["tmp_name"],"../up/banner/".time().$_FILES["pic"]["name"]))
              {
                $pic_name = time().$_FILES["pic"]["name"];
               }
      mysql_query("update product set name='$name',link='$link',
      price='$price',pic='$pic_name',comment='$comment' where id=$id");
    $msg="تم التعديل";
    $sub=product();
  }
  else
  {
    $editqu=mysql_query("select * from product where id='$id'");
    while($row=mysql_fetch_array($editqu))
    {
      extract($row);
    }
    $textarea="comment";
     $sub = Template_Array("$site_template/admin/product_add.html",0);
  }
}
elseif($action=="delete")
{
  mysql_query("delete from product where id='$id'");
  $msg="تم الحذف بنجاح";
  $sub=product();
}
elseif($action=="state")
{
    $pages_query = mysql_query("SELECT * FROM product where 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 product set state='$state' where id='$id'"); 
        $sub = product();
}
else
{
  $sub = product(); 
}
}
else
{
    echo Template_Array("$site_template/admin/login.html");
    die();
}
 include_once("footer.php");
 ?>