Path : /var/www/html/smart_kpp2_v2/
File Upload :
Current File : /var/www/html/smart_kpp2_v2/login.php

<?php
/** ensure this file is being included by a parent file */
defined( '_VALID_' ) or die( 'Direct Access to this location is not allowed.' );

$p = (get_magic_quotes_gpc()) ? $_GET['p']  : addslashes($_GET['p']);

$url_id = (get_magic_quotes_gpc()) ? $_GET['url_id']  : addslashes($_GET['url_id']);
$userId = (get_magic_quotes_gpc()) ? $_GET['userId']  : addslashes($_GET['userId']); //line id

	$sql_officename = "select * from system_office_name";
    $dbquery_officename = mysqli_query($connect,$sql_officename);
    $result_officename = mysqli_fetch_array($dbquery_officename);
    $office_name = $result_officename['office_name'];

    //ตรวจสอบการลงทะเบียน Line ID
    $sql_line = "select * from line_user where line_userId='$userId' ";
    $dbquery_line= mysqli_query($connect,$sql_line);
    $result_line = mysqli_fetch_array($dbquery_line);
    $totalRows_line_userId = mysqli_num_rows($dbquery_line); 
    $p_id = $result_line['person_id']; //เลข ปชช.ที่เชื่อมกับ Line 

//exit();


$user_agent = $_SERVER['HTTP_USER_AGENT'];
function getOS() { 
    global $user_agent;
    $os_platform = "desktop";
    $os_array = array(
        '/windows nt 10.0/i' => 'Windows 10',
        '/windows nt 6.3/i' => 'Windows 8.1',
        '/windows nt 6.2/i' => 'Windows 8',
        '/windows nt 6.1/i' => 'Windows 7',
        '/windows nt 6.0/i' => 'Windows Vista',
        '/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
        '/windows nt 5.1/i' => 'Windows XP',
        '/windows xp/i' => 'Windows XP',
        '/windows nt 5.0/i' => 'Windows 2000',
        '/macintosh|mac os x/i' => 'Mac OS X',
        '/mac_powerpc/i' => 'Mac OS 9',
        '/linux/i' => 'Linux',
        '/ubuntu/i' => 'Ubuntu',
        '/iphone/i' => 'iPhone',
        '/ipod/i' => 'iPod',
        '/ipad/i' => 'iPad',
        '/android/i' => 'Android',
        '/blackberry/i' => 'BlackBerry',
        '/webos/i' => 'Mobile'
    );
    foreach ($os_array as $regex => $value) { 
        if (preg_match($regex, $user_agent)) {
            $os_platform = $value;
            if(($os_platform=='Android') or ($os_platform=='BlackBerry') or ($os_platform=='iPhone') or ($os_platform=='iPad')){
                $os_platform="mobile";
            } else {
                $os_platform="desktop";
            }
        }
    }   
    return $os_platform;
}
$user_os = getOS();
?>

