<?php
if (isset($_POST['addnote'])) {
  $ntitle = $_POST['ntitle'];
  $package = $_POST['package'];
  $content = $_POST['content'];
  if (empty($ntitle) || empty($content)) {
    $message =  "<div style='color:#e6102e'><i class='fa fa-warning fa-5x'></i><p><b>Please input all empty fields</b></p></div>";

  }else{

    $fetch = $conn->query("SELECT * FROM notes WHERE title = '$ntitle'");
    $result = $fetch->fetchAll(PDO::FETCH_OBJ);
    $count = $fetch->rowCount();
    if ($count > 0) {
    $message = "<div style='color:#e6102e'><i class='fa fa-ban fa-5x'></i><p><b>You have added this title once </b></p></div>";
    }else{
    $in = array('package' => $package,
          'title' => $ntitle,
          'text' => $content, 
    );
    create('notes',$in);
    $message = "<div style='color:#169f85'><i class='fa fa-check-circle-o fa-5x'></i><p><b>You have successfully added $ntitle</b></p></div>";

      
    }
    
  }
}

?>
<!-- page content -->
  
                <div class="x_panel">
                  <div class="x_title">
                    <div class="row">
                      <a href="?mod=hlecturer&link2=<?php echo $vlink2 ?>&action=notes&point=add"><button class="btn btn-default <?php if(isset($_GET['point']) && $_GET['point'] == "add"){ echo "active";} ?>">Add Note</button></a>
                      <a href="?mod=hlecturer&link2=<?php echo $vlink2 ?>&action=notes&point=view"><button class="btn btn-default <?php if(isset($_GET['point']) && $_GET['point'] == "view"){ echo "active";} ?>">View Notes</button></a>
                    </div>
                    
                    <div class="clearfix"></div>
                  </div>
                  <?php
                  if(isset($_GET['point']) && $_GET['point'] == "add"){
                    include('pages/laddnote.php');
                  }elseif (isset($_GET['point']) && $_GET['point'] == "view") {
                    include('pages/lviewnote.php');
                  }else{
                    include('pages/laddnote.php');  
                  }
                  ?>
                  


                            </div>
                
        <!-- /page content -->
<div class="modal fade" id="myModal22" role="dialog">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
        <div class="modal-body text-center">
        <div id="inputHere">
<?php
if (isset($message)) {
echo "$message";
}
?>
        </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Ok</button>
        </div>
      </div>
    </div>
  </div>

<?php
if (isset($message)) {
?>
<script type="text/javascript">
$(document).ready(function(e) {
$('#myModal22').modal('show');
});
</script>
<?php
}
?>

