<?php require_once('../auth/auth.php');
    if(@$_GET['n_id']){
        $n_id= $_GET['n_id'];
        @$note_query= mysqli_query($conn,"SELECT * FROM notebook WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND n_id='$n_id'  LIMIT 1 ") or die (mysqli_error($conn));
        $row_not= mysqli_fetch_assoc ($note_query);
    }
?>
<!--<script src="https://cdn.ckeditor.com/4.20.2/standard/ckeditor.js"></script>-->
<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-6">
        <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
          <div class="card-header" style="padding: 5px 8px;"><h3 class="card-title"> <?php echo language(401); ?>  </h3> <div class="card-tools">
          <button type="button" class="btn btn-tool" data-card-widget="remove"> <i class="fas fa-times"></i>  </button> </div>
        </div>
        <form id="note_form" action="#" method="post" autocomplete="off">
          <?php if(isset($_GET['n_id'])){  ?>
          <input type="hidden" name="n_id" value="<?php echo @$n_id ;?>"/>
          <?php }else{?>
          <input type="hidden" name="n_id" value="0"/>
          <?php } ?>
          <div class="card-body">
            <div class="col-md-12">
              <div class="row">
                <div class="col-md-12 product">
                  <div class="form-group">
                    <label> <?php echo language(402); ?> <b class="text-danger"> *</b></label>
                    <input type="text" name="note_head" class="form-control form-control-sm"
                    value="<?php echo @$row_not['note_head'];?>" required="true">
                  </div>
                </div>
                <div class="col-md-12 product">
                  <div class="form-group">
                    <label> <?php echo language(403); ?> <b class="text-danger"> *</b></label>
                    <textarea class="form-control form-control-sm" name="editor"   cols="30" rows="10"> <?php echo @$row_not['note_body']; ?> </textarea>
                  </div>
                </div>
              </div>
              <center>
              <div class="card-footer" style="padding: 8px 5px;">
                <button type="submit" id="save" class="btn btn-success btn-xs"><?php if (@$_GET['n_id']) {echo  language(25);}else{echo language(23);}?></button>
                <button type="reset" class="btn btn-secondary btn-xs"><?php echo language(24);?></button>

              </div>
              </center>
            </div>
          </div>
        </form>
      </div>
    </div>
    <!--  -->
    <div class="col-md-6">
      <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
        <div class="card-header" style="padding: 5px 8px;"><h3 class="card-title"> <?php echo language(404); ?> </h3> <div class="card-tools">
        <button type="button" class="btn btn-tool" data-card-widget="remove"> <i class="fas fa-times"></i>  </button> </div>
      </div>
      <tr>
        <th rowspan="3"  class="text-center" >
          <input type="text" id="search" class="form-control form-control-sm search"  placeholder="searching" required="true" style="border-radius: ;border:1px solid primary;width:100%; text-align:center;">
        </th>
      </tr>
      <table class="table-sm table" cellpadding="0" cellspacing="0">
        <thead>
          <tr class="sticky-top">
            <th class="text-center" style="width:5%;"><?php echo language(15); ?></th>
            <th class="text-center" style="width:25%;"><?php echo language(402); ?> </th>
            <th class="text-center" style="width:20%;"><?php echo language(403); ?></th>
            <th class="text-center" style="width:10%;"><?php echo language(214); ?> </th>
            <th class="text-center" style="width:10%;"><?php echo language(131); ?> </th>
            <th class="text-center" style="width:10%;"># </th>
          </tr>
        </thead>
        <tbody id="colview" class="searchtable">
          <?php
          $note_query_data=  mysqli_query($conn,"SELECT `n_id`, `coid`, `bid`, `brid`, `note_head`, `note_body`, `userid`, `date`, `active` FROM `notebook` WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND userid='$uid'  ");
          $i=0;
          while ($row_nv= mysqli_fetch_array ($note_query_data) ){ ?>
          <tr class="btn-outline-dark tr-hover"  onclick="pagecall('../notebook/note_index.php?n_id='+'<?php echo $row_nv['n_id'];?>','#home')">
            <td class="text-center"><?php echo ++$i; ?></td>
            <td><?php echo $row_nv['note_head']; ?></td>
            <td><?php echo $row_nv['note_body']; ?></td>
            <td class="text-center"><?php  $ttttt = $row_nv['userid'];
              echo $usessrname=mysqli_fetch_assoc(mysqli_query($conn,"SELECT username FROM user WHERE  us_coid='$coid' AND uid='$ttttt' LIMIT 1 "))['username']; ?>
            </td>
            <td class="text-center"><?php echo $row_nv['date']; ?></td>
            <td class="text-center" onclick="not_delete(<?php echo $row_nv['n_id'];?>)"> <i class="fa fa-trash"></i></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>
    </div>
  </div>
</div>
</div>
</section>
<script>
    function not_delete(n_id) {
      $.post("../notebook/note_index_db.php",{del_n_id : n_id},
        function(data){
        pagecall('../notebook/note_index.php','#home',0);
        });
    }
</script>
<script>
// $(document).ready(function() {
// CKEDITOR.replace('editor', {
// toolbarGroups: [{
// "name": "basicstyles",
// "groups": ["basicstyles"]
// },
// {
// "name": "links",
// "groups": ["links"]
// },
// {
// "name": "paragraph",
// "groups": ["list", "blocks"]
// },
// {
// "name": "document",
// "groups": ["mode"]
// },
// {
// "name": "insert",
// "groups": ["insert"]
// },
// {
// "name": "styles",
// "groups": ["styles"]
// }],
// removeButtons: 'Underline,Strike,Subscript,Superscript,Anchor,Styles,Specialchar,PasteFromWord'
// });
// });
</script>
<script>
$(document).ready(function() {
$('#note_form').on('submit', function(e){
$('#save').prop('disabled', true);
$('#save').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> '+'Loading...');
e.preventDefault();
$.post("../notebook/note_index_db.php",$(this).serialize(),function(data){
$('#note_form')[0].reset();
$('#save').prop('disabled', false);
$('#save').html('Save');
pagecall('../notebook/note_index.php','#home');

});
});
$('.search').on('keyup',function(){
var searchTerm = $(this).val().toLowerCase();
$('.searchtable tr').each(function(){
var lineStr = $(this).text().toLowerCase();
if(lineStr.indexOf(searchTerm) === -1){
$(this).hide();
}else{
$(this).show();
}
});
});
});
</script>