<?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>Add Task</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_me(ids)
   {
        var table1 = document.getElementById("table1");
        var table2 = document.getElementById("table2");
        checkboxes = document.getElementsByName("check_tab1");
        var i;

        for (i = 0; i < checkboxes.length; i++)
        {
            if (checkboxes[i].checked)
            {
                var newRow = table2.insertRow(table2.length);
                cell1 = newRow.insertCell(0);
                cell2 = newRow.insertCell(1);
                cell3 = newRow.insertCell(2);
                cell1.innerHTML = '<input type="hidden" name="team_staff[]" value="' + ids + '">';
                cell2.innerHTML = table1.rows[i + 1].cells[1].innerHTML;
                cell3.innerHTML = table1.rows[i + 1].cells[2].innerHTML;

                var index = table1.rows[i + 1].rowIndex;
                table1.deleteRow(index);
                i--;
            }
        }
    }
</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>
                    Add Task
                    <!--<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 tk_task_managment where tm_id='$record_id'";
                    $ptr_data_3=mysql_query($query);
                    $data=mysql_fetch_array($ptr_data_3);
                }
                else
                {
                    $record_id=''; 
                }

         if(isset($_POST['submit']))
           {
                if (empty($_POST['task_name'])){
                    $task_Err = "Field is required";
                }
                else{
                $task_name=addslashes($_POST['task_name']);
                }
                $proj_id=$_POST['select_project'];
                $team_id=$_POST['select_team'];
                $categary_id=$_POST['select_categary'];
                
                // 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'];
                }
                // if (empty($_POST['due_date'])){
                //     $task_Err = "Field is required";
                // }
                // else{
                $due_date=$_POST['due_date'];
                // }
                $new_date=explode("/",$due_date);
                $due_date_fromat=$new_date[2].''.$new_date[1].''.$new_date[0];
                $admin_id =$_SESSION['admin_id'];
                // task updating
                   if($record_id)
                   { 
                        if($task_name !="" &&  $Priority !="")
                        {
                          $upd_task="update tk_task_managment set `task_name`='".$task_name."', `proj_id`='".$proj_id."',`team_id`='".$team_id."',`categary_id`='".$categary_id."',`priority`='".$Priority."',`description`='".$description."',`updated_admin_id`='".$admin_id."',`cm_id`='".$_SESSION['cm_id']."',`due_date`='".$due_date_fromat."',`updated_date`='".date('Y-m-d : H:i:s')."' where tm_id='".$record_id."' ";
                          $ptr_upd_task=mysql_query($upd_task); 


                          $upd_team_proj="update tk_team_project set `proj_id`='".$proj_id."',`team_id`='".$team_id."',`admin_id`='".$admin_id."',`cm_id`='".$_SESSION['cm_id']."',`added_date`='".date('Y-m-d : H:i:s')."' where tm_id='".$record_id."' ";
                          $ptr_upd_team_proj=mysql_query($upd_team_proj);
                          if ($ptr_upd_team_proj)
                            {
                                ?>
                                <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="tk_add_task.php";', 1000);</script>
                                <?php
                            }       
                        }  
                    }
                    // inserting data
                    else
                   {
                        if($task_name !="" &&   $Priority !=""  )
                        {
                          $insert_task="insert into tk_task_managment (`task_name`,`proj_id`,`team_id`,`categary_id`,`priority`,`description`,`status`,`admin_id`,`cm_id`,`due_date`,`added_date`) values('".$task_name."','".$proj_id."','".$team_id."','".$categary_id."','". $Priority."','".$description."','in_progress','".$admin_id."','".$_SESSION['cm_id']."','".$due_date_fromat."','".date('Y-m-d : H:i:s')."')";
                          $ptr_ins_t=mysql_query($insert_task);
                          $task_id=mysql_insert_id();
                          
                          $insert_team_project="insert into tk_team_project(`proj_id`,`team_id`,`tm_id`,`admin_id`,`cm_id`,`added_date`) values('".$proj_id."','".$team_id."','".$task_id."','".$admin_id."','".$_SESSION['cm_id']."','".date('Y-m-d : H:i:s')."')";
                          $ptr_ins_tp=mysql_query($insert_team_project);  
                          if ($ptr_ins_tp)
                          {
                              ?>
                              <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="tk_add_task.php";', 1000);</script>
                              <?php
                          }
                        }
                    }
            }
            // task  deleting
              if($_REQUEST['deleteRecord']!='' && $_REQUEST['id']!='')
                {
                        $id=$_REQUEST['id'];
                        $delete_task="delete from tk_task_managment where tm_id='".$id."'";   //task delete
                        $ptr_delete_task=mysql_query($delete_task);
                        $delete_task_details="delete from tk_task_details where tm_id='".$id."'";     //task detail delete
                        $ptr_delete_details=mysql_query($delete_task_details);
                        if ($ptr_delete_task)
                        {
                        ?>
                            <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="tk_add_task.php";', 1000);
                                                            // }
                            </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>Project Name </label>
                                        <select class="form-control" id="sel1" placeholder="select"
                                            name="select_project" value="<?=$data['proj_id']?>">
                                            <option>select project</option>
                                            <?php
                                                  $project="select proj_id,proj_name from tk_project";
                                                  $p_query=mysql_query($project);
                                                  while($data_p=mysql_fetch_array($p_query))
                                                  {
                                                    $sel='';
                                                    if($data['proj_id']==$data_p['proj_id'])
                                                    {
                                                      $sel='selected=selected';
                                                    }
                                                      echo '<option '.$sel.' value="'.$data_p['proj_id'].'">'.strip_tags(ucfirst($data_p['proj_name'])). '</option>';
                                                  }
                                                  ?>
                                        </select>
                                        <!-- adding new project button -->
                                        <button type="button" class="btn btn-default" data-toggle="modal"
                                            data-target="#add_project" style="margin-top:25px;"><i
                                                class="fa fa-plus-circle"></i> Add New Project</button>
                                        <?php
                                            if(isset($_REQUEST['submit_project']))
                                            {
                                                if (empty($_POST['project_name'])){
                                                    $project1_Err = "Field is required";
                                                }
                                                else{
                                                $project_name=addslashes($_POST['project_name']);
                                                }
                                                $admin_id =$_SESSION['admin_id'];

                                                if($project_name !="")
                                                {
                                                    $insert_project="insert into tk_project(`proj_name`,`admin_id`,`cm_id`,`added_date`) values('".$project_name."','".$admin_id."','".$_SESSION['cm_id']."','".date('Y-m-d : H:i:s')."')";
                                                    $ptr_ins=mysql_query($insert_project);
                                                    $proj_id=mysql_insert_id();
                                                    if($ptr_ins)
                                                    {
                                                            ?>
                                                <script>
                                                    setTimeout('document.location.href="tk_add_task.php";', 500);
                                                </script>
                                                <?php
                                                    }
                                                }
                                            }
                                        ?>
                                        <div class="modal fade" id="add_project">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <button type="button" class="close" data-dismiss="modal"
                                                            aria-label="Close">
                                                            <span aria-hidden="true">&times;</span></button>
                                                        <h4 class="modal-title"> Add New Project </h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <!-- body code -->
                                                        <div class="box box-default">
                                                            <form name="task_form" method="post">
                                                                <div class="box-body">
                                                                    <div class="row">
                                                                        <div class="col-md-8">
                                                                            <div class="form-group">
                                                                                <label><span style="color:red">*</span>Project Name </label>
                                                                                <input type="text" class="form-control" name="project_name" id="project_name"
                                                                                 value="<?=$data['proj_name']?>"  placeholder="">
                                                                            </div>
                                                                            <div class="form-group">
                                                                                <div class="">
                                                                                    <input type="submit" name="submit_project" value="Submit" class="btn btn-block btn-success">
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label><span style="color:red">*</span>Team Name </label>
                                        <select class="form-control" id="sel1" placeholder="select" name="select_team">
                                            <option>select Team</option>
                                            <?php
                                                $team="select team_id,team_name from tk_team";
                                                $t_query=mysql_query($team);
                                                while($data_t=mysql_fetch_array($t_query))
                                               {
                                                    $sel='';
                                                        if($data['team_id']==$data_t['team_id'])
                                                        {
                                                          $sel='selected=selected';
                                                        }
                                                    echo  '<option '.$sel.' value="'.$data_t['team_id'].'">'.strip_tags(ucfirst($data_t['team_name'])). '</option>';  
                                                }    
                                            ?>
                                        </select>
                                        <!-- adding new team button -->
                                        <button type="button" class="btn btn-default" data-toggle="modal"
                                            data-target="#add_team" style="margin-top:25px;">
                                            <i class="fa fa-users"></i> Add New Team</button>
                                        <?php
                                        if(isset($_REQUEST['submit_team']))
                                            {
                                                if (empty($_POST['team_name'])){
                                                    $team1_Err = "Field is required";
                                                }
                                                else{
                                                    $team_name=addslashes($_POST['team_name']);
                                                }
                                                if (empty($_POST['team_staff']))
                                                {
                                                    $staff1_Err = "Please select collabraters";
                                                }
                                                else{
                                                    $staff_id=$_POST['team_staff'];
                                                }
                                                $admin_id =$_SESSION['admin_id'];
                                                if($team_name !="" && $staff_id !="")
                                                {
                                                    $insert_team="insert into tk_team(`team_name`,`admin_id`,`cm_id`,`added_date`) values('".$team_name."','".$admin_id."','".$_SESSION['cm_id']."','".date('Y-m-d : H:i:s')."')";
                                                    $ptr_ins_team=mysql_query($insert_team);
                                                    $team_id=mysql_insert_id();
                                                    if($ptr_ins_team)
                                                    {
                                                            ?>
                                                        <script>
                                                            setTimeout('document.location.href="tk_add_task.php";', 500);
                                                        </script>
                                                        <?php
                                                    }
                                                    $staff_count=count($staff_id);

                                                    for($i=0;$i<$staff_count;$i++)
                                                    {
                                                        $insert_team_collabraters="insert into tk_team_collabraters(`team_id`,`staff_id`,`admin_id`,`cm_id`,`added_date`) values('".$team_id."','".  $staff_id[$i]."','".$admin_id."','".$_SESSION['cm_id']."','".date('Y-m-d : H:i:s')."')";
                                                        $ptr_ins_collabraters=mysql_query($insert_team_collabraters);  
                                                    }
                                                } 
                                            }  
                                        ?>
                                        <div class="modal fade" id="add_team">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <button type="button" class="close" data-dismiss="modal"
                                                            aria-label="Close">
                                                            <span aria-hidden="true">&times;</span></button>
                                                        <h4 class="modal-title"> Create New Team </h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <!-- body code -->
                                                        <div class="box box-default">
                                                            <form name="task_form" method="post">
                                                                <div class="box-body">
                                                                    <div class="row">
                                                                        <div class="col-md-6">
                                                                            <div class="form-group">
                                                                                <label><span style="color:red">*</span>Team Name &nbsp;&nbsp;
                                                                                    <span style="color:red"> <?php echo $team1_Err ;?></span>
                                                                                </label>
                                                                                <input type="text" class="form-control" name="team_name" id="team_name" placeholder="">
                                                                            </div>
                                                                            <div class="form-group">
                                                                                <label><span style="color:red">*</span>Assigned Collabraters &nbsp;&nbsp;
                                                                                    <span style="color:red"> <?php echo $staff1_Err ;?></span> </label>
                                                                                <div class="direct-chat-messages">
                                                                                <div class="table-responsive">
                                                                                    <table class="table no-margin"
                                                                                        id="table2">
                                                                                        <thead>
                                                                                            <tr>
                                                                                                <th></th>
                                                                                                <th>Staff_name</th>
                                                                                                <th>Photo</th>
                                                                                                <th></th>
                                                                                            </tr>
                                                                                        </thead>
                                                                                    </table>
                                                                                </div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                        <div class="col-md-6">
                                                                            <div>.</div>
                                                                            <div class="form-group">
                                                                            </div>
                                                                            <div class="box-body">
                                                                                <h4 class="box-title"> Collabraters</h4>
                                                                                <div class="direct-chat-messages">
                                                                                    <div class="table-responsive">
                                                                                        <table class="table no-margin"
                                                                                            id="table1" ;>
                                                                                            <thead>
                                                                                                <tr>
                                                                                                    <th></th>
                                                                                                    <th>Staff_name</th>
                                                                                                    <th>Photo</th>
                                                                                                    <th>User_Type</th>
                                                                                                </tr>
                                                                                            </thead>
                                                                                            <tbody>
                                                                                                <?php
                                                                                                    $sel_collabraters="select name,photo,type,admin_id,attendence_id from site_setting order by name asc";
                                                                                                    $ptr_sel_colla=mysql_query($sel_collabraters);
                                                                                                    while( $fetch_data=mysql_fetch_array($ptr_sel_colla))
                                                                                                    {
                                                                                                     echo '<tr><td><input type="checkbox" name="check_tab1" value="'.$fetch_data['admin_id'].'" onclick="select_me('.$fetch_data['admin_id'].');" ></td><td>'.ucfirst($fetch_data['name']).'</td><td><img src='.$fetch_data['photo'].'></td><td>'.$fetch_data['type'].'</td></tr>';
                                                                                                    }
                                                                                                ?>
                                                                                            </tbody>
                                                                                        </table>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                    <div class="form-group">
                                                                        <div class="">
                                                                            <input type="submit" name="submit_team"
                                                                                value="Submit"
                                                                                class="btn btn-block btn-success">
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label><span style="color:red">*</span>Categary Name </label>
                                        <select class="form-control" id="sel1" placeholder="select"
                                            name="select_categary">
                                            <option>select Categary</option>
                                            <?php
                                                    $categary="select categary_id,categary_name from tk_categary";
                                                    $c_query=mysql_query($categary);
                                                    while($data_c=mysql_fetch_array($c_query))
                                                   {
                                                        $sel='';
                                                        if($data['categary_id']==$data_c['categary_id'])
                                                        {
                                                          $sel='selected=selected';
                                                        }
                                                        echo  '<option '.$sel.' value="'.$data_c['categary_id'].'">'.strip_tags(ucfirst($data_c['categary_name'])). '</option>';
                                                    }
                                                ?>
                                        </select>

                                        <!-- adding new categary button-->
                                        <button type="button" class="btn btn-default" data-toggle="modal"
                                            data-target="#add_categary" style="margin-top:25px;">
                                            <i class="fa fa-dot-circle-o"></i> Add New Categ..</button>

                                        <?php
                                            if(isset($_REQUEST['submit_categary']))
                                            {
                                                if (empty($_POST['categary_name'])){
                                                    $cate1_Err = "Field is required";
                                                }
                                                else{
                                                $categary_name=addslashes($_POST['categary_name']);
                                                }
                                                $admin_id =$_SESSION['admin_id'];
                                                if($categary_name !="" ){
                                                        $insert_categary="insert into tk_categary(`categary_name`,`admin_id`,`cm_id`,`added_date`) values('".$categary_name."','".$admin_id."','".$_SESSION['cm_id']."','".date('Y-m-d : H:i:s')."')";
                                                        $ptr_ins_cate=mysql_query($insert_categary);
                                                        $categary_id=mysql_insert_id();
                                                        if($ptr_ins_cate){
                                                            ?>
                                                    <script>
                                                        setTimeout('document.location.href="tk_add_task.php";', 500);
                                                    </script>
                                                    <?php
                                                        }
                                                        }
                                            }
                                        ?>
                                        <div class="modal fade" id="add_categary">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <button type="button" class="close" data-dismiss="modal"
                                                            aria-label="Close">
                                                            <span aria-hidden="true">&times;</span></button>
                                                        <h4 class="modal-title">
                                                            Create New categary
                                                        </h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <!-- body code -->
                                                        <div class="box box-default">
                                                            <form name="task_form" method="post">
                                                                <div class="box-body">
                                                                    <div class="row">
                                                                        <div class="col-md-8">
                                                                            <div class="form-group">
                                                                                <label><span
                                                                                        style="color:red">*</span>Categary Name</label>
                                                                                <input type="text" class="form-control" name="categary_name" id="categary_name" value=""
                                                                                    placeholder="">
                                                                            </div>
                                                                            <div class="form-group">
                                                                                <div class="">
                                                                                    <input type="submit"
                                                                                        name="submit_categary"
                                                                                        value="Submit"
                                                                                        class="btn btn-block btn-success">
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- /.col -->
                                <div class="col-md-5">
                                    <div class="form-group">
                                        <label><span style="color:red">*</span>Task Name &nbsp;&nbsp;<span style="color:red">
                                                <?php echo $task_Err ;?></span></label>
                                        <input type="text" class="form-control" name="task_name" id="task_name"
                                            placeholder="" value="<?=$data['task_name']?>">
                                    </div>
                                    <div class="form-group">
                                        <label>Description</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 class="form-group">
                                        <label>Due Date</label>
                                        <div class="input-group date">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="form-control pull-left" name="due_date"
                                                id="datepicker" value="<?=$data['due_date']?>">
                                        </div>
                                    </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>

                <!-- manage task and task table -->
                <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 Task</h3>
                            </div>
                            <!-- search filter -->
                            <div class="">
                                <form method="post" name="search">
                                    <div class="input-group" style="padding:0% 2% 0% 82%; ">
                                        <input type="text" class="form-control" name="keyword" id="search_project"
                                            value="<?php if($_REQUEST['search']!=" search") echo $_REQUEST['search'];?>"
                                        placeholder="search Task">
                                        <div class="input-group-btn">
                                            <input type="image" src="images/search.jpg" name="search" value="search" style="height:34px;" >
                                        </div>
                                    </div>
                                </form>
                            </div>
                             <!-- end search filter -->
                            <style>
                                th {
                                    text-align: center;
                                }
                            </style>
                            <div class="box-body">
                                <div class="table-responsive">
                                    <table class="table no-margin" style="text-align:center">
                                        <thead>
                                            <tr>
                                                <th>Sr. No.</th>
                                                <th>Project Name</th>
                                                <th>Team Name</th>
                                                <th>Task Name</th>
                                                <th>Description</th>
                                                <th>Priority</th>
                                                <th>Status</th>
                                                <th>Categary</th>
                                                <th>Added Date</th>
                                                <th>Due Date</th>
                                                <th>Added By</th>
                                                <th>Details</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                                $i=1;
                                                if($_REQUEST['keyword']!="keyword")
                                                $search=trim($_REQUEST['keyword']);
                                                if($search)
                                                {
                                                   $task_search=" and (task_name like '%".$search."%' || priority like '%".$search."%' || status like '%".$search."%')";
                                                }
                                                else{
                                                   $task_search="";
                                                }
                                               
                                               $sel_task="select * from tk_task_managment where 1 ".$task_search." order by added_date desc";
                                               $ptr_sel_task=mysql_query($sel_task);
                                               while($data=mysql_fetch_array($ptr_sel_task))
                                               {
                                                    $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);

                                                    $t_data="select team_name from tk_team where team_id='".$data['team_id']."'";
                                                    $ptr_data_t=mysql_query($t_data);
                                                    $team_data=mysql_fetch_array($ptr_data_t);
                                                    // $staff_details_id=$_SESSION['staff_id'];

                                                    $c_data="select categary_name from tk_categary where categary_id='".$data['categary_id']."'";
                                                    $ptr_data_c=mysql_query($c_data);
                                                    $cat_data=mysql_fetch_array($ptr_data_c);

                                                    $add_data="select name from site_setting where 1 and admin_id='".$data['admin_id']."'";
                                                    $ptr_data_a=mysql_query($add_data);
                                                    $data_add=mysql_fetch_array($ptr_data_a);
                                                    ?>
                                                    <tr>
                                                        <td>
                                                            <?php echo $i++ ?>
                                                        </td>
                                                        <td>
                                                            <?php echo strip_tags(ucfirst($proj_data['proj_name']))?>
                                                        </td>
                                                        <td>
                                                            <?php echo strip_tags(ucfirst($team_data['team_name']))?>
                                                        </td>
                                                        <td>
                                                            <?php echo strip_tags(ucwords($data['task_name']))?>
                                                        </td>
                                                        <td>
                                                            <?php echo strip_tags(substr(ucwords($data['description']),0,70))?>...
                                                        </td>
                                                        <td>
                                                            <?php echo ucfirst($data['priority'])?>
                                                        </td>
                                                        <td>
                                                            <?php if($data['status']=='complete') 
                                                                { 
                                                                ?>
                                                                <p class="label label-success"> <?php echo ucfirst($data['status']);?></p>
                                                                <?php
                                                                } 
                                                                if($data['status']=='in_progress') 
                                                                { 
                                                                ?>
                                                                <p class="label label-warning"><?php echo ucfirst($data['status']);?></p>
                                                                <?php
                                                                } 
                                                                if($data['status']=='pending') 
                                                                { 
                                                                    ?>
                                                                    <p class="label label-danger"><?php echo ucfirst($data['status']);?></p>
                                                                    <?php
                                                                } 
                                                            ?>
                                                        </td>
                                                        <td>
                                                            <?php echo strip_tags(ucfirst($cat_data['categary_name']))?>
                                                        </td>
                                                        <td>
                                                            <?php
                                                                $new_addDate = date("d-m-Y", strtotime( $data['added_date']));  
                                                                echo $new_addDate;  
                                                            ?>
                                                        </td>
                                                        <td>
                                                            <?php 
                                                                $new_dueDate = date("d-m-Y", strtotime( $data['due_date']));
                                                                echo $new_dueDate 
                                                            ?>
                                                        </td>
                                                        <td>
                                                            <?php echo ucfirst($data_add['name']);?>
                                                        </td>
                                                        <td>
                                                             <!--task details button -->
                                                            <a href="tk_detail.php?id=<?= $data['tm_id'] ?>" target=""><i class="fa fa-file"></i></a> 
                                                        </td>
                                                        <td>
                                                            <?php
                                                                if($data['status']!='complete'){
                                                                ?>
                                                                <a href="tk_add_task.php?id=<?= $data['tm_id'] ?>"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;
                                                            <a href="tk_add_task.php?deleteRecord=1&id=<?= $data['tm_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>
                                </div>
                                <!-- /.table-responsive -->
                                <!-- /.box-body -->
                            </div>
                            <!-- /.box-footer -->
                        </div>
                        <!-- /.box -->
                    </div>
                    <!-- /.col -->
                </div>
                <!--end manage task and task table -->
                <!-- /.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>