<?php include 'inc_classes.php'; 

include "admin_authentication.php";

//include "include/headHeader.php";

//include "include/functions.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';

// }

?>

<!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>Add Individual 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>


<style>

    .current_pg {

        color: #fcf8f8;

        float: left;

        padding: 8px 16px;

        text-decoration: none;

        border: 1px solid #ddd;

        background-color: #23bd23;

    }



    .disabled_pg {

        color: darkgray;

        float: left;

        padding: 8px 16px;

        text-decoration: none;

        border: 1px solid #ddd;

    }

</style>

<script>
    function select_me(ids, name) {

        var table1 = document.getElementById("table1");

        var table2 = document.getElementById("table2");

        checkboxes = document.getElementsByName("check_tab1");

        var i;

        var staffName = document.getElementById("staffName_" + ids).innerHTML;



        if ($('input[value=' + ids + ']').attr('checked', true)) {

            document.getElementById('table2').innerHTML = document.getElementById('table2').innerHTML + '<tr><input type="hidden" name="staff_ids[]" value="' + ids + '"><td align="center" width="10%">' + staffName + '</td></tr>';

            if (document.getElementById(ids))

                document.getElementById(ids).style.display = "none";

        }
    }

    // function removeSelected(a)

	// {

	// 	//alert(a);

	// 	hide1=a;

	// 	idsn="selected"+hide1;

	// 	$('#'+idsn).remove();

	// }

</script>

<script type="text/javascript">

    function show_types(value) {

        Repeat_type = value.split("-");

        // alert(Repeat_type[0]);

        if (Repeat_type[0] == "weekly") {

            ok = document.getElementById("weakly_type").style.display = 'block';

            document.getElementById("dead_line").style.display = 'block';

            document.getElementById("monthly_type").style.display = 'none';

            document.getElementById("yearly_type").style.display = 'none';

        }

        else if (Repeat_type[0] == "once") {

            document.getElementById("monthly_type").style.display = 'none';

            document.getElementById("dead_line").style.display = 'block';

            document.getElementById("weakly_type").style.display = 'none';

            document.getElementById("yearly_type").style.display = 'none';



        }

        else if (Repeat_type[0] == "monthly") {

            document.getElementById("monthly_type").style.display = 'block';

            document.getElementById("dead_line").style.display = 'block';

            document.getElementById("weakly_type").style.display = 'none';

            document.getElementById("yearly_type").style.display = 'none';



        }

        else if (Repeat_type[0] == "yearly") {

            document.getElementById("weakly_type").style.display = 'none';

            document.getElementById("dead_line").style.display = 'block';

            document.getElementById("monthly_type").style.display = 'none';

            document.getElementById("yearly_type").style.display = 'block';

        }

        else {

            document.getElementById("weakly_type").style.display = 'none';

            document.getElementById("dead_line").style.display = 'block';

            document.getElementById("monthly_type").style.display = 'none';

            document.getElementById("yearly_type").style.display = 'none';

        }

    }

    function show_records(value) {

        Repeat_type = value.split("-");

        // alert(Repeat_type[0]);

        if (Repeat_type[0] == "staff_assign") {

            ok = document.getElementById("staff").style.display = 'block';

            document.getElementById("meetings").style.display = 'none';

            document.getElementById("selfs").style.display = 'none';

        }

        else if (Repeat_type[0] == "meeting") {

            document.getElementById("staff").style.display = 'none';

            document.getElementById("meetings").style.display = 'block';

            document.getElementById("selfs").style.display = 'none';

        }

        else if (Repeat_type[0] == "staff_discussion") {

            document.getElementById("staff").style.display = 'none';

            document.getElementById("meetings").style.display = 'block';

            document.getElementById("selfs").style.display = 'none';

        }

        else if (Repeat_type[0] == "self") {

            document.getElementById("staff").style.display = 'none';

            document.getElementById("meetings").style.display = 'none';

            document.getElementById("selfs").style.display = 'block';

        }

        else if (Repeat_type[0] == "student_discussion") {

            document.getElementById("staff").style.display = 'block';

            document.getElementById("meetings").style.display = 'none';

            document.getElementById("selfs").style.display = 'none';

        }

        else {

            document.getElementById("staff").style.display = 'none';

            document.getElementById("meetings").style.display = 'none';

            document.getElementById("selfs").style.display = 'none';

        }

    }

    function emp_name(emp) {

        // var emp_names=document.getElementById("emp_names").value;

        var employee_data = "action=employee&emp_names=" + emp;

        // alert(emp);

        $.ajax({

            url: "tk_staff_ajax.php", type: "post", data: employee_data, cache: false,

            success: function (retemployee) {

                // alert(retemployee);

                document.getElementById("fetch_emp").innerHTML = retemployee;

            }

        });

    }

    function select_staff(branch) {

        var branch_data = "action=staff&branch_name=" + branch;

        // alert(branch);

        $.ajax({

            url: "tk_staff_ajax.php", type: "post", data: branch_data, cache: false,

            success: function (retstaff) {

                // alert(retstaff);

                document.getElementById("staff_name1").innerHTML = retstaff;

            }

        });

    }

    function select_admin(branch1) {

        var branch_data1 = "action=admin&branch_name1=" + branch1;

        // alert(branch);

        $.ajax({

            url: "tk_staff_ajax.php", type: "post", data: branch_data1, cache: false,

            success: function (retadmin) {

                // alert(retstaff);

                document.getElementById("admin_name").innerHTML = retadmin;



            }

        });

    }

    function show_hours(priority) {

        staff_id = document.getElementById("staff_name1").value;

        var priority_data = "action=hours&priority=" + priority + "&staff_id=" + staff_id;

        // alert(branch);

        $.ajax({

            url: "tk_staff_ajax.php", type: "post", data: priority_data, cache: false,

            success: function (rethours) {

                // alert(rethours);

                document.getElementById("hours").innerHTML = rethours;



            }

        });

    }
    function hours(value) {
        var hour = value.split("-");
        if (hour > 8) {
            alert("Are You Want To Add Task " + hour + " Hours ");
        }
    }

    function show_time(value) {

        time_status = value.split("-");

        // alert(time_status[0]);

        if (time_status[0] == "minute") {

            document.getElementById("minute").style.display = 'block';

            document.getElementById("hour").style.display = 'none';

        }

        else if (time_status[0] == "hour") {

            document.getElementById("minute").style.display = 'none';

            document.getElementById("hour").style.display = 'block';

        }

        else {

            document.getElementById("minute").style.display = 'none';

            document.getElementById("hour").style.display = 'none';

        }

    }

    function repetations_valid(status, id) {
        tasks_id = id;
        var repeat_data = "action=active&repeat_valid=" + status + "&task_id=" + tasks_id;
        $.ajax({

            url: "tk_staff_ajax.php", type: "post", data: repeat_data, cache: false,

            success: function (retrepeat) {

                alert(status + " Successfully");
            }
        });
    }
    
function validation() 
{
    var branch_name = document.getElementById("branch_name");
    var assign_type = document.getElementById("assign_type");
    var staffs_id = document.getElementById("staffs_id");
    var staff_name1 = document.getElementById("staff_name1");
    var task_name = document.getElementById("task_name");
    var desc = document.getElementById("desc");
    var assign_by = document.getElementById("assign_by");
    var priority1 = document.getElementById("priority1");
    var task_hour = parseInt(document.getElementById("task_hour").value, 10) || 0;
    var task_minute = parseInt(document.getElementById("task_minute").value, 10) || 0;
    var totalMinutes = (task_hour * 60) + task_minute;
    var repeat_type = document.getElementById("repeat_type");
    var datepicker = document.getElementById("datepicker");
    var datepicker1 = document.getElementById("datepicker1");
    var datepicker2 = document.getElementById("datepicker2");
    var error = false; 
    var show_error = 'Please Correct The Following Errors:\n';

    var elements = [branch_name, assign_type, staffs_id, staff_name1, task_name, desc, assign_by, priority1, document.getElementById("task_hour"), document.getElementById("task_minute"), repeat_type, datepicker, datepicker1, datepicker2, document.getElementById("table1"), document.getElementById("check1")];
    elements.forEach(function(element) {
        if (element) {
            element.style.border = '';
        }
    });
    if (branch_name.value.trim() === "") {
        error = true;
        show_error += 'Please Select a Branch \n';
        branch_name.style.border = '1px solid red'; 
    }
    if (assign_type.value.trim() === "") {
        error = true;
        show_error += 'Please Select a Task Type \n';
        assign_type.style.border = '1px solid red'; 
    }
    if (assign_type.value === 'self' && staffs_id.value.trim() === "") {
        error = true;
        show_error += 'Please Refresh the Page \n';
        staffs_id.style.border = '1px solid red'; 
    }
    if ((assign_type.value === 'staff_assign' || assign_type.value === 'student_discussion') && staff_name1.value.trim() === "") {
        error = true;
        show_error += 'Please Select the Staff \n';
        staff_name1.style.border = '1px solid red'; 
    }
    if ((assign_type.value === 'meeting' || assign_type.value === 'staff_discussion') && document.querySelectorAll("input[name='staff_ids[]']:checked").length === 0) {
        error = true;
        show_error += 'Please Select at least one Staff \n';
        document.getElementById("table1").style.border = '1px solid red'; 
    }
    if (task_name.value.trim() === "") {
        error = true;
        show_error += 'Please Enter the Task Name\n';
        task_name.style.border = '1px solid red';
    }
    if (desc.value.trim() === "") {
        error = true;
        show_error += 'Please Add a Task Description \n';
        desc.style.border = '1px solid red';
    }
    if (assign_by.value.trim() === "") {
        error = true;
        show_error += 'Please Select the Staff Assigning the Task \n';
        assign_by.style.border = '1px solid red'; 
    }
    if (priority1.value.trim() === "") {
        error = true;
        show_error += 'Please Select the Priority \n';
        priority1.style.border = '1px solid red'; 
    }
    if (totalMinutes === 0) {
        error = true;
        show_error += 'Task Time Should Not Be 0\n';
        document.getElementById("task_hour").style.border = '1px solid red'; 
        document.getElementById("task_minute").style.border = '1px solid red'; 
    }
    if (repeat_type.value.trim() === "") {
        error = true;
        show_error += 'Please Select a Task Repetition Type \n';
        repeat_type.style.border = '1px solid red'; 
    }
    if (datepicker.value.trim() === "") {
        error = true;
        show_error += 'Please Select a Due Date \n';
        datepicker.style.border = '1px solid red'; 
    }
    if (repeat_type.value === 'monthly' && datepicker1.value.trim() === "") {
        error = true;
        show_error += 'Please Select a Task Start Date in the Month \n';
        datepicker1.style.border = '1px solid red'; 
    }
    if (repeat_type.value === 'yearly' && datepicker2.value.trim() === "") {
        error = true;
        show_error += 'Please Select a Task Start Date in the Year \n';
        datepicker2.style.border = '1px solid red'; 
    }
    if (repeat_type.value === 'weekly' && document.querySelectorAll("input[name='days[]']:checked").length === 0) {
        error = true;
        show_error += 'Please Select at least one Day \n';
        document.getElementById("check1").style.border = '1px solid red'; 
    }

    if (error) {
        alert(show_error);
        return false;
    } else {
        return true;
    }
}

