<?php include 'inc_classes.php'; 
include "admin_authentication.php";
$edit_access='';
$sel_acc="select * from edit_previleges where admin_id='".$_SESSION['admin_id']."' and privilege_id='392'";
$ptr_access=mysql_query($sel_acc);
if(mysql_num_rows($ptr_access))
{
	$edit_access='yes';
}
$staff_task_id=$_GET['id'];
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Ticket Detail</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">
    <!-- 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 status(valid) {
        // alert(valid);
        subject_id = document.getElementById("subject_id").value;
        // alert(subject_id);
        admin_ids = document.getElementById("admin_ids").value;
        var valid_data = "action=subject&status=" + valid + "&subject_id=" + subject_id+ "&admin_id=" + admin_ids;
        $.ajax({
            url: "ts_ticket_ajax.php", type: "post", data: valid_data, cache: false,
            success: function (retvalid) {
                alert("Status Successfully Updated as " + valid);
                setTimeout('document.location.href="ts_ticket_detail.php?id=<?= $staff_task_id ?>";', 200);
            }
        });
    }
</script>
<?php
 function convertToHoursMins($time, $format = '%02d:%02d') {
    if ($time < 1) {
        return;
    }
    $hours = floor($time / 60);
    $minutes = ($time % 60);
    return sprintf($format, $hours, $minutes);
}
?>

