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

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Add Categary</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>


<body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">
        <?php include "include/header-main.php"; ?>
        <!-- Left side column. contains the logo and sidebar -->
        <?php include "include/menu_left.php"; ?>
        <!-- Content Wrapper. Contains page content -->
        <!-- Left side column. contains the logo and sidebar -->
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                    Add Categary
                    <!--<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_categary where categary_id='$record_id'";
                            $ptr_data=mysql_query($query);
                            $data=mysql_fetch_array($ptr_data);
                        }
                        else
                        {
                            $record_id='';
                            
                        }

                        if(isset($_REQUEST['submit']))
                          {
                            if (empty($_POST['categary_name'])) {
                                $categary_Err = "Field is required";
                                }
                                else{
                                    $categary_name=addslashes($_POST['categary_name']);
                                }
                                    $admin_id =$_SESSION['admin_id'];

                                if($record_id)
                                {
                                        // categary updating
                                    if($categary_name !="")
                                    {
                                        $upd_categary="update tk_categary set `categary_name`='".$categary_name."',`updated_admin_id`='".$admin_id."',`cm_id`='".$_SESSION['cm_id']."',`updated_date`='".date('Y-m-d : H:i:s')."' where categary_id='".$record_id."' ";
                                            $ptr_upd_categary=mysql_query($upd_categary); 
                                            if ($ptr_upd_categary)
                                            {
                                                ?>
                                                <!-- updating alert box -->
                                                <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_categary.php";', 1000);</script>
                                            <?php  
                                            }  
                                    }     
                                }  
                                // categary inserting
                                  else
                                  {
                                    if($categary_name !="")
                                    {
                                      $insert_categary="insert into tk_categary(`categary_name`,`admin_id`,`cm_id`,`added_date`) values('".$categary_name."','".$admin_id."','".$_SESSION['cm_id']."','".date('Y-m-d : H:i:s')."')";
                                      $ptr_ins=mysql_query($insert_categary);
                                    //   $categary_id=mysql_insert_id();
                                    if ($ptr_ins)
                                    {
                                        ?>
                                        <!-- updating alert box -->
                                        <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_categary.php";', 1000);</script>
                                    <?php  
                                    }
                                    }
                                  }
                        }
                                // categary deleting
                        if($_REQUEST['deleteRecord']!='' && $_REQUEST['id']!='')
                        {
                          $id=$_REQUEST['id'];
                          $delete_cat="delete from tk_categary where categary_id='".$id."'";
                          $ptr_delete_cat=mysql_query($delete_cat);
                        //   $delete_cat1="delete from tk_task_managment where categary_id='".$id."'";
                        //   $ptr_delete_cat1=mysql_query($delete_cat1);
                       
                              if ($ptr_delete_cat)
                              {
                            ?>
                                    <!-- delete altert box -->
                                    <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_categary.php";', 1000);
                                    </script>

                                    <?php   
                                 }
                        }

                                      ?>
            <!-- Main content -->
            <section class="content">
                <div class="box box-default">
                    <form name="task_form" method="post">
                        <div class="box-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <p style="color:red"> * Required Field</p>
                                    <div class="form-group">
                                        <label><span style="color:red">*</span>categary Name &nbsp;&nbsp;<span
                                                style="color:red">
                                                <?php echo $categary_Err ;?>
                                            </span> </label>
                                        <input type="text" class="form-control" name="categary_name" id="categary_name"
                                            value="<?=$data['categary_name']?>" placeholder="">
                                    </div>
                                    <div class="form-group">
                                        <div class="">
                                            <input type="submit" name="submit"
                                                value="<?php if($record_id) echo 'Update '; else echo 'Submit'; ?>"
                                                class="btn btn-block btn-success">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <!-- manage categary and categary table -->
                <div class="row">
                    <div class="col-md-12">
                        <div class="box box-info">
                            <div class="box-header with-border">
                                <h3 class="box-title">Manage Categary</h3>
                            </div>
                            <div class="">
                                <form method="post" name="search">
                                    <div class="input-group" style="padding:0% 2% 0% 82%; ">
                                        <input type="text" class="form-control" name="keyword" id="search_project"
                                            value="<?php if($_REQUEST['search']!=" search") echo $_REQUEST['search'];?>"
                                        placeholder="Search Categary">
                                        <div class="input-group-btn">
                                            <input type="image" src="images/search.jpg" name="search" value="search" style="height:34px;">
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="box-body">
                                <div class="table-responsive">
                                    <table class="table no-margin">
                                        <thead>
                                            <tr>
                                                <th>Sr. No.</th>
                                                <th>categary Name</th>
                                                <th>Added Date</th>
                                                <th>Added By</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                                          $i=1;
                                                          if($_REQUEST['keyword']!="keyword")
                                                          $search=trim($_REQUEST['keyword']);
                                                          if($search)
                                                          {
                                                             $cate_search=" and categary_name like '%".$search."%'";
                                                          }
                                                          else{
                                                             $cate_search="";
                                                          }
                                                         
                                                          $my_data="select * from tk_categary where 1 ".$cate_search." order by added_date desc";
                                                          $ptr_data_1=mysql_query($my_data);
                                                          while($data_1=mysql_fetch_array($ptr_data_1))
                                                          {
                                                              $p_data="select name from site_setting where 1 and admin_id='".$data_1['admin_id']."'";
                                                              $ptr_data=mysql_query($p_data);
                                                              $proj_data=mysql_fetch_array($ptr_data);
                                                            ?>
                                            <tr>
                                                <td>
                                                    <?php echo $i++ ?>
                                                </td>
                                                <td>
                                                    <?php echo strip_tags(ucfirst($data_1['categary_name']));?>
                                                </td>
                                                <td>
                                                    <?php
                                                                 $add_Date = date("d-m-Y", strtotime($data_1['added_date']));
                                                                         echo $add_Date ;
                                                                ?>
                                                </td>
                                                <td>
                                                    <?php echo ucfirst($proj_data['name']);?>
                                                </td>
                                                <td>
                                                    <a href="tk_add_categary.php?id=<?= $data_1['categary_id'] ?>">
                                                     <i class="fa fa-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;                                 <!--  edit -->
                                                    <a href="tk_add_categary.php?deleteRecord=1&id=<?= $data_1['categary_id']?>">
                                                    <i class="fa fa-trash"></i></a>                                                         <!-- delete -->
                                                </td>
                                            </tr>
                                            <?php
                                                          }
                                                  ?>
                                        </tbody>
                                    </table>
                                     <!-- table pagination code -->
                                    <div class="pagination">
                                        <a href="#">&laquo;</a>
                                        <a href="" class="active">1</a>
                                        <a href="" >2</a>
                                        <a href="">3</a>
                                        <a href="">&raquo;</a>
                                  </div>
                                </div>
                                <!-- /.table-responsive -->
                            </div>
                            <!-- /.box-body -->
                        </div>
                        <!-- /.box -->
                    </div>
                    <!-- /.col -->
                </div>
                <!-- end manage categary and categary 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()

            //Date picker
            $('#datepicker').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                startDate: '-1d',
                Default: true,
                todayHighlight: true
            })
            $('#datepicker1').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                Default: true,
                todayHighlight: true
            })

            //iCheck for checkbox and radio inputs
            $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue'
            })
            //Red color scheme for iCheck
            $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
                checkboxClass: 'icheckbox_minimal-red',
                radioClass: 'iradio_minimal-red'
            })
            //Flat red color scheme for iCheck
            $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
                checkboxClass: 'icheckbox_flat-green',
                radioClass: 'iradio_flat-green'
            })

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

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

</html>