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

  }else{

    if ($atype == 'Image' || $atype == 'Document') {
      if (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('png','jpeg','jpg','doc','docx','pdf','PNG','JPEG','JPG','DOC','DOCX','PDF');
        if (in_array($ext1, $validextensions) == false) {
        $message = "Please input a valid extension";
        }else{


    $in = array('package' => $package,
          'type' => $atype,
          'content' => $uploadpic, 
          'date' => $dates, 
          'time' => $times, 
    );
    move_uploaded_file($picp, $upload_folder1);
    create('assignment',$in);
    $message = "<div style='color:#169f85'><i class='fa fa-check-circle-o fa-5x'></i><p><b>You have successfully added An Assignment</b></p></div>";

      
      }
    }
    }elseif ($atype == 'Text') {
      if (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{
      $in = array('package' => $package,
          'type' => $atype,
          'content' => $content, 
          'date' => $dates, 
          'time' => $times, 
    );
    create('assignment',$in);
    $message = "<div style='color:#169f85'><i class='fa fa-check-circle-o fa-5x'></i><p><b>You have successfully added An Assignment</b></p></div>";
    }
  }

    
    
  }
 }
?>
<script type="text/javascript">
  $(document).ready(function(){
    $("#texts").hide();
    $("#documents").hide();
    $("#atype").change(function(){
      var types = $("#atype").val();
      if (types == 'Text') {
        $("#texts").show();
        $("#documents").hide();
      }else if (types == 'Image' || types == 'Document') {
        $("#documents").show();
        $("#texts").hide();
      }else{
        $("#texts").hide();
        $("#documents").hide();
      }
    });
  });
</script>
<!-- page content -->
  
                <div class="x_panel">
                  <div class="x_title">
                    <div class="row">
                        <a href="?mod=hlecturer&link2=<?php echo $vlink2 ?>&action=assignments&point=add"><button class="btn btn-default <?php if(isset($_GET['point']) && $_GET['point'] == "add"){ echo "active";} ?>">Add Assignment</button></a>
                      <a href="?mod=hlecturer&link2=<?php echo $vlink2 ?>&action=assignments&point=view"><button class="btn btn-default <?php if(isset($_GET['point']) && $_GET['point'] == "view"){ echo "active";} ?>">View Assignments</button></a>
                    </div>
                    
                    <div class="clearfix"></div>
                  </div>
                  
                            <?php
                            if(isset($_GET['point']) && $_GET['point'] == "add"){
                              include('pages/laddassignment.php');
                            }elseif (isset($_GET['point']) && $_GET['point'] == "view" && !isset($_GET['sol'])) {
                              include('pages/lviewassignment.php');
                            }elseif (isset($_GET['point']) && $_GET['point'] == "view" && isset($_GET['sol']) && !empty($_GET['sol'])) {
                              include('pages/lsviewassignment.php');
                            }else{
                              include('pages/laddassignment.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
}
?>