<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">
                <div>
                    <!-- <a href="tk_dashboard.php"> Back</a> -->
                    <h2>
                        Details
                    </h2>
                </div>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                    <li class="active">Dashboard</li>
                </ol>
            </section>
            <section class="invoice">
                <div class="box box-default">
                    <div class="row">
                        <div class="col-xs-12">
                            <?php
                            if($_REQUEST['id']!='')
                            {
                                $record_id=$_REQUEST['id'];
                                $task_detail_data="select * from ts_incidence where inc_id='".$record_id."' ";
                                $ptr_detail=mysql_query($task_detail_data);
                                $data=mysql_fetch_array($ptr_detail);
                            }
                            if(isset($_REQUEST['submit']))
                            { 
                                $comment=addslashes($_POST['comment']);
                                $admin_id=$_SESSION['admin_id'];
                            
                                if($comment !="")
                                {
                                    // detail inserting
                                    $insert_comment="insert into ts_details(`inc_id`,`comment`,`staff_id`,`added_date`) values('".$record_id."','".$comment."','".$admin_id."','".date('Y-m-d : H:i:s')."')";
                                    $ptr_comment=mysql_query($insert_comment);  
                                    if ($ptr_comment)
                                    {
                                        ?>
                                        <!-- <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_ticket_detail.php?id=<?= $record_id ?>";', 500);</script>
                                        <?php
                                    }
                                }
                            }
                            ?>
                            <div>
                                <h2 class="page-header"> 
                                <strong>Subject Id : <?php echo $record_id ;?></strong>
                                <span class="dropdown">
                                <?php
                                 if($data['status']!='complete')
                                {
                                ?>
                                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                        <aside class="pull-right"><i class="fa fa-user-plus"></i></aside>
                                    </a>
                                    <?php
                                }
                                ?>
                                    <ul class="dropdown-menu" style="margin-left:650px;width:290px;">
                                        <div class="direct-chat-messages">
                                    <!-- <div class="direct-chat-messages"> -->
                                        <!-- adding direct collabtraters to task -->
                                        <?php
                                            if(isset($_REQUEST['add']))
                                            {
                                                $staff_id=$_POST['staff'];
                                                $admin_id =$_SESSION['admin_id'];
                                                                
                                                $insert_ticket="insert into ts_incidence (`inc_id`,`categary_id`,`subject`,`generation`,`description`,`assign_to`,`status`,`priority`,`admin_id`,`added_date`) values('".$record_id."','".$data['categary_id']."','".$data['subject']."','secondary','".$data['description']."','". $staff_id."','".$data['status']."','".$data['priority']."','".$admin_id."','".date('Y-m-d : H:i:s')."')";
                                                $ptr_ticket=mysql_query($insert_ticket);
                                                ?>
                                                 <script>setTimeout('document.location.href="ts_ticket_detail.php?id=<?= $record_id ?>";', 500);</script>
                                                <?php
                                            }
                                            $task_id1=$_GET['id'];
                                            $staff_id_coll='';
                                                    $sel_staff_id="select assign_to from ts_incidence where inc_id='".$record_id."'";
                                                    $ptr_staff_id=mysql_query($sel_staff_id);
                                                    $tot=mysql_num_rows($ptr_staff_id); 
                                                    $it=1;
                                                    while($fetch_staff_id=mysql_fetch_array($ptr_staff_id))
                                                    {
                                                        if($it==$tot)
                                                        {
                                                            $staff_id_coll .= $fetch_staff_id['assign_to'];
                                                        }
                                                        else{            
                                                            $staff_id_coll .=$fetch_staff_id['assign_to'].',';
                                                            }
                                                        $it++;                                                               
                                                    }
                                                    $sel_staff_id_task="select admin_id from ts_incidence where inc_id='".$record_id."'";
                                                    $ptr_staff_id_task=mysql_query($sel_staff_id_task);
                                                    $tota=mysql_num_rows($ptr_staff_id_task); 
                                                    $ok=1;
                                                    while($fetch_staff_id_task=mysql_fetch_array($ptr_staff_id_task))
                                                    {      
                                                        $staff_id_coll .=','.$fetch_staff_id_task['admin_id'];   
                                                    }
                                                    $sel_staff="select name,photo,admin_id from site_setting where admin_id NOT IN(".$staff_id_coll.") and system_status='Enabled' order by name asc ";
                                                    $ptr_staff_data=mysql_query($sel_staff);
                                                    while($fetch_staff_data=mysql_fetch_array($ptr_staff_data))
                                                    {
                                                        $colla_id = $fetch_staff_data['admin_id'];    
                                                        ?>
                                                        <!-- collabraters adding button -->
                                                        
                                                            <form name="collabraters" method="post">
                                                                <li>
                                                                    <div>
                                                                        <span><input type="submit" name="add" value=""></span>
                                                                        <span><input type="hidden" name="staff" value=<?php echo $colla_id
                                                                                ;?>></span>
                                                                        <span><img src="../faculty_login/staff_photo/<?php echo $fetch_staff_data['photo'];?>" width="20px"; height="20px";></span>
                                                                        <span>
                                                                            <?php if($fetch_staff_data) echo $fetch_staff_data['name']; ?>
                                                                        </span>
                                                                    </div>
                                                                </li>
                                                            </form>
                                                   
                                                        <?php
                                                    }
                                        ?>
                                    </div>
                                    </ul>
                                </span>
                            </h2>
                            </div>
                            <form name="task_form" method="post">
                                <!-- <div class="col-xs-12"> -->
                                    <div style="text-align:center">
                                        <p><strong>Status : <?php echo ucfirst($data['status'])?></strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <?php
                                        if($_SESSION['admin_id']==$data['admin_id'] && $data['generation']=='primary' || $_SESSION['type']=='S')
                                        {
                                        ?>
                                            <span>
                                                <label>In_Progress
                                                    <input type="radio" name="ts_status" value="in_progress"
                                                        onchange="status(this.value)" <?php
                                                        if($_POST['ts_status']=="in_progress" ) echo 'checked="checked"' ;
                                                        else if($data['status']=="in_progress" ) echo 'checked="checked"'; ?> >
                                                </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                <label>Solved
                                                    <input type="radio" name="ts_status" value="solved"
                                                        onchange="status(this.value)" <?php
                                                        if($_POST['ts_status']=="solved" ) echo 'checked="checked"' ;
                                                        else if($data['status']=="solved" )
                                                        echo 'checked="checked"' ; ?> >
                                                </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                <label>Halt
                                                    <input type="radio" name="ts_status" value="halt"
                                                        onchange="status(this.value)" <?php
                                                        if($_POST['ts_status']=="halt" ) echo 'checked="checked"' ;
                                                        else if($data['status']=="halt" ) echo 'checked="checked"'; ?> >
                                                </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                <label>Cancel
                                                    <input type="radio" name="ts_status" value="cancel"
                                                        onchange="status(this.value)" <?php
                                                        if($_POST['ts_status']=="cancel" ) echo 'checked="checked"' ;
                                                        else if($data['status']=="cancel" ) echo 'checked="checked"'; ?> >
                                                </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                <input type="hidden" name="subject_id" id="subject_id"
                                                        value="<?php echo $record_id;?>">
                                                <input type="hidden" name="admin" id="admin_ids"
                                                        value="<?php echo $_SESSION['admin_id'];?>">
                                            </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <?php
                                            }
                                            ?>
                                        </p>
                                    </div>
                                    <h3 style="text-align:center"><span ><?php echo ucwords($data['subject']); ?></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <button type="button" class="btn btn-default" data-toggle="modal"
                                                data-target="#subject">
                                                Members
                                        </button>
                                        <div class="modal fade" id="subject">
                                            <div class="modal-dialog" style="width:400px;">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <h4 class="modal-title">
                                                            <span style="color:blue">
                                                                Subject Assign Members
                                                            </span>
                                                        </h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <!-- body code -->
                                                        <div class="box box-warning">
                                                            <div style="text-align:left">
                                                                <?php
                                                                    $assign="select name from site_setting where 1 and admin_id='".$data['admin_id']."'";
                                                                    $ptr_assign=mysql_query($assign);
                                                                    $assign_data=mysql_fetch_array($ptr_assign);
                                                                    echo '<h3><b>Subject Genrated By - </h3></b>';
                                                                    echo ucwords($assign_data['name']).'<br>';
                                                                    $sel_reason="select assign_to, admin_id from ts_incidence where inc_id='".$record_id."'";
                                                                    $ptr_reason=mysql_query($sel_reason);
                                                                    $no_records=mysql_num_rows($ptr_reason);
                                                                    $i=1;
                                                                    echo '<h3><b>Subject To - </h3></b>';
                                                                        while($data_reason=mysql_fetch_array($ptr_reason))
                                                                        {
                                                                            $add="select name from site_setting where 1 and admin_id='".$data_reason['assign_to']."'";
                                                                            $ptr=mysql_query($add);
                                                                            $data2=mysql_fetch_array($ptr);
                                                                        
                                                                                echo $i++.' . '.ucwords($data2['name']).'<br>';
                                                                        }
                                                                ?>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </h3>
                                    <div style="margin-left:10%;margin-right:10%; background-color:rgb(244,240,236);">
                                        <i class="fa  fa-comments-o"></i> <strong> Chat</strong>
                                        <!-- <li><?php //echo $data['description']?></li> -->
                                        <?php
                                        $sel_task_Details="select * from ts_details where inc_id='".$data['inc_id']."' order by dt_id ASC";
                                        $ptr_data_d=mysql_query($sel_task_Details);     
                                        $records=mysql_num_rows($ptr_data_d);
                                        if($records >= 2)
                                        {
                                            ?>
                                            <div class="direct-chat-messages" style="text-align:left">
                                               
                                                <?php  
                                        }                                         
                                                while( $fetch_details_data=mysql_fetch_array($ptr_data_d))
                                                {
                                                   $staff_name_com="select name,photo from site_setting where 1 and admin_id='".$fetch_details_data['staff_id']."'";
                                                    $ptr_staff_com=mysql_query($staff_name_com);
                                                    $fetch_staff_com=mysql_fetch_array($ptr_staff_com);
                                                    if($fetch_details_data['comment']!='')
                                                    {
                                                        $add_date=date("d-m-Y : H:i",strtotime($fetch_details_data['added_date']));
                                                        if($_SESSION['admin_id']==$fetch_details_data['staff_id'])
                                                        {
                                                            ?>
                                                                <div style="margin-left:40%;">
                                                                    <?php
                                                        }
                                                        else //if($_SESSION['admin_id']!=$fetch_details_data['staff_id'])
                                                        {
                                                            ?>
                                                            <div style="margin-right:40%;">
                                                            <?php
                                                        }
                                                        ?>
                                                            <div>
                                                                <span><img
                                                                        src="../faculty_login/staff_photo/<?php echo $fetch_staff_com['photo'];?>"
                                                                        width="20px" ; height="20px" ;></span>
                                                                <strong>
                                                                    <?php echo ucfirst($fetch_staff_com['name']);?>
                                                                </strong>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">
                                                                    <?php echo $add_date ;?>
                                                                </span>
                                                            </div>
                                                            <div style="margin-left:50px;">
                                                                        <?php echo strip_tags(ucwords($fetch_details_data['comment']));?>
                                                                    </em></li>
                                                            </div>
                                                            </div><br>
                                                        <?php
                                                    }
                                                } 
                                            if($records >= 2)
                                            {
                                            ?>
                                        
                                            </div>
                                            <?php
                                        }
                                        ?>
                                    </div>
                                <!-- </div> -->
                                <br><br>
                                <div class="col-xs-12">
                                    <?php
                                    if($data['status']!='complete')
                                    {
                                        ?>
                                        <div class="form-group">
                                            <textarea class="form-control" name="comment" rows="3" <?php echo
                                                $comment_Err ;?>
                                            placeholder="Ask Quetions or Post Update..."></textarea>
                                        </div>
                                        <div class="form-group">
                                            <input type="submit" name="submit" value="Save Change"
                                                class="btn btn-block btn-success">
                                        </div>
                                        <?php
                                    }
                                    ?>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </section>
        </div>
        <?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 -->
    <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <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 delete_staff(staff_id, tm_id) {
            var staff_data = "action=delete_staff&staff_id=" + staff_id + "&tm_id=" + tm_id;
            // alert(staff_data);
            $.ajax({
                url: "ajax_task.php", type: "post", data: staff_data, cache: false,
                success: function (staffData) {
                    alert(staffData);
                    document.getElementById("st_id" + staff_id).innerHTML = '';
                }
            });
        }
    </script>
    <script>
        $(function () {
            //Initialize Select2 Elements
            $('.select2').select2()


            //Date picker
            $('#datepicker').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                startDate: '-0d',
                Default: true,
                todayHighlight: true
            })
            $('#datepicker1').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                startDate: '-1d',
                endDate: '+0d',
                Default: true,
                todayHighlight: true
            })
            //  $('#datepicker2').datepicker({
            //     autoclose: true,
            //     format: 'dd/mm/yyyy',
            //     Default: true,
            //     todayHighlight: true
            // })
            $('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'
            })
            $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
                checkboxClass: 'icheckbox_flat-green',
                radioClass: 'iradio_flat-yellow'
            })

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

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

</html>