MMCT TEAM
Server IP : 2a02:4780:3:1493:0:3736:a38e:7  /  Your IP : 216.73.216.139
Web Server : LiteSpeed
System : Linux sg-nme-web1393.main-hosting.eu 4.18.0-553.40.1.lve.el8.x86_64 #1 SMP Wed Feb 12 18:54:57 UTC 2025 x86_64
User : u926327694 ( 926327694)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u926327694/domains/smsoft.in/public_html/demo/src/../../att/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u926327694/domains/smsoft.in/public_html/demo/src/../../att/attendance.php
<?php
$qs = str_replace('$', '', $_SERVER['QUERY_STRING']); // get rid of the $
$qs = str_replace('*', '', $qs); // get rid of the *

$submissions = explode(',', $qs); // split the subs

$SID = ""; // store for sid
$MID = ""; // store for mid

include "dbconnect.php";

// loop
for ($i = 0; $i < count($submissions); $i++) {
    $sections = explode('&', $submissions[$i]);

    if ($i == 0) {
        $SID = $sections[0];
        $MID = $sections[1];
        $RFID = $sections[2];
        $DOT = $sections[3];
    } else {
        $RFID = $sections[0];
        $DOT = $sections[1];
    }


    //select school
    $con_school = mysqli_connect($servername, $username, $password, $dbname);
    $sel_school = mysqli_query($con_school, "select * from schools where bio_machine_id='$MID'");
    
   // echo   "select * from schools where bio_machine_id='$MID'"; exit;
    $main_username = "";
    $main_password = "";
    $main_dbname = "";
    //for sms
    $smsId = "";
    $smsAPI = "";
    $smsURL = "";
    $whatsapp_api_key = '';
    $whatsapp_api_url = '';
    $whatsapp_instance_id = '';
    $whatsapp_type = '';
    $smsTempId = "";
    $smsIsActive = 0;
    $smsIsActiveWhatsapp = 0;
    $smsIsActiveWhatsapp_stu = 0;
    $sms_schoolname = "";
    $schoolcode = "";
    $receiver_admin = "";
    $smsIsActive_stu = 0;
    $smsIsActive_stu_in = 0;
    $smsIsActive_stu_out = 0;
    $smsIsActive_stu_out_both = 0;
    $second_from = "00:00:00";
    $second_to = "00:00:00";
    $is_active_second_time = 1;
    while ($row_school = mysqli_fetch_array($sel_school)) {
        $main_username = $row_school['dbUsernameStudent'];
        $main_password = $row_school['dbPassword'];
        $main_dbname = $row_school['dbStudent'];

        //for sms
        $smsId = $row_school['smsId'];
        $smsAPI = $row_school['smsAPI'];
        $smsURL = $row_school['smsURL'];
        $smsTempId = $row_school['smsTempIdAtten'];
        $smsIsActive = $row_school['smsIsActive_Teacher'];
        $smsIsActiveWhatsapp = $row_school['smsIsActive_Teacher_whatsapp'];
        $smsIsActiveWhatsapp_stu = $row_school['smsIsActive_Student_whatsapp'];
        $smsIsActive_stu = $row_school['smsIsActive_Student'];
        $smsIsActive_stu_in = $row_school['smsIsActive_Student_in'];
        $smsIsActive_stu_out = $row_school['smsIsActive_Student_out'];
        $smsIsActive_stu_out_both = $row_school['smsIsActive_stu_out_both'];
        $sms_schoolname = $row_school['sms_schoolname'];
        $schoolcode = $row_school['schoolCode'];
        $receiver_admin = $row_school['Bio_SMS'];
        
        $second_from = $row_school['second_from'];
        $second_to = $row_school['second_to'];
        $is_active_second_time = $row_school['is_active_second_time'];
        
        $whatsapp_api_key = $row_school['whatsapp_api_key'];
	    $whatsapp_api_url = $row_school['whatsapp_api_url'];
	    $whatsapp_instance_id = $row_school['whatsapp_instance_id'];
	    $whatsapp_type = $row_school['whatsapp_type'];
    }



    $con = mysqli_connect("localhost", $main_username, $main_password, $main_dbname);
    // Check connection
    if (!$con) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
        exit;
    }

    $string = $DOT;

    $day = substr($string, 0, 2);
    $month = substr($string, 2, 2);
    $year = substr($string, 4, 4);

    $hour = substr($string, 8, 2);
    $min = substr($string, 10, 2);
    $sec = substr($string, 12, 2);

    $result_date = $year . '-' . $month . '-' . $day;
    $result_time = $hour . ':' . $min . ':' . $sec;

    if($RFID != '0' && $RFID != '')
    {
        // check register student base on rfid
        $chk_reg = mysqli_query($con, "SELECT * FROM `student_registration` WHERE  `RFID`='$RFID'");
        
        if(mysqli_num_rows($chk_reg) > 0) {
            mysqli_query($con, "ALTER TABLE `attendreports`  ADD `TimeIN` TIME NOT NULL  AFTER `TimeOfTransaction`,  ADD `TimeOUT` TIME NOT NULL  AFTER `TimeIN`;");
        
            $insert = mysqli_query($con, "INSERT INTO `attendreports`(`OrgId`, `MachineId`, `RFId`, `DateOfTransaction`, `TimeIN`, `TimeOUT`) VALUES ('$SID','$MID','$RFID','$result_date','$result_time','$result_time')");
        
            if ($insert) {
                $result_check = mysqli_query($con, "select * from attendence as att inner join student_registration as st on st.S_id=att.S_id where att.date='$result_date' and st.RFId='$RFID' and (att.IN_TIME != '00:00:00' OR att.IN_TIME!='')");
                $result_check1 = mysqli_num_rows($result_check);
                if ($result_check1 == 1) {
                    // this condition for out attedance set from time and to time between this time only make absent this is work only when we can make is_active_second_time = 1
                    if((strtotime($second_from)<=strtotime($result_time) && strtotime($second_to)>=strtotime($result_time)) || $is_active_second_time=="0")
                    {
                        $result_check_sql_first_time = mysqli_query($con,"select * from attendence as att inner join student_registration as st on st.S_id=att.S_id where att.date='$result_date' and st.RFId='$RFID' and (att.OUT_TIME = '00:00:00' OR att.OUT_TIME = '')");
                        $out_first_time = mysqli_num_rows($result_check_sql_first_time);
                        $result_student = mysqli_query($con, "select att.id as AttendanceId from attendence as att inner join student_registration as st on st.S_id=att.S_id where att.date='$result_date' and st.RFId='$RFID' and (att.IN_TIME != '00:00:00' OR att.IN_TIME!='')");
                        $res_student = mysqli_fetch_array($result_student);
                        $AttendanceId = $res_student['AttendanceId'];
                        mysqli_query($con, "UPDATE `attendence` SET `OUT_TIME` = '$result_time' where id=$AttendanceId");
            
                        $res15 = mysqli_query($con, "SELECT * FROM `student_registration` WHERE  `RFID`='$RFID'");
                        $res16 = mysqli_fetch_array($res15);
            
                        if ($res16['Class'] == "Teacher") {
                            $result_time_123 = mysqli_query($con, "select min(AttendanceId) from attendreports where `DateOfTransaction`='$result_date' and `RFId`='$RFID'");
                            $result_student = mysqli_fetch_array($result_time_123);
            
                            $result_time11 = mysqli_query($con, "select * from attendreports where AttendanceId=$result_student[0]");
                            $result_student1_123 = mysqli_fetch_array($result_time11);
                                
                            $new_time_format_in = Date('h:ia',strtotime($result_student1_123['TimeIN']));
                            $new_time_format_out = Date('h:ia',strtotime($result_time));
                            
                            if($schoolcode == 'HMBEG') {
                                $bd = "on ". $result_date . " " . $new_time_format_out." left at ";
                            }
                            else {
                                $bd = "Out ".$result_date . " " . $new_time_format_out;
                            }
                            if ($smsIsActive == "1" && $smsIsActive_stu_out == "1") {
                                if($out_first_time > 0) {
                                    sendAttensms($res16['Name'], $bd, $sms_schoolname, $res16['Communication_number'], $smsURL, $smsAPI, $smsId, $smsTempId, $schoolcode);
                                }
                            }
                            if ($smsIsActiveWhatsapp == "1" && $smsIsActive_stu_out == "1") {
                                if($out_first_time > 0) {
                                    $message_wp = "Dear ".$res16['Name'].",\nPlease be informed that you left at ".$sms_schoolname." on ". $result_date . " " . $new_time_format_out."\n Thank You.";
                                    sendAttenWhatsapp($res16['Communication_number'], $whatsapp_api_key, $whatsapp_api_url, $whatsapp_instance_id, $whatsapp_type, $message_wp);
                                }
                            }
                            if ($smsIsActive == "1" && $smsIsActive_stu_out_both == "1") {
                                $bd = $result_date . " " . $new_time_format_in . "-" . $new_time_format_out;
                                if($out_first_time > 0) {
                                    sendAttensms($res16['Name'], $bd, $sms_schoolname, $res16['Communication_number'], $smsURL, $smsAPI, $smsId, $smsTempId, $schoolcode);
                                }
                            }
                            if ($smsIsActiveWhatsapp == "1" && $smsIsActive_stu_out_both == "1") {
                                if($out_first_time > 0) {
                                    $message_wp = "Dear ".$res16['Name'].",\nPlease be informed that you arrived at ".$sms_schoolname." on ". $result_date . " " . $new_time_format_in." and left at ". $result_date . " " . $new_time_format_out."\n Thank You.";
                                    sendAttenWhatsapp($res16['Communication_number'], $whatsapp_api_key, $whatsapp_api_url, $whatsapp_instance_id, $whatsapp_type, $message_wp);
                                }
                            }
                        } else {
                            $result_time_123 = mysqli_query($con, "select min(AttendanceId) from attendreports where `DateOfTransaction`='$result_date' and `RFId`='$RFID'");
                            $result_student = mysqli_fetch_array($result_time_123);
            
                            $result_time11 = mysqli_query($con, "select * from attendreports where AttendanceId=$result_student[0]");
                            $result_student1_123 = mysqli_fetch_array($result_time11);
                                
                            $new_time_format_in = Date('h:ia',strtotime($result_student1_123['TimeIN']));
                            $new_time_format_out = Date('h:ia',strtotime($result_time));
                            
                            if ($smsIsActive_stu == "1" && $smsIsActive_stu_out == "1") {
                                if($schoolcode == 'HMBEG') {
                                    $bd = "on ". $result_date . " " . $new_time_format_out." left at ";
                                }
                                else {
                                    $bd = "Out ".$result_date . " " . $new_time_format_out;
                                }
            
                                if($out_first_time > 0) {
                                    sendAttensms($res16['Name'], $bd, $sms_schoolname, $res16['Communication_number'], $smsURL, $smsAPI, $smsId, $smsTempId, $schoolcode);
                                }
                            }
                            
                            if ($smsIsActiveWhatsapp_stu == "1" && $smsIsActive_stu_out == "1") {
                                if($out_first_time > 0) {
                                    $name_wp = $res16['Name'];
                                    $message_wp = "Dear parent,\nkindly note your son/daughter ".$name_wp." is left at ".$sms_schoolname." on ".$result_date . " " . $new_time_format_out."\n Thank You.";
                                    sendAttenWhatsapp($res16['Communication_number'], $whatsapp_api_key, $whatsapp_api_url, $whatsapp_instance_id, $whatsapp_type, $message_wp);
                                }
                            }
                            
                            if ($smsIsActive_stu == "1" && $smsIsActive_stu_out_both == "1") {
                                $bd = $result_date . " " . $new_time_format_in . "-" . $new_time_format_out;
                                if($out_first_time > 0) {
                                    sendAttensms($res16['Name'], $bd, $sms_schoolname, $res16['Communication_number'], $smsURL, $smsAPI, $smsId, $smsTempId, $schoolcode);
                                }
                            }
                            
                            if ($smsIsActiveWhatsapp_stu == "1" && $smsIsActive_stu_out_both == "1") {
                                if($out_first_time > 0) {
                                    $message_wp = "Dear parent,\nkindly note your son/daughter ".$res16['Name'].", is arrived at ".$sms_schoolname." on ". $result_date . " " . $new_time_format_in." and left at ". $result_date . " " . $new_time_format_out."\n Thank You.";
                                    sendAttenWhatsapp($res16['Communication_number'], $whatsapp_api_key, $whatsapp_api_url, $whatsapp_instance_id, $whatsapp_type, $message_wp);
                                }
                            }
                        }
                    }
                } else {
                    $result_time = mysqli_query($con, "select min(AttendanceId) from attendreports where `DateOfTransaction`='$result_date' and `RFId`='$RFID'");
                    $result_student = mysqli_fetch_array($result_time);
        
                    $result_time11 = mysqli_query($con, "select * from attendreports where AttendanceId=$result_student[0]");
                    $result_student1 = mysqli_fetch_array($result_time11);
        
                    $res15 = mysqli_query($con, "SELECT * FROM `student_registration` WHERE  `RFID`='$result_student1[RFId]'  ");
                    $res16 = mysqli_fetch_array($res15);
        
                    $orderdate = explode('-', $result_date);
                    $year = $orderdate[0];
                    $month   = $orderdate[1];
                    $day  = $orderdate[2];
        
                    $S_id = $res16['S_id'];
                    mysqli_query($con, "INSERT INTO `attendence`(`S_id`, `Class`, `Division`, `Subject`, `Roll_number`, `Name`, `Sex`, `Mobile`, `date`, `Status`, `DD`, `MM`, `YYYY`, `Nature_Student`, `IN_TIME`, `OUT_TIME`, `Att_Time`) VALUES ('$S_id','$res16[Class]','$res16[Division]','Day', '$res16[Roll_number]', '$res16[Name]', '$res16[Sex]','$res16[Communication_number]','$result_date', 'PRESENT', '$day', '$month', '$year','$res16[Nature_Student]','$result_student1[TimeIN]','','$result_student1[DateOfTransaction]')") or die("error");
        
                    if ($res16['Class'] == "Teacher") {
                        $result_time_123 = mysqli_query($con, "select min(AttendanceId) from attendreports where `DateOfTransaction`='$result_date' and `RFId`='$RFID'");
                        $result_student = mysqli_fetch_array($result_time_123);
            
                        $result_time11 = mysqli_query($con, "select * from attendreports where AttendanceId=$result_student[0]");
                        $result_student1_123 = mysqli_fetch_array($result_time11);
                                
                        $new_time_format_in = Date('h:ia',strtotime($result_student1_123['TimeIN']));
                        $new_time_format_out = Date('h:ia',strtotime($result_time));
                                
                        if($schoolcode == 'HMBEG') {
                            $bd = "on ". $result_date . " " . $new_time_format_in." reached at ";
                        }
                        else {
                            $bd = "In ".$result_date . " " . $new_time_format_in;
                        }
                                
                        if ($smsIsActive == "1" && $smsIsActive_stu_in == "1") {
                            sendAttensms($res16['Name'], $bd, $sms_schoolname, $res16['Communication_number'], $smsURL, $smsAPI, $smsId, $smsTempId, $schoolcode);
                        }
                        
                        if ($smsIsActiveWhatsapp == "1" && $smsIsActive_stu_in == "1") {
                            $message_wp = "Dear ".$res16['Name'].",\nPlease be informed that you arrived at ".$sms_schoolname." on ". $result_date . " " . $new_time_format_in."\n Thank You.";
                            sendAttenWhatsapp($res16['Communication_number'], $whatsapp_api_key, $whatsapp_api_url, $whatsapp_instance_id, $whatsapp_type, $message_wp);
                        }
                    }
                    else {
                        $result_time_123 = mysqli_query($con, "select min(AttendanceId) from attendreports where `DateOfTransaction`='$result_date' and `RFId`='$RFID'");
                        $result_student = mysqli_fetch_array($result_time_123);
            
                        $result_time11 = mysqli_query($con, "select * from attendreports where AttendanceId=$result_student[0]");
                        $result_student1_123 = mysqli_fetch_array($result_time11);
                                
                        $new_time_format_in = Date('h:ia',strtotime($result_student1_123['TimeIN']));
                        $new_time_format_out = Date('h:ia',strtotime($result_time));
                                
                        if($schoolcode == 'HMBEG') {
                            $bd = "on ". $result_date . " " . $new_time_format_in." reached at ";
                        }
                        else {
                            $bd = "In ".$result_date . " " . $new_time_format_in;
                        }
                                
                        if ($smsIsActive_stu == "1" && $smsIsActive_stu_in == "1") {
                            sendAttensms($res16['Name'], $bd, $sms_schoolname, $res16['Communication_number'], $smsURL, $smsAPI, $smsId, $smsTempId, $schoolcode);
                        }
                        
                        if ($smsIsActiveWhatsapp_stu == "1" && $smsIsActive_stu_in == "1") {
                            $bd_wp = $result_date . " " . $new_time_format_in." reached at ";
                            $name_wp = $res16['Name'];
                            $message_wp = "Dear parent,\nkindly note your son/daughter ".$name_wp." is arrived at ".$sms_schoolname." on ".$result_date . " " . $new_time_format_in."\n Thank You.";
                            sendAttenWhatsapp($res16['Communication_number'], $whatsapp_api_key, $whatsapp_api_url, $whatsapp_instance_id, $whatsapp_type, $message_wp);
                        }
                    }
                }
            } else {
                echo 'Values are not registered';
            }
        }
        else {
            /*$log = Date('d-m-Y H:i:s')." = RFID =  ".$RFID.' school = '.$schoolcode."\n";
            file_put_contents('./temp.log', $log, FILE_APPEND);*/
        }
    }
    
}

if ($RFID != "") {
    //Successfully received/inserted the data
    echo '$RFID=0#';
}

MMCT - 2023