<?php
include_once("header.php");
if($login==1)
{
if($action=="add")
{
  if(isset($submit)&&$place!=0)
  {
   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 head_menu values('','$name','$content','$pic_name','1','$place')");
    $msg="تم الاضافه بنجاح";
    $sub =headmenu();
    header( 'refresh: 2; url=head.php' );
  }
  else
  {
     if(isset($submit)&&$place==0)
     {
       $msg="يرجى تحديد مكان العرض";
     }
      $textarea="content";
    $sub=Template_Array("$site_template/admin/head_add.html",0);
  }
}
elseif($action=="edit")
{
  if(isset($submit)&&$place!=0)
  {
      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 head_menu set name='$name',content='$content',
    pic='$pic_name',view_place='$place' where head_id=$id");
    $msg="تم التعديل";
    $sub=headmenu();
  }
  else
  {
    $editqu=mysql_query("select * from head_menu where head_id='$id'");
    while($row=mysql_fetch_array($editqu))
    {
      extract($row);
    }
    if(isset($submit)&&$place==0)
     {
       $msg="يرجى تحديد مكان العرض";
     }
    $textarea="content";
     $sub = Template_Array("$site_template/admin/head_add.html",0);
  }
}
elseif($action=="delete")
{
  mysql_query("delete from head_menu where head_id='$id'");
  $msg="تم الحذف بنجاح";
  $sub=headmenu();
}
elseif($action=="state")
{
    $pages_query = mysql_query("SELECT * FROM head_menu where head_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 head_menu set state='$state' where head_id='$id'"); 
        $sub = headmenu();
}
else
{
  $sub = headmenu(); 
}
}
else
{
    echo Template_Array("$site_template/admin/login.html");
    die();
}
 include_once("footer.php");
 ?>