</script>

<?php

include "include/ps_pagination.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"; ?>

        <?php include "include/menu_left.php"; ?>

        <div class="content-wrapper">

            <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_individual_task where staff_task_id='$record_id'";

				$ptr_data_3=mysql_query($query);

				$data=mysql_fetch_array($ptr_data_3);

			}

			else

			{

				$record_id=''; 

			}



         	if(isset($_POST['submit']))

           	{
                $branch_name=$_POST['branch_name'];
                $assign_type=$_POST['assign_types'];
                $task_name=addslashes($_POST['task_name']);
                $staff_ids=$_POST['staff_ids'];
                if($assign_type=='self')
                {  
                    $staff_id=trim($_POST['staffs_id']);
                }
                else
                {
                    $staff_id=trim($_POST['staff_name1']);
                }
                $repetation=trim($_POST['repeat_type']);
                $repeat1="select type_id from tk_task_repetation_type where repetation_type='".$repetation."'";
                $ptr_repeat1=mysql_query($repeat1);
                $data_repeat1=mysql_fetch_array($ptr_repeat1);
                $repetation_id=$data_repeat1['type_id'];
                $description=addslashes($_POST['desc']);
                $assign_by=trim($_POST['assign_by']);
                $Priority=$_POST['priority1'];
                $task_hour=$_POST['task_hour'];
                $task_minute=$_POST['task_minute'];
                $tot_min=$task_hour*60;

                $hour= $tot_min+$task_minute;
                $hours=$hour;
                $days=$_POST['days'];
                $repeat_date_m=$_POST['monthly_date'];

                $new_date2=explode("/",$repeat_date_m);

                $repeat_date_month=$new_date2[2].'-'.$new_date2[1].'-'.$new_date2[0];

                $repeat_date_y=$_POST['yearly_date'];

                $new_date1=explode("/",$repeat_date_y);

                $repeat_date_year=$new_date1[2].'-'.$new_date1[1].'-'.$new_date1[0];

                $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'];    

                    if($_SESSION['type']=='S' || $_SESSION['branch_access']=='yes')

					{

                        $sel_branch="select cm_id,admin_id from site_setting where branch_name='".$branch_name."'";

                        $ptr_branch=mysql_query($sel_branch);

                        $data_branch=mysql_fetch_array($ptr_branch);

                        $cm_id=$data_branch['cm_id'];

                        // $Validation="valid";

                        // $validation_admin=$_SESSION['admin_id'];

                    }

                    else

                    {

                        $cm_id=$_SESSION['cm_id'];

                        // $Validation="pending";

                        // $validation_admin="";

                    }

                if($_SESSION['type']=='S' || $edit_access=='yes' && $_SESSION['admin_id']!=$staff_id)

				{

                    $Validation="valid";

                    $validation_admin=trim($_SESSION['admin_id']);

                }

				else

				{

                    $Validation="pending";

                    $validation_admin="";

				}

                if($_POST['added_date']!=''){

                    $ad_date=$_POST['added_date'];

                    $new_dates=explode("/",$ad_date);

                    $added_date=$new_dates[2].'-'.$new_dates[1].'-'.$new_dates[0];

                }

                elseif($record_id){

                    $added_date=$data['added_date'];

                }

                else{

                $added_date=date('Y-m-d : H:i:s');

                }

                if($record_id)

                {

                    if($task_name !=""  &&  $cm_id !="" &&   $Priority !=""  &&   $due_date_fromat !=""   && $description !=""  && $assign_by !=""  && $hours !=0 && $assign_type!="")

                    {

                        $sel_staff_type="select type from site_setting where admin_id='".$staff_id."'";

                        $ptr_staff_type=mysql_query($sel_staff_type);

                        $data_staff_type=mysql_fetch_array($ptr_staff_type);

                        $staff_type=$data_staff_type['type'];

                        if($staff_type=='F'){

                            $points=$hours*0.221;

                        }

                        else{

                            $points=$hours*0.208;

                        }

                        '<br>'.  $upd_task="update tk_individual_task set `task_name`='".$task_name."', `staff_id`='".$staff_id."',`priority`='".$Priority."',`task_minute`='".$task_minute."',`task_hour`='".$task_hour."',`hours`='".$hours."',`points`='".$points."',`description`='".$description."',`assign_by`='".$assign_by."',`cm_id`='".$cm_id."', `repetation_id`='".$repetation_id."', `repeat_date_month`='".$repeat_date_month."', `repeat_date_year`='".$repeat_date_year."',`due_date`='".$due_date_fromat."' ,`added_date`='".$added_date."' where staff_task_id='".$record_id."' ";

                        $ptr_upd_task=mysql_query($upd_task); 

                        $days_count=count($days);

                        if($days_count > 0)

                        {

                            $delete_rec="delete from tk_repetation_days where staff_task_id='".$record_id."'";

                            $ptr_delete_rec=mysql_query($delete_rec);

                            for($i=0;$i<$days_count;$i++)

                            {

                            '<br>'. $insert_days="insert into tk_repetation_days(`staff_task_id`,`repetation_id`,`days`) values('".$record_id."','".$repetation_id."','".$days[$i]."')";

                            $ptr_days=mysql_query($insert_days);

                            }

                        }

                        if($ptr_upd_task)

                        {

                            ?>

                                <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_individual_task.php";', 500);</script>

                            <?php

                        }       

                    }

                }

                else

                {

                        if($task_name !="" && $cm_id !="" &&  $Priority !=""  &&   $due_date_fromat !=""  && $description !=""  && $assign_by !=""  &&  $assign_type!="" && $hours!=0)

                        {

                            $ref_id=rand(100000,999999);

                            if($assign_type=='staff_discussion' || $assign_type=='meeting'  &&   $staff_ids !="")

                            {

                                $staff_count=count($staff_ids);

                                // if($days!=0){

                                if($repetation_id=='3')

                                {

                                    $days_count=intval(count($days));

                                    for($j=0;$j<$staff_count;$j++)

                                    {

                                        $sel_staff_type="select type from site_setting where admin_id='".$staff_ids[$i]."'";

                                        $ptr_staff_type=mysql_query($sel_staff_type);

                                        $data_staff_type=mysql_fetch_array($ptr_staff_type);

                                        $staff_type=$data_staff_type['type'];

                                        if($staff_type=='F'){

                                            $points=$hours*0.221;

                                        }

                                        else{

                                            $points=$hours*0.208;

                                        }

                                        $insert_task="insert into tk_individual_task(`task_type`,`ref_id`,`task_name`,`assign_type`,`staff_id`,`description`,`assign_by`,`priority`,`task_minute`,`task_hour`,`hours`,`points`,`due_date`,`date`,`deadline_count`,`Validation`,`validation_admin`,`status`,`repetation_id`,`repetation_valid`,`repeat_date_month`,`repeat_date_year`,`cm_id`,`admin_id`,`added_date`) values('adhoc_task','".$ref_id."','".$task_name."','".$assign_type."','".$staff_ids[$j]."','".$description."','".$assign_by."','".$Priority."','".$task_minute."','".$task_hour."','". $hours."','". $points."','".$due_date_fromat."','".$added_date."','1','".$Validation."','".$validation_admin."','in_progress','".$repetation_id."','active','".$repeat_date_month."','".$repeat_date_year."','".$cm_id."','".$admin_id."','".$added_date."')";

                                        $ptr_ins_t=mysql_query($insert_task);

                                        $task_ids=mysql_insert_id(); 

                                        $task_details="insert into individual_task_details(`staff_task_id`,`admin_id`,`cm_id`,`added_date`) values('".$task_ids."','".$admin_id."','".$_SESSION['cm_id']."','".$added_date."')";

                                        $ptr_data=mysql_query($task_details); 



                                        for($i=0;$i<$days_count;$i++)

                                        {

                                            $insert_days="insert into tk_repetation_days(`staff_task_id`,`repetation_id`,`days`) values('".$task_ids."','".$repetation_id."','".$days[$i]."')";

                                            $ptr_days=mysql_query($insert_days);

                                        }

                                    }                                           

                                }

                                else

                                {

                                    //echo "<br/>No Weekly repeatation ";

                                    for($i=0;$i<$staff_count;$i++)

                                    {

                                        $sel_staff_type="select type from site_setting where admin_id='".$staff_ids[$i]."'";

                                        $ptr_staff_type=mysql_query($sel_staff_type);

                                        $data_staff_type=mysql_fetch_array($ptr_staff_type);

                                        $staff_type=$data_staff_type['type'];

                                        if($staff_type=='F'){

                                            $points=$hours*0.221;

                                        }

                                        else{

                                            $points=$hours*0.208;

                                        }

                                        '<br>'.$insert_task="insert into tk_individual_task(`task_type`,`ref_id`,`task_name`,`assign_type`,`staff_id`,`description`,`assign_by`,`priority`,`task_minute`,`task_hour`,`hours`,`points`,`due_date`,`date`,`deadline_count`,`Validation`,`validation_admin`,`status`,`repetation_id`,`repetation_valid`,`repeat_date_month`,`repeat_date_year`,`cm_id`,`admin_id`,`added_date`) values('adhoc_task','".$ref_id."','".$task_name."','".$assign_type."','".$staff_ids[$i]."','".$description."','".$assign_by."','".$Priority."','".$task_minute."','".$task_hour."','". $hours."','". $points."','".$due_date_fromat."','".$added_date."','1','".$Validation."','".$validation_admin."','in_progress','".$repetation_id."','active','".$repeat_date_month."','".$repeat_date_year."','".$cm_id."','".$admin_id."','".$added_date."')";

                                        $ptr_ins_t=mysql_query($insert_task);

                                        $task_ids=mysql_insert_id(); 

                                        $task_details="insert into individual_task_details(`staff_task_id`,`admin_id`,`cm_id`,`added_date`) values('".$task_ids."','".$admin_id."','".$_SESSION['cm_id']."','".$added_date."')";

                                        $ptr_data=mysql_query($task_details); 

                                    }

                                }

                            }

                            else

                            {

                                $sel_staff_type="select type from site_setting where admin_id='".$staff_id."'";

                                $ptr_staff_type=mysql_query($sel_staff_type);

                                $data_staff_type=mysql_fetch_array($ptr_staff_type);

                                $staff_type=$data_staff_type['type'];

                                if($staff_type=='F'){

                                    $points=$hours*0.221;

                                }

                                else{

                                    $points=$hours*0.208;

                                }

                                '<br>'.$insert_tasks="insert into tk_individual_task(`task_type`,`ref_id`,`task_name`,`assign_type`,`staff_id`,`description`,`assign_by`,`priority`,`task_minute`,`task_hour`,`hours`,`points`,`due_date`,`date`,`deadline_count`,`Validation`,`validation_admin`,`status`,`repetation_id`,`repetation_valid`,`repeat_date_month`,`repeat_date_year`,`cm_id`,`admin_id`,`added_date`) values('adhoc_task','".$ref_id."','".$task_name."','".$assign_type."','".$staff_id."','".$description."','".$assign_by."','".$Priority."','".$task_minute."','".$task_hour."','". $hours."','". $points."','".$due_date_fromat."','".$added_date."','1','".$Validation."','".$validation_admin."','in_progress','".$repetation_id."','active','".$repeat_date_month."','".$repeat_date_year."','".$cm_id."','".$admin_id."','".$added_date."')";

                                $ptr_ins_t=mysql_query($insert_tasks);

                                $task_id=mysql_insert_id(); 

                                $task_details="insert into individual_task_details(`staff_task_id`,`admin_id`,`cm_id`,`added_date`) values('".$task_id."','".$admin_id."','".$_SESSION['cm_id']."','".date('Y-m-d : H:i:s')."')";

                                $ptr_data=mysql_query($task_details); 

                                if($days!='')

                                {

                                    $days_count=count($days);

                                    for($i=0;$i<$days_count;$i++)

                                    {

                                        $insert_days="insert into tk_repetation_days(`staff_task_id`,`repetation_id`,`days`) values('".$task_id."','".$repetation_id."','".$days[$i]."')";

                                        $ptr_days=mysql_query($insert_days);

                                    }

                                }

                            }

                        }

                        //   if($task_id !="")

                        //   {

                        //       // detail inserting

                        //      $task_details="insert into individual_task_details(`staff_task_id`,`admin_id`,`cm_id`,`added_date`) values('".$task_id."','".$admin_id."','".$_SESSION['cm_id']."','".date('Y-m-d : H:i:s')."')";

                        //       $ptr_data=mysql_query($task_details); 

                        //   } 

                        //   $days_count=count($days);

						// 	for($i=0;$i<$days_count;$i++)

						// 		{

                        //         $insert_days="insert into tk_repetation_days(`staff_task_id`,`repetation_id`,`days`) values('".$task_id."','".$repetation_id."','".$days[$i]."')";

                        //         $ptr_days=mysql_query($insert_days);

                        //             }

                            // if($emp_id!=$staff_id){

                            // $insert_id="insert into tk_employee_total_performance(`staff_id`) values('".$staff_id."')";

                            // $ptr_id=mysql_query($insert_id);

                            //         }

                          if ($ptr_ins_t)

                            {

                                ?>

                                    <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_individual_task.php";', 500);</script>

                                <?php

                            }

                }

            }

            // }

            // task  deleting

              if($_REQUEST['deleteRecord']!='' && $_REQUEST['id']!='')

                {

                    $id=$_REQUEST['id'];

                    $delete_task="delete from tk_individual_task where staff_task_id='".$id."'";   //task delete

                    $ptr_delete_task=mysql_query($delete_task);

                    $delete_task_details="delete from individual_task_details where staff_task_id='".$id."'";     //task detail delete

                    $ptr_delete_details=mysql_query($delete_task_details);

                    $delete_task_days="delete from tk_repetation_days where staff_task_id='".$id."'";     //task repetation days delete

                    $ptr_delete_days=mysql_query($delete_task_days);

                    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_individual_task.php";', 500);

                                                                            // }

                            </script>

                        <?php

                        }

                }

            ?>

            <!-- Main content -->

            <section class="content">

                <!-- SELECT2 EXAMPLE -->

                <div class="box box-default">

                    <div class="box-body">

                        <form method="POST" id="jqueryForm" name="jqueryForm" enctype="multipart/form-data" onsubmit="return validation()">

                            <div class="row">

                                <div class="col-md-5">

                                    <p style="color:red"> * Required Field</p>

                                        <?php

                                            $task_hours="select sum(hours)as task_hour from tk_individual_task where 1 and Validation!='in_valid' and staff_id='".$_SESSION['admin_id']."'and DATE(date)='".date("Y-m-d")."' order by added_date DESC";

                                            $ptr_task_hours=mysql_query($task_hours);

                                            $data_hour=mysql_fetch_array($ptr_task_hours);

                                            $task_time=$data_hour['task_hour'];

                                            $tot_hours= convertToHoursMins($task_time, '%02d hour %02d min');

                                        ?>

                                    <p class="text-muted well well-sm no-shadow" style="margin-top: 10px;">

                                        <?php echo 'My Todays Total Task Assign Hours <b>'. $tot_hours.'</b>'; ?>

                                    </p>

                                    <?php
                                        if ($_SESSION['type'] == 'S' || $_SESSION['branch_access'] == 'yes') {
                                        ?>
                                            <label><span style="color:red">*</span> Branch Name </label>
                                            <div class="form-group">
                                                <select class="form-control" style="width:200px" name="branch_name" id="branch_name" onchange="select_staff(this.value)">
                                                    <option value="">Select Branch</option>
                                                    <?php
                                                    $sel_branch = "SELECT * FROM branch WHERE 1 ORDER BY branch_id ASC";
                                                    $query_branch = mysql_query($sel_branch);
                                                    while ($row_branch = mysql_fetch_array($query_branch)) {
                                                        $selected = '';
                                                        if ($_POST['branch_name'] == $row_branch['branch_name']) {
                                                            $selected = 'selected="selected"';
                                                        }
                                                        $selected_branch = "SELECT branch_name FROM site_setting WHERE cm_id = '".$data['cm_id']."' AND type = 'A'";
                                                        $ptr_selected = mysql_query($selected_branch);
                                                        if (mysql_num_rows($ptr_selected)) {
                                                            $data_cm_id = mysql_fetch_array($ptr_selected);
                                                            if ($data_cm_id['branch_name'] == $row_branch['branch_name']) {
                                                                $selected = 'selected="selected"';
                                                            }
                                                        }
                                                        ?>
                                                        <option <?php echo $selected; ?> value="<?php echo $row_branch['branch_name']; ?>">
                                                            <?php echo $row_branch['branch_name']; ?>
                                                        </option>
                                                        <?php
                                                    }
                                                    ?>
                                                </select>
                                            </div>
                                        <?php
                                        } else {
                                        ?>
                                            <input type="hidden" name="branch_name" id="branch_name" value="<?php echo $_SESSION['branch_name']; ?>" />
                                        <?php
                                        }
                                    ?>

                                    <div class="form-group">

                                        <div>

                                            <label><span style="color:red">*</span>Task Type &nbsp;&nbsp;
                                                </span></label>

                                        </div>

                                        <select class="form-control" style="width:200px;" name="assign_types"

                                            id="assign_type" onChange="show_records(this.value)">

                                            <option value="">Select </option>

                                            <option value="self" <? if ($_POST['assign_type']=="self" )

                                                echo "selected='selected'" ; else if($data['assign_type']=="self" )

                                                echo "selected='selected'" ;?>>Self</option>

                                            <option value="staff_assign" <? if ($_POST['assign_type']=="staff_assign" )

                                                echo "selected='selected'" ; else

                                                if($data['assign_type']=="staff_assign" ) echo "selected='selected'" ;?>

                                                >Staff Assign</option>

                                            <option value="meeting" <? if ($_POST['assign_type']=="meeting" )

                                                echo "selected='selected'" ; else if($data['assign_type']=="meeting" )

                                                echo "selected='selected'" ;?>>Meeting</option>

                                            <option value="staff_discussion" <? if

                                                ($_POST['assign_type']=="staff_discussion" ) echo "selected='selected'"

                                                ; else if($data['assign_type']=="staff_discussion" )

                                                echo "selected='selected'" ;?>>Staff Discussion</option>

                                            <option value="student_discussion" <?php if

                                                ($_POST['assign_type']=="student_discussion" )

                                                echo "selected='selected'" ; else

                                                if($data['assign_type']=="student_discussion" )

                                                echo "selected='selected'" ;?>>Student Discussion</option>

                                        </select>

                                    </div>

                                    <div class="form-group" id="selfs" <?php if($data['assign_type']=='self' )

                                        echo 'style="display:block"' ;else echo 'style="display:none"' ;?> >

                                        <?php

                                        if($record_id)

                                        {

                                            $staff_idss=$data['staff_id'];

                                        }

                                        else{

                                            $staff_idss=$_SESSION['admin_id'];   

                                        }

                                        $sel_my_name="select admin_id,name from site_setting where 1 and system_status='Enabled' and admin_id='".$staff_idss."' ";

                                        $ptr_my_name=mysql_query($sel_my_name);

                                        $data_my_name=mysql_fetch_array($ptr_my_name);

                                        ?>

                                        <input type="text" name="" id="" readonly="readonly"

                                            value="<?php echo  $data_my_name['name'] ?>" <?php echo

                                            $data_my_name['name']?> />

                                        <input type="hidden" name="staffs_id" id="staffs_id"

                                            value="<?php echo  $staff_idss ?>" />

                                    </div>

                                    <div class="form-group" id="staff" <?php if($data['assign_type']=='staff_assign'

                                        ||$data['assign_type']=='student_discussion' ) echo 'style="display:block"'

                                        ;else echo 'style="display:none"' ;?> >

                                        <label><span style="color:red">*</span>Select Staff &nbsp;&nbsp;</label>

                                        <?php

                                            if($record_id)

                                            {

                                                ?>

                                                <div>

                                                    <select class="form-control" style="width:200px" name="staff_name1"

                                                        id="staff_name1">

                                                        <option value="">Select Staff</option>

                                                        <?php

                                                $sel_staff1="select admin_id,name from site_setting where cm_id='".$data['cm_id']."' and system_status='Enabled' order by name ASC";

                                                $c_query=mysql_query($sel_staff1);

                                                while($data_c=mysql_fetch_array($c_query))

                                            {

                                                    $sel='';

                                                    if($data['staff_id']==$data_c['admin_id'])

                                                    {

                                                    $sel='selected=selected';

                                                    }

                                                    ?>

                                                        <option <?php echo $sel;?> value="

                                                            <?php echo $data_c['admin_id'] ;?>">

                                                            <?php echo ucfirst($data_c['name']);?>

                                                        </option>

                                                        <?php

                                                }

                                                ?>

                                                    </select>

                                                </div>

                                                <?php

                                            }

                                            else

                                            {

                                                ?>

                                                    <div>

                                                        <select class="form-control " style="width:200px" name="staff_name1"

                                                            id="staff_name1">

                                                            <option value="">Select Staff</option>

                                                        </select>

                                                    </div>

                                                <?php

                                            }

                                        ?>

                                    </div>

                                    <div class="row" style="text-align:center;display:none" id="meetings">

                                        <div class="col-md-5">

                                            <label><span style="color:red">*</span>Select Staff &nbsp;&nbsp;</label><br>

                                            <div class="direct-chat-messages">

                                                <div class="table-responsive form-group">

                                                    <table class="table no-margin" style="text-align:left" id="table2">

                                                        <tr>

                                                            <td></td>

                                                        </tr>

                                                    </table>

                                                </div>

                                            </div>

                                        </div>

                                        <div class="col-md-7">

                                            <input type="text" class="form-control" style="width:150px" name="emp_names"

                                                id="emp_names" placeholder="Search Employee " value=""

                                                onkeydown="emp_name(this.value)" style="margin-left:50%" />

                                            <div class="direct-chat-messages">

                                                <div class="table-responsive form-group" id="fetch_emp">

                                                    <table class="table no-margin" style="text-align:left" id="table1">

                                                        <?php

                                                        $team_name_update="select name,admin_id from site_setting where 1 and system_status='Enabled' order by name ASC ";

                                                        $ptr_team_name_update=mysql_query($team_name_update);

                                                        while($update_data=mysql_fetch_array($ptr_team_name_update))

                                                        {

                                                        

                                                           echo "<tr id=".$update_data['admin_id']."><td><input type='checkbox' id='check_tab_".$update_data['admin_id']."' name='check_tab1' value='".$update_data['admin_id']."' onclick='select_me(".$update_data['admin_id'].");'></td><td id='staffName_".$update_data['admin_id']."'>".ucfirst($update_data['name'])."</td></tr>";

                                                        }

                                                    ?>

                                                    </table>

                                                </div>

                                            </div>

                                        </div>

                                    </div>

                                    <div class="form-group">

                                        <label><span style="color:red">*</span> Enter Task Name &nbsp;&nbsp;</label>
                                        <input type="text" class="form-control" style="width:200px" name="task_name"
                                            id="task_name" placeholder="Task Name" value="<?=$data['task_name']?>">
                                    </div>
                                    <div class="form-group">

                                        <label><span style="color:red">*</span>Description &nbsp;&nbsp;</label>
                                            <textarea class="form-control" name="desc" id="desc" rows="3" placeholder="Enter ..."><?php echo $data['description']; ?></textarea>
                                    </div>

                                </div>

                                <div class="col-md-5">

                                    <div class="form-group">

                                        <label><span style="color:red">*</span>Assign By &nbsp;&nbsp;</label>

                                        <div>

                                            <select class="form-control " style="width:250px" name="assign_by"

                                                id="assign_by">

                                                <option value="">Select Staff</option>

                                                <?php

                                                    $sel_staff1="select admin_id,name from site_setting where 1 and system_status='Enabled' order by name DESC";

                                                    $c_query=mysql_query($sel_staff1);

                                                    while($data_c=mysql_fetch_array($c_query))

                                                    {

                                                        $sel='';

                                                        if($record_id)

                                                        {

                                                            if($data['assign_by']==$data_c['admin_id'])

                                                            {

                                                                $sel='selected=selected';

                                                            }

                                                        }

                                                        else 

                                                        {

                                                            if($_SESSION['admin_id']==$data_c['admin_id'])

                                                            {

                                                                $sel='selected=selected';

                                                            }

                                                        }

                                                        ?>

                                                            <option <?php echo $sel;?> value="

                                                                <?php echo $data_c['admin_id'] ;?>">

                                                                <?php echo ucfirst($data_c['name']);?>

                                                            </option>

                                                            <?php

                                                    }

                                                ?>

                                            </select>

                                        </div>

                                    </div>

                                    <div class="form-group">

                                        <div>

                                            <label><span style="color:red">*</span>Priority &nbsp;&nbsp;
                                            </label>

                                        </div>

                                        <select class="form-control" style="width:250px;" name="priority1"

                                            id="priority1" onChange="show_hours(this.value)">

                                            <!-- <option value=""> Select </option> -->

                                            <option value="medium" <?php if ($_POST['priority1']=="medium" )

                                                echo "selected='selected'" ; else if($data['priority']=="medium" )

                                                echo "selected='selected'" ;?>>Medium </option>

                                            <option value="low" <? if ($_POST['priority1']=="low" )

                                                echo "selected='selected'" ; else if($data['priority']=="low" )

                                                echo "selected='selected'" ;?>>Low </option>

                                            <option value="high" <? if ($_POST['priority1']=="high" )

                                                echo "selected='selected'" ; else if($data['priority']=="high" )

                                                echo "selected='selected'" ;?>>High </option>

                                        </select>

                                    </div>

                                    <div class="form-group">

                                        <label><span style="color:red">*</span>Task Time &nbsp;&nbsp;</label>
                                        <div class="row ">

                                            <div class="col-md-3">

                                            <label>Minute : </label>

                                                <select class="form-control " style="width:100px;"

                                                    name="task_minute" id="task_minute">

                                                    <option>Minute</option>

                                                    <?php

                                                for($i=0;$i<=60;$i++){

                                                    $sel='';

                                                    if($i==$data['task_minute']){

                                                        $sel='selected=selected';

                                                    }

                                                    echo '<option '.$sel.'>'.$i.'</option>';

                                                }

                                                ?>

                                                </select>

                                            </div>&nbsp;&nbsp;

                                            <div class="col-md-3">

                                            <label> Hour : </label>&nbsp;&nbsp;&nbsp;&nbsp;

                                                <select class="form-control " style="width:100px;"

                                                    name="task_hour" id="task_hour" onChange="hours(this.value)">

                                                    <option>Hour</option>

                                                    <?php

                                                for($j=0;$j<=12;$j++){

                                                    $sel='';

                                                    if($j==$data['task_hour']){

                                                        $sel='selected=selected';

                                                    }

                                                    echo '<option '.$sel.'>'.$j.'</option>';

                                                }

                                                ?>

                                                </select>

                                                <!-- <input type="text" class="form-control" style="width:100px" name="task_hour" id="task_hour"

                                            placeholder="Hour" value="<?=$data['task_hour']?>"> -->

                                            </div>

                                        </div>

                                    </div>

                                    <div class="form-group">

                                        <div>
                                            <label><span style="color:red">*</span>Repetation &nbsp;&nbsp;</label>
                                        </div>

                                        <select class="form-control" style="width:250px;" name="repeat_type"

                                            id="repeat_type" onChange="show_types(this.value)">

                                            <!-- <option value="">Select </option> -->

                                            <?php

                                                    $repeat="select type_id,repetation_type from tk_task_repetation_type order by type_id ASC";

                                                    $ptr_repeat=mysql_query($repeat);

                                                    while($data_repeat=mysql_fetch_array($ptr_repeat))

                                                   {

                                                        $sel='';

                                                        if($data['repetation_id']==$data_repeat['type_id'])

                                                        {

                                                          $sel='selected=selected';

                                                        }

                                                        echo  '<option '.$sel.' value="'.$data_repeat['repetation_type'].'">'.strip_tags(ucfirst($data_repeat['repetation_type'])). '</option>';

                                                    }

                                                ?>

                                        </select>

                                    </div>

                                    <div id="weakly_type" <?php if($data['repetation_id']==3)

                                        echo 'style="display:block"' ;else echo 'style="display:none"' ;?>>

                                        <label><span style="color:red">*</span>Select Days</label>

                                        <div class="checkbox" id="check1" >

                                            <?php

                                            $sel_day="select days from tk_days ";

                                            $ptr_days=mysql_query($sel_day);

                                           while($data_day=mysql_fetch_array($ptr_days)){

                                               $sel='';

                                               if($record_id){

                                                 $task_day="select * from tk_repetation_days where staff_task_id='".$data['staff_task_id']."' and days='".$data_day['days']."'";

                                                    $ptr_task_days=mysql_query($task_day);

                                                    if(mysql_num_rows($ptr_task_days))

                                                    {

                                                        $sel='checked="checked"';

                                                    }

                                                }

                                                ?>
                                                <label >
                                                    <input type="checkbox" <?php echo $sel; ?>  value="<?php echo $data_day['days']; ?>" name="days[]">
                                                    <b style="color: <?php echo ($data_day['days'] == 'Sun') ? 'red' : 'blue'; ?>">
                                                        <?php echo $data_day['days']; ?>
                                                    </b>
                                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                            <?php   

                                           }

                                            ?>

                                        </div>

                                    </div>

                                    <div id="monthly_type" <?php if($data['repetation_id']==4)

                                        echo 'style="display:block"' ;else echo 'style="display:none"' ;?>>

                                        <div class="form-group">

                                            <label><span style="color:red">*</span>Create 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" readonly="readonly"

                                                    name="monthly_date" id="datepicker1" value="<?php if($_POST['monthly_date']) echo $_POST['monthly_date']; else {

                                                    if($data['repeat_date_month'] !='')

                                                    {

                                                        $arrage_date1= explode('-',$data['repeat_date_month'],3);     

                                                        echo $arrage_date1[2].'/'.$arrage_date1[1].'/'.$arrage_date1[0]; 

                                                    }

									                }?>">

                                            </div>

                                        </div>

                                    </div>

                                    <div id="yearly_type" <?php if($data['repetation_id']==5)

                                        echo 'style="display:block"' ;else echo 'style="display:none"' ;?>>

                                        <div class="form-group">

                                            <label><span style="color:red">*</span>Create 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" readonly="readonly"

                                                    name="yearly_date" id="datepicker2" value="<?php if($_POST['yearly_date']) echo $_POST['yearly_date']; else {

                                                    if($data['repeat_date_year'] !='')

                                                    {

                                                        $arrage_date2= explode('-',$data['repeat_date_year'],3);     

                                                        echo $arrage_date2[2].'/'.$arrage_date2[1].'/'.$arrage_date2[0]; 

                                                    }

									            }?>">

                                            </div>

                                        </div>

                                    </div>

                                    <div id="dead_line" <?php if($data['repetation_id']=='1' ||

                                        $data['repetation_id']=='2' || $data['repetation_id']=='3' ||

                                        $data['repetation_id']=='4' || $data['repetation_id']=='5' )

                                        echo 'style="display:block"' ;else echo 'style="display:block"' ;?>>

                                        <div class="form-group">

                                            <!-- <label>Dead Line</label> -->

                                            <div>

                                                <label><span style="color:red">*</span>Dead Line &nbsp;&nbsp;</label>

                                            </div>

                                            <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" readonly="readonly"

                                                    name="due_date" id="datepicker" value="<?php if($_POST['due_date']) echo $_POST['due_date']; else {

                                                        if($data['due_date'] !='')

                                                        {

                                                            $due_dates=DATE($data['due_date']);

                                                            $expl_date=explode(' ',$due_dates);

                                                            $arrage_date= explode('-',$expl_date[0],3);     

                                                            echo $due1=$arrage_date[2].'/'.$arrage_date[1].'/'.$arrage_date[0]; 

                                                            //  echo DATE($due1);

                                                        }

                                                    }?>" />

                                            </div>

                                        </div>

                                        <?php

                                         if($_SESSION['type']=='S' || $edit_access=='yes')

                                        {

                                            ?>

                                            <div class="form-group">
                                                <div>

                                                    <label>Added Date </label>

                                                </div>

                                                <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" readonly="readonly"

                                                        name="added_date" id="datepicker12" value="<?php 

                                                        if($data['added_date'] !='')

                                                        {

                                                            $added_date=DATE($data['added_date']);

                                                            $expl_dates=explode(' ',$added_date);

                                                            $arrages_date= explode('-',$expl_dates[0],3);     

                                                            echo $add_date=$arrages_date[2].'/'.$arrages_date[1].'/'.$arrages_date[0]; 

                                                            //  echo DATE($due1);

                                                        }

                                                        else{

                                                            echo date('d/m/Y');

                                                        }

                                                    ?>" />

                                                </div>

                                            </div>

                                            <?php 

                                        }

                                        ?>

                                    </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=""> -->

                            <div class="table-responsive">
                                <form method="get" name="search">
                                    <table class="table table-bordered table-responsive">
                                        <tr>
                                            <td>
                                                <?php if ($_SESSION['type'] == 'S' || $_SESSION['branch_access'] == 'yes') { ?>
                                                    <select class="form-control select2" id="branch_name1" name="branch_name1" onchange="select_admin(this.value);">
                                                        <option value="">Select Branch</option>
                                                        <?php 
                                                        $sel_branch = "SELECT branch_id, branch_name FROM branch";
                                                        $ptr_sel = mysql_query($sel_branch);
                                                        while ($data_branch = mysql_fetch_array($ptr_sel)) {
                                                            $sel = ($data_branch['branch_name'] == $_GET['branch_name1']) ? 'selected="selected"' : '';
                                                            echo '<option ' . $sel . ' value="' . $data_branch['branch_name'] . '">' . $data_branch['branch_name'] . '</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                <?php } else { ?>
                                                    <input type="hidden" name="branch_name1" id="branch_name1" value="<?php echo $_SESSION['branch_name']; ?>" />
                                                <?php } ?>
                                            </td>
                                            <td>
                                                <?php if ($_REQUEST['admin_name'] != '') {
                                                    $sel_staffs = "SELECT admin_id, name FROM site_setting WHERE branch_name='" . $_GET['branch_name1'] . "' AND system_status='Enabled'";
                                                    $ptr_que = mysql_query($sel_staffs);
                                                ?>
                                                    <select class="form-control select2" id="admin_names1" name="admin_name">
                                                        <option value="">Assigned To</option>
                                                        <?php
                                                        while ($data_query = mysql_fetch_array($ptr_que)) {
                                                            $sel = ($data_query['admin_id'] == $_GET['admin_name']) ? 'selected="selected"' : '';
                                                            echo '<option ' . $sel . ' value="' . $data_query['admin_id'] . '">' . $data_query['name'] . '</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                <?php } else { ?>
                                                    <select class="form-control select2" id="admin_name" name="admin_name">
                                                        <option value="">Assigned To</option>
                                                    </select>
                                                <?php } ?>
                                            </td>
                                            <?php if ($_SESSION['type'] == 'S' || $edit_access == 'yes' || $manager_access == 'manager' || $_SESSION['branch_access'] == 'yes') { ?>
                                                <td>
                                                    <select class="form-control select2" id="staff_names" name="staff_names">
                                                        <option value="">Assigned By</option>
                                                        <?php
                                                        $categary = "SELECT admin_id, name FROM site_setting WHERE system_status='Enabled' ORDER BY name ASC";   
                                                        $c_query = mysql_query($categary);
                                                        while ($data_c = mysql_fetch_array($c_query)) {
                                                            $sel = ($data_c['admin_id'] == $_GET['staff_names']) ? 'selected="selected"' : '';
                                                            echo '<option ' . $sel . ' value="' . $data_c['admin_id'] . '">' . ucfirst($data_c['name']) . '</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                            <?php } ?>
                                            <td>
                                                <select class="form-control select2" id="repeat_type" name="repeat_type">
                                                    <option value="">Repetition</option>
                                                    <?php
                                                    $repeat = "SELECT type_id, repetation_type FROM tk_task_repetation_type ORDER BY type_id ASC";
                                                    $ptr_repeat = mysql_query($repeat);
                                                    while ($data_repeat = mysql_fetch_array($ptr_repeat)) {
                                                        $sel = ($data_repeat['type_id'] == $_GET['repeat_type']) ? 'selected="selected"' : '';
                                                        echo '<option ' . $sel . ' value="' . $data_repeat['type_id'] . '">' . ucfirst(strip_tags($data_repeat['repetation_type'])) . '</option>';
                                                    }
                                                    ?>
                                                </select>
                                            </td>
                                            <td>
                                                <select class="form-control select2" id="status" name="status">
                                                    <option value="">Status</option>
                                                    <option value="complete" <?php if ($_GET['status'] == "complete") echo "selected='selected'"; ?>>Complete</option>
                                                    <option value="in_progress" <?php if ($_GET['status'] == "in_progress") echo "selected='selected'"; ?>>In Progress</option>
                                                    <option value="in_complete" <?php if ($_GET['status'] == "in_complete") echo "selected='selected'"; ?>>Incomplete</option>
                                                    <option value="cancel" <?php if ($_GET['status'] == "cancel") echo "selected='selected'"; ?>>Cancel</option>
                                                    <option value="halt" <?php if ($_GET['status'] == "halt") echo "selected='selected'"; ?>>Halt</option>
                                                </select>
                                            </td>
                                            <td>
                                                <input type="text" name="start_date" class="form-control datepicker" id="datepicker3" placeholder="Task Added Date" value="<?php echo $_REQUEST['start_date']; ?>">
                                            </td>
                                            <td>
                                                <input type="text" class="form-control" name="keyword" id="search_project" placeholder="Search" value="<?php if ($_REQUEST['keyword'] != "search") echo $_REQUEST['keyword']; ?>">
                                            </td>
                                            <td>
                                                <button type="submit" class="btn btn-primary">
                                                    <img src="images/search.jpg" alt="Search" style="height:32px;">
                                                </button>
                                            </td>
                                        </tr>
                                    </table>
                                </form>
                                <style>
                                    th, td {
                                        text-align: center;
                                        vertical-align: middle;
                                    }

                                    .table thead th {
                                        background-color: #f2f2f2; 
                                        font-weight: bold;
                                    }
                                </style>
                                <div class="box-body">
                                    <table class="table table-bordered table-responsive no-margin">
                                        <thead>
                                            <tr>
                                                <th>Sr. No.</th>
                                                <th>Task Name</th>
                                                <th>Type</th>
                                                <th>Assigned To</th>
                                                <th>Repetition</th>
                                                <th>Hours</th>
                                                <th>Points</th>
                                                <th>Priority</th>
                                                <th>Status</th>
                                                <th>Added Date</th>
                                                <th>Deadline</th>
                                                <th>Assigned By</th>
                                                <th>Validation</th>
                                                <th>Added By</th>
                                                <th>Details</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php        
                                            if (isset($_REQUEST['submit_valiadtion'])) {
                                                $task_ids = $_POST['task_id1'];
                                                $validation = $_POST['validation'];
                                                $reason = $_POST['reason'];
                                                $admin_id = $_SESSION['admin_id'];

                                                if ($reason != '') {
                                                    $insert_project = "INSERT INTO tk_task_validation (`staff_task_id`, `reasons`, `added_date`, `admin_id`) 
                                                                    VALUES ('$task_ids', '$reason', '" . date('Y-m-d H:i:s') . "', '$admin_id')";
                                                    $ptr_ins = mysql_query($insert_project);
                                                    if ($ptr_ins) {
                                                        ?>
                                                        <script>setTimeout('document.location.href="tk_add_individual_task.php"', 100);</script>
                                                        <?php
                                                    }
                                                }

                                                if ($validation != '') {
                                                    $update_status = "UPDATE tk_individual_task 
                                                                    SET `Validation` = '$validation', `validation_admin` = '$admin_id' 
                                                                    WHERE staff_task_id = '$task_ids'";
                                                    $ptr_ins_t = mysql_query($update_status);
                                                    if ($ptr_ins_t) {
                                                        ?>
                                                        <script>setTimeout('document.location.href="tk_add_individual_task.php"', 100);</script>
                                                        <?php
                                                    }
                                                }
                                            }

                                            if ($_REQUEST['start_date'] && $_REQUEST['start_date'] !== "0000-00-00") {
                                                $frm_date = explode("/", $_REQUEST['start_date']);
                                                $frm_dates = $frm_date[2] . "-" . $frm_date[1] . "-" . $frm_date[0];
                                                $start_date = $frm_dates;
                                                $dates = " AND DATE(added_date) = '" . date('Y-m-d', strtotime($frm_dates)) . "'";
                                            }

                                            $search_cm_id = '';
                                            if ($_REQUEST['branch_name1'] != '') {
                                                $branch_name = $_REQUEST['branch_name1'];
                                                $select_cm_id = "SELECT cm_id FROM site_setting WHERE branch_name = '$branch_name' AND system_status = 'Enabled' AND type = 'A'";
                                                $ptr_cm_id = mysql_query($select_cm_id);
                                                $data_cm_id = mysql_fetch_array($ptr_cm_id);
                                                $search_cm_id = "AND cm_id = '" . $data_cm_id['cm_id'] . "'";
                                            }

                                            $search_staff_id = '';
                                            if ($_REQUEST['admin_name'] != '') {
                                                $staff_id = $_REQUEST['admin_name'];
                                                $search_staff_id = "AND staff_id = '$staff_id'";
                                            }

                                            $search_admin_id = '';
                                            if ($_REQUEST['staff_names'] != '') {
                                                $admin_ids = $_REQUEST['staff_names'];
                                                $search_admin_id = "AND assign_by = '$admin_ids'";
                                            }

                                            $search_repeat_type = '';
                                            if ($_REQUEST['repeat_type'] != '') {
                                                $repeat_type = $_REQUEST['repeat_type'];
                                                $search_repeat_type = "AND repetation_id = '$repeat_type'";
                                            }

                                            $search_status = '';
                                            if ($_REQUEST['status'] != '') {
                                                $status = $_REQUEST['status'];
                                                $search_status = "AND status = '$status'";
                                            }

                                            $search = '';
                                            if ($_REQUEST['keyword'] != "keyword") {
                                                $search = trim($_REQUEST['keyword']);
                                            }

                                            $task_search = $search ? "AND (task_name LIKE '%$search%' OR priority LIKE '%$search%' OR status LIKE '%$search%')" : '';

                                            $select_directory = 'ORDER BY staff_task_id DESC';
                                            $date_query = '';
                                            if ($_GET['order'] != '' && $_GET['orderby'] == 'batch_id') {
                                                $select_directory = "ORDER BY " . $_GET['orderby'] . " " . $_GET['order'];
                                                $date_query = '&order=' . $_GET['order'] . '&orderby=' . $_GET['orderby'];
                                            }

                                            $i = 1;
                                            if ($_SESSION['type'] == 'S' || $edit_access == 'yes') {
                                                $sql_query = "SELECT * FROM tk_individual_task WHERE 1 $search_admin_id $search_staff_id $search_status $task_search $dates $search_repeat_type AND task_type = 'adhoc_task' ORDER BY staff_task_id DESC";
                                            } elseif ($manager_access == 'manager') {
                                                $sql_query = "SELECT * FROM tk_individual_task WHERE 1 AND ($string) $search_staff_id $search_status $task_search $dates $search_repeat_type AND task_type = 'adhoc_task' ORDER BY staff_task_id DESC";
                                            } else {
                                                $sql_query = "SELECT * FROM tk_individual_task WHERE 1 AND assign_by = '".$_SESSION['admin_id']."' $search_staff_id $search_status $task_search $dates $search_repeat_type AND task_type = 'adhoc_task' ORDER BY staff_task_id DESC";
                                            }
                                            
                                            $no_of_records = mysql_num_rows($db->query($sql_query));
                                            
                                            if ($no_of_records) {
                                                $bgColorCounter = 1;
                                            
                                                $query_string = '&keyword=' . urlencode($search) . '&branch_name1=' . urlencode($branch_name) . '&status=' . urlencode($status) . '&staff_names=' . urlencode($admin_ids) . '&admin_name=' . urlencode($staff_id) . '&repeat_type=' . urlencode($repeat_type) . '&start_date=' . urlencode($_REQUEST['start_date']);
                                                $query_string1 = $query_string . $date_query;
                                            
                                                $pager = new PS_Pagination($sql_query, $_SESSION['show_records'], 5, $query_string1);
                                                $all_records = $pager->paginate();
                                            
                                                while ($data1 = mysql_fetch_array($all_records)) {
                                                    $bgcolor = ($bgColorCounter % 2 == 0) ? 'class="grey_td"' : '';
                                            
                                                    include "include/paging_script.php";
                                            
                                                    $sel_staff = "SELECT name FROM site_setting WHERE admin_id = '".$data1['staff_id']."'";
                                                    $ptr_staff = mysql_query($sel_staff);
                                                    $data_staff = mysql_fetch_array($ptr_staff);
                                            
                                                    $add_data = "SELECT name FROM site_setting WHERE admin_id = '".$data1['admin_id']."'";
                                                    $ptr_data_a = mysql_query($add_data);
                                                    $data_add = mysql_fetch_array($ptr_data_a);
                                            
                                                    $assign_by_data = "SELECT name FROM site_setting WHERE admin_id = '".$data1['assign_by']."'";
                                                    $ptr_assign_by = mysql_query($assign_by_data);
                                                    $data_assign_by = mysql_fetch_array($ptr_assign_by);
                                        
										            ?>
                                                    <tr>

                                                        <td>

                                                            <?php echo $sr_no; ?>

                                                        </td>



                                                        <td>

                                                            <?php echo strip_tags(ucwords($data1['task_name']))?>

                                                        </td>

                                                        <td>

                                                            <?php echo ucwords($data1['assign_type'])?>

                                                        </td>

                                                        <td>

                                                            <?php echo ucwords($data_staff['name'])?>

                                                        </td>

                                                        <td>

                                                            <?php 

                                                            $repeat="select repetation_type from tk_task_repetation_type where type_id='".$data1['repetation_id']."' order by type_id ASC";

                                                            $ptr_repeat=mysql_query($repeat);

                                                            $data_repeat=mysql_fetch_array($ptr_repeat);

                                                            if($_SESSION['type']=='S' || $edit_access=='yes' || $manager_access=='manager' && $_SESSION['admin_id']!=$data1['staff_id'] && $data1['repetation_id']!=1)

                                                            {

                                                                if($data1['repetation_id']=='0')

                                                                {

                                                                    echo 'Repeated';

                                                                }

                                                                elseif($data1['repetation_id']!='1')

                                                                {

                                                                    if($data1['repetation_valid']=='active')

                                                                    {

                                                                        ?>

                                                                        <button type="button" class="btn btn-success" data-toggle="modal"

                                                                            data-target="#s_<?php echo $data1['staff_task_id'];?>">

                                                                            <?php echo ucwords($data_repeat['repetation_type']);?>

                                                                        </button>

                                                                        <?php

                                                                    }

                                                                    else

                                                                    {

                                                                        ?>

                                                                        <button type="button" class="btn btn-danger" data-toggle="modal"

                                                                            data-target="#s_<?php echo $data1['staff_task_id'];?>">

                                                                            <?php echo ucwords($data_repeat['repetation_type']);?>

                                                                        </button>

                                                                        <?php

                                                                    }

                                                                    ?>

                                                                    <div class="modal fade"

                                                                        id="s_<?php echo $data1['staff_task_id'];?>">

                                                                        <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"> Task Name :

                                                                                        <span style="color:blue">

                                                                                            <?php echo ucwords($data1['task_name']) ?>

                                                                                        </span>

                                                                                    </h4>

                                                                                    <div> Repetation :

                                                                                        <?php echo ucfirst($data_repeat['repetation_type']); ?>

                                                                                    </div>

                                                                                </div>

                                                                                <!-- <div class="direct-chat-messages"> -->

                                                                                <form name="task_forms" method="POST">

                                                                                    <div class="modal-body">

                                                                                        <label>Task Repetation </label><br>

                                                                                        <label>Active

                                                                                            <input type="radio" name="repetation_valids"

                                                                                                value="active"

                                                                                                onchange="repetations_valid(this.value,'<?php echo $data1['staff_task_id']; ?>')"

                                                                                                <?php

                                                                                                if($_POST['repetation_valids']=="active"

                                                                                                ) echo 'checked="checked"' ; else

                                                                                                if($data1['repetation_valid']=="active"

                                                                                                ) echo 'checked="checked"' ; ?> >

                                                                                        </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                                                                                        <label>In-Active

                                                                                            <input type="radio" name="repetation_valids"

                                                                                                value="in_active"

                                                                                                onchange="repetations_valid(this.value,'<?php echo $data1['staff_task_id']; ?>')"

                                                                                                <?php

                                                                                                if($_POST['repetation_valids']=="in_active"

                                                                                                ) echo 'checked="checked"' ; else

                                                                                                if($data1['repetation_valid']=="in_active"

                                                                                                ) echo 'checked="checked"' ; ?> >

                                                                                        </label>

                                                                                        <input type="hidden" id="tasking_id"

                                                                                            value="<?php echo $data1['staff_task_id'];?>">

                                                                                        <!-- <div class="form-group">

                                                                                                    <input type="submit" name="submit_valiadtion" value="Submit" class="btn btn-block btn-success">

                                                                                                </div> -->

                                                                                    </div>

                                                                                </form>

                                                                                <!-- </div> -->

                                                                            </div>

                                                                        </div>

                                                                    </div>

                                                                    <?php

                                                                }

                                                                else

                                                                {

                                                                    echo ucwords($data_repeat['repetation_type']);

                                                                }

                                                            }

                                                            else

                                                            {

                                                                if($data1['repetation_id']=='0')

                                                                {

                                                                    echo 'Repeated';

                                                                }

                                                                else{

                                                                    echo ucwords($data_repeat['repetation_type']);

                                                                }

                                                            }

                                                            ?>

                                                        </td>

                                                        <td>

                                                            <?php 

                                                            $hours=$data1['hours'];

                                                            $time1= convertToHoursMins($hours, '%02d hour %02d min');

                                                            echo $time1;

                                                            ?>

                                                        </td>

                                                        <td>

                                                            <?php 

                                                            echo substr($data1['points'],0,4).' points';

                                                            ?>

                                                        </td>

                                                        <td>

                                                            <?php echo ucfirst($data1['priority'])?>

                                                        </td>

                                                        <td>

                                                            <?php

                                                                if($data1['status']=='complete') 

                                                                { 

                                                                ?>

                                                                <p class="label label-success">

                                                                    <?php echo ucfirst($data1['status']);?>

                                                                </p>

                                                                <?php

                                                                } 

                                                                if($data1['status']=='in_progress') 

                                                                { 

                                                                ?>

                                                                <p class="label label-warning">

                                                                    <?php echo ucfirst($data1['status']);?>

                                                                </p>

                                                                <?php

                                                                } 

                                                                if($data1['status']=='in_complete') 

                                                                { 

                                                                    ?>

                                                                <p class="label label-danger">

                                                                    <?php echo ucfirst($data1['status']);?>

                                                                </p>

                                                                <?php

                                                                } 

                                                                if($data1['status']=='cancel') 

                                                                { 

                                                                    ?>

                                                                <p class="label label-default">

                                                                    <?php echo ucfirst($data1['status']);?>

                                                                </p>

                                                                <?php

                                                                }

                                                                if($data1['status']=='halt') 

                                                                { 

                                                                    ?>

                                                                <p class="label label-primary">

                                                                    <?php echo ucfirst($data1['status']);?>

                                                                </p>

                                                                <?php

                                                                }

                                                            ?>

                                                        </td>

                                                        <td>

                                                            <?php

                                                            $new_addDate = date("d-m-Y", strtotime($data1['added_date']));  

                                                            echo $new_addDate;  

                                                            ?>

                                                        </td>

                                                        <td>

                                                            <?php 

                                                            if($data1['due_date']!='')

                                                            {

                                                                $new_dueDate = date("d-m-Y", strtotime($data1['due_date']));

                                                                echo $new_dueDate ;

                                                                // echo $data['due_date'];

                                                            }

                                                            ?>

                                                        </td>

                                                        <td>

                                                            <?php echo ucwords($data_assign_by['name'])?>

                                                        </td>

                                                        <td>

                                                            <?php

                                                            if($data1['status']!='complete')

                                                            {

                                                                if($_SESSION['type']=="S" || $edit_access=='yes' || $manager_access=='manager' && $_SESSION['admin_id']!=$data1['staff_id']  )

                                                                {

                                                                    ?>

                                                                    <button type="button" class="btn btn-default" data-toggle="modal"

                                                                        data-target="#<?php echo $data1['staff_task_id']?>"

                                                                        style="width:70px;">

                                                                        <?php echo ucfirst($data1['Validation']);?>

                                                                    </button>

                                                                    <?php

                                                                }

                                                                else

                                                                {

                                                                    if($data1['Validation']!='pending')

                                                                    {

                                                                        ?>

                                                                        <button type="button" class="btn btn-default" data-toggle="modal"

                                                                            data-target="#<?php echo $data1['staff_task_id']?>"

                                                                            style="width:70px;">

                                                                            <?php echo ucfirst($data1['Validation']);?>

                                                                        </button>

                                                                        <?php

                                                                    }

                                                                    else

                                                                    {

                                                                        echo ucfirst($data1['Validation']);

                                                                    }

                                                                }

                                                                        //     $sel_reason="select reasons,admin_id from tk_task_validation where staff_task_id='".$data1['staff_task_id']."'order by v_id DESC ";

                                                                        //     $ptr_reason=mysql_query($sel_reason);

                                                                        //     $data_reason=mysql_fetch_array($ptr_reason);

                                                                        //     $sel_valid_name="select name from site_setting where admin_id='".$data1['validation_admin']."'";

                                                                        //     $pt_name=mysql_query($sel_valid_name);

                                                                        //     $data_validation=mysql_fetch_array($pt_name);

                                                                            ?>

                                                                    <!-- <span title="<?php //echo(ucwords($data_reason['reasons'])) ?>">

                                                                        <?php //echo ucfirst($data1['Validation']); ?>

                                                                    </span><?php //if($data1['Validation']!='pending'){?><span style="color:blue"> [ By

                                                                        <?php  //echo  Ucwords($data_validation['name']); ?> ]

                                                                    </span>-->

                                                                    <?php //} 

                                                                    ?>

                                                                    <?php

                                                                // }

                                                            }

                                                                ?>

                                                            <div class="modal fade" id="<?php echo $data1['staff_task_id'];?>">

                                                                <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><label>Task Validation </label></h4>

                                                                        </div>

                                                                        <div class="modal-body">

                                                                            <!-- body code -->

                                                                            <div class="box box-default">

                                                                                <form name="task_form12" method="post">

                                                                                    <div class="box-body">

                                                                                        <div class="row">

                                                                                            <!-- <div class="col-md-8"> -->

                                                                                                <div class="form-group">

                                                                                                    <?php

                                                                                                     $sel_valid_names="select name from site_setting where admin_id='".$data1['validation_admin']."'";

                                                                                                     $pt_names=mysql_query($sel_valid_names);

                                                                                                     $data_validations=mysql_fetch_array($pt_names);

                                                                                            if($_SESSION['type']=="S" || $edit_access=='yes' || $manager_access=='manager' && $_SESSION['admin_id']!=$data1['staff_id'])

                                                                                            { ?>

                                                                                                    <label>Valid

                                                                                                        <input type="radio"

                                                                                                            name="validation"

                                                                                                            value="valid" <?php

                                                                                                            if($_POST['validation']=="valid"

                                                                                                            )

                                                                                                            echo 'checked="checked"'

                                                                                                            ; else

                                                                                                            if($data1['Validation']=="valid"

                                                                                                            )

                                                                                                            echo 'checked="checked"'

                                                                                                            ; ?> class="minimal"

                                                                                                        >

                                                                                                    </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                                                                                                    <label>In-Valid

                                                                                                        <input type="radio"

                                                                                                            name="validation"

                                                                                                            value="in_valid"

                                                                                                            <?php

                                                                                                            if($_POST['validation']=="in_valid"

                                                                                                            )

                                                                                                            echo 'checked="checked"'

                                                                                                            ; else

                                                                                                            if($data1['Validation']=="in_valid"

                                                                                                            )

                                                                                                            echo 'checked="checked"'

                                                                                                            ; ?>

                                                                                                        class="minimal-red">

                                                                                                    </label>

                                                                                                    <?php

                                                                                                if($data1['Validation']!='pending')

                                                                                                {

                                                                                                    ?>

                                                                                                    <div> Task <b>

                                                                                                            <?php echo ucfirst($data1['Validation']) ?>

                                                                                                        </b> By

                                                                                                        <?php  echo  Ucwords($data_validations['name']); ?>

                                                                                                    </div>

                                                                                                    <?php

                                                                                                } ?>

                                                                                                <div class="form-group">

                                                                                                    <textarea type=""

                                                                                                        class="form-control"

                                                                                                        name="reason"

                                                                                                        id="reason" value=""

                                                                                                        placeholder="Add Query"></textarea>

                                                                                                </div>

                                                                                                <div class="form-group">

                                                                                                    <div class="">

                                                                                                        <input type="submit"

                                                                                                            name="submit_valiadtion"

                                                                                                            value="Submit"

                                                                                                            class="btn btn-block btn-success">

                                                                                                    </div>

                                                                                                </div>

                                                                                                <?php   

                                                                                            }

                                                                                                else 

                                                                                                {

                                                                                                    ?>

                                                                                                    <div> Task <b>

                                                                                                            <?php echo ucfirst($data1['Validation']) ?>

                                                                                                        </b> By

                                                                                                        <?php  echo  Ucwords($data_validations['name']); ?>

                                                                                                    </div>

                                                                                                    <?php

                                                                                                } ?>

                                                                                                    <input type="hidden"

                                                                                                        name="task_id1"

                                                                                                        value="<?php echo $data1['staff_task_id'];?>">

                                                                                                </div>

                                                                                                

                                                                                            <!-- </div>

                                                                                            <div class="col-md-4"> -->

                                                                                                <!-- <div class="direct-chat-messages"> -->

                                                                                                <?php

                                                                                                $sel_reason="select reasons,admin_id from tk_task_validation where staff_task_id='".$data1['staff_task_id']."'";

                                                                                                $ptr_reason=mysql_query($sel_reason);

                                                                                                $no_records=mysql_num_rows($ptr_reason);

                                                                                                if($no_records)

                                                                                                {

                                                                                                    ?>

                                                                                                    <label>Reasons </label><br>

                                                                                                    <?php

                                                                                                    while($data_reason=mysql_fetch_array($ptr_reason))

                                                                                                    {

                                                                                                        $add="select name from site_setting where 1 and admin_id='".$data_reason['admin_id']."'";

                                                                                                        $ptr=mysql_query($add);

                                                                                                        $data2=mysql_fetch_array($ptr);

                                                                                                        if($data_reason['reasons']!='')

                                                                                                        {

                                                                                                            echo '<div><b>'.ucfirst($data2['name']).'</b></div>';

                                                                                                            echo '<li>'.ucwords($data_reason['reasons']).'</li>';

                                                                                                        }

                                                                                                    }

                                                                                                }

                                                                                                ?>

                                                                                                <!-- </div> -->

                                                                                            <!-- </div> -->

                                                                                        </div>

                                                                                    </div>

                                                                                </form>

                                                                            </div>

                                                                        </div>

                                                                    </div>

                                                                </div>

                                                            </div>

                                                        </td>

                                                        <td>

                                                            <?php echo ucfirst($data_add['name']);?>

                                                        </td>

                                                        <td>

                                                            <?php

                                                            // echo $data1['staff_task_id'];

                                                            if($data1['Validation']=='valid' || $_SESSION['type']=="S" || $edit_access=='yes' || $manager_access=='manager')

                                                            {

                                                                ?>

                                                                <a href="tk_individual_task_detail.php?id=<?=$data1['staff_task_id'] ?>"

                                                                    target=""><i class="fa fa-file"></i></a>

                                                                <?php

                                                            }

                                                            ?>

                                                        </td>

                                                        <td>

                                                            <?php

                                                            // echo $data1['staff_task_id'];

                                                            // if($data1['status']!='complete'){

                                                            if($_SESSION['type']=="S")

                                                            { 

                                                                ?>

                                                                <a

                                                                    href="tk_add_individual_task.php?id=<?=$data1['staff_task_id']?>"><i

                                                                        class="fa fa-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;

                                                                <a

                                                                    href="tk_add_individual_task.php?deleteRecord=1&id=<?=$data1['staff_task_id']?>">

                                                                    <i class="fa fa-trash"></i></a>

                                                                <?php

                                                            }

                                                            else if( $edit_access=='yes')

                                                            {

                                                                if($data1['status']!='complete'  && $data1['repetation_id']!='0')

                                                                {

                                                                    ?>

                                                                    <a

                                                                        href="tk_add_individual_task.php?id=<?=$data1['staff_task_id']?>"><i

                                                                            class="fa fa-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;

                                                                    <a

                                                                        href="tk_add_individual_task.php?deleteRecord=1&id=<?=$data1['staff_task_id']?>">

                                                                        <i class="fa fa-trash"></i></a>

                                                                    <?php   

                                                                }

                                                            }

                                                            else if($data1['Validation']!='valid' && $data1['status']!='complete')

                                                            {

                                                                ?>

                                                                <a

                                                                    href="tk_add_individual_task.php?id=<?=$data1['staff_task_id']?>"><i

                                                                        class="fa fa-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;

                                                                <a

                                                                    href="tk_add_individual_task.php?deleteRecord=1&id=<?=$data1['staff_task_id']?>">

                                                                    <i class="fa fa-trash"></i></a>

                                                                <?php

                                                            }

                                                            ?>

                                                        </td>

                                                    </tr>

                                                    <?php

									                $bgColorCounter++;

									            }

									            ?>

                                                <tr class="head_td">

                                                    <td colspan="17">

                                                        <table cellspacing="0" cellpadding="0" width="100%">

                                                            <tr>

                                                                <?php

                                                        if($no_of_records>10)

                                                        {

                                                            echo '<td width="5%" align="left"> Show &nbsp;&nbsp;</td>

                                                            <td width="20%" align="left"><select class="form-control" name="show_records" onchange="redirect(this.value)">';

                                                            $show_records=array(0=>'10',1=>'20','50','100','200');

                                                            for($s=0;$s<count($show_records);$s++)

                                                            {

                                                                if($_SESSION['show_records']==$show_records[$s])

                                                                    echo '<option selected="selected" value="'.$show_records[$s].'">'.$show_records[$s].' Records</option>';

                                                                else

                                                                    echo '<option value="'.$show_records[$s].'">'.$show_records[$s].' Records</option>';

                                                            }

                                                            echo'</td></select>';

                                                        }

                                                        echo '<td width="75%" align="right">'.$pager->renderFullNav().'</td>';

                                                        ?>

                                                            </tr>

                                                        </table>

                                                    </td>

                                                </tr>

                                                <?php

                                            }

                                            ?>

                                        </tbody>

                                    </table>

                                </div>
                            </div>
                        </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

            })

            $('#datepicker2').datepicker({

                autoclose: true,

                format: 'dd/mm/yyyy',

                Default: true,

                todayHighlight: true

            })

            $('#datepicker3').datepicker({

                autoclose: true,

                format: 'dd/mm/yyyy',

                Default: true,

                todayHighlight: true

            })

            $('#datepicker12').datepicker({

                autoclose: true,

                format: 'dd/mm/yyyy',

                startDate: '-1d',

                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'

            })

            $('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>

    <?php

	 if($_SESSION['type']!='S' || $_SESSION['branch_access']=='no')

     {

		?>

        <script>

            branch = document.getElementById("branch_name").value;

            select_staff(branch);

            branch1 = document.getElementById("branch_names1").value;

            select_admin(branch1);

        </script>

        <?php

	}

	?>

</body>



</html>