<?php
if (isset($_POST['add'])) {
  $ntitle = $_POST['ntitle'];
  $package = $_POST['package'];
  $type = $_POST['type'];
  $content = $_POST['content'];
  $file = $_FILES['pfile']['tmp_name'];
  $date = date('l M d, Y H:i');
  if (empty($ntitle) || empty($file)) {
    $message =  "<div style='color:#e6102e'><i class='fa fa-warning fa-5x'></i><p><b>Please input all empty fields</b></p></div>";

  }else{

    $temporary = explode("." , $_FILES [ "pfile" ][ "name" ]);
        $file_extension = end ($temporary );
        $pic = $_FILES['pfile']['name'];
        $picp = $_FILES['pfile']['tmp_name'];
        $pics = $_FILES['pfile']['size'];


        $hash = sha1($pic);
        $random = rand(000,999);
        $comb = $hash.$random;

        $ext1 = pathinfo($pic, PATHINFO_EXTENSION);
        $ext1 = strtolower($ext1);

        $upload_folder1 = "document/".$comb.".".$ext1;
        $uploadpic = $comb.".".$ext1;

        $validextensions = array('mp3','MP3','avi','AVI');
        if (in_array($ext1, $validextensions) == false) {
        $message = "Please input a valid extension";
        }else{



    $fetch = $conn->query("SELECT * FROM documents WHERE package = '$vlink2' AND type = '$type' AND 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,
          'type' => $type,
          'title' => $ntitle,
          'description' => $content, 
          'doc' => $uploadpic, 
    );
    move_uploaded_file($picp, $upload_folder1);
    create('documents',$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=audios&point=add"><button class="btn btn-default <?php if(isset($_GET['point']) && $_GET['point'] == "add"){ echo "active";} ?>">Add Audio</button></a>
                      <a href="?mod=hlecturer&link2=<?php echo $vlink2 ?>&action=audios&point=view"><button class="btn btn-default <?php if(isset($_GET['point']) && $_GET['point'] == "view"){ echo "active";} ?>">View Audio</button></a>
                    </div>
                    
                    <div class="clearfix"></div>
                  </div>
                  <?php
                  if(isset($_GET['point']) && $_GET['point'] == "add"){
                    include('pages/laddaudio.php');
                  }elseif (isset($_GET['point']) && $_GET['point'] == "view") {
                    include('pages/lviewaudio.php');
                  }else{
                    include('pages/laddaudio.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
}
?>

