<?php include 'inc_classes.php'; 
include "admin_authentication.php";
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Create Ticket</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap datepicker -->
    <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="plugins/iCheck/all.css">
    <!-- Bootstrap Color Picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css">
    <!-- Bootstrap time Picker -->
    <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="bower_components/select2/dist/css/select2.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- paginate style -->
    <link rel="stylesheet" href="dist/css/paginate.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
    <!-- Google Font -->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
    
</head>
<script>
        function select_staff(role) {
            // alert(role);
            var staff_data = "action=staff&roles=" + role;
            $.ajax({
                url: "ts_ticket_ajax.php", type: "post", data: staff_data, cache: false,
                success: function (retstaff) {
                    // alert(retstaff);
                    document.getElementById("select_staffs").innerHTML = retstaff;

                }
            });
        }
    </script>
<body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">
        <?php include "include/header-main.php"; ?>
        <!-- Left side column. contains the logo and sidebar -->
        <?php include "include/menu_left.php"; ?>
        <!-- Content Wrapper. Contains page content -->
        <!-- Left side column. contains the logo and sidebar -->
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                Create Ticket
                    <!--<small>Version 2.0</small>-->
                </h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                    <li class="active">Dashboard</li>
                </ol>
            </section>
            <?php
                if($_REQUEST['id']!='')
                {
                    $record_id=$_REQUEST['id'];
                    $query="select * from ts_incidence where id='$record_id'";
                    $ptr_data_3=mysql_query($query);
                    $data=mysql_fetch_array($ptr_data_3);
                }
                else
                {
                    $record_id=''; 
                }

         if(isset($_POST['submit']))
           {
               
                // $proj_id=$_POST['select_project'];
                // $team_id=$_POST['select_team'];
                // $categary=$_POST['select_categary'];
                $ref_id=rand(1000,9999);
                $inc_id='IN'.$ref_id;
                if (empty($_POST['categary'])){
                    $cat_Err = "Field is required";
                }
                else{
                    $categary=$_POST['categary'];
                }
                $sel_role="select ut_id from add_user_type where 1 and short_key='".$categary."'";
                $ptr_role=mysql_query($sel_role);
                $data_role=mysql_fetch_array($ptr_role);
                $ut_id=$data_role['ut_id'];
                if (empty($_POST['staff_name'])){
                    $staff_Err = "Field is required";
                }
                else{
                    $staff_id=trim($_POST['staff_name']);
                }
                if(empty($_POST['subject'])){
                    $subject_error = "Field is required";
                }
                else{
                        $subject=$_POST['subject'];
                 }
                 if (!strlen(trim(($_POST['desc']))))
                //  if (empty($_POST['desc']))
                 {
                     $desc_Err = "Field is required";
                }
                else
                {
                    $description=addslashes($_POST['desc']);
                }
                // }
                if (empty($_POST['optradio'])){
                    $priority_Err = "Field is required";
                }
                else{
                $Priority=$_POST['optradio'];
                }
                $admin_id =$_SESSION['admin_id'];
                // task updating
                   if($record_id)
                   { 
                        if($categary !="" &&  $staff_id !="" &&  $subject !="" &&  $description !="" &&  $Priority !="")
                        {
                            $upd_ticket="update ts_incidence set `categary_id`='".$ut_id."',`subject`='".$subject."',`description`='".$description."',`assign_to`='".$staff_id."',`priority`='".$Priority."' where id='".$record_id."'";
                            $ptr_upd_ticket=mysql_query($upd_ticket);

                            $upd_comment="update ts_details set `comment`='".$description."' where inc_id='".$data['inc_id']."'";
                            $ptr_up_cmt=mysql_query($upd_comment); 
                          if($ptr_upd_ticket)
                            {
                                ?>
                                <div class="alert alert-success alert-dismissible">
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                    <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                                    <p> Record Updated Successfully.</p>
                                </div>
                                <script>setTimeout('document.location.href="ts_add_ticket.php";', 500);</script>
                                <?php
                            }       
                        }  
                    }
                    // inserting data
                    else
                   {
                        if($categary !="" &&  $staff_id !="" &&  $subject !="" &&  $description !="" &&  $Priority !="")
                        {
                            $insert_ticket="insert into ts_incidence (`inc_id`,`categary_id`,`subject`,`generation`,`description`,`assign_to`,`status`,`priority`,`admin_id`,`added_date`) values('".$inc_id."','".$ut_id."','".$subject."','primary','".$description."','". $staff_id."','in_progress','".$Priority."','".$admin_id."','".date('Y-m-d : H:i:s')."')";
                            $ptr_ticket=mysql_query($insert_ticket);
                            $task_id=mysql_insert_id();
                          
                            '<br>'. $insert_comment="insert into ts_details(`inc_id`,`comment`,`staff_id`,`added_date`) values('".$inc_id."','".$description."','".$admin_id."','".date('Y-m-d : H:i:s')."')";
                            $ptr_comment=mysql_query($insert_comment);  
                            if ($ptr_ticket)
                            {
                                ?>
                                <div class="alert alert-success alert-dismissible">
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                    <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                                    <p> Record Inserted Successfully.</p>
                                </div>
                                <!-- <script>setTimeout('document.location.href="ts_add_ticket.php";', 500);</script> -->
                                <?php
                            }
                        }
                    }     
                    // ==================================== Ticket Mail ===============================================
                    // $sel_mail="select email from site_setting where admin_id='".$_SESSION['admin_id']."'";
                    // $ptr_mail=mysql_query($sel_mail);
                    // $data_mail=mysql_fetch_array($ptr_mail);
                    // '<br>'.$admin_mail=$data_mail['email'];
                    $sel_mails="select email from site_setting where admin_id='".$staff_id."'";
                    $ptr_mails=mysql_query($sel_mails);
                    $data_mails=mysql_fetch_array($ptr_mails);
                    '<br>'. $staff_mail=$data_mails['email'];

                    require 'PHPMailer-5.2.14/class.phpmailer.php';

                    $mail = new PHPMailer(true);
                    try {
                        // erp.isas.developer@gmail.com	
                        // erp.isas
                            //$mail = new PHPMailer();
                            //$mail->IsSMTP();                                      // Set mailer to use SMTP
                            $mail->SMTPDebug=1;
                            $mail->Host = 'smtp.gmail.com';                       // Specify main and backup server
                            $mail->SMTPAuth = true;                               // Enable SMTP authentication
                            $mail->Username = 'erp.isas.developer@gmail.com	';                   // SMTP username
                            $mail->Password = 'erp.isas';                            // SMTP password
                            $mail->SMTPSecure = 'ssl';                            // Enable encryption, 'tls' also accepted
                            $mail->Port = 465;
                            $mail->setFrom('info@isasbeautyschool.com', 'ISAS');
                            $mail->addAddress("kiran@isassystems.com"); 
                            //$mail->addCC("dattatray@isassystems.com"); 
                            
                            ///usr/local/bin/php -q /home/isasadmin007/isastest/faculty_login/dsr_mail.php?&send_mail=mail
                            ///bin/touch /home/isasadmin007/public_html/cron_test.txt >/dev/null 2>&1 && /bin/echo "Cron ran at: `date`" >> /home/isasadmin007/public_html/cron_test.txt
                            $mail->Subject = 'New ticket Assign To you on - '.date('Y-m-d H:i:s').'';
                    
                            $sendMessage=$GLOBALS['box_message_top'];
                            $sendMessage.=$message;
                            $sendMessage.=$GLOBALS['box_message_bottom'];
                            
                            $mail->WordWrap = 3000;
                            $mail->isHTML(true);
                            $mail->Body = $sendMessage;
                                
                            $mail->Send();
                            echo "Email Sent Successfully.";
                        } 
                        catch (phpmailerException $e) {
                            echo $e->errorMessage(); 
                        } 
                        catch (Exception $e) {
                            echo $e->getMessage(); 
                        }	
                    // ======================= ticket mail code end =============================       
                }
            // task  deleting
              if($_REQUEST['deleteRecord']!='' && $_REQUEST['id']!=''  && $_REQUEST['inc_id']!='' )
                {
                        $id=$_REQUEST['id'];
                        $inc_id=$_REQUEST['inc_id'];
                        $delete_ticket="delete from ts_incidence where id='".$id."'";   //task delete
                        $ptr_delete_ticket=mysql_query($delete_ticket);
                        $delete_details="delete from ts_details where inc_id='".$inc_id."'";     //task detail delete
                        $ptr_delete_details=mysql_query($delete_details);
                        if ($ptr_delete_ticket)
                        {
                        ?>
                            <div class="alert alert-danger alert-dismissible">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                                <p> Record Deleted Successfully.</p>
                            </div>
                            <script>
                                //  if(confirm("Are you sure, you want to delete selected record(s)?")){
                                setTimeout('document.location.href="ts_add_ticket.php";', 500);
                                                            // }
                            </script>
                        <?php
                        }
                }
              
   
            ?>
            <!-- Main content -->
            <section class="content">
                <!-- SELECT2 EXAMPLE -->
                <div class="box box-default">
                    <div class="box-body">
                        <form name="task_form" method="post">
                            <div class="row">
                                <div class="col-md-5">
                                    <p style="color:red"> * Required Field</p>
                                    <div class="form-group">
                                    <label><span style="color:red">*</span>Categary Name &nbsp;&nbsp;<span style="color:red">
                                                <?php echo $cat_Err ;?></span></label>
                                        <select class="form-control select2" id="select_categary" placeholder="select"
                                            name="categary" onchange="select_staff(this.value)">
                                            <option value="">select Categary</option>
                                                <?php
                                                    $categary="select ut_id,user_type,short_key from add_user_type";
                                                    $c_query=mysql_query($categary);
                                                    while($data_c=mysql_fetch_array($c_query))
                                                    {
                                                        $sel='';
                                                        if($data['categary_id']==$data_c['ut_id'])
                                                        {
                                                            $sel='selected=selected';
                                                        }
                                                        echo '<option '.$sel.' value="'.$data_c['short_key'].'">'.strip_tags(ucfirst($data_c['user_type'])). '</option>';
                                                    }
                                                ?>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                    <label><span style="color:red">*</span>Staff Name &nbsp;&nbsp;<span style="color:red">
                                                <?php echo $staff_Err ; ?></span></label>
                                        <?php
                                         if($record_id)
                                         {
                                             ?>
                                             <div>
                                                 <select class="form-control select2"  name="staff_name"
                                                     id="select_staffs">
                                                     <option value="">Select Staff</option>
                                                     <?php 
                                                        $sel_ut="select short_key from add_user_type where 1 and ut_id='".$data['categary_id']."'";
                                                        $ptr_ut=mysql_query($sel_ut);
                                                        $data_ut=mysql_fetch_array($ptr_ut);

                                                        $sel_staff1="select admin_id,name from site_setting where type='".$data_ut['short_key']."' and system_status='Enabled' order by name ASC";
                                                        $c_query=mysql_query($sel_staff1);
                                                        while($data_c=mysql_fetch_array($c_query))
                                                        {
                                                            $sel='';
                                                            if($data['assign_to']==$data_c['admin_id'])
                                                            {
                                                            $sel='selected=selected';
                                                            }
                                                            ?>
                                                                <option <?php echo $sel;?> value="
                                                                    <?php echo $data_c['admin_id'] ;?>">
                                                                    <?php echo ucfirst($data_c['name']);?>
                                                                </option>
                                                                <?php
                                                        }
                                                        ?>
                                                 </select>
                                             </div>
                                             <?php
                                         }
                                         else
                                         {
                                             ?>
                                            <select class="form-control select2" id="select_staffs" placeholder="select"
                                                name="staff_name" >
                                                <option value="">select Staff</option>
                                            </select>
                                            <?php
                                         }
                                         ?>
                                    </div>
                                    <div class="form-group">
                                        <label><span style="color:red">*</span>Subject &nbsp;&nbsp;<span style="color:red">
                                                <?php echo $subject_error ;?></span></label>
                                        <input type="text" class="form-control" name="subject" id="subject"
                                            placeholder="" value="<?=$data['subject']?>">
                                    </div>
                                    <div class="form-group">
                                        <label><span style="color:red">*</span>Description &nbsp;&nbsp;<span style="color:red">
                                                <?php echo $desc_Err ;?></span></label>
                                        <textarea class="form-control" name="desc" rows="3"
                                            placeholder="Enter ..."> <?php echo $data['description'] ?></textarea>
                                    </div>
                                    <div class="form-group">
                                        <div> 
                                            <label>
                                                <span style="color:red">*</span> Priority &nbsp;&nbsp;<span style="color:red"> <?php echo $priority_Err ;?></span>
                                           </label>
                                        </div>
                                        <label class="radio-inline"><input type="radio" name="optradio" id="high" <?php
                                                if($data['priority']=='high' ) echo 'checked="checked"' ; ?>
                                            value="high">High</label>
                                        <label class="radio-inline"><input type="radio" name="optradio" id="medium"
                                                <?php if($data['priority']=='medium' ) echo 'checked="checked"' ; ?>
                                            value="medium">Medium</label>
                                        <label class="radio-inline"><input type="radio" name="optradio" id="low" <?php
                                                if($data['priority']=='low' ) echo 'checked="checked"' ; ?>
                                            value="low">Low</label>
                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <input type="submit" name="submit"
                                        value="<?php if($record_id) echo 'Update'; else echo 'Submit'; ?>"
                                        class="btn btn-block btn-success">
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <style>
                    th {
                        text-align: center;
                    }
                </style>
                <div class="row">
                    <!-- Left col -->
                    <div class="col-md-12">
                        <!-- TABLE: LATEST ORDERS -->
                        <div class="box box-info">
                            <div class="box-header with-border">
                                <h3 class="box-title">manage Ticket</h3>
                            </div>
                            <div class="table-responsive">
                                <table class="table no-margin" >
                                    <form method="get" name="search">
                                        <tr>
                                            <!-- <td> -->
                                                <?php
                                                //  if($_SESSION['type']=='S' ||  $edit_access=='yes'|| $_SESSION['type']=='LD')
                                                // {
                                                    ?>
                                                    <!-- <select class="form-control select2" id="branch_name1"
                                                        style="width:150px" name="branch_name1"
                                                        onchange="select_admin(this.value)" ;>
                                                        <option value="">Select Branch</option> -->
                                                        <?php 
                                                            // $sel_branch="select branch_id,branch_name from branch";
                                                            // $ptr_sel=mysql_query($sel_branch);
                                                            // while($data_branch=mysql_fetch_array($ptr_sel))
                                                            // {
                                                            //     $sel='';
                                                            //     if($data_branch['branch_name']==$_GET['branch_name1'])
                                                            //     {
                                                            //         $sel='selected="selected"';
                                                            //     }
                                                            //     echo '<option '.$sel.' value="'.$data_branch['branch_name'].'" >'.$data_branch['branch_name'].'</option>';
                                                            // }
                                                        ?>
                                                    <!-- </select> -->
                                                    <?php
                                                // }
                                                // else
                                                // {
                                                    ?>
                                                        <!-- <input type="hidden" name="branch_names1" id="branch_names1" value="<?php echo $_SESSION['branch_name']; ?>" /> -->
                                                    <?php
                                                // }
                                                ?>
                                            <!-- </td> -->
                                            <!-- <td width="5px"></td> -->
                                            <td>
                                                <div>
                                                    <select class="form-control select2" style="width:150px" name="cat_type" id="select">
                                                         <option value="">Categary </option>
                                                        <?php
                                                            $categary="select ut_id,user_type,short_key from add_user_type";
                                                            $c_query=mysql_query($categary);
                                                            while($data_c=mysql_fetch_array($c_query))
                                                            {
                                                                $sel='';
                                                                if($_GET['cat_type']==$data_c['ut_id'])
                                                                {
                                                                    $sel='selected=selected';
                                                                }
                                                                echo '<option '.$sel.' value="'.$data_c['ut_id'].'">'.strip_tags(ucfirst($data_c['user_type'])). '</option>';
                                                            }
                                                        ?>
                                                    </select>
                                                </div>
                                            </td>
                                            <td>
                                                <div>
                                                    <select class="form-control select2" style="width:150px"
                                                        id="admin_name" name="admin_name">
                                                        <option value="">Assinged To</option>
                                                        <?php
                                                        $categary="select admin_id,name from site_setting where 1 and system_status='Enabled' order by name ASC";   //where cm_id='".$branch_data['cm_id']."'
                                                        $c_query=mysql_query($categary);
                                                        while($data_c=mysql_fetch_array($c_query))
                                                        {
                                                            $sel='';
                                                            if($data_c['admin_id']==$_GET['admin_name'])
                                                            {
                                                                $sel='selected="selected"';
                                                            }
                                                            echo  '<option '.$sel.' value="'.$data_c['admin_id'].'">'.ucfirst($data_c['name']). '</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                </div>
                                            </td>
                                            <?php 
                                            if($_SESSION['type']=='S')
                                            {
                                                ?>
                                                <td>
                                                    <div>
                                                        <select class="form-control select2" style="width:150px"
                                                            id="staff_names" name="staff_names">
                                                            <option value="">Assinged By</option>
                                                            <?php
                                                        $categary="select admin_id,name from site_setting where 1 and system_status='Enabled' order by name ASC";   //where cm_id='".$branch_data['cm_id']."'
                                                        $c_query=mysql_query($categary);
                                                        while($data_c=mysql_fetch_array($c_query))
                                                        {
                                                            $sel='';
                                                            if($data_c['admin_id']==$_GET['staff_names'])
                                                            {
                                                                $sel='selected="selected"';
                                                            }
                                                            echo  '<option '.$sel.' value="'.$data_c['admin_id'].'">'.ucfirst($data_c['name']). '</option>';
                                                        }
                                                        ?>
                                                        </select>
                                                    </div>
                                                </td>
                                                <?php
                                            }
                                            ?>
                                            </td>
                                            <td>
                                                <div>
                                                    <select class="form-control select2"  id="status" style="width:150px"name="status">
                                                        <option value="">Status</option>
                                                        <option value="solved" <?php if ($_GET['status']=="solved" )
                                                            echo "selected='selected'" ;?>>Solved</option>
                                                        <option value="in_progress" <?php if
                                                            ($_GET['status']=="in_progress" ) echo "selected='selected'"
                                                            ;?>>In_Progress</option>
                                                        <option value="cancel" <?php if ($_GET['status']=="cancel" )
                                                            echo "selected='selected'" ;?>>Cancel</option>
                                                        <option value="halt" <?php if ($_GET['status']=="halt" )
                                                            echo "selected='selected'" ;?>>Halt</option>
                                                    </select>
                                                </div>
                                            </td>
                                            <td width="">
                                                <input type="text" name="start_date" class="input_text datepicker"style="width:110px"
                                                    placeholder="Task Added Date" id="datepicker3" title="Task Date"
                                                    value="<?php echo $_REQUEST['start_date'];?>">
                                            </td>
                                            <td>
                                                <input type="text" class="form-control" name="keyword" style="width:100px"
                                                    id="searches" value="<?php if($_REQUEST['search']!=" search")
                                                    echo $_REQUEST['keyword'];?>" placeholder="search">
                                            </td>
                                            <td>
                                                <input type="image" src="images/search.jpg" name="search" value="search"
                                                    style="height:32px;">
                                            </td>
                                        </tr>
                                    </form>
                                    <tr>
                                        <div class="box-body">
                                            <table class="table no-margin" style="text-align:center">
                                                <thead>
                                                    <tr>
                                                        <th>Sr. No.</th>
                                                        <th>Ticket Id</th>
                                                        <th>Assign To</th>
                                                        <th>Subject</th>
                                                        <th>Description</th>
                                                        <th>Categary</th>
                                                        <th>Priority</th>
                                                        <th>Status</th>
                                                        <th>Assign By</th>
                                                        <th>Details</th>
                                                        <th>Added Date</th>
                                                        <th>Action</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                        if($_REQUEST['start_date'] && $_REQUEST['start_date']!=="0000-00-00")
                                                        {
                                                            $frm_date=explode("/",$_REQUEST['start_date']);
                                                            $frm_dates=$frm_date[2]."-".$frm_date[1]."-".$frm_date[0];
                                                            $start_date=$frm_dates;
                                                            $dates=" and DATE(added_date )='".date('Y-m-d',strtotime($frm_dates))."'";
                                                        }
                                                        if($_REQUEST['admin_name']!='')
                                                        {
                                                            $staff_id=$_REQUEST['admin_name'];
                                                            $search_staff_id="and assign_to='".$staff_id."'";
                                                        }
                                                        else
                                                        {
                                                            $search_staff_id='';
                                                        }
                                                        if($_REQUEST['staff_names']!='')
                                                        {
                                                            $admin_ids=$_REQUEST['staff_names'];
                                                            $search_admin_id="and admin_id='".$admin_ids."'";
                                                        }
                                                        else
                                                        {
                                                            //   $search_admin_id="and assign_by='".$_SESSION['admin_id']."'";
                                                            $search_admin_id="";
                                                        }
            
                                                        if($_REQUEST['cat_type']!='')
                                                        {
                                                            $categary_type=$_REQUEST['cat_type'];
                                                            $search_cat_type="and categary_id='".$categary_type."'";
                                                        }
                                                        else
                                                        {
                                                            $search_cat_type="";
                                                        }
            
                                                        if($_REQUEST['status']!='')
                                                        {
                                                            $status=$_REQUEST['status'];
                                                            $search_status="and status='".$status."'";
                                                        }
                                                        else
                                                        {
                                                            $search_status="";
                                                        }
                                                        $i=1;
                                                        if($_REQUEST['keyword']!="keyword")
                                                            $search=trim($_REQUEST['keyword']);
                                                        if($search)
                                                        {
                                                            $ticket_search=" and (subject like '%".$search."%' || priority like '%".$search."%' || inc_id like '%".$search."%')";
                                                        }
                                                        else
                                                        {
                                                            $ticket_search="";
                                                        }
                                                    
                                                    if($_SESSION['type']=='S')
                                                    {
                                                      $sel_in="select * from ts_incidence where 1 ".$ticket_search." ".$search_cat_type." ". $search_staff_id." ".$search_admin_id." ".$search_status." ".$dates." order by added_date desc";
                                                    }
                                                    else{
                                                        $sel_in="select * from ts_incidence where 1  ".$ticket_search." ".$search_cat_type." ". $search_staff_id." ".$search_status." ".$dates." and admin_id='".$_SESSION['admin_id']."' and generation='primary' order by added_date desc";
                                                    }
                                                    $ptr_in=mysql_query($sel_in);
                                                    while($data_in=mysql_fetch_array($ptr_in))
                                                    {
                                                            // $p_data="select proj_name from tk_project where proj_id='".$data['proj_id']."'";
                                                            // $ptr_data_p=mysql_query($p_data);
                                                            // $proj_data=mysql_fetch_array($ptr_data_p);

                                                            $sel_admin="select name from site_setting where 1 and admin_id='".$data_in['admin_id']."'";
                                                            $ptr_admin=mysql_query($sel_admin);
                                                            $data_admin=mysql_fetch_array($ptr_admin);

                                                            $sel_cat="select user_type from add_user_type where 1 and ut_id='".$data_in['categary_id']."'";
                                                            $ptr_cat=mysql_query($sel_cat);
                                                            $data_cat=mysql_fetch_array($ptr_cat);

                                                            $add_data="select name from site_setting where 1 and admin_id='".$data_in['assign_to']."'";
                                                            $ptr_data_a=mysql_query($add_data);
                                                            $data_add=mysql_fetch_array($ptr_data_a);
                                                            ?>
                                                            <tr>
                                                                <td>
                                                                    <?php echo $i++ ?>
                                                                </td>
                                                                <td>
                                                                    <?php echo ($data_in['inc_id'])?>
                                                                </td>
                                                                <td>
                                                                    <?php echo strip_tags(ucfirst($data_add['name']))?>
                                                                </td>
                                                                <td>
                                                                    <?php echo strip_tags(ucwords($data_in['subject']))?>
                                                                </td>
                                                                <td>
                                                                    <?php echo strip_tags(substr(ucwords($data_in['description']),0,70))?>...
                                                                </td>
                                                                <td>
                                                                    <?php echo strip_tags(ucfirst($data_cat['user_type']))?>
                                                                </td>
                                                                <td>
                                                                    <?php echo ucfirst($data_in['priority'])?>
                                                                </td>
                                                                <td>
                                                                        <?php
                                                                        //  echo ucfirst($data_in['status']);
                                                                        ?>
                                                                        <?php if($data_in['status']=='solved') 
                                                                            { 
                                                                                ?>
                                                                                <p class="label label-success"> <?php echo ucfirst($data_in['status']);?></p>
                                                                                <?php
                                                                            } 
                                                                            if($data_in['status']=='in_progress') 
                                                                            { 
                                                                                ?>
                                                                                <p class="label label-warning"><?php echo ucfirst($data_in['status']);?></p>
                                                                                <?php
                                                                            } 
                                                                            if($data_in['status']=='cancel') 
                                                                            { 
                                                                                ?>
                                                                                <p class="label label-danger"><?php echo ucfirst($data_in['status']);?></p>
                                                                                <?php
                                                                            } 
                                                                            if($data_in['status']=='halt') 
                                                                            { 
                                                                                ?>
                                                                                <p class="label label-primary"><?php echo ucfirst($data_in['status']);?></p>
                                                                                <?php
                                                                            } 
                                                                            if($data_in['status']=='pending') 
                                                                            { 
                                                                                ?>
                                                                                <p class="label label-danger"><?php echo ucfirst($data_in['status']);?></p>
                                                                                <?php
                                                                            } 
                                                                        ?>
                                                                    </td>
                                                                <td>
                                                                    <?php echo ucfirst($data_admin['name'])?>
                                                                </td>
                                                                
                                                                <td>
                                                                    <!--task details button -->
                                                                    <a href="ts_ticket_detail.php?id=<?= $data_in['inc_id'] ?>" target=""><i class="fa fa-file"></i></a> 
                                                                </td>
                                                                <td>
                                                                    <?php
                                                                        $new_addDate = date("d-m-Y", strtotime( $data_in['added_date']));  
                                                                        echo $new_addDate;  
                                                                    ?>
                                                                </td>
                                                                <td>
                                                                    <?php
                                                                        if($data['status']!='complete'){
                                                                        ?>
                                                                        <a href="ts_add_ticket.php?id=<?= $data_in['id'] ?>"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;
                                                                    <a href="ts_add_ticket.php?deleteRecord=1&id=<?= $data_in['id']?>&inc_id=<?= $data_in['inc_id']?>">
                                                                        <i class="fa fa-trash"></i></a>
                                                                        <?php
                                                                        }
                                                                        ?>
                                                                </td>
                                                            </tr>
                                                            <?php
                                                        }
                                                    ?>
                                                </tbody>
                                            </table>
                                            <!-- table pagination code -->
                                            <div class="pagination">
                                                <a href="#">&laquo;</a>
                                                <a href="" class="active">1</a>
                                                <a href="" >2</a>
                                                <a href="">3</a>
                                                <a href="">&raquo;</a>
                                        </div>
                                        
                                            <!-- /.table-responsive -->
                                            <!-- /.box-body -->
                                        </div>
                                    </tr>
                                </table>
                            </div>
                            <!-- /.box-footer -->
                        </div>
                        <!-- /.box -->
                    </div>
                    <!-- /.col -->
                </div>
                
                <!-- /.box -->
            </section>
            <!-- /.content -->
        </div>
        <!-- /.content-wrapper -->
        <?php include "include/footer-main.php"; ?>
    </div>

    <!-- jQuery 3 -->
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap 3.3.7 -->
    <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- Select2 -->
    <script src="bower_components/select2/dist/js/select2.full.min.js"></script>
    <!-- InputMask -->
    <script src="plugins/input-mask/jquery.inputmask.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>
    <!-- date-range-picker -->
    <script src="bower_components/moment/min/moment.min.js"></script>
    <script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
    <!-- bootstrap datepicker -->
    <script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
    <!-- bootstrap color picker -->
    <script src="bower_components/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js"></script>
    <!-- bootstrap time picker -->
    <script src="plugins/timepicker/bootstrap-timepicker.min.js"></script>
    <!-- SlimScroll -->
    <script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
    <!-- iCheck 1.0.1 -->
    <script src="plugins/iCheck/icheck.min.js"></script>
    <!-- FastClick -->
    <script src="bower_components/fastclick/lib/fastclick.js"></script>
    <!-- AdminLTE App -->
    <script src="dist/js/adminlte.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="dist/js/demo.js"></script>
    <!-- Page script -->
    <script>
        $(function () {
            //Initialize Select2 Elements
            $('.select2').select2()

            //Datemask dd/mm/yyyy
            /*$('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
            //Datemask2 mm/dd/yyyy
            $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
            //Money Euro
            $('[data-mask]').inputmask()
        
            //Date range picker
            $('#reservation').daterangepicker()
            //Date range picker with time picker
            $('#reservationtime').daterangepicker({ timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A' })
            //Date range as a button
            $('#daterange-btn').daterangepicker(
              {
                ranges   : {
                  'Today'       : [moment(), moment()],
                  'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                  'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
                  'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                  'This Month'  : [moment().startOf('month'), moment().endOf('month')],
                  'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                },
                startDate: moment().subtract(29, 'days'),
                endDate  : moment()
              },
              function (start, end) {
                $('#daterange-btn span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
              }
            )*/

            //Date picker
            $('#datepicker').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                startDate: '-0d',
                Default: true,
                todayHighlight: true
            })
            $('#datepicker1').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                Default: true,
                todayHighlight: true
            })
            //iCheck for checkbox and radio inputs
            $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue'
            })
            //Red color scheme for iCheck
            $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
                checkboxClass: 'icheckbox_minimal-red',
                radioClass: 'iradio_minimal-red'
            })
            //Flat red color scheme for iCheck
            $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
                checkboxClass: 'icheckbox_flat-green',
                radioClass: 'iradio_flat-green'
            })

            //Colorpicker
            $('.my-colorpicker1').colorpicker()
            //color picker with addon
            $('.my-colorpicker2').colorpicker()

            //Timepicker
            $('.timepicker').timepicker({
                showInputs: false
            })
        })
    </script>
</body>

</html>