<!DOCTYPE html>
<html lang="th">
<head>
    <title>เข้าสู่ระบบ Smart Area : KPP2</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="images/favicon.ico">
    <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Kanit', 'Arial', sans-serif;
        }

        body {
            background: url('images/kpp2amss.jpeg') no-repeat center center fixed;
            background-size: cover;
            background-position: center;
            display: flex;
            justify-content: flex-start; /* ปรับให้ชิดซ้าย */
            align-items: center;
            min-height: 100vh;
            position: relative;
        }

        body::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.2); /* เพิ่มความมืดเล็กน้อย */
            z-index: -1;
        }

        .login {
            background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.1));
            backdrop-filter: blur(12px); /* Glassmorphism effect */
            border-radius: 15px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
            width: 400px;
            padding: 30px;
            text-align: center;
            border: 1px solid rgba(255, 255, 255, 0.3);
            margin-left: 10%; /* ห่างจากขอบซ้าย 10% */
            transition: transform 0.3s ease;
        }

        .login:hover {
            transform: translateY(-5px); /* เอฟเฟกต์ลอยเมื่อ hover */
        }

        .login-header {
            margin-bottom: 20px;
        }

        .login-header img {
            max-width: 100%;
            height: auto;
            margin-bottom: 10px;
        }

        .login-header p {
            color: #fff;
            font-size: 14px;
            opacity: 0.8;
        }

        .inputlabel {
            color: #0dcec1;
            font-weight: bold;
            font-size: 20px;
            margin-bottom: 8px;
            text-shadow: 2px 2px 1px rgba(0, 0, 0, 0.5);
        }

        .inputbox {
            width: 100%;
            padding: 12px 15px;
            margin-bottom: 15px;
            border: 2px solid rgba(255, 255, 255, 0.5);
            border-radius: 8px;
            font-size: 16px;
            background: rgba(255, 255, 255, 0.9);
            transition: border-color 0.3s, box-shadow 0.3s;
        }

        .inputbox:focus {
            border-color: #4CAF50;
            box-shadow: 0 0 8px rgba(76, 175, 80, 0.3);
            outline: none;
        }

        .button {
            padding: 12px 25px;
            background: linear-gradient(45deg, #4CAF50, #66BB6A);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-right: 10px;
        }

        .button:hover {
            background: linear-gradient(45deg, #45a049, #5cb860);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        }

        .button[type="reset"] {
            background: linear-gradient(45deg, #FF8C00, #FFB300);
        }

        .button[type="reset"]:hover {
            background: linear-gradient(45deg, #E67300, #FFA000);
        }

        .remember-forgot {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: 15px 0;
            font-size: 14px;
            color: #fff;
        }

        .remember-me input {
            margin-right: 5px;
        }

        .forgot-password a {
            color: #0dcec1;
            font-weight: bold;
            text-decoration: none;
            text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
        }

        .forgot-password a:hover {
            color: #FF8C00;
            text-decoration: underline;
        }

        .browser-recommendation {
            margin-top: 20px;
            color: #fff;
            font-size: 12px;
            opacity: 0.9;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
        }

        @media (max-width: 768px) {
            .login {
                width: 90%;
                margin-left: 5%;
                padding: 20px;
            }

            .inputbox {
                padding: 10px;
            }

            .button {
                padding: 10px 20px;
            }
        }

        .clr {
            clear: both;
        }
    </style>
    <link href="https://fonts.googleapis.com/css2?family=Kanit:wght@400;500;600&display=swap" rel="stylesheet">
    <script language="javascript" type="text/javascript">
        function setFocus() {
            document.loginForm.username.select();
            document.loginForm.username.focus();
        }
    </script>
</head>
<body onLoad="setFocus();">
    <div id="ctr" class="login">
    
        <div class="login-form">
            <div class="login-header">
                <h1><img src="images/obec.png" style="height: 120px;" alt="Smart Area Logo"></h1>
                <p>หากเป็นบุคลากรในหน่วยงาน ถ้ายังไม่มี Username และ Password สามารถ Login ด้วยเลขประจำตัวประชาชน</p>
    
   <!--div style="display: flex; gap: 10px;">
    <a href="#" style="flex: 1; text-decoration: none;">
        <div style="display: flex; align-items: center; justify-content: center; background: linear-gradient(90deg, #f0f4ff, #d9e2ff); padding: 4px; border-radius: 10px; text-align: center;">
            <span style="color: #333; font-weight: bold; margin-right: 10px;">LOGIN ด้วย</span>
            <img src="images/ThaiD.png" style="height: 38px; width: 38px; border-radius: 5px;">
        </div>
    </a>
    <a href="http://smart2.kpp2.go.th/linebot/check.php" style="flex: 1; text-decoration: none;">
        <div style="display: flex; align-items: center; justify-content: center; background: linear-gradient(90deg, #f0f4ff, #d9e2ff); padding: 4px; border-radius: 10px; text-align: center;">
            <span style="color: #333; font-weight: bold; margin-right: 10px;">LOGIN Line</span>
            <img src="images/Line.png" style="height: 38px; width: 38px; border-radius: 5px;">
        </div>
    </a>
</div -->

            </div>
            <form action="index.php" method="post" name="loginForm" id="loginForm">

            <?php if($p==""){ //login ปกติ ?>

                <div class="form-block">
                    <div class="inputlabel">ชื่อผู้ใช้งาน</div>
                    <input name="username" type="text" class="inputbox" size="15" 
                        required title="กรุณากรอกชื่อผู้ใช้"
                        oninvalid="this.setCustomValidity('กรุณากรอกชื่อผู้ใช้')"
                        oninput="this.setCustomValidity('')">
                        <div class="inputlabel">รหัสผ่าน</div>

                       
<div style="position: relative;">
    <input name="pass" type="password" class="inputbox" size="15"
        required title="กรุณากรอกรหัสผ่าน"
        oninvalid="this.setCustomValidity('กรุณากรอกรหัสผ่าน')"
        oninput="this.setCustomValidity('')">
        <button type="button" onclick="togglePassword(this)"
        style="position: absolute; right: 5px; top: 40%; transform: translateY(-50%); border: none; background: none; cursor: pointer; padding: 0 10px;">
        <svg class="eye-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#1a79ed" stroke-width="2">
            <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
            <circle cx="12" cy="12" r="3"></circle>
        </svg>
        <svg class="eye-slash-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#1a79ed" stroke-width="2" style="display: none;">
            <path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"></path>
            <path d="M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"></path>
            <line x1="1" y1="1" x2="23" y2="23"></line>
        </svg>
    </button>
</div>

<script>
function togglePassword(button) {
    const input = button.previousElementSibling;
    const eyeIcon = button.querySelector('.eye-icon');
    const eyeSlashIcon = button.querySelector('.eye-slash-icon');
    if (input.type === 'password') {
        input.type = 'text';
        eyeIcon.style.display = 'none';
        eyeIcon.style.stroke = '#FF0000'; // Red when password is visible
        eyeSlashIcon.style.display = 'block';
        eyeSlashIcon.style.stroke = '#FF0000';
    } else {
        input.type = 'password';
        eyeIcon.style.display = 'block';
        eyeIcon.style.stroke = '#1a79ed'; // Black when password is hidden
        eyeSlashIcon.style.display = 'none';
        eyeSlashIcon.style.stroke = '#1a79ed';
    }
}
</script>


                        <input name="user_os" type="hidden" value="desktop">
                    <!--input name="user_os" type="hidden" value="<?php echo $user_os ?>"-->

                    <!-- Cloudflare Turnstile -->
        <!-- div class="cf-turnstile" data-sitekey="0x4AAAAAABsKnMlhkx0HLMpn"></div><br -->
                    <div align="left">
                        <input type="submit" name="login_submit" class="button" value="เข้าสู่ระบบ" /> 
                        <input type="reset" class="button" value="Reset" />
                    </div>
                    <div class="remember-forgot">
                        <div class="remember-me">
                            <input type="checkbox" id="remember">
                            <label for="remember">จดจำฉัน</label>
                        </div>
                        <div class="forgot-password">
                            <a href="forgotpassword.php?p=chk">ลืมรหัสผ่าน</a>
                        </div>
                    </div>
                </div>

                
                <?php } //end login ปกติ ?>
          
 <?php 
 if($_GET['person_id'] != ""){
       
    
       //มาจากระบบ thaid
       //&person_id=OTQyNDIxNzY1Mzk0NTI5OTg=;
           $person_id2 = isset($_GET['person_id']) ? htmlspecialchars($_GET['person_id'], ENT_QUOTES, 'UTF-8') : '';
           // Decode
           $person_id2 = base64_decode($person_id2);
           $person_id2 = $person_id2-94238746238462099;
           if($person_id2 > ""){ 
               $p_id = $person_id2;
           }
           $person_id2 = $_SESSION ['pid'];
           /*
           if($p_id == '3430300990899'){
               $p_id = '1431000080115';
           } */
require_once "amssplus_connect.php";
//require_once "modules/permission/time_inc.php"; 
$sql_chk = "select * from system_user where person_id='$p_id'";
$dbquery_chk = mysqli_query($connect,$sql_chk);
$result1_chk = mysqli_fetch_array($dbquery_chk);
$username = $result1_chk['username'];
$pass = $result1_chk['userpass'];
$school_user = $result1_chk['school_user']; //0=area 1=school
//echo "$username";
//echo $p_id;
//echo $pass;

if($school_user == 0){ //เขต
            $sql_person = "SELECT
                person_main.id, 
                person_main.person_id, 
                person_main.prename, 
                person_main.`name`,
                person_main.surname,
                person_main.`status`, 
                person_main.pic, 
                person_position.position_name, 
                system_workgroup.workgroup_desc
            FROM
                person_main
                INNER JOIN
                person_position
                ON 
                    person_main.position_code = person_position.position_code
                INNER JOIN
                system_workgroup
                ON 
                    person_main.department = system_workgroup.workgroup
            WHERE
                person_main.person_id = '$p_id'";
}
if($school_user == 1){ //รร.
            $sql_person = "SELECT
                person_sch_main.id,
                person_sch_main.person_id,
                person_sch_main.prename,
                person_sch_main.`name`,
                person_sch_main.surname,
                person_sch_main.pic,
                person_sch_main.`status`,
                person_sch_position.position_name,
                system_school.school_code,
                system_school.school_name
            FROM
                person_sch_main
            INNER JOIN person_sch_position 
                    ON person_sch_main.position_code = person_sch_position.position_code
            INNER JOIN system_school 
                    ON person_sch_main.school_code = system_school.school_code
            WHERE
                person_sch_main.person_id = '$p_id'";
}

    $dbquery_person = mysqli_query($connect,$sql_person);
    $result_person = mysqli_fetch_array($dbquery_person);
    $total_pid = mysqli_num_rows($dbquery_person);    
    $position_code = $result_person['position_code'];
    $department = $result_person['department'];
    $id_person = $result_person['id'];
    $fullname = $result_person['name']." ".$result_person['surname'];
    $position_name = $result_person['position_name'];
    $school_name = $result_person['workgroup_desc'];


            ?>

<div id="ctr" align="center">
 
       <div class="text-center">
           <h4><font color='red'>เข้าระบบ </font><br>
               <span class="fw-bold"><font color='#fff'>ด้วยระบบพิสูจน์และยืนยันตัวตนทางดิจิทัล (Digital ID)</font></span>
           </h4>
           <h3 class="mt-3">
               <?php if ($total_pid > 0) { ?>
                <font color='red'>สวัสดีคุณ</font> <font color='#fff'><?php echo $fullname?></font>
               <?php } else { ?>
                   <span class="text-danger">ไม่พบข้อมูลท่านในระบบ โปรดติดต่อ สพท. หรือธุรการโรงเรียนเพื่อเพิ่มชื่อในระบบ</span>
               <?php } ?>
           </h3>
       </div>
       <form method="post">
           <input name="username" type="hidden" class="form-control" value="<?php echo htmlspecialchars($username); ?>">
           <input name="pass" type="hidden" class="form-control" value="<?php echo htmlspecialchars($pass); ?>">
           <input name="p" type="hidden" class="form-control" value="1">
           <input name="user_os" type="hidden" value="desktop">
           <input name="url_id" type="hidden" value="<?php echo htmlspecialchars($url_id); ?>">
           <button type="submit" name="login_submit" class="btn btn-success btn-lg btn-block"> ดำเนินการต่อไป </button>
       </form>
   </div>
 
<?php 
exit;
} 
//login thaiD 
?>


<?php if($p > ""){ //login line 

/** ensure this file is being included by a parent file */
//defined( '_VALID_' ) or die( 'Direct Access to this location is not allowed.' );
require_once "amssplus_connect.php";
//require_once "modules/permission/time_inc.php"; 
$sql_chk = "select * from system_user where person_id='$p_id'";
$dbquery_chk = mysqli_query($connect,$sql_chk);
$result1_chk = mysqli_fetch_array($dbquery_chk);
$username = $result1_chk['username'];
$pass = $result1_chk['userpass'];
//เขต
$sql_person = "select * from person_main where person_id='$p_id' ";
$dbquery_person = mysqli_query($connect,$sql_person);
$result_person = mysqli_fetch_array($dbquery_person);
$total_pid = mysqli_num_rows($dbquery_person);
$position_code = $result_person['position_code'];
$department = $result_person['department'];
$id_person = $result_person['id'];
$fullname=$result_person['name']." ".$result_person['surname'];
    //หาตำแหน่ง
    $sql_position = "select * from  person_position where position_code='$position_code' ";
    $dbquery_position = mysqli_query($connect,$sql_position);
    $result_position = mysqli_fetch_array($dbquery_position);
    $position_name = $result_position['position_name'];
    //หาหน่วยงาน
    $sql_workgroup = "select * from  system_workgroup where workgroup='$department' ";
    $dbquery_workgroup = mysqli_query($connect,$sql_workgroup);
    $result_workgroup = mysqli_fetch_array($dbquery_workgroup);
    $school_name = $result_workgroup['workgroup_desc'];
?>  


<div id="ctr" align="center">
    <table width="100%">
        <tr>
        <td><center><h3><font color='red'>สวัสดีคุณ</font> <font color='#fff'><?php echo $fullname?></font></h3>
            <h4>เข้าระบบ Smart Area YST1 ด้วย <br><font color='#0dcec1'><b>LINE Notify</b></font></h4>
            </center>
            
            <input name="username" type="hidden"  class="form-control" placeholder="ชื่อผู้ใช้งาน (Username)" size="15" value="<?php echo $username?>"/><br>
            <input name="pass" type="hidden" class="form-control" placeholder="รหัสผ่าน (Password)" value="<?php echo $pass?>"/><br>
            <input name="p" type="hidden"  class="form-control" value="1" size="15" />
            <input name="user_os" type="hidden" value="desktop">
            <input name="url_id" type="hidden" size="100" value="<?php echo $url_id ?>">

            <button type="submit" name="login_submit" class="btn btn-success btn-lg btn-block"> กดปุ่มเพื่อเข้าสู่ระบบ </button>
            </td>
        </tr>
    </table>  
</div>  
<?php } //end login line ?>




            </form>
            <div class="browser-recommendation">
                <p>SmartArea by DLiCT YST1.GO.TH V.6.65 (2025)<br>กลุ่มส่งเสริมการศึกษาทางไกล เทคโนโลยีสารสนเทศและการสื่อสาร</p>
                <p>แนะนำให้ใช้บราวเซอร์ Google Chrome</p>
            </div>
        </div>
    </div>
    <noscript>
        <div style="color: red; text-align: center; margin-top: 20px; background: white; padding: 10px; border-radius: 5px;">
            !Warning! Javascript must be enabled for proper operation of the Administrator
        </div>
    </noscript>
    <div class="clr"></div>
    
</body>
</html>