<?php
include_once("header.php");
if($login==1)
{
  // $sub="اهلا بك يا $_COOKIE[username]";

 if($action=="show")
  {
    if(isset($submit))
    {
      mysql_query("insert into ticket_reply values('','$id','$content','0','$_COOKIE[userid]','".time()."')");
      $msg="تم الرد على التذكره";
      $sub=ticket();
    }
    else
    {
        
      $ticketquery=mysql_query("select * from support_ticket where id='$ticketid'");
      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/ticketreply.html",0);
      $replyquery=mysql_query("select * from ticket_reply where ticket_id='$id'");
     $sub .= Template_Array("$site_template/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/ticketreply.html",2);
      }
      $sub .= Template_Array("$site_template/ticketreply.html",3);
      $textarea="content";
     $sub .= Template_Array("$site_template/ticketreply.html",4);
    }
  }
  elseif($action=="addticket")
  {
    if(isset($submit))
    {
      mysql_query("insert into support_ticket values('','$catid','".time()."','$importance','$title',
      '$comment','1','$_COOKIE[userid]')");
      $msg="تم فتح التذكره بنجاح";
      $sub = ticket();
    }
    else
    {
        $catquery=mysql_query("select * from support_cat");
        while($catrow=mysql_fetch_array($catquery))
        {
           extract($catrow);
           $cats .="<option value=$id>$name</option>";
        }
        $sub .= Template_Array("$site_template/add_ticket.html",0);
    }
  }
  elseif($action=="state")
  {
    $pages_query = mysql_query("SELECT * FROM support_ticket where id='$ticketid'",$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='$ticketid'"); 
        $sub = ticket();
         header( 'refresh: 1; url=usercp.php' );
}
  elseif($action=="delete")
  {
    mysql_query("delete from support_ticket where id='$ticketid'");
    $msg="تم الحذف";
    $sub = ticket();
     header( 'refresh: 1; url=usercp.php' );
  }
else
{
  $sub .=ticket();
}
}
else
{
      $sub = "عفوا لقد ادخلت اسم مستخدم أو كلمه مرور غير صحيحه من فضلك حاول مره اخري";
     $sub .= Template_Array("$site_template/login.html");
}
include_once("footer.php");
?>