ok

Mini Shell

Direktori : /home/ngwcolle/www/admin/
Upload File :
Current File : //home/ngwcolle/www/admin/manage-teacher.php

<?php session_start();
//DB conncetion
include_once('includes/config.php');
error_reporting(0);
//validating Session
if (strlen($_SESSION['aid']==0)) {
  header('location:logout.php');
  } else{
    function imageResize($imageResourceId,$width,$height) {
        $targetWidth = 290;
        $targetHeight = 330;  
        $targetLayer=imagecreatetruecolor($targetWidth,$targetHeight);
        imagecopyresampled($targetLayer,$imageResourceId,0,0,0,0,$targetWidth,$targetHeight, $width,$height);
        return $targetLayer;
    }
//Code for record deletion
if($_GET['teacherid']){
$teacherid=$_GET['teacherid'];
mysqli_query($con,"UPDATE tbl_teacher set status=0 where id ='$teacherid'");
echo "<script>alert('Teacher Exited Successfully');</script>";
echo "<script>window.location.href='manage-teacher.php'</script>";
          }
          
          if(isset($_POST['img_update'])){
            $imgid=$_POST['imgid'];
            $oldphotoid=$_POST['oldphotoid'];
            
if(is_array($_FILES)){ 
    $file = $_FILES['cdate']['tmp_name']; 
    $sourceProperties = getimagesize($file);
    $fileNewName = time().$_FILES['cdate']['name'];
    $folderPath = "../upload/teacher/";
    $ext = pathinfo($_FILES['cdate']['name'], PATHINFO_EXTENSION);
    $imageType = $sourceProperties[2];
    switch ($imageType) {
        case IMAGETYPE_PNG:
            $imageResourceId = imagecreatefrompng($file); 
            $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
            // imagepng($targetLayer,$folderPath. $fileNewName. "_thump.". $ext);
            imagepng($targetLayer,$folderPath. $fileNewName);
            break;

        case IMAGETYPE_GIF:
            $imageResourceId = imagecreatefromgif($file); 
            $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
            // imagegif($targetLayer,$folderPath. $fileNewName. "_thump.". $ext);
            imagepng($targetLayer,$folderPath. $fileNewName);
            break;

        case IMAGETYPE_JPEG:
            $imageResourceId = imagecreatefromjpeg($file); 
            $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
            // imagejpeg($targetLayer,$folderPath. $fileNewName. "_thump.". $ext);
            imagepng($targetLayer,$folderPath. $fileNewName);
            break;

        default:
            // echo "Invalid Image type.";
            echo '<script>alert("Invalid Image type.")</script>';
        //   exit;
        //   header("Location:manage-teacher.php");
            break;
    }
    echo $fileNewName;
    if(move_uploaded_file($file, $folderPath.$fileNewName. ".". $ext))
    {
        unlink($folderPath.$fileNewName. ".". $ext);
        unlink($folderPath.$oldphotoid);
        // unlink($oldphotoid);
        
        $query=mysqli_query($con, "UPDATE tbl_teacher set photopath='$fileNewName' where id=' $imgid'");
                            if ($query) {
                            echo '<script>alert("Teacher Image updated Successfully.")</script>';
                            echo "<script>window.location.href ='manage-teacher.php'</script>";
                            }
                            else
                            {
                            echo '<script>alert("Something Went Wrong. Please try again.")</script>';
                            }
    }
    else
    {
            echo "Failed to upload file.";
    }

    // move_uploaded_file($file, $folderPath.$fileNewName. ".". $ext);
    // unlink($folderPath.$fileNewName. ".". $ext);
    // echo "Image Resize Successfully.";
}


          }
?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Manage Teacher</title>

    <!-- Custom fonts for this template -->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link
        href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
        rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">

    <!-- Custom styles for this page -->
    <link href="vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
<style>
/*     
input[type=file]::file-selector-button {
  margin-right: 20px;
  border: none;
  background: #084cdf;
  padding: 3px 5px;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  transition: background .2s ease-in-out;
}

input[type=file]::file-selector-button:hover {
  background: #0d45a5;
} */

.btn-bs-file{
    position:relative;
}
.btn-bs-file input[type="file"]{
    position: absolute;
    top: -9999999;
    filter: alpha(opacity=0);
    opacity: 0;
    width:0;
    height:0;
    outline: none;
    cursor: inherit;
}


</style>
</head>

<body id="page-top">

    <!-- Page Wrapper -->
    <div id="wrapper">

        <!-- Sidebar -->
  <?php include_once('includes/sidebar.php');?>
        <!-- End of Sidebar -->

        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">

            <!-- Main Content -->
            <div id="content">

                <!-- Topbar -->
<?php include_once('includes/topbar.php');?>
                <!-- End of Topbar -->

                <!-- Begin Page Content -->
                <div class="container-fluid">

                    <!-- Page Heading -->
                       <div class="d-sm-flex align-items-center justify-content-between mb-4">
                        <h1 class="h3 mb-0 text-gray-800">Manage Teacher</h1>
                
                    </div>
    

                    <!-- DataTales Example -->
                    <div class="card shadow mb-4">
                        <div class="card-header py-3">
                        <div class="float-left"><h6 class="m-0 font-weight-bold text-primary">Teacher's Information</h6></div>    
                        <div class="float-right">
                            <a href="add-teacher.php" class="btn btn-success">Add New Teacher</a>
                            <a href="add-subject.php" class="btn btn-warning">Add New Subject</a>
                        </div>    
                        
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                                    <thead>
                                        <tr>
                                            <th>Sno.</th>
                                            <th>Teacher Name</th>
                                            <th>Designation</th>                                
                                             <th>Joining Date</th>
                                             <th>Image</th>
                                             <th>Status</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                  
                                    <tbody>
<?php $query=mysqli_query($con,"SELECT * from tbl_teacher order by id desc ");
$cnt=1;
while($row=mysqli_fetch_array($query)){
?>

                                        <tr>
                                            <td><?php echo $cnt;?></td>
                                            <td><?php echo $row['tname'];?></td>
                                            <td><?php echo $row['disgnation'];?></td>
                                                        <td><?php echo $row['doj'];?></td>
                                                        <td>
                                                        <img src="../upload/teacher/<?php echo $row['photopath']; ?>" alt="" class="img-responsive" height="60" width="80"/>
                                                        <form method="post"  name="adminprofile" enctype="multipart/form-data">
                                                        <div>
   <!-- <input type="file" name="myfile" /> -->
  
  <label class="btn-bs-file btn btn-xs btn-primary text-small">
  <i class="fa fa-picture-o" aria-hidden="true"></i>Browse
                <input id="file-upload"  type="file" name="cdate" onchange="return fileValidation()" />
            </label>
                                                        
<input type="hidden" name="imgid" value="<?php echo $row['id'];?>">
<input type="hidden" name="oldphotoid" value="<?php echo $row['photopath'];?>">
  <button type="submit" name="img_update" class="btn btn-sm btn-success" style="display:inline"><i class="fa fa-check" aria-hidden="true"></i></button>   
</div>
</form>                               

                                                        </td>
                                            <td>
                                                <?php if($row['status']==1)
                                                {
                                                    echo "Active";
                                                }
                                                else{
                                                    echo "Not Exist";
                                                }
                                                    ?></td>
                                            <td>

                                <a href="edit-teacher.php?teamid=<?php echo $row['id'];?>" class="btn-sm btn-primary"><i class="fa fa-edit"  aria-hidden="true"></i></a> 

                                <a href="manage-teacher.php?teacherid=<?php echo $row['id'];?>" onclick="return confirm('Do you really want to Exit the teacher?');" class="btn-sm btn-danger"><i class="fa fa-user-times" aria-hidden="true"></i></a></td>
                                        </tr>
                               <?php $cnt++;
                           } ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>

                </div>
                <!-- /.container-fluid -->

            </div>
            <!-- End of Main Content -->

            <!-- Footer -->
    <?php include_once('includes/footer.php');?>
            <!-- End of Footer -->

        </div>
        <!-- End of Content Wrapper -->

    </div>
    <!-- End of Page Wrapper -->

    <!-- Scroll to Top Button-->
    <?php include_once('includes/footer2.php');?>

    <!-- Bootstrap core JavaScript-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="js/sb-admin-2.min.js"></script>

    <!-- Page level plugins -->
    <script src="vendor/datatables/jquery.dataTables.min.js"></script>
    <script src="vendor/datatables/dataTables.bootstrap4.min.js"></script>

    <!-- Page level custom scripts -->
    <script src="js/demo/datatables-demo.js"></script>
</body>
</html>
<script>
 
 /* javascript function to validate file type */
 function fileValidation() {
     var inputElement = document.getElementById('file-upload');
     var files = inputElement.files;
     if(files.length==0){
        //  alert("Please choose a file first...");
         return false;
     }else{
         var filename = files[0].name;

         /* getting file extenstion eg- .jpg,.png, etc */
         var extension = filename.substr(filename.lastIndexOf("."));

         /* define allowed file types */
         var allowedExtensionsRegx = /(\.jpg|\.jpeg|\.png|\.gif)$/i;

         /* testing extension with regular expression */
         var isAllowed = allowedExtensionsRegx.test(extension);

         if(isAllowed){
             alert("File type is valid for the upload");
             /* file upload logic goes here... */
         }else{
             alert("Invalid File Type.Choose image/Photo file Only");
              inputElement.value = '';
             
             return false;
         }
     }
 }
 </script>

<?php } ?>

Zerion Mini Shell 1.0