<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2/25/2022
 * Time: 12:12 PM
 */

class Tollgate extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function gate($source, $destination)
    {
        $sql = "SELECT * FROM `gatelist` WHERE source='" . $source . "' and destination='" . $destination . "' ";
        $query = $this->db->query($sql);
        return $sss = $query->result_array();
    }

    public function register($test)
    {

        $sql = "SELECT * FROM `register` WHERE phone='" . $test['phone'] . "' and number ='" . $test['number'] . "'";

        $query = $this->db->query($sql);

        $eee = $query->num_rows();

        if ($eee == 0) {
            $this->db->insert('register', $test);
            echo '<script>alert("Register Successfully");window.location.replace("' . base_url() . 'home")</script>';
        } else {
            echo '<script>alert("already exists!!");window.location.replace("' . base_url() . 'home")</script>';
        }
    }

    public function login($number, $password)
    {
        $sql = "SELECT * FROM `register` WHERE number='" . $number . "' and password ='" . $password . "'";
        $query = $this->db->query($sql);

        $eee = $query->num_rows();

        if ($eee == 1) {
            echo '<script>alert("Login Successfully");window.location.replace("' . base_url() . 'userview")</script>';
        } else {
            echo '<script>alert("Login Failed !!");window.location.replace("' . base_url() . 'home")</script>';
        }

    }

    public function card($cardnumber, $cvv, $amount, $source, $destination, $number,$button)
    {
        $sql = "INSERT INTO `arrivals`(`id`, `number`, `card number`, `source`, `destination`, `amount`,`cvv`,`button`) VALUES ('','" . $number . "','" . $cardnumber . "','" . $source . "','" . $destination . "','" . $amount . "','" . $cvv . "','".$button."')";

        $query = $this->db->query($sql);
        if ($query == 1) {
            echo '<script>alert("Payment Successfully");window.location.replace("' . base_url() . 'front")</script>';
        } else {
            echo '<script>alert("Payment Failed !!");window.location.replace("' . base_url() . 'front")</script>';
        }
    }
public function adminlogin($adminname,$password)
{
    $sql = "SELECT * FROM `admin` WHERE username='" . $adminname . "' and password ='" . $password . "'";

    $query = $this->db->query($sql);
    $eee = $query->num_rows();

    if ($eee == 1) {
        echo '<script>alert("Login Successfully");window.location.replace("' . base_url() . 'adminview")</script>';
    } else {
        echo '<script>alert("Login Failed !!");window.location.replace("' . base_url() . 'admin")</script>';
    }
}
public function adminview()
{
    $sql = "SELECT * FROM `arrivals` ORDER BY id DESC limit 8 ";
    $query = $this->db->query($sql);
    return $eee = $query->result_array();

}
    public function tolllogin($username,$password)
    {
        $sql = "SELECT * FROM `toll` WHERE username='" . $username . "' and password ='" . $password . "'";
        $query = $this->db->query($sql);
        $eee = $query->num_rows();
        if($eee == 1) {
            echo '<script>alert("Login Successfully");window.location.replace("' . base_url() . 'tollview")</script>';
        } else {
            echo '<script>alert("Login Failed !!");window.location.replace("' . base_url() . 'toll")</script>';
        }
    }
    public function tollview()
    {
        $sql = "SELECT * FROM `arrivals` ORDER BY id DESC limit 4";
        $query = $this->db->query($sql);
        return $eee = $query->result_array();

    }
public function update($button,$number,$id)
{
    $sql = "UPDATE `arrivals` SET `button`='" . $button . "' WHERE id='" . $id . "' and number='" . $number . "'";

    $query = $this->db->query($sql);

    if ($query == 1) {
        echo '<script>alert("Updated Successfully");window.location.replace("' . base_url() . 'tollview")</script>';
    } else {
        echo '<script>alert("Updated Failed !!");window.location.replace("' . base_url() . 'toll")</script>';
    }
}
public function test($gm)
{
   $this->db->insert(test,$gm);
}




}