<?php
include "../../pidbco/pidbjoin.php";

if(!isset($_SESSION))
{
    session_start();
}

if(!isset($_SESSION['jay_proj_mngmnt']) && empty($_SESSION['jay_proj_mngmnt']))
{
    echo '<script type="text/javascript">alert("You Want To Login Now.."); window.location.href="../Login";</script>';
}

include "../ses_write.php";
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Marketing</title>

    <!-- Bootstrap core CSS -->

    <link href="../components/css/bootstrap.min.css" rel="stylesheet">

    <link href="../components/fonts/css/font-awesome.min.css" rel="stylesheet">
    <link href="../components/css/animate.min.css" rel="stylesheet">

    <!-- Custom styling plus plugins -->
    <link href="../components/css/custom.css" rel="stylesheet">
    <link href="../components/css/icheck/flat/green.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../components/css/maps/jquery-jvectormap-2.0.1.css" />
    <link href="../components/css/floatexamples.css" rel="stylesheet" type="text/css" />


    <script src="../components/js/jquery.min.js"></script>
    <script src="../components/js/nprogress.js"></script>
    <script>
        NProgress.start();
    </script>

    <style>
        input[type=number] {
            -moz-appearance:textfield;
        }

        input[type=number]::-webkit-inner-spin-button,
        input[type=number]::-webkit-outer-spin-button {
            -webkit-appearance: none;
            margin: 0;
        }
    </style>

    <script src="../components/js/jquery.min.js"></script>

    <!--[if lt IE 9]>
    <script src="../assets/js/ie8-responsive-file-warning.js"></script>
    <![endif]-->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- DataTables CSS -->
    <link href="../components/data_table/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">

    <!-- DataTables Responsive CSS -->
    <link href="../components/data_table/datatables-responsive/css/dataTables.responsive.css" rel="stylesheet">



</head>




<body class="nav-md">

<div class="container body">


<div class="main_container">

<?php include("left_menu.php"); ?>

<!-- top navigation -->
<?php include("../marketing/top_nav.php"); ?>
<!-- /top navigation -->

<script>
    function dep_register()
    {
        var ck_name = /^[A-Za-z .,0-9 ]{3,30}$/;

        //Department
        if(document.getElementById('dep_name').value == "")
        {
            alert("please Enter Department Name.!");
            $('#dep_name').focus();
            return false;
        }
        if(document.getElementById('dep_name').value.match(ck_name))
        {

        }
        else
        {
            alert('Miss Match Error Department Name..!');
            $('#dep_name').focus();
            return false;
        }

        //Status
        if(document.getElementById('status').value == "")
        {
            alert("please Enter Status.!");
            $('#status').focus();
            return false;
        }

        var dep_name = $('#dep_name').val();
        var status = $('#status').val();

        $.ajax({
            url   :"ajax_department.php",
            type  : "POST",
            data  :
            {
                btn_add_dep_data : 1,
                dep_name  : dep_name,
                status    : status
            },
            success:function(res121)
            {
                $('#alerts').html(res121);

            }
        });
    }
</script>
<script>
    function show_dep_data()
    {
        $.ajax({
            url   :"ajax_department.php" ,
            type  : "POST",
            data  :
            {
                btn_show_dep_data : 1

            },
            success:function(res122)
            {
                $('#show_data').html(res122);

            }
        });
    }
</script>
<script>
    function edt_department(id)
    {
        if(id == "")
        {
            alert('Error..!');
            return false;
        }

        $.ajax({
            url   :"ajax_department.php" ,
            type  : "POST",
            data  :
            {
                btn_edt_dep_data : 1,
                id               : id
            },
            success:function(res123)
            {
                $('#edt_data').html(res123);

            }
        });
    }
</script>
<script>
    function upd_department()
    {
        var ck_name = /^[A-Za-z .,0-9 ]{3,30}$/;

        //Department
        if(document.getElementById('dep_name').value == "")
        {
            alert("please Enter Department Name.!");
            $('#dep_name').focus();
            return false;
        }
        if(document.getElementById('dep_name').value.match(ck_name))
        {

        }
        else
        {
            alert('Miss Match Error Department Name..!');
            $('#dep_name').focus();
            return false;
        }

        //Status
        if(document.getElementById('status').value == "")
        {
            alert("please Enter Status.!");
            $('#status').focus();
            return false;
        }

        if(document.getElementById('did').value == "")
        {
            alert("Error!..");
            return false;
        }

        var did = $('#did').val();
        var dep_name = $('#dep_name').val();
        var status = $('#status').val();

        $.ajax({
            url   :"ajax_department.php" ,
            type  : "POST",
            data  :
            {
                btn_upd_dep_data : 1,
                dep_name  : dep_name,
                status    : status,
                did       : did
            },
            success:function(res124)
            {

                $('#alerts').html(res124);

            }
        });
    }
