<?php


class jet
{
  private $connection;
  private $sql;
  private $table_name;

   
   public function __construct($host ="ewg.dedicated.co.za" , $user ="elegaysv_Code2" , $password = "EWG2Cod!@#" , $dbname ="elegaysv_spar") {

    $this->connection = mysqli_connect($host, $user, $password, $dbname);

    if (mysqli_connect_errno()) { 
      return "Failed to connect to MySQL: "  . mysqli_connect_error();
      exit();
     }
   }

   function check_table_exists($table)
    {
        $this->table_name = $table;
        $sql = "SHOW TABLES LIKE '$table' ";
        $result = mysqli_query($this->connection, $sql);

        if (mysqli_num_rows($result) > 0) {

            return true;

        } else {

            return false;

        }
    }


    public function query($table_name, $sql)
    {
        $this->sql = $sql;
        $this->table_name = $table_name;
        // if (!$this->check_table_exists($table_name)) {
        //     echo "[SQL] TABLE NAME DOES NOT EXIST OR IS INCORRECT $table_name";
        // }
        $result = mysqli_query($this->connection, $this->sql);

        if (mysqli_error($this->connection)) {
            echo "[SQL QUERY FAILED] on " . $_SERVER['REQUEST_URI'] . " at line " . __LINE__ . ": " . mysqli_error($this->connection) . "<br>";
            echo "[SQL QUERY]: " . $sql;
            exit();
        } else {
            if (stripos(trim($sql), 'INSERT') === 0) {
                return mysqli_insert_id($this->connection);
            } else {
                return $result;
            }
        }
    }

}

class nav
{

    /**
     * Start Navbar
     */
    function __construct()
    {
        ?>
        
        <style>

            body{
                margin:0;
                padding:0;
            }

            .navbar{
                width:100%;
                background-color:#333333;
                display:flex;
                flex-direction:row;
                justify-content:space-between;
                align-items:center;
                padding:0px 20px;
                box-sizing:border-box;
            }

            .nav-brand{
                color:white;
                font-size:22px;
                font-weight:bold;
            }

            .nav-links{
                list-style:none;
                display:flex;
                margin:0;
                padding:0;
            }

            .nav-links li{
                margin:0px 10px;
            }

            .nav-links li a{
                display:block;
                color:white;
                text-decoration:none;
                padding:15px 10px;
                transition:0.3s;
            }

            .nav-links li a:hover{
                background-color:#111111;
            }

        </style>

        <nav class="navbar">

            <div class="nav-brand">
                
        <?php
    }

    /**
     * Add Brand / Logo Text
     */
    function add_brand($name)
    {
        echo $name;
    }

    /**
     * End Brand Section
     */
    function end_brand()
    {
        ?>
            </div>

            <ul class="nav-links">
        <?php
    }

    /**
     * Add Navigation Link
     */
    function add_link($name, $url)
    {
        ?>
            <li>
                <a href="<?php echo $url; ?>">
                    <?php echo $name; ?>
                </a>
            </li>
        <?php
    }

    /**
     * Add Button Link
     */
    function add_button($name, $onclick = "")
    {
        ?>
            <li>
                <a href="#" onclick="<?php echo $onclick; ?>">
                    <?php echo $name; ?>
                </a>
            </li>
        <?php
    }

    /**
     * End Navbar
     */
    function nav_end()
    {
        ?>
            </ul>

        </nav>

        <?php
    }

}

