Mini Shell

Direktori : /var/www/vhosts/ccp.ac.th/smtp.ccp.ac.th/httpdocs/sp/admin/
Upload File :
Current File : /var/www/vhosts/ccp.ac.th/smtp.ccp.ac.th/httpdocs/sp/admin/edit_teacher.php

<?php

    include '../db/database.php';
    include 'function_date.php';
    
    $teacherID = $_POST['teacherID'];
    $sex = $_POST['sex'];
    $titleID = $_POST['titleID'];
    $name = $_POST['name'];
    $lastName = $_POST['lastName'];
    $noPosition = $_POST['noPosition'];
    $licenseNumber = $_POST['licenseNumber'];
    $licenseDate = $_POST['licenseDate'];
    $idCard = $_POST['idCard'];
    $birthDate = $_POST['birthDate'];
    $bloodGroup = $_POST['bloodGroup'];
    $status = $_POST['status'];
    $telephone = $_POST['telephone'];
    $dateGovernment = $_POST['dateGovernment'];
    $dateGovernmentPresent = $_POST['dateGovernmentPresent'];
    $salary = $_POST['salary'];
    $salaryPosition = $_POST['salaryPosition'];
    $salaryCost = $_POST['salaryCost'];
    $salaryCompensation = $_POST['salaryCompensation'];
    $position = $_POST['position'];
    $positionManage = $_POST['positionManage'];
    $class = $_POST['class'];
    $academic = $_POST['academic'];
    $rating = $_POST['rating'];
    $typeID = $_POST['typeID'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    $status_user = $_POST['status_user'];
    
    if ($licenseDate == ""){
        $licenseDate1 = "0000-00-00";
    }  else {
      $licenseDate1 = mydate($licenseDate);  
     }
    
     $birthDate1 = mydate($birthDate);
    
    if ($dateGovernment == ""){
       $dateGovernment1 = "0000-00-00";
    }  else {
      $dateGovernment1 = mydate($dateGovernment);  
    }
     
    $dateGovernmentPresent1 = mydate($dateGovernmentPresent);
  
    
      //ถ้ากรอก password เข้ามาก็ให้ update
    if (!empty( $password)) {
          //เข้ารหัส Password
        $salt = 'tikde78uj4ujuhlaoikiksakeidke';
        $hash_password = hash_hmac('sha256', $password, $salt);
        $sql = "UPDATE `teacher` SET `password`='$hash_password' WHERE (`teacherID`='$teacherID')";
         mysqli_query($link, $sql);
    }
    
     //ถ้าอัพเดทอัพโหลดรูปประจำตัว
    if (is_uploaded_file($_FILES['userPicture']['tmp_name'])) {
        //ลบรูปเดิมก่อน
        $sql_img = "SELECT picture FROM teacher WHERE teacherID='$teacherID'";
        $result_img = mysqli_query($link, $sql_img);
        $img_name = mysqli_fetch_row($result_img);
        @unlink('./dist/img/'.$img_name[0]);
        
        $new_image_name = 'news_'.uniqid().".".pathinfo(basename($_FILES['userPicture']['name']), PATHINFO_EXTENSION);
        $image_upload_path = "./dist/img/".$new_image_name;
        move_uploaded_file($_FILES['userPicture']['tmp_name'],$image_upload_path);
        
        $sql = "UPDATE `teacher` SET `picture`='$new_image_name' WHERE (`teacherID`='$teacherID')";
        mysqli_query($link, $sql);
    }
    
    $sql = "UPDATE `teacher` SET  `sex`='$sex',`titleID`='$titleID', `name`='$name', `lastName`='$lastName', `noPosition`='$noPosition',`licenseNumber`='$licenseNumber', `licenseDate`='$licenseDate1' ,`idCard`='$idCard', `birthDate`='$birthDate1', `bloodGroup`='$bloodGroup', `status`='$status',`telephone`='$telephone', `dateGovernment`='$dateGovernment1', `dateGovernmentPresent`='$dateGovernmentPresent1',`salary`='$salary', `salaryPosition`='$salaryPosition', `salaryCost`='$salaryCost', `salaryCompensation`='$salaryCompensation',`position`='$position', `positionManage`='$positionManage' ,`class`='$class', `academic`='$academic', `rating`='$rating', `typeID`='$typeID',`username`='$username',`status_user`='$status_user' WHERE (`teacherID`='$teacherID')";
    
    $result = mysqli_query($link, $sql);
    
    if ($result) {
        header('Content-Type: application/json');
        echo json_encode(array('status' => 'success','message' => 'แก้ไขข้อมูลเรียบร้อยแล้ว'));
    } else {
        header('Content-Type: application/json');
        $errors = "Username ซ้ำ กรุณาเปลี่ยน Username ใหม่" . mysqli_error($link);
        echo json_encode(array('status' => 'danger','message' => $errors));
    }

Zerion Mini Shell 1.0