<?php $this->load->view('backend/header'); ?>
<?php $this->load->view('backend/sidebar'); ?>
      <div class="page-wrapper">
            <div class="message"></div>
            <div class="row page-titles">
                <div class="col-md-5 align-self-center">
                    <!-- <h3 class="text-themecolor">Notice Board</h3> -->
                </div>
                <div class="col-md-7 align-self-center">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="javascript:void(0)">Home</a></li>
                        <li class="breadcrumb-item active">Notice Board</li>
                    </ol>
                </div>
            </div>
        <div class="container-fluid">
                <div class="row m-b-10"> 
                    <div class="col-12">
                        <button type="button" class="btn btn-info"><i class="fa fa-plus"></i><a data-toggle="modal" data-target="#noticemodel" data-whatever="@getbootstrap" class="text-white "><i class="" aria-hidden="true"></i> Add Notice </a></button>
                    </div>
                </div> 
                <center>
                                <!-- start of status -->
              <?php if( $this->session->flashdata('error') != "" ) : ?>
                                 <div class="row"><div class="col-xs-12"><div class="alert alert-danger"><?php echo $this->session->flashdata('error'); ?></div></div></div>
                              <?php endif; ?>
                              <?php if( $this->session->flashdata('success') != "" ) : ?>
                                <div class="col-xs-12"><div class="alert alert-success"><?php echo $this->session->flashdata('success'); ?></div></div>
                              <?php endif; ?>
                              <?php if( $this->session->flashdata('delsuccess') != "" ) : ?>
                                <div class="col-xs-12"><div class="alert alert-danger"><?php echo $this->session->flashdata('delsuccess'); ?></div></div>
                              <?php endif; ?>
         

                              <!-- end of status -->
                </center>
                <div class="row">
                    <div class="col-12">
                        <div class="card card-outline-info">
                            <div class="card-header">
                                    <h4 class="m-b-0 text-white"> Notice</h4>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive ">
                                    <table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
                                                <!-- <th>Sl</th> -->
                                                <th>Title/Description</th>
                                                <th>File</th>
                                                <th>Date Created</th>
                                                <th>Actions</th>
                                            </tr>
                                        </thead>
                                        <tfoot>
                                            <tr>
                                                <!-- <th>Sl</th> -->
                                                <th>Title/Description</th>
                                                <th>File</th>
                                                <th>Date Created</th>
                                                <th>Actions</th>
                                            </tr>
                                        </tfoot>
                                        <tbody>
                                           <?php foreach($notice as $value): ?>
                                            <tr>
                                                <!-- <td><?php echo $value->id; ?></td> -->
                                                <td><?php echo $value->title; ?></td>
                                                <td><a href="<?php echo base_url(); ?>assets/images/notice/<?php echo $value->file_url; ?>" target="_blank"><?php echo $value->file_url; ?></a></td>
                                                <td><?php echo $value->date; ?></td>
                                                <td class="jsgrid-align-center ">
                                                <a href="" title="Edit" <?php if($this->session->userdata('user_type')=='EMPLOYEE'){ ?> hidden <?php } ?> class="btn btn-sm btn-info waves-effect waves-light enotice" data-id="<?php echo $value->id; ?>"><i class="fa fa-pencil-square-o"></i></a>

                                                    <!-- <a data-toggle="modal" data-target="#editnotice" data-whatever="@getbootstrap" href="<?php echo base_url();?>notice/notice_edit/<?php echo $value->id;?>" title="Edit" class="btn btn-sm btn-info waves-effect waves-light"><i class="fa fa-pencil-square-o">Edit</i></a> -->
                                                    <a onclick="return confirm('Are you sure to delete this Notice?')" href="<?php echo base_url();?>notice/Delete_notice/<?php echo $value->id;?>" title="Delete" class="btn btn-sm btn-danger waves-effect waves-light"><i class="fa fa-trash-o"> Remove Notice</i></a>
                                                </td>
                                            </tr>
                                            <?php endforeach; ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                        <!-- sample modal content -->
                        <div class="modal fade" id="noticemodel" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content ">
                                    <div class="modal-header">
                                        <h4 class="modal-title" id="exampleModalLabel1">Notice Board</h4>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    </div>
                                    <form role="form" method="post" action="Published_Notice" id="btnSubmit" enctype="multipart/form-data">
                                    <div class="modal-body">
                                            <div class="form-group">
                                                <label for="message-text" class="control-label">Notice Details</label>
                                                <textarea class="form-control" name="title" id="message-text1" required minlength="25" maxlength="150"></textarea>
                                            </div>
                                            <div class="form-group">
                                                <label class="control-label">Document</label>
                                                <label for="recipient-name1" class="control-label">Title</label>
                                                <input type="file" name="file_url" class="form-control" id="recipient-name1" required>
                                                                                                <!-- <td><mark><a href="<?php echo base_url(); ?>assets/images/notice/<?php echo $value->file_url ?>" target="_blank"><?php echo $value->file_url ?></a></mark> -->

                                            </div>
                                            <div class="form-group">
                                                <label for="message-text" class="control-label">Published Date</label>
                                                <input type="date" name="nodate" class="form-control" id="recipient-name1" required>
                                            </div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                        <button type="submit" class="btn btn-primary">Submit</button>
                                    </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <!-- /.modal --> 


                        <!-- edit modal -->
                        <div class="modal fade" id="editnotice" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content ">
                                    <div class="modal-header">
                                        <h4 class="modal-title" id="exampleModalLabel1">Edit </h4>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    </div>
                                    <form method="post" action="Update_notice" id="noticeform" enctype="multipart/form-data">
                                    <div class="modal-body">
                                        
                                        <div class="form-group">
                                       <label>Notice Details </label>
                                       <textarea class="form-control" name="title" cols="30"  rows="8" id="message-text1" required minlength="25" maxlength="150"></textarea>
<!-- <textarea name="" id="" cols="30" rows="10"></textarea> -->
                                        </div>

                                        <div class="form-group">
                                                <label class="control-label">Image</label>
                                                <label for="not-name1" class="control-label">Title</label>
                                                <input type="" name="file_url" class="form-control" id="not-name1" value="" required>


                                            </div>

                                        <!-- <div class="form-group">
                                        <label>Category Name </label>
                                        <input type="text" name="catname" class="form-control" value="" placeholder="Category name..." minlength="2" required>
                                        </div>  -->
                                        <div class="form-group">
                                                <label for="message-text" class="control-label">Published Date</label>
                                                <input type="date" name="nodate" class="form-control" id="not-name1" value="<?php echo $value->date; ?>" required>
                                            </div>                                         
                                        
                                    </div>
                                    <div class="modal-footer">
                                    <input type="hidden" name="id" value="" class="form-control" id="not-name1">                                       
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                        <button type="submit" class="btn btn-primary">Update</button>
                                    </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                         <!-- end of modal -->







                         <script type="text/javascript">
        $(document).ready(function () {
        $(".enotice").click(function (e) {
        e.preventDefault(e);
        // Get the record's ID via attribute
        var iid = $(this).attr('data-id');
        $('#noticeform').trigger("reset");
        $('#editnotice').modal('show');
        $.ajax({
        url: 'editednoticeID?id=' + iid,
        method: 'GET',
        data: '',
        dataType: 'json',
        }).done(function (response) {
        console.log(response);
        // Populate the form fields with the data returned from server
                                                            $('#noticeform').find('[name="id"]').val(response.noticevalue.id).end();
        $('#noticeform').find('[name="title"]').val(response.noticevalue.title).end();
        $('#noticeform').find('[name="file_url"]').val(response.noticevalue.file_url).end();
        $('#noticeform').find('[name="nodate"]').val(response.noticevalue.date).end();
                                                        });
        });
        });
        </script>
<?php $this->load->view('backend/footer'); ?>