</script>
<script>
    $(function()
    {

        $(".checkbox").click(function(){
            $('#delete').prop('disabled',$('input.checkbox:checked').length == 0);
        });

    });
</script>
<script>
    function del_dep_data()
    {
        if (confirm("Are you sure you want to delete?"))
        {
            var notChecked = [], checked = [];

            $(":checkbox").each(function()
            {
                if(this.checked)
                {
                    checked.push(this.id);
                }
                else
                {
                    notChecked.push(this.id);
                }
            });

            $.ajax({
                url   :"ajax_department.php" ,
                type  : "POST",
                data  :
                {
                    btn_delete_dep_data : 1,
                    checked             : checked
                },
                success:function(res125)
                {
                    $('#alerts').html(res125);
                }
            });
        }
    }
</script>

<!-- page content -->
<div class="right_col" role="main">
    <div class="row">
        <div id="alerts"></div>
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
                <div class="x_title">
                    <h2>Department<small>registration</small></h2>
                    <ul class="nav navbar-right panel_toolbox">
                        <li>
                            <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                        </li>
                        <li>
                            <a class="close-link"><i class="fa fa-close"></i></a>
                        </li>
                    </ul>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content" id="edt_data">
                    <form id="frm_1" name="frm_1" data-parsley-validate class="form-horizontal form-label-left">

                        <div class="form-group">
                            <div class="col-md-3 col-sm-3 col-xs-12">
                                <input id="dep_name" class="form-control col-md-7 col-xs-12" placeholder="Department Name*" required="required"  type="text" name="dep_name" >
                            </div>
                            <div class="col-md-3 col-sm-3 col-xs-12">
                                <select id="status" class="form-control col-md-7 col-xs-12 " name="status"  required="required">
                                    <option value="">Status*</option>
                                    <option value="1">Active</option>
                                    <option value="0">In-Active*</option>
                                </select>
                            </div>
                            <div class="col-md-3 col-sm-3 col-xs-12 ">
                                <button type="button" class="btn btn-primary " onclick="dep_register();">SAVE</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
                <div class="x_title">
                    <h2>Department<small>View</small></h2>
                    <ul class="nav navbar-right panel_toolbox">
                        <li class="col-md-pull-6">
                            <button class="btn btn-default btn-sm" onclick="del_dep_data();"  disabled="disabled" id="delete" name="delete"><span class="glyphicon glyphicon-trash"  ></span></button>
                        </li>
                        <li>
                            <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                        </li>
                        <li>
                            <a class="close-link"><i class="fa fa-close"></i></a>
                        </li>
                    </ul>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content" id="show_data">
                    <div class="dataTables_wrapper">
                        <table class="table table-striped table-bordered table-hover table-responsive" id="dataTables-example">
                            <thead>
                            <tr>
                                <th width="5%">#</th>
                                <th>Department</th>
                                <th>Status</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            $stmt = mysqli_query($con,"SELECT * FROM department_det ORDER BY id DESC ");
                            $i=1;
                            while($res = mysqli_fetch_object($stmt))
                            {
                                ?>
                                <tr class="odd gradeX" data-toggle="modal"  style="cursor: pointer;">
                                    <td width="5%"><input type="checkbox" class="checkbox"  id="<?php echo $res->id; ?>" style="cursor: pointer;" /></td>
                                    <td onclick="edt_department(<?php echo $res->id; ?>);" ><?php echo $res->dep_name; ?></td>
                                    <td width="20%" onclick="edt_department(<?php echo $res->id; ?>);" class="center"><?php if($res->status == 1){ echo 'Active'; }else{ echo 'In-Active'; } ?></td>
                                </tr>
                                <?php
                                $i++;
                            }
                            ?>
                            </tbody>
                        </table>
                    </div>
                    <!-- /.table-responsive -->
                </div>
            </div>
        </div>
    </div>

</div>
<!-- /page content -->

</div>

</div>

<div id="custom_notifications" class="custom-notifications dsp_none">
    <ul class="list-unstyled notifications clearfix" data-tabbed_notifications="notif-group">
    </ul>
    <div class="clearfix"></div>
    <div id="notif-group" class="tabbed_notifications"></div>
</div>


<script src="../components/js/bootstrap.min.js"></script>


<!-- bootstrap progress js -->
<script src="../components/js/progressbar/bootstrap-progressbar.min.js"></script>
<script src="../components/js/nicescroll/jquery.nicescroll.min.js"></script>
<!-- icheck -->
<script src="../components/js/icheck/icheck.min.js"></script>
<!-- tags -->
<script src="../components/js/tags/jquery.tagsinput.min.js"></script>
<!-- switchery -->
<script src="../components/js/switchery/switchery.min.js"></script>



<script src="../components/js/custom.js"></script>


<!-- DataTables JavaScript -->
<script src="../components/data_table/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="../components/data_table/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
<!-- Page-Level Demo Scripts - Tables - Use for reference -->
<script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
            responsive: true
        });
    });
</script>

</body>

</html>
