<?php
  include_once("header.php");
  if(!$start)$start=0;
if($login==1)
{
  if($action=="addcat")
  {
    if(isset($submit))
    {
      mysql_query("insert into support_cat values('','$name','1')");
     $msg="تم الاضافه بنجاح";
     $sub=support_cat();
    }
    else
    {
      $sub = Template_Array("$site_template/admin/supportcat_add.html",0);
    }
  }
  elseif($action=="editcat")
  {
     if(isset($submit))
     {
       mysql_query("update support_cat set name='$name' where id='$id'");
       $msg="تم التعديل بنجاح";
       $sub=support_cat();
     }
     else
     {
       $catquery=mysql_query("select * from support_cat where id='$id'");
       while($row=mysql_fetch_array($catquery))
       {
         extract($row);
       }
       $sub = Template_Array("$site_template/admin/supportcat_add.html",0);
     }
  }
  elseif($action=="statecat")
  {
    $pages_query = mysql_query("SELECT * FROM support_cat 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 support_cat set state='$state' where id='$id'"); 
        $sub = support_cat();
  }
  elseif($action=="deletecat")
  {
     mysql_query("delete from support_cat where id='$id'");
     $msg="تم الحذف بنجاح";
     $sub = support_cat();
  }
  elseif($action=="showticket")
  {
     $sub=ticket();
  }
  elseif($action=="stateticket")
  {
     $pages_query = mysql_query("SELECT * FROM support_ticket 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 support_ticket set state='$state' where id='$id'"); 
        $sub = ticket();
        $sub .= support_cat();
  }
  elseif($action=="deleteticket")
  {
    mysql_query("delete from support_ticket where id='$id'");
    $msg="تم حذف التذكره بنجاح";
    $sub = ticket();
  }
  elseif($action=="replyticket")
  {
    if(isset($submit))
    {
      mysql_query("insert into ticket_reply values('','$id','$content','0','".time()."')");
      $msg="تم الرد على التذكره";
      $sub=ticket();
    }
    else
    {
        
      $ticketquery=mysql_query("select * from support_ticket where id='$id'");
      while($ticketrow=mysql_fetch_array($ticketquery))
      {
        extract($ticketrow);
        $ticket_date=date("Y-m-d-(h:i)",$ticket_date);
       $user=mysql_result(mysql_query("select user_name as name from user where id='$ticketrow[user_id]'"),"name");
       switch($impotance)
       {
         case 1;
         $impotance="عادى";
         break;
         case 2;
         $impotance="متوسط";
         break;
         case 3;
         $impotance="مهم";
         break;
         case 4;
         $impotance="مهم جدا";
         break ;
       }
      }
      $sub .= Template_Array("$site_template/admin/ticketreply.html",0);
      $replyquery=mysql_query("select * from ticket_reply where ticket_id='$id'");
     $sub .= Template_Array("$site_template/admin/ticketreply.html",1);
      while($replyrow=mysql_fetch_array($replyquery))
      {
         extract($replyrow);
         $reply_time=date("Y-m-d-h:i",$reply_time);
         $usermod=mysql_result(mysql_query("select user_name as name from user where id='$replyrow[user_id]'"),"name");
          if($user_id==0)$usermod="admin";
         $sub .= Template_Array("$site_template/admin/ticketreply.html",2);
      }
      $sub .= Template_Array("$site_template/admin/ticketreply.html",3);
      $textarea="content";
     $sub .= Template_Array("$site_template/admin/ticketreply.html",4);
    }
  }
  else
  {
    $sub = support_cat();
  }
}
else
{
    echo Template_Array("$site_template/admin/login.html");
    die();
}
  include_once("footer.php");
?>
