Mini Shell

Direktori : /var/www/vhosts/ccp.ac.th/smtp.ccp.ac.th/httpdocs/new/sp/admin/
Upload File :
Current File : /var/www/vhosts/ccp.ac.th/smtp.ccp.ac.th/httpdocs/new/sp/admin/insert_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);
   
    //เช็ค Username ซ้ำกันหรือไม่
    $sql_user = "SELECT username FROM teacher WHERE username='$username'";
    $result_user = mysqli_query($link, $sql_user);
    $is_user = mysqli_num_rows($result_user);
    if ($is_user == 1) {
        header('Content-Type: application/json');
        $errors = "Username มีคนใช้แล้ว กรุณาเปลี่ยน Username ใหม่" . mysqli_error($link);
        echo json_encode(array('status' => 'danger','message' => $errors));
        exit;
    }
    
    //เข้ารหัส Password
    $salt = 'tikde78uj4ujuhlaoikiksakeidke';
    $hash_password = hash_hmac('sha256', $password, $salt);
    
    //อัพโหลดรูปประจำตัว 
    if (is_uploaded_file($_FILES['userPicture']['tmp_name'])) {
        $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);
    } else {
        $new_image_name = "";
    }
    
    $sql = "INSERT INTO `teacher` (`teacherID`, `sex`, `titleID`, `name`, `lastName`, `noPosition`, `licenseNumber`, `licenseDate`, `idCard`, `birthDate`, `bloodGroup`, `status`,  `telephone`, `dateGovernment`, `dateGovernmentPresent`, `salary`, `salaryPosition`, `salaryCost`, `salaryCompensation`, `position`, `positionManage`, `class`, `academic`, `rating`, `typeID`,`username`,`password`,`status_user`, `picture`) VALUES 
          ('$teacherID', '$sex', '$titleID', '$name', '$lastName', '$noPosition', '$licenseNumber', '$licenseDate1', '$idCard', '$birthDate1', '$bloodGroup', '$status', '$telephone','$dateGovernment1', '$dateGovernmentPresent1', '$salary', '$salaryPosition', '$salaryCost', '$salaryCompensation','$position', '$positionManage', '$class', '$academic ', '$rating', '$typeID','$username','$hash_password','$status_user', '$new_image_name')";
    $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 = "รหัสบุคลากร ซ้ำ กรุณาเปลี่ยน รหัสบุคลากร ใหม่" . mysqli_error($link);
        echo json_encode(array('status' => 'danger','message' => $errors));
    }

Zerion Mini Shell 1.0