<?php //print_r($usertype);exit; ?>
    <section class="content-header">
      <h1>
        Message
      </h1>
      <ol class="breadcrumb">
        <li><a href="<?php echo base_url().'admin';?>"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">List</li>
      </ol>
    </section>

    <section class="content">
      <div class="row">
        <?php echo $this->utility->showMsg();?>
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">Management</h3>
             </div>
               
              <div></div>
            <!-- /.box-header -->
            <div class="box-body">
            <form action="" id="search_frm" method="post" style="margin-bottom: 5%;">
              <input type="text" name="search" class="form-control" placeholder="Search by message keyword" value="<?php if($this->input->post('search')) { echo $this->input->post('search'); }?>" style="width: 25%; float: right;">
              <input type="text" name="search_name" class="form-control" placeholder="Search by from username" value="<?php if($this->input->post('search_name')) { echo $this->input->post('search_name'); }?>" style="width: 25%; float: right;">
              <input type="submit" class="btn btn-primary" value="Search" style="float: right;">
            </form>
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>To username</th>
                  <th>From username</th>
                  <th>Time</th>
                  <th>Message</th>
                  <?php if(chkWritePermission('All_Message',$this->session->userdata('admin_id'))!=0 || $this->session->userdata('admin_id')=='19624' ){ ?>
                  <th>Action</th>
                  <?php } ?>
                </tr>
                </thead>
                 <?php if(count($todaysComments)>0)
                {?>
                <tbody>
               <?php
                $i=1;
                foreach ($todaysComments as $data) 
                {
                  $toUserData = getValue('feu_userdetails',array('user_id'=>$data['user_id']));
                  if(!empty($toUserData))
                  {
                    $fileData = getFiles($toUserData['avatar_file_id']);
                    $usrname = $toUserData['username'];
                    //print_r($fileData); //die;
                    if(!empty($fileData))
                    {
                      if(file_exists(FCPATH.'assets/userfiles/'.$fileData['path'].'/'.$fileData['filename'].'.'.$fileData['extension']))
                      {
                        $imageFile = base_url().'assets/userfiles/'.$fileData['path'].'/'.$fileData['filename'].'.'.$fileData['extension'];
                      }
                      else
                      {
                        $imageFile = base_url().'assets/images/default-avatar.jpg';
                      }
                    }
                    else
                    {
                        $imageFile = base_url().'assets/images/default-avatar.jpg';
                    }
                  }
                ?>
                <tr>
                    <td>
                      <img class="direct-chat-img" src="<?php echo $imageFile; ?>" title=""> 
                      <br/>
                      <?php echo $usrname; ?>
                    </td>
                    <td>
                      <?php if(!empty($data['filename']) && file_exists(FCPATH.'assets/userfiles/'.$data['path'].'/'.$data['filename'].'.'.$data['extension']))
                          {
                      ?>
                        <img class="direct-chat-img" src="<?php echo base_url();?>assets/userfiles/<?php echo $data['path'].'/'.$data['filename'].'.'.$data['extension']; ?>" title="">
                      <?php  } else { ?>
                        <img class="direct-chat-img" src="<?php echo base_url();?>assets/images/default-avatar.jpg" title="<?php echo $data['username']; ?>">
                      <?php } ?>
                      <br/>
                      <?php echo $data['username']; ?>
                    </td>
                    <td><?php echo date('d-m-Y h:i:s',$data['created']);?></td>
                    <td><?php echo $data['text'];?></td>
                    <?php if(chkWritePermission('All_Message',$this->session->userdata('admin_id'))!=0 || $this->session->userdata('admin_id')=='19624' ){ ?>
                    <td>
                      <a href="<?php echo base_url();?>admin/message/deleteComment/<?php echo $data['msg_id']; ?>/<?php echo str_replace('/','-',uri_string()); ?>" title="Delete" onclick="return confirm('Are you sure to delete ?');"><span class="fa fa-ban"></span></a>
                    </td> 
                    <?php } ?>
                </tr>

               <?php $i++; } ?>

                </tbody>
                <?php } ?>
                <tfoot>
               
                </tfoot>
              </table>
              <?php if($this->uri->segment(3)!='expiredusers'){ ?>
                <div class="custom_pagination"><?php echo $link; ?></div>
              <?php } ?>  
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <style type="text/css">
      .dataTables_info, .dataTables_paginate {   
      display: none;
      }
    </style>

    
<script>
  $(function () {
    $("#example1").DataTable();

    $('.custom_pagination a').click(function(e){
      e.preventDefault();
      $('#search_frm').attr('action',$(this).attr('href'));
      $('#search_frm').submit();
    })
  });
</script>
<style type="text/css">
  .dataTables_length, .dataTables_filter{ display: none; }
</